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

Add Apache Arrow as a recommended library and supported file attachment #223

Merged
merged 1 commit into from
Jul 29, 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
4 changes: 4 additions & 0 deletions bin/resolve-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const fetch = require("node-fetch");
const package = await resolve("vega-lite-api");
console.log(`export const vegaliteApi = dependency("${package.name}", "${package.version}", "${package.export}");`);
}
{
const package = await resolve("apache-arrow@4");
console.log(`export const arrow = dependency("${package.name}", "${package.version}", "${package.export}");`);
}
})();

async function resolve(specifier) {
Expand Down
1 change: 1 addition & 0 deletions src/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export const sql = dependency("sql.js", "1.5.0", "dist/sql-wasm.js");
export const vega = dependency("vega", "5.20.2", "build/vega.min.js");
export const vegalite = dependency("vega-lite", "5.1.0", "build/vega-lite.min.js");
export const vegaliteApi = dependency("vega-lite-api", "5.0.0", "build/vega-lite-api.min.js");
export const arrow = dependency("apache-arrow", "4.0.1", "Arrow.es2015.min.js");
6 changes: 5 additions & 1 deletion src/fileAttachment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {require as requireDefault} from "d3-require";
import {d3Dsv} from "./dependencies.js";
import {arrow, d3Dsv} from "./dependencies.js";
import {SQLiteDatabaseClient} from "./sqlite.js";
import jszip from "./zip.js";

Expand Down Expand Up @@ -53,6 +53,10 @@ class AbstractFile {
i.src = url;
});
}
async arrow() {
const [Arrow, response] = await Promise.all([requireDefault(arrow.resolve()), remote_fetch(this)]);
return Arrow.Table.from(response);
}
async sqlite() {
return SQLiteDatabaseClient.open(remote_fetch(this));
}
Expand Down
3 changes: 2 additions & 1 deletion src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import svg from "./svg.js";
import tex from "./tex.js";
import vegalite from "./vegalite.js";
import width from "./width.js";
import {d3, graphviz, htl, inputs, lodash, plot} from "./dependencies.js";
import {arrow, d3, graphviz, htl, inputs, lodash, plot} from "./dependencies.js";

export default Object.assign(function Library(resolver) {
const require = requirer(resolver);
Object.defineProperties(this, properties({
FileAttachment: () => NoFileAttachments,
Arrow: () => require(arrow.resolve()),
Inputs: () => require(inputs.resolve()),
Mutable: () => Mutable,
Plot: () => require(plot.resolve()),
Expand Down
1 change: 1 addition & 0 deletions test/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Library} from "../src/index.js";

test("new Library returns a library with the expected keys", async t => {
t.deepEqual(Object.keys(new Library()).sort(), [
"Arrow",
"DOM",
"FileAttachment",
"Files",
Expand Down