@@ -17,7 +17,7 @@ import {customElement, property} from 'lit/decorators.js';
1717import { styleMap } from 'lit/directives/style-map.js' ;
1818
1919import { BatchSelection } from './batch_selection' ;
20- import { areFieldsComparable , Batch , Field , FieldId } from './entry' ;
20+ import { areFieldsComparable , Batch , Field , FieldId , fieldUnit } from './entry' ;
2121import { dispatch , EventType } from './events' ;
2222import { FieldMatcher , Match } from './matcher' ;
2323import { FieldMetric , getRatio } from './metric' ;
@@ -38,8 +38,8 @@ export class MatchesTableUi extends LitElement {
3838
3939 private renderFieldHeader ( batch : Batch , fieldIndex : number , rowspan : number ) {
4040 return html `
41- <th rowspan= ${ rowspan } title = " ${ batch . fields [ fieldIndex ] . description } "
42- class = "headerRow" >
41+ <th colspan = 2 rowspan= ${ rowspan }
42+ title = " ${ batch . fields [ fieldIndex ] . description } " class = "headerRow" >
4343 ${ batch . fields [ fieldIndex ] . displayName }
4444 </ th> ` ;
4545 }
@@ -53,34 +53,36 @@ export class MatchesTableUi extends LitElement {
5353 selection . rows [ selectionRowIndex ] [ selectionFieldIndex ] ;
5454 const referenceValue =
5555 reference . rows [ referenceRowIndex ] [ referenceFieldIndex ] ;
56- if ( selectionField . id === FieldId . EFFORT ||
57- selectionField . id === FieldId . QUALITY ) {
58- const referenceStyle = { 'color' : reference . color } ;
59- const selectionStyle = { 'color' : selection . color } ;
60- return html `
61- <td class= "encodingSettingCell" >
62- <span style= ${ styleMap ( referenceStyle ) } > ${ referenceValue } </ span>
63- <span style= ${ styleMap ( selectionStyle ) } > ${ selectionValue } </ span>
64- </ td> ` ;
65- }
66-
6756 const referenceField = reference . fields [ referenceFieldIndex ] ;
6857 const isNumber = selectionField . isNumber && referenceField . isNumber ;
6958 const cssClass = isNumber ? 'numberCell' : '' ;
7059
71- if ( isNumber && selectionField . id !== FieldId . WIDTH &&
72- selectionField . id !== FieldId . HEIGHT &&
73- selectionField . id !== FieldId . FRAME_COUNT &&
74- selectionField . id !== FieldId . MEGAPIXELS ) {
75- const ratio =
76- getRatio ( selectionValue as number , referenceValue as number ) ;
77- return html `<td class= "${ cssClass } " > ${ getRelativePercent ( ratio ) } </ td> ` ;
78- }
79- if ( selectionValue === referenceValue ) {
80- return html `<td class= "${ cssClass } " > ${ selectionValue } </ td> ` ;
60+ if ( selectionField . id !== FieldId . EFFORT &&
61+ selectionField . id !== FieldId . QUALITY ) {
62+ if ( this . state . showRelativeRatios && isNumber &&
63+ selectionField . id !== FieldId . WIDTH &&
64+ selectionField . id !== FieldId . HEIGHT &&
65+ selectionField . id !== FieldId . FRAME_COUNT &&
66+ selectionField . id !== FieldId . MEGAPIXELS ) {
67+ const ratio =
68+ getRatio ( selectionValue as number , referenceValue as number ) ;
69+ return html `<td colspan= 2 class= "${ cssClass } " > ${
70+ getRelativePercent ( ratio ) } </ td> `;
71+ }
72+ if ( selectionValue === referenceValue ) {
73+ return html `<td colspan= 2 class= "${ cssClass } " > ${ selectionValue } </ td> ` ;
74+ }
8175 }
76+ const referenceStyle = { 'color' : reference . color } ;
77+ const selectionStyle = { 'color' : selection . color } ;
78+ // TODO: Align all floating point numbers in same column at decimal point.
8279 return html `
83- <td class= "${ cssClass } " > ${ selectionValue } ≠ ${ referenceValue } </ td> ` ;
80+ <td style= ${ styleMap ( referenceStyle ) } class= "${ cssClass } " >
81+ ${ referenceValue }
82+ </ td>
83+ <td style= ${ styleMap ( selectionStyle ) } class= "${ cssClass } " >
84+ ${ selectionValue }
85+ </ td> ` ;
8486 }
8587
8688 // Header rows (two needed because some cells use a rowspan)
@@ -89,8 +91,8 @@ export class MatchesTableUi extends LitElement {
8991 reference : Batch , matchers : FieldMatcher [ ] , metrics : FieldMetric [ ] ,
9092 referenceSharedFieldIndices : number [ ] ) {
9193 return html `<tr>
92- <th colspan= ${ matchers . length } class= "headerRow" > Matchers </ th>
93- <th colspan= ${ metrics . length } class= "headerRow" > Metrics </ th>
94+ <th colspan= ${ matchers . length * 2 } class= "headerRow" > Matchers </ th>
95+ <th colspan= ${ metrics . length * 2 } class= "headerRow" > Metrics </ th>
9496 ${ referenceSharedFieldIndices . map ( ( fieldIndex ) => {
9597 return this . renderFieldHeader ( reference , fieldIndex , /*rowspan=*/ 2 ) ;
9698 } ) }
@@ -112,6 +114,66 @@ export class MatchesTableUi extends LitElement {
112114 </ tr> ` ;
113115 }
114116
117+ private renderAbsoluteMeanRows (
118+ selection : Batch , numColumns : number , matchers : FieldMatcher [ ] ,
119+ metricIndices : number [ ] , selectionSharedFieldIndices : number [ ] ) {
120+ const selectionStyle = { 'color' : selection . color } ;
121+ return html `
122+ <tr>
123+ <th colspan= ${ numColumns * 2 } > Arithmetic means </ th>
124+ </ tr>
125+ <tr>
126+ <td colspan= ${ matchers . length * 2 } class= "missing" > </ td>
127+ ${ metricIndices . map ( ( metricIndex ) => {
128+ const mean = this . batchSelection . stats [ metricIndex ] . getAbsoluteMean ( ) ;
129+ const metric = this . state . metrics [ metricIndex ] ;
130+ const fieldIndex = metric . fieldIndices [ this . batchSelection . batch . index ] ;
131+ const field = this . batchSelection . batch . fields [ fieldIndex ] ;
132+ return html `
133+ <td colspan= 2 class= "numberCell" style = ${ styleMap ( selectionStyle ) } >
134+ ${ mean } ${ fieldUnit ( field . id ) }
135+ </ td> ` ;
136+ } ) }
137+ <td colspan= ${ selectionSharedFieldIndices . length * 2 } class= "missing" >
138+ </ td>
139+ </ tr> ` ;
140+ }
141+
142+ private renderRelativeMeanRows (
143+ numColumns : number , matchers : FieldMatcher [ ] , metricIndices : number [ ] ,
144+ selectionSharedFieldIndices : number [ ] ) {
145+ return html `
146+ <tr>
147+ <th colspan= ${ numColumns * 2 } > Arithmetic means </ th>
148+ </ tr>
149+ <tr>
150+ <td colspan= ${ matchers . length * 2 } class= "missing" > </ td>
151+ ${ metricIndices . map ( ( metricIndex ) => {
152+ const mean = this . batchSelection . stats [ metricIndex ] . getRelativeMean (
153+ /*geometric=*/ false ) ;
154+ return html `
155+ <td colspan= 2 class= "numberCell" > ${ getRelativePercent ( mean ) } </ td> ` ;
156+ } ) }
157+ <td colspan= ${ selectionSharedFieldIndices . length * 2 } class= "missing" >
158+ </ td>
159+ </ tr>
160+
161+ <tr>
162+ <th colspan= ${ numColumns * 2 } > Geometric means </ th>
163+ </ tr>
164+ <tr>
165+ <td colspan= ${ matchers . length * 2 } class= "missing" > </ td>
166+ ${ metricIndices . map ( ( metricIndex ) => {
167+ const mean = this . batchSelection . stats [ metricIndex ] . getRelativeMean (
168+ /*geometric=*/ true ) ;
169+ return html `
170+ <td colspan= 2 class= "numberCell" > ${ getRelativePercent ( mean ) } </ td> ` ;
171+ } ) }
172+ <td colspan= ${ selectionSharedFieldIndices . length * 2 } class= "missing" >
173+ </ td>
174+ </ tr> ` ;
175+ }
176+
115177 override render ( ) {
116178 if ( ! this . batchSelection ) return html `` ;
117179 const reference =
@@ -215,7 +277,7 @@ export class MatchesTableUi extends LitElement {
215277 truncatedRows = html `
216278 <tr>
217279 <td @click = ${ onDisplayHiddenRow }
218- colspan= ${ numColumns } class= "hiddenRow" >
280+ colspan= ${ numColumns * 2 } class= "hiddenRow" >
219281 ${ rows . length - 100 } hidden rows . Click to expand .
220282 </ td>
221283 </ tr> ` ;
@@ -230,34 +292,14 @@ export class MatchesTableUi extends LitElement {
230292 ${ this . renderSecondHeaderRow ( reference , matchers , metrics ) }
231293 ${ rows . map ( renderRow ) }
232294 ${ truncatedRows }
233-
234- <tr>
235- <th colspan= ${ numColumns } > Arithmetic means </ th>
236- </ tr>
237- <tr>
238- <td colspan= ${ matchers . length } class= "missing" > </ td>
239- ${ metricIndices . map ( ( metricIndex ) => {
240- const mean =
241- this . batchSelection . stats [ metricIndex ] . getMean ( /*geometric=*/ false ) ;
242- return html `<td class= "numberCell" > ${ getRelativePercent ( mean ) } </ td> ` ;
243- } ) }
244- <td colspan= ${ selectionSharedFieldIndices . length } class= "missing" >
245- </ td>
246- </ tr>
247-
248- <tr>
249- <th colspan= ${ numColumns } > Geometric means </ th>
250- </ tr>
251- <tr>
252- <td colspan= ${ matchers . length } class= "missing" > </ td>
253- ${ metricIndices . map ( ( metricIndex ) => {
254- const mean =
255- this . batchSelection . stats [ metricIndex ] . getMean ( /*geometric=*/ true ) ;
256- return html `<td class= "numberCell" > ${ getRelativePercent ( mean ) } </ td> ` ;
257- } ) }
258- <td colspan= ${ selectionSharedFieldIndices . length } class= "missing" >
259- </ td>
260- </ tr>
295+ ${
296+ this . state . showRelativeRatios ?
297+ this . renderRelativeMeanRows (
298+ numColumns , matchers , metricIndices ,
299+ selectionSharedFieldIndices ) :
300+ this . renderAbsoluteMeanRows (
301+ selection , numColumns , matchers , metricIndices ,
302+ selectionSharedFieldIndices ) }
261303 </ table> ` ;
262304 }
263305
@@ -299,9 +341,6 @@ export class MatchesTableUi extends LitElement {
299341 .numberCell {
300342 text-align : right;
301343 }
302- .encodingSettingCell {
303- text-align : center;
304- }
305344
306345 tr {
307346 background : var (--mdc-theme-background );
0 commit comments