Skip to content

Commit c287203

Browse files
authored
Fix re-sharing via URL (#118)
* dont overwrite 'title' with 'customtitle' to fix "reshare" functionality
1 parent 4558e63 commit c287203

File tree

6 files changed

+22
-13
lines changed

6 files changed

+22
-13
lines changed

src/components/Chart.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@
751751
let labelOffset = 0;
752752
for (const ds of datasets) {
753753
ctx.fillStyle = ds.color;
754-
const label = `— ${ds.title}`;
754+
const label = `— ${ds.displayTitle()}`;
755755
drawText(ctx, label, width - 10, height - 10 - labelOffset, 0, Align.right, Align.bottom);
756756
labelOffset += 12;
757757
}

src/components/LeftMenu.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<side class="left" {style} data-tour="browser">
1414
<ImportDataSetsMenu />
1515
<div class="tree">
16-
{#each $datasetTree.datasets as child (child.title)}
16+
{#each $datasetTree.datasets as child (child.displayTitle())}
1717
{#if child instanceof DataSet}
1818
<TreeLeafNode {chart} node={child} />
1919
{:else}

src/components/tree/TreeInnerNode.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
<span on:click={toggleExpanded}>
2525
<Fa icon={expanded ? faChevronDown : faChevronRight} style="width: 0.9em; margin-right: 0.5em" />
2626
<span>
27-
{node.title}
27+
{node.displayTitle()}
2828
</span>
2929
</span>
3030
{#if expanded}
31-
{#each node.datasets as child (child.title)}
31+
{#each node.datasets as child (child.displayTitle())}
3232
{#if child instanceof DataSet}
3333
<TreeLeafNode {chart} node={child} />
3434
{:else}

src/components/tree/TreeLeafNode.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
>
3636
<Fa icon={selected ? faEye : faEyeSlash} {color} style="width: 1em; margin-right: 0.5em" />
3737
<span>
38-
{node.title}
38+
{node.displayTitle()}
3939
</span>
4040
</div>
4141

src/data/DataSet.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export default class DataSet {
3434
this.gap = computeGap(data);
3535
}
3636

37+
displayTitle(): string {
38+
// for display to user; use custom title if available, otherwise default to title
39+
return this.customTitle || this.title;
40+
}
41+
3742
randomize(): void {
3843
this.color = getRandomColor();
3944
}
@@ -108,6 +113,11 @@ export class DataGroup {
108113

109114
constructor(public readonly title: string, public readonly datasets: (DataSet | DataGroup)[]) {}
110115

116+
displayTitle(): string {
117+
// for interface compatibility with `DataSet.displayTitle()`
118+
return this.title;
119+
}
120+
111121
flat(arr: DataSet[]): void {
112122
for (const child of this.datasets) {
113123
if (child instanceof DataSet) {

src/deriveLinkDefaults.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,7 @@ export function initialLoader(datasets: ILinkConfig['datasets']) {
181181

182182
return Promise.all(resolvedDataSets).then((data) => {
183183
const cleaned = data.filter((d): d is DataSet => d != null);
184-
cleaned.forEach((d) => {
185-
if (d.customTitle) {
186-
d.title = d.customTitle;
187-
}
188-
add(d);
189-
});
184+
cleaned.forEach((d) => add(d));
190185
return cleaned;
191186
});
192187
};
@@ -228,11 +223,15 @@ export function getDirectLinkImpl(state: SharedState): { url: URL; anySkipped: b
228223
let anySkipped = false;
229224
state.active.forEach((data) => {
230225
if (data.params) {
231-
config.datasets.push({
226+
const ds = {
232227
color: data.color,
233228
title: data.title,
234229
params: data.params as unknown as Record<string, unknown>,
235-
});
230+
};
231+
if (data.customTitle) {
232+
ds.params.custom_title = data.customTitle;
233+
}
234+
config.datasets.push(ds);
236235
} else {
237236
console.log('unable to get direct link to dataset:', data.title);
238237
anySkipped = true;

0 commit comments

Comments
 (0)