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

fix broken activateData for tooltips #285

Merged
merged 1 commit into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
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
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