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

WIP: Attempt to support arrow serialization #119

Closed
wants to merge 6 commits into from
Closed
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
45 changes: 39 additions & 6 deletions vl-convert-rs/src/converter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::module_loader::import_map::{url_for_path, vega_themes_url, vega_url, VlVersion};
use crate::module_loader::import_map::{
url_for_path, vega_themes_url, vega_url, VlVersion, ARROW_PATH,
};
use crate::module_loader::{VlConvertModuleLoader, IMPORT_MAP};
use std::borrow::Cow;
use std::collections::hash_map::Entry;
Expand Down Expand Up @@ -141,9 +143,38 @@ var vegaThemes;
import('{vega_themes_url}').then((imported) => {{
vegaThemes = imported;
}})

var arrow;
import('{arrow_url}').then((imported) => {{
arrow = imported;
}})

async function base64UrlToArrayBuffer(b64Url) {{
const res = await fetch(b64Url);
return await res.arrayBuffer();
}}

async function deserializeArrowDatasets(spec) {{
// Handle data
for (const dataset of spec.data || []) {{
if (typeof dataset.url === "string" && dataset.url.startsWith("data:application/vnd.apache.arrow.file;base64,")) {{
dataset.values = arrow.tableFromIPC(await base64UrlToArrayBuffer(dataset.url));
delete dataset.url;
}}
}}

// Handle group marks recursively
for (const mark of spec.marks || []) {{
if (mark.type === "group") {{
await deserializeArrowDatasets(mark);
}}
}}
}}

"#,
vega_url = vega_url(),
vega_themes_url = vega_themes_url(),
arrow_url = url_for_path(ARROW_PATH),
));

self.worker.execute_script("<anon>", import_code)?;
Expand Down Expand Up @@ -219,11 +250,13 @@ import('{url}').then((sg) => {{
// Create and initialize svg function string
let function_str = r#"
function vegaToSvg(vgSpec) {
let runtime = vega.parse(vgSpec);
const baseURL = 'https://vega.github.io/vega-datasets/';
const loader = vega.loader({ mode: 'http', baseURL });
let view = new vega.View(runtime, {renderer: 'none', loader});
let svgPromise = view.toSVG().finally(() => { view.finalize() });
let svgPromise = deserializeArrowDatasets(vgSpec).then(() => {
let runtime = vega.parse(vgSpec);
const baseURL = 'https://vega.github.io/vega-datasets/';
const loader = vega.loader({ mode: 'http', baseURL });
let view = new vega.View(runtime, {renderer: 'none', loader});
return view.toSVG().finally(() => { view.finalize() });
});
return svgPromise
}
"#;
Expand Down
6 changes: 5 additions & 1 deletion vl-convert-rs/src/html.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::module_loader::import_map::{DEBOUNCE_PATH, SKYPACK_URL, VEGA_EMBED_PATH, VEGA_PATH};
use crate::module_loader::import_map::{
ARROW_PATH, DEBOUNCE_PATH, SKYPACK_URL, VEGA_EMBED_PATH, VEGA_PATH, VEGA_SCHEMA_PATH,
};
use crate::module_loader::VlConvertBundleLoader;
use crate::VlVersion;
use deno_core::error::AnyError;
Expand Down Expand Up @@ -73,6 +75,8 @@ import vegaEmbed from "{SKYPACK_URL}{VEGA_EMBED_PATH}"
import vega from "{SKYPACK_URL}{VEGA_PATH}"
import vegaLite from "{SKYPACK_URL}{VEGA_LITE_PATH}"
import lodashDebounce from "{SKYPACK_URL}{DEBOUNCE_PATH}"
import vegaSchemaUrlParser from "{SKYPACK_URL}{VEGA_SCHEMA_PATH}"
import * as arrow from "{SKYPACK_URL}{ARROW_PATH}"
{snippet}
"#,
VEGA_LITE_PATH = vl_version.to_path()
Expand Down
232 changes: 124 additions & 108 deletions vl-convert-rs/src/module_loader/import_map.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions vl-convert-rs/tests/test_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ mod test_png_no_theme {

#[rstest(name, scale,
case("circle_binned", 1.0),
case("circle_binned_b64", 1.0),
case("circle_binned_base_url", 1.0),
case("stacked_bar_h", 2.0),
case("bar_chart_trellis_compact", 2.0),
Expand Down
18 changes: 18 additions & 0 deletions vl-convert-rs/tests/vl-specs/circle_binned_b64.vl.json

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading