Skip to content

Commit

Permalink
<SigmaGraph>: improve logic for arranging parallel edges
Browse files Browse the repository at this point in the history
  • Loading branch information
darrylyeo committed Apr 20, 2024
1 parent 5fb6cae commit 473db4d
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/components/SigmaGraph.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -150,31 +150,42 @@
$effect(() => {
if(arrangeParallelEdges && EdgeCurveModule){
EdgeCurveModule.indexParallelEdgesIndex(graph, { edgeIndexAttribute: 'parallelIndex', edgeMaxIndexAttribute: 'parallelMaxIndex' })
EdgeCurveModule.indexParallelEdgesIndex(graph, { edgeIndexAttribute: 'edgeIndex', edgeMaxIndexAttribute: 'edgeCount' })
// Adapt types and curvature of parallel edges for rendering:
graph.forEachEdge(
(
edge,
{
parallelIndex,
parallelMaxIndex,
}: { parallelIndex: number; parallelMaxIndex: number } | { parallelIndex?: null; parallelMaxIndex?: null },
edgeIndex,
edgeCount,
}: { edgeIndex: number; edgeCount: number } | { edgeIndex?: null; edgeCount?: null },
) => {
if (typeof parallelIndex === 'number') {
if (typeof edgeIndex === 'number') {
const curvature = (
// [-1, 1]
edgeIndex / (edgeCount - 1) * 2 - 1
// [0, 1]
// edgeIndex / (edgeCount - 1)
// (0, 1]
// (edgeIndex + 1) / (edgeCount)
) * (
1 - Math.exp(-0.1 * edgeCount)
)
if(curvature !== 0)
graph.mergeEdgeAttributes(edge, {
type: 'curved',
curvature,
})
else
graph.mergeEdgeAttributes(edge, {
type: 'straight',
})
} else {
graph.mergeEdgeAttributes(edge, {
type: 'curved',
curvature: (
// -1 to 1
parallelIndex / parallelMaxIndex * 2 - 1
// 0 to 1
// (parallelIndex - 1) / (parallelMaxIndex - 1)
) * (
1
)
type: 'straight',
})
} else {
graph.setEdgeAttribute(edge, 'type', 'straight');
}
},
)
Expand Down

0 comments on commit 473db4d

Please sign in to comment.