This is an automated email from the ASF dual-hosted git repository. deqingli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
The following commit(s) were added to refs/heads/master by this push: new 3a2ed94 resolve the error when the data and links in sankey graph is empty 3a2ed94 is described below commit 3a2ed94b8128ff16856cd33a4597b6ca8ec5bdc0 Author: deqingli <annong...@gmail.com> AuthorDate: Wed Apr 11 20:43:10 2018 +0800 resolve the error when the data and links in sankey graph is empty --- src/chart/sankey/sankeyVisual.js | 50 ++++++++++++++++++++-------------------- test/sankey-test.html | 1 + 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/chart/sankey/sankeyVisual.js b/src/chart/sankey/sankeyVisual.js index 0b6faef..5462658 100644 --- a/src/chart/sankey/sankeyVisual.js +++ b/src/chart/sankey/sankeyVisual.js @@ -10,31 +10,31 @@ export default function (ecModel, payload) { ecModel.eachSeriesByType('sankey', function (seriesModel) { var graph = seriesModel.getGraph(); var nodes = graph.nodes; - - nodes.sort(function (a, b) { - return a.getLayout().value - b.getLayout().value; - }); - - var minValue = nodes[0].getLayout().value; - var maxValue = nodes[nodes.length - 1].getLayout().value; - - zrUtil.each(nodes, function (node) { - var mapping = new VisualMapping({ - type: 'color', - mappingMethod: 'linear', - dataExtent: [minValue, maxValue], - visual: seriesModel.get('color') + if (nodes.length) { + nodes.sort(function (a, b) { + return a.getLayout().value - b.getLayout().value; }); - - var mapValueToColor = mapping.mapValueToVisual(node.getLayout().value); - node.setVisual('color', mapValueToColor); - // If set itemStyle.normal.color - var itemModel = node.getModel(); - var customColor = itemModel.get('itemStyle.color'); - if (customColor != null) { - node.setVisual('color', customColor); - } - }); - + + var minValue = nodes[0].getLayout().value; + var maxValue = nodes[nodes.length - 1].getLayout().value; + + zrUtil.each(nodes, function (node) { + var mapping = new VisualMapping({ + type: 'color', + mappingMethod: 'linear', + dataExtent: [minValue, maxValue], + visual: seriesModel.get('color') + }); + + var mapValueToColor = mapping.mapValueToVisual(node.getLayout().value); + node.setVisual('color', mapValueToColor); + // If set itemStyle.normal.color + var itemModel = node.getModel(); + var customColor = itemModel.get('itemStyle.color'); + if (customColor != null) { + node.setVisual('color', customColor); + } + }); + } }); } \ No newline at end of file diff --git a/test/sankey-test.html b/test/sankey-test.html index 0366c71..3ecdaa7 100644 --- a/test/sankey-test.html +++ b/test/sankey-test.html @@ -168,6 +168,7 @@ layout:'none', data: testData.nodes, links: testData.links, + // Used to test when the data is null whether it is work well. // data: [], // links: [], lineStyle: { -- To stop receiving notification emails like this one, please contact deqin...@apache.org. --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org