Skip to content

Commit 03715c7

Browse files
authored
honor the 'viewport' of direct links (dont autofit them away) (#114)
1 parent 9e1d105 commit 03715c7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/deriveLinkDefaults.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
importTwitter,
1515
importWiki,
1616
} from './api/EpiData';
17+
import { NavMode } from './components/chartUtils';
1718
import DataSet, { DataGroup, DEFAULT_GROUP, flatten, DEFAULT_VIEWPORT } from './data/DataSet';
1819
import EpiDate from './data/EpiDate';
1920
import EpiPoint from './data/EpiPoint';
@@ -35,13 +36,15 @@ export interface SharedState {
3536
active: DataSet[];
3637
viewport: null | [number, number, number, number];
3738
showPoints: boolean;
39+
navMode: NavMode;
3840
}
3941

4042
const DEFAULT_VALUES: SharedState = {
4143
group: DEFAULT_GROUP,
4244
active: [],
4345
viewport: DEFAULT_VIEWPORT,
4446
showPoints: false,
47+
navMode: NavMode.pan,
4548
};
4649

4750
const lookups = {
@@ -202,6 +205,8 @@ export default function deriveLinkDefaults(): SharedState & { loader?: ReturnTyp
202205
active: [],
203206
showPoints: parsed.chart?.showPoints ?? DEFAULT_VALUES.showPoints,
204207
viewport: parsed.chart?.viewport ?? DEFAULT_VALUES.viewport,
208+
// if we were not passed viewport coords, set to autofit mode
209+
navMode: parsed.chart?.viewport ? DEFAULT_VALUES.navMode : NavMode.autofit,
205210
loader: initialLoader(parsed.datasets),
206211
};
207212
} catch (err) {
@@ -214,7 +219,8 @@ export default function deriveLinkDefaults(): SharedState & { loader?: ReturnTyp
214219
export function getDirectLinkImpl(state: SharedState): { url: URL; anySkipped: boolean } {
215220
const config: ILinkConfig = {
216221
chart: {
217-
viewport: state.viewport ?? [0, 0, 0, 0],
222+
// if in autofit mode, pass null viewport, else preserve viewport (or default to 0s)
223+
viewport: state.navMode == NavMode.autofit ? null : state.viewport ?? [0, 0, 0, 0],
218224
showPoints: state.showPoints,
219225
},
220226
datasets: [],

src/store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { get, writable } from 'svelte/store';
2-
import { NavMode } from './components/chartUtils';
32
import DataSet, { DataGroup } from './data/DataSet';
43
import deriveLinkDefaults, { getDirectLinkImpl } from './deriveLinkDefaults';
54
import FormSelections from './components/dialogs/formSelections';
@@ -16,7 +15,7 @@ export const expandedDataGroups = writable([defaults.group]);
1615

1716
export const isShowingPoints = writable(defaults.showPoints);
1817
export const initialViewport = writable(defaults.viewport);
19-
export const navMode = writable(NavMode.autofit);
18+
export const navMode = writable(defaults.navMode);
2019

2120
export function getFormSelections() {
2221
try {
@@ -97,6 +96,7 @@ export function getDirectLink(chart: IChart): { url: URL; anySkipped: boolean }
9796
active: get(activeDatasets),
9897
showPoints: get(isShowingPoints),
9998
viewport: chart.getViewport(),
99+
navMode: get(navMode),
100100
});
101101
}
102102

0 commit comments

Comments
 (0)