Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sankey): avoid throwing errors when the links / nodes / levels option is undefined #20380

Merged
merged 5 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.