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 #583 from FormidableLabs/improvement/victory-selec…
Browse files Browse the repository at this point in the history
…tion-container-perf

Improvement/victory selection container perf
  • Loading branch information
boygirl authored Apr 17, 2018
2 parents 383850f + 4e4dd13 commit 3495936
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/components/containers/selection-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ const SelectionHelpers = {
// eslint-disable-next-line complexity, max-statements
onMouseDown(evt, targetProps) {
evt.preventDefault();
const { activateSelectedData, allowSelection, polar } = targetProps;
const { activateSelectedData, allowSelection, polar, selectedData } = targetProps;
if (!allowSelection) {
return {};
}
const dimension = targetProps.selectionDimension;
const datasets = targetProps.datasets || [];
const { x, y } = Selection.getSVGEventCoordinates(evt);
const x1 = polar || dimension !== "y" ? x : Selection.getDomainCoordinates(targetProps).x[0];
const y1 = polar || dimension !== "x" ? y : Selection.getDomainCoordinates(targetProps).y[0];
Expand All @@ -86,12 +85,12 @@ const SelectionHelpers = {
targetProps.onSelectionCleared(defaults({}, mutatedProps, targetProps));
}
const parentMutation = [{ target: "parent", mutation: () => mutatedProps }];
const dataMutation = activateSelectedData ? [{
target: "data",
childName: targetProps.children || datasets.length ? "all" : undefined,
eventKey: "all",
mutation: () => null
}] : [];
const dataMutation = selectedData && activateSelectedData ?
selectedData.map((d) => {
return {
childName: d.childName, eventKey: d.eventKey, target: "data", mutation: () => null
};
}) : [];

return parentMutation.concat(...dataMutation);
},
Expand All @@ -100,7 +99,7 @@ const SelectionHelpers = {
const { allowSelection, select, polar } = targetProps;
const dimension = targetProps.selectionDimension;
if (!allowSelection || !select) {
return {};
return null;
} else {
const { x, y } = Selection.getSVGEventCoordinates(evt);
const x2 = polar || dimension !== "y" ? x : Selection.getDomainCoordinates(targetProps).x[1];
Expand All @@ -117,7 +116,7 @@ const SelectionHelpers = {
onMouseUp(evt, targetProps) {
const { activateSelectedData, allowSelection, x2, y2 } = targetProps;
if (!allowSelection) {
return {};
return null;
}
if (!x2 || !y2) {
return [{
Expand All @@ -130,7 +129,9 @@ const SelectionHelpers = {
const datasets = this.getDatasets(targetProps);
const bounds = Selection.getBounds(targetProps);
const selectedData = this.filterDatasets(targetProps, datasets, bounds);
const mutatedProps = { datasets, select: false, x1: null, x2: null, y1: null, y2: null };
const mutatedProps = {
selectedData, 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 = [{
Expand Down

0 comments on commit 3495936

Please sign in to comment.