1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15+ import '@material/mwc-button' ;
1516import '@material/mwc-icon' ;
17+ import '@material/mwc-menu' ;
1618import '@material/mwc-tab-bar' ;
1719import '@material/mwc-tab' ;
1820import './batch_name_ui' ;
@@ -27,6 +29,8 @@ import './panel_ui';
2729import './sentence_ui' ;
2830import './settings_ui' ;
2931
32+ import { ActionDetail } from '@material/mwc-list' ;
33+ import { Menu } from '@material/mwc-menu' ;
3034import { css , html , LitElement } from 'lit' ;
3135import { customElement , query } from 'lit/decorators.js' ;
3236
@@ -67,14 +71,37 @@ export class CodecCompare extends LitElement {
6771 @query ( 'help-ui' ) private readonly helpUi ! : HelpUi ;
6872 @query ( 'loading-ui' ) private readonly loadingUi ! : LoadingUi ;
6973
74+ @query ( '#referenceMenu' ) private readonly referenceMenu ! : Menu ;
75+
7076 private renderReference ( referenceBatch : Batch ) {
7177 return html `
72- <p id= "referenceBatch" >
73- compared to <batch- name-ui .batch = ${ referenceBatch } @click = ${ ( ) => {
74- dispatch (
75- EventType . BATCH_INFO_REQUEST , { batchIndex : referenceBatch . index } ) ;
76- } } > </ batch- name-ui> .
77- </ p> ` ;
78+ <mwc- butto n icon= "arrow_drop_down" trailingIcon raised
79+ title = "Change the reference batch to compare other codecs with"
80+ id = "referenceButton" @click = ${ ( ) => {
81+ this . referenceMenu . show ( ) ;
82+ } } >
83+ <batch- name-ui .batch = ${ referenceBatch } > </ batch- name-ui>
84+ </ mwc- butto n>
85+ <mwc- menu
86+ .anchor = ${ this . referenceMenu }
87+ cor ner= "BOTTOM_LEFT"
88+ menuCorner = "START"
89+ id = "referenceMenu"
90+ @action = ${ ( e : CustomEvent < ActionDetail > ) => {
91+ this . state . referenceBatchSelectionIndex = e . detail . index ;
92+ dispatch ( EventType . REFERENCE_CHANGED ) ;
93+ } } >
94+ ${
95+ this . state . batches . map (
96+ ( batch ) => html `
97+ <mwc- lis t- item ?activated= ${ batch . index === referenceBatch . index } >
98+ <batch- name-ui .batch = ${ batch } > </ batch- name-ui>
99+ ${
100+ batch . index === referenceBatch . index ?
101+ html `<span class= "referenceBatchChip" > reference </ span> ` :
102+ html `` }
103+ </ mwc- lis t- item> ` ) }
104+ </ mwc- menu> ` ;
78105 }
79106
80107 private renderSentence ( ) {
@@ -107,17 +134,27 @@ export class CodecCompare extends LitElement {
107134 }
108135
109136 override render ( ) {
110- let numComparisons = 0 ;
137+ let minNumComparisons = - 1 ;
138+ let maxNumComparisons = - 1 ;
111139 let truncatedResults = false ;
112140 let hasHistograms = false ;
113141 for ( const [ index , batchSelection ] of this . state . batchSelections
114142 . entries ( ) ) {
115143 if ( index !== this . state . referenceBatchSelectionIndex ) {
116- numComparisons += batchSelection . matchedDataPoints . rows . length ;
144+ const numComparisons = batchSelection . matchedDataPoints . rows . length ;
145+ minNumComparisons = minNumComparisons === - 1 ?
146+ numComparisons :
147+ Math . min ( minNumComparisons , numComparisons ) ;
148+ maxNumComparisons = maxNumComparisons === - 1 ?
149+ numComparisons :
150+ Math . max ( maxNumComparisons , numComparisons ) ;
117151 truncatedResults ||= batchSelection . matchedDataPoints . limited ;
118152 }
119153 hasHistograms ||= batchSelection . histogram . length > 0 ;
120154 }
155+ const numComparisonsStr = minNumComparisons === maxNumComparisons ?
156+ `${ Math . max ( 0 , maxNumComparisons ) } ` :
157+ `${ minNumComparisons } to ${ maxNumComparisons } ` ;
121158
122159 let referenceBatch : Batch | undefined = undefined ;
123160 if ( this . state . referenceBatchSelectionIndex >= 0 &&
@@ -143,11 +180,15 @@ export class CodecCompare extends LitElement {
143180 <div id= "advancedInterface" >
144181 <div class= "scrollFriendlyPadding" > </ div>
145182 ${ truncatedResults ? this . renderTruncatedResults ( ) : '' }
146- <p id= "numComparisons" > Based on ${ numComparisons } comparisons , </ p>
183+ <p id= "numComparisons" style = "position: relative;">
184+ Based on ${ numComparisonsStr } comparisons
185+ ${
186+ referenceBatch ? html `with ${ this . renderReference ( referenceBatch ) } ` :
187+ '' } ,
188+ </ p>
147189 <matchers- ui .state = ${ this . state } id= "matchers" > </ matchers- ui>
148190 <metrics- ui .state = ${ this . state } id= "metrics" > </ metrics- ui>
149191 <batch- selections- ui .state = ${ this . state } > </ batch- selections- ui>
150- ${ referenceBatch ? this . renderReference ( referenceBatch ) : '' }
151192 <div class= "scrollFriendlyPadding" > </ div>
152193 </ div>
153194 </ div>
@@ -204,7 +245,7 @@ export class CodecCompare extends LitElement {
204245 </ p>
205246
206247 <p id= "credits" >
207- Codec Compare version 0.5.3 <br>
248+ Codec Compare version 0.5.4 <br>
208249 <a href= "https://github.com/webmproject/codec-compare" >
209250 Sources on GitHub
210251 </ a>
@@ -277,8 +318,8 @@ export class CodecCompare extends LitElement {
277318 let jsonPaths = url . getAll ( 'batch' ) ;
278319 try {
279320 if ( jsonPaths . length === 0 ) {
280- const pathOfJsonContaingJsonPaths =
281- decodeURIComponent ( url . get ( 'load' ) ?? '/demo_batches .json' ) ;
321+ const pathOfJsonContaingJsonPaths = decodeURIComponent (
322+ url . get ( 'load' ) ?? '/default_batches .json' ) ;
282323 jsonPaths = await loadJsonContainingBatchJsonPaths (
283324 pathOfJsonContaingJsonPaths ) ;
284325 }
@@ -365,6 +406,29 @@ export class CodecCompare extends LitElement {
365406 batch-name-ui : hover {
366407 cursor : pointer;
367408 }
409+ # referenceButton {
410+ --mdc-theme-primary : white;
411+ --mdc-theme-on-primary : var (--mdc-theme-text );
412+ /* Align the following comma to the bottom of the button. */
413+ vertical-align : bottom;
414+ }
415+ # referenceButton batch-name-ui {
416+ color : var (--mdc-theme-text );
417+ font-size : 16px ;
418+ white-space : nowrap;
419+ text-transform : none;
420+ }
421+ # referenceMenu {
422+ --mdc-menu-item-height : 20px ;
423+ }
424+ .referenceBatchChip {
425+ background : var (--mdc-theme-primary );
426+ color : var (--mdc-theme-background );
427+ border-radius : 16px ;
428+ padding : 2px 8px ;
429+ font-size : 12px ;
430+ margin-left : 8px ;
431+ }
368432 # truncatedResults {
369433 background : orange;
370434 border-radius : 16px ;
0 commit comments