This is an automated email from the ASF dual-hosted git repository. sushuang pushed a commit to branch decal-custom in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit affc3917c79433719e8277269ae807548be27bdc Author: 100pah <[email protected]> AuthorDate: Thu Oct 29 23:55:57 2020 +0800 fix: fix decal visual assignment --- src/chart/treemap/TreemapView.ts | 5 +++-- src/coord/parallel/AxisModel.ts | 5 +++-- src/data/List.ts | 3 +-- src/model/mixin/areaStyle.ts | 5 +++-- src/model/mixin/itemStyle.ts | 5 +++-- src/model/mixin/lineStyle.ts | 5 +++-- src/util/types.ts | 3 ++- src/visual/aria.ts | 24 +++++++++++++----------- src/visual/style.ts | 3 +++ test/decal.html | 4 ++-- 10 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/chart/treemap/TreemapView.ts b/src/chart/treemap/TreemapView.ts index 4779b5b..93eb244 100644 --- a/src/chart/treemap/TreemapView.ts +++ b/src/chart/treemap/TreemapView.ts @@ -77,8 +77,9 @@ const getStateItemStyle = makeStyleMapper([ ['shadowBlur'], ['shadowOffsetX'], ['shadowOffsetY'], - ['shadowColor'], - ['decal'] + ['shadowColor'] + // Option decal is in `DecalObject` but style.decal is in `PatternObject`. + // So do not transfer decal directly. ]); const getItemStyleNormal = function (model: Model<TreemapSeriesNodeItemOption['itemStyle']>): PathStyleProps { // Normal style props should include emphasis style props. diff --git a/src/coord/parallel/AxisModel.ts b/src/coord/parallel/AxisModel.ts index fa8efba..7c5e4be 100644 --- a/src/coord/parallel/AxisModel.ts +++ b/src/coord/parallel/AxisModel.ts @@ -79,8 +79,9 @@ class ParallelAxisModel extends ComponentModel<ParallelAxisOption> { ['lineWidth', 'borderWidth'], ['stroke', 'borderColor'], ['width', 'width'], - ['opacity', 'opacity'], - ['decal'] + ['opacity', 'opacity'] + // Option decal is in `DecalObject` but style.decal is in `PatternObject`. + // So do not transfer decal directly. ] )(this.getModel('areaSelectStyle')) as ParallelAreaSelectStyleProps; } diff --git a/src/data/List.ts b/src/data/List.ts index eae8bbb..e960680 100644 --- a/src/data/List.ts +++ b/src/data/List.ts @@ -1787,7 +1787,6 @@ class List< * Make sure itemVisual property is unique */ // TODO: use key to save visual to reduce memory. - // eslint-disable-next-line ensureUniqueItemVisual<K extends keyof Visual>(idx: number, key: K): Visual[K] { const itemVisuals = this._itemVisuals; let itemVisual = itemVisuals[idx] as Visual; @@ -1795,7 +1794,7 @@ class List< itemVisual = itemVisuals[idx] = {} as Visual; } let val = itemVisual[key]; - if (!val) { + if (val == null) { val = this.getVisual(key); // TODO Performance? diff --git a/src/model/mixin/areaStyle.ts b/src/model/mixin/areaStyle.ts index e0f37ff..5efd4e6 100644 --- a/src/model/mixin/areaStyle.ts +++ b/src/model/mixin/areaStyle.ts @@ -28,8 +28,9 @@ export const AREA_STYLE_KEY_MAP = [ ['shadowOffsetX'], ['shadowOffsetY'], ['opacity'], - ['shadowColor'], - ['decal'] + ['shadowColor'] + // Option decal is in `DecalObject` but style.decal is in `PatternObject`. + // So do not transfer decal directly. ]; const getAreaStyle = makeStyleMapper(AREA_STYLE_KEY_MAP); diff --git a/src/model/mixin/itemStyle.ts b/src/model/mixin/itemStyle.ts index 3e38aac..950bf39 100644 --- a/src/model/mixin/itemStyle.ts +++ b/src/model/mixin/itemStyle.ts @@ -35,8 +35,9 @@ export const ITEM_STYLE_KEY_MAP = [ ['lineDashOffset', 'borderDashOffset'], ['lineCap', 'borderCap'], ['lineJoin', 'borderJoin'], - ['miterLimit', 'borderMiterLimit'], - ['decal'] + ['miterLimit', 'borderMiterLimit'] + // Option decal is in `DecalObject` but style.decal is in `PatternObject`. + // So do not transfer decal directly. ]; const getItemStyle = makeStyleMapper(ITEM_STYLE_KEY_MAP); diff --git a/src/model/mixin/lineStyle.ts b/src/model/mixin/lineStyle.ts index dac90db..168102e 100644 --- a/src/model/mixin/lineStyle.ts +++ b/src/model/mixin/lineStyle.ts @@ -34,8 +34,9 @@ export const LINE_STYLE_KEY_MAP = [ ['lineDashOffset', 'dashOffset'], ['lineCap', 'cap'], ['lineJoin', 'join'], - ['miterLimit'], - ['decal'] + ['miterLimit'] + // Option decal is in `DecalObject` but style.decal is in `PatternObject`. + // So do not transfer decal directly. ]; const getLineStyle = makeStyleMapper(LINE_STYLE_KEY_MAP); diff --git a/src/util/types.ts b/src/util/types.ts index 0be5a4c..1d7a605 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -688,7 +688,8 @@ export interface DecalObject { }; export interface InnerDecalObject extends DecalObject { - // If option has changed + // Mark dirty when object may be changed. + // The record in WeakMap will be deleted. dirty?: boolean } diff --git a/src/visual/aria.ts b/src/visual/aria.ts index 41011f1..2a14d2f 100644 --- a/src/visual/aria.ts +++ b/src/visual/aria.ts @@ -105,7 +105,6 @@ export default function (ecModel: GlobalModel, api: ExtensionAPI) { const dataCount = dataAll.count(); dataAll.each(rawIdx => { const idx = idxMap[rawIdx]; - const itemStyle = data.ensureUniqueItemVisual(idx, 'style'); const name = dataAll.getName(rawIdx) || (rawIdx + ''); const paletteDecal = getDecalFromPalette( seriesModel.ecModel, @@ -113,26 +112,29 @@ export default function (ecModel: GlobalModel, api: ExtensionAPI) { decalScope, dataCount ); - const decal = zrUtil.defaults( - itemStyle.decal || {}, - paletteDecal - ); - data.setItemVisual(idx, 'decal', decal); + const specifiedDecal = data.getItemVisual(idx, 'decal'); + data.setItemVisual(idx, 'decal', mergeDecal(specifiedDecal, paletteDecal)); }); } else { - const style = data.getVisual('style'); const paletteDecal = getDecalFromPalette( seriesModel.ecModel, seriesModel.name, decalPaletteScope, ecModel.getSeriesCount() ); - const decal = style.decal - ? zrUtil.defaults(style.decal, paletteDecal) + const specifiedDecal = data.getVisual('decal'); + data.setVisual('decal', mergeDecal(specifiedDecal, paletteDecal)); + } + + function mergeDecal(specifiedDecal: DecalObject, paletteDecal: DecalObject): DecalObject { + // Merge decal from palette to decal from itemStyle. + // User do not need to specify all of the decal props. + const resultDecal = specifiedDecal + ? zrUtil.extend(zrUtil.extend({}, paletteDecal), specifiedDecal) : paletteDecal; - (decal as InnerDecalObject).dirty = true; - data.setVisual('decal', decal); + (resultDecal as InnerDecalObject).dirty = true; + return resultDecal; } }); } diff --git a/src/visual/style.ts b/src/visual/style.ts index aaa866d..e8c6832 100644 --- a/src/visual/style.ts +++ b/src/visual/style.ts @@ -90,6 +90,9 @@ const seriesStyleTask: StageHandler = { const colorCallback = isFunction(color) ? color as unknown as ColorCallback : null; // Get from color palette by default. if (!globalStyle[colorKey] || colorCallback) { + // Note: if some series has color specified (e.g., by itemStyle.color), we DO NOT + // make it effect palette. Bacause some scenarios users need to make some series + // transparent or as background, which should better not effect the palette. globalStyle[colorKey] = seriesModel.getColorFromPalette( // TODO series count changed. seriesModel.name, null, ecModel.getSeriesCount() diff --git a/test/decal.html b/test/decal.html index da1d9b6..bb449a2 100644 --- a/test/decal.html +++ b/test/decal.html @@ -175,7 +175,7 @@ under the License. title: [ 'It should use decal when aria.show is true', '(1) Each bar and pie piece should have different decal', - '(2) The first bar and pie piece decal should be blue' + '(2) The first bar and pie piece decal should be **blue**' ], option: option // height: 300, @@ -245,7 +245,7 @@ under the License. var chart = testHelper.create(echarts, 'main1', { title: [ 'If aria is not enabled, decal can also be enabled', - '(1) Only the first bar and pie piece should use decal', + '(1) Only the first bar and pie piece should use decal (be **blue**)', '(2) `aria.label` should be in the HTML' ], option: option --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
