UNPKG

21.8 kBMarkdownView Raw
1<a name="module_perspective-viewer"></a>
2
3## perspective-viewer
4Module for the `<perspective-viewer>` custom element. This module has no exports, but importing it has a side effect: the [module:perspective_viewer~PerspectiveViewer](module:perspective_viewer~PerspectiveViewer) class is registered as a custom element, after which it can be used as a standard DOM element. The documentation in this module defines the instance structure of a `<perspective-viewer>` DOM object instantiated typically, through HTML or any relevent DOM method e.g. `document.createElement("perspective-viewer")` or `document.getElementsByTagName("perspective-viewer")`.
5
6
7* [perspective-viewer](#module_perspective-viewer)
8 * [~PerspectiveViewer](#module_perspective-viewer..PerspectiveViewer) ⇐ <code>HTMLElement</code>
9 * [new PerspectiveViewer()](#new_module_perspective-viewer..PerspectiveViewer_new)
10 * [.sort](#module_perspective-viewer..PerspectiveViewer+sort) : <code>[ &#x27;array&#x27; ].&lt;string&gt;</code>
11 * [.columns](#module_perspective-viewer..PerspectiveViewer+columns)
12 * [.computed-columns](#module_perspective-viewer..PerspectiveViewer+computed-columns)
13 * [.aggregates](#module_perspective-viewer..PerspectiveViewer+aggregates)
14 * [.filters](#module_perspective-viewer..PerspectiveViewer+filters) : <code>array</code>
15 * [.plugin](#module_perspective-viewer..PerspectiveViewer+plugin) : <code>string</code>
16 * [.column-pivots](#module_perspective-viewer..PerspectiveViewer+column-pivots) : <code>[ &#x27;Array&#x27; ].&lt;String&gt;</code>
17 * [.row-pivots](#module_perspective-viewer..PerspectiveViewer+row-pivots) : <code>[ &#x27;array&#x27; ].&lt;string&gt;</code>
18 * [.editable](#module_perspective-viewer..PerspectiveViewer+editable) : <code>boolean</code>
19 * [.throttle](#module_perspective-viewer..PerspectiveViewer+throttle) : <code>integer</code> \| <code>string</code>
20 * [.worker](#module_perspective-viewer..PerspectiveViewer+worker)
21 * [.table](#module_perspective-viewer..PerspectiveViewer+table)
22 * [.view](#module_perspective-viewer..PerspectiveViewer+view)
23 * [.load(data)](#module_perspective-viewer..PerspectiveViewer+load) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;void&gt;</code>
24 * [.update(data)](#module_perspective-viewer..PerspectiveViewer+update)
25 * [.notifyResize()](#module_perspective-viewer..PerspectiveViewer+notifyResize)
26 * [.clone(widget)](#module_perspective-viewer..PerspectiveViewer+clone)
27 * [.delete(delete_table)](#module_perspective-viewer..PerspectiveViewer+delete) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;boolean&gt;</code>
28 * [.restyleElement()](#module_perspective-viewer..PerspectiveViewer+restyleElement)
29 * [.save()](#module_perspective-viewer..PerspectiveViewer+save) ⇒ <code>object</code>
30 * [.restore(config)](#module_perspective-viewer..PerspectiveViewer+restore) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;void&gt;</code>
31 * [.flush()](#module_perspective-viewer..PerspectiveViewer+flush) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;void&gt;</code>
32 * [.clear()](#module_perspective-viewer..PerspectiveViewer+clear)
33 * [.replace()](#module_perspective-viewer..PerspectiveViewer+replace)
34 * [.reset()](#module_perspective-viewer..PerspectiveViewer+reset)
35 * [.copy()](#module_perspective-viewer..PerspectiveViewer+copy)
36 * [.toggleConfig()](#module_perspective-viewer..PerspectiveViewer+toggleConfig)
37
38
39* * *
40
41<a name="module_perspective-viewer..PerspectiveViewer"></a>
42
43### perspective-viewer~PerspectiveViewer ⇐ <code>HTMLElement</code>
44**Kind**: inner class of [<code>perspective-viewer</code>](#module_perspective-viewer)
45**Extends**: <code>HTMLElement</code>
46
47* [~PerspectiveViewer](#module_perspective-viewer..PerspectiveViewer) ⇐ <code>HTMLElement</code>
48 * [new PerspectiveViewer()](#new_module_perspective-viewer..PerspectiveViewer_new)
49 * [.sort](#module_perspective-viewer..PerspectiveViewer+sort) : <code>[ &#x27;array&#x27; ].&lt;string&gt;</code>
50 * [.columns](#module_perspective-viewer..PerspectiveViewer+columns)
51 * [.computed-columns](#module_perspective-viewer..PerspectiveViewer+computed-columns)
52 * [.aggregates](#module_perspective-viewer..PerspectiveViewer+aggregates)
53 * [.filters](#module_perspective-viewer..PerspectiveViewer+filters) : <code>array</code>
54 * [.plugin](#module_perspective-viewer..PerspectiveViewer+plugin) : <code>string</code>
55 * [.column-pivots](#module_perspective-viewer..PerspectiveViewer+column-pivots) : <code>[ &#x27;Array&#x27; ].&lt;String&gt;</code>
56 * [.row-pivots](#module_perspective-viewer..PerspectiveViewer+row-pivots) : <code>[ &#x27;array&#x27; ].&lt;string&gt;</code>
57 * [.editable](#module_perspective-viewer..PerspectiveViewer+editable) : <code>boolean</code>
58 * [.throttle](#module_perspective-viewer..PerspectiveViewer+throttle) : <code>integer</code> \| <code>string</code>
59 * [.worker](#module_perspective-viewer..PerspectiveViewer+worker)
60 * [.table](#module_perspective-viewer..PerspectiveViewer+table)
61 * [.view](#module_perspective-viewer..PerspectiveViewer+view)
62 * [.load(data)](#module_perspective-viewer..PerspectiveViewer+load) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;void&gt;</code>
63 * [.update(data)](#module_perspective-viewer..PerspectiveViewer+update)
64 * [.notifyResize()](#module_perspective-viewer..PerspectiveViewer+notifyResize)
65 * [.clone(widget)](#module_perspective-viewer..PerspectiveViewer+clone)
66 * [.delete(delete_table)](#module_perspective-viewer..PerspectiveViewer+delete) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;boolean&gt;</code>
67 * [.restyleElement()](#module_perspective-viewer..PerspectiveViewer+restyleElement)
68 * [.save()](#module_perspective-viewer..PerspectiveViewer+save) ⇒ <code>object</code>
69 * [.restore(config)](#module_perspective-viewer..PerspectiveViewer+restore) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;void&gt;</code>
70 * [.flush()](#module_perspective-viewer..PerspectiveViewer+flush) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;void&gt;</code>
71 * [.clear()](#module_perspective-viewer..PerspectiveViewer+clear)
72 * [.replace()](#module_perspective-viewer..PerspectiveViewer+replace)
73 * [.reset()](#module_perspective-viewer..PerspectiveViewer+reset)
74 * [.copy()](#module_perspective-viewer..PerspectiveViewer+copy)
75 * [.toggleConfig()](#module_perspective-viewer..PerspectiveViewer+toggleConfig)
76
77
78* * *
79
80<a name="new_module_perspective-viewer..PerspectiveViewer_new"></a>
81
82#### new PerspectiveViewer()
83The HTMLElement class for `<perspective-viewer>` custom element. This class is not exported, so this constructor cannot be invoked in the typical manner; instead, instances of the class are created through the Custom Elements DOM API. Properties of an instance of this class, such as [module:perspective_viewer~PerspectiveViewer#columns](module:perspective_viewer~PerspectiveViewer#columns), are reflected on the DOM element as Attributes, and should be accessed as such - e.g. `instance.setAttribute("columns", JSON.stringify(["a", "b"]))`.
84
85**Example**
86```js
87// Create a new `<perspective-viewer>` const elem = document.createElement("perspective-viewer"); elem.setAttribute("columns", JSON.stringify(["a", "b"])); document.body.appendChild(elem);
88```
89
90* * *
91
92<a name="module_perspective-viewer..PerspectiveViewer+sort"></a>
93
94#### perspectiveViewer.sort : <code>[ &#x27;array&#x27; ].&lt;string&gt;</code>
95Sets this `perspective.table.view`'s `sort` property, an array of column names.
96
97**Kind**: instance property of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
98**Emits**: <code>PerspectiveViewer#event:perspective-config-update</code>
99**Example** *(via Javascript DOM)*
100```js
101let elem = document.getElementById('my_viewer');
102elem.setAttribute('sort', JSON.stringify([["x","desc"]));
103```
104**Example** *(via HTML)*
105```js
106<perspective-viewer sort='[["x","desc"]]'></perspective-viewer>
107```
108
109* * *
110
111<a name="module_perspective-viewer..PerspectiveViewer+columns"></a>
112
113#### perspectiveViewer.columns
114The set of visible columns.
115
116**Kind**: instance property of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
117**Emits**: <code>PerspectiveViewer#event:perspective-config-update</code>
118**Params**
119
120- columns <code>array</code> - An array of strings, the names of visible columns.
121
122**Example** *(via Javascript DOM)*
123```js
124let elem = document.getElementById('my_viewer');
125elem.setAttribute('columns', JSON.stringify(["x", "y'"]));
126```
127**Example** *(via HTML)*
128```js
129<perspective-viewer columns='["x", "y"]'></perspective-viewer>
130```
131
132* * *
133
134<a name="module_perspective-viewer..PerspectiveViewer+computed-columns"></a>
135
136#### perspectiveViewer.computed-columns
137The set of visible columns.
138
139**Kind**: instance property of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
140**Emits**: <code>PerspectiveViewer#event:perspective-config-update</code>
141**Params**
142
143- computed-columns <code>array</code> - An array of computed column objects
144
145**Example** *(via Javascript DOM)*
146```js
147let elem = document.getElementById('my_viewer');
148elem.setAttribute('computed-columns', JSON.stringify([{name: "x+y", func: "add", inputs: ["x", "y"]}]));
149```
150**Example** *(via HTML)*
151```js
152<perspective-viewer computed-columns="[{name:'x+y',func:'add',inputs:['x','y']}]""></perspective-viewer>
153```
154
155* * *
156
157<a name="module_perspective-viewer..PerspectiveViewer+aggregates"></a>
158
159#### perspectiveViewer.aggregates
160The set of column aggregate configurations.
161
162**Kind**: instance property of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
163**Emits**: <code>PerspectiveViewer#event:perspective-config-update</code>
164**Params**
165
166- aggregates <code>object</code> - A dictionary whose keys are column names, and values are valid aggregations. The `aggregates` attribute works as an override; in lieu of a key for a column supplied by the developers, a default will be selected and reflected to the attribute based on the column's type. See [perspective/src/js/defaults.js](perspective/src/js/defaults.js)
167
168**Example** *(via Javascript DOM)*
169```js
170let elem = document.getElementById('my_viewer');
171elem.setAttribute('aggregates', JSON.stringify({x: "distinct count"}));
172```
173**Example** *(via HTML)*
174```js
175<perspective-viewer aggregates='{"x": "distinct count"}'>
176</perspective-viewer>
177```
178
179* * *
180
181<a name="module_perspective-viewer..PerspectiveViewer+filters"></a>
182
183#### perspectiveViewer.filters : <code>array</code>
184The set of column filter configurations.
185
186**Kind**: instance property of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
187**Emits**: <code>PerspectiveViewer#event:perspective-config-update</code>
188**Example** *(via Javascript DOM)*
189```js
190let filters = [
191 ["x", "<", 3],
192 ["y", "contains", "abc"]
193];
194let elem = document.getElementById('my_viewer');
195elem.setAttribute('filters', JSON.stringify(filters));
196```
197**Example** *(via HTML)*
198```js
199<perspective-viewer filters='[["x", "<", 3], ["y", "contains", "abc"]]'>
200</perspective-viewer>
201```
202
203* * *
204
205<a name="module_perspective-viewer..PerspectiveViewer+plugin"></a>
206
207#### perspectiveViewer.plugin : <code>string</code>
208Sets the currently selected plugin, via its `name` field.
209
210**Kind**: instance property of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
211**Emits**: <code>PerspectiveViewer#event:perspective-config-update</code>
212
213* * *
214
215<a name="module_perspective-viewer..PerspectiveViewer+column-pivots"></a>
216
217#### perspectiveViewer.column-pivots : <code>[ &#x27;Array&#x27; ].&lt;String&gt;</code>
218Sets this `perspective.table.view`'s `column_pivots` property.
219
220**Kind**: instance property of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
221**Emits**: <code>PerspectiveViewer#event:perspective-config-update</code>
222
223* * *
224
225<a name="module_perspective-viewer..PerspectiveViewer+row-pivots"></a>
226
227#### perspectiveViewer.row-pivots : <code>[ &#x27;array&#x27; ].&lt;string&gt;</code>
228Sets this `perspective.table.view`'s `row_pivots` property.
229
230**Kind**: instance property of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
231**Emits**: <code>PerspectiveViewer#event:perspective-config-update</code>
232
233* * *
234
235<a name="module_perspective-viewer..PerspectiveViewer+editable"></a>
236
237#### perspectiveViewer.editable : <code>boolean</code>
238Determines whether this viewer is editable or not (though it is ultimately up to the plugin as to whether editing is implemented).
239
240**Kind**: instance property of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
241**Emits**: <code>PerspectiveViewer#event:perspective-config-update</code>
242
243* * *
244
245<a name="module_perspective-viewer..PerspectiveViewer+throttle"></a>
246
247#### perspectiveViewer.throttle : <code>integer</code> \| <code>string</code>
248Determines the render throttling behavior. Can be an integer, for millisecond window to throttle render event; or, if `undefined`, will try to determine the optimal throttle time from this component's render framerate.
249
250**Kind**: instance property of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
251**Example**
252```js
253<!-- Only draws at most 1 frame/sec. --> <perspective-viewer throttle="1000"></perspective-viewer>
254```
255
256* * *
257
258<a name="module_perspective-viewer..PerspectiveViewer+worker"></a>
259
260#### perspectiveViewer.worker
261This element's `perspective` worker instance. This property is not reflected as an HTML attribute, and is readonly; it can be effectively set however by calling the `load() method with a `perspective.table` instance from the preferred worker.
262
263**Kind**: instance property of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
264**Read only**: true
265**Example**
266```js
267let elem = document.getElementById('my_viewer'); let table = elem.worker.table([{x:1, y:2}]); elem.load(table);
268```
269
270* * *
271
272<a name="module_perspective-viewer..PerspectiveViewer+table"></a>
273
274#### perspectiveViewer.table
275This element's `perspective.table` instance.
276
277**Kind**: instance property of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
278**Read only**: true
279
280* * *
281
282<a name="module_perspective-viewer..PerspectiveViewer+view"></a>
283
284#### perspectiveViewer.view
285This element's `perspective.table.view` instance. The instance itself will change after every `PerspectiveViewer#perspective-config-update` event.
286
287**Kind**: instance property of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
288**Read only**: true
289
290* * *
291
292<a name="module_perspective-viewer..PerspectiveViewer+load"></a>
293
294#### perspectiveViewer.load(data) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;void&gt;</code>
295Load data. If `load` or `update` have already been called on this element, its internal `perspective.table` will also be deleted.
296
297**Kind**: instance method of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
298**Returns**: <code>[ &#x27;Promise&#x27; ].&lt;void&gt;</code> - A promise which resolves once the data is loaded and a `perspective.view` has been created.
299**Emits**: <code>module:perspective\_viewer~PerspectiveViewer#perspective-click PerspectiveViewer#perspective-view-update ]);event:</code>
300**Params**
301
302- data <code>any</code> - The data to load. Works with the same input types supported by `perspective.table`.
303
304**Example** *(Load CSV)*
305```js
306const my_viewer = document.getElementById('#my_viewer');
307my_viewer.load("x,y\n1,a\n2,b");
308```
309**Example** *(Load perspective.table)*
310```js
311const my_viewer = document.getElementById('#my_viewer');
312const tbl = perspective.table("x,y\n1,a\n2,b");
313my_viewer.load(tbl);
314```
315**Example** *(Load Promise&lt;perspective.table&gt;)*
316```js
317const my_viewer = document.getElementById('#my_viewer');
318const tbl = async () => perspective.table("x,y\n1,a\n2,b");
319my_viewer.load(tbl);
320```
321
322* * *
323
324<a name="module_perspective-viewer..PerspectiveViewer+update"></a>
325
326#### perspectiveViewer.update(data)
327Updates this element's `perspective.table` with new data.
328
329**Kind**: instance method of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
330**Emits**: <code>PerspectiveViewer#event:perspective-view-update</code>
331**Params**
332
333- data <code>any</code> - The data to load. Works with the same input types supported by `perspective.table.update`.
334
335**Example**
336```js
337const my_viewer = document.getElementById('#my_viewer'); my_viewer.update([ {x: 1, y: 'a'}, {x: 2, y: 'b'} ]);
338```
339
340* * *
341
342<a name="module_perspective-viewer..PerspectiveViewer+notifyResize"></a>
343
344#### perspectiveViewer.notifyResize()
345Determine whether to reflow the viewer and redraw.
346
347**Kind**: instance method of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
348
349* * *
350
351<a name="module_perspective-viewer..PerspectiveViewer+clone"></a>
352
353#### perspectiveViewer.clone(widget)
354Duplicate an existing `<perspective-element>`, including data and view settings. The underlying `perspective.table` will be shared between both elements
355
356**Kind**: instance method of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
357**Params**
358
359- widget <code>any</code> - A `<perspective-viewer>` instance to clone.
360
361
362* * *
363
364<a name="module_perspective-viewer..PerspectiveViewer+delete"></a>
365
366#### perspectiveViewer.delete(delete_table) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;boolean&gt;</code>
367Deletes this element's data and clears it's internal state (but not its user state). This (or the underlying `perspective.table`'s equivalent method) must be called in order for its memory to be reclaimed.
368
369**Kind**: instance method of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
370**Returns**: <code>[ &#x27;Promise&#x27; ].&lt;boolean&gt;</code> - Whether or not this call resulted in the underlying `perspective.table` actually being deleted.
371**Params**
372
373- delete_table <code>boolean</code> <code> = true</code> - Should a delete call also be made to the underlying `table()`.
374
375
376* * *
377
378<a name="module_perspective-viewer..PerspectiveViewer+restyleElement"></a>
379
380#### perspectiveViewer.restyleElement()
381Restyles the elements and to pick up any style changes
382
383**Kind**: instance method of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
384
385* * *
386
387<a name="module_perspective-viewer..PerspectiveViewer+save"></a>
388
389#### perspectiveViewer.save() ⇒ <code>object</code>
390Serialize this element's attribute/interaction state.
391
392**Kind**: instance method of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
393**Returns**: <code>object</code> - a serialized element.
394
395* * *
396
397<a name="module_perspective-viewer..PerspectiveViewer+restore"></a>
398
399#### perspectiveViewer.restore(config) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;void&gt;</code>
400Restore this element to a state as generated by a reciprocal call to `save` or `serialize`.
401
402**Kind**: instance method of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
403**Returns**: <code>[ &#x27;Promise&#x27; ].&lt;void&gt;</code> - A promise which resolves when the changes have been applied.
404**Params**
405
406- config <code>object</code> | <code>string</code> - returned by `save` or `serialize`.
407
408
409* * *
410
411<a name="module_perspective-viewer..PerspectiveViewer+flush"></a>
412
413#### perspectiveViewer.flush() ⇒ <code>[ &#x27;Promise&#x27; ].&lt;void&gt;</code>
414Flush any pending attribute modifications to this element.
415
416**Kind**: instance method of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
417**Returns**: <code>[ &#x27;Promise&#x27; ].&lt;void&gt;</code> - A promise which resolves when the current attribute state has been applied.
418
419* * *
420
421<a name="module_perspective-viewer..PerspectiveViewer+clear"></a>
422
423#### perspectiveViewer.clear()
424Clears the rows in the current [table](table).
425
426**Kind**: instance method of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
427
428* * *
429
430<a name="module_perspective-viewer..PerspectiveViewer+replace"></a>
431
432#### perspectiveViewer.replace()
433Replaces all rows in the current [table](table).
434
435**Kind**: instance method of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
436
437* * *
438
439<a name="module_perspective-viewer..PerspectiveViewer+reset"></a>
440
441#### perspectiveViewer.reset()
442Reset's this element's view state and attributes to default. Does not delete this element's `perspective.table` or otherwise modify the data state.
443
444**Kind**: instance method of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
445
446* * *
447
448<a name="module_perspective-viewer..PerspectiveViewer+copy"></a>
449
450#### perspectiveViewer.copy()
451Copies this element's view data (as a CSV) to the clipboard. This method must be called from an event handler, subject to the browser's restrictions on clipboard access. See [https://www.w3.org/TR/clipboard-apis/#allow-read-clipboard](https://www.w3.org/TR/clipboard-apis/#allow-read-clipboard).
452
453**Kind**: instance method of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
454
455* * *
456
457<a name="module_perspective-viewer..PerspectiveViewer+toggleConfig"></a>
458
459#### perspectiveViewer.toggleConfig()
460Opens/closes the element's config menu.
461
462**Kind**: instance method of [<code>PerspectiveViewer</code>](#module_perspective-viewer..PerspectiveViewer)
463
464* * *
465