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

guard for minimum domains, set maximum scaling for wheel events #431

Merged
merged 2 commits into from
Feb 6, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
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