Skip to content

Commit

Permalink
Merge pull request #20380 from sz-p/fix-20336
Browse files Browse the repository at this point in the history
fix(sankey): avoid throwing errors when the `links` / `nodes` / `levels` option is undefined
  • Loading branch information
plainheart authored Sep 29, 2024
2 parents 38613d2 + d60b241 commit bb12cee
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 18 deletions.
14 changes: 7 additions & 7 deletions src/chart/sankey/SankeySeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ class SankeySeriesModel extends SeriesModel<SankeySeriesOption> {
* 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 levels = option.levels;
const links = option.edges || option.links || [];
const nodes = option.data || option.nodes || [];
const levels = option.levels || [];
this.levelModels = [];
const levelModels = this.levelModels;

Expand All @@ -172,10 +172,10 @@ class SankeySeriesModel extends SeriesModel<SankeySeriesOption> {
}
}
}
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;
Expand Down
62 changes: 51 additions & 11 deletions test/sankey.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bb12cee

Please sign in to comment.