@@ -25,34 +25,51 @@ ChartJS.register(
2525 Tooltip ,
2626 Legend ,
2727 Colors ,
28- BarElement ,
28+ BarElement
2929) ;
3030
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+
3248 const [ data , setData ] = React . useState ( [ ] ) ;
3349 const colorMode = useColorMode ( ) ;
3450 ChartJS . defaults . color = colorMode . colorMode === "light" ? "#666" : "white" ;
3551
3652 React . useEffect ( ( ) => {
3753 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 ) ,
4763 ] ) . then ( ( charts ) => setData ( charts ) ) ;
48- } , [ colorMode . colorMode ] ) ;
64+ } , [ selectedEngines ] ) ;
4965
5066 return data && data . map ( ( chart ) => chart ) ;
51- }
67+ } ;
5268
53- const buildChartFromBenchmark = async ( name : string ) => {
69+ const buildChartFromBenchmark = async ( name : string , engines : string [ ] ) => {
5470 const data = await fetchData (
5571 `https://raw.githubusercontent.com/boa-dev/data/main/bench/results/${ name } .json` ,
72+ engines
5673 ) ;
5774
5875 const barData = getBarChartData ( data ) ;
@@ -64,50 +81,33 @@ const buildChartFromBenchmark = async (name: string) => {
6481 </ div >
6582 < div className = { styles [ "cards-wrap" ] } >
6683 < div className = { `card ${ styles [ "benchmark-card" ] } ` } >
67- < Line data = { data } > </ Line >
84+ < Line data = { data } options = { ChartOptions } > </ Line >
6885 </ div >
6986 < div className = { `card ${ styles [ "benchmark-card" ] } ` } >
70- < Bar data = { barData } > </ Bar >
87+ < Bar data = { barData } options = { ChartOptions } > </ Bar >
7188 </ div >
7289 </ div >
7390 </ div >
7491 ) ;
7592} ;
7693
77- const fetchData = async ( url : string ) => {
94+ const fetchData = async ( url : string , engines : string [ ] ) => {
7895 const response = await fetch ( url ) ;
7996 const data = await response . json ( ) ;
97+ // Add the dataset if the engine is enabled
8098 return {
8199 labels : data . labels . map ( ( epoch : number ) =>
82- new Date ( epoch ) . toLocaleDateString ( ) ,
100+ new Date ( epoch ) . toLocaleDateString ( )
83101 ) ,
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+ } ) ,
111111 } ;
112112} ;
113113
0 commit comments