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

Improvement/victory selection container perf #583

Merged
merged 2 commits into from
Apr 17, 2018
Merged
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
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