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 #285 from FormidableLabs/bug/tooltip-activateData
Browse files Browse the repository at this point in the history
fix broken activateData for tooltips
  • Loading branch information
boygirl authored Aug 8, 2017
2 parents 7f25238 + b840115 commit da942e1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 49 deletions.
86 changes: 38 additions & 48 deletions src/victory-tooltip/victory-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,55 +94,45 @@ export default class VictoryTooltip extends React.Component {
groupComponent: <g/>
};

static defaultEvents = [{
target: "data",
eventHandlers: {
onMouseOver: (targetProps) => {
return [
{
target: "labels",
mutation: () => ({ active: true })
}, {
target: "data",
mutation: () => targetProps.activateData ? ({ active: true }) : ({ active: undefined })
}
];
},
onTouchStart: (targetProps) => {
return [
{
target: "labels",
mutation: () => ({ active: true })
}, {
target: "data",
mutation: () => targetProps.activateData ? ({ active: true }) : ({ active: undefined })
}
];
},
onMouseOut: () => {
return [
{
target: "labels",
mutation: () => ({ active: undefined })
}, {
target: "data",
mutation: () => ({ active: undefined })
}
];
},
onTouchEnd: () => {
return [
{
target: "labels",
mutation: () => ({ active: undefined })
}, {
target: "data",
mutation: () => ({ active: undefined })
}
];
static defaultEvents = (props) => {
return [{
target: "data",
eventHandlers: {
onMouseOver: () => {
return props.activateData ?
[
{ target: "labels", mutation: () => ({ active: true }) },
{ target: "data", mutation: () => ({ active: true }) }
] :
[{ target: "labels", mutation: () => ({ active: true }) }];
},
onTouchStart: () => {
return props.activateData ?
[
{ target: "labels", mutation: () => ({ active: true }) },
{ target: "data", mutation: () => ({ active: true }) }
] :
[{ target: "labels", mutation: () => ({ active: true }) }];
},
onMouseOut: () => {
return props.activateData ?
[
{ target: "labels", mutation: () => ({ active: false }) },
{ target: "data", mutation: () => ({ active: false }) }
] :
[{ target: "labels", mutation: () => ({ active: false }) }];
},
onTouchEnd: () => {
return props.activateData ?
[
{ target: "labels", mutation: () => ({ active: false }) },
{ target: "data", mutation: () => ({ active: false }) }
] :
[{ target: "labels", mutation: () => ({ active: false }) }];
}
}
}
}];
}];
};

shouldComponentUpdate(nextProps) {
return !Collection.areVictoryPropsEqual(this.props, nextProps);
Expand Down
4 changes: 3 additions & 1 deletion src/victory-util/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ export default {
getComponentEvents(props, components) {
const events = Array.isArray(components) && components.reduce((memo, componentName) => {
const component = props[componentName];
const componentEvents = component && component.type && component.type.defaultEvents;
const defaultEvents = component && component.type && component.type.defaultEvents;
const componentEvents = isFunction(defaultEvents) ?
defaultEvents(component.props) : defaultEvents;
memo = Array.isArray(componentEvents) ? memo.concat(...componentEvents) : memo;
return memo;
}, []);
Expand Down

0 comments on commit da942e1

Please sign in to comment.