From b2897aca005a3c9a886c82ed226b249150705152 Mon Sep 17 00:00:00 2001 From: jiawulin001 Date: Thu, 21 Apr 2022 11:45:20 +0800 Subject: [PATCH 1/9] Add 'decal' to ITEM_STYLE_KEY_MAP and add check if it is 'none' --- src/component/legend/LegendView.ts | 4 +++- src/model/mixin/itemStyle.ts | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/component/legend/LegendView.ts b/src/component/legend/LegendView.ts index 69df98221c..453210e7bc 100644 --- a/src/component/legend/LegendView.ts +++ b/src/component/legend/LegendView.ts @@ -565,7 +565,9 @@ function getLegendStyle( const itemStyle = legendItemModel.getItemStyle(); const iconBrushType = iconType.lastIndexOf('empty', 0) === 0 ? 'fill' : 'stroke'; - itemStyle.decal = itemVisualStyle.decal; + if (itemStyle.decal !== 'none') { + itemStyle.decal = itemVisualStyle.decal; + } if (itemStyle.fill === 'inherit') { /** * Series with visualDrawType as 'stroke' should have diff --git a/src/model/mixin/itemStyle.ts b/src/model/mixin/itemStyle.ts index 950bf39034..fe250181f2 100644 --- a/src/model/mixin/itemStyle.ts +++ b/src/model/mixin/itemStyle.ts @@ -35,7 +35,8 @@ export const ITEM_STYLE_KEY_MAP = [ ['lineDashOffset', 'borderDashOffset'], ['lineCap', 'borderCap'], ['lineJoin', 'borderJoin'], - ['miterLimit', 'borderMiterLimit'] + ['miterLimit', 'borderMiterLimit'], + ['decal'] // Option decal is in `DecalObject` but style.decal is in `PatternObject`. // So do not transfer decal directly. ]; From 11e37cc68ef41767509c1a4a08438537cc6e4998 Mon Sep 17 00:00:00 2001 From: jiawulin001 Date: Thu, 21 Apr 2022 15:26:30 +0800 Subject: [PATCH 2/9] Update legend decal style dealer --- src/component/legend/LegendView.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/component/legend/LegendView.ts b/src/component/legend/LegendView.ts index 453210e7bc..210b648ded 100644 --- a/src/component/legend/LegendView.ts +++ b/src/component/legend/LegendView.ts @@ -49,6 +49,7 @@ import Model from '../../model/Model'; import {LineStyleProps} from '../../model/mixin/lineStyle'; import {createSymbol, ECSymbol} from '../../util/symbol'; import SeriesModel from '../../model/Series'; +import { createOrUpdatePatternFromDecal } from '../../util/decal'; const curry = zrUtil.curry; const each = zrUtil.each; @@ -564,10 +565,14 @@ function getLegendStyle( const legendItemModel = legendModel.getModel('itemStyle') as Model; const itemStyle = legendItemModel.getItemStyle(); const iconBrushType = iconType.lastIndexOf('empty', 0) === 0 ? 'fill' : 'stroke'; - - if (itemStyle.decal !== 'none') { + const decalStyle = legendItemModel.getShallow('decal', false); + if (decalStyle === 'inherit') { itemStyle.decal = itemVisualStyle.decal; + } + else { + itemStyle.decal = createOrUpdatePatternFromDecal(decalStyle, legendItemModel.ecModel.scheduler.api); } + if (itemStyle.fill === 'inherit') { /** * Series with visualDrawType as 'stroke' should have From ec1db268f325e7adaea879359854039528a5dc22 Mon Sep 17 00:00:00 2001 From: jiawulin001 Date: Thu, 21 Apr 2022 15:35:07 +0800 Subject: [PATCH 3/9] fix lint error --- src/component/legend/LegendView.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/component/legend/LegendView.ts b/src/component/legend/LegendView.ts index 210b648ded..e6921118eb 100644 --- a/src/component/legend/LegendView.ts +++ b/src/component/legend/LegendView.ts @@ -566,13 +566,13 @@ function getLegendStyle( const itemStyle = legendItemModel.getItemStyle(); const iconBrushType = iconType.lastIndexOf('empty', 0) === 0 ? 'fill' : 'stroke'; const decalStyle = legendItemModel.getShallow('decal', false); - if (decalStyle === 'inherit') { + if (!decalStyle || decalStyle === 'inherit') { itemStyle.decal = itemVisualStyle.decal; - } + } else { itemStyle.decal = createOrUpdatePatternFromDecal(decalStyle, legendItemModel.ecModel.scheduler.api); } - + if (itemStyle.fill === 'inherit') { /** * Series with visualDrawType as 'stroke' should have From 94856a961721dc01a81bbfab16fdd822e495b595 Mon Sep 17 00:00:00 2001 From: jiawulin001 Date: Thu, 21 Apr 2022 15:54:16 +0800 Subject: [PATCH 4/9] added passed down api for functions in legendView --- src/component/legend/LegendView.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/component/legend/LegendView.ts b/src/component/legend/LegendView.ts index e6921118eb..ef534dd1c6 100644 --- a/src/component/legend/LegendView.ts +++ b/src/component/legend/LegendView.ts @@ -218,7 +218,7 @@ class LegendView extends ComponentView { const itemGroup = this._createItem( seriesModel, name, dataIndex, legendItemModel, legendModel, itemAlign, - lineVisualStyle, style, legendIcon, selectMode + lineVisualStyle, style, legendIcon, selectMode, api ); itemGroup.on('click', curry(dispatchSelectAction, name, null, api, excludeSeriesId)) @@ -259,7 +259,7 @@ class LegendView extends ComponentView { const itemGroup = this._createItem( seriesModel, name, dataIndex, legendItemModel, legendModel, itemAlign, - {}, style, legendIcon, selectMode + {}, style, legendIcon, selectMode, api ); // FIXME: consider different series has items with the same name. @@ -340,7 +340,8 @@ class LegendView extends ComponentView { lineVisualStyle: LineStyleProps, itemVisualStyle: PathStyleProps, legendIcon: string, - selectMode: LegendOption['selectedMode'] + selectMode: LegendOption['selectedMode'], + api: ExtensionAPI ) { const drawType = seriesModel.visualDrawType; const itemWidth = legendModel.get('itemWidth'); @@ -359,7 +360,8 @@ class LegendView extends ComponentView { lineVisualStyle, itemVisualStyle, drawType, - isSelected + isSelected, + api ); const itemGroup = new Group(); @@ -544,7 +546,8 @@ function getLegendStyle( lineVisualStyle: PathStyleProps, itemVisualStyle: PathStyleProps, drawType: 'fill' | 'stroke', - isSelected: boolean + isSelected: boolean, + api: ExtensionAPI ) { /** * Use series style if is inherit; @@ -570,7 +573,7 @@ function getLegendStyle( itemStyle.decal = itemVisualStyle.decal; } else { - itemStyle.decal = createOrUpdatePatternFromDecal(decalStyle, legendItemModel.ecModel.scheduler.api); + itemStyle.decal = createOrUpdatePatternFromDecal(decalStyle, api); } if (itemStyle.fill === 'inherit') { From 7c029eece63086a8a895c5f5c778711220fe1965 Mon Sep 17 00:00:00 2001 From: jiawulin001 Date: Thu, 21 Apr 2022 15:56:46 +0800 Subject: [PATCH 5/9] remove decal from ITEM_STYLE_KEY_MAP --- src/model/mixin/itemStyle.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/model/mixin/itemStyle.ts b/src/model/mixin/itemStyle.ts index fe250181f2..950bf39034 100644 --- a/src/model/mixin/itemStyle.ts +++ b/src/model/mixin/itemStyle.ts @@ -35,8 +35,7 @@ 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. ]; From 66d064ca080b64c0b9ce130b2fac45d8ea67afb2 Mon Sep 17 00:00:00 2001 From: jiawulin001 Date: Thu, 21 Apr 2022 16:10:39 +0800 Subject: [PATCH 6/9] Update with ternary expression --- src/component/legend/LegendView.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/component/legend/LegendView.ts b/src/component/legend/LegendView.ts index ef534dd1c6..53e44a84e6 100644 --- a/src/component/legend/LegendView.ts +++ b/src/component/legend/LegendView.ts @@ -569,12 +569,9 @@ function getLegendStyle( const itemStyle = legendItemModel.getItemStyle(); const iconBrushType = iconType.lastIndexOf('empty', 0) === 0 ? 'fill' : 'stroke'; const decalStyle = legendItemModel.getShallow('decal', false); - if (!decalStyle || decalStyle === 'inherit') { - itemStyle.decal = itemVisualStyle.decal; - } - else { - itemStyle.decal = createOrUpdatePatternFromDecal(decalStyle, api); - } + itemStyle.decal = (!decalStyle || decalStyle === 'inherit') + ? itemVisualStyle.decal + : createOrUpdatePatternFromDecal(decalStyle, api) if (itemStyle.fill === 'inherit') { /** From 6626f488c38e6f10cfdc646bd1ab2266a5ab4f61 Mon Sep 17 00:00:00 2001 From: jiawulin001 Date: Thu, 21 Apr 2022 16:14:43 +0800 Subject: [PATCH 7/9] fix lint errors --- src/component/legend/LegendView.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/component/legend/LegendView.ts b/src/component/legend/LegendView.ts index 53e44a84e6..48478d5d5f 100644 --- a/src/component/legend/LegendView.ts +++ b/src/component/legend/LegendView.ts @@ -569,9 +569,9 @@ function getLegendStyle( const itemStyle = legendItemModel.getItemStyle(); const iconBrushType = iconType.lastIndexOf('empty', 0) === 0 ? 'fill' : 'stroke'; const decalStyle = legendItemModel.getShallow('decal', false); - itemStyle.decal = (!decalStyle || decalStyle === 'inherit') + itemStyle.decal = (!decalStyle || decalStyle === 'inherit') ? itemVisualStyle.decal - : createOrUpdatePatternFromDecal(decalStyle, api) + : createOrUpdatePatternFromDecal(decalStyle, api); if (itemStyle.fill === 'inherit') { /** From a956d3e7ebc652a7fe0f3f4d90f5bfc8cde64436 Mon Sep 17 00:00:00 2001 From: jiawulin001 Date: Fri, 22 Apr 2022 11:40:40 +0800 Subject: [PATCH 8/9] fix: fix names legendItemModel->itemStyleModel, legendModel->legendItemModel --- src/component/legend/LegendView.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/component/legend/LegendView.ts b/src/component/legend/LegendView.ts index 48478d5d5f..481cb6b90c 100644 --- a/src/component/legend/LegendView.ts +++ b/src/component/legend/LegendView.ts @@ -542,7 +542,7 @@ class LegendView extends ComponentView { function getLegendStyle( iconType: string, - legendModel: LegendModel['_data'][number], + legendItemModel: LegendModel['_data'][number], lineVisualStyle: PathStyleProps, itemVisualStyle: PathStyleProps, drawType: 'fill' | 'stroke', @@ -565,10 +565,10 @@ function getLegendStyle( } // itemStyle - const legendItemModel = legendModel.getModel('itemStyle') as Model; - const itemStyle = legendItemModel.getItemStyle(); + const itemStyleModel = legendItemModel.getModel('itemStyle') as Model; + const itemStyle = itemStyleModel.getItemStyle(); const iconBrushType = iconType.lastIndexOf('empty', 0) === 0 ? 'fill' : 'stroke'; - const decalStyle = legendItemModel.getShallow('decal', false); + const decalStyle = itemStyleModel.getShallow('decal', false); itemStyle.decal = (!decalStyle || decalStyle === 'inherit') ? itemVisualStyle.decal : createOrUpdatePatternFromDecal(decalStyle, api); @@ -596,7 +596,7 @@ function getLegendStyle( handleCommonProps(itemStyle, itemVisualStyle); // lineStyle - const legendLineModel = legendModel.getModel('lineStyle') as Model; + const legendLineModel = legendItemModel.getModel('lineStyle') as Model; const lineStyle: LineStyleProps = legendLineModel.getLineStyle(); handleCommonProps(lineStyle, lineVisualStyle); @@ -606,7 +606,7 @@ function getLegendStyle( (lineStyle.stroke === 'auto') && (lineStyle.stroke = itemVisualStyle.fill); if (!isSelected) { - const borderWidth = legendModel.get('inactiveBorderWidth'); + const borderWidth = legendItemModel.get('inactiveBorderWidth'); /** * Since stroke is set to be inactiveBorderColor, it may occur that * there is no border in series but border in legend, so we need to @@ -616,8 +616,8 @@ function getLegendStyle( itemStyle.lineWidth = borderWidth === 'auto' ? (itemVisualStyle.lineWidth > 0 && visualHasBorder ? 2 : 0) : itemStyle.lineWidth; - itemStyle.fill = legendModel.get('inactiveColor'); - itemStyle.stroke = legendModel.get('inactiveBorderColor'); + itemStyle.fill = legendItemModel.get('inactiveColor'); + itemStyle.stroke = legendItemModel.get('inactiveBorderColor'); lineStyle.stroke = legendLineModel.get('inactiveColor'); lineStyle.lineWidth = legendLineModel.get('inactiveWidth'); } From e9d1f833af56b8faeaf32d01ac190cb8edc46434 Mon Sep 17 00:00:00 2001 From: jiawulin001 Date: Fri, 22 Apr 2022 11:48:24 +0800 Subject: [PATCH 9/9] fix: remove explicit input 'false'(default) from getShallow --- src/component/legend/LegendView.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/component/legend/LegendView.ts b/src/component/legend/LegendView.ts index 481cb6b90c..6e6c9ceb8c 100644 --- a/src/component/legend/LegendView.ts +++ b/src/component/legend/LegendView.ts @@ -568,7 +568,7 @@ function getLegendStyle( const itemStyleModel = legendItemModel.getModel('itemStyle') as Model; const itemStyle = itemStyleModel.getItemStyle(); const iconBrushType = iconType.lastIndexOf('empty', 0) === 0 ? 'fill' : 'stroke'; - const decalStyle = itemStyleModel.getShallow('decal', false); + const decalStyle = itemStyleModel.getShallow('decal'); itemStyle.decal = (!decalStyle || decalStyle === 'inherit') ? itemVisualStyle.decal : createOrUpdatePatternFromDecal(decalStyle, api);