Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-add getEditPort() and restyleElement() methods #1531

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/perspective-viewer-d3fc/src/js/plugin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export function register(...plugins) {
}
}

async restyleElement(...args) {
async restyle(...args) {
let settings = this._settings;
if (settings) {
delete settings["colorStyles"];
Expand Down
2 changes: 2 additions & 0 deletions packages/perspective-viewer-datagrid/src/js/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ customElements.define(
datagrid[PLUGIN_SYMBOL] = token;
}

async restyle() {}

delete() {
if (this.datagrid.table_model) {
this.datagrid._resetAutoSize();
Expand Down
29 changes: 29 additions & 0 deletions rust/perspective-viewer/src/rust/custom_elements/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use flate2::read::ZlibDecoder;
use flate2::write::ZlibEncoder;
use flate2::Compression;
use futures::channel::oneshot::*;
use futures::future::join_all;
use js_intern::*;
use js_sys::*;
use std::cell::RefCell;
Expand Down Expand Up @@ -326,6 +327,34 @@ impl PerspectiveViewerElement {
promisify_ignore_view_delete(async move { renderer.resize().await })
}

/// Get this viewer's edit port for the currently loaded `Table`.
pub fn js_get_edit_port(&self) -> Result<f64, JsValue> {
self.session
.metadata()
.get_edit_port()
.ok_or_else(|| "No `Table` loaded".into())
}

/// Restyle all plugins from current document.
pub fn js_restyle_element(&self) -> js_sys::Promise {
let renderer = self.renderer.clone();
let session = self.session.clone();
promisify_ignore_view_delete(async move {
let view = session.get_view().into_jserror()?;
let plugins = renderer.get_all_plugins();
let tasks = plugins.iter().map(|plugin| {
let view = &view;
async move { plugin.restyle(view).await }
});

join_all(tasks)
.await
.into_iter()
.collect::<Result<Vec<_>, _>>()
.map(|_| JsValue::UNDEFINED)
})
}

/// 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.
Expand Down
4 changes: 4 additions & 0 deletions rust/perspective-viewer/src/rust/js/perspective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ extern "C" {
#[wasm_bindgen(method, catch, js_name = delete)]
pub async fn _delete(this: &JsPerspectiveTable) -> Result<JsValue, JsValue>;

#[wasm_bindgen(method, catch, js_name = make_port)]
pub async fn _make_port(this: &JsPerspectiveTable) -> Result<JsValue, JsValue>;

#[wasm_bindgen(method, catch, js_name = schema)]
pub async fn _schema(this: &JsPerspectiveTable) -> Result<JsValue, JsValue>;

Expand Down Expand Up @@ -140,6 +143,7 @@ impl JsPerspectiveWorker {
impl JsPerspectiveTable {
async_typed!(_columns, columns(&self) -> js_sys::Array);
async_typed!(_delete, delete(self) -> ());
async_typed!(_make_port, make_port(&self) -> f64);
async_typed!(_validate_expressions, validate_expressions(&self, exprs: Array) -> JsPerspectiveValidatedExpressions);
async_typed!(_schema, schema(&self) -> JsPerspectiveTableSchema);
async_typed!(_view, view(&self, config: &JsPerspectiveViewConfig) -> JsPerspectiveView);
Expand Down
8 changes: 8 additions & 0 deletions rust/perspective-viewer/src/rust/js/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ use super::perspective::JsPerspectiveView;

async resize() {}

async restyle() {}

save() {}

restore() {}
Expand Down Expand Up @@ -114,6 +116,12 @@ extern "C" {
#[wasm_bindgen(method)]
pub fn delete(this: &JsPerspectiveViewerPlugin);

#[wasm_bindgen(method, catch)]
pub async fn restyle(
this: &JsPerspectiveViewerPlugin,
view: &JsPerspectiveView
) -> Result<JsValue, JsValue>;

#[wasm_bindgen(method, catch)]
pub async fn draw(
this: &JsPerspectiveViewerPlugin,
Expand Down
8 changes: 8 additions & 0 deletions rust/perspective-viewer/src/rust/session/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct SessionMetadata(Option<SessionMetadataState>);
pub struct SessionMetadataState {
column_names: Vec<String>,
table_schema: HashMap<String, Type>,
edit_port: f64,
view_schema: Option<HashMap<String, Type>>,
view_expression_schema: Option<HashMap<String, Type>>,
view_expression_alias: Option<HashMap<String, String>>,
Expand Down Expand Up @@ -54,9 +55,12 @@ impl SessionMetadata {
.into_serde::<HashMap<String, Type>>()
.into_jserror()?;

let edit_port = table.make_port().await?;

Ok(SessionMetadata(Some(SessionMetadataState {
column_names,
table_schema,
edit_port,
..SessionMetadataState::default()
})))
}
Expand Down Expand Up @@ -168,6 +172,10 @@ impl SessionMetadata {
.unwrap_or(false)
}

pub fn get_edit_port(&self) -> Option<f64> {
self.0.as_ref().map(|meta| meta.edit_port)
}

/// Returns the type of a column name relative to the `Table`. Despite the name,
/// `get_column_table_type()` also returns the `Table` type for Expressions,
/// which despite living on the `View` still have a `table` type associated with
Expand Down
8 changes: 5 additions & 3 deletions rust/perspective-viewer/src/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ export class PerspectiveViewerElement extends HTMLElement {
* @category Util
*/
async restyleElement(): Promise<void> {
console.error("Not Implemented");
await this.load_wasm();
await this.instance.js_restyle_element();
}

/**
Expand All @@ -395,8 +396,9 @@ export class PerspectiveViewerElement extends HTMLElement {
* ```
*/
async getEditPort(): Promise<number> {
console.error("Not Implemented");
return -1;
await this.load_wasm();
const port = await this.instance.js_get_edit_port();
return port;
}

/**
Expand Down