* Mapping to exists for merge. * * @public * @param {Array. |Array. } exists * @param {Object|Array. } newCptOptions * @return {Array. } Result, like [{exist: ..., option: ...}, {}], * index of which is the same as ex
(exists, newCptOptions)
| 11816 | * index of which is the same as exists. |
| 11817 | */ |
| 11818 | function mappingToExists(exists, newCptOptions) { |
| 11819 | // Mapping by the order by original option (but not order of |
| 11820 | // new option) in merge mode. Because we should ensure |
| 11821 | // some specified index (like xAxisIndex) is consistent with |
| 11822 | // original option, which is easy to understand, espatially in |
| 11823 | // media query. And in most case, merge option is used to |
| 11824 | // update partial option but not be expected to change order. |
| 11825 | newCptOptions = (newCptOptions || []).slice(); |
| 11826 | |
| 11827 | var result = map(exists || [], function (obj, index) { |
| 11828 | return {exist: obj}; |
| 11829 | }); |
| 11830 | |
| 11831 | // Mapping by id or name if specified. |
| 11832 | each$2(newCptOptions, function (cptOption, index) { |
| 11833 | if (!isObject$2(cptOption)) { |
| 11834 | return; |
| 11835 | } |
| 11836 | |
| 11837 | // id has highest priority. |
| 11838 | for (var i = 0; i < result.length; i++) { |
| 11839 | if (!result[i].option // Consider name: two map to one. |
| 11840 | && cptOption.id != null |
| 11841 | && result[i].exist.id === cptOption.id + '' |
| 11842 | ) { |
| 11843 | result[i].option = cptOption; |
| 11844 | newCptOptions[index] = null; |
| 11845 | return; |
| 11846 | } |
| 11847 | } |
| 11848 | |
| 11849 | for (var i = 0; i < result.length; i++) { |
| 11850 | var exist = result[i].exist; |
| 11851 | if (!result[i].option // Consider name: two map to one. |
| 11852 | // Can not match when both ids exist but different. |
| 11853 | && (exist.id == null || cptOption.id == null) |
| 11854 | && cptOption.name != null |
| 11855 | && !isIdInner(cptOption) |
| 11856 | && !isIdInner(exist) |
| 11857 | && exist.name === cptOption.name + '' |
| 11858 | ) { |
| 11859 | result[i].option = cptOption; |
| 11860 | newCptOptions[index] = null; |
| 11861 | return; |
| 11862 | } |
| 11863 | } |
| 11864 | }); |
| 11865 | |
| 11866 | // Otherwise mapping by index. |
| 11867 | each$2(newCptOptions, function (cptOption, index) { |
| 11868 | if (!isObject$2(cptOption)) { |
| 11869 | return; |
| 11870 | } |
| 11871 | |
| 11872 | var i = 0; |
| 11873 | for (; i < result.length; i++) { |
| 11874 | var exist = result[i].exist; |
| 11875 | if (!result[i].option |
no test coverage detected