Struct PerspectiveViewerElement

Source
pub struct PerspectiveViewerElement { /* private fields */ }
Expand description

The <perspective-viewer> custom element.

§JavaScript Examples

Create a new <perspective-viewer>:

const viewer = document.createElement("perspective-viewer");
window.body.appendChild(viewer);

Implementations§

Source§

impl PerspectiveViewerElement

Source

pub fn load(&self, table: JsValue) -> ApiFuture<()>

Loads a Table (or rather, a Javascript Promise which returns a Table) in this viewer.

When PerspectiveViewerElement::load resolves, the first frame of the UI + visualization is guaranteed to have been drawn. Awaiting the result of this method in a try/catch block will capture any errors thrown during the loading process, or from the Table Promise itself.

A Table can be created using the @finos/perspective library from NPM (see perspective_js documentation for details).

§JavaScript Examples
import perspective from "@finos/perspective";

const worker = await perspective.worker();
viewer.load(worker.table("x,y\n1,2"));
Source

pub fn delete(self) -> ApiFuture<()>

Delete the internal View and all associated state, rendering this <perspective-viewer> unusable and freeing all associated resources. Does not delete the supplied Table (as this is constructed by the callee).

Calling any method on a <perspective-viewer> after Self::delete will throw.

Allowing a <perspective-viewer> to be garbage-collected without calling PerspectiveViewerElement::delete will leak WASM memory!

§JavaScript Examples
await viewer.delete();
Source

pub fn eject(&mut self) -> ApiFuture<()>

Restart this <perspective-viewer> to its initial state, before load().

Use Self::restart if you plan to call Self::load on this viewer again, or alternatively Self::delete if this viewer is no longer needed.

Source

pub fn getView(&self) -> ApiFuture<View>

Get the underlying View for this viewer.

Use this method to get promgrammatic access to the View as currently configured by the user, for e.g. serializing as an Apache Arrow before passing to another library.

The View returned by this method is owned by the PerspectiveViewerElement and may be invalidated by View::delete at any time. Plugins which rely on this View for their [HTMLPerspectiveViewerPluginElement::draw] implementations should treat this condition as a cancellation by silently aborting on “View already deleted” errors from method calls.

§JavaScript Examples
const view = await viewer.getView();
Source

pub fn getTable(&self, wait_for_table: Option<bool>) -> ApiFuture<Table>

Get the underlying Table for this viewer (as passed to PerspectiveViewerElement::load).

§Arguments
§JavaScript Examples
const table = await viewer.getTable();
Source

pub fn getRenderStats(&self) -> ApiResult<JsValue>

Get render statistics. Some fields of the returned stats object are relative to the last time PerspectiveViewerElement::getRenderStats was called, ergo calling this method resets these fields.

§JavaScript Examples
const {virtual_fps, actual_fps} = await viewer.getRenderStats();
Source

pub fn flush(&self) -> ApiFuture<()>

Flush any pending modifications to this <perspective-viewer>. Since <perspective-viewer>’s API is almost entirely async, it may take some milliseconds before any user-initiated changes to the View affects the rendered element. If you want to make sure all pending actions have been rendered, call and await Self::flush.

Self::flush will resolve immediately if there is no Table set.

§JavaScript Examples

In this example, Self::restore is called without await, but the eventual render which results from this call can still be awaited by immediately awaiting Self::flush instead.

viewer.restore(config);
await viewer.flush();
Source

pub fn restore(&self, update: JsValue) -> ApiFuture<()>

Restores this element from a full/partial perspective_js::JsViewConfig.

One of the best ways to use Self::restore is by first configuring a <perspective-viewer> as you wish, then using either the Debug panel or “Copy” -> “config.json” from the toolbar menu to snapshot the Self::restore argument as JSON.

§Arguments
  • update - The config to restore to, as returned by Self::save in either “json”, “string” or “arraybuffer” format.
§JavaScript Examples

Apply a group_by to the current View, without modifying/resetting other fields:

await viewer.restore({group_by: ["State"]});
Source

pub fn resetError(&self) -> ApiFuture<()>

Source

pub fn save(&self, format: Option<String>) -> ApiFuture<JsValue>

Save this element to serialized state object, one which can be restored via the Self::restore method.

§Arguments
  • format - Supports “json” (default), “arraybuffer” or “string”.
§JavaScript Examples

Get the current group_by setting:

const {group_by} = await viewer.restore();

Reset workflow attached to an external button myResetButton:

const token = await viewer.save();
myResetButton.addEventListener("clien", async () => {
    await viewer.restore(token);
});
Source

pub fn download(&self, flat: Option<bool>) -> ApiFuture<()>

Download this viewer’s internal View data as a .csv file.

§Arguments
§JavaScript Examples
myDownloadButton.addEventListener("click", async () => {
    await viewer.download();
})
Source

pub fn copy(&self, method: Option<JsString>) -> ApiFuture<()>

Copy this viewer’s View or Table data as CSV to the system clipboard.

§Arguments
  • method - The ExportMethod (serialized as a String) to use to render the data to the Clipboard.
§JavaScript Examples
myDownloadButton.addEventListener("click", async () => {
    await viewer.copy();
})
Source

pub fn reset(&self, reset_all: Option<bool>) -> ApiFuture<()>

Reset the viewer’s ViewerConfig to the default.

§Arguments
  • reset_all - If set, will clear expressions and column settings as well.
§JavaScript Examples
await viewer.reset();
Source

pub fn resize(&self, force: Option<bool>) -> ApiFuture<()>

Recalculate the viewer’s dimensions and redraw.

Use this method to tell <perspective-viewer> its dimensions have changed when auto-size mode has been disabled via Self::setAutoSize. Self::resize resolves when the resize-initiated redraw of this element has completed.

§Arguments
§JavaScript Examples
await viewer.resize(true)
Source

pub fn setAutoSize(&self, autosize: bool)

Sets the auto-size behavior of this component.

When true, this <perspective-viewer> will register a ResizeObserver on itself and call Self::resize whenever its own dimensions change. However, when embedded in a larger application context, you may want to call Self::resize manually to avoid over-rendering; in this case auto-sizing can be disabled via this method. Auto-size behavior is enabled by default.

§Arguments
  • autosize - Whether to enable auto-size behavior or not.
§JavaScript Examples

Disable auto-size behavior:

viewer.setAutoSize(false);
Source

pub fn setAutoPause(&self, autopause: bool)

Sets the auto-pause behavior of this component.

When true, this <perspective-viewer> will register an IntersectionObserver on itself and subsequently skip rendering whenever its viewport visibility changes. Auto-pause is enabled by default.

§Arguments
  • autopause Whether to enable auto-pause behavior or not.
§JavaScript Examples

Disable auto-size behavior:

viewer.setAutoPause(false);
Source

pub fn getSelection(&self) -> Option<JsViewWindow>

Return a perspective_js::JsViewWindow for the currently selected region.

Source

pub fn setSelection(&self, window: Option<JsViewWindow>) -> ApiResult<()>

Set the selection perspective_js::JsViewWindow for this element.

Source

pub fn getEditPort(&self) -> Result<f64, JsValue>

Get this viewer’s edit port for the currently loaded Table (see Table::update for details on ports).

Source

pub fn restyleElement(&self) -> ApiFuture<JsValue>

Restyle all plugins from current document.

Self::restyleElement must be called for many runtime changes to CSS properties to be reflected in an already-rendered <perspective-viewer>.

§JavaScript Examples
viewer.style = "--icon--color: red";
await viewer.restyleElement();
Source

pub fn resetThemes(&self, themes: Option<Box<[JsValue]>>) -> ApiFuture<JsValue>

Set the available theme names available in the status bar UI.

Calling Self::resetThemes may cause the current theme to switch, if e.g. the new theme set does not contain the current theme.

§JavaScript Examples

Restrict <perspective-viewer> theme options to only default light and dark themes, regardless of what is auto-detected from the page’s CSS:

viewer.resetThemes(["Pro Light", "Pro Dark"])
Source

pub fn setThrottle(&self, val: Option<f64>)

Determines the render throttling behavior. Can be an integer, for millisecond window to throttle render event; or, if None, adaptive throttling will be calculated from the measured render time of the last 5 frames.

§Arguments
  • throttle - The throttle rate in milliseconds (f64), or None for adaptive throttling.
§JavaScript Examples

Only draws at most 1 frame/sec:

viewer.setThrottle(1000);
Source

pub fn toggleConfig(&self, force: Option<bool>) -> ApiFuture<JsValue>

Toggle (or force) the config panel open/closed.

§Arguments
  • force - Force the state of the panel open or closed, or None to toggle.
§JavaScript Examples
await viewer.toggleConfig();
Source

pub fn getAllPlugins(&self) -> Array

Get an Array of all of the plugin custom elements registered for this element. This may not include plugins which called registerPlugin after the host has rendered for the first time.

Source

pub fn getPlugin( &self, name: Option<String>, ) -> ApiResult<JsPerspectiveViewerPlugin>

Gets a plugin Custom Element with the name field, or get the active plugin if no name is provided.

§Arguments
  • name - The name property of a perspective plugin Custom Element, or None for the active plugin’s Custom Element.
Source

pub fn toggleColumnSettings(&self, column_name: String) -> ApiFuture<()>

Asynchronously opens the column settings for a specific column. When finished, the <perspective-viewer> element will emit a “perspective-toggle-column-settings” CustomEvent. The event’s details property has two fields: {open: bool, column_name?: string}. The CustomEvent is also fired whenever the user toggles the sidebar manually.

Source

pub fn openColumnSettings( &self, column_name: Option<String>, toggle: Option<bool>, ) -> ApiFuture<()>

Force open the settings for a particular column. Pass null to close the column settings panel. See Self::toggleColumnSettings for more.

Trait Implementations§

Source§

impl Clone for PerspectiveViewerElement

Source§

fn clone(&self) -> PerspectiveViewerElement

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CustomElementMetadata for PerspectiveViewerElement

Source§

const CUSTOM_ELEMENT_NAME: &'static str = "perspective-viewer"

Source§

const STATICS: &'static [&'static str]

Source§

const TYPE_NAME: &'static str = _

Source§

fn struct_name() -> &'static str

Source§

impl From<PerspectiveViewerElement> for JsValue

Source§

fn from(value: PerspectiveViewerElement) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for PerspectiveViewerElement

Source§

type Abi = u32

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for PerspectiveViewerElement

Source§

type Abi = u32

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for PerspectiveViewerElement

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<PerspectiveViewerElement>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for PerspectiveViewerElement

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for PerspectiveViewerElement

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for PerspectiveViewerElement

Source§

type Abi = u32

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<PerspectiveViewerElement>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
Source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for PerspectiveViewerElement

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<PerspectiveViewerElement>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl TryFromJsValue for PerspectiveViewerElement

Source§

type Error = JsValue

The type returned in the event of a conversion error.
Source§

fn try_from_js_value(value: JsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl VectorFromWasmAbi for PerspectiveViewerElement

Source§

impl VectorIntoJsValue for PerspectiveViewerElement

Source§

impl VectorIntoWasmAbi for PerspectiveViewerElement

Source§

impl WasmDescribe for PerspectiveViewerElement

Source§

impl WasmDescribeVector for PerspectiveViewerElement

Source§

impl SupportsConstructor for PerspectiveViewerElement

Source§

impl SupportsInstanceProperty for PerspectiveViewerElement

Source§

impl SupportsStaticProperty for PerspectiveViewerElement

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoPropValue<Option<T>> for T

Source§

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
Source§

impl<T> IntoPropValue<T> for T

Source§

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
Source§

impl<T> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
Source§

impl<T> Tee for T
where T: Clone,

Source§

fn tee<const N: usize>(self) -> <T as TeeInternal<N>>::Output
where T: TeeInternal<N>,

Extension method to add tee() method to all T: Clone. Read more
Source§

impl<T> TeeInternal<{${count($x)} + 1}> for T
where T: Clone,

Source§

type Output = (T, T)

Source§

fn tee_internal(self) -> <T as TeeInternal<{${count($x)} + 1}>>::Output

Source§

impl<T> TeeInternal<{${count($x)} + 1}> for T
where T: Clone,

Source§

type Output = (T, T, T)

Source§

fn tee_internal(self) -> <T as TeeInternal<{${count($x)} + 1}>>::Output

Source§

impl<T> TeeInternal<{${count($x)} + 1}> for T
where T: Clone,

Source§

type Output = (T, T, T, T)

Source§

fn tee_internal(self) -> <T as TeeInternal<{${count($x)} + 1}>>::Output

Source§

impl<T> TeeInternal<{${count($x)} + 1}> for T
where T: Clone,

Source§

type Output = (T, T, T, T, T)

Source§

fn tee_internal(self) -> <T as TeeInternal<{${count($x)} + 1}>>::Output

Source§

impl<T> TeeInternal<{${count($x)} + 1}> for T
where T: Clone,

Source§

type Output = (T, T, T, T, T, T)

Source§

fn tee_internal(self) -> <T as TeeInternal<{${count($x)} + 1}>>::Output

Source§

impl<T> TeeInternal<{${count($x)} + 1}> for T
where T: Clone,

Source§

type Output = (T, T, T, T, T, T, T)

Source§

fn tee_internal(self) -> <T as TeeInternal<{${count($x)} + 1}>>::Output

Source§

impl<T> TeeInternal<{${count($x)} + 1}> for T
where T: Clone,

Source§

type Output = (T, T, T, T, T, T, T, T)

Source§

fn tee_internal(self) -> <T as TeeInternal<{${count($x)} + 1}>>::Output

Source§

impl<T> TeeInternal<{${count($x)} + 1}> for T
where T: Clone,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<Token, Builder, How> AllPropsFor<Builder, How> for Token
where Builder: Buildable<Token>, <Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,

Source§

impl<T> HasAllProps<(), T> for T