Skip to content

Commit

Permalink
fix(axes): treat renderTick as a React component
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Jul 12, 2019
1 parent 871c7ef commit 4bd566c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 36 deletions.
4 changes: 2 additions & 2 deletions packages/axes/src/components/Axis.js
Expand Up @@ -113,7 +113,7 @@ const Axis = ({
return (
<g transform={`translate(${x},${y})`}>
{ticks.map((tick, tickIndex) =>
renderTick({
React.createElement(renderTick, {
tickIndex,
format: formatValue,
rotate: tickRotation,
Expand Down Expand Up @@ -156,7 +156,7 @@ const Axis = ({
{interpolatedStyles => (
<Fragment>
{interpolatedStyles.map(({ style, data: tick }, tickIndex) =>
renderTick({
React.createElement(renderTick, {
tickIndex,
format: formatValue,
textBaseline,
Expand Down
60 changes: 26 additions & 34 deletions packages/bar/stories/bar.stories.js
Expand Up @@ -4,6 +4,7 @@ import { action } from '@storybook/addon-actions'
import { generateCountriesData, sets } from '@nivo/generators'
import range from 'lodash/range'
import random from 'lodash/random'
import { useTheme } from '@nivo/core'
import { Bar } from '../src'

const keys = ['hot dogs', 'burgers', 'sandwich', 'kebab', 'fries', 'donut']
Expand Down Expand Up @@ -201,47 +202,38 @@ stories.add('custom tooltip', () => (
/>
))

const CustomTick = tick => {
const theme = useTheme()

return (
<g transform={`translate(${tick.x},${tick.y + 22})`}>
<rect x={-14} y={-6} rx={3} ry={3} width={28} height={24} fill="rgba(0, 0, 0, .05)" />
<rect x={-12} y={-12} rx={2} ry={2} width={24} height={24} fill="rgb(232, 193, 160)" />
<line stroke="rgb(232, 193, 160)" strokeWidth={1.5} y1={-22} y2={-12} />
<text
textAnchor="middle"
dominantBaseline="middle"
style={{
...theme.axis.ticks.text,
fill: '#333',
fontSize: 10,
}}
>
{tick.value}
</text>
</g>
)
}

stories.add(
'custom axis ticks',
() => (
<Bar
{...commonProps}
animate={false}
axisLeft={null}
axisBottom={{
renderTick: tick => (
<g key={tick.key} transform={`translate(${tick.x},${tick.y + 22})`}>
<rect
x={-14}
y={-6}
rx={3}
ry={3}
width={28}
height={24}
fill="rgba(0, 0, 0, .05)"
/>
<rect
x={-12}
y={-12}
rx={2}
ry={2}
width={24}
height={24}
fill="rgb(232, 193, 160)"
/>
<line stroke="rgb(232, 193, 160)" strokeWidth={1.5} y1={-22} y2={-12} />
<text
textAnchor="middle"
dominantBaseline="middle"
style={{
...tick.theme.axis.ticks.text,
fill: '#333',
fontSize: 10,
}}
>
{tick.value}
</text>
</g>
),
renderTick: CustomTick,
}}
/>
),
Expand Down

0 comments on commit 4bd566c

Please sign in to comment.