File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
rust/perspective-viewer/src Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -234,6 +234,16 @@ impl PerspectiveViewerElement {
234234 Ok ( result)
235235 }
236236
237+ /// Get the underlying `View` for thie viewer.
238+ pub fn js_get_view ( & self ) -> js_sys:: Promise {
239+ let session = self . session . clone ( ) ;
240+ future_to_promise ( async move {
241+ session
242+ . js_get_view ( )
243+ . ok_or_else ( || JsValue :: from ( "No table set" ) )
244+ } )
245+ }
246+
237247 /// Get the underlying `Table` for this viewer.
238248 ///
239249 /// # Arguments
Original file line number Diff line number Diff line change @@ -132,6 +132,10 @@ impl Session {
132132 . map ( |x| x. unchecked_into :: < JsValue > ( ) )
133133 }
134134
135+ pub fn js_get_view ( & self ) -> Option < JsValue > {
136+ Some ( self . borrow ( ) . view_sub . as_ref ( ) ?. get_view ( ) . as_jsvalue ( ) )
137+ }
138+
135139 pub fn is_column_expression_in_use ( & self , name : & str ) -> bool {
136140 self . borrow ( ) . config . is_column_expression_in_use ( name)
137141 }
Original file line number Diff line number Diff line change @@ -190,6 +190,30 @@ export class HTMLPerspectiveViewerElement extends HTMLElement {
190190 return table ;
191191 }
192192
193+ /**
194+ * Returns the underlying `perspective.View` currently configured for this
195+ * `<perspective-viewer>`. Because ownership of the `perspective.View` is
196+ * mainainted by the `<perspective-viewer>` it was created by, this `View`
197+ * may become deleted (invalidated by calling `delete()`) at any time -
198+ * specifically, it will be deleted whenever the `PerspectiveViewConfig`
199+ * changes. Because of this, when using this API, prefer calling
200+ * `getView()` repeatedly over caching the returned `perspective.View`,
201+ * especially in `async` contexts.
202+ * @category Data
203+ * @returns A `Promise` which ressolves to a `perspective.View`.
204+ * @example <caption>Collapse grid to root</caption>
205+ * ```javascript
206+ * const viewer = document.querySelector("perspective-viewer");
207+ * const view = await viewer.getView();
208+ * await view.set_depth(0);
209+ * ```
210+ */
211+ async getView ( ) : Promise < perspective . View > {
212+ await this . load_wasm ( ) ;
213+ const view = await this . instance . js_get_view ( ) ;
214+ return view ;
215+ }
216+
193217 /**
194218 * Restore this element to a state as generated by a reciprocal call to
195219 * `save`. In `json` (default) format, `PerspectiveViewerConfig`'s fields
You can’t perform that action at this time.
0 commit comments