1- import logo from './logo.svg' ;
2- import './App.css' ;
1+ import { client , useConfig , useElementData } from '@sigmacomputing/plugin' ;
32import * as d3 from 'd3' ;
4- import { client , useConfig , useElementData } from '@sigmacomputing/plugin' ;
53import { useEffect , useRef } from 'react' ;
4+ import './App.css' ;
65
76client . config . configureEditorPanel ( [
87 { name : "vertices" , type : "element" } ,
@@ -22,48 +21,48 @@ function renderGraph(data, ref) {
2221 const nodes = data . nodes . map ( d => Object . create ( d ) ) ;
2322
2423 const simulation = d3 . forceSimulation ( nodes )
25- . force ( "link" , d3 . forceLink ( links ) . id ( d => d . id ) )
26- . force ( "charge" , d3 . forceManyBody ( ) )
27- . force ( "center" , d3 . forceCenter ( width / 2 , height / 2 ) ) ;
24+ . force ( "link" , d3 . forceLink ( links ) . id ( d => d . id ) )
25+ . force ( "charge" , d3 . forceManyBody ( ) )
26+ . force ( "center" , d3 . forceCenter ( width / 2 , height / 2 ) ) ;
2827
2928 const svg = d3 . select ( ref . current )
30- . attr ( "width" , "100vw" )
31- . attr ( "height" , "100vh" )
32- . attr ( "preserveAspectRatio" , "xMidYMid meet" )
33- . attr ( "viewBox" , [ 0 , 0 , width , height ] ) ;
29+ . attr ( "width" , "100vw" )
30+ . attr ( "height" , "100vh" )
31+ . attr ( "preserveAspectRatio" , "xMidYMid meet" )
32+ . attr ( "viewBox" , [ 0 , 0 , width , height ] ) ;
3433
3534 const link = svg . append ( "g" )
36- . attr ( "stroke" , "#999" )
37- . attr ( "stroke-opacity" , 0.6 )
35+ . attr ( "stroke" , "#999" )
36+ . attr ( "stroke-opacity" , 0.6 )
3837 . selectAll ( "line" )
3938 . data ( links )
4039 . join ( "line" )
41- . attr ( "stroke-width" , d => Math . sqrt ( d . value ) ) ;
40+ . attr ( "stroke-width" , d => Math . sqrt ( d . value ) ) ;
4241
4342 const node = svg . append ( "g" )
44- . attr ( "stroke" , "#fff" )
45- . attr ( "stroke-width" , 1.5 )
43+ . attr ( "stroke" , "#fff" )
44+ . attr ( "stroke-width" , 1.5 )
4645 . selectAll ( "circle" )
4746 . data ( nodes )
4847 . join ( "circle" )
49- . attr ( "r" , 5 )
50- . attr ( "fill" , color )
51- . call ( drag ( simulation ) ) ;
48+ . attr ( "r" , 5 )
49+ . attr ( "fill" , color )
50+ . call ( drag ( simulation ) ) ;
5251
5352 node . append ( "title" )
54- . text ( d => d . id ) ;
53+ . text ( d => d . id ) ;
5554 node . append ( "text" ) . text ( d => d . id ) ;
5655
5756 simulation . on ( "tick" , ( ) => {
5857 link
59- . attr ( "x1" , d => d . source . x )
60- . attr ( "y1" , d => d . source . y )
61- . attr ( "x2" , d => d . target . x )
62- . attr ( "y2" , d => d . target . y ) ;
58+ . attr ( "x1" , d => d . source . x )
59+ . attr ( "y1" , d => d . source . y )
60+ . attr ( "x2" , d => d . target . x )
61+ . attr ( "y2" , d => d . target . y ) ;
6362
6463 node
65- . attr ( "cx" , d => d . x )
66- . attr ( "cy" , d => d . y ) ;
64+ . attr ( "cx" , d => d . x )
65+ . attr ( "cy" , d => d . y ) ;
6766 } ) ;
6867
6968 return simulation . stop ;
@@ -75,32 +74,32 @@ const color = () => {
7574}
7675
7776const drag = simulation => {
78-
77+
7978 function dragstarted ( event ) {
8079 if ( ! event . active ) simulation . alphaTarget ( 0.3 ) . restart ( ) ;
8180 event . subject . fx = event . subject . x ;
8281 event . subject . fy = event . subject . y ;
8382 }
84-
83+
8584 function dragged ( event ) {
8685 event . subject . fx = event . x ;
8786 event . subject . fy = event . y ;
8887 }
89-
88+
9089 function dragended ( event ) {
9190 if ( ! event . active ) simulation . alphaTarget ( 0 ) ;
9291 event . subject . fx = null ;
9392 event . subject . fy = null ;
9493 }
95-
94+
9695 return d3 . drag ( )
97- . on ( "start" , dragstarted )
98- . on ( "drag" , dragged )
99- . on ( "end" , dragended ) ;
96+ . on ( "start" , dragstarted )
97+ . on ( "drag" , dragged )
98+ . on ( "end" , dragended ) ;
10099}
101100
102101function transform ( config , vertices , edges ) {
103- const { id, to, from, value} = config ;
102+ const { id, to, from, value } = config ;
104103 console . log ( arguments ) ;
105104 if ( ! id || ! to || ! from || ! value || ! vertices ?. [ id ] ?. length || ! edges ?. [ to ] ?. length || ! edges [ value ] ?. length ) return { nodes : [ ] , links : [ ] } ;
106105 const transformed = {
0 commit comments