UNPKG

@finos/perspective-viewer

Version:

The `<perspective-viewer>` Custom Element, frontend for Perspective.js

332 lines (192 loc) 8.86 kB
# Class: PerspectiveViewerPluginElement The `<perspective-viewer-plugin>` element, the default perspective plugin which is registered and activated automcatically when a `<perspective-viewer>` is loaded without plugins. While you will not typically instantiate this class directly, it is simple enough to function as a good "default" plugin implementation which can be extended to create custom plugins. **`example`** ```javascript class MyPlugin extends customElements.get("perspective-viewer-plugin") { // Custom plugin overrides } ``` ## Hierarchy - `HTMLElement` ↳ **`PerspectiveViewerPluginElement`** ## Implements - [`IPerspectiveViewerPlugin`](../interfaces/IPerspectiveViewerPlugin.md) ## Table of contents ### Constructors - [constructor](PerspectiveViewerPluginElement.md#constructor) ### Accessors - [config\_column\_names](PerspectiveViewerPluginElement.md#config_column_names) - [min\_config\_columns](PerspectiveViewerPluginElement.md#min_config_columns) - [name](PerspectiveViewerPluginElement.md#name) - [select\_mode](PerspectiveViewerPluginElement.md#select_mode) ### Methods - [clear](PerspectiveViewerPluginElement.md#clear) - [delete](PerspectiveViewerPluginElement.md#delete) - [draw](PerspectiveViewerPluginElement.md#draw) - [resize](PerspectiveViewerPluginElement.md#resize) - [restore](PerspectiveViewerPluginElement.md#restore) - [restyle](PerspectiveViewerPluginElement.md#restyle) - [save](PerspectiveViewerPluginElement.md#save) - [update](PerspectiveViewerPluginElement.md#update) ## Constructors ### constructor**new PerspectiveViewerPluginElement**() #### Overrides HTMLElement.constructor #### Defined in [rust/perspective-viewer/src/ts/plugin.ts:182](https://github.com/finos/perspective/blob/e19cc4010/rust/perspective-viewer/src/ts/plugin.ts#L182) ## 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:198](https://github.com/finos/perspective/blob/e19cc4010/rust/perspective-viewer/src/ts/plugin.ts#L198) ___ ### 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:194](https://github.com/finos/perspective/blob/e19cc4010/rust/perspective-viewer/src/ts/plugin.ts#L194) ___ ### 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:186](https://github.com/finos/perspective/blob/e19cc4010/rust/perspective-viewer/src/ts/plugin.ts#L186) ___ ### select\_mode • `get` **select_mode**(): ``"select"`` \| ``"toggle"`` 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 ``"select"`` \| ``"toggle"`` #### Defined in [rust/perspective-viewer/src/ts/plugin.ts:190](https://github.com/finos/perspective/blob/e19cc4010/rust/perspective-viewer/src/ts/plugin.ts#L190) ## 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`\> #### Implementation of [IPerspectiveViewerPlugin](../interfaces/IPerspectiveViewerPlugin.md).[clear](../interfaces/IPerspectiveViewerPlugin.md#clear) #### Defined in [rust/perspective-viewer/src/ts/plugin.ts:213](https://github.com/finos/perspective/blob/e19cc4010/rust/perspective-viewer/src/ts/plugin.ts#L213) ___ ### delete**delete**(): `Promise`<`void`\> Free any resources acquired by this plugin and prepare to be deleted. #### Returns `Promise`<`void`\> #### Implementation of [IPerspectiveViewerPlugin](../interfaces/IPerspectiveViewerPlugin.md).[delete](../interfaces/IPerspectiveViewerPlugin.md#delete) #### Defined in [rust/perspective-viewer/src/ts/plugin.ts:233](https://github.com/finos/perspective/blob/e19cc4010/rust/perspective-viewer/src/ts/plugin.ts#L233) ___ ### 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`\> #### Implementation of [IPerspectiveViewerPlugin](../interfaces/IPerspectiveViewerPlugin.md).[draw](../interfaces/IPerspectiveViewerPlugin.md#draw) #### Defined in [rust/perspective-viewer/src/ts/plugin.ts:206](https://github.com/finos/perspective/blob/e19cc4010/rust/perspective-viewer/src/ts/plugin.ts#L206) ___ ### 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`\> #### Implementation of [IPerspectiveViewerPlugin](../interfaces/IPerspectiveViewerPlugin.md).[resize](../interfaces/IPerspectiveViewerPlugin.md#resize) #### Defined in [rust/perspective-viewer/src/ts/plugin.ts:217](https://github.com/finos/perspective/blob/e19cc4010/rust/perspective-viewer/src/ts/plugin.ts#L217) ___ ### restore**restore**(): `Promise`<`void`\> Restore this plugin to a state previously returned by `save()`. #### Returns `Promise`<`void`\> #### Implementation of [IPerspectiveViewerPlugin](../interfaces/IPerspectiveViewerPlugin.md).[restore](../interfaces/IPerspectiveViewerPlugin.md#restore) #### Defined in [rust/perspective-viewer/src/ts/plugin.ts:229](https://github.com/finos/perspective/blob/e19cc4010/rust/perspective-viewer/src/ts/plugin.ts#L229) ___ ### 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`\> #### Implementation of [IPerspectiveViewerPlugin](../interfaces/IPerspectiveViewerPlugin.md).[restyle](../interfaces/IPerspectiveViewerPlugin.md#restyle) #### Defined in [rust/perspective-viewer/src/ts/plugin.ts:221](https://github.com/finos/perspective/blob/e19cc4010/rust/perspective-viewer/src/ts/plugin.ts#L221) ___ ### 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`\> #### Implementation of [IPerspectiveViewerPlugin](../interfaces/IPerspectiveViewerPlugin.md).[save](../interfaces/IPerspectiveViewerPlugin.md#save) #### Defined in [rust/perspective-viewer/src/ts/plugin.ts:225](https://github.com/finos/perspective/blob/e19cc4010/rust/perspective-viewer/src/ts/plugin.ts#L225) ___ ### 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`\> #### Implementation of [IPerspectiveViewerPlugin](../interfaces/IPerspectiveViewerPlugin.md).[update](../interfaces/IPerspectiveViewerPlugin.md#update) #### Defined in [rust/perspective-viewer/src/ts/plugin.ts:202](https://github.com/finos/perspective/blob/e19cc4010/rust/perspective-viewer/src/ts/plugin.ts#L202)