@@ -20,52 +20,70 @@ function identityCells(run: Run): string[] {
2020 ] ;
2121}
2222
23+ interface TableValue {
24+ value : string ;
25+ reference : string ;
26+ }
27+
2328function renderTable (
2429 id : string ,
2530 caption : string ,
2631 valueLabel : string ,
27- rows : Array < { run : Run ; value : string ; reference : string } > ,
32+ runs : Run [ ] ,
33+ valueForRun : ( run : Run ) => TableValue ,
2834) : HTMLElement {
29- const details = h ( 'details' , { class : 'chart-data-details' , id } ) ;
30- details . appendChild ( h ( 'summary' , { } , `${ caption } (${ rows . length } rows)` ) ) ;
31- const wrapper = h ( 'div' , { class : 'chart-data-table-wrap' } ) ;
32- const table = h ( 'table' , { class : 'chart-data-table' } ) ;
33- table . appendChild (
34- h (
35- 'caption' ,
36- { } ,
37- `${ caption } . Full labels are shown here when chart labels are truncated.` ,
38- ) ,
39- ) ;
35+ const details = h ( 'details' , { class : 'chart-data-details' , id } ) as HTMLDetailsElement ;
36+ details . appendChild ( h ( 'summary' , { } , `${ caption } (${ runs . length } rows)` ) ) ;
37+
38+ let materialized = false ;
39+ const materialize = ( ) : void => {
40+ if ( materialized ) return ;
41+ materialized = true ;
42+
43+ const wrapper = h ( 'div' , { class : 'chart-data-table-wrap' } ) ;
44+ const table = h ( 'table' , { class : 'chart-data-table' } ) ;
45+ table . appendChild (
46+ h (
47+ 'caption' ,
48+ { } ,
49+ `${ caption } . Full labels are shown here when chart labels are truncated.` ,
50+ ) ,
51+ ) ;
4052
41- const header = h ( 'tr' ) ;
42- for ( const label of [
43- 'Model' ,
44- 'Variant' ,
45- 'Penalty' ,
46- 'Solver' ,
47- 'Backend / reference' ,
48- 'Scale' ,
49- valueLabel ,
50- 'Reference' ,
51- ] ) {
52- header . appendChild ( h ( 'th' , { scope : 'col' } , label ) ) ;
53- }
54- const thead = h ( 'thead' ) ;
55- thead . appendChild ( header ) ;
56- table . appendChild ( thead ) ;
53+ const header = h ( 'tr' ) ;
54+ for ( const label of [
55+ 'Model' ,
56+ 'Variant' ,
57+ 'Penalty' ,
58+ 'Solver' ,
59+ 'Backend / reference' ,
60+ 'Scale' ,
61+ valueLabel ,
62+ 'Reference' ,
63+ ] ) {
64+ header . appendChild ( h ( 'th' , { scope : 'col' } , label ) ) ;
65+ }
66+ const thead = h ( 'thead' ) ;
67+ thead . appendChild ( header ) ;
68+ table . appendChild ( thead ) ;
5769
58- const tbody = h ( 'tbody' ) ;
59- for ( const { run, value, reference } of rows ) {
60- const tr = h ( 'tr' ) ;
61- for ( const cell of [ ...identityCells ( run ) , value , reference ] ) {
62- tr . appendChild ( h ( 'td' , { } , cell ) ) ;
70+ const tbody = h ( 'tbody' ) ;
71+ for ( const run of runs ) {
72+ const { value, reference } = valueForRun ( run ) ;
73+ const tr = h ( 'tr' ) ;
74+ for ( const cell of [ ...identityCells ( run ) , value , reference ] ) {
75+ tr . appendChild ( h ( 'td' , { } , cell ) ) ;
76+ }
77+ tbody . appendChild ( tr ) ;
6378 }
64- tbody . appendChild ( tr ) ;
65- }
66- table . appendChild ( tbody ) ;
67- wrapper . appendChild ( table ) ;
68- details . appendChild ( wrapper ) ;
79+ table . appendChild ( tbody ) ;
80+ wrapper . appendChild ( table ) ;
81+ details . appendChild ( wrapper ) ;
82+ } ;
83+
84+ details . addEventListener ( 'toggle' , ( ) => {
85+ if ( details . open ) materialize ( ) ;
86+ } ) ;
6987 return details ;
7088}
7189
@@ -87,20 +105,32 @@ export function renderChartDataFallback(
87105 ) ,
88106 ) ;
89107
90- const timing = selectTimingRuns ( timingSourceRuns , state ) . runs . map ( ( run ) => ( {
91- run,
92- value : `${ run . metrics . timing ! . fit_time_ms . toFixed ( 3 ) } ms` ,
93- reference : run . metrics . timing ! . quality ,
94- } ) ) ;
95- const speedup = selectSpeedupRuns ( speedupSourceRuns , state ) . runs . map ( ( run ) => ( {
96- run,
97- value : `${ run . metrics . speedup ! . value . toFixed ( 3 ) } ×` ,
98- reference : `${ run . metrics . speedup ! . reference_framework } (${ run . metrics . speedup ! . reported_semantics } )` ,
99- } ) ) ;
108+ const timingRuns = selectTimingRuns ( timingSourceRuns , state ) . runs ;
109+ const speedupRuns = selectSpeedupRuns ( speedupSourceRuns , state ) . runs ;
100110
101- section . appendChild ( renderTable ( 'timing-chart-data' , 'Fit Time chart data' , 'Time' , timing ) ) ;
102111 section . appendChild (
103- renderTable ( 'speedup-chart-data' , 'Speedup chart data' , 'Speedup' , speedup ) ,
112+ renderTable (
113+ 'timing-chart-data' ,
114+ 'Fit Time chart data' ,
115+ 'Time' ,
116+ timingRuns ,
117+ run => ( {
118+ value : `${ run . metrics . timing ! . fit_time_ms . toFixed ( 3 ) } ms` ,
119+ reference : run . metrics . timing ! . quality ,
120+ } ) ,
121+ ) ,
122+ ) ;
123+ section . appendChild (
124+ renderTable (
125+ 'speedup-chart-data' ,
126+ 'Speedup chart data' ,
127+ 'Speedup' ,
128+ speedupRuns ,
129+ run => ( {
130+ value : `${ run . metrics . speedup ! . value . toFixed ( 3 ) } ×` ,
131+ reference : `${ run . metrics . speedup ! . reference_framework } (${ run . metrics . speedup ! . reported_semantics } )` ,
132+ } ) ,
133+ ) ,
104134 ) ;
105135 return section ;
106136}
0 commit comments