1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* AUTO-GENERATED FILE. DO NOT MODIFY.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { each, isObject, isArray, createHashMap, map, assert, isString, indexOf, isStringSafe, isNumber } from 'zrender/lib/core/util.js';
import env from 'zrender/lib/core/env.js';
import { isNumeric, getRandomIdBase, getPrecision, round } from './number.js';
import { warn } from './log.js';
function interpolateNumber(p0, p1, percent) {
return (p1 - p0) * percent + p0;
}
/**
* Make the name displayable. But we should
* make sure it is not duplicated with user
* specified name, so use '\0';
*/
var DUMMY_COMPONENT_NAME_PREFIX = 'series\0';
var INTERNAL_COMPONENT_ID_PREFIX = '\0_ec_\0';
/**
* If value is not array, then translate it to array.
* @param {*} value
* @return {Array} [value] or value
*/
export function normalizeToArray(value) {
return value instanceof Array ? value : value == null ? [] : [value];
}
/**
* Sync default option between normal and emphasis like `position` and `show`
* In case some one will write code like
* label: {
* show: false,
* position: 'outside',
* fontSize: 18
* },
* emphasis: {
* label: { show: true }
* }
*/
export function defaultEmphasis(opt, key, subOpts) {
// Caution: performance sensitive.
if (opt) {
opt[key] = opt[key] || {};
opt.emphasis = opt.emphasis || {};
opt.emphasis[key] = opt.emphasis[key] || {};
// Default emphasis option from normal
for (var i = 0, len = subOpts.length; i < len; i++) {
var subOptName = subOpts[i];
if (!opt.emphasis[key].hasOwnProperty(subOptName) && opt[key].hasOwnProperty(subOptName)) {
opt.emphasis[key][subOptName] = opt[key][subOptName];
}
}
}
}
export var TEXT_STYLE_OPTIONS = ['fontStyle', 'fontWeight', 'fontSize', 'fontFamily', 'rich', 'tag', 'color', 'textBorderColor', 'textBorderWidth', 'width', 'height', 'lineHeight', 'align', 'verticalAlign', 'baseline', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY', 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY', 'backgroundColor', 'borderColor', 'borderWidth', 'borderRadius', 'padding'];
// modelUtil.LABEL_OPTIONS = modelUtil.TEXT_STYLE_OPTIONS.concat([
// 'position', 'offset', 'rotate', 'origin', 'show', 'distance', 'formatter',
// 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
// // FIXME: deprecated, check and remove it.
// 'textStyle'
// ]);
/**
* The method does not ensure performance.
* data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
* This helper method retrieves value from data.
*/
export function getDataItemValue(dataItem) {
return isObject(dataItem) && !isArray(dataItem) && !(dataItem instanceof Date) ? dataItem.value : dataItem;
}
/**
* data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
* This helper method determine if dataItem has extra option besides value
*/
export function isDataItemOption(dataItem) {
return isObject(dataItem) && !(dataItem instanceof Array);
// // markLine data can be array
// && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
}
;
/**
* Mapping to existings for merge.
*
* Mode "normalMege":
* The mapping result (merge result) will keep the order of the existing
* component, rather than the order of new option. Because we should ensure
* some specified index reference (like xAxisIndex) keep work.
* And in most cases, "merge option" is used to update partial option but not
* be expected to change the order.
*
* Mode "replaceMege":
* (1) Only the id mapped components will be merged.
* (2) Other existing components (except internal components) will be removed.
* (3) Other new options will be used to create new component.
* (4) The index of the existing components will not be modified.
* That means their might be "hole" after the removal.
* The new components are created first at those available index.
*
* Mode "replaceAll":
* This mode try to support that reproduce an echarts instance from another
* echarts instance (via `getOption`) in some simple cases.
* In this scenario, the `result` index are exactly the consistent with the `newCmptOptions`,
* which ensures the component index referring (like `xAxisIndex: ?`) corrent. That is,
* the "hole" in `newCmptOptions` will also be kept.
* On the contrary, other modes try best to eliminate holes.
* PENDING: This is an experimental mode yet.
*
* @return See the comment of <MappingResult>.
*/
export function mappingToExists(existings, newCmptOptions, mode) {
var isNormalMergeMode = mode === 'normalMerge';
var isReplaceMergeMode = mode === 'replaceMerge';
var isReplaceAllMode = mode === 'replaceAll';
existings = existings || [];
newCmptOptions = (newCmptOptions || []).slice();
var existingIdIdxMap = createHashMap();
// Validate id and name on user input option.
each(newCmptOptions, function (cmptOption, index) {
if (!isObject(cmptOption)) {
newCmptOptions[index] = null;
return;
}
if (process.env.NODE_ENV !== 'production') {
// There is some legacy case that name is set as `false`.
// But should work normally rather than throw error.
if (cmptOption.id != null && !isValidIdOrName(cmptOption.id)) {
warnInvalidateIdOrName(cmptOption.id);
}
if (cmptOption.name != null && !isValidIdOrName(cmptOption.name)) {
warnInvalidateIdOrName(cmptOption.name);
}
}
});
var result = prepareResult(existings, existingIdIdxMap, mode);
if (isNormalMergeMode || isReplaceMergeMode) {
mappingById(result, existings, existingIdIdxMap, newCmptOptions);
}
if (isNormalMergeMode) {
mappingByName(result, newCmptOptions);
}
if (isNormalMergeMode || isReplaceMergeMode) {
mappingByIndex(result, newCmptOptions, isReplaceMergeMode);
} else if (isReplaceAllMode) {
mappingInReplaceAllMode(result, newCmptOptions);
}
makeIdAndName(result);
// The array `result` MUST NOT contain elided items, otherwise the
// forEach will omit those items and result in incorrect result.
return result;
}
function prepareResult(existings, existingIdIdxMap, mode) {
var result = [];
if (mode === 'replaceAll') {
return result;
}
// Do not use native `map` to in case that the array `existings`
// contains elided items, which will be omitted.
for (var index = 0; index < existings.length; index++) {
var existing = existings[index];
// Because of replaceMerge, `existing` may be null/undefined.
if (existing && existing.id != null) {
existingIdIdxMap.set(existing.id, index);
}
// For non-internal-componnets:
// Mode "normalMerge": all existings kept.
// Mode "replaceMerge": all existing removed unless mapped by id.
// For internal-components:
// go with "replaceMerge" approach in both mode.
result.push({
existing: mode === 'replaceMerge' || isComponentIdInternal(existing) ? null : existing,
newOption: null,
keyInfo: null,
brandNew: null
});
}
return result;
}
function mappingById(result, existings, existingIdIdxMap, newCmptOptions) {
// Mapping by id if specified.
each(newCmptOptions, function (cmptOption, index) {
if (!cmptOption || cmptOption.id == null) {
return;
}
var optionId = makeComparableKey(cmptOption.id);
var existingIdx = existingIdIdxMap.get(optionId);
if (existingIdx != null) {
var resultItem = result[existingIdx];
assert(!resultItem.newOption, 'Duplicated option on id "' + optionId + '".');
resultItem.newOption = cmptOption;
// In both mode, if id matched, new option will be merged to
// the existings rather than creating new component model.
resultItem.existing = existings[existingIdx];
newCmptOptions[index] = null;
}
});
}
function mappingByName(result, newCmptOptions) {
// Mapping by name if specified.
each(newCmptOptions, function (cmptOption, index) {
if (!cmptOption || cmptOption.name == null) {
return;
}
for (var i = 0; i < result.length; i++) {
var existing = result[i].existing;
if (!result[i].newOption // Consider name: two map to one.
// Can not match when both ids existing but different.
&& existing && (existing.id == null || cmptOption.id == null) && !isComponentIdInternal(cmptOption) && !isComponentIdInternal(existing) && keyExistAndEqual('name', existing, cmptOption)) {
result[i].newOption = cmptOption;
newCmptOptions[index] = null;
return;
}
}
});
}
function mappingByIndex(result, newCmptOptions, brandNew) {
each(newCmptOptions, function (cmptOption) {
if (!cmptOption) {
return;
}
// Find the first place that not mapped by id and not internal component (consider the "hole").
var resultItem;
var nextIdx = 0;
while (
// Be `!resultItem` only when `nextIdx >= result.length`.
(resultItem = result[nextIdx]
// (1) Existing models that already have id should be able to mapped to. Because
// after mapping performed, model will always be assigned with an id if user not given.
// After that all models have id.
// (2) If new option has id, it can only set to a hole or append to the last. It should
// not be merged to the existings with different id. Because id should not be overwritten.
// (3) Name can be overwritten, because axis use name as 'show label text'.
) && (resultItem.newOption || isComponentIdInternal(resultItem.existing) ||
// In mode "replaceMerge", here no not-mapped-non-internal-existing.
resultItem.existing && cmptOption.id != null && !keyExistAndEqual('id', cmptOption, resultItem.existing))) {
nextIdx++;
}
if (resultItem) {
resultItem.newOption = cmptOption;
resultItem.brandNew = brandNew;
} else {
result.push({
newOption: cmptOption,
brandNew: brandNew,
existing: null,
keyInfo: null
});
}
nextIdx++;
});
}
function mappingInReplaceAllMode(result, newCmptOptions) {
each(newCmptOptions, function (cmptOption) {
// The feature "reproduce" requires "hole" will also reproduced
// in case that component index referring are broken.
result.push({
newOption: cmptOption,
brandNew: true,
existing: null,
keyInfo: null
});
});
}
/**
* Make id and name for mapping result (result of mappingToExists)
* into `keyInfo` field.
*/
function makeIdAndName(mapResult) {
// We use this id to hash component models and view instances
// in echarts. id can be specified by user, or auto generated.
// The id generation rule ensures new view instance are able
// to mapped to old instance when setOption are called in
// no-merge mode. So we generate model id by name and plus
// type in view id.
// name can be duplicated among components, which is convenient
// to specify multi components (like series) by one name.
// Ensure that each id is distinct.
var idMap = createHashMap();
each(mapResult, function (item) {
var existing = item.existing;
existing && idMap.set(existing.id, item);
});
each(mapResult, function (item) {
var opt = item.newOption;
// Force ensure id not duplicated.
assert(!opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item, 'id duplicates: ' + (opt && opt.id));
opt && opt.id != null && idMap.set(opt.id, item);
!item.keyInfo && (item.keyInfo = {});
});
// Make name and id.
each(mapResult, function (item, index) {
var existing = item.existing;
var opt = item.newOption;
var keyInfo = item.keyInfo;
if (!isObject(opt)) {
return;
}
// Name can be overwritten. Consider case: axis.name = '20km'.
// But id generated by name will not be changed, which affect
// only in that case: setOption with 'not merge mode' and view
// instance will be recreated, which can be accepted.
keyInfo.name = opt.name != null ? makeComparableKey(opt.name) : existing ? existing.name
// Avoid that different series has the same name,
// because name may be used like in color pallet.
: DUMMY_COMPONENT_NAME_PREFIX + index;
if (existing) {
keyInfo.id = makeComparableKey(existing.id);
} else if (opt.id != null) {
keyInfo.id = makeComparableKey(opt.id);
} else {
// Consider this situatoin:
// optionA: [{name: 'a'}, {name: 'a'}, {..}]
// optionB [{..}, {name: 'a'}, {name: 'a'}]
// Series with the same name between optionA and optionB
// should be mapped.
var idNum = 0;
do {
keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
} while (idMap.get(keyInfo.id));
}
idMap.set(keyInfo.id, item);
});
}
function keyExistAndEqual(attr, obj1, obj2) {
var key1 = convertOptionIdName(obj1[attr], null);
var key2 = convertOptionIdName(obj2[attr], null);
// See `MappingExistingItem`. `id` and `name` trade string equals to number.
return key1 != null && key2 != null && key1 === key2;
}
/**
* @return return null if not exist.
*/
function makeComparableKey(val) {
if (process.env.NODE_ENV !== 'production') {
if (val == null) {
throw new Error();
}
}
return convertOptionIdName(val, '');
}
export function convertOptionIdName(idOrName, defaultValue) {
if (idOrName == null) {
return defaultValue;
}
return isString(idOrName) ? idOrName : isNumber(idOrName) || isStringSafe(idOrName) ? idOrName + '' : defaultValue;
}
function warnInvalidateIdOrName(idOrName) {
if (process.env.NODE_ENV !== 'production') {
warn('`' + idOrName + '` is invalid id or name. Must be a string or number.');
}
}
function isValidIdOrName(idOrName) {
return isStringSafe(idOrName) || isNumeric(idOrName);
}
export function isNameSpecified(componentModel) {
var name = componentModel.name;
// Is specified when `indexOf` get -1 or > 0.
return !!(name && name.indexOf(DUMMY_COMPONENT_NAME_PREFIX));
}
/**
* @public
* @param {Object} cmptOption
* @return {boolean}
*/
export function isComponentIdInternal(cmptOption) {
return cmptOption && cmptOption.id != null && makeComparableKey(cmptOption.id).indexOf(INTERNAL_COMPONENT_ID_PREFIX) === 0;
}
export function makeInternalComponentId(idSuffix) {
return INTERNAL_COMPONENT_ID_PREFIX + idSuffix;
}
export function setComponentTypeToKeyInfo(mappingResult, mainType, componentModelCtor) {
// Set mainType and complete subType.
each(mappingResult, function (item) {
var newOption = item.newOption;
if (isObject(newOption)) {
item.keyInfo.mainType = mainType;
item.keyInfo.subType = determineSubType(mainType, newOption, item.existing, componentModelCtor);
}
});
}
function determineSubType(mainType, newCmptOption, existComponent, componentModelCtor) {
var subType = newCmptOption.type ? newCmptOption.type : existComponent ? existComponent.subType
// Use determineSubType only when there is no existComponent.
: componentModelCtor.determineSubType(mainType, newCmptOption);
// tooltip, markline, markpoint may always has no subType
return subType;
}
/**
* A helper for removing duplicate items between batchA and batchB,
* and in themselves, and categorize by series.
*
* @param batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
* @param batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
* @return result: [resultBatchA, resultBatchB]
*/
export function compressBatches(batchA, batchB) {
var mapA = {};
var mapB = {};
makeMap(batchA || [], mapA);
makeMap(batchB || [], mapB, mapA);
return [mapToArray(mapA), mapToArray(mapB)];
function makeMap(sourceBatch, map, otherMap) {
for (var i = 0, len = sourceBatch.length; i < len; i++) {
var seriesId = convertOptionIdName(sourceBatch[i].seriesId, null);
if (seriesId == null) {
return;
}
var dataIndices = normalizeToArray(sourceBatch[i].dataIndex);
var otherDataIndices = otherMap && otherMap[seriesId];
for (var j = 0, lenj = dataIndices.length; j < lenj; j++) {
var dataIndex = dataIndices[j];
if (otherDataIndices && otherDataIndices[dataIndex]) {
otherDataIndices[dataIndex] = null;
} else {
(map[seriesId] || (map[seriesId] = {}))[dataIndex] = 1;
}
}
}
}
function mapToArray(map, isData) {
var result = [];
for (var i in map) {
if (map.hasOwnProperty(i) && map[i] != null) {
if (isData) {
result.push(+i);
} else {
var dataIndices = mapToArray(map[i], true);
dataIndices.length && result.push({
seriesId: i,
dataIndex: dataIndices
});
}
}
}
return result;
}
}
/**
* @param payload Contains dataIndex (means rawIndex) / dataIndexInside / name
* each of which can be Array or primary type.
* @return dataIndex If not found, return undefined/null.
*/
export function queryDataIndex(data, payload) {
if (payload.dataIndexInside != null) {
return payload.dataIndexInside;
} else if (payload.dataIndex != null) {
return isArray(payload.dataIndex) ? map(payload.dataIndex, function (value) {
return data.indexOfRawIndex(value);
}) : data.indexOfRawIndex(payload.dataIndex);
} else if (payload.name != null) {
return isArray(payload.name) ? map(payload.name, function (value) {
return data.indexOfName(value);
}) : data.indexOfName(payload.name);
}
}
/**
* Enable property storage to any host object.
* Notice: Serialization is not supported.
*
* For example:
* let inner = zrUitl.makeInner();
*
* function some1(hostObj) {
* inner(hostObj).someProperty = 1212;
* ...
* }
* function some2() {
* let fields = inner(this);
* fields.someProperty1 = 1212;
* fields.someProperty2 = 'xx';
* ...
* }
*
* @return {Function}
*/
export function makeInner() {
var key = '__ec_inner_' + innerUniqueIndex++;
return function (hostObj) {
return hostObj[key] || (hostObj[key] = {});
};
}
var innerUniqueIndex = getRandomIdBase();
/**
* The same behavior as `component.getReferringComponents`.
*/
export function parseFinder(ecModel, finderInput, opt) {
var _a = preParseFinder(finderInput, opt),
mainTypeSpecified = _a.mainTypeSpecified,
queryOptionMap = _a.queryOptionMap,
others = _a.others;
var result = others;
var defaultMainType = opt ? opt.defaultMainType : null;
if (!mainTypeSpecified && defaultMainType) {
queryOptionMap.set(defaultMainType, {});
}
queryOptionMap.each(function (queryOption, mainType) {
var queryResult = queryReferringComponents(ecModel, mainType, queryOption, {
useDefault: defaultMainType === mainType,
enableAll: opt && opt.enableAll != null ? opt.enableAll : true,
enableNone: opt && opt.enableNone != null ? opt.enableNone : true
});
result[mainType + 'Models'] = queryResult.models;
result[mainType + 'Model'] = queryResult.models[0];
});
return result;
}
export function preParseFinder(finderInput, opt) {
var finder;
if (isString(finderInput)) {
var obj = {};
obj[finderInput + 'Index'] = 0;
finder = obj;
} else {
finder = finderInput;
}
var queryOptionMap = createHashMap();
var others = {};
var mainTypeSpecified = false;
each(finder, function (value, key) {
// Exclude 'dataIndex' and other illgal keys.
if (key === 'dataIndex' || key === 'dataIndexInside') {
others[key] = value;
return;
}
var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
var mainType = parsedKey[1];
var queryType = (parsedKey[2] || '').toLowerCase();
if (!mainType || !queryType || opt && opt.includeMainTypes && indexOf(opt.includeMainTypes, mainType) < 0) {
return;
}
mainTypeSpecified = mainTypeSpecified || !!mainType;
var queryOption = queryOptionMap.get(mainType) || queryOptionMap.set(mainType, {});
queryOption[queryType] = value;
});
return {
mainTypeSpecified: mainTypeSpecified,
queryOptionMap: queryOptionMap,
others: others
};
}
export var SINGLE_REFERRING = {
useDefault: true,
enableAll: false,
enableNone: false
};
export var MULTIPLE_REFERRING = {
useDefault: false,
enableAll: true,
enableNone: true
};
export function queryReferringComponents(ecModel, mainType, userOption, opt) {
opt = opt || SINGLE_REFERRING;
var indexOption = userOption.index;
var idOption = userOption.id;
var nameOption = userOption.name;
var result = {
models: null,
specified: indexOption != null || idOption != null || nameOption != null
};
if (!result.specified) {
// Use the first as default if `useDefault`.
var firstCmpt = void 0;
result.models = opt.useDefault && (firstCmpt = ecModel.getComponent(mainType)) ? [firstCmpt] : [];
return result;
}
if (indexOption === 'none' || indexOption === false) {
assert(opt.enableNone, '`"none"` or `false` is not a valid value on index option.');
result.models = [];
return result;
}
// `queryComponents` will return all components if
// both all of index/id/name are null/undefined.
if (indexOption === 'all') {
assert(opt.enableAll, '`"all"` is not a valid value on index option.');
indexOption = idOption = nameOption = null;
}
result.models = ecModel.queryComponents({
mainType: mainType,
index: indexOption,
id: idOption,
name: nameOption
});
return result;
}
export function setAttribute(dom, key, value) {
dom.setAttribute ? dom.setAttribute(key, value) : dom[key] = value;
}
export function getAttribute(dom, key) {
return dom.getAttribute ? dom.getAttribute(key) : dom[key];
}
export function getTooltipRenderMode(renderModeOption) {
if (renderModeOption === 'auto') {
// Using html when `document` exists, use richText otherwise
return env.domSupported ? 'html' : 'richText';
} else {
return renderModeOption || 'html';
}
}
/**
* Group a list by key.
*/
export function groupData(array, getKey // return key
) {
var buckets = createHashMap();
var keys = [];
each(array, function (item) {
var key = getKey(item);
(buckets.get(key) || (keys.push(key), buckets.set(key, []))).push(item);
});
return {
keys: keys,
buckets: buckets
};
}
/**
* Interpolate raw values of a series with percent
*
* @param data data
* @param labelModel label model of the text element
* @param sourceValue start value. May be null/undefined when init.
* @param targetValue end value
* @param percent 0~1 percentage; 0 uses start value while 1 uses end value
* @return interpolated values
* If `sourceValue` and `targetValue` are `number`, return `number`.
* If `sourceValue` and `targetValue` are `string`, return `string`.
* If `sourceValue` and `targetValue` are `(string | number)[]`, return `(string | number)[]`.
* Other cases do not supported.
*/
export function interpolateRawValues(data, precision, sourceValue, targetValue, percent) {
var isAutoPrecision = precision == null || precision === 'auto';
if (targetValue == null) {
return targetValue;
}
if (isNumber(targetValue)) {
var value = interpolateNumber(sourceValue || 0, targetValue, percent);
return round(value, isAutoPrecision ? Math.max(getPrecision(sourceValue || 0), getPrecision(targetValue)) : precision);
} else if (isString(targetValue)) {
return percent < 1 ? sourceValue : targetValue;
} else {
var interpolated = [];
var leftArr = sourceValue;
var rightArr = targetValue;
var length_1 = Math.max(leftArr ? leftArr.length : 0, rightArr.length);
for (var i = 0; i < length_1; ++i) {
var info = data.getDimensionInfo(i);
// Don't interpolate ordinal dims
if (info && info.type === 'ordinal') {
// In init, there is no `sourceValue`, but should better not to get undefined result.
interpolated[i] = (percent < 1 && leftArr ? leftArr : rightArr)[i];
} else {
var leftVal = leftArr && leftArr[i] ? leftArr[i] : 0;
var rightVal = rightArr[i];
var value = interpolateNumber(leftVal, rightVal, percent);
interpolated[i] = round(value, isAutoPrecision ? Math.max(getPrecision(leftVal), getPrecision(rightVal)) : precision);
}
}
return interpolated;
}
}