Skip to content

Commit

Permalink
Merge pull request carbon-design-system#793 from hlyang397/update-ini…
Browse files Browse the repository at this point in the history
…tial-zoom-domain

* feat: keep initialZoomDomain in model to detect change

- update zoom domain if initialZoomDomain is changed

* refactor: update variable names for readability

Co-authored-by: Fei Z <[email protected]>
Co-authored-by: Eliad Moosavi <[email protected]>
  • Loading branch information
3 people authored Sep 10, 2020
1 parent 020ebaa commit f6b40f3
Showing 1 changed file with 34 additions and 14 deletions.
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

0 comments on commit f6b40f3

Please sign in to comment.