-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
365 lines (323 loc) · 15.5 KB
/
demo.html
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='initial-scale=1, maximum-scale=1'>
<title>ui.js demo</title>
<link rel='shortcut icon' type='image/x-icon' href='misc/favicon_white.ico' />
<link type="text/css" href="vendors/kepler.css" rel="stylesheet">
<link type="text/css" href="css/ui.css" rel="stylesheet">
<link type="text/css" href="demo.css" rel="stylesheet">
<link type="text/css" href="css/info.css" rel="stylesheet">
<script type='text/javascript' src='vendors/chroma.min.js'></script>
<script type='module' src='./libs/ui.js'></script>
</head>
<body>
<script type='module'>
// Move all this to UI.Demo
import {UI} from './libs/ui.js';
// 0) Menu to show/hide the elements of the demo
let demo = new UI.Demo();
document.body.appendChild(demo);
// shorthand for the parts
let menu = demo.querySelector('#demo-menu');
let components = demo.querySelector('#demo-components');
let args;
/* 1) SIMPLE WIDGETS */
let simple_widgets = UI.el({type: 'div', classes: ['demo-category'], innerText: 'Simple Widgets'});
menu.appendChild(simple_widgets)
simple_widgets.onclick = () => {
document.querySelectorAll('.demo-item.simple').forEach(i => i.classList.toggle('visible'));
};
// 1.1) button
// 1.1.1) + button
simpleDemoItem({widget: 'Button', args: {label: 'upload', icon: 'add'}, name: 'with icon'});
// 1.1.2) Upload button
simpleDemoItem({widget: 'Button', args: {label: 'upload'}, name: 'upload'});
// 1.1.3) Cancel button
simpleDemoItem({widget: 'Button', args: {label: 'cancel', classes: ['cancel']}, name: 'cancel'});
// 1.2) Checkbox
// 1.2.1) Round
simpleDemoItem({widget: 'CheckBox', args: {label: 'round', square: false, embed: true}, name: 'round'});
// 1.2.2) Square
simpleDemoItem({widget: 'CheckBox', args: {label: 'square', square: true, embed: true}, name: 'square'});
// 1.3) DropDown
simpleDemoItem({widget: 'DropDown', args: {embed: true}});
// 1.4) Slider
simpleDemoItem({widget: 'Slider', args: {label: 'some kpi', value: 33, embed: true}});
// 1.5) Double Slider
simpleDemoItem({widget: 'DoubleSlider', args: {label: 'some kpi range', min: -140, max: -70, embed: true}});
// 1.6) Progressbar
simpleDemoItem({widget: 'ProgressBar', args: {label: 'some kpi', value: 56, embed: true}});
// 1.7) Progressbar group
simpleDemoItem({widget: 'ProgressBarGroup', args: {embed: true}});
/* 2) COMPLEX WIDGETS */
let complex_widgets = UI.el({type: 'div', classes: ['demo-category'], innerText: 'Complex Widgets'});
complex_widgets.onclick = () => {
document.querySelectorAll('.demo-item.complex').forEach(i => i.classList.toggle('visible'));
};
menu.appendChild(complex_widgets);
// 2.1) Simple Panel
let s_panel = UI.el({type: 'div', classes: ['demo-item', 'complex'], innerText: 'panel'});
menu.appendChild(s_panel);
s_panel.onclick = (evt) => {
evt.target.classList.toggle('clicked');
let el_panel = components.querySelector('#panel_1');
if (el_panel === null) {
el_panel = new UI.Panel({id: 'panel_1', closable: true});
// Add data to the panel
let body = el_panel.querySelector('.panel-body');
for (let i=0; i<15; i++) {
body.appendChild(UI.el({type: 'div', innerText: `Some text ${i}`, classes: ['t_label']}));
}
components.appendChild(el_panel);
} else {
components.removeChild(el_panel);
}
};
// 2.2) Header (left:0..2, titel:0..1, right:0..2 => 3x2x3=18)
// 2.2.1) Left: 0 - Title: 0 - right: 0
// 2.2.2) Left: 0 - Title: 1 - right: 0
// 2.2.3) Left: 1 - Title: 0 - right: 1
// 2.2.1) Left: 0 - Title: 0 - right: 0
// 2.2.1) Left: 0 - Title: 0 - right: 0
complexDemoItem({widget: 'Header', args: {subtitle: 'sublabel', before: ['grab', 'eye_open'], after: ['settings', 'close']}});
// 2.3) Colorbar
// 2.3.1) Example 1
args = {title: 'Quantity [unit]', category: 'diverging', scheme: 'Spectral', n_colors: 7, min: -10, max: 31, reverse: false};
complexDemoItem({widget: 'DiscreteColorBar', args: args, name: 'ex1'});
// 2.3.2) Example 2
args = {title: 'Something [#]', category: 'singlehue', scheme: 'Purples', n_colors: 4, min: 0, max: 100, reverse: false};
complexDemoItem({widget: 'DiscreteColorBar', args: args, name: 'ex2'});
// 2.3.2) Example 3
args = {title: 'Anything [dB]', category: 'qualitative', scheme: 'Set1', n_colors: 5, min: -140, max: -70, reverse: true};
complexDemoItem({widget: 'DiscreteColorBar', args: args, name: 'ex3'});
// 2.3bis) heatmap example (to go along one of the examples above...or both!!)
complexDemoItem({widget: 'Heatmap', name: 'div', args: {resizable: true, mode: 'all', movable: true}});
let fake_items = {
'item 1': 'int',
'element 2 ': 'float',
'component 3': 'string',
'row 4': 'geo',
'level 5': 'int',
'section 5a': 'obj',
'category 6': 'int',
'channel 7': 'string',
'subchannel 7z': 'mtl',
'group 8': 'geo',
'section 9': 'float',
'subsection 9': 'json',
'row 10': 'geo',
};
// 2.4) Item Grouper
complexDemoItem({widget: 'ItemGrouper', args: {selected: Object.keys(fake_items)}});
// 2.5) item picker
// 2.5.1) example 1
complexDemoItem({widget: 'ItemPicker', args: {items: fake_items}, name: 'ex1'});
// 2.5.2) example 2
complexDemoItem({widget: 'ItemPicker', args: {}, name: 'ex2'});
// 2.6) item griper
// 2.6.1) example 1
complexDemoItem({widget: 'ItemGriper', args: {items: fake_items}, name: 'ex1'});
// 2.6.6) example 2
complexDemoItem({widget: 'ItemGriper', args: {fake: true}, name: 'ex2'});
// 2.7) tooltip: the one that shows detailed info about a hovered point
complexDemoItem({widget: 'Tooltip', args: {}});
// 2.8) sinfle file reader
complexDemoItem({widget: 'SingleFileReader', args: {embed: true}});
/* 3) OTHER */
let other_widgets = UI.el({type: 'div', classes: ['demo-category'], innerText: 'Other'});
menu.appendChild(other_widgets);
other_widgets.onclick = () => {
document.querySelectorAll('.demo-item.other').forEach(i => i.classList.toggle('visible'));
};
// 3.0) Icons
otherDemoItem({widget: 'IconsShowCase', name: '!icons'});
// 3.1) resizable window
// 3.1.1) empty div with resizers on bottom right corner and around
let s_resizable = UI.el({type: 'div', classes: ['demo-item', 'other'], innerText: 'resizable simple'});
menu.appendChild(s_resizable);
s_resizable.onclick = (evt) => {
evt.target.classList.toggle('clicked');
let element = components.querySelector('#demo-resizable');
if (element === null) {
let div = UI.Box({id: 'demo-resizable', classes: ['resizable']});
components.appendChild(div);
UI.makeResizableDiv(div.id, 'simple');
} else {
components.removeChild(element);
}
}
// 3.1.2) empty div with resizers on all corners
let s_resizable_corners = UI.el({type: 'div', classes: ['demo-item', 'other'], innerText: 'resizable corners'});
menu.appendChild(s_resizable_corners);
s_resizable_corners.onclick = (evt) => {
evt.target.classList.toggle('clicked');
let element = components.querySelector('#demo-resizable_corners');
if (element === null) {
let div = UI.Box({id: 'demo-resizable_corners', classes: ['resizable']});
div.style.position = 'absolute';
components.appendChild(div);
UI.makeResizableDiv(div.id, 'corners');
} else {
components.removeChild(element);
}
}
// 3.1.3) empty div with resizers on all middles
let s_resizable_middles = UI.el({type: 'div', classes: ['demo-item', 'other'], innerText: 'resizable middles'});
menu.appendChild(s_resizable_middles);
s_resizable_middles.onclick = (evt) => {
evt.target.classList.toggle('clicked');
let element = components.querySelector('#demo-resizable_middles');
if (element === null) {
let div = UI.Box({id: 'demo-resizable_middles', classes: ['resizable']});
div.style.position = 'absolute';
components.appendChild(div);
UI.makeResizableDiv(div.id, 'middles');
} else {
components.removeChild(element);
}
}
// 3.1.4) empty div with resizers on all points
let s_resizable_all = UI.el({type: 'div', classes: ['demo-item', 'other'], innerText: 'resizable all'});
menu.appendChild(s_resizable_all);
s_resizable_all.onclick = (evt) => {
evt.target.classList.toggle('clicked');
let element = components.querySelector('#demo-resizable_all');
if (element === null) {
let div = UI.Box({id: 'demo-resizable_all', classes: ['resizable']});
div.style.position = 'absolute';
components.appendChild(div);
UI.makeResizableDiv(div.id, 'all');
} else {
components.removeChild(element);
}
}
// 3.1.5) Panel
let s_resizable_panel = UI.el({type: 'div', classes: ['demo-item', 'other'], innerText: 'resizable panel'});
menu.appendChild(s_resizable_panel);
s_resizable_panel.onclick = (evt) => {
evt.target.classList.toggle('clicked');
toggleComponent('Panel', {id: 'resizable-panel-demo'});
let element = components.querySelector('#resizable-panel-demo');
if (element !== null) {
UI.makeResizableDiv(element.id);
}
};
// 3.2) movable window
let s_movable = UI.el({type: 'div', classes: ['demo-item', 'other'], innerText: 'movable'});
menu.appendChild(s_movable);
s_movable.onclick = (evt) => {
evt.target.classList.toggle('clicked');
let element = components.querySelector('#demo-movable');
if (element === null) {
let div = UI.Box({id: 'demo-movable', classes: ['movable']});
div.style.position = 'absolute';
components.appendChild(div);
UI.makeMovableDiv(div.id);
} else {
components.removeChild(element);
}
}
// 3.3) Movable and resizable
let s_removable = UI.el({type: 'div', classes: ['demo-item', 'other'], innerText: 'removable'});
menu.appendChild(s_removable);
s_removable.onclick = (evt) => {
evt.target.classList.toggle('clicked');
let element = components.querySelector('#demo-removable');
if (element === null) {
let div = UI.Box({id: 'demo-removable', classes: ['movable']});
div.style.position = 'absolute';
components.appendChild(div);
UI.makeMovableDiv(div.id);
UI.makeResizableDiv(div.id, 'all');
} else {
components.removeChild(element);
}
}
// 3.4) Context menu
let s_context = UI.el({type: 'div', classes: ['demo-item', 'other'], innerText: 'context menu'});
menu.appendChild(s_context);
s_context.onclick = (evt) => {
UI.ContextMenu.toggle();
evt.target.classList.toggle('clicked');
};
// 3.4) Fixed
otherDemoItem({widget: 'Fixed', args: {top: '100px', left: '50%'}});
// 3.5) Modal
otherDemoItem({widget: 'Modal'});
// 3.6) Modal DirectoryHandler
let dh = UI.DirectoryHandler();
otherDemoItem({widget: 'Modal', args: {div: dh}, name: 'Modal DH'});
/* Helper functions*/
function simpleDemoItem(opts) {
demoItem(opts.widget, opts.args, 'simple', opts.name);
}
function complexDemoItem(opts) {
demoItem(opts.widget, opts.args, 'complex', opts.name);
}
function otherDemoItem(opts) {
demoItem(opts.widget, opts.args, 'other', opts.name);
}
function demoItem(widget, args, category, name) {
/**
*
* widget: case-correct string, UI component name
* args: json, arguments to the widget (needed to create the component)
* category: string, component category ('simple', 'complex', 'other')
* name: string, name of the item in the demo. only postfix is needed
*
* to simplify the API:
* - if not specified, the id will always be the widget name appended by '-demo'
* - if not specified, the label
*/
args = args || {};
let postfix = '';
if (name) {
let name_ = name;
if (name_.startsWith('!')) {
name_ = name_.split('!')[1];
}
postfix += '_' + name_.replace(/ /g, '-');
}
args.id = args.id || 'demo-' + widget.toLowerCase() + postfix;
if (!name) {
name = widget; // + ' ' + args.label;
} else {
// we use the ! sign to force a name in the menu because why not?
if (name.startsWith('!')) {
name = name.split('!')[1];
} else {
name = widget + ' ' + name;
}
}
let item_switch = UI.el({type: 'div', classes: ['demo-item', category], innerText: name});
menu.appendChild(item_switch);
item_switch.onclick = (evt) => {
evt.target.classList.toggle('clicked');
toggleComponent(widget, args);
};
}
function toggleComponent(widget, args) {
/**
* toggle component on the page
* assumption: id is included in args
*/
let element = components.querySelector(`#${args.id}`);
if (element) {
components.removeChild(element);
} else {
element = new UI[widget](args);
components.appendChild(element);
if (args.movable) {
UI.makeMovableDiv(args.id);
element.style.position = 'absolute';
}
if (args.resizable) {
UI.makeResizableDiv(args.id, args.mode);
}
}
}
</script>
</body>
</html>