You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by su...@apache.org on 2020/10/15 16:48:34 UTC
[incubator-echarts] 03/08: fix: (1) clarify id and name type. (2)
compat non supported name type.
This is an automated email from the ASF dual-hosted git repository.
sushuang pushed a commit to branch fix-ut
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit 81b2efe537d7e32892c60517ec316ab6c6df4ee3
Author: 100pah <su...@gmail.com>
AuthorDate: Thu Oct 15 16:18:56 2020 +0800
fix: (1) clarify id and name type. (2) compat non supported name type.
---
src/chart/treemap/Breadcrumb.ts | 3 ++-
src/chart/treemap/TreemapSeries.ts | 8 +++++---
src/chart/treemap/TreemapView.ts | 7 ++++---
src/echarts.ts | 10 ++++++++--
src/model/Global.ts | 27 +++++++++++++++------------
src/util/model.ts | 21 ++++++++++++++-------
src/util/types.ts | 4 +---
7 files changed, 49 insertions(+), 31 deletions(-)
diff --git a/src/chart/treemap/Breadcrumb.ts b/src/chart/treemap/Breadcrumb.ts
index 6ee42a6..beacf13 100644
--- a/src/chart/treemap/Breadcrumb.ts
+++ b/src/chart/treemap/Breadcrumb.ts
@@ -28,6 +28,7 @@ import { curry, defaults } from 'zrender/src/core/util';
import { ZRElementEvent, BoxLayoutOptionMixin, ECElement } from '../../util/types';
import Element from 'zrender/src/Element';
import Model from '../../model/Model';
+import { convertOptionIdName } from '../../util/model';
const TEXT_PADDING = 8;
const ITEM_GAP = 8;
@@ -110,7 +111,7 @@ class Breadcrumb {
*/
_prepare(targetNode: TreeNode, layoutParam: LayoutParam, textStyleModel: BreadcrumbTextStyleModel) {
for (let node = targetNode; node; node = node.parentNode) {
- const text = node.getModel<TreemapSeriesNodeItemOption>().get('name');
+ const text = convertOptionIdName(node.getModel<TreemapSeriesNodeItemOption>().get('name'), '');
const textRect = textStyleModel.getTextRect(text);
const itemWidth = Math.max(
textRect.width + TEXT_PADDING * 2,
diff --git a/src/chart/treemap/TreemapSeries.ts b/src/chart/treemap/TreemapSeries.ts
index 9bc1852..4aa4fc8 100644
--- a/src/chart/treemap/TreemapSeries.ts
+++ b/src/chart/treemap/TreemapSeries.ts
@@ -30,7 +30,9 @@ import {
RoamOptionMixin,
CallbackDataParams,
ColorString,
- StatesOptionMixin
+ StatesOptionMixin,
+ OptionId,
+ OptionName
} from '../../util/types';
import GlobalModel from '../../model/Global';
import { LayoutRect } from '../../util/layout';
@@ -119,8 +121,8 @@ export interface TreemapSeriesLevelOption extends TreemapSeriesVisualOption,
export interface TreemapSeriesNodeItemOption extends TreemapSeriesVisualOption,
TreemapStateOption, StatesOptionMixin<TreemapStateOption, ExtraStateOption> {
- id?: string
- name?: string
+ id?: OptionId
+ name?: OptionName
value?: TreemapSeriesDataValue
diff --git a/src/chart/treemap/TreemapView.ts b/src/chart/treemap/TreemapView.ts
index 2d97f7a..702111e 100644
--- a/src/chart/treemap/TreemapView.ts
+++ b/src/chart/treemap/TreemapView.ts
@@ -44,7 +44,7 @@ import { LayoutRect } from '../../util/layout';
import { TreemapLayoutNode } from './treemapLayout';
import Element from 'zrender/src/Element';
import Displayable from 'zrender/src/graphic/Displayable';
-import { makeInner } from '../../util/model';
+import { makeInner, convertOptionIdName } from '../../util/model';
import { PathStyleProps, PathProps } from 'zrender/src/graphic/Path';
import { TreeSeriesNodeItemOption } from '../tree/TreeSeries';
import {
@@ -954,7 +954,7 @@ function renderNode(
seriesModel.getFormattedLabel(
thisNode.dataIndex, 'normal', null, null, normalLabelModel.get('formatter')
),
- nodeModel.get('name')
+ convertOptionIdName(nodeModel.get('name'), null)
);
if (!upperLabelRect && thisLayout.isLeafRoot) {
const iconChar = seriesModel.get('drillDownIcon', true);
@@ -964,7 +964,8 @@ function renderNode(
const isShow = normalLabelModel.getShallow('show');
setLabelStyle(
- rectEl, getLabelStatesModels(nodeModel, upperLabelRect ? PATH_UPPERLABEL_NORMAL : PATH_LABEL_NOAMAL),
+ rectEl,
+ getLabelStatesModels(nodeModel, upperLabelRect ? PATH_UPPERLABEL_NORMAL : PATH_LABEL_NOAMAL),
{
defaultText: isShow ? text : null,
inheritColor: visualColor,
diff --git a/src/echarts.ts b/src/echarts.ts
index 8c1bb7e..fefd6f8 100644
--- a/src/echarts.ts
+++ b/src/echarts.ts
@@ -1381,9 +1381,15 @@ class ECharts extends Eventful {
subType && (condition.subType = subType); // subType may be '' by parseClassType;
const excludeSeriesId = payload.excludeSeriesId;
- let excludeSeriesIdMap: zrUtil.HashMap<string[], string>;
+ let excludeSeriesIdMap: zrUtil.HashMap<true, string>;
if (excludeSeriesId != null) {
- excludeSeriesIdMap = zrUtil.createHashMap(modelUtil.normalizeToArray(excludeSeriesId));
+ excludeSeriesIdMap = zrUtil.createHashMap();
+ each(modelUtil.normalizeToArray(excludeSeriesId), id => {
+ const modelId = modelUtil.convertOptionIdName(id, null);
+ if (modelId != null) {
+ excludeSeriesIdMap.set(modelId, true);
+ }
+ });
}
// If dispatchAction before setOption, do nothing.
diff --git a/src/model/Global.ts b/src/model/Global.ts
index 0b97c8d..99bd7e9 100644
--- a/src/model/Global.ts
+++ b/src/model/Global.ts
@@ -52,7 +52,9 @@ import {
ThemeOption,
ComponentOption,
ComponentMainType,
- ComponentSubType
+ ComponentSubType,
+ OptionId,
+ OptionName
} from '../util/types';
import OptionManager from './OptionManager';
import Scheduler from '../stream/Scheduler';
@@ -540,8 +542,8 @@ class GlobalModel extends Model<ECUnitOption> {
mainType: mainType,
// subType will be filtered finally.
index: q[indexAttr] as (number | number[]),
- id: q[idAttr] as (string | string[]),
- name: q[nameAttr] as (string | string[])
+ id: q[idAttr] as (OptionId | OptionId[]),
+ name: q[nameAttr] as (OptionName | OptionName[])
}
: null;
}
@@ -622,10 +624,11 @@ class GlobalModel extends Model<ECUnitOption> {
/**
* Get series list before filtered by name.
*/
- getSeriesByName(name: string): SeriesModel[] {
+ getSeriesByName(name: OptionName): SeriesModel[] {
+ const nameStr = modelUtil.convertOptionIdName(name, null);
return filter(
this._componentsMap.get('series') as SeriesModel[],
- oneSeries => !!oneSeries && oneSeries.name === name
+ oneSeries => !!oneSeries && nameStr != null && oneSeries.name === nameStr
);
}
@@ -853,8 +856,8 @@ export interface QueryConditionKindB {
mainType: ComponentMainType;
subType?: ComponentSubType;
index?: number | number[];
- id?: string | number | (string | number)[];
- name?: (string | number) | (string | number)[];
+ id?: OptionId | OptionId[];
+ name?: OptionName | OptionName[];
}
export interface EachComponentAllCallback {
(mainType: string, model: ComponentModel, componentIndex: number): void;
@@ -909,18 +912,18 @@ function queryByIdOrName<T extends { id?: string, name?: string }>(
// Here is a break from echarts4: string and number are
// traded as equal.
if (isArray(idOrName)) {
- const keyMap = createHashMap<boolean>(idOrName);
+ const keyMap = createHashMap<boolean>();
each(idOrName, function (idOrNameItem) {
if (idOrNameItem != null) {
- modelUtil.validateIdOrName(idOrNameItem);
- keyMap.set(idOrNameItem, true);
+ const idName = modelUtil.convertOptionIdName(idOrNameItem, null);
+ idName != null && keyMap.set(idOrNameItem, true);
}
});
return filter(cmpts, cmpt => cmpt && keyMap.get(cmpt[attr]));
}
else {
- modelUtil.validateIdOrName(idOrName);
- return filter(cmpts, cmpt => cmpt && cmpt[attr] === idOrName + '');
+ const idName = modelUtil.convertOptionIdName(idOrName, null);
+ return filter(cmpts, cmpt => cmpt && idName != null && cmpt[attr] === idName);
}
}
diff --git a/src/util/model.ts b/src/util/model.ts
index 35af503..5f214b8 100644
--- a/src/util/model.ts
+++ b/src/util/model.ts
@@ -52,6 +52,7 @@ import CartesianAxisModel from '../coord/cartesian/AxisModel';
import GridModel from '../coord/cartesian/GridModel';
import { isNumeric, getRandomIdBase, getPrecisionSafe, round } from './number';
import { interpolateNumber } from 'zrender/src/animation/Animator';
+import { warn } from './log';
/**
* Make the name displayable. But we should
@@ -232,8 +233,17 @@ export function mappingToExists<T extends MappingExistingItem>(
newCmptOptions[index] = null;
return;
}
- cmptOption.id == null || validateIdOrName(cmptOption.id);
- cmptOption.name == null || validateIdOrName(cmptOption.name);
+
+ if (__DEV__) {
+ // 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);
+ }
+ }
});
const result = prepareResult(existings, existingIdIdxMap, mode);
@@ -535,12 +545,9 @@ export function convertOptionIdName(idOrName: unknown, defaultValue: string): st
: defaultValue;
}
-export function validateIdOrName(idOrName: unknown) {
+function warnInvalidateIdOrName(idOrName: unknown) {
if (__DEV__) {
- assert(
- isValidIdOrName(idOrName),
- '`' + idOrName + '` is invalid id or name. Must be a string.'
- );
+ warn('`' + idOrName + '` is invalid id or name. Must be a string or number.');
}
}
diff --git a/src/util/types.ts b/src/util/types.ts
index 7ce3e5f..443b382 100644
--- a/src/util/types.ts
+++ b/src/util/types.ts
@@ -133,7 +133,7 @@ export interface DataModel extends DataHost, DataFormatMixin {}
// Pick<DataFormatMixin, 'getDataParams' | 'formatTooltip'> {}
interface PayloadItem {
- excludeSeriesId?: string | string[];
+ excludeSeriesId?: OptionId | OptionId[];
animation?: PayloadAnimationPart
[other: string]: any;
}
@@ -1343,8 +1343,6 @@ export interface SeriesOption<StateOption=any, ExtraStateOpts extends {
ColorPaletteOptionMixin,
StatesOptionMixin<StateOption, ExtraStateOpts>
{
- name?: string
-
silent?: boolean
blendMode?: string
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org