forked from moltar/typescript-runtime-type-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.ts
50 lines (45 loc) · 1 KB
/
graph.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { View, parse } from 'vega';
import { compile } from 'vega-lite';
import SVGO from 'svgo';
const svgo = new SVGO({
js2svg: {
pretty: true,
},
});
export async function graph(filename: string): Promise<string> {
const vegaSpec = compile({
data: {
url: filename,
},
mark: 'bar',
width: 880,
height: 600,
encoding: {
y: {
field: 'ops',
type: 'quantitative',
title: 'operations / sec',
axis: {
labelFontSize: 12,
titleFontSize: 14,
titleFontWeight: 'normal',
},
},
x: {
field: 'name',
type: 'nominal',
title: 'module',
axis: {
labelFontSize: 14,
labelAngle: 90,
titleFontSize: 14,
titleFontWeight: 'normal',
},
},
},
});
const view = new View(parse(vegaSpec.spec), { renderer: 'none' });
const svg = await view.toSVG();
const optimizeSvg = await svgo.optimize(svg);
return optimizeSvg.data;
}