Skip to content

Commit

Permalink
fix: edge overlap, when there are even numbers of edges between two p…
Browse files Browse the repository at this point in the history
…oints
  • Loading branch information
CorvusYe committed Mar 30, 2024
1 parent eaa0158 commit fed7c7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 9 additions & 4 deletions example/lib/demos/self_loop_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@ class SelfLoopDemo extends StatelessWidget {
Widget build(BuildContext context) {
var vertexes = <Map>{};

vertexes.add(
vertexes.addAll([
{
'id': 'node',
'tag': 'tag',
'tags': ['tag'],
},
);
{
'id': 'node2',
'tag': 'tag3',
'tags': ['tag', 'tag2'],
}
]);
var edges = <Map>{};

for (var i = 0; i < 10; i++) {
for (var i = 0; i < 20; i++) {
edges.add({
'srcId': 'node',
'dstId': 'node',
'dstId': 'node${i.isEven ? '2' : ''}',
'edgeName': 'edge$i',
'ranking': i,
});
Expand Down
8 changes: 3 additions & 5 deletions lib/core/options/shape/edge/edge_line_shape.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,16 @@ class EdgeLineShape extends EdgeShape {
edge.cpn?.graph.edgesFromTwoVertex(edge.start, edge.end) ?? [];
var idx = edgeList.indexOf(edge);
if (edgeList.length.isOdd) {
if (idx == 0) {
return 0;
} else if (idx.isEven) {
if (idx.isEven) {
return idx / 2;
} else {
return -(idx + 1) / 2;
}
} else {
if (idx.isEven) {
return idx / 2;
return idx / 2 + 0.5;
} else {
return -(idx - 1) / 2;
return -(idx - 1) / 2 - 0.5;
}
}
}
Expand Down

0 comments on commit fed7c7d

Please sign in to comment.