@@ -25,34 +25,51 @@ ChartJS.register(
25
25
Tooltip ,
26
26
Legend ,
27
27
Colors ,
28
- BarElement ,
28
+ BarElement
29
29
) ;
30
30
31
- export function BenchmarkGraphs ( ) {
31
+ interface BenchmarkGraphsProps {
32
+ selectedEngines : string [ ] ;
33
+ }
34
+
35
+ const ChartOptions = {
36
+ plugins : {
37
+ colors : {
38
+ forceOverride : true ,
39
+ } ,
40
+ } ,
41
+ } ;
42
+
43
+ export const BenchmarkGraphs : React . FC < BenchmarkGraphsProps > = ( {
44
+ selectedEngines,
45
+ } ) => {
46
+ // Control the state of which engines are displayed using a Set
47
+
32
48
const [ data , setData ] = React . useState ( [ ] ) ;
33
49
const colorMode = useColorMode ( ) ;
34
50
ChartJS . defaults . color = colorMode . colorMode === "light" ? "#666" : "white" ;
35
51
36
52
React . useEffect ( ( ) => {
37
53
Promise . all ( [
38
- buildChartFromBenchmark ( "Crypto" ) ,
39
- buildChartFromBenchmark ( "DeltaBlue" ) ,
40
- buildChartFromBenchmark ( "EarleyBoyer" ) ,
41
- buildChartFromBenchmark ( "NavierStokes" ) ,
42
- buildChartFromBenchmark ( "RayTrace" ) ,
43
- buildChartFromBenchmark ( "RegExp" ) ,
44
- buildChartFromBenchmark ( "Richards" ) ,
45
- buildChartFromBenchmark ( "Splay" ) ,
46
- buildChartFromBenchmark ( "score" ) ,
54
+ buildChartFromBenchmark ( "Crypto" , selectedEngines ) ,
55
+ buildChartFromBenchmark ( "DeltaBlue" , selectedEngines ) ,
56
+ buildChartFromBenchmark ( "EarleyBoyer" , selectedEngines ) ,
57
+ buildChartFromBenchmark ( "NavierStokes" , selectedEngines ) ,
58
+ buildChartFromBenchmark ( "RayTrace" , selectedEngines ) ,
59
+ buildChartFromBenchmark ( "RegExp" , selectedEngines ) ,
60
+ buildChartFromBenchmark ( "Richards" , selectedEngines ) ,
61
+ buildChartFromBenchmark ( "Splay" , selectedEngines ) ,
62
+ buildChartFromBenchmark ( "score" , selectedEngines ) ,
47
63
] ) . then ( ( charts ) => setData ( charts ) ) ;
48
- } , [ colorMode . colorMode ] ) ;
64
+ } , [ selectedEngines ] ) ;
49
65
50
66
return data && data . map ( ( chart ) => chart ) ;
51
- }
67
+ } ;
52
68
53
- const buildChartFromBenchmark = async ( name : string ) => {
69
+ const buildChartFromBenchmark = async ( name : string , engines : string [ ] ) => {
54
70
const data = await fetchData (
55
71
`https://raw.githubusercontent.com/boa-dev/data/main/bench/results/${ name } .json` ,
72
+ engines
56
73
) ;
57
74
58
75
const barData = getBarChartData ( data ) ;
@@ -64,50 +81,33 @@ const buildChartFromBenchmark = async (name: string) => {
64
81
</ div >
65
82
< div className = { styles [ "cards-wrap" ] } >
66
83
< div className = { `card ${ styles [ "benchmark-card" ] } ` } >
67
- < Line data = { data } > </ Line >
84
+ < Line data = { data } options = { ChartOptions } > </ Line >
68
85
</ div >
69
86
< div className = { `card ${ styles [ "benchmark-card" ] } ` } >
70
- < Bar data = { barData } > </ Bar >
87
+ < Bar data = { barData } options = { ChartOptions } > </ Bar >
71
88
</ div >
72
89
</ div >
73
90
</ div >
74
91
) ;
75
92
} ;
76
93
77
- const fetchData = async ( url : string ) => {
94
+ const fetchData = async ( url : string , engines : string [ ] ) => {
78
95
const response = await fetch ( url ) ;
79
96
const data = await response . json ( ) ;
97
+ // Add the dataset if the engine is enabled
80
98
return {
81
99
labels : data . labels . map ( ( epoch : number ) =>
82
- new Date ( epoch ) . toLocaleDateString ( ) ,
100
+ new Date ( epoch ) . toLocaleDateString ( )
83
101
) ,
84
- datasets : [
85
- {
86
- label : "boa" ,
87
- data : data . results [ "boa" ] ,
88
- fill : false ,
89
- } ,
90
- {
91
- label : "v8-jitless" ,
92
- data : data . results [ "v8-jitless" ] ,
93
- fill : false ,
94
- } ,
95
- {
96
- label : "libjs" ,
97
- data : data . results [ "libjs" ] ,
98
- fill : false ,
99
- } ,
100
- {
101
- label : "duktape" ,
102
- data : data . results [ "duktape" ] ,
103
- fill : false ,
104
- } ,
105
- {
106
- label : "quickjs" ,
107
- data : data . results [ "quickjs" ] ,
108
- fill : false ,
109
- } ,
110
- ] ,
102
+ datasets : Object . keys ( data . results )
103
+ . filter ( ( engine ) => engines . includes ( engine ) )
104
+ . map ( ( engine ) => {
105
+ return {
106
+ label : engine ,
107
+ data : data . results [ engine ] ,
108
+ fill : false ,
109
+ } ;
110
+ } ) ,
111
111
} ;
112
112
} ;
113
113
0 commit comments