perspective 2.4.0

A data visualization and analytics component, especially well-suited for large and/or streaming datasets.
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
# @finos/perspective-viewer

Module for the `<perspective-viewer>` custom element.  This module has no
(real) exports, but importing it has a side effect: the
`PerspectiveViewerElement`class is registered as a custom element, after
which it can be used as a standard DOM element.

Though `<perspective-viewer>` is written mostly in Rust, the nature
of WebAssembly's compilation makes it a dynamic module;  in order to
guarantee that the Custom Elements extension methods are registered
synchronously with this package's import, we need perform said registration
within this wrapper module.  As a result, the API methods of the Custom
Elements are all `async` (as they must await the wasm module instance).

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")`.

## Table of contents

### Classes

- [HTMLPerspectiveViewerElement]#HTMLPerspectiveViewerElement
- [HTMLPerspectiveViewerPluginElement]#HTMLPerspectiveViewerPluginElement

### Interfaces

- [IPerspectiveViewerElement]#IPerspectiveViewerElement
- [IPerspectiveViewerPlugin]#IPerspectiveViewerPlugin

### Type Aliases

- [PerspectiveViewerConfig]#perspectiveviewerconfig

### Variables

- [default]#default

### Functions

- [convert]#convert

## Type Aliases

### PerspectiveViewerConfig

Ƭ **PerspectiveViewerConfig**: `perspective.ViewConfig` & { `plugin?`: `string` ; `plugin_config?`: `any` ; `settings?`: `boolean`  }

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:15](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L15)

## Variables

### default

• **default**: `Object`

#### Defined in

[rust/perspective-viewer/src/ts/perspective-viewer.ts:44](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/perspective-viewer.ts#L44)

## Functions

### convert

▸ **convert**(`old`, `options?`): `Record`<`string`, `unknown`\> \| `ArrayBuffer` \| `string`

A migration utility for `@finos/perspective-viewer` and
`@finos/perspective-workspace` persisted state objects.  If you have an
application which persists tokens returned by the `.save()` method of a
Perspective Custom Element, and you want to upgrade Perspective to the latest
version, this module is for you!  You know who you are!

Say you have a `<perspective-viewer>` Custom Element from
`@finos/perspective-viewer>=0.8.3`, and have persisted an arbitrary persistence
token object:

```javascript
const old_elem = document.querySelector("perspective-viewer");
const old_token = await old_elem.save();
```

To migrate this token to the version of `@finos/perspective-migrate` itself:

```javascript
import {convert} from "@finos/perspective-viewer`;

// ...

const new_elem = document.querySelector("perspective-viewer");
const new_token = convert(old_token);
await new_elem.restore(new_token);
```

`convert` can also be imported in node for converting persisted tokens
outside the browser.

```javascript
const {convert} = require("@finos/perspective-viewer/dist/cjs/migrate.js");
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `old` | `string` \| `ArrayBuffer` \| `Record`<`string`, `unknown`\> | the layout to convert, in `<perspective-viewer>` or `<perspective-workspace>` format. |
| `options` | `PerspectiveConvertOptions` | a `PerspectiveConvertOptions` object specifying the convert options for this call. |

#### Returns

`Record`<`string`, `unknown`\> \| `ArrayBuffer` \| `string`

a layout for either `<perspective-viewer>` or
`<perspective-workspace>`, updated to the perspective version of this
script's package.

#### Defined in

[rust/perspective-viewer/src/ts/migrate.ts:55](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/migrate.ts#L55)


# Interface: IPerspectiveViewerElement

The Custom Elements implementation for `<perspective-viewer>`, as well at its
API.  `PerspectiveViewerElement` should not be constructed directly (like its
parent class `HTMLElement`);  instead, use `document.createElement()` or
declare your `<perspective-viewer>` element in HTML.  Once instantiated,
`<perspective-viewer>` works just like a standard `HTMLElement`, with a few
extra perspective-specific methods.

**`Example`**

```javascript
const viewer = document.createElement("perspective-viewer");
```

**`Example`**

```javascript
document.body.innerHTML = `
    <perspective-viewer id="viewer"></perspective-viewer>
`;
const viewer = document.body.querySelector("#viewer");
```

## Hierarchy

- **`IPerspectiveViewerElement`**

  [`HTMLPerspectiveViewerElement`]#`HTMLPerspectiveViewerElement`

## Implemented by

- [`HTMLPerspectiveViewerElement`]#`HTMLPerspectiveViewerElement`

## Table of contents

### Data Methods

- [getTable]#gettable
- [getView]#getview
- [load]#load

### Internal Methods

- [unsafeGetModel]#unsafegetmodel

### Other Methods

- [restore]#restore

### Persistence Methods

- [reset]#reset
- [save]#save

### Plugin Methods

- [getAllPlugins]#getallplugins
- [getPlugin]#getplugin

### UI Action Methods

- [copy]#copy
- [download]#download
- [toggleConfig]#toggleconfig

### Util Methods

- [delete]#delete
- [flush]#flush
- [getEditPort]#geteditport
- [notifyResize]#notifyresize
- [resetThemes]#resetthemes
- [restyleElement]#restyleelement
- [setAutoSize]#setautosize
- [setThrottle]#setthrottle

## Data Methods

### getTable

▸ **getTable**(`wait_for_table?`): `Promise`<`Table`\>

Returns the `perspective.Table()` which was supplied to `load()`

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `wait_for_table?` | `boolean` | Whether to await `load()` if it has not yet been invoked, or fail immediately. |

#### Returns

`Promise`<`Table`\>

A `Promise` which resolves to a `perspective.Table`

**`Example`**

<caption>Share a `Table`</caption>

```javascript
const viewers = document.querySelectorAll("perspective-viewer");
const [viewer1, viewer2] = Array.from(viewers);
const table = await viewer1.getTable();
await viewer2.load(table);
```

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:128](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L128)

___

### getView

▸ **getView**(): `Promise`<`View`\>

Returns the underlying `perspective.View` currently configured for this
`<perspective-viewer>`.  Because ownership of the `perspective.View` is
mainainted by the `<perspective-viewer>` it was created by, this `View`
may become deleted (invalidated by calling `delete()`) at any time -
specifically, it will be deleted whenever the `PerspectiveViewConfig`
changes.  Because of this, when using this API, prefer calling
`getView()` repeatedly over caching the returned `perspective.View`,
especially in `async` contexts.

#### Returns

`Promise`<`View`\>

A `Promise` which ressolves to a `perspective.View`.

**`Example`**

<caption>Collapse grid to root</caption>

```javascript
const viewer = document.querySelector("perspective-viewer");
const view = await viewer.getView();
await view.set_depth(0);
```

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:150](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L150)

___

### load

▸ **load**(`table`): `Promise`<`void`\>

Load a `perspective.Table`.  If `load` or `update` have already been
called on this element, its internal `perspective.Table` will _not_ be
deleted, but it will bed de-referenced by this `<perspective-viewer>`.

#### Parameters

| Name | Type |
| :------ | :------ |
| `table` | `Table` \| `Promise`<`Table`\> |

#### Returns

`Promise`<`void`\>

A promise which resolves once the data is
loaded, a `perspective.View` has been created, and the active plugin has
rendered.

**`Example`**

<caption>Load perspective.table</caption>

```javascript
const my_viewer = document.getElementById('#my_viewer');
const tbl = perspective.table("x,y\n1,a\n2,b");
my_viewer.load(tbl);
```

**`Example`**

<caption>Load Promise&lt;perspective.table&gt;</caption>

```javascript
const my_viewer = document.getElementById('#my_viewer');
const tbl = perspective.table("x,y\n1,a\n2,b");
my_viewer.load(tbl);
```

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:67](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L67)

___

## Internal Methods

### unsafeGetModel

▸ **unsafeGetModel**(): `number`

Get the raw pointer to this `<perspective-viewer>` WASM model, such that
it may be passed back to WASM function calls that take a
`PerspectiveViewerElement` as an argument.

#### Returns

`number`

A pointer to this model

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:436](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L436)

___

## Other Methods

### restore

▸ **restore**(`config`): `Promise`<`void`\>

Restore this element to a state as generated by a reciprocal call to
`save`.  In `json` (default) format, `PerspectiveViewerConfig`'s fields
have specific semantics:

 - When a key is missing, this field is ignored;  `<perspective-viewer>`
   will maintain whatever settings for this field is currently applied.
 - When the key is supplied, but the value is `undefined`, the field is
   reset to its default value for this current `View`, i.e. the state it
   would be in after `load()` resolves.
 - When the key is defined to a value, the value is applied for this
   field.

This behavior is convenient for explicitly controlling current vs desired
UI state in a single request, but it does make it a bit inconvenient to
use `restore()` to reset a `<perspective-viewer>` to default as you must
do so explicitly for each key;  for this case, use `reset()` instead of
restore.

As noted in `save()`, this configuration state does not include the
`Table` or its `Schema`.  In order for `restore()` to work correctly, it
must be called on a `<perspective-viewer>` that has a `Table already
`load()`-ed, with the same (or a type-compatible superset) `Schema`.
It does not need have the same rows, or even be populated.

@category Persistence
@param config returned by `save()`.  This can be any format returned by
`save()`; the specific deserialization is chosen by `typeof config`.
@returns A promise which resolves when the changes have been applied and
rendered.
@example <caption>Restore a viewer from `localStorage`</caption>

```javascript
const viewer = document.querySelector("perspective-viewer");
const token = localStorage.getItem("viewer_state");
await viewer.restore(token);
```

#### Parameters

| Name | Type |
| :------ | :------ |
| `config` | `string` \| [`PerspectiveViewerConfig`]#perspectiveviewerconfig \| `ArrayBuffer` |

#### Returns

`Promise`<`void`\>

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:190](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L190)

___

## Persistence Methods

### reset

▸ **reset**(`all`): `Promise`<`void`\>

Reset's this element's view state and attributes to default.  Does not
delete this element's `perspective.table` or otherwise modify the data
state.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `all` | `any` | Should `expressions` param be reset as well, defaults to |

#### Returns

`Promise`<`void`\>

**`Example`**

```javascript
const viewer = document.querySelector("perspective-viewer");
await viewer.reset();
```

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:258](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L258)

___

### save

▸ **save**(): `Promise`<[`PerspectiveViewerConfig`](#perspectiveviewerconfig)\>

Serialize this element's attribute/interaction state, but _not_ the
`perspective.Table` or its `Schema`.  `save()` is designed to be used in
conjunction with `restore()` to persist user settings and bookmarks, but
the `PerspectiveViewerConfig` object returned in `json` format can also
be written by hand quite easily, which is useful for authoring
pre-conceived configs.

#### Returns

`Promise`<[`PerspectiveViewerConfig`](#perspectiveviewerconfig)\>

a serialized element in the chosen format.

**`Example`**

<caption>Save a viewer to `localStorage`</caption>

```javascript
const viewer = document.querySelector("perspective-viewer");
const token = await viewer.save("string");
localStorage.setItem("viewer_state", token);
```

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:215](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L215)

▸ **save**(`format`): `Promise`<[`PerspectiveViewerConfig`](#perspectiveviewerconfig)\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `format` | ``"json"`` |

#### Returns

`Promise`<[`PerspectiveViewerConfig`](#perspectiveviewerconfig)\>

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:216](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L216)

▸ **save**(`format`): `Promise`<`ArrayBuffer`\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `format` | ``"arraybuffer"`` |

#### Returns

`Promise`<`ArrayBuffer`\>

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:217](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L217)

▸ **save**(`format`): `Promise`<`string`\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `format` | ``"string"`` |

#### Returns

`Promise`<`string`\>

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:218](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L218)

▸ **save**(`format?`): `Promise`<`string` \| [`PerspectiveViewerConfig`](#perspectiveviewerconfig) \| `ArrayBuffer`\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `format?` | ``"string"`` \| ``"json"`` \| ``"arraybuffer"`` |

#### Returns

`Promise`<`string` \| [`PerspectiveViewerConfig`](#perspectiveviewerconfig) \| `ArrayBuffer`\>

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:219](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L219)

___

## Plugin Methods

### getAllPlugins

▸ **getAllPlugins**(): `HTMLElement`[]

Get all plugin custom element instances, in order of registration.

If no plugins have been registered (via `registerPlugin()`), calling
`getAllPlugins()` will cause `perspective-viewer-plugin` to be registered
as a side effect.

#### Returns

`HTMLElement`[]

An `Array` of the plugin instances for this
`<perspective-viewer>`.

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:426](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L426)

___

### getPlugin

▸ **getPlugin**(`name?`): `Promise`<`HTMLElement`\>

Get the currently active plugin custom element instance, or a specific
named instance if requested.  `getPlugin(name)` does not activate the
plugin requested, so if this plugin is not active the returned
`HTMLElement` will not have a `parentElement`.

If no plugins have been registered (via `registerPlugin()`), calling
`getPlugin()` will cause `perspective-viewer-plugin` to be registered as
a side effect.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name?` | `string` | Optionally a specific plugin name, defaulting to the current active plugin. |

#### Returns

`Promise`<`HTMLElement`\>

The active or requested plugin instance.

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:413](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L413)

___

## UI Action Methods

### copy

▸ **copy**(`flat`): `Promise`<`void`\>

Copies 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).

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `flat` | `boolean` | Whether to use the element's current view config, or to use a default "flat" view. |

#### Returns

`Promise`<`void`\>

**`Example`**

```javascript
const viewer = document.querySelector("perspective-viewer");
const button = document.querySelector("button");
button.addEventListener("click", async () => {
    await viewer.copy();
});
```

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:298](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L298)

___

### download

▸ **download**(`flat`): `Promise`<`void`\>

Download this element's data as a CSV file.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `flat` | `boolean` | Whether to use the element's current view config, or to use a default "flat" view. |

#### Returns

`Promise`<`void`\>

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:278](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L278)

___

### toggleConfig

▸ **toggleConfig**(`force?`): `Promise`<`void`\>

Opens/closes the element's config menu, equivalent to clicking the
settings button in the UI.  This method is equivalent to
`viewer.restore({settings: force})` when `force` is present, but
`restore()` cannot toggle as `toggleConfig()` can, you would need to
first read the settings state from `save()` otherwise.

Calling `toggleConfig()` may be delayed if an async render is currently
in process, and it may only partially render the UI if `load()` has not
yet resolved.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `force?` | `boolean` | If supplied, explicitly set the config state to "open" (`true`) or "closed" (`false`). |

#### Returns

`Promise`<`void`\>

**`Example`**

```javascript
await viewer.toggleConfig();
```

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:396](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L396)

___

## Util Methods

### delete

▸ **delete**(): `Promise`<`void`\>

Deletes this element and clears it's internal state (but not its
user state).  This (or the underlying `perspective.view`'s equivalent
method) must be called in order for its memory to be reclaimed, as well
as the reciprocal method on the `perspective.table` which this viewer is
bound to.

#### Returns

`Promise`<`void`\>

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:269](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L269)

___

### flush

▸ **flush**(): `Promise`<`void`\>

Flush any pending modifications to this `<perspective-viewer>`.  Since
`<perspective-viewer>`'s API is almost entirely `async`, it may take
some milliseconds before any method call such as `restore()` affects
the rendered element.  If you want to make sure any invoked method which
affects the rendered has had its results rendered, call and await
`flush()`

#### Returns

`Promise`<`void`\>

A promise which resolves when the current
pending state changes have been applied and rendered.

**`Example`**

<caption>Flush an unawaited `restore()`</caption>

```javascript
const viewer = document.querySelector("perspective-viewer");
viewer.restore({group_by: ["State"]});
await viewer.flush();
console.log("Viewer has been rendered with a pivot!");
```

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:243](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L243)

___

### getEditPort

▸ **getEditPort**(): `number`

Gets the edit port, the port number for which `Table` updates from this
`<perspective-viewer>` are generated.  This port number will be present
in the options object for a `View.on_update()` callback for any update
which was originated by the `<perspective-viewer>`/user, which can be
used to distinguish server-originated updates from user edits.

#### Returns

`number`

A promise which resolves to the current edit port.

**`Example`**

```javascript
const viewer = document.querySelector("perspective-viewer");
const editport = await viewer.getEditPort();
const table = await viewer.getTable();
const view = await table.view();
view.on_update(obj => {
    if (obj.port_id = editport) {
        console.log("User edit detected");
    }
});
```

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:357](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L357)

___

### notifyResize

▸ **notifyResize**(`force`): `Promise`<`void`\>

Redraw this `<perspective-viewer>` and plugin when its dimensions or
visibility has been updated.  By default, `<perspective-viewer>` will
auto-size when its own dimensions change, so this method need not be
called;  when disabled via `setAutoSize(false)` however, this method
_must_ be called, and will not respond to dimension or style changes to
its parent container otherwise.  `notifyResize()` does not recalculate
the current `View`, but all plugins will re-request the data window
(which itself may be smaller or larger due to resize).

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `force` | `any` | Whether to re-render, even if the dimenions have not changed. When set to `false` and auto-size is enabled (the defaults), calling this method will automatically disable auto-size. |

#### Returns

`Promise`<`void`\>

A `Promise<void>` which resolves when this resize event has
finished rendering.

**`Example`**

<caption>Bind `notfyResize()` to browser dimensions</caption>

```javascript
const viewer = document.querySelector("perspective-viewer");
viewer.setAutoSize(false);
window.addEventListener("resize", () => viewer.notifyResize());
```

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:93](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L93)

___

### resetThemes

▸ **resetThemes**(`themes?`): `Promise`<`void`\>

Sets the theme names available via the `<perspective-viewer>` status bar
UI.  Typically these will be auto-detected simply by including the
theme `.css` in a `<link>` tag;  however, auto-detection can fail if
the `<link>` tag is not a same-origin request due to CORS.  For servers
configured to allow cross-origin requests, you can use the
[`crossorigin` attribute](https://html.spec.whatwg.org/multipage/semantics.html#attr-link-crossorigin)
to enable detection, e.g. `<link crossorigin="anonymous" .. >`.  If for
whatever reason auto-detection still fails, you may set the themes via
this method.  Note the theme `.css` must still be loaded in this case -
the `resetThemes()` method only lets the `<perspective-viewer>` know what
theme names are available.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `themes?` | `string`[] | A list of theme names to use, or auto-detect from document's stylesheets if `undefined`. |

#### Returns

`Promise`<`void`\>

**`Example`**

```javascript
const viewer = document.querySelector("perspective-viewer");
await viewer.resetThemes(["Pro Light", "Pro Dark"]);
```

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:333](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L333)

___

### restyleElement

▸ **restyleElement**(): `Promise`<`void`\>

Restyles the elements and to pick up any style changes.  While most of
perspective styling is plain CSS and can be updated at any time, some
CSS rules are read and cached, e.g. the series colors for
`@finos/perspective-viewer-d3fc` which are read from CSS then reapplied
as SVG and Canvas attributes.

#### Returns

`Promise`<`void`\>

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:309](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L309)

___

### setAutoSize

▸ **setAutoSize**(`autosize`): `void`

Determines the auto-size behavior.  When `true` (the default), this
element will re-render itself whenever its own dimensions change,
utilizing a `ResizeObserver`;  when `false`, you must explicitly call
`notifyResize()` when the element's dimensions have changed.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `autosize` | `any` | Whether to re-render when this element's dimensions change. |

#### Returns

`void`

**`Example`**

<caption>Disable auto-size</caption>

```javascript
await viewer.setAutoSize(false);
```

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:110](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L110)

___

### setThrottle

▸ **setThrottle**(`value?`): `void`

Determines 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.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `value?` | `number` | an optional throttle rate in milliseconds (integer). If not supplied, adaptive throttling is calculated from the average plugin render time. |

#### Returns

`void`

**`Example`**

<caption>Limit FPS to 1 frame per second</caption>

```javascript
await viewer.setThrottle(1000);
```

#### Defined in

[rust/perspective-viewer/src/ts/viewer.ts:375](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/viewer.ts#L375)


# Interface: IPerspectiveViewerPlugin

The `IPerspectiveViewerPlugin` interface defines the necessary API for a
`<perspective-viewer>` plugin, which also must be an `HTMLElement` via the
Custom Elements API or otherwise.  Rather than implement this API from
scratch however, the simplest way is to inherit from
`<perspective-viewer-plugin>`, which implements `IPerspectiveViewerPlugin`
with non-offensive default implementations, where only the `draw()` and
`name()` methods need be overridden to get started with a simple plugin.

Note that plugins are frozen once a `<perspective-viewer>` has been
instantiated, so generally new plugin code must be executed at the module
level (if packaged as a library), or during application init to ensure global
availability of a plugin.

**`Example`**

```javascript
const BasePlugin = customElements.get("perspective-viewer-plugin");
class MyPlugin extends BasePlugin {
    get name() {
        return "My Plugin";
    }
    async draw(view) {
        const count = await view.num_rows();
        this.innerHTML = `View has ${count} rows`;
    }
}

customElements.define("my-plugin", MyPlugin);
const Viewer = customElements.get("perspective-viewer");
Viewer.registerPlugin("my-plugin");
```

**`No Inherit Doc`**

## Implemented by

- [`HTMLPerspectiveViewerPluginElement`]#`HTMLPerspectiveViewerPluginElement`

## Table of contents

### Accessors

- [config\_column\_names]#config_column_names
- [min\_config\_columns]#min_config_columns
- [name]#name
- [priority]#priority
- [select\_mode]#select_mode

### Methods

- [clear]#clear
- [delete]#delete
- [draw]#draw
- [resize]#resize
- [restore]#restore
- [restyle]#restyle
- [save]#save
- [update]#update

## Accessors

### config\_column\_names

• `get` **config_column_names**(): `string`[]

The named column labels, if desired.  Named columns behave differently
in drag/drop mode than unnamed columns, having replace/swap behavior
rather than insert.  If provided, the length of `config_column_names`
_must_ be `>= min_config_columns`, as this is assumed by the drag/drop
logic.

#### Returns

`string`[]

#### Defined in

[rust/perspective-viewer/src/ts/plugin.ts:82](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/plugin.ts#L82)

___

### min\_config\_columns

• `get` **min_config_columns**(): `number`

The minimum number of columns required for this plugin to operate.
This mostly affects drag/drop and column remove button behavior,
preventing the use from applying configs which violate this min.

While this option can technically be `undefined` (as in the case of
`@finos/perspective-viewer-datagrid`), doing so currently has nearly
identical behavior to 1.

#### Returns

`number`

#### Defined in

[rust/perspective-viewer/src/ts/plugin.ts:73](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/plugin.ts#L73)

___

### name

• `get` **name**(): `string`

The name for this plugin, which is used as both it's unique key for use
as a parameter for the `plugin` field of a `ViewerConfig`, and as the
display name for this plugin in the `<perspective-viewer>` UI.

#### Returns

`string`

#### Defined in

[rust/perspective-viewer/src/ts/plugin.ts:54](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/plugin.ts#L54)

___

### priority

• `get` **priority**(): `number`

The load priority of the plugin. If the plugin shares priority with another,
the first to load has a higher priority.

A larger number has a higher priority.

The plugin with the highest priority will be loaded by default by the Perspective viewer.
If you would like to instead begin with a lower priority plugin, choose it explicitly with
a `HTMLPerspectiveViewerPluginElement.restore` call.

#### Returns

`number`

#### Defined in

[rust/perspective-viewer/src/ts/plugin.ts:94](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/plugin.ts#L94)

___

### select\_mode

• `get` **select_mode**(): `string`

Select mode determines how column add/remove buttons behave for this
plugin.  `"select"` mode exclusively selects the added column, removing
other columns.  `"toggle"` mode toggles the column on or off (dependent
on column state), leaving existing columns alone.

#### Returns

`string`

#### Defined in

[rust/perspective-viewer/src/ts/plugin.ts:62](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/plugin.ts#L62)

## Methods

### clear

▸ **clear**(): `Promise`<`void`\>

Clear this plugin, though it is up to the discretion of the plugin
author to determine what this means.  Defaults to resetting this
element's `innerHTML`, so be sure to override if you want custom
behavior.

#### Returns

`Promise`<`void`\>

**`Example`**

```javascript
async clear(): Promise<void> {
    this.innerHTML = "";
}
```

#### Defined in

[rust/perspective-viewer/src/ts/plugin.ts:138](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/plugin.ts#L138)

___

### delete

▸ **delete**(): `Promise`<`void`\>

Free any resources acquired by this plugin and prepare to be deleted.

#### Returns

`Promise`<`void`\>

#### Defined in

[rust/perspective-viewer/src/ts/plugin.ts:173](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/plugin.ts#L173)

___

### draw

▸ **draw**(`view`): `Promise`<`void`\>

Render this plugin using the provided `View`.  While there is no
provision to cancel a render in progress per se, calling a method on
a `View` which has been deleted will throw an exception.

#### Parameters

| Name | Type |
| :------ | :------ |
| `view` | `View` |

#### Returns

`Promise`<`void`\>

**`Example`**

```
async draw(view: perspective.View): Promise<void> {
    const csv = await view.to_csv();
    this.innerHTML = `<pre>${csv}</pre>`;
}
```

#### Defined in

[rust/perspective-viewer/src/ts/plugin.ts:109](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/plugin.ts#L109)

___

### resize

▸ **resize**(): `Promise`<`void`\>

Like `update()`, but for when the dimensions of the plugin have changed
and the underlying data has not.

#### Returns

`Promise`<`void`\>

#### Defined in

[rust/perspective-viewer/src/ts/plugin.ts:144](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/plugin.ts#L144)

___

### restore

▸ **restore**(`config`): `Promise`<`void`\>

Restore this plugin to a state previously returned by `save()`.

#### Parameters

| Name | Type |
| :------ | :------ |
| `config` | `any` |

#### Returns

`Promise`<`void`\>

#### Defined in

[rust/perspective-viewer/src/ts/plugin.ts:168](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/plugin.ts#L168)

___

### restyle

▸ **restyle**(): `Promise`<`void`\>

Notify the plugin that the style environment has changed.  Useful for
plugins which read CSS styles via `window.getComputedStyle()`.

#### Returns

`Promise`<`void`\>

#### Defined in

[rust/perspective-viewer/src/ts/plugin.ts:150](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/plugin.ts#L150)

___

### save

▸ **save**(): `Promise`<`any`\>

Save this plugin's state to a JSON-serializable value.  While this value
can be anything, it should work reciprocally with `restore()` to return
this plugin's renderer to the same state, though potentially with a
different `View`.

`save()` should be used for user-persistent settings that are
data-agnostic, so the user can have persistent view during refresh or
reload.  For example, `@finos/perspective-viewer-d3fc` uses
`plugin_config` to remember the user-repositionable legend coordinates.

#### Returns

`Promise`<`any`\>

#### Defined in

[rust/perspective-viewer/src/ts/plugin.ts:163](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/plugin.ts#L163)

___

### update

▸ **update**(`view`): `Promise`<`void`\>

Draw under the assumption that the `ViewConfig` has not changed since
the previous call to `draw()`, but the underlying data has.  Defaults to
dispatch to `draw()`.

#### Parameters

| Name | Type |
| :------ | :------ |
| `view` | `View` |

#### Returns

`Promise`<`void`\>

**`Example`**

```javascript
async update(view: perspective.View): Promise<void> {
    return this.draw(view);
}
```

#### Defined in

[rust/perspective-viewer/src/ts/plugin.ts:123](https://github.com/finos/perspective/blob/2096ed8bf/rust/perspective-viewer/src/ts/plugin.ts#L123)