@@ -24,13 +24,13 @@ interface ISelectedEntityProps {
24
24
25
25
const isDarkTheme = document . body . classList . contains ( 'theme_DARK' )
26
26
27
- const colorPicker = ( COLORS : Utils . IGoodColor [ ] , isDarkTheme : boolean ) => {
28
- const color = new Utils . GoodColorPicker ( COLORS , isDarkTheme )
27
+ const colorPicker = ( COLORS : Utils . IGoodColor [ ] ) => {
28
+ const color = new Utils . GoodColorPicker ( COLORS )
29
29
return ( label : string ) => color . getColor ( label )
30
30
}
31
31
32
- const labelColors = colorPicker ( Utils . NODE_COLORS , isDarkTheme )
33
- const edgeColors = colorPicker ( Utils . EDGE_COLORS , isDarkTheme )
32
+ const labelColors = colorPicker ( isDarkTheme ? Utils . NODE_COLORS_DARK : Utils . NODE_COLORS )
33
+ const edgeColors = colorPicker ( isDarkTheme ? Utils . EDGE_COLORS_DARK : Utils . EDGE_COLORS )
34
34
35
35
export default function Graph ( props : { graphKey : string , data : any [ ] } ) {
36
36
@@ -55,14 +55,16 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
55
55
errors : [ ] ,
56
56
}
57
57
58
- let nodeLabels = new Set ( parsedResponse . labels )
59
- let edgeTypes = new Set ( parsedResponse . types )
58
+ const [ nodeLabels , setNodeLabels ] = useState ( parsedResponse . labels )
59
+ const [ edgeTypes , setEdgeTypes ] = useState ( parsedResponse . types )
60
60
61
61
const [ graphData , setGraphData ] = useState ( data )
62
62
63
63
useMemo ( async ( ) => {
64
64
65
65
let newGraphData = graphData
66
+ let newNodeLabels : { [ key : string ] : number } = nodeLabels
67
+ let newEdgeTypes : { [ key : string ] : number } = edgeTypes
66
68
67
69
if ( parsedResponse . nodeIds . length > 0 ) {
68
70
try {
@@ -73,12 +75,9 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
73
75
const parsedData = responseParser ( resp [ 0 ] . response )
74
76
parsedData . nodes . forEach ( n => {
75
77
nodeIds . add ( n . id )
76
- n . labels . forEach ( nodeLabels . add , nodeLabels )
77
- } )
78
-
79
- parsedData . edges . forEach ( e => {
80
- edgeTypes . add ( e . type )
78
+ n . labels . forEach ( l => newNodeLabels [ l ] = ( newNodeLabels [ l ] + 1 ) || 1 )
81
79
} )
80
+ parsedData . edges . forEach ( e => newEdgeTypes [ e . type ] = ( newEdgeTypes [ e . type ] + 1 ) || 1 )
82
81
83
82
newGraphData = {
84
83
...newGraphData ,
@@ -107,12 +106,10 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
107
106
const parsedData = responseParser ( resp [ 0 ] . response )
108
107
parsedData . nodes . forEach ( n => {
109
108
nodeIds . add ( n . id )
110
- n . labels . forEach ( nodeLabels . add , nodeLabels )
111
- } )
112
-
113
- parsedData . edges . forEach ( e => {
114
- edgeTypes . add ( e . type )
109
+ n . labels . forEach ( l => newNodeLabels [ l ] = ( newNodeLabels [ l ] + 1 ) || 1 )
115
110
} )
111
+ const filteredEdges = parsedData . edges . filter ( e => nodeIds . has ( e . source ) && nodeIds . has ( e . target ) && ! edgeIds . has ( e . id ) ) . map ( e => ( { ...e , startNode : e . source , endNode : e . target } ) )
112
+ filteredEdges . forEach ( e => newEdgeTypes [ e . type ] = ( newEdgeTypes [ e . type ] + 1 ) || 1 )
116
113
117
114
setGraphData ( {
118
115
...newGraphData ,
@@ -123,10 +120,7 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
123
120
data : [ {
124
121
graph : {
125
122
nodes : parsedData . nodes ,
126
- /* TODO:
127
- * track newly added edges
128
- */
129
- relationships : parsedData . edges . filter ( e => nodeIds . has ( e . source ) && nodeIds . has ( e . target ) && ! edgeIds . has ( e . id ) ) . map ( e => ( { ...e , startNode : e . source , endNode : e . target } ) )
123
+ relationships : filteredEdges ,
130
124
}
131
125
} ]
132
126
}
@@ -135,6 +129,9 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
135
129
}
136
130
} catch { }
137
131
132
+ setNodeLabels ( newNodeLabels )
133
+ setEdgeTypes ( newEdgeTypes )
134
+
138
135
setStart ( true )
139
136
} , [ ] )
140
137
@@ -167,20 +164,34 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
167
164
const data = await globalThis . PluginSDK ?. executeRedisCommand ( `graph.ro_query "${ props . graphKey } " "MATCH (n)-[t]-(m) WHERE id(n)=${ node . id } RETURN t, m"` )
168
165
if ( ! Array . isArray ( data ) ) return ;
169
166
if ( data . length < 1 || data [ 0 ] . status !== 'success' ) return ;
170
-
171
167
const parsedData = responseParser ( data [ 0 ] . response )
168
+
169
+ let newNodeLabels = nodeLabels
170
+ let newEdgeTypes = edgeTypes
171
+
172
+ parsedData . nodes . forEach ( n => {
173
+ nodeIds . add ( n . id )
174
+ n . labels . forEach ( l => newNodeLabels [ l ] = ( newNodeLabels [ l ] + 1 ) || 1 )
175
+ } )
176
+ const filteredEdges = parsedData . edges . filter ( e => ! edgeIds . has ( e . id ) ) . map ( e => ( { ...e , startNode : e . source , endNode : e . target } ) )
177
+ filteredEdges . forEach ( e => newEdgeTypes [ e . type ] = ( newEdgeTypes [ e . type ] + 1 ) || 1 )
178
+
172
179
graphd3 . updateWithGraphData ( {
173
180
results : [ {
174
181
columns : parsedData . headers ,
175
182
data : [ {
176
183
graph : {
177
184
nodes : parsedData . nodes ,
178
- relationships : parsedData . edges . filter ( e => ! edgeIds . has ( e . id ) ) . map ( e => ( { ... e , startNode : e . source , endNode : e . target } ) )
185
+ relationships : filteredEdges ,
179
186
}
180
187
} ]
181
188
} ] ,
182
189
errors : [ ] ,
183
- } ) ;
190
+ } )
191
+
192
+ setNodeLabels ( newNodeLabels )
193
+ setEdgeTypes ( newEdgeTypes )
194
+
184
195
} ,
185
196
onRelationshipDoubleClick ( relationship ) {
186
197
} ,
@@ -218,10 +229,10 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
218
229
< div className = "d3-info" >
219
230
< div className = "graph-legends" >
220
231
{
221
- parsedResponse . nodes . length > 0 && (
232
+ Object . keys ( nodeLabels ) . length > 0 && (
222
233
< div className = "d3-info-labels" >
223
234
{
224
- [ ... nodeLabels ] . map ( ( item , i ) => (
235
+ Object . keys ( nodeLabels ) . map ( ( item , i ) => (
225
236
< div
226
237
className = "box-node-label"
227
238
style = { { backgroundColor : labelColors ( item ) . color , color : labelColors ( item ) . textColor } }
@@ -235,10 +246,10 @@ export default function Graph(props: { graphKey: string, data: any[] }) {
235
246
)
236
247
}
237
248
{
238
- parsedResponse . edges . length > 0 && (
249
+ Object . keys ( edgeTypes ) . length > 0 && (
239
250
< div className = "d3-info-labels" >
240
251
{
241
- [ ... edgeTypes ] . map ( ( item , i ) => (
252
+ Object . keys ( edgeTypes ) . map ( ( item , i ) => (
242
253
< div
243
254
key = { item + i . toString ( ) }
244
255
className = "box-edge-type"
0 commit comments