UNPKG

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