diff --git a/src/components/BalanceSummary/index.js b/src/components/BalanceSummary/index.js index 17bd93ef..f0edf2b5 100644 --- a/src/components/BalanceSummary/index.js +++ b/src/components/BalanceSummary/index.js @@ -35,7 +35,8 @@ const BalanceSummary = ({ renderHeader, selectedTime, }: Props) => { - const unit = getFiatCurrencyByTicker(counterValue).units[0] + const currency = getFiatCurrencyByTicker(counterValue) + const account = accounts.length === 1 ? accounts[0] : null return ( - isAvailable ? ( - - ) : null + renderTooltip={ + isAvailable && !account + ? d => ( + + + {d.date.toISOString().substr(0, 10)} + + ) + : null } /> diff --git a/src/components/DashboardPage/AccountCard.js b/src/components/DashboardPage/AccountCard.js index 43502b46..62f6d608 100644 --- a/src/components/DashboardPage/AccountCard.js +++ b/src/components/DashboardPage/AccountCard.js @@ -88,7 +88,7 @@ const AccountCard = ({ hideAxis isInteractive={false} id={`account-chart-${account.id}`} - unit={account.unit} + account={account} /> )} diff --git a/src/components/base/Chart/Tooltip.js b/src/components/base/Chart/Tooltip.js index 54cc7900..7ea0e93f 100644 --- a/src/components/base/Chart/Tooltip.js +++ b/src/components/base/Chart/Tooltip.js @@ -1,47 +1,37 @@ // @flow -import React from 'react' +import React, { Fragment } from 'react' +import styled from 'styled-components' -import type { Unit } from '@ledgerhq/live-common/lib/types' +import type { Account } from '@ledgerhq/live-common/lib/types' -import { colors as themeColors } from 'styles/theme' -import { TooltipContainer } from 'components/base/Tooltip' +import CounterValue from 'components/CounterValue' import FormattedVal from 'components/base/FormattedVal' +import Box from 'components/base/Box' import type { Item } from './types' -/** - * we use inline style for more perfs, as tooltip may re-render numerous times - */ - -const Arrow = () => ( - - - -) +const Container = styled(Box).attrs({ + px: 4, + py: 3, + align: 'center', +})` + background: white; + border: 1px solid #d8d8d8; + border-radius: 4px; + width: 150px; + height: 90px; + box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.03); +` const Tooltip = ({ - d, + item, renderTooltip, - fiat, - unit, + account, }: { - d: Item, + item: Item, renderTooltip?: Function, - fiat?: string, - unit?: Unit, + account: Account, }) => (
- + {renderTooltip ? ( - renderTooltip(d) + renderTooltip(item) ) : ( - + + + + + {item.date.toISOString().substr(0, 10)} + + )} - - +
) -Tooltip.defaultProps = { - renderTooltip: undefined, - fiat: undefined, - unit: undefined, -} - export default Tooltip diff --git a/src/components/base/Chart/handleMouseEvents.js b/src/components/base/Chart/handleMouseEvents.js index 9f39e8c3..b30c7742 100644 --- a/src/components/base/Chart/handleMouseEvents.js +++ b/src/components/base/Chart/handleMouseEvents.js @@ -29,7 +29,7 @@ export default function handleMouseEvents({ renderTooltip?: Function, }) { const { MARGINS, HEIGHT, WIDTH, NODES, DATA, x, y } = ctx - const { hideAxis, unit } = props + const { account } = props const bisectDate = d3.bisector(d => d.parsedDate).left @@ -65,21 +65,15 @@ export default function handleMouseEvents({ NODES.tooltip .style('transition', '100ms cubic-bezier(.61,1,.53,1) opacity') .style('opacity', 1) - .style('transform', `translate3d(${MARGINS.left + x(d.parsedDate)}px, ${y(d.value)}px, 0)`) + .style('transform', `translate3d(${MARGINS.left + x(d.parsedDate)}px, 0, 0)`) NODES.focus.style('opacity', 1) - if (!hideAxis) { - NODES.xBar.style('opacity', 1) - NODES.yBar.style('opacity', 1) - } + NODES.xBar.style('opacity', 1) } function mouseOut() { NODES.tooltip.style('opacity', 0).style('transition', '100ms linear opacity') NODES.focus.style('opacity', 0) - if (!hideAxis) { - NODES.xBar.style('opacity', 0) - NODES.yBar.style('opacity', 0) - } + NODES.xBar.style('opacity', 0) } function mouseMove() { @@ -97,24 +91,17 @@ export default function handleMouseEvents({ renderToString( - + , ), ) - .style('transform', `translate3d(${MARGINS.left + x(d.parsedDate)}px, ${y(d.value)}px, 0)`) - if (!hideAxis) { - NODES.xBar - .attr('x1', x(d.parsedDate)) - .attr('x2', x(d.parsedDate)) - .attr('y1', HEIGHT) - .attr('y2', y(d.value)) - NODES.yBar - .attr('x1', 0) - .attr('x2', x(d.parsedDate)) - .attr('y1', y(d.value)) - .attr('y2', y(d.value)) - } + .style('transform', `translate3d(${MARGINS.left + x(d.parsedDate)}px, 0, 0)`) + NODES.xBar + .attr('x1', x(d.parsedDate)) + .attr('x2', x(d.parsedDate)) + .attr('y1', 0) + .attr('y2', HEIGHT) } return node diff --git a/src/components/base/Chart/helpers.js b/src/components/base/Chart/helpers.js index 6f0256c7..3505fba9 100644 --- a/src/components/base/Chart/helpers.js +++ b/src/components/base/Chart/helpers.js @@ -16,7 +16,7 @@ export function generateColors(color) { focus: color, gradientStart: cColor.fade(0.7), gradientStop: cColor.fade(1), - focusBar: cColor.fade(0.5), + focusBar: '#d8d8d8', } } diff --git a/src/components/base/Chart/index.js b/src/components/base/Chart/index.js index 7362b379..21cba1b6 100644 --- a/src/components/base/Chart/index.js +++ b/src/components/base/Chart/index.js @@ -37,7 +37,7 @@ import React, { PureComponent } from 'react' import * as d3 from 'd3' import noop from 'lodash/noop' -import type { Unit } from '@ledgerhq/live-common/lib/types' +import type { Account } from '@ledgerhq/live-common/lib/types' import refreshNodes from './refreshNodes' import refreshDraw from './refreshDraw' @@ -48,7 +48,7 @@ import type { Data } from './types' export type Props = { data: Data, // eslint-disable-line react/no-unused-prop-types - unit?: Unit, // eslint-disable-line react/no-unused-prop-types + account?: Account, // eslint-disable-line react/no-unused-prop-types id?: string, // eslint-disable-line react/no-unused-prop-types height?: number, @@ -69,7 +69,6 @@ class Chart extends PureComponent { id: 'chart', isInteractive: true, tickXScale: 'month', - unit: undefined, } componentDidMount() { diff --git a/src/components/base/Chart/refreshDraw.js b/src/components/base/Chart/refreshDraw.js index 30835ae9..188b5913 100644 --- a/src/components/base/Chart/refreshDraw.js +++ b/src/components/base/Chart/refreshDraw.js @@ -65,9 +65,8 @@ export default function refreshDraw({ ctx, props }: { ctx: CTX, props: Props }) if (isInteractive) { // Update focus bar colors NODES.xBar.attr('stroke', COLORS.focusBar) - NODES.yBar.attr('stroke', COLORS.focusBar) // Update dot color - NODES.focus.attr('fill', COLORS.focus) + NODES.focus.attr('stroke', COLORS.focus) } // Update gradient color NODES.gradientStart.attr('stop-color', COLORS.gradientStart) @@ -82,7 +81,6 @@ export default function refreshDraw({ ctx, props }: { ctx: CTX, props: Props }) NODES.focus.style('opacity', 0) NODES.tooltip.style('opacity', 0) NODES.xBar.style('opacity', 0) - NODES.yBar.style('opacity', 0) } // Draw axis diff --git a/src/components/base/Chart/refreshNodes.js b/src/components/base/Chart/refreshNodes.js index d4280ad4..3fde2f95 100644 --- a/src/components/base/Chart/refreshNodes.js +++ b/src/components/base/Chart/refreshNodes.js @@ -30,16 +30,7 @@ export default function refreshNodes({ ctx, node, props }: { ctx: CTX, node: any NODES.wrapper .append('line') .attr('stroke', COLORS.focusBar) - .attr('stroke-width', '1px') - .attr('stroke-dasharray', '3, 2'), - ) - - ensure({ onlyIf: isInteractive, NODES, key: 'yBar' }, () => - NODES.wrapper - .append('line') - .attr('stroke', COLORS.focusBar) - .attr('stroke-width', '1px') - .attr('stroke-dasharray', '3, 2'), + .attr('stroke-width', '1px'), ) // Gradient @@ -98,7 +89,9 @@ export default function refreshNodes({ ctx, node, props }: { ctx: CTX, node: any NODES.wrapper .append('g') .append('circle') - .attr('fill', COLORS.focus) + .attr('fill', 'white') + .attr('stroke', COLORS.focus) + .attr('stroke-width', 2) .attr('r', 4), ) diff --git a/src/components/base/Chart/stories.js b/src/components/base/Chart/stories.js index 79a90f08..8b26d3d6 100644 --- a/src/components/base/Chart/stories.js +++ b/src/components/base/Chart/stories.js @@ -9,11 +9,15 @@ import { boolean, number } from '@storybook/addon-knobs' import { color } from '@storybook/addon-knobs/react' import Chart from 'components/base/Chart' +import Box from 'components/base/Box' const stories = storiesOf('Components/base', module) const data = generateRandomData(365) -const unit = getCryptoCurrencyById('bitcoin').units[0] +const currency = getCryptoCurrencyById('bitcoin') +const fakeAccount = { + currency, +} type State = { start: number, @@ -32,23 +36,31 @@ class Wrapper extends Component { const { start, stop } = this.state return ( - - + + + + )