doLayout method
void
doLayout(
- Context context,
- Graph graph,
- num width,
- num height,
)
override
Implementation
@override
void doLayout(Context context, Graph graph, num width, num height) {
var nodes = graph.nodes;
int nodeCount = nodes.length;
if (nodeCount == 0) {
onLayoutEnd();
return;
}
Offset center = Offset(this.center[0].convert(width), this.center[1].convert(height));
if (nodeCount == 1) {
nodes[0].x = center.dx;
nodes[0].y = center.dy;
onLayoutEnd();
return;
}
List<num> radiusList = computeRadius(graph, width, height);
///计算角度的递增量
var angleStep = (endAngle - startAngle) / (nodeCount - 1);
///节点排序
List<GraphNode> layoutNodes = nodes;
sortNode(graph, layoutNodes);
for (int i = 0; i < nodeCount; ++i) {
num r = radiusList[0] + radiusList[2] * i;
num tmp = angleStep * i;
num angle = clockwise ? startAngle + tmp : endAngle - tmp;
Offset off = circlePoint(r, angle, center);
layoutNodes[i].x = off.dx;
layoutNodes[i].y = off.dy;
}
onLayoutEnd();
}