Skip to content

Commit 4e0af1b

Browse files
committed
Add number of nodes and edges to the toolbar
1 parent 8bba003 commit 4e0af1b

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

src/widget.tsx

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { MainAreaWidget, ReactWidget } from '@jupyterlab/apputils';
1+
import {
2+
MainAreaWidget,
3+
ReactWidget,
4+
Toolbar,
5+
UseSignal
6+
} from '@jupyterlab/apputils';
27

38
import { InputGroup } from '@jupyterlab/ui-components';
49

@@ -9,6 +14,7 @@ import cytoscape from 'cytoscape';
914
import React, { useState } from 'react';
1015

1116
import { Model } from './model';
17+
import { Signal, ISignal } from '@lumino/signaling';
1218

1319
class Graph extends Widget {
1420
constructor(model: Model) {
@@ -17,6 +23,27 @@ class Graph extends Widget {
1723
this._model.filterChanged.connect(() => this.update());
1824
}
1925

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+
2047
update(): void {
2148
const { plugins, filter, requires, optional } = this._model;
2249
const nodes: Array<cytoscape.NodeDefinition> = [];
@@ -134,6 +161,11 @@ class Graph extends Widget {
134161
}
135162
]
136163
});
164+
165+
this._V = this._cy.nodes().length;
166+
this._E = this._cy.edges().length;
167+
168+
this._updated.emit(void 0);
137169
}
138170

139171
protected onResize(): void {
@@ -145,6 +177,9 @@ class Graph extends Widget {
145177

146178
private _model: Model;
147179
private _cy: cytoscape.Core;
180+
private _V = 0;
181+
private _E = 0;
182+
private _updated = new Signal<this, void>(this);
148183
}
149184

150185
const FilterComponent = (props: { model: Model }): JSX.Element => {
@@ -210,6 +245,26 @@ export class GraphContainer extends MainAreaWidget<Graph> {
210245
</label>
211246
);
212247
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);
213268
}
214269
}
215270

0 commit comments

Comments
 (0)