100pah commented on a change in pull request #15405:
URL: https://github.com/apache/echarts/pull/15405#discussion_r709497973
##########
File path: src/chart/graph/simpleLayoutHelper.ts
##########
@@ -49,7 +69,80 @@ export function simpleLayoutEdge(graph: Graph, seriesModel:
GraphSeriesModel) {
const p1 = vec2.clone(edge.node1.getLayout());
const p2 = vec2.clone(edge.node2.getLayout());
const points = [p1, p2];
- if (+curveness) {
+ if (edge.node1 === edge.node2) {
+ const curve = getCurvenessForEdge(edge, seriesModel, index, true);
+ const curveness = curve >= 1 ? curve : 1 - curve;
+ const symbolSize = seriesModel.get('symbolSize');
+ const size = zrUtil.isArray(symbolSize) ? Number((symbolSize[0] +
symbolSize[1]) / 2) : Number(symbolSize);
+ const radius = getNodeGlobalScale(seriesModel) * size / 2 *
curveness;
+ const inEdges = edge.node1.inEdges.filter((edge) => {
+ return edge.node1 !== edge.node2;
+ });
+ const outEdges = edge.node1.outEdges.filter((edge) => {
+ return edge.node1 !== edge.node2;
+ });
+ const allNodes: GraphNode[] = [];
+ inEdges.forEach((edge) => {
+ allNodes.push(edge.node1);
+ });
+ outEdges.forEach((edge) => {
+ allNodes.push(edge.node2);
+ });
+ const vectors: any[][] = [];
+ let d = -Infinity;
+ let pt1: number[] = [];
+ let pt2: number[] = [];
+ if (allNodes.length > 1) {
+ allNodes.forEach(node => {
+ const v: any[] = [];
+ vec2.sub(v, node.getLayout(), edge.node1.getLayout());
+ vec2.normalize(v, v);
+ vectors.push(v);
+ });
+ // find the max angle
+ for (let i = 0; i < vectors.length; i++) {
+ for (let j = i + 1; j < vectors.length; j++) {
+ if (vec2.distSquare(vectors[i], vectors[j]) > d) {
+ d = vec2.distSquare(vectors[i], vectors[j]);
+ pt1 = vectors[i];
+ pt2 = vectors[j];
+ }
+ }
+ }
Review comment:
I think we need to find `the max angle of two adjacent edges` rather
than `the max angle of any two edges`.
The latter one probably make the self-loop edge intersect with some other
edge between the found edges.
<img width="442" alt="Screen Shot 2021-09-15 at 9 37 35 PM"
src="https://user-images.githubusercontent.com/1956569/133443745-333a18a0-e2c5-4ae0-970d-a1bf8f7f4fa9.png">
And I think we should better take into account every edges rather than only
every nodes:
<img width="437" alt="Screen Shot 2021-09-16 at 10 21 32 PM"
src="https://user-images.githubusercontent.com/1956569/133629659-20565517-a394-4a3b-94ca-f48c7fdbccb4.png">
And when there are more than one self-loop edges, the strategy probably
complicated to make it look good. For example, consider these cases:
<img width="294" alt="Screen Shot 2021-09-16 at 10 29 58 PM"
src="https://user-images.githubusercontent.com/1956569/133634612-a346a3d5-423c-457c-bf31-8372d66bf052.png">
<img width="287" alt="Screen Shot 2021-09-16 at 10 35 54 PM"
src="https://user-images.githubusercontent.com/1956569/133634670-a07afb9f-0d81-4118-9ef8-e459db13d02e.png">
Some other cases:
<img width="248" alt="Screen Shot 2021-09-21 at 12 26 32 AM"
src="https://user-images.githubusercontent.com/1956569/134038784-e6dd8435-7be9-4c5c-858e-163a6beae536.png">
So wrap up this above, I think we should better to find the max `n`
intersection angles for the next step to arrange the self-loop edges. May be we
could:
0. Do this step after all of the non-self-loop-edges layout finished.
1. Use `Math.atan2` to get the radians to x positive.
2. sort the edges by their radians
3. Get a list of intersection angles by `sortedEdges[n+1].radian -
sortedEdges[n].radian`, and sort desc.
---
See [PR-fix](https://github.com/HCLacids/echarts/pull/1) for more details.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]