Skip to content

Commit

Permalink
feat(theming): add ability to theme crosshairs
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed Apr 17, 2019
1 parent e46b10c commit f03848f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 34 deletions.
7 changes: 7 additions & 0 deletions packages/core/src/theming/defaultTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ export const defaultTheme = {
padding: '3px 5px',
},
},
crosshair: {
line: {
stroke: '#000000',
strokeWidth: 1,
strokeOpacity: 0.35,
},
},
annotations: {
text: {
fontSize: 13,
Expand Down
35 changes: 35 additions & 0 deletions packages/core/src/theming/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,39 @@ export const markersThemePropType = PropTypes.shape({
text: PropTypes.shape({ ...textProps }).isRequired,
})

export const crosshairPropType = PropTypes.shape({
line: PropTypes.shape({
stroke: PropTypes.string.isRequired,
strokeWidth: PropTypes.number.isRequired,
strokeDasharray: PropTypes.string,
}).isRequired,
})

export const annotationsPropType = PropTypes.shape({
text: PropTypes.shape({
...textProps,
outlineWidth: PropTypes.number.isRequired,
outlineColor: PropTypes.string.isRequired,
}).isRequired,
link: PropTypes.shape({
stroke: PropTypes.string.isRequired,
strokeWidth: PropTypes.number.isRequired,
outlineWidth: PropTypes.number.isRequired,
outlineColor: PropTypes.string.isRequired,
}).isRequired,
outline: PropTypes.shape({
stroke: PropTypes.string.isRequired,
strokeWidth: PropTypes.number.isRequired,
outlineWidth: PropTypes.number.isRequired,
outlineColor: PropTypes.string.isRequired,
}).isRequired,
symbol: PropTypes.shape({
fill: PropTypes.string.isRequired,
outlineWidth: PropTypes.number.isRequired,
outlineColor: PropTypes.string.isRequired,
}).isRequired,
})

export const themePropType = PropTypes.shape({
background: PropTypes.string.isRequired,
fontFamily: PropTypes.string.isRequired,
Expand All @@ -70,4 +103,6 @@ export const themePropType = PropTypes.shape({
labels: labelsThemePropType.isRequired,
dots: dotsThemePropType.isRequired,
markers: markersThemePropType,
crosshair: crosshairPropType.isRequired,
annotations: annotationsPropType.isRequired,
})
42 changes: 18 additions & 24 deletions packages/line/src/LineSlicesItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,25 @@ Chip.propTypes = {
color: PropTypes.string.isRequired,
}

const LineSlicesItem = ({ slice, height, showTooltip, hideTooltip, isHover }) => (
<g transform={`translate(${slice.x}, 0)`}>
{isHover && (
<line
x1={0}
x2={0}
y1={0}
y2={height}
stroke="#000"
strokeOpacity={0.35}
strokeWidth={1}
const LineSlicesItem = ({ slice, height, showTooltip, hideTooltip, isHover, theme }) => {
return (
<g transform={`translate(${slice.x}, 0)`}>
{isHover && (
<line x1={0} x2={0} y1={0} y2={height} fill="none" style={theme.crosshair.line} />
)}
<rect
x={-20}
width={40}
height={height}
fill="#F00"
fillOpacity={0}
onMouseEnter={showTooltip}
onMouseMove={showTooltip}
onMouseLeave={hideTooltip}
/>
)}
<rect
x={-20}
width={40}
height={height}
fill="#F00"
fillOpacity={0}
onMouseEnter={showTooltip}
onMouseMove={showTooltip}
onMouseLeave={hideTooltip}
/>
</g>
)
</g>
)
}

LineSlicesItem.propTypes = {
slice: PropTypes.object.isRequired,
Expand Down
13 changes: 3 additions & 10 deletions packages/radar/src/RadarTooltipItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,8 @@ const RadarTooltipItem = memo(
}, [startAngle, endAngle, radius, arcGenerator])

return (
<g>
<line
x1={0}
y1={0}
x2={tipX}
y2={tipY}
stroke="#000"
strokeOpacity={isHover ? 0.35 : 0}
/>
<>
{isHover && <line x1={0} y1={0} x2={tipX} y2={tipY} style={theme.crosshair.line} />}
<path
d={path}
fill="#F00"
Expand All @@ -89,7 +82,7 @@ const RadarTooltipItem = memo(
onMouseMove={showItemTooltip}
onMouseLeave={hideItemTooltip}
/>
</g>
</>
)
}
)
Expand Down

0 comments on commit f03848f

Please sign in to comment.