-
Notifications
You must be signed in to change notification settings - Fork 19.8k
Closed
Labels
bugdifficulty: easyIssues that can be fixed more easily than the average.Issues that can be fixed more easily than the average.enThis issue is in EnglishThis issue is in Englishtypescript
Description
Version
5.5.0
Link to Minimal Reproduction
Steps to Reproduce
If your sankey diagram options doesn't contain data and links attribute the return of the getInitialData will be undefined and so the wrapData function will throw an error.
Current Behavior
If you set data and links in a sankey diagram to undefined you will get an error:
TypeError: Cannot read properties of undefined (reading 'CHANGABLE_METHODS')
at wrapData (Series.js:512:39)
at SeriesModel2.mergeOption (Series.js:145:5)
at GlobalModel2.<anonymous> (Global.js:321:28)
at Array.forEach (<anonymous>)
at each (util.js:171:9)
at GlobalModel2.visitComponent (Global.js:272:7)
at entity.topologicalTravel (component.js:109:18)
at GlobalModel2._mergeOption (Global.js:251:20)
at GlobalModel2._resetOption (Global.js:181:14)
at GlobalModel2.setOption (Global.js:157:10)
This error is the result of the getInitialData function in the SankeySeries.ts file at line 175.
/**
* 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;
this.levelModels = [];
const levelModels = this.levelModels;
for (let i = 0; i < levels.length; i++) {
if (levels[i].depth != null && levels[i].depth >= 0) {
levelModels[levels[i].depth] = new Model(levels[i], this, ecModel);
}
else {
if (__DEV__) {
throw new Error('levels[i].depth is mandatory and should be natural number');
}
}
}
if (nodes && links) { // => no return of the data object, when there are links or nodes undefined or null
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;
const layout = seriesModel.getData().getItemLayout(idx);
if (layout) {
const nodeDepth = layout.depth;
const levelModel = seriesModel.levelModels[nodeDepth];
if (levelModel) {
model.parentModel = levelModel;
}
}
return model;
});
edgeData.wrapMethod('getItemModel', function (model: Model, idx: number) {
const seriesModel = model.parentModel as SankeySeriesModel;
const edge = seriesModel.getGraph().getEdgeByIndex(idx);
const layout = edge.node1.getLayout();
if (layout) {
const depth = layout.depth;
const levelModel = seriesModel.levelModels[depth];
if (levelModel) {
model.parentModel = levelModel;
}
}
return model;
});
}
}Expected Behavior
There should be no error, because in the interface definition data and links can be undefined.
Environment
- OS: Windows 10
- Browser: Chrome
- Framework: AngularAny additional comments?
No response
Metadata
Metadata
Assignees
Labels
bugdifficulty: easyIssues that can be fixed more easily than the average.Issues that can be fixed more easily than the average.enThis issue is in EnglishThis issue is in Englishtypescript