Skip to content

Commit

Permalink
Merge pull request #520 from FormidableLabs/feature/allow-pan
Browse files Browse the repository at this point in the history
add allowPan prop for VictoryZoomContainer
  • Loading branch information
boygirl authored Sep 29, 2017
2 parents 44136ef + 9c3c0c9 commit b1308e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/components/containers/victory-zoom-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const zoomContainerMixin = (base) => class VictoryZoomContainer extends b

static propTypes = {
...VictoryContainer.propTypes,
allowPan: PropTypes.bool,
allowZoom: PropTypes.bool,
clipContainerComponent: PropTypes.element.isRequired,
downsample: PropTypes.oneOfType([
Expand All @@ -34,6 +35,7 @@ export const zoomContainerMixin = (base) => class VictoryZoomContainer extends b
static defaultProps = {
...VictoryContainer.defaultProps,
clipContainerComponent: <VictoryClipContainer/>,
allowPan: true,
allowZoom: true,
zoomActive: false
};
Expand Down
19 changes: 14 additions & 5 deletions src/components/containers/zoom-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ const Helpers = {
return defaults({}, childrenDomain, originalDomain, domain);
},

onMouseDown(evt) {
onMouseDown(evt, targetProps) {
evt.preventDefault();
if (!targetProps.allowPan) {
return undefined;
}
const { x, y } = Selection.getSVGEventCoordinates(evt);
return [{
target: "parent",
Expand All @@ -175,7 +178,10 @@ const Helpers = {
}];
},

onMouseUp() {
onMouseUp(evt, targetProps) {
if (!targetProps.allowPan) {
return undefined;
}
return [{
target: "parent",
mutation: () => {
Expand All @@ -184,7 +190,10 @@ const Helpers = {
}];
},

onMouseLeave() {
onMouseLeave(evt, targetProps) {
if (!targetProps.allowPan) {
return undefined;
}
return [{
target: "parent",
mutation: () => {
Expand All @@ -194,7 +203,7 @@ const Helpers = {
},

onMouseMove(evt, targetProps, eventKey, ctx) { // eslint-disable-line max-params
if (targetProps.panning) {
if (targetProps.panning && targetProps.allowPan) {
const { scale, startX, startY, onZoomDomainChange, zoomDimension, zoomDomain } = targetProps;
const { x, y } = Selection.getSVGEventCoordinates(evt);
const originalDomain = this.getDomain(targetProps);
Expand Down Expand Up @@ -224,7 +233,7 @@ const Helpers = {

onWheel(evt, targetProps, eventKey, ctx) { // eslint-disable-line max-params
if (!targetProps.allowZoom) {
return {};
return undefined;
}
const { onZoomDomainChange, zoomDimension, zoomDomain } = targetProps;
const originalDomain = this.getDomain(targetProps);
Expand Down

0 comments on commit b1308e2

Please sign in to comment.