This repository has been archived by the owner on Oct 9, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvis-tests.ts
258 lines (216 loc) · 6.14 KB
/
vis-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import { NodeOptions } from 'vis';
import vis = require('vis');
// Test DataSet constructor
new vis.DataSet();
new vis.DataSet({});
new vis.DataSet([]);
new vis.DataSet([], {});
// Test Network constructor
new vis.Network(new HTMLDivElement(), { nodes: new vis.DataSet(), edges: new vis.DataSet() }, {});
//
// Test code sample from http://visjs.org/docs/data/dataset.html#Example
//
interface TestData {
id: number;
text?: string;
date?: any;
group?: number;
balance?: number;
first?: boolean;
}
// create a DataSet
let options = {};
let data = new vis.DataSet<TestData>(options);
// add items
// note that the data items can contain different properties and data formats
data.add([
{ id: 1, text: 'item 1', date: new Date(2013, 6, 20), group: 1, first: true },
{ id: 2, text: 'item 2', date: '2013-06-23', group: 2 },
{ id: 3, text: 'item 3', date: '2013-06-25', group: 2 },
{ id: 4, text: 'item 4' }
]);
// subscribe to any change in the DataSet
data.on('*', (event: any, properties: any, senderId: any) => {
console.log('event', event, properties);
});
// update an existing item
data.update({ id: 2, group: 1 });
// remove an item
data.remove(4);
// get all ids
const ids = data.getIds();
console.log('ids', ids);
// get a specific item
const item1 = data.get(1);
console.log('item1', item1);
// retrieve a filtered subset of the data
let items = data.get({
filter: (item: any) => {
return item.group === 1;
}
});
console.log('filtered items', items);
// retrieve formatted items
items = data.get({
fields: ['id', 'date'],
type: {
date: 'ISODate'
}
});
console.log('formatted items', items);
//
// Test code sample from http://visjs.org/docs/data/dataset.html#Subscriptions
//
// create a DataSet
data = new vis.DataSet<TestData>();
// subscribe to any change in the DataSet
data.on('*', (event: any, properties: any, senderId: any) => {
console.log('event:', event, 'properties:', properties, 'senderId:', senderId);
});
// add an item
data.add({ id: 1, text: 'item 1' }); // triggers an 'add' event
data.update({ id: 1, text: 'item 1 (updated)' }); // triggers an 'update' event
data.remove(1); // triggers an 'remove' event
//
// Test code sample from http://visjs.org/docs/data/dataset.html#Data_Manipulation
//
// create a DataSet
data = new vis.DataSet<TestData>();
// add items
data.add([
{ id: 1, text: 'item 1' },
{ id: 2, text: 'item 2' },
{ id: 3, text: 'item 3' }
]);
// update an item
data.update({ id: 2, text: 'item 2 (updated)' });
// remove an item
data.remove(3);
//
// Test code sample from http://visjs.org/docs/data/dataset.html#Data_Selection
//
// create a DataSet
data = new vis.DataSet<TestData>();
data.add([
{ id: 1, text: 'item 1', date: '2013-06-20', group: 1, first: true },
{ id: 2, text: 'item 2', date: '2013-06-23', group: 2 },
{ id: 3, text: 'item 3', date: '2013-06-25', group: 2 },
{ id: 4, text: 'item 4' }
]);
// retrieve formatted items
items = data.get({
fields: ['id', 'date', 'group'], // output the specified fields only
type: {
date: 'Date', // convert the date fields to Date objects
group: 'String' // convert the group fields to Strings
}
});
const dataset = new vis.DataSet<TestData>();
// retrieve all items having a property group with value 2
const group2 = dataset.get({
filter: (item: any) => {
return (item.group === 2);
}
});
// retrieve all items having a property balance with a value above zero
const positiveBalance = dataset.get({
filter: (item: any) => {
return item.balance !== undefined && item.balance > 0;
}
});
// DataGroup test
const groups = [
{id: "1", content: "group 1", visible: true},
{id: "2", content: "group 2", visible: false},
{id: "3", content: "parent group", nestedGroups: [ "1", "2" ], visible: false, showNested: true}
];
const timelineContainer = <HTMLElement> document.getElementById('timeline');
const timeline = new vis.Timeline(timelineContainer, [], groups);
//
// Test code sample from Getting Started http://visjs.org/docs/network/
//
// create an array with nodes
const nodes = new vis.DataSet([
{ id: 1, label: 'Node 1' },
{ id: 2, label: 'Node 2' },
{ id: 3, label: 'Node 3' },
{ id: 4, label: 'Node 4' },
{ id: 5, label: 'Node 5' }
]);
// create an array with edges
const edges = new vis.DataSet([
{ from: 1, to: 3 },
{ from: 1, to: 2 },
{ from: 2, to: 4 },
{ from: 2, to: 5 }
]);
// create a network
const container = <HTMLElement> document.getElementById('mynetwork');
// provide the data in the vis format
const data2 = { nodes, edges };
options = {};
// initialize your network!
const network = new vis.Network(container, data2, options);
//
// Test code sample from http://visjs.org/docs/network/configure.html#
//
// these are all options in full.
const options2 = {
configure: {
enabled: true,
filter: 'nodes,edges',
container,
showButton: true
}
};
network.setOptions(options2);
//
// Test code sample from http://visjs.org/docs/network/#locales
//
const locales = {
en: {
edit: 'Edit',
del: 'Delete selected',
back: 'Back',
addNode: 'Add Node',
addEdge: 'Add Edge',
editNode: 'Edit Node',
editEdge: 'Edit Edge',
addDescription: 'Click in an empty space to place a new node.',
edgeDescription: 'Click on a node and drag the edge to another node to connect them.',
editEdgeDescription: 'Click on the control points and drag them to a node to connect to it.',
createEdgeError: 'Cannot link edges to a cluster.',
deleteClusterError: 'Clusters cannot be deleted.',
editClusterError: 'Clusters cannot be edited.'
}
};
options = {
locale: 'en',
locales,
};
network.setOptions(options);
//
// should accept different formats of widthConstraint for NodeOptions
//
let nodeWidthConstraintOptions: NodeOptions = {
widthConstraint: {
maximum: 100
}
};
nodeWidthConstraintOptions = {
widthConstraint: false
};
nodeWidthConstraintOptions = {
widthConstraint: {
minimum: 1,
maximum: 5
}
};
nodeWidthConstraintOptions = {
widthConstraint: {
minimum: 1
}
};
nodeWidthConstraintOptions = {
widthConstraint: 150
};