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 3 commits
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
48 changes: 34 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,40 @@ export class ZoomBar extends Component {
// add value 0 to the extended domain for zoom bar area graph
this.compensateDataForDefaultDomain(zoomBarData, defaultDomain);

// get old initialZoomDomain from model
const oldInitialZoomDomain = this.model.get("initialZoomDomain");
// get new initialZoomDomain from option
const newInitialZoomDomain = Tools.getProperty(
this.model.getOptions(),
"zoomBar",
"top",
"initialZoomDomain"
);

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

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

// keep max selection range
Expand Down