MCPcopy Index your code
hub / github.com/apache/echarts / graphForceLayout

Function graphForceLayout

src/chart/graph/forceLayout.ts:40–169  ·  view source on GitHub ↗
(ecModel: GlobalModel)

Source from the content-addressed store, hash-verified

38export const graphForceLayoutStageHandler = createSimpleOverallStageHandler(SERIES_TYPE_GRAPH, graphForceLayout);
39
40function graphForceLayout(ecModel: GlobalModel) {
41 ecModel.eachSeriesByType(SERIES_TYPE_GRAPH, function (graphSeries: GraphSeriesModel) {
42 const coordSys = graphSeries.coordinateSystem;
43 if (coordSys && coordSys.type !== 'view') {
44 return;
45 }
46 if (graphSeries.get('layout') === 'force') {
47 const preservedPoints = graphSeries.preservedPoints || {};
48 const graph = graphSeries.getGraph();
49 const nodeData = graph.data;
50 const edgeData = graph.edgeData;
51 const forceModel = graphSeries.getModel('force');
52 const initLayout = forceModel.get('initLayout');
53 if (graphSeries.preservedPoints) {
54 nodeData.each(function (idx) {
55 const id = nodeData.getId(idx);
56 nodeData.setItemLayout(idx, preservedPoints[id] || [NaN, NaN]);
57 });
58 }
59 else if (!initLayout || initLayout === 'none') {
60 simpleLayout(graphSeries);
61 }
62 else if (initLayout === 'circular') {
63 circularLayout(graphSeries, 'value');
64 }
65
66 const nodeDataExtent = nodeData.getDataExtent('value');
67 const edgeDataExtent = edgeData.getDataExtent('value');
68 // let edgeDataExtent = edgeData.getDataExtent('value');
69 const repulsion = forceModel.get('repulsion');
70 const edgeLength = forceModel.get('edgeLength');
71 const repulsionArr = zrUtil.isArray(repulsion)
72 ? repulsion : [repulsion, repulsion];
73 let edgeLengthArr = zrUtil.isArray(edgeLength)
74 ? edgeLength : [edgeLength, edgeLength];
75
76 // Larger value has smaller length
77 edgeLengthArr = [edgeLengthArr[1], edgeLengthArr[0]];
78
79 const nodes = nodeData.mapArray('value', function (value: number, idx) {
80 const point = nodeData.getItemLayout(idx) as number[];
81 let rep = linearMap(value, nodeDataExtent, repulsionArr);
82 if (isNaN(rep)) {
83 rep = (repulsionArr[0] + repulsionArr[1]) / 2;
84 }
85 return {
86 w: rep,
87 rep: rep,
88 fixed: nodeData.getItemModel<GraphNodeItemOption>(idx).get('fixed'),
89 p: (!point || isNaN(point[0]) || isNaN(point[1])) ? null : point
90 };
91 });
92 const edges = edgeData.mapArray('value', function (value: number, idx) {
93 const edge = graph.getEdgeByIndex(idx);
94 let d = linearMap(value, edgeDataExtent, edgeLengthArr);
95 if (isNaN(d)) {
96 d = (edgeLengthArr[0] + edgeLengthArr[1]) / 2;
97 }

Callers

nothing calls this directly

Calls 15

simpleLayoutFunction · 0.90
circularLayoutFunction · 0.90
linearMapFunction · 0.90
getCurvenessForEdgeFunction · 0.90
forceLayoutFunction · 0.90
eachSeriesByTypeMethod · 0.80
setItemLayoutMethod · 0.80
mapArrayMethod · 0.80
getItemLayoutMethod · 0.80
getItemModelMethod · 0.80
getEdgeByIndexMethod · 0.80
getNodeByIndexMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…