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

Function circularLayout

src/chart/graph/circularLayoutHelper.ts:53–116  ·  view source on GitHub ↗
(
    seriesModel: GraphSeriesModel,
    basedOn: 'value' | 'symbolSize',
    draggingNode?: GraphNode,
    pointer?: [number, number]
)

Source from the content-addressed store, hash-verified

51 * probably we have to use `basedOn: 'value'`.
52 */
53export function circularLayout(
54 seriesModel: GraphSeriesModel,
55 basedOn: 'value' | 'symbolSize',
56 draggingNode?: GraphNode,
57 pointer?: [number, number]
58) {
59 const coordSys = seriesModel.coordinateSystem;
60 if (coordSys && coordSys.type !== 'view') {
61 return;
62 }
63
64 const rect = coordSys.getBoundingRect();
65
66 const nodeData = seriesModel.getData();
67 const graph = nodeData.graph;
68
69 const cx = rect.width / 2 + rect.x;
70 const cy = rect.height / 2 + rect.y;
71 const r = Math.min(rect.width, rect.height) / 2;
72 const count = nodeData.count();
73
74 nodeData.setLayout({
75 cx: cx,
76 cy: cy
77 });
78
79 if (!count) {
80 return;
81 }
82
83 if (draggingNode) {
84 const [tempX, tempY] = coordSys.pointToData(pointer) as [number, number];
85 const v = [tempX - cx, tempY - cy];
86 vec2.normalize(v, v);
87 vec2.scale(v, v, r);
88 draggingNode.setLayout([cx + v[0], cy + v[1]], true);
89
90 const circularRotateLabel = seriesModel.get(['circular', 'rotateLabel']);
91 rotateNodeLabel(draggingNode, circularRotateLabel, cx, cy);
92 }
93
94 _layoutNodesBasedOn[basedOn](seriesModel, graph, nodeData, r, cx, cy, count);
95
96 graph.eachEdge(function (edge, index) {
97 let curveness = zrUtil.retrieve3(
98 edge.getModel<GraphEdgeItemOption>().get(['lineStyle', 'curveness']),
99 getCurvenessForEdge(edge, seriesModel, index),
100 0
101 );
102 const p1 = vec2.clone(edge.node1.getLayout());
103 const p2 = vec2.clone(edge.node2.getLayout());
104 let cp1;
105 const x12 = (p1[0] + p2[0]) / 2;
106 const y12 = (p1[1] + p2[1]) / 2;
107 if (+curveness) {
108 curveness *= 3;
109 cp1 = [
110 cx * curveness + x12 * (1 - curveness),

Callers 3

graphForceLayoutFunction · 0.90
graphCircularLayoutFunction · 0.90
renderMethod · 0.90

Calls 14

getCurvenessForEdgeFunction · 0.90
rotateNodeLabelFunction · 0.85
eachEdgeMethod · 0.80
getDataMethod · 0.65
countMethod · 0.65
setLayoutMethod · 0.65
pointToDataMethod · 0.65
getLayoutMethod · 0.65
getBoundingRectMethod · 0.45
normalizeMethod · 0.45
scaleMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…