JuNe98 opened a new issue, #20336:
URL: https://github.com/apache/echarts/issues/20336

   ### Version
   
   5.5.0
   
   ### Link to Minimal Reproduction
   
   
https://echarts.apache.org/examples/en/editor.html?c=sankey-simple&code=PYBwLglsB2AEC8sDeAoWsDOBTAThLGAXMmurGAJ4hbEDkGAhtANZYW0A0p6ANgxcACuYOtBhZO3WFgC2IABYMMEIiTJkAZsADGg1bQYATAFYNtWaNvZSAvl3WGGYBsUHRDWDRGhZD9sjzezKoA2lLoqOrqGEI45nQMklFkzjgA5lgisAYAjEnJsABuDDyCNLAArOGwdtWRBTGCceUG-cmpGVkGAExtUcWl5QDM1bXJ9cmNzXQARn3qHZmzef7JA2XEAByjq2QTUVPx2Ym7CwzpS9kzK9Xo68M7dbeYsUe01_Mp550JNwVFJQ2sByj3Gz0OLQ-py-Fy62k-d0B5W6oykAF1SDYUDYANxAA
   
   ### 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.
   
   ```TypeScript
    /**
        * 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
   
   ```markdown
   - OS: Windows 10
   - Browser: Chrome
   - Framework: Angular
   ```
   
   
   ### Any additional comments?
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org
For additional commands, e-mail: commits-h...@echarts.apache.org

Reply via email to