From 69e1dac590d2de9dcd4c7244fec442edd501c1ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Tue, 6 Mar 2018 18:49:24 +0100 Subject: [PATCH] Fix Tooltip --- src/components/BalanceSummary/index.js | 18 ++++++++++++------ src/components/base/Chart/index.js | 25 ++++++++++++++----------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/components/BalanceSummary/index.js b/src/components/BalanceSummary/index.js index b979b497..236d5084 100644 --- a/src/components/BalanceSummary/index.js +++ b/src/components/BalanceSummary/index.js @@ -3,7 +3,7 @@ import React, { Fragment } from 'react' import moment from 'moment' -import { formatShort, formatCurrencyUnit, getFiatUnit } from '@ledgerhq/currencies' +import { formatShort, getFiatUnit } from '@ledgerhq/currencies' import type { Accounts } from 'types/common' @@ -12,6 +12,7 @@ import { space } from 'styles/theme' import { AreaChart } from 'components/base/Chart' import Box, { Card } from 'components/base/Box' import CalculateBalance from 'components/CalculateBalance' +import FormattedVal from 'components/base/FormattedVal' function getTickCountX(selectedTime) { switch (selectedTime) { @@ -88,11 +89,16 @@ const BalanceSummary = ({ right: space[6], }} strokeWidth={2} - renderLabels={d => - formatCurrencyUnit(unit, d.y * 100, { - showCode: true, - }) - } + renderLabels={d => d.y} + renderTooltip={d => ( + + )} renderTickX={renderTickX(selectedTime)} renderTickY={t => formatShort(unit, t)} tickCountX={getTickCountX(selectedTime)} diff --git a/src/components/base/Chart/index.js b/src/components/base/Chart/index.js index 3607af7c..c5a5f3ae 100644 --- a/src/components/base/Chart/index.js +++ b/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 Box from 'components/base/Box' +import Text from 'components/base/Text' import { TooltipContainer } from 'components/base/Tooltip' const ANIMATION_DURATION = 600 @@ -121,7 +122,7 @@ class CustomTooltip extends Component { } render() { - const { x, y, active, text, datum } = this.props + const { x, y, active, text, datum, renderer } = this.props if (!active) { return null @@ -133,7 +134,7 @@ class CustomTooltip extends Component { mt={-space[1]} style={{ position: 'absolute', top: y, left: x, transform: `translate3d(-50%, 0, 0)` }} > - {text(datum)} + {renderer(text(datum))} ) @@ -151,13 +152,6 @@ type GenericChart = { color: string, data: Array, } -type Chart = GenericChart & { - renderLabels: Function, - renderTickX: Function, - renderTickY: Function, - tickCountX: number, - tickCountY: number, -} export const SimpleAreaChart = ({ linearGradient, @@ -208,7 +202,14 @@ SimpleAreaChart.defaultProps = { ...DEFAULT_PROPS, } -const areaChartTooltip = +type Chart = GenericChart & { + renderLabels: Function, + renderTickX: Function, + renderTickY: Function, + renderTooltip: Function, + tickCountX: number, + tickCountY: number, +} const AreaChartContainer = @@ -224,6 +225,8 @@ export class AreaChart extends PureComponent { ...DEFAULT_PROPS, } + _tooltip = + render() { const { color, @@ -302,7 +305,7 @@ export class AreaChart extends PureComponent { data={data} x="name" y="value" - labelComponent={areaChartTooltip} + labelComponent={this._tooltip} labels={renderLabels} style={{ data: {