-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[WIP] feat: click trigger treemap tooltip #4245
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -360,8 +360,9 @@ | |
e.persist(); | ||
const { onMouseEnter, children } = this.props; | ||
const tooltipItem = findChildByType(children, Tooltip); | ||
const tooltipTrigger = tooltipItem.props.trigger; | ||
|
||
if (tooltipItem) { | ||
if (tooltipItem && tooltipTrigger === 'hover') { | ||
this.setState( | ||
{ | ||
isTooltipActive: true, | ||
|
@@ -382,8 +383,9 @@ | |
e.persist(); | ||
const { onMouseLeave, children } = this.props; | ||
const tooltipItem = findChildByType(children, Tooltip); | ||
const tooltipTrigger = tooltipItem.props.trigger; | ||
|
||
if (tooltipItem) { | ||
if (tooltipItem && tooltipTrigger === 'hover') { | ||
this.setState( | ||
{ | ||
isTooltipActive: false, | ||
|
@@ -419,8 +421,30 @@ | |
}; | ||
|
||
handleClick(node: TreemapNode) { | ||
const { onClick, type } = this.props; | ||
if (type === 'nest' && node.children) { | ||
const { onClick, type, children } = this.props; | ||
const tooltipItem = findChildByType(children, Tooltip); | ||
const tooltipTrigger = tooltipItem.props.trigger; | ||
const { activeNode } = this.state; | ||
const isNestedParentNode = type === 'nest' && node.children; | ||
|
||
if (tooltipTrigger === 'click') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How much of this is copy-paste from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just hacked this to get it it to work, no references from anywhere except Treemap (its not pretty I know :p) |
||
if ( | ||
(!activeNode || (activeNode && (activeNode.index !== node.index || activeNode.depth !== node.depth))) && | ||
!isNestedParentNode | ||
) { | ||
this.setState({ | ||
isTooltipActive: true, | ||
activeNode: node, | ||
}); | ||
} else { | ||
this.setState({ | ||
isTooltipActive: false, | ||
activeNode: null, | ||
}); | ||
} | ||
} | ||
|
||
if (isNestedParentNode) { | ||
const { width, height, dataKey, aspectRatio } = this.props; | ||
const root = computeNode({ | ||
depth: 0, | ||
|
@@ -446,7 +470,7 @@ | |
} | ||
|
||
handleNestIndex(node: TreemapNode, i: number) { | ||
let { nestIndex } = this.state; | ||
const { nestIndex, isTooltipActive } = this.state; | ||
const { width, height, dataKey, aspectRatio } = this.props; | ||
const root = computeNode({ | ||
depth: 0, | ||
|
@@ -455,13 +479,16 @@ | |
dataKey, | ||
}); | ||
|
||
if (isTooltipActive) { | ||
this.setState({ isTooltipActive: false, activeNode: null }); | ||
} | ||
|
||
const formatRoot = squarify(root, aspectRatio); | ||
|
||
nestIndex = nestIndex.slice(0, i + 1); | ||
this.setState({ | ||
formatRoot, | ||
currentRoot: node, | ||
nestIndex, | ||
nestIndex: nestIndex.slice(0, i + 1), | ||
}); | ||
} | ||
|
||
|
@@ -479,7 +506,7 @@ | |
const { isAnimationFinished } = this.state; | ||
const { width, height, x, y, depth } = nodeProps; | ||
const translateX = parseInt(`${(Math.random() * 2 - 1) * width}`, 10); | ||
let event = {} as any; | ||
let event = {}; | ||
if (isLeaf || type === 'nest') { | ||
event = { | ||
onMouseEnter: this.handleMouseEnter.bind(this, nodeProps), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another
findChildByType
😢 we need to move all of this to contextThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outside of this PR of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. I'm solving problems from issues in a siloed way.. need to start helping with the broader changes.