From d140ddc77b96569b894a405ed676495e849d9178 Mon Sep 17 00:00:00 2001 From: lang Date: Sun, 1 Nov 2015 16:46:55 +0800 Subject: [PATCH] Graph legend selectable --- src/chart/graph/GraphView.js | 5 ++++- src/chart/helper/LineDraw.js | 9 ++++++--- src/chart/helper/SymbolDraw.js | 10 +++++----- src/chart/line/LineView.js | 23 ++++++++++------------- src/data/helper/linkList.js | 2 +- src/util/graphic.js | 4 ++-- 6 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/chart/graph/GraphView.js b/src/chart/graph/GraphView.js index 2304c92cd..46b3b5ab2 100644 --- a/src/chart/graph/GraphView.js +++ b/src/chart/graph/GraphView.js @@ -41,7 +41,10 @@ define(function (require) { lineDraw.updateData( data.graph.edgeData, - seriesModel, api, false + seriesModel, api, false, + function (idx) { + return data.graph.edges[idx].dataIndex >= 0; + } ); // Save the original lineWidth diff --git a/src/chart/helper/LineDraw.js b/src/chart/helper/LineDraw.js index dbe1d60a0..ed57884dd 100644 --- a/src/chart/helper/LineDraw.js +++ b/src/chart/helper/LineDraw.js @@ -13,15 +13,18 @@ define(function (require) { * @param {module:echarts/model/Series} seriesModel * @param {module:echarts/ExtensionAPI} api * @param {boolean} [enableAnimation=false] + * @param {Function} [isIgnore] */ - lineDrawProto.updateData = function (data, seriesModel, api, enableAnimation) { + lineDrawProto.updateData = function ( + data, seriesModel, api, enableAnimation, isIgnore + ) { var group = this.group; var oldData = this._data; data.diff(oldData) .add(function (idx) { var shape = data.getItemLayout(idx); - if (shape) { + if (!(isIgnore && isIgnore[idx])) { var line = new graphic[shape.cpx1 != null ? 'BezierCurve' : 'Line']({ shape: shape }); @@ -33,7 +36,7 @@ define(function (require) { .update(function (newIdx, oldIdx) { var line = oldData.getItemGraphicEl(oldIdx); var shape = data.getItemLayout(newIdx); - if (!shape) { + if (!(isIgnore && isIgnore(newIdx))) { group.remove(line); return; } diff --git a/src/chart/helper/SymbolDraw.js b/src/chart/helper/SymbolDraw.js index 55f0c860a..757990832 100644 --- a/src/chart/helper/SymbolDraw.js +++ b/src/chart/helper/SymbolDraw.js @@ -65,10 +65,10 @@ define(function (require) { * @param {module:echarts/model/Series} seriesModel * @param {module:echarts/ExtensionAPI} api * @param {boolean} [enableAnimation=false] - * @param {Array.} [ignoreMap] + * @param {Array.} [isIgnore] */ symbolProto.updateData = function ( - data, seriesModel, api, enableAnimation, ignoreMap + data, seriesModel, api, enableAnimation, isIgnore ) { var group = this.group; @@ -76,7 +76,7 @@ define(function (require) { data.diff(oldData) .add(function (newIdx) { - if (data.hasValue(newIdx) && !(ignoreMap && ignoreMap[newIdx])) { + if (data.hasValue(newIdx) && !(isIgnore && isIgnore(newIdx))) { var symbolEl = createSymbol(data, newIdx, enableAnimation); if (symbolEl) { @@ -88,7 +88,7 @@ define(function (require) { .update(function (newIdx, oldIdx) { var el = oldData.getItemGraphicEl(oldIdx); // Empty data - if (!data.hasValue(newIdx) || (ignoreMap && ignoreMap[newIdx])) { + if (!data.hasValue(newIdx) || (isIgnore && isIgnore(newIdx))) { group.remove(el); return; } @@ -102,7 +102,7 @@ define(function (require) { // Symbol changed if ( oldData.getItemVisual(oldIdx, 'symbol') !== symbolType - || (!el && !(ignoreMap && ignoreMap[newIdx])) + || (!el && !(isIgnore && isIgnore(newIdx))) ) { // Remove the old one el && group.remove(el); diff --git a/src/chart/line/LineView.js b/src/chart/line/LineView.js index 73b84cc2a..a27fc07b5 100644 --- a/src/chart/line/LineView.js +++ b/src/chart/line/LineView.js @@ -110,8 +110,8 @@ define(function(require) { var stackedOnPoints = getStackedOnPoints(coordSys, data); - var symbolIgnoreMap = !isCoordSysPolar && !seriesModel.get('showAllSymbol') - && this._getSymbolIgnored(data, coordSys); + var isSymbolIgnore = !isCoordSysPolar && !seriesModel.get('showAllSymbol') + && this._getSymbolIgnoreFunc(data, coordSys); // Initialization animation or coordinate system changed if ( @@ -120,7 +120,7 @@ define(function(require) { && hasAnimation) ) { symbolDraw.updateData( - data, seriesModel, api, hasAnimation, symbolIgnoreMap + data, seriesModel, api, hasAnimation, isSymbolIgnore ); polyline = this._newPolyline(group, points, coordSys, hasAnimation); @@ -135,7 +135,7 @@ define(function(require) { else { symbolDraw.updateData( - data, seriesModel, api, false, symbolIgnoreMap + data, seriesModel, api, false, isSymbolIgnore ); // Update clipPath @@ -281,20 +281,17 @@ define(function(require) { /** * @private */ - _getSymbolIgnored: function (data, coordSys) { + _getSymbolIgnoreFunc: function (data, coordSys) { var categoryAxis = coordSys.getAxesByScale('ordinal')[0]; - var ignoreMap; // `getLabelInterval` is provided by echarts/component/axis if (categoryAxis && categoryAxis.getLabelInterval) { - ignoreMap = []; var labelInterval = categoryAxis.getLabelInterval(); - data.each(function (idx) { - ignoreMap[idx] = (typeof labelInterval === 'function') - && !labelInterval(idx, categoryAxis.scale.getItem(idx)) - || idx % (labelInterval + 1); - }); + return function (idx) { + return (typeof labelInterval === 'function') + && !labelInterval(idx, categoryAxis.scale.getItem(idx)) + || idx % (labelInterval + 1); + }; } - return ignoreMap; }, /** diff --git a/src/data/helper/linkList.js b/src/data/helper/linkList.js index 7055a7cac..8022b7b72 100644 --- a/src/data/helper/linkList.js +++ b/src/data/helper/linkList.js @@ -42,5 +42,5 @@ define(function (require) { linkToTree: function (list, tree) { linkList(list, tree, 'tree'); } - } + }; }); \ No newline at end of file diff --git a/src/util/graphic.js b/src/util/graphic.js index 9cdd50434..2367efa84 100644 --- a/src/util/graphic.js +++ b/src/util/graphic.js @@ -159,7 +159,7 @@ define(function(require) { function doSingleEnterHover(el) { if (el.__isHover) { return; - }; + } if (el.__hoverStlDirty) { var stroke = el.style.stroke; var fill = el.style.fill; @@ -266,7 +266,7 @@ define(function(require) { /** * Set hover style of element - * @param {module:zrender/graphic/Displayable} el + * @param {module:zrender/Element} el * @param {Object} [hoverStyle] */ graphic.setHoverStyle = function (el, hoverStyle) { -- GitLab