1
- import { MainAreaWidget , ReactWidget } from '@jupyterlab/apputils' ;
1
+ import {
2
+ MainAreaWidget ,
3
+ ReactWidget ,
4
+ Toolbar ,
5
+ UseSignal
6
+ } from '@jupyterlab/apputils' ;
2
7
3
8
import { InputGroup } from '@jupyterlab/ui-components' ;
4
9
@@ -9,6 +14,7 @@ import cytoscape from 'cytoscape';
9
14
import React , { useState } from 'react' ;
10
15
11
16
import { Model } from './model' ;
17
+ import { Signal , ISignal } from '@lumino/signaling' ;
12
18
13
19
class Graph extends Widget {
14
20
constructor ( model : Model ) {
@@ -17,6 +23,27 @@ class Graph extends Widget {
17
23
this . _model . filterChanged . connect ( ( ) => this . update ( ) ) ;
18
24
}
19
25
26
+ /**
27
+ * Return the number of nodes.
28
+ */
29
+ get V ( ) : number {
30
+ return this . _V ;
31
+ }
32
+
33
+ /**
34
+ * Return the number of edges.
35
+ */
36
+ get E ( ) : number {
37
+ return this . _E ;
38
+ }
39
+
40
+ /**
41
+ * A signal emitted when the widget is updated.
42
+ */
43
+ get updated ( ) : ISignal < Graph , void > {
44
+ return this . _updated ;
45
+ }
46
+
20
47
update ( ) : void {
21
48
const { plugins, filter, requires, optional } = this . _model ;
22
49
const nodes : Array < cytoscape . NodeDefinition > = [ ] ;
@@ -134,6 +161,11 @@ class Graph extends Widget {
134
161
}
135
162
]
136
163
} ) ;
164
+
165
+ this . _V = this . _cy . nodes ( ) . length ;
166
+ this . _E = this . _cy . edges ( ) . length ;
167
+
168
+ this . _updated . emit ( void 0 ) ;
137
169
}
138
170
139
171
protected onResize ( ) : void {
@@ -145,6 +177,9 @@ class Graph extends Widget {
145
177
146
178
private _model : Model ;
147
179
private _cy : cytoscape . Core ;
180
+ private _V = 0 ;
181
+ private _E = 0 ;
182
+ private _updated = new Signal < this, void > ( this ) ;
148
183
}
149
184
150
185
const FilterComponent = ( props : { model : Model } ) : JSX . Element => {
@@ -210,6 +245,26 @@ export class GraphContainer extends MainAreaWidget<Graph> {
210
245
</ label >
211
246
) ;
212
247
this . toolbar . addItem ( 'optional' , optional ) ;
248
+
249
+ this . toolbar . addItem ( 'spacer' , Toolbar . createSpacerItem ( ) ) ;
250
+
251
+ const nodes = ReactWidget . create (
252
+ < UseSignal signal = { this . content . updated } >
253
+ { ( ) : JSX . Element => (
254
+ < div style = { { marginRight : '5px' } } > { this . content . V } plugins</ div >
255
+ ) }
256
+ </ UseSignal >
257
+ ) ;
258
+ this . toolbar . addItem ( 'nodes' , nodes ) ;
259
+
260
+ const edges = ReactWidget . create (
261
+ < UseSignal signal = { this . content . updated } >
262
+ { ( ) : JSX . Element => (
263
+ < div style = { { marginRight : '5px' } } > { this . content . E } connections</ div >
264
+ ) }
265
+ </ UseSignal >
266
+ ) ;
267
+ this . toolbar . addItem ( 'edges' , edges ) ;
213
268
}
214
269
}
215
270
0 commit comments