-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbenchmarkVLTpl.ts
91 lines (85 loc) · 2.01 KB
/
benchmarkVLTpl.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/
// Vega-Lite configuration
/**
* General Vega-Lite configuration
*/
const GENERAL_CONFIG = {
$schema: 'https://vega.github.io/schema/vega-lite/v5.json',
description: 'Box plots of some action time.',
title: 'Duration of common actions',
data: {} as Record<string, any>,
config: { facet: { spacing: 80 } }
};
/**
* Matrix of figures per test file
*
* @param tests Kind of test
* @param comparison Field name to compare
* @returns The specification
*/
function configPerFile(
tests: string[],
comparison: string
): Record<string, any> {
return {
vconcat: tests.map(t => {
return {
title: t,
transform: [{ filter: `datum.test === '${t}'` }],
facet: {
column: { field: 'browser', type: 'nominal' }
},
spec: {
mark: { type: 'boxplot', extent: 'min-max' },
encoding: {
y: { field: comparison, type: 'nominal' },
x: {
field: 'time',
title: 'Time (ms)',
type: 'quantitative',
scale: { zero: false }
}
}
}
};
})
};
}
/**
* Generate the Vega-Lite specification for test
*
* Note: The data field is set to empty
*
* @param tests Kind of test
* @param comparison Field name to compare
* @param filenames Test file name list
* @returns The specification
*/
function generateVegaLiteSpec(
tests: string[],
comparison: string,
filenames?: string[]
): Record<string, any> {
const files = filenames ?? [];
if (files.length === 0) {
return {
...GENERAL_CONFIG,
...configPerFile(tests, comparison)
};
} else {
return {
...GENERAL_CONFIG,
hconcat: files.map(b => {
return {
title: b,
transform: [{ filter: `datum.file === '${b}'` }],
...configPerFile(tests, comparison)
};
})
};
}
}
export default generateVegaLiteSpec;