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

Apply hover effect when hovering on donut arc or detail line #535

Merged
merged 2 commits into from
Mar 8, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion src/components/NibrsDonut.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class NibrsDonut extends React.Component {
this.state = { hover: null }
}

onDetailHover = d => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of adding this, i think we can leverage the rememberValue function that's there, and pass that down to the NibrsDonutDetails component and then update the onMouseOver={() => onMouseOver(d.key)} to just be onMouseOver={rememberValue(d.key)}

this.setState({ hover: d })
}

rememberValue = d => () => {
this.setState({ hover: d })
}
Expand Down Expand Up @@ -71,7 +75,14 @@ class NibrsDonut extends React.Component {
</svg>
</div>
<div className='col col-6 px1'>
<NibrsDonutDetails colorMap={colorMap} data={dataSorted} selected={hover} />
<NibrsDonutDetails
colorMap={colorMap}
data={dataSorted}
hover={hover}
onMouseOver={this.onDetailHover}
onMouseOut={this.forgetValue}
selected={hover}
/>
</div>
</div>
</div>
Expand Down
14 changes: 11 additions & 3 deletions src/components/NibrsDonutDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@ import React from 'react'

const fmt = format(',.0f')

const NibrsDonutDetails = ({ colorMap, data, selected }) => (
const NibrsDonutDetails = ({ colorMap, data, hover, onMouseOver, onMouseOut, selected }) => (
<div className='mt2 lg-mt4'>
<span className='mb2 bold caps fs-12 red'>Incidents</span>
<ul className='list-style-none p0 m0 fs-14'>
{data.map((d, i) => {
const active = d.key === selected
const border = active ? 'border-bottom' : 'border-bottom-dashed'
const opacity = hover === null || active ? 1 : 0.5
return (
<li
key={i}
className={`mb1 flex items-baseline ${border}`}
className={`mb1 flex items-baseline ${border} cursor-pointer`}
onMouseOver={() => onMouseOver(d.key)}
onMouseOut={onMouseOut}
>
<span
className='mr1'
style={{ width: 10, height: 10, backgroundColor: colorMap(d.key) }}
style={{
width: 10,
height: 10,
backgroundColor: colorMap(d.key),
opacity,
}}
/>
<div className={`flex flex-auto justify-between ${active && 'bold'}`}>
<span>{d.key}</span>
Expand Down