Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: keep initialZoomDomain in model to detect change #793

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions packages/core/src/components/axes/zoom-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,6 @@ export class ZoomBar extends Component {
Events.ZoomBar.UPDATE,
this.render.bind(this)
);

// get initZoomDomain
const initialZoomDomain = Tools.getProperty(
this.model.getOptions(),
"zoomBar",
"top",
"initialZoomDomain"
);
if (initialZoomDomain !== null) {
this.model.set(
{ zoomDomain: initialZoomDomain },
{ skipUpdate: true }
);
}
}

render(animate = true) {
Expand Down Expand Up @@ -128,6 +114,41 @@ export class ZoomBar extends Component {
// add value 0 to the extended domain for zoom bar area graph
this.compensateDataForDefaultDomain(zoomBarData, defaultDomain);

const initialZoomDomainInModel = this.model.get(
hlyang397 marked this conversation as resolved.
Show resolved Hide resolved
"initialZoomDomain"
);
// get initZoomDomain
const initialZoomDomainInProp = Tools.getProperty(
this.model.getOptions(),
"zoomBar",
"top",
"initialZoomDomain"
);

// update initialZoomDomain and set zoomDomain in model only if the configuration is changed
// not the same object, or both start date and end date are not equal
if (
!(
initialZoomDomainInModel === initialZoomDomainInProp ||
(initialZoomDomainInModel &&
initialZoomDomainInProp &&
initialZoomDomainInModel[0].valueOf() ===
initialZoomDomainInProp[0].valueOf() &&
initialZoomDomainInModel[1].valueOf() ===
initialZoomDomainInProp[1].valueOf())
)
) {
this.model.set(
{
initialZoomDomain: initialZoomDomainInProp,
zoomDomain: initialZoomDomainInProp
? initialZoomDomainInProp
: defaultDomain
},
{ skipUpdate: true }
);
}

this.xScale.range([axesLeftMargin, width]).domain(defaultDomain);

// keep max selection range
Expand Down