11import * as d3 from 'd3' ;
22
3+ let text = [ {
4+ t : 'reverseproxy' ,
5+ } , {
6+ t : 'books' ,
7+ } , {
8+ t : 'orders' ,
9+ } , {
10+ t : 'customers'
11+ } ]
312class RouteTrace {
413 containerEl ;
514 props ;
615 svg ;
7-
16+
17+ // creating D3 container for the nodes
818 constructor ( containerEl , props ) {
919 this . containerEl = containerEl ;
1020 this . props = props ;
@@ -17,11 +27,15 @@ class RouteTrace {
1727 this . updateDatapoints ( ) ;
1828 }
1929
30+
2031 updateDatapoints = ( ) => {
2132 const { svg, props : { data, width, height } } = this ;
2233 console . log ( 'data: ' , data )
2334 console . log ( 'nodes: ' , data [ 0 ] )
2435 console . log ( 'links: ' , data [ 1 ] )
36+
37+ console . log ( '1st data point: ' , data [ 0 ] [ 0 ] )
38+ console . log ( '4th data point: ' , data [ 0 ] [ 3 ] )
2539
2640
2741 var simulation = d3 . forceSimulation ( data [ 0 ] )
@@ -30,18 +44,32 @@ class RouteTrace {
3044 . force ( 'center' , d3 . forceCenter ( width / 2 , height / 2 ) )
3145
3246 const node = svg
33- . selectAll ( "circle" )
34- . data ( data [ 0 ] )
35- . enter ( )
36- . append ( "circle" )
47+ . selectAll ( "circle" )
48+ . data ( data [ 0 ] )
49+ . enter ( )
50+ . append ( "circle" )
51+
52+ // node.select('circle').data(stuff).append("circle").select('text')
53+ // .text(function(d) { return d.id });
54+
55+ const circleAttributes = node
3756 . attr ( "r" , 20 )
38- . attr ( 'cx' , ( ) => Math . random ( ) * width )
39- . attr ( 'cy' , ( ) => Math . random ( ) * height )
57+ // .attr('cx', 200 )
58+ // .attr('cy', 200 )
4059 . style ( "fill" , "#00eda0" )
41- . on ( 'mouseup' , ( d , i , nodes ) => this . setActiveDatapoint ( d , nodes [ i ] ) ) ;
60+ . on ( 'mouseup' , ( d , i , nodes ) => this . setActiveDatapoint ( d , nodes [ i ] ) )
61+
62+ const text = svg . selectAll ( "text" )
63+ . data ( data [ 0 ] ) . enter ( ) . append ( "text" )
64+
65+ const labels = text
66+ . attr ( "x" , d => d . x )
67+ . attr ( "y" , d => d . y )
68+ . attr ( "dx" , 12 )
69+ . attr ( "dy" , ".35em" )
70+ . text ( d => d . id ) ;
71+
4272
43- node . append ( "title" )
44- . text ( function ( d ) { return d . id ; } ) ;
4573
4674 const link = svg
4775 . selectAll ( "line" )
@@ -57,7 +85,6 @@ class RouteTrace {
5785 simulation . force ( 'link' )
5886 . links ( link ) ;
5987
60-
6188 function ticked ( ) {
6289 link
6390 . attr ( "x1" , function ( d ) { return d . source . x ; } )
@@ -69,7 +96,6 @@ class RouteTrace {
6996 . attr ( "cx" , function ( d ) { return d . x ; } )
7097 . attr ( "cy" , function ( d ) { return d . y ; } ) ;
7198 }
72-
7399 }
74100
75101 setActiveDatapoint = ( d , node ) => {
0 commit comments