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 #571 from FormidableLabs/improvement/activate-data
Browse files Browse the repository at this point in the history
add activate props, and selectionBlacklist
  • Loading branch information
boygirl authored Feb 12, 2018
2 parents 50c9cd2 + 86634f8 commit b4a22dc
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
36 changes: 19 additions & 17 deletions src/components/containers/selection-helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Selection, Data, Helpers } from "victory-core";
import { assign, defaults, throttle, isFunction } from "lodash";
import { assign, defaults, throttle, isFunction, includes } from "lodash";
import React from "react";

const SelectionHelpers = {
Expand All @@ -14,7 +14,11 @@ const SelectionHelpers = {
};

const iteratee = (child, childName, parent) => {
if (child.type && child.type.role === "axis") {
const role = child.type && child.type.role;
const blacklist = props.selectionBlacklist || [];
if (role === "axis" || role === "legend" || role === "label") {
return null;
} else if (includes(blacklist, childName)) {
return null;
} else if (child.type && isFunction(child.type.getData)) {
child = parent ? React.cloneElement(child, parent.props) : child;
Expand Down Expand Up @@ -62,10 +66,10 @@ const SelectionHelpers = {
return count > 0 ? { eventKey, data } : null;
},

// eslint-disable-next-line complexity
// eslint-disable-next-line complexity, max-statements
onMouseDown(evt, targetProps) {
evt.preventDefault();
const { allowSelection, polar } = targetProps;
const { activateSelectedData, allowSelection, polar } = targetProps;
if (!allowSelection) {
return {};
}
Expand All @@ -81,17 +85,15 @@ const SelectionHelpers = {
if (isFunction(targetProps.onSelectionCleared)) {
targetProps.onSelectionCleared(defaults({}, mutatedProps, targetProps));
}
return [
{
target: "parent",
mutation: () => mutatedProps
}, {
target: "data",
childName: targetProps.children || datasets.length ? "all" : undefined,
eventKey: "all",
mutation: () => null
}
];
const parentMutation = [{ target: "parent", mutation: () => mutatedProps }];
const dataMutation = activateSelectedData ? [{
target: "data",
childName: targetProps.children || datasets.length ? "all" : undefined,
eventKey: "all",
mutation: () => null
}] : [];

return parentMutation.concat(...dataMutation);
},

onMouseMove(evt, targetProps) {
Expand All @@ -113,7 +115,7 @@ const SelectionHelpers = {
},

onMouseUp(evt, targetProps) {
const { allowSelection, x2, y2 } = targetProps;
const { activateSelectedData, allowSelection, x2, y2 } = targetProps;
if (!allowSelection) {
return {};
}
Expand All @@ -136,7 +138,7 @@ const SelectionHelpers = {
mutation: () => mutatedProps
}];

const dataMutation = selectedData ?
const dataMutation = selectedData && activateSelectedData ?
selectedData.map((d) => {
return {
childName: d.childName, eventKey: d.eventKey, target: "data",
Expand Down
3 changes: 3 additions & 0 deletions src/components/containers/victory-selection-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ export const selectionContainerMixin = (base) => class VictorySelectionContainer
static displayName = "VictorySelectionContainer";
static propTypes = {
...VictoryContainer.propTypes,
activateSelectedData: PropTypes.bool,
allowSelection: PropTypes.bool,
disable: PropTypes.bool,
onSelection: PropTypes.func,
onSelectionCleared: PropTypes.func,
selectionBlacklist: PropTypes.arrayOf(PropTypes.string),
selectionComponent: PropTypes.element,
selectionDimension: PropTypes.oneOf(["x", "y"]),
selectionStyle: PropTypes.object
};
static defaultProps = {
...VictoryContainer.defaultProps,
activateSelectedData: true,
allowSelection: true,
selectionComponent: <rect/>,
selectionStyle: {
Expand Down
4 changes: 4 additions & 0 deletions src/components/containers/victory-voronoi-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const voronoiContainerMixin = (base) => class VictoryVoronoiContainer ext
static displayName = "VictoryVoronoiContainer";
static propTypes = {
...VictoryContainer.propTypes,
activateData: PropTypes.bool,
activateLabels: PropTypes.bool,
disable: PropTypes.bool,
labelComponent: PropTypes.element,
labels: PropTypes.func,
Expand All @@ -20,6 +22,8 @@ export const voronoiContainerMixin = (base) => class VictoryVoronoiContainer ext
};
static defaultProps = {
...VictoryContainer.defaultProps,
activateData: true,
activateLabels: true,
labelComponent: <VictoryTooltip/>,
voronoiPadding: 5
};
Expand Down
22 changes: 19 additions & 3 deletions src/components/containers/voronoi-helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Selection, Data, Helpers } from "victory-core";
import { assign, throttle, isFunction, groupBy, keys, isEqual, includes } from "lodash";
import { assign, throttle, isFunction, isEmpty, groupBy, keys, isEqual, includes } from "lodash";
import { voronoi as d3Voronoi } from "d3-voronoi";
import React from "react";

Expand Down Expand Up @@ -94,7 +94,15 @@ const VoronoiHelpers = {

getActiveMutations(props, point) {
const { childName, continuous } = point;
const targets = props.labels ? ["data"] : ["data", "labels"];
const { activateData, activateLabels, labels } = props;
if (!activateData && !activateLabels) {
return [];
}
const defaultTarget = activateData ? ["data"] : [];
const targets = labels && !activateLabels ? defaultTarget : defaultTarget.concat("labels");
if (isEmpty(targets)) {
return [];
}
return targets.map((target) => {
const eventKey = continuous === true && target === "data" ? "all" : point.eventKey;
return {
Expand All @@ -105,7 +113,15 @@ const VoronoiHelpers = {

getInactiveMutations(props, point) {
const { childName, continuous } = point;
const targets = props.labels ? ["data"] : ["data", "labels"];
const { activateData, activateLabels, labels } = props;
if (!activateData && !activateLabels) {
return [];
}
const defaultTarget = activateData ? ["data"] : [];
const targets = labels && !activateLabels ? defaultTarget : defaultTarget.concat("labels");
if (isEmpty(targets)) {
return [];
}
return targets.map((target) => {
const eventKey = continuous && target === "data" ? "all" : point.eventKey;
return {
Expand Down

0 comments on commit b4a22dc

Please sign in to comment.