diff options
author | Thomas F. K. Jorna <[email protected]> | 2021-10-17 01:04:13 +0200 |
---|---|---|
committer | Thomas F. K. Jorna <[email protected]> | 2021-10-17 01:04:13 +0200 |
commit | 85b665b343d63096a3e62c210931040a44b07a1b (patch) | |
tree | f4fbcc054f275dee2d6d3d712719cad145d0aac5 /pages | |
parent | 0895967f20ef33bc0f32c99bac0a93761915b87f (diff) |
feat(algos): properly working communities
Diffstat (limited to 'pages')
-rw-r--r-- | pages/index.tsx | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/pages/index.tsx b/pages/index.tsx index 9c2ae37..a2c99be 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -41,6 +41,7 @@ import { algos, colorList, initialBehavior, + initialColoring, initialFilter, initialMouse, initialPhysics, @@ -107,7 +108,7 @@ export function GraphPage() { const [emacsNodeId, setEmacsNodeId] = useState<string | null>(null) const [behavior, setBehavior] = usePersistantState('behavior', initialBehavior) const [mouse, setMouse] = usePersistantState('mouse', initialMouse) - const [coloring, setColoring] = usePersistantState('coloring', 'community') + const [coloring, setColoring] = usePersistantState('coloring', initialColoring) const [ previewNodeState, { @@ -705,7 +706,7 @@ export interface GraphProps { variables: { [variable: string]: string } graphRef: any clusterRef: any - coloring: string + coloring: typeof initialColoring } export const Graph = function (props: GraphProps) { @@ -902,7 +903,7 @@ export const Graph = function (props: GraphProps) { return { target, source, weight: link.type === 'cite' ? 1 : 2 } }) - if (coloring === 'community') { + if (coloring.method === 'community') { const community = jLouvain().nodes(filteredNodeIds).edges(weightedLinks) clusterRef.current = community() } @@ -911,7 +912,7 @@ export const Graph = function (props: GraphProps) { * ) */ //console.log(clusterRef.current) return { nodes: filteredNodes, links: filteredLinks } - }, [filter, graphData]) + }, [filter, graphData, coloring.method]) const [scopedGraphData, setScopedGraphData] = useState<GraphData>({ nodes: [], links: [] }) @@ -1092,13 +1093,13 @@ export const Graph = function (props: GraphProps) { const getNodeColorById = (id: string) => { const linklen = filteredLinksByNodeIdRef.current[id!]?.length ?? 0 - if (coloring === 'degree') { + if (coloring.method === 'degree') { return visuals.nodeColorScheme[ numberWithinRange(linklen, 0, visuals.nodeColorScheme.length - 1) ] } return visuals.nodeColorScheme[ - linklen && clusterRef.current[id] % (visuals.nodeColorScheme.length - 1) + linklen && clusterRef.current[id] % visuals.nodeColorScheme.length ] } |