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
impl PerspectiveViewerElement
sourcepub fn load(&self, table: JsValue) -> ApiFuture<()>
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"));
sourcepub fn delete(&mut self) -> ApiFuture<bool>
pub fn delete(&mut self) -> ApiFuture<bool>
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).
Allowing a <perspective-viewer> to be garbage-collected
without calling PerspectiveViewerElement::delete will leak WASM
memory!
§JavaScript Examples
await viewer.delete();
sourcepub fn getView(&self) -> ApiFuture<View>
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.
§JavaScript Examples
const view = await viewer.getView();
sourcepub fn getTable(&self, wait_for_table: Option<bool>) -> ApiFuture<Table>
pub fn getTable(&self, wait_for_table: Option<bool>) -> ApiFuture<Table>
Get the underlying Table for this viewer (as passed to
PerspectiveViewerElement::load).
§Arguments
wait_for_table- whether to wait forPerspectiveViewerElement::loadto be called, or fail immediately ifPerspectiveViewerElement::loadhas not yet been called.
§JavaScript Examples
const table = await viewer.getTable();
sourcepub fn getRenderStats(&self) -> ApiResult<JsValue>
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();
sourcepub fn flush(&self) -> ApiFuture<()>
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.
§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();
sourcepub fn restore(&self, update: JsValue) -> ApiFuture<()>
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 bySelf::savein 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"]});
sourcepub fn save(&self, format: Option<String>) -> ApiFuture<JsValue>
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);
});
sourcepub fn download(&self, flat: Option<bool>) -> ApiFuture<()>
pub fn download(&self, flat: Option<bool>) -> ApiFuture<()>
Download this viewer’s internal View data as a .csv file.
§Arguments
flat- Whether to use the currentperspective_js::JsViewConfigto generate this data, or use the default.
§JavaScript Examples
myDownloadButton.addEventListener("click", async () => {
await viewer.download();
})
sourcepub fn copy(&self, flat: Option<bool>) -> ApiFuture<()>
pub fn copy(&self, flat: Option<bool>) -> ApiFuture<()>
Copy this viewer’s View or Table data as CSV to the system
clipboard.
§Arguments
flat- Whether to use the currentperspective_js::JsViewConfigto generate this data, or use the default.
§JavaScript Examples
myDownloadButton.addEventListener("click", async () => {
await viewer.copy();
})
sourcepub fn resize(&self, force: Option<bool>) -> ApiFuture<()>
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
force- IfSelf::resizeis called withfalseor without an argument, and auto-size mode is enabled viaSelf::setAutoSize,Self::resizewill log a warning and auto-disable auto-size mode.
§JavaScript Examples
await viewer.resize(true)
sourcepub fn setAutoSize(&mut self, autosize: bool)
pub fn setAutoSize(&mut 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 enableauto-sizebehavior or not.
§JavaScript Examples
Disable auto-size behavior:
viewer.setAutoSize(false);
sourcepub fn setAutoPause(&mut self, autopause: bool)
pub fn setAutoPause(&mut 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
autopauseWhether to enableauto-pausebehavior or not.
§JavaScript Examples
Disable auto-size behavior:
viewer.setAutoPause(false);
sourcepub fn getSelection(&self) -> Option<JsViewWindow>
pub fn getSelection(&self) -> Option<JsViewWindow>
Return a perspective_js::JsViewWindow for the currently selected
region.
sourcepub fn setSelection(&self, window: Option<JsViewWindow>) -> ApiResult<()>
pub fn setSelection(&self, window: Option<JsViewWindow>) -> ApiResult<()>
Set the selection perspective_js::JsViewWindow for this element.
sourcepub fn getEditPort(&self) -> Result<f64, JsValue>
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).
sourcepub fn restyleElement(&self) -> ApiFuture<JsValue>
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();
sourcepub fn resetThemes(&self, themes: Option<Box<[JsValue]>>) -> ApiFuture<JsValue>
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"])
sourcepub fn setThrottle(&mut self, val: Option<f64>)
pub fn setThrottle(&mut 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), orNonefor adaptive throttling.
§JavaScript Examples
Only draws at most 1 frame/sec:
viewer.setThrottle(1000);sourcepub fn toggleConfig(&self, force: Option<bool>) -> ApiFuture<JsValue>
pub fn toggleConfig(&self, force: Option<bool>) -> ApiFuture<JsValue>
sourcepub fn getAllPlugins(&self) -> Array
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.
sourcepub fn getPlugin(
&self,
name: Option<String>,
) -> ApiResult<JsPerspectiveViewerPlugin>
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- Thenameproperty of a perspective plugin Custom Element, orNonefor the active plugin’s Custom Element.
sourcepub fn toggleColumnSettings(&self, column_name: String) -> ApiFuture<()>
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.
sourcepub fn openColumnSettings(
&self,
column_name: Option<String>,
toggle: Option<bool>,
) -> ApiFuture<()>
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
impl Clone for PerspectiveViewerElement
source§fn clone(&self) -> PerspectiveViewerElement
fn clone(&self) -> PerspectiveViewerElement
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl From<PerspectiveViewerElement> for JsValue
impl From<PerspectiveViewerElement> for JsValue
source§fn from(value: PerspectiveViewerElement) -> Self
fn from(value: PerspectiveViewerElement) -> Self
source§impl RefFromWasmAbi for PerspectiveViewerElement
impl RefFromWasmAbi for PerspectiveViewerElement
§type Anchor = Ref<'static, PerspectiveViewerElement>
type Anchor = Ref<'static, PerspectiveViewerElement>
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§impl VectorFromWasmAbi for PerspectiveViewerElement
impl VectorFromWasmAbi for PerspectiveViewerElement
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[PerspectiveViewerElement]>
source§impl VectorIntoWasmAbi for PerspectiveViewerElement
impl VectorIntoWasmAbi for PerspectiveViewerElement
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[PerspectiveViewerElement]>) -> Self::Abi
source§impl WasmDescribeVector for PerspectiveViewerElement
impl WasmDescribeVector for PerspectiveViewerElement
Auto Trait Implementations§
impl Freeze for PerspectiveViewerElement
impl !RefUnwindSafe for PerspectiveViewerElement
impl !Send for PerspectiveViewerElement
impl !Sync for PerspectiveViewerElement
impl Unpin for PerspectiveViewerElement
impl !UnwindSafe for PerspectiveViewerElement
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moresource§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self to a value of a Properties struct.source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self to a value of a Properties struct.source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::Abisource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.source§impl<T> Tee for Twhere
T: Clone,
impl<T> Tee for Twhere
T: Clone,
source§fn tee<const N: usize>(self) -> <T as TeeInternal<N>>::Outputwhere
T: TeeInternal<N>,
fn tee<const N: usize>(self) -> <T as TeeInternal<N>>::Outputwhere
T: TeeInternal<N>,
tee() method to all T: Clone. This can’t be
done directly as part of TeeInternal because it makes specifying the
const param at the tee() invocation site cumbersome:
TeeInternal::<N>::tee(&obj) as opposed to obj.tee::<N>(). The
constraint Self: TeeInternal<N> collapses the potential impl matches
to exactly 1, which makes the call to tee_internal() unambiguous.
This constraint is also allowed to contain the generic parameter N
because it is specified as a constraint to the method (as opposed to
a constraint on the trait). I’m honestly quite surprised this works … Read more