Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle onBrushDomainChangeEnd on drag and pan of brush. #1126

Merged
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
28 changes: 16 additions & 12 deletions packages/victory-brush-container/src/brush-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,20 @@ const Helpers = {
return {};
},

onMouseUp(evt, targetProps) {
onMouseUp(evt, targetProps) { // eslint-disable-line max-statements, complexity
const {
x1, y1, x2, y2, onBrushDomainChange, onBrushDomainChangeEnd, onBrushCleared, domain,
allowResize, defaultBrushArea
x1, y1, x2, y2, isPanning, isSelecting, onBrushDomainChange, onBrushDomainChangeEnd,
onBrushCleared, domain, allowResize, allowDrag, defaultBrushArea
} = targetProps;
// if the mouse hasn't moved since a mouseDown event, select the default brush area

const defaultBrushHasArea = defaultBrushArea !== undefined && defaultBrushArea !== "none";
const cachedDomain = targetProps.cachedCurrentDomain || targetProps.currentDomain;
const currentDomain = this.getDefaultBrushArea(defaultBrushArea, domain, cachedDomain);
const mutatedProps = { isPanning: false, isSelecting: false };

// if the mouse hasn't moved since a mouseDown event, select the default brush area
if ((allowResize || defaultBrushHasArea) && (x1 === x2 || y1 === y2)) {
const cachedDomain = targetProps.cachedCurrentDomain || targetProps.currentDomain;
const currentDomain = this.getDefaultBrushArea(defaultBrushArea, domain, cachedDomain);
const mutatedProps = { isPanning: false, isSelecting: false, currentDomain };
mutatedProps.currentDomain = currentDomain;
if (isFunction(onBrushDomainChange)) {
onBrushDomainChange(currentDomain, defaults({}, mutatedProps, targetProps));
}
Expand All @@ -262,14 +265,15 @@ const Helpers = {
if (isFunction(onBrushCleared)) {
onBrushCleared(currentDomain, defaults({}, mutatedProps, targetProps));
}
return [{
target: "parent",
mutation: () => mutatedProps
}];
} else if ((allowDrag && isPanning) || (allowResize && isSelecting)) {
if (isFunction(onBrushDomainChangeEnd)) {
onBrushDomainChangeEnd(currentDomain, defaults({}, mutatedProps, targetProps));
}
}

return [{
target: "parent",
mutation: () => ({ isPanning: false, isSelecting: false })
mutation: () => mutatedProps
}];
},

Expand Down