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

add allowSelection prop #540

Merged
merged 1 commit into from
Dec 8, 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
15 changes: 10 additions & 5 deletions src/components/containers/selection-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ const SelectionHelpers = {
// eslint-disable-next-line complexity
onMouseDown(evt, targetProps) {
evt.preventDefault();
const { polar } = targetProps;
const { allowSelection, polar } = targetProps;
if (!allowSelection) {
return {};
}
const dimension = targetProps.selectionDimension;
const datasets = targetProps.datasets || [];
const { x, y } = Selection.getSVGEventCoordinates(evt);
Expand All @@ -93,9 +96,9 @@ const SelectionHelpers = {
},

onMouseMove(evt, targetProps) {
const { select, polar } = targetProps;
const { allowSelection, select, polar } = targetProps;
const dimension = targetProps.selectionDimension;
if (!select) {
if (!allowSelection || !select) {
return {};
} else {
const { x, y } = Selection.getSVGEventCoordinates(evt);
Expand All @@ -111,7 +114,10 @@ const SelectionHelpers = {
},

onMouseUp(evt, targetProps) {
const { x2, y2 } = targetProps;
const { allowSelection, x2, y2 } = targetProps;
if (!allowSelection) {
return {};
}
if (!x2 || !y2) {
return [{
target: "parent",
Expand All @@ -126,7 +132,6 @@ const SelectionHelpers = {
const mutatedProps = { datasets, select: false, x1: null, x2: null, y1: null, y2: null };
const callbackMutation = selectedData && isFunction(targetProps.onSelection) ?
targetProps.onSelection(selectedData, bounds, defaults({}, mutatedProps, targetProps)) : {};

const parentMutation = [{
target: "parent",
mutation: () => mutatedProps
Expand Down
2 changes: 2 additions & 0 deletions src/components/containers/victory-selection-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const selectionContainerMixin = (base) => class VictorySelectionContainer
static displayName = "VictorySelectionContainer";
static propTypes = {
...VictoryContainer.propTypes,
allowSelection: PropTypes.bool,
onSelection: PropTypes.func,
onSelectionCleared: PropTypes.func,
selectionComponent: PropTypes.element,
Expand All @@ -15,6 +16,7 @@ export const selectionContainerMixin = (base) => class VictorySelectionContainer
};
static defaultProps = {
...VictoryContainer.defaultProps,
allowSelection: true,
selectionComponent: <rect/>,
selectionStyle: {
stroke: "transparent",
Expand Down