import React, { useState, memo } from 'react'; import styled from 'styled-components'; import { FlexibleXYPlot, VerticalBarSeries, HorizontalGridLines, XAxis, YAxis, Hint } from 'react-vis'; import shortId from 'shortid'; import numeral from 'numeral'; import './VerticalBarPlot.css'; const CustomVerticalBarPlot = styled(FlexibleXYPlot)` && { .rv-xy-plot__series--bar rect { transition: all 0.4s ease-in-out; } .rv-xy-plot__series--bar rect:hover { fill: #000 !important; stroke-width: 2px !important; } .rv-hint__content { font-size: 1.5rem; } } `; interface IProps { items: any; } /** * ATTENTION: React-vis don't have typescript support, so we can't define * props with right interface */ export function VerticalBarPlot({ items, ...rest }: IProps) { const [value, changeValue] = useState(false); return ( {items?.map((bar: any) => ( changeValue(v)} onSeriesMouseOut={() => changeValue(false)} key={shortId.generate()} {...bar} /> ))} {value !== false && ( [ { title: v.x, value: numeral(v.y).format('0.000a') } ]} /> )} numeral(v).format('0.0a')} /> ); } export default memo(VerticalBarPlot);