Browse Source

Fix Tooltip

master
Loëck Vézien 7 years ago
parent
commit
69e1dac590
No known key found for this signature in database GPG Key ID: CBCDCE384E853AC4
  1. 18
      src/components/BalanceSummary/index.js
  2. 25
      src/components/base/Chart/index.js

18
src/components/BalanceSummary/index.js

@ -3,7 +3,7 @@
import React, { Fragment } from 'react' import React, { Fragment } from 'react'
import moment from 'moment' import moment from 'moment'
import { formatShort, formatCurrencyUnit, getFiatUnit } from '@ledgerhq/currencies' import { formatShort, getFiatUnit } from '@ledgerhq/currencies'
import type { Accounts } from 'types/common' import type { Accounts } from 'types/common'
@ -12,6 +12,7 @@ import { space } from 'styles/theme'
import { AreaChart } from 'components/base/Chart' import { AreaChart } from 'components/base/Chart'
import Box, { Card } from 'components/base/Box' import Box, { Card } from 'components/base/Box'
import CalculateBalance from 'components/CalculateBalance' import CalculateBalance from 'components/CalculateBalance'
import FormattedVal from 'components/base/FormattedVal'
function getTickCountX(selectedTime) { function getTickCountX(selectedTime) {
switch (selectedTime) { switch (selectedTime) {
@ -88,11 +89,16 @@ const BalanceSummary = ({
right: space[6], right: space[6],
}} }}
strokeWidth={2} strokeWidth={2}
renderLabels={d => renderLabels={d => d.y}
formatCurrencyUnit(unit, d.y * 100, { renderTooltip={d => (
showCode: true, <FormattedVal
}) alwaysShowSign={false}
} color="white"
showCode
fiat={counterValue}
val={d}
/>
)}
renderTickX={renderTickX(selectedTime)} renderTickX={renderTickX(selectedTime)}
renderTickY={t => formatShort(unit, t)} renderTickY={t => formatShort(unit, t)}
tickCountX={getTickCountX(selectedTime)} tickCountX={getTickCountX(selectedTime)}

25
src/components/base/Chart/index.js

@ -13,6 +13,7 @@ import VictoryVoronoiContainer from 'victory-chart/lib/components/containers/vic
import { space, colors, fontSizes } from 'styles/theme' import { space, colors, fontSizes } from 'styles/theme'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import Text from 'components/base/Text'
import { TooltipContainer } from 'components/base/Tooltip' import { TooltipContainer } from 'components/base/Tooltip'
const ANIMATION_DURATION = 600 const ANIMATION_DURATION = 600
@ -121,7 +122,7 @@ class CustomTooltip extends Component<Object> {
} }
render() { render() {
const { x, y, active, text, datum } = this.props const { x, y, active, text, datum, renderer } = this.props
if (!active) { if (!active) {
return null return null
@ -133,7 +134,7 @@ class CustomTooltip extends Component<Object> {
mt={-space[1]} mt={-space[1]}
style={{ position: 'absolute', top: y, left: x, transform: `translate3d(-50%, 0, 0)` }} style={{ position: 'absolute', top: y, left: x, transform: `translate3d(-50%, 0, 0)` }}
> >
{text(datum)} <Text style={{ lineHeight: 1 }}>{renderer(text(datum))}</Text>
</TooltipContainer> </TooltipContainer>
</foreignObject> </foreignObject>
) )
@ -151,13 +152,6 @@ type GenericChart = {
color: string, color: string,
data: Array<Object>, data: Array<Object>,
} }
type Chart = GenericChart & {
renderLabels: Function,
renderTickX: Function,
renderTickY: Function,
tickCountX: number,
tickCountY: number,
}
export const SimpleAreaChart = ({ export const SimpleAreaChart = ({
linearGradient, linearGradient,
@ -208,7 +202,14 @@ SimpleAreaChart.defaultProps = {
...DEFAULT_PROPS, ...DEFAULT_PROPS,
} }
const areaChartTooltip = <CustomTooltip /> type Chart = GenericChart & {
renderLabels: Function,
renderTickX: Function,
renderTickY: Function,
renderTooltip: Function,
tickCountX: number,
tickCountY: number,
}
const AreaChartContainer = <VictoryVoronoiContainer voronoiDimension="x" /> const AreaChartContainer = <VictoryVoronoiContainer voronoiDimension="x" />
@ -224,6 +225,8 @@ export class AreaChart extends PureComponent<Chart> {
...DEFAULT_PROPS, ...DEFAULT_PROPS,
} }
_tooltip = <CustomTooltip renderer={this.props.renderTooltip} />
render() { render() {
const { const {
color, color,
@ -302,7 +305,7 @@ export class AreaChart extends PureComponent<Chart> {
data={data} data={data}
x="name" x="name"
y="value" y="value"
labelComponent={areaChartTooltip} labelComponent={this._tooltip}
labels={renderLabels} labels={renderLabels}
style={{ style={{
data: { data: {

Loading…
Cancel
Save