Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #431 from FormidableLabs/minimum-zoom-domain
Browse files Browse the repository at this point in the history
guard for minimum domains, set maximum scaling for wheel events
  • Loading branch information
boygirl authored Feb 6, 2017
2 parents 6dc5ec4 + b90d886 commit 6760a0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 1 addition & 3 deletions demo/components/victory-brush-container-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ class App extends React.Component {

constructor() {
super();
this.state = {
points: []
};
this.state = {};
}

handleZoom(domain) {
Expand Down
14 changes: 10 additions & 4 deletions src/components/containers/zoom-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ const Helpers = {
const [from, to] = currentDomain;
const range = Math.abs(from - to);
const midpoint = +from + (range / 2);
const newRange = (range * factor) / 2;
return [
const newRange = (range * Math.abs(factor)) / 2;
const minDomain = Collection.containsDates(originalDomain) ?
[ new Date(midpoint - 4), new Date(midpoint) ] : // 4ms is standard browser date precision
[ midpoint - 1 / Number.MAX_SAFE_INTEGER, midpoint ];
const newDomain = [
Collection.getMaxValue([midpoint - newRange, fromBound]),
Collection.getMinValue([midpoint + newRange, toBound])
];
return Math.abs(minDomain[1] - minDomain[0]) > Math.abs(newDomain[1] - newDomain[0]) ?
minDomain : newDomain;
},

/**
Expand Down Expand Up @@ -136,8 +141,9 @@ const Helpers = {
const lastDomain = targetProps.currentDomain || zoomDomain || originalDomain;
const {x} = lastDomain;
const xBounds = originalDomain.x;
// TODO: Check scale factor
const nextXDomain = this.scale(x, xBounds, 1 + (evt.deltaY / 300));
const sign = evt.deltaY > 0 ? 1 : -1;
const delta = Math.min(Math.abs(evt.deltaY / 300), 0.75); // TODO: Check scale factor
const nextXDomain = this.scale(x, xBounds, 1 + sign * delta);
const currentDomain = { x: nextXDomain, y: originalDomain.y };
const resumeAnimation = this.handleAnimation(ctx);
if (isFunction(onDomainChange)) {
Expand Down

0 comments on commit 6760a0f

Please sign in to comment.