From af72d75bbd5611ec24a3b764a559ca8a50dccbf2 Mon Sep 17 00:00:00 2001 From: sz-p Date: Sat, 28 Sep 2024 16:44:14 +0800 Subject: [PATCH 1/5] fix: #20336 sankey getInitialData function catch undefined data and edges --- src/chart/sankey/SankeySeries.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chart/sankey/SankeySeries.ts b/src/chart/sankey/SankeySeries.ts index 9dca447cad..aa569aba9a 100644 --- a/src/chart/sankey/SankeySeries.ts +++ b/src/chart/sankey/SankeySeries.ts @@ -156,8 +156,8 @@ class SankeySeriesModel extends SeriesModel { * Init a graph data structure from data in option series */ getInitialData(option: SankeySeriesOption, ecModel: GlobalModel) { - const links = option.edges || option.links; - const nodes = option.data || option.nodes; + const links = option.edges || option.links || []; + const nodes = option.data || option.nodes || []; const levels = option.levels; this.levelModels = []; const levelModels = this.levelModels; From 5b0a153ffe13203e28c8b9e99af3ae6389b0adf4 Mon Sep 17 00:00:00 2001 From: sz-p Date: Sat, 28 Sep 2024 17:00:13 +0800 Subject: [PATCH 2/5] test: #20336 sankey getInitialData function catch undefined data and edges --- test/sankey.html | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/test/sankey.html b/test/sankey.html index f9e16bd30e..888d1daed7 100644 --- a/test/sankey.html +++ b/test/sankey.html @@ -38,6 +38,7 @@
+
@@ -168,7 +169,7 @@ title: 'emphasis trajectory', option: option }); - + if (chart) { window.onresize = function () { chart.resize(); @@ -180,5 +181,31 @@ }); + + - \ No newline at end of file + From 9593e0f82699b2020b9754c739a0825f3185c960 Mon Sep 17 00:00:00 2001 From: plainheart Date: Sun, 29 Sep 2024 10:20:04 +0800 Subject: [PATCH 3/5] test(sankey): fix test case --- test/sankey.html | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/test/sankey.html b/test/sankey.html index 888d1daed7..558dc4af37 100644 --- a/test/sankey.html +++ b/test/sankey.html @@ -80,9 +80,8 @@ }); if (chart) { - window.onresize = function () { - chart.resize(); - }; + window.addEventListener('resize', chart.resize); + chart.on('click', function (params) { console.log(params, params.data); }); @@ -132,9 +131,8 @@ if (chart) { - window.onresize = function () { - chart.resize(); - }; + window.addEventListener('resize', chart.resize); + chart.on('click', function (params) { console.log(params, params.data); }); @@ -171,9 +169,8 @@ }); if (chart) { - window.onresize = function () { - chart.resize(); - }; + window.addEventListener('resize', chart.resize); + chart.on('click', function (params) { console.log(params, params.data); }); @@ -191,7 +188,8 @@ type: 'sankey', layout: 'none', data: undefined, - links: undefined + links: undefined, + levels: undefined }] } @@ -200,9 +198,7 @@ option: option }); if (chart) { - window.onresize = function () { - chart.resize(); - }; + window.addEventListener('resize', chart.resize); } }); From 3f03c76c095afb0f58da1767bda9ead27e93e5e9 Mon Sep 17 00:00:00 2001 From: plainheart Date: Sun, 29 Sep 2024 10:21:17 +0800 Subject: [PATCH 4/5] fix(sankey): also allow the `levels` option to be `undefined` --- src/chart/sankey/SankeySeries.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/chart/sankey/SankeySeries.ts b/src/chart/sankey/SankeySeries.ts index aa569aba9a..a91f907b27 100644 --- a/src/chart/sankey/SankeySeries.ts +++ b/src/chart/sankey/SankeySeries.ts @@ -158,7 +158,7 @@ class SankeySeriesModel extends SeriesModel { getInitialData(option: SankeySeriesOption, ecModel: GlobalModel) { const links = option.edges || option.links || []; const nodes = option.data || option.nodes || []; - const levels = option.levels; + const levels = option.levels || []; this.levelModels = []; const levelModels = this.levelModels; @@ -172,10 +172,10 @@ class SankeySeriesModel extends SeriesModel { } } } - if (nodes && links) { - const graph = createGraphFromNodeEdge(nodes, links, this, true, beforeLink); - return graph.data; - } + + const graph = createGraphFromNodeEdge(nodes, links, this, true, beforeLink); + return graph.data; + function beforeLink(nodeData: SeriesData, edgeData: SeriesData) { nodeData.wrapMethod('getItemModel', function (model: Model, idx: number) { const seriesModel = model.parentModel as SankeySeriesModel; From d60b241f34a59f61c8887a74b50ce34e4482e78a Mon Sep 17 00:00:00 2001 From: plainheart Date: Sun, 29 Sep 2024 10:30:32 +0800 Subject: [PATCH 5/5] test(sankey): tweak test case --- test/sankey.html | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/test/sankey.html b/test/sankey.html index 558dc4af37..7b6205d108 100644 --- a/test/sankey.html +++ b/test/sankey.html @@ -182,8 +182,16 @@ require([ 'echarts', ], function (echarts) { - + var title = 'The sankey chart should be rendered without any error in console when `**nodes**` or `**links**` is set as `**undefined**`'; var option = { + title: { + text: title, + top: 'center', + left: 'center', + textStyle: { + overflow: 'break' + } + }, series: [{ type: 'sankey', layout: 'none', @@ -194,12 +202,21 @@ } var chart = testHelper.create(echarts, 'main3', { - title: 'The sankey chart should be rendered without any error in console when `**nodes**` or `**links**` is set as `**undefined**`', - option: option + title, + option }); - if (chart) { - window.addEventListener('resize', chart.resize); - } + var resizeChart = function () { + chart.resize(); + chart.setOption({ + title: { + textStyle: { + width: chart.getWidth() * 0.8 + } + } + }); + }; + resizeChart(); + window.addEventListener('resize', resizeChart); });