You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2020/04/03 08:57:05 UTC

[incubator-echarts] branch next updated: fix: color palette for each data should not be shared by different types of series.

This is an automated email from the ASF dual-hosted git repository.

shenyi pushed a commit to branch next
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git


The following commit(s) were added to refs/heads/next by this push:
     new 708aeb5  fix: color palette for each data should not be shared by different types of series.
708aeb5 is described below

commit 708aeb5adc960760a628c4d69ca7551152ccb050
Author: pissang <bm...@gmail.com>
AuthorDate: Fri Apr 3 16:56:23 2020 +0800

    fix: color palette for each data should not be shared by different types of series.
---
 src/chart/candlestick/candlestickVisual.ts |   6 +-
 src/visual/style.ts                        | 100 +++++++++++++++++------------
 2 files changed, 64 insertions(+), 42 deletions(-)

diff --git a/src/chart/candlestick/candlestickVisual.ts b/src/chart/candlestick/candlestickVisual.ts
index 7e7ed5c..103f528 100644
--- a/src/chart/candlestick/candlestickVisual.ts
+++ b/src/chart/candlestick/candlestickVisual.ts
@@ -21,6 +21,7 @@ import createRenderPlanner from '../helper/createRenderPlanner';
 import { StageHandler } from '../../util/types';
 import CandlestickSeriesModel, { CandlestickDataItemOption } from './CandlestickSeries';
 import Model from '../../model/Model';
+import { extend } from 'zrender/src/core/util';
 
 const positiveBorderColorQuery = ['itemStyle', 'borderColor'] as const;
 const negativeBorderColorQuery = ['itemStyle', 'borderColor0'] as const;
@@ -67,9 +68,12 @@ const candlestickVisual: StageHandler = {
                     const itemModel = data.getItemModel(dataIndex);
                     const sign = data.getItemLayout(dataIndex).sign;
 
-                    const style = itemModel.getItemStyle(['color', 'borderColor']);
+                    const style = itemModel.getItemStyle();
                     style.fill = getColor(sign, itemModel);
                     style.stroke = getBorderColor(sign, itemModel) || style.fill;
+
+                    const existsStyle = data.ensureUniqueItemVisual(dataIndex, 'style');
+                    extend(existsStyle, style);
                 }
             }
         };
diff --git a/src/visual/style.ts b/src/visual/style.ts
index 8b77540..06dc192 100644
--- a/src/visual/style.ts
+++ b/src/visual/style.ts
@@ -17,17 +17,16 @@
 * under the License.
 */
 
-import { isFunction, extend } from 'zrender/src/core/util';
+import { isFunction, extend, createHashMap } from 'zrender/src/core/util';
 import { StageHandler, CallbackDataParams, ZRColor, Dictionary } from '../util/types';
 import makeStyleMapper from '../model/mixin/makeStyleMapper';
 import { ITEM_STYLE_KEY_MAP } from '../model/mixin/itemStyle';
 import { LINE_STYLE_KEY_MAP } from '../model/mixin/lineStyle';
 import SeriesModel from '../model/Series';
 import Model from '../model/Model';
+import { makeInner } from '../util/model';
 
-interface SeriesModelWithPaletteScope extends SeriesModel {
-    __paletteScope: any
-}
+const inner = makeInner<{scope: object}, SeriesModel>();
 
 const defaultStyleMappers = {
     itemStyle: makeStyleMapper(ITEM_STYLE_KEY_MAP, true),
@@ -118,7 +117,7 @@ const dataStyleTask: StageHandler = {
     createOnAllSeries: true,
     performRawSeries: true,
     reset(seriesModel, ecModel) {
-        if (seriesModel.ignoreStyleOnData) {
+        if (seriesModel.ignoreStyleOnData || ecModel.isSeriesFiltered(seriesModel)) {
             return;
         }
 
@@ -129,17 +128,15 @@ const dataStyleTask: StageHandler = {
         const getStyle = getStyleMapper(seriesModel, stylePath);
 
         return {
-            dataEach: (data.hasItemOption || seriesModel.useColorPaletteOnData) ? function (data, idx) {
+            dataEach: data.hasItemOption ? function (data, idx) {
                 // Not use getItemModel for performance considuration
-                if (data.hasItemOption) {
-                    const rawItem = data.getRawDataItem(idx) as any;
-                    if (rawItem && rawItem[stylePath]) {
-                        sharedModel.option = rawItem[stylePath];
-                        const style = getStyle(sharedModel);
-
-                        const existsStyle = data.ensureUniqueItemVisual(idx, 'style');
-                        extend(existsStyle, style);
-                    }
+                const rawItem = data.getRawDataItem(idx) as any;
+                if (rawItem && rawItem[stylePath]) {
+                    sharedModel.option = rawItem[stylePath];
+                    const style = getStyle(sharedModel);
+
+                    const existsStyle = data.ensureUniqueItemVisual(idx, 'style');
+                    extend(existsStyle, style);
                 }
             } : null
         };
@@ -149,35 +146,56 @@ const dataStyleTask: StageHandler = {
 const dataColorPaletteTask: StageHandler = {
     createOnAllSeries: true,
     performRawSeries: true,
-    reset(seriesModel, ecModel) {
-        if (seriesModel.ignoreStyleOnData) {
-            return;
-        }
-
-        const dataAll = seriesModel.getRawData();
-        const idxMap: Dictionary<number> = {};
-        const data = seriesModel.getData();
-
-        const stylePath = seriesModel.visualStyleAccessPath
-            || 'itemStyle';
-        const colorKey = getDefaultColorKey(seriesModel, stylePath);
-
-        data.each(function (idx) {
-            const rawIdx = data.getRawIndex(idx);
-            idxMap[rawIdx] = idx;
+    overallReset(ecModel) {
+        // Each type of series use one scope.
+        // Pie and funnel are using diferrent scopes
+        const paletteScopeGroupByType = createHashMap<object>();
+        ecModel.eachSeries(function (seriesModel) {
+            if (!seriesModel.useColorPaletteOnData) {
+                return;
+            }
+            let colorScope = paletteScopeGroupByType.get(seriesModel.type);
+            if (!colorScope) {
+                colorScope = {};
+                paletteScopeGroupByType.set(seriesModel.type, colorScope);
+            }
+            inner(seriesModel).scope = colorScope;
         });
 
-        dataAll.each(function (rawIdx) {
-            const idx = idxMap[rawIdx];
-            const existsStyle = data.ensureUniqueItemVisual(idx, 'style');
-            if (!existsStyle[colorKey]) {
-                // Get color from palette.
-                existsStyle[colorKey] = seriesModel.getColorFromPalette(
-                    dataAll.getName(rawIdx) || (rawIdx + ''),
-                    (seriesModel as SeriesModelWithPaletteScope).__paletteScope,
-                    dataAll.count()
-                );
+
+        ecModel.eachSeries(function (seriesModel) {
+            if (!seriesModel.useColorPaletteOnData || ecModel.isSeriesFiltered(seriesModel)) {
+                return;
             }
+
+            const dataAll = seriesModel.getRawData();
+            const idxMap: Dictionary<number> = {};
+            const data = seriesModel.getData();
+            const colorScope = inner(seriesModel).scope;
+
+            const stylePath = seriesModel.visualStyleAccessPath
+                || 'itemStyle';
+            const colorKey = getDefaultColorKey(seriesModel, stylePath);
+
+            data.each(function (idx) {
+                const rawIdx = data.getRawIndex(idx);
+                idxMap[rawIdx] = idx;
+            });
+
+            // Iterate on dat before filtered. To make sure color from palette can be
+            // Consistent when toggling legend.
+            dataAll.each(function (rawIdx) {
+                const idx = idxMap[rawIdx];
+                const existsStyle = data.ensureUniqueItemVisual(idx, 'style');
+                if (!existsStyle[colorKey]) {
+                    // Get color from palette.
+                    existsStyle[colorKey] = seriesModel.getColorFromPalette(
+                        dataAll.getName(rawIdx) || (rawIdx + ''),
+                        colorScope,
+                        dataAll.count()
+                    );
+                }
+            });
         });
     }
 };


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org