MCPcopy
hub / github.com/apache/echarts / getInitialData

Method getInitialData

src/chart/graph/GraphSeries.ts:285–341  ·  view source on GitHub ↗
(option: GraphSeriesOption, ecModel: GlobalModel)

Source from the content-addressed store, hash-verified

283 }
284
285 getInitialData(option: GraphSeriesOption, ecModel: GlobalModel): SeriesData {
286 const edges = option.edges || option.links || [];
287 const nodes = option.data || option.nodes || [];
288 const self = this;
289
290 if (nodes && edges) {
291 // auto curveness
292 initCurvenessList(this);
293 const graph = createGraphFromNodeEdge(nodes as GraphNodeItemOption[], edges, this, true, beforeLink);
294 zrUtil.each(graph.edges, function (edge) {
295 createEdgeMapForCurveness(edge.node1, edge.node2, this, edge.dataIndex);
296 }, this);
297 return graph.data;
298 }
299
300 function beforeLink(nodeData: SeriesData, edgeData: SeriesData) {
301 // Overwrite nodeData.getItemModel to
302 nodeData.wrapMethod('getItemModel', function (model) {
303 const categoriesModels = self._categoriesModels;
304 const categoryIdx = model.getShallow('category');
305 const categoryModel = categoriesModels[categoryIdx];
306 if (categoryModel) {
307 categoryModel.parentModel = model.parentModel;
308 model.parentModel = categoryModel;
309 }
310 return model;
311 });
312
313 // TODO Inherit resolveParentPath by default in Model#getModel?
314 const oldGetModel = Model.prototype.getModel;
315 function newGetModel(this: Model, path: any, parentModel?: Model) {
316 const model = oldGetModel.call(this, path, parentModel);
317 model.resolveParentPath = resolveParentPath;
318 return model;
319 }
320
321 edgeData.wrapMethod('getItemModel', function (model: Model) {
322 model.resolveParentPath = resolveParentPath;
323 model.getModel = newGetModel;
324 return model;
325 });
326
327 function resolveParentPath(this: Model, pathArr: readonly string[]): string[] {
328 if (pathArr && (pathArr[0] === 'label' || pathArr[1] === 'label')) {
329 const newPathArr = pathArr.slice();
330 if (pathArr[0] === 'label') {
331 newPathArr[0] = 'edgeLabel';
332 }
333 else if (pathArr[1] === 'label') {
334 newPathArr[1] = 'edgeLabel';
335 }
336 return newPathArr;
337 }
338 return pathArr as string[];
339 }
340 }
341 }
342

Callers

nothing calls this directly

Calls 4

initCurvenessListFunction · 0.90
createGraphFromNodeEdgeFunction · 0.85
eachMethod · 0.45

Tested by

no test coverage detected