Skip to content

Commit 45d789e

Browse files
committed
feat: add Plotly support
1 parent aedadd5 commit 45d789e

22 files changed

Lines changed: 6265 additions & 133 deletions

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
temp*
2-
*.dll
3-
*.js
2+
*.dll

build.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { datauri, esbuild } from './deps.ts';
1+
import { esbuild } from './deps.ts';
22

33
await Deno.spawn(Deno.execPath(), {
44
args: ['bundle', '--no-check', './src/client.ts', './public/client.js'],
@@ -7,26 +7,8 @@ await Deno.spawn(Deno.execPath(), {
77
const js = await Deno.readTextFile('./public/client.js');
88
const mjs = (await esbuild.transform(js, { minify: true })).code;
99

10-
const html = /*html*/ `
11-
<!DOCTYPE html>
12-
<html lang="en">
13-
<head>
14-
<meta charset="UTF-8">
15-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
16-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
17-
<link rel="icon" type="image/png" src="${await datauri(
18-
'./public/logo-min.png',
19-
)}">
20-
<title>Deplot</title>
21-
</head>
22-
<body>
23-
<span id="deno_args" hidden></span>
24-
<div id="plot_container" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%">
25-
<canvas id="plot"></canvas>
26-
</div>
27-
<script type="module" defer>${mjs}</script>
28-
</body>
29-
</html>`;
10+
await Deno.writeTextFile('./public/client.min.js', mjs);
3011

31-
await Deno.writeTextFile('./public/bundle.html', html);
32-
Deno.exit();
12+
await Deno.remove('./public/client.js');
13+
14+
Deno.exit();

deno.jsonc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,15 @@
77
"deno.ns",
88
"deno.unstable"
99
]
10+
},
11+
"lint": {
12+
"files": {
13+
"exclude": ["vendor", "public"]
14+
}
15+
},
16+
"fmt": {
17+
"files": {
18+
"exclude": ["vendor", "public"]
19+
}
1020
}
1121
}

deps.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
export { serve } from 'https://deno.land/std@0.138.0/http/server.ts';
2-
export * as staticFiles from 'https://deno.land/x/static_files@1.1.6/mod.ts';
32
export { ensureFile } from 'https://deno.land/std@0.138.0/fs/ensure_file.ts';
43
export { join } from 'https://deno.land/std@0.138.0/path/mod.ts';
5-
export { datauri } from 'https://deno.land/x/datauri@v1.1.2/mod.ts';
64
export { Webview } from 'https://deno.land/x/webview@0.7.0-pre.1/mod.ts';
75
export { WebSocketServer } from 'https://deno.land/x/websocket@v0.1.4/mod.ts';
86
export type { WebSocketClient } from 'https://deno.land/x/websocket@v0.1.4/mod.ts';
9-
// export * as Plotly from 'https://cdn.skypack.dev/plotly.js@2.11?dts';
10-
// export * as Plotly from 'https://esm.sh/plotly.js@2.11';
11-
// export { Plotly } from 'https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/types/plotly.js/index.d.ts';
7+
export { lookup } from 'https://deno.land/x/media_types@v2.8.3/mod.ts';
128
export * as ChartJs from 'https://cdn.skypack.dev/chart.js@3.7?dts';
13-
// import ensureVersion from 'https://deno.land/x/ensure_version@1.0.3/mod.ts';
9+
import ensureVersion from 'https://deno.land/x/ensure_version@1.0.3/mod.ts';
1410
export * as esbuild from 'https://deno.land/x/esbuild@v0.14.38/mod.js';
1511

16-
// ensureVersion('>=1.20');
12+
ensureVersion('>=1.20', false);

examples/plotly.ts

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,56 @@
1-
// import { Plotly } from '../deps.ts'
2-
3-
// function editablePlot() {
4-
// const trace1: Plotly.Data = {
5-
// x: [0, 1, 2, 3, 4],
6-
// y: [1, 5, 3, 7, 5],
7-
// mode: 'lines+markers',
8-
// type: 'scatter'
9-
// }
10-
11-
// const trace2: Plotly.Data = {
12-
// x: [1, 2, 3, 4, 5],
13-
// y: [4, 0, 4, 6, 8],
14-
// mode: 'lines+markers',
15-
// type: 'scatter'
16-
// }
17-
18-
// const data = [trace1, trace2]
19-
// const layout: Partial<Plotly.Layout> = {title: 'Click Here<br>to Edit Chart Title'}
20-
21-
// Plotly.newPlot('myDiv', data, layout, {editable: true})
22-
// }
23-
24-
// async function barPlot() {
25-
// const trace1: Plotly.Data = {
26-
// x:['Zebras', 'Lions', 'Pelicans'],
27-
// y: [90, 40, 60],
28-
// type: 'bar',
29-
// name: 'New York Zoo'
30-
// }
31-
32-
// const trace2: Plotly.Data = {
33-
// x:['Zebras', 'Lions', 'Pelicans'],
34-
// y: [10, 80, 45],
35-
// type: 'bar',
36-
// name: 'San Francisco Zoo'
37-
// }
38-
39-
// const data = [trace1, trace2]
40-
41-
// const layout: Partial<Plotly.Layout> = {
42-
// title: 'Hide the Modebar',
43-
// showlegend: true
44-
// }
45-
46-
// console.log(await Plotly.newPlot('myDiv', data, layout, {displayModeBar: false}))
47-
// }
48-
49-
// editablePlot()
50-
// barPlot()
1+
import { Deplot } from '../mod.ts';
2+
import { Datas } from '../src/types.ts';
3+
4+
const deplot = new Deplot('Plotly');
5+
6+
function editablePlot() {
7+
const trace1: Plotly.Data = {
8+
x: [0, 1, 2, 3, 4],
9+
y: [1, 5, 3, 7, 5],
10+
mode: 'lines+markers',
11+
type: 'scatter',
12+
};
13+
14+
const trace2: Plotly.Data = {
15+
x: [1, 2, 3, 4, 5],
16+
y: [4, 0, 4, 6, 8],
17+
mode: 'lines+markers',
18+
type: 'scatter',
19+
};
20+
21+
const data = [trace1, trace2];
22+
const layout: Partial<Plotly.Layout> = {
23+
title: 'Click Here<br>to Edit Chart Title',
24+
};
25+
const datas: Datas = { data, layout, config: { editable: true } };
26+
27+
deplot.plot(datas, { title: 'ChartJs line plot', size: [800, 800] });
28+
}
29+
30+
function barPlot() {
31+
const trace1: Plotly.Data = {
32+
x: ['Zebras', 'Lions', 'Pelicans'],
33+
y: [90, 40, 60],
34+
type: 'bar',
35+
name: 'New York Zoo',
36+
};
37+
38+
const trace2: Plotly.Data = {
39+
x: ['Zebras', 'Lions', 'Pelicans'],
40+
y: [10, 80, 45],
41+
type: 'bar',
42+
name: 'San Francisco Zoo',
43+
};
44+
45+
const data = [trace1, trace2];
46+
const layout: Partial<Plotly.Layout> = {
47+
title: 'Hide the Modebar',
48+
showlegend: true,
49+
};
50+
const datas: Datas = { data, layout, config: { editable: true } };
51+
52+
deplot.plot(datas, { title: 'ChartJs line plot', size: [800, 600] });
53+
}
54+
55+
editablePlot();
56+
barPlot();

public/bundle.html

Lines changed: 0 additions & 21 deletions
This file was deleted.

public/client.min.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/index.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<meta http-equiv="X-UA-Compatible" content="IE=edge">
67
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<link rel="icon" type="image/png">
8+
<link rel="shortcut icon" type="image/png" src="/logo-min.png">
89
<title>Deplot</title>
910
</head>
11+
1012
<body>
1113
<span id="deno_args" hidden></span>
1214
<div id="plot_container" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%">
1315
<canvas id="plot"></canvas>
1416
</div>
15-
<script type="module" defer></script>
17+
<script defer src="/client.min.js"></script>
1618
</body>
19+
<style>
20+
body {
21+
overflow: hidden;
22+
}
23+
</style>
24+
1725
</html>

public/plotly-2_11_1.min.js

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ scripts:
1717

1818
examples:
1919
cmd:
20-
- deno run --allow-read --allow-write="." --allow-net="0.0.0.0,127.0.0.1,localhost" --allow-run --allow-env --allow-ffi --unstable ./examples/chartjs.ts
21-
# - deno run --allow-read="." --allow-env --allow-ffi --unstable ./examples/plotly.ts
20+
- deno run --allow-read --allow-write --allow-net="0.0.0.0,127.0.0.1,localhost" --allow-run --allow-env --allow-ffi --unstable ./examples/chartjs.ts
21+
- deno run --allow-read --allow-write --allow-net="0.0.0.0,127.0.0.1,localhost" --allow-run --allow-env --allow-ffi --unstable ./examples/plotly.ts
2222
# - deno run --allow-read="." --allow-env --allow-ffi --unstable ./examples/gcharts.ts
2323

2424
test:

0 commit comments

Comments
 (0)