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

add allowPan prop for VictoryZoomContainer #520

Merged
merged 1 commit into from
Sep 29, 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
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