Skip to content

Commit 1774ece

Browse files
committed
Keep zoom after on data change
1 parent 9ca2b6a commit 1774ece

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/Chart.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ export default function Chart({
3838
return;
3939
}
4040

41+
const keepZoom =
42+
currentTimeDomain.current?.start === timeDomain.start &&
43+
currentTimeDomain.current?.end === timeDomain.end &&
44+
currentTimeDomain.current?.type === timeDomain.type;
4145
const props: HtmlProps = {
4246
width,
4347
height,
4448
locale,
49+
keepZoom,
4550
datasets,
4651
timeDomain,
4752
noDataString,
@@ -139,6 +144,7 @@ type HtmlProps = {
139144
zoomEnabled: boolean;
140145
height: number;
141146
width: number;
147+
keepZoom: boolean;
142148
marginHorizontal: number;
143149
locale: string;
144150
timeDomain: TimeDomain;

src/drawFunction.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ window.draw = props => {
345345
const newScale =
346346
!x ||
347347
!wholeScaleX ||
348-
zoomEnabled !== props.zoomEnabled ||
349-
timeDomain !== props.timeDomain
348+
!props.keepZoom
350349
zoomEnabled = props.zoomEnabled
351350
timeDomain = props.timeDomain
352351
if (newScale) {
@@ -769,6 +768,10 @@ window.draw = props => {
769768
}
770769
771770
updateHighlight(newScale ? 0 : 300)
771+
772+
if (!newScale && props.keepZoom) {
773+
rescaleY({ sourceEvent: null })
774+
}
772775
} catch (e) {
773776
postMessage('error', e.message)
774777
}
@@ -784,4 +787,4 @@ console.log = (...args) => {
784787
}
785788
786789
true
787-
`
790+
`;

0 commit comments

Comments
 (0)