* Make id and name for mapping result (result of mappingToExists) * into `keyInfo` field. * * @public * @param {Array. } Result, like [{exist: ..., option: ...}, {}], * which order is the same as exists. * @return {Array. } The input.
(mapResult)
| 11908 | * @return {Array.<Object>} The input. |
| 11909 | */ |
| 11910 | function makeIdAndName(mapResult) { |
| 11911 | // We use this id to hash component models and view instances |
| 11912 | // in echarts. id can be specified by user, or auto generated. |
| 11913 | |
| 11914 | // The id generation rule ensures new view instance are able |
| 11915 | // to mapped to old instance when setOption are called in |
| 11916 | // no-merge mode. So we generate model id by name and plus |
| 11917 | // type in view id. |
| 11918 | |
| 11919 | // name can be duplicated among components, which is convenient |
| 11920 | // to specify multi components (like series) by one name. |
| 11921 | |
| 11922 | // Ensure that each id is distinct. |
| 11923 | var idMap = createHashMap(); |
| 11924 | |
| 11925 | each$2(mapResult, function (item, index) { |
| 11926 | var existCpt = item.exist; |
| 11927 | existCpt && idMap.set(existCpt.id, item); |
| 11928 | }); |
| 11929 | |
| 11930 | each$2(mapResult, function (item, index) { |
| 11931 | var opt = item.option; |
| 11932 | |
| 11933 | assert$1( |
| 11934 | !opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item, |
| 11935 | 'id duplicates: ' + (opt && opt.id) |
| 11936 | ); |
| 11937 | |
| 11938 | opt && opt.id != null && idMap.set(opt.id, item); |
| 11939 | !item.keyInfo && (item.keyInfo = {}); |
| 11940 | }); |
| 11941 | |
| 11942 | // Make name and id. |
| 11943 | each$2(mapResult, function (item, index) { |
| 11944 | var existCpt = item.exist; |
| 11945 | var opt = item.option; |
| 11946 | var keyInfo = item.keyInfo; |
| 11947 | |
| 11948 | if (!isObject$2(opt)) { |
| 11949 | return; |
| 11950 | } |
| 11951 | |
| 11952 | // name can be overwitten. Consider case: axis.name = '20km'. |
| 11953 | // But id generated by name will not be changed, which affect |
| 11954 | // only in that case: setOption with 'not merge mode' and view |
| 11955 | // instance will be recreated, which can be accepted. |
| 11956 | keyInfo.name = opt.name != null |
| 11957 | ? opt.name + '' |
| 11958 | : existCpt |
| 11959 | ? existCpt.name |
| 11960 | // Avoid diffferent series has the same name, |
| 11961 | // because name may be used like in color pallet. |
| 11962 | : DUMMY_COMPONENT_NAME_PREFIX + index; |
| 11963 | |
| 11964 | if (existCpt) { |
| 11965 | keyInfo.id = existCpt.id; |
| 11966 | } |
| 11967 | else if (opt.id != null) { |
no test coverage detected