Skip to content

Commit 1750af8

Browse files
authored
Fix RD-mode and two-batch links (#45)
1 parent 376c487 commit 1750af8

5 files changed

Lines changed: 31 additions & 10 deletions

File tree

CHANGELOG.md

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

3+
## v0.7.3
4+
5+
- Fix RD-curve and two-batch view links.
6+
37
## v0.7.2
48

59
- Remember the selected tabs, batch, and match as URL parameters.

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.7.2",
3+
"version": "0.7.3",
44
"description": "Codec performance comparison tool",
55
"publisher": "Google LLC",
66
"author": "Yannis Guyon",

src/batch_ui.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {customElement, property} from 'lit/decorators.js';
2424
import {Batch} from './entry';
2525
import {EventType, listen} from './events';
2626
import {State} from './state';
27-
import {getRdModeHash} from './state_hash';
27+
import {getRdModeHash, getTwoBatchViewHash} from './state_hash';
2828

2929
/** Component displaying the details of a batch. */
3030
@customElement('batch-ui')
@@ -46,13 +46,10 @@ export class BatchUi extends LitElement {
4646
// Keep the batches in the same order.
4747
const minIndex = Math.min(refIndex, batchIndex);
4848
const maxIndex = Math.max(refIndex, batchIndex);
49-
// Remove any state that depends on batch indices.
50-
const stateHash = new URLSearchParams(
51-
window.location.hash.length > 3 ? window.location.hash.slice(1) : '');
52-
stateHash.delete('shown');
49+
5350
const twoBatchLink = `?batch=${this.state.batches[minIndex].url}&batch=${
54-
this.state.batches[maxIndex].url}${
55-
stateHash.size > 0 ? `#${stateHash.toString()}` : ''}`;
51+
this.state.batches[maxIndex].url}#${
52+
getTwoBatchViewHash(this.state, window.location.hash)}`;
5653

5754
const rdModeHash = getRdModeHash(
5855
this.state, this.batch, this.batch, undefined, window.location.hash);

src/codec_compare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class CodecCompare extends LitElement {
259259
</p>
260260
261261
<p id="credits">
262-
Codec Compare version 0.7.2<br>
262+
Codec Compare version 0.7.3<br>
263263
<a href="https://github.com/webmproject/codec-compare">
264264
Sources on GitHub
265265
</a>

src/state_hash.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,28 @@ export function trimDefaultStateMapping(
327327
return values;
328328
}
329329

330-
/** Returns the hash part of the URL to a Rate-Distortion curve plot. */
330+
/** Returns the hash part of the URL for a two-batch view. */
331+
export function getTwoBatchViewHash(state: State, currentHash: string) {
332+
// Get the current hash (the part after the '#' in the URL), if any.
333+
const hash =
334+
new URLSearchParams(currentHash.length > 3 ? currentHash.slice(1) : '');
335+
// Remove any state that depends on indices.
336+
hash.delete('shown');
337+
hash.delete('panel_batch');
338+
hash.delete('panel_match');
339+
// Do not open the batch panel on load.
340+
hash.delete('panel');
341+
return hash.toString();
342+
}
343+
344+
/** Returns the hash part of the URL for a Rate-Distortion curve plot. */
331345
export function getRdModeHash(
332346
state: State, batch: Batch, reference: Batch, rowIndex: number|undefined,
333347
currentHash: string) {
334348
// No distortion means no Rate-Distortion curve.
335349
if (state.batchesAreLikelyLossless) return undefined;
336350

351+
// Get the current hash (the part after the '#' in the URL), if any.
337352
const hash =
338353
new URLSearchParams(currentHash.length > 3 ? currentHash.slice(1) : '');
339354

@@ -422,6 +437,11 @@ export function getRdModeHash(
422437
}
423438
// Use the default reference because it has no impact in RD mode.
424439
hash.delete('ref');
440+
// Remove any state that depends on indices.
441+
hash.delete('panel_batch');
442+
hash.delete('panel_match');
443+
// Do not open the batch panel on load.
444+
hash.delete('panel');
425445

426446
if (rowIndex !== undefined) {
427447
// Only display the selected image.

0 commit comments

Comments
 (0)