Skip to content

Commit b71d515

Browse files
authored
Merge pull request #2960 from finos/fix-export-html
Fix export-to-html in `perspective-viewer`
2 parents 04b6106 + ed4bf27 commit b71d515

File tree

5 files changed

+114
-4
lines changed

5 files changed

+114
-4
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script type="module" src="http://localhost:6598/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.js"></script>
5+
<script type="module" src="http://localhost:6598/node_modules/@finos/perspective-test/load-viewer-csv-single-threaded.js"></script>
6+
<link rel="stylesheet" href="http://localhost:6598/node_modules/@finos/perspective-viewer/dist/css/pro.css" />
7+
<link rel="stylesheet" href="http://localhost:6598/node_modules/@fontsource/roboto-mono/400.css" />
8+
<style>
9+
perspective-viewer {
10+
position: absolute;
11+
top: 0;
12+
bottom: 0;
13+
left: 0;
14+
right: 0;
15+
}
16+
</style>
17+
</head>
18+
<body>
19+
<perspective-viewer></perspective-viewer>
20+
</body>
21+
</html>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2+
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3+
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4+
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5+
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6+
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7+
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
8+
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9+
// ┃ This file is part of the Perspective library, distributed under the terms ┃
10+
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11+
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12+
13+
import { test, expect } from "@finos/perspective-test";
14+
import * as path from "node:path";
15+
16+
test.beforeEach(async ({ page }) => {
17+
const p = path.resolve(
18+
"rust/perspective-viewer/test/html/superstore-single-threaded.html"
19+
);
20+
21+
await page.goto(`file://${p}`);
22+
await page.evaluate(async () => {
23+
while (!window["__TEST_PERSPECTIVE_READY__"]) {
24+
await new Promise((x) => setTimeout(x, 10));
25+
}
26+
});
27+
28+
await page.evaluate(async () => {
29+
await document.querySelector("perspective-viewer")!.restore({
30+
plugin: "Debug",
31+
});
32+
});
33+
});
34+
35+
test.describe("Export button", () => {
36+
test("Single threaded engine mode works", async ({ page }) => {
37+
await page.evaluate(async () => {
38+
const viewer = document.querySelector("perspective-viewer")!;
39+
await viewer.restore({
40+
group_by: ["State"],
41+
columns: ["Sales", "Profit"],
42+
settings: true,
43+
});
44+
});
45+
46+
const value = await page.evaluate(async () => {
47+
return document.querySelector("perspective-viewer")!.innerText
48+
.length;
49+
});
50+
51+
// Superstore as a CSV
52+
expect(value).toEqual(836);
53+
});
54+
});

tools/perspective-esbuild-plugin/worker.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ exports.WorkerPlugin = function WorkerPlugin(options = {}) {
7474
import worker from ${JSON.stringify(args.path)};
7575
function make_host(a, b) {
7676
function addEventListener(type, callback) {
77-
a.push(callback);
77+
if (type === "message") {
78+
a.push(callback);
79+
}
7880
}
7981
8082
function removeEventListener(callback) {
@@ -84,9 +86,9 @@ exports.WorkerPlugin = function WorkerPlugin(options = {}) {
8486
}
8587
}
8688
87-
function postMessage(msg) {
89+
function postMessage(msg, ports) {
8890
for (const listener of b) {
89-
listener({data: msg});
91+
listener({data: msg, ports: ports});
9092
}
9193
}
9294
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2+
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3+
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4+
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5+
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6+
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7+
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
8+
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9+
// ┃ This file is part of the Perspective library, distributed under the terms ┃
10+
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11+
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12+
13+
import "http://localhost:6598/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.js";
14+
import perspective from "http://localhost:6598/node_modules/@finos/perspective/dist/cdn/perspective.js";
15+
16+
async function load() {
17+
let resp = await fetch(
18+
"http://localhost:6598/node_modules/@finos/perspective-test/assets/superstore.csv"
19+
);
20+
21+
let csv = await resp.text();
22+
const viewer = document.querySelector("perspective-viewer");
23+
const worker = await perspective.worker();
24+
const table = worker.table(csv, { index: "Row ID" });
25+
await viewer.load(table);
26+
window.__TEST_WORKER__ = worker;
27+
}
28+
29+
await load();
30+
window.__TEST_PERSPECTIVE_READY__ = true;

tools/perspective-test/src/js/start_test_server.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ async function cwd_static_file_handler(
6161
let content = await read_promise(filePath);
6262
if (typeof content !== "undefined") {
6363
console.log(`200 ${url}`);
64-
response.writeHead(200, { "Content-Type": contentType });
64+
response.writeHead(200, {
65+
"Content-Type": contentType,
66+
"Access-Control-Allow-Origin": "*",
67+
});
6568
if (extname === ".arrow" || extname === ".feather") {
6669
response.end(content, "utf-8");
6770
} else {

0 commit comments

Comments
 (0)