Skip to content

Commit c510273

Browse files
authored
Shorten batch visibility URL hash in codec-compare (#27)
Load default_batches.json instead of demo_batches.json by default. Move the ref batch's name to the top of the Summary and Advanced tabs. Replace the focus button by a ref batch dropdown in Advanced tab. Display the reference batch in the Summary tab in absolute mode. Display "reference" chip in Advanced tab instead of "-" cells. Display per-batch match count in Advanced tab, instead of total sum.
1 parent 9f55cde commit c510273

14 files changed

Lines changed: 225 additions & 108 deletions

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## v0.5.4
4+
5+
- Shorten the URL hash way of storing which batches are displayed.
6+
- Load default_batches.json instead of demo_batches.json by default.
7+
- Move the reference batch's name to the top of the Summary and Advanced tabs.
8+
- Replace the focus icon button by a dropdown to select the reference batch in
9+
the Advanced tab.
10+
- Display the reference batch in the Summary tab in absolute mode.
11+
- Display a "reference" chip in Advanced tab instead of "-" cells.
12+
- Display the number of comparisons per batch instead of the sum in the Advanced
13+
tab.
14+
315
## v0.5.3
416

517
- Display the constants-table-ui component when selecting a match.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codec_compare",
3-
"version": "0.5.3",
3+
"version": "0.5.4",
44
"description": "Codec performance comparison tool",
55
"publisher": "Google LLC",
66
"author": "Yannis Guyon",

readme_preview.png

-161 Bytes
Loading

src/batch_selection_actions_ui.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,7 @@ export class BatchSelectionActionsUi extends LitElement {
3434

3535
override render() {
3636
const batchSelection = this.state.batchSelections[this.batchSelectionIndex];
37-
38-
// Note: A span is used because title does not appear on hover when
39-
// mwc-icon-button is disabled.
40-
const focusTitle = `${
41-
this.isReference ? 'Used' :
42-
'Use'} as reference to compare other codecs with`;
43-
4437
return html`
45-
<span title="${focusTitle}">
46-
<mwc-icon-button
47-
?disabled=${this.isReference}
48-
icon=${this.isReference ? 'center_focus_strong' : 'center_focus_weak'}
49-
@click=${() => {
50-
this.state.referenceBatchSelectionIndex = this.batchSelectionIndex;
51-
dispatch(EventType.REFERENCE_CHANGED);
52-
}}>
53-
</mwc-icon-button>
54-
</span>
5538
<span title="${batchSelection.isDisplayed ? 'Hide' : 'Show'}">
5639
<mwc-icon-button
5740
icon=${batchSelection.isDisplayed ? 'visibility' : 'visibility_off'}

src/batch_selections_ui.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,6 @@ export class BatchSelectionsUi extends LitElement {
4848
const referenceBatch =
4949
this.state.batchSelections[this.state.referenceBatchSelectionIndex]
5050
.batch;
51-
if (this.state.showRelativeRatios &&
52-
batchSelectionIndex === this.state.referenceBatchSelectionIndex) {
53-
const title = referenceBatch.name + ' is used as reference';
54-
return html`
55-
<td class="stat" title="${title}">
56-
-
57-
</td>
58-
`;
59-
}
6051
if (batchSelection.matchedDataPoints.rows.length === 0) {
6152
const title = 'There is no data to compare ' + batch.name + ' with ' +
6253
referenceBatch.name;
@@ -142,7 +133,8 @@ export class BatchSelectionsUi extends LitElement {
142133
}
143134

144135
private renderBatchSelectionRow(
145-
batchSelection: BatchSelection, index: number) {
136+
batchSelection: BatchSelection, index: number,
137+
numEnabledMetrics: number) {
146138
const batch = batchSelection.batch;
147139
return html`
148140
<tr>
@@ -162,10 +154,20 @@ export class BatchSelectionsUi extends LitElement {
162154
.isReference=${index === this.state.referenceBatchSelectionIndex}>
163155
</batch-selection-actions-ui>
164156
</td>
165-
${this.state.metrics.map((metric: FieldMetric, metricIndex: number) => {
166-
return this.renderRowMetric(
167-
batchSelection, index, metric, batchSelection.stats[metricIndex]);
168-
})}
157+
${
158+
(this.state.showRelativeRatios &&
159+
index === this.state.referenceBatchSelectionIndex) ?
160+
html`
161+
<td class="notText" colspan=${numEnabledMetrics}
162+
title="${batch.name} is used as reference">
163+
<span class="referenceBatchChip">reference</span>
164+
</td>` :
165+
this.state.metrics.map(
166+
(metric: FieldMetric, metricIndex: number) => {
167+
return this.renderRowMetric(
168+
batchSelection, index, metric,
169+
batchSelection.stats[metricIndex]);
170+
})}
169171
</tr>`;
170172
}
171173

@@ -182,7 +184,8 @@ export class BatchSelectionsUi extends LitElement {
182184
${
183185
this.state.batchSelections.map(
184186
(batchSelection: BatchSelection, index: number) => {
185-
return this.renderBatchSelectionRow(batchSelection, index);
187+
return this.renderBatchSelectionRow(
188+
batchSelection, index, numEnabledMetrics);
186189
})}
187190
</table>
188191
`;
@@ -267,6 +270,15 @@ export class BatchSelectionsUi extends LitElement {
267270
#filterChip:hover {
268271
cursor: pointer;
269272
}
273+
274+
.referenceBatchChip {
275+
background: var(--mdc-theme-primary);
276+
color: var(--mdc-theme-background);
277+
border-radius: 16px;
278+
padding: 2px 8px;
279+
font-size: 12px;
280+
margin-left: 8px;
281+
}
270282
`;
271283
}
272284

src/batch_selections_ui_test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('BatchSelectionsUi', () => {
6363
expect(stats).toBeDefined();
6464
if (stats === undefined) return;
6565

66-
expect(stats).toHaveSize(state.batches.length);
66+
expect(stats).toHaveSize(state.batches.length - 1);
6767
expect(stats).toHaveSize(expectedStats.length);
6868
for (const [index, stat] of stats.entries()) {
6969
expect(stat).toBeInstanceOf(HTMLTableCellElement);
@@ -75,20 +75,20 @@ describe('BatchSelectionsUi', () => {
7575
};
7676

7777
// No stat was computed yet.
78-
expectStatsToBe(['-', 'n/a']);
78+
expectStatsToBe(['n/a']);
7979

8080
// The first batch is used as the reference so there is no stat compared
8181
// with itself. The second batch is compared with the first batch based on
8282
// the values of the field used as a metric.
8383
expect(state.referenceBatchSelectionIndex).toBe(0);
8484
dispatch(EventType.MATCHER_OR_METRIC_CHANGED);
8585
await batchSelectionsEl.updateComplete;
86-
expectStatsToBe(['-', '+120.0%']);
86+
expectStatsToBe(['+120.0%']);
8787

8888
// Swapping the reference leads to the opposite results.
8989
state.referenceBatchSelectionIndex = 1;
9090
dispatch(EventType.REFERENCE_CHANGED);
9191
await batchSelectionsEl.updateComplete;
92-
expectStatsToBe(['-54.5%', '-']);
92+
expectStatsToBe(['-54.5%']);
9393
});
9494
});

src/codec_compare.ts

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import '@material/mwc-button';
1516
import '@material/mwc-icon';
17+
import '@material/mwc-menu';
1618
import '@material/mwc-tab-bar';
1719
import '@material/mwc-tab';
1820
import './batch_name_ui';
@@ -27,6 +29,8 @@ import './panel_ui';
2729
import './sentence_ui';
2830
import './settings_ui';
2931

32+
import {ActionDetail} from '@material/mwc-list';
33+
import {Menu} from '@material/mwc-menu';
3034
import {css, html, LitElement} from 'lit';
3135
import {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-button 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-button>
85+
<mwc-menu
86+
.anchor=${this.referenceMenu}
87+
corner="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-list-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-list-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;

src/entry_loader_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('loadBatchJson', () => {
148148
describe('loadJsonContainingBatchJsonPaths', () => {
149149
it('loads a JSON file', async () => {
150150
const paths =
151-
await loadJsonContainingBatchJsonPaths('/assets/demo_batches.json');
151+
await loadJsonContainingBatchJsonPaths('/assets/default_batches.json');
152152
expect(paths).toEqual(jasmine.arrayWithExactContents([
153153
'/assets/demo_batch_some_codec_exp.json',
154154
'/assets/demo_batch_some_codec_effort1.json',

src/help_ui.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,8 @@ export class HelpUi extends LitElement {
100100
['codec-compare', 'gallery-ui', '#sourceDataSet']);
101101
}
102102

103-
// This is not the description of the #referenceBatch <p> but it is used as
104-
// a convenient top anchor to fill the remaining graph area till the bottom
105-
// of the screen.
106-
positionElementAtTheRightOf(
107-
this.graphDescription, ['codec-compare', '#referenceBatch']);
108103
this.graphDescription.style.bottom = '60px';
104+
this.graphDescription.style.left = '600px';
109105
this.graphDescription.style.height = '';
110106

111107
// Note that the positions above will be stale if the elements used as
@@ -154,7 +150,7 @@ export class HelpUi extends LitElement {
154150
point is an image compressed then decompressed, with some codec settings
155151
and some measured information such as encoding duration, visual
156152
distortion etc. The number of comparisons is the number of matched pairs
157-
across all batches.
153+
between a batch and the reference batch.
158154
</p>
159155
</div>
160156
@@ -191,8 +187,6 @@ export class HelpUi extends LitElement {
191187
target="_blank">
192188
bits-per-pixel usually seen on the web
193189
<mwc-icon>open_in_new</mwc-icon></a>.<br>
194-
Click the focus button to set a batch as the reference to compare the
195-
others against.<br>
196190
Click the visibility button to show or hide a specific batch in the plot
197191
and in the SUMMARY tab.<br>
198192
The statistics relative to the reference batch for the fields selected
@@ -211,7 +205,7 @@ export class HelpUi extends LitElement {
211205
presented here to compare their relative performance.<br>
212206
<br>
213207
The count associated with each asset corresponds to the number of
214-
matched pairs based on that asset.<br>
208+
matched pairs based on that asset accross all batches.<br>
215209
Each image can be toggled on or off across all batches.
216210
</p>
217211
</div>`;
@@ -276,7 +270,7 @@ export class HelpUi extends LitElement {
276270
top: 0;
277271
bottom: 0;
278272
right: 0;
279-
/** Translucid enough to see through, dark enough to read white text.*/
273+
/* Translucid enough to see through, dark enough to read white text. */
280274
background: rgba(0,0,0,0.7);
281275
}
282276

0 commit comments

Comments
 (0)