Skip to content

Commit

Permalink
feat(radar): pass key to tooltip format function (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
tloszabno authored and plouc committed Jun 27, 2019
1 parent f856200 commit cca8a9e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/radar/src/RadarTooltipItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const RadarTooltipItem = memo(
keys.map(key => [
<Chip key={key} color={colorByKey[key]} />,
key,
format ? format(datum[key]) : datum[key],
format ? format(datum[key], key) : datum[key],
]),
'2'
).reverse()}
Expand Down
15 changes: 15 additions & 0 deletions packages/radar/stories/radar.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ stories.add('with formatted values', () => (
/>
))

stories.add('with formatted values per key', () => (
<Radar
{...commonProperties}
tooltipFormat={(value, key) => {
if (key === 'syrah') {
return value + ' BitCoins'
} else {
return `${Number(value).toLocaleString('ru-RU', {
minimumFractionDigits: 2,
})} ₽`
}
}}
/>
))

const LabelComponent = ({ id, anchor }) => (
<g transform={`translate(${anchor === 'end' ? -60 : anchor === 'middle' ? -30 : 0}, -20)`}>
<text>{id}</text>
Expand Down

0 comments on commit cca8a9e

Please sign in to comment.