Browse Source

Merge pull request #356 from meriadec/update-chart

Update chart
master
Gaëtan Renaudeau 7 years ago
committed by GitHub
parent
commit
688455b200
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      src/components/BalanceSummary/index.js
  2. 22
      src/components/CalculateBalance.js
  3. 4
      src/components/CounterValue/index.js
  4. 4
      src/components/DashboardPage/AccountCard.js
  5. 20
      src/components/DevTools.js
  6. 6
      src/components/TopBar/ItemContainer.js
  7. 4
      src/components/TopBar/index.js
  8. 96
      src/components/base/Chart/Tooltip.js
  9. 35
      src/components/base/Chart/handleMouseEvents.js
  10. 2
      src/components/base/Chart/helpers.js
  11. 15
      src/components/base/Chart/index.js
  12. 12
      src/components/base/Chart/refreshDraw.js
  13. 23
      src/components/base/Chart/refreshNodes.js
  14. 44
      src/components/base/Chart/stories.js
  15. 1
      src/components/base/Chart/types.js

34
src/components/BalanceSummary/index.js

@ -35,7 +35,8 @@ const BalanceSummary = ({
renderHeader, renderHeader,
selectedTime, selectedTime,
}: Props) => { }: Props) => {
const unit = getFiatCurrencyByTicker(counterValue).units[0] const currency = getFiatCurrencyByTicker(counterValue)
const account = accounts.length === 1 ? accounts[0] : undefined
return ( return (
<Card p={0} py={6}> <Card p={0} py={6}>
<CalculateBalance <CalculateBalance
@ -61,21 +62,30 @@ const BalanceSummary = ({
<Box ff="Open Sans" fontSize={4} color="graphite" pt={6}> <Box ff="Open Sans" fontSize={4} color="graphite" pt={6}>
<Chart <Chart
id={chartId} id={chartId}
account={account}
color={chartColor} color={chartColor}
data={balanceHistory} data={balanceHistory}
height={250} height={250}
unit={unit} currency={currency}
tickXScale={selectedTime} tickXScale={selectedTime}
renderTooltip={d => renderTooltip={
isAvailable ? ( isAvailable && !account
<FormattedVal ? d => (
alwaysShowSign={false} <Fragment>
color="white" <FormattedVal
showCode alwaysShowSign={false}
fiat={counterValue} fontSize={5}
val={d.value} color="dark"
/> showCode
) : null fiat={counterValue}
val={d.value}
/>
<Box ff="Open Sans|Regular" color="grey" fontSize={3} mt={2}>
{d.date.toISOString().substr(0, 10)}
</Box>
</Fragment>
)
: undefined
} }
/> />
</Box> </Box>

22
src/components/CalculateBalance.js

@ -4,7 +4,7 @@
import { PureComponent } from 'react' import { PureComponent } from 'react'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import type { Account, BalanceHistory } from '@ledgerhq/live-common/lib/types' import type { Account } from '@ledgerhq/live-common/lib/types'
import { getBalanceHistorySum } from '@ledgerhq/live-common/lib/helpers/account' import { getBalanceHistorySum } from '@ledgerhq/live-common/lib/helpers/account'
import CounterValues from 'helpers/countervalues' import CounterValues from 'helpers/countervalues'
import { exchangeSettingsForAccountSelector, counterValueCurrencySelector } from 'reducers/settings' import { exchangeSettingsForAccountSelector, counterValueCurrencySelector } from 'reducers/settings'
@ -16,8 +16,14 @@ type OwnProps = {
children: Props => *, children: Props => *,
} }
type Item = {
date: Date,
value: number,
originalValue: number,
}
type Props = OwnProps & { type Props = OwnProps & {
balanceHistory: BalanceHistory, balanceHistory: Item[],
balanceStart: number, balanceStart: number,
balanceEnd: number, balanceEnd: number,
isAvailable: boolean, isAvailable: boolean,
@ -26,10 +32,18 @@ type Props = OwnProps & {
const mapStateToProps = (state: State, props: OwnProps) => { const mapStateToProps = (state: State, props: OwnProps) => {
const counterValueCurrency = counterValueCurrencySelector(state) const counterValueCurrency = counterValueCurrencySelector(state)
let isAvailable = true let isAvailable = true
// create array of original values, used to reconciliate
// with counter values after calculation
const originalValues = []
const balanceHistory = getBalanceHistorySum( const balanceHistory = getBalanceHistorySum(
props.accounts, props.accounts,
props.daysCount, props.daysCount,
(account, value, date) => { (account, value, date) => {
// keep track of original value
originalValues.push(value)
const cv = CounterValues.calculateSelector(state, { const cv = CounterValues.calculateSelector(state, {
value, value,
date, date,
@ -43,7 +57,11 @@ const mapStateToProps = (state: State, props: OwnProps) => {
} }
return cv return cv
}, },
).map((item, i) =>
// reconciliate balance history with original values
({ ...item, originalValue: originalValues[i] || 0 }),
) )
return { return {
isAvailable, isAvailable,
balanceHistory, balanceHistory,

4
src/components/CounterValue/index.js

@ -49,7 +49,9 @@ const mapStateToProps = (state: State, props: OwnProps) => {
class CounterValue extends PureComponent<Props> { class CounterValue extends PureComponent<Props> {
render() { render() {
const { value, counterValueCurrency, date, ...props } = this.props const { value, counterValueCurrency, date, ...props } = this.props
if (!value && value !== 0) return null if (!value && value !== 0) {
return null
}
return ( return (
<FormattedVal <FormattedVal
val={value} val={value}

4
src/components/DashboardPage/AccountCard.js

@ -86,9 +86,9 @@ const AccountCard = ({
color={account.currency.color} color={account.currency.color}
height={52} height={52}
hideAxis hideAxis
interactive={false} isInteractive={false}
id={`account-chart-${account.id}`} id={`account-chart-${account.id}`}
unit={account.unit} account={account}
/> />
</Box> </Box>
)} )}

20
src/components/DevTools.js

@ -254,26 +254,8 @@ class DevTools extends PureComponent<any, State> {
color="#8884d8" color="#8884d8"
height={50} height={50}
hideAxis hideAxis
interactive={false} isInteractive={false}
/> />
{/* <WrapperChart
height={50}
render={({ height, width }) => (
<VictoryArea
data={cpuUsage[k]}
y="value"
style={{
data: {
stroke: '#8884d8',
fill: '#8884d8',
},
}}
height={height}
width={width}
padding={{ top: 10, right: 0, left: 0, bottom: 0 }}
/>
)}
/> */}
</Box> </Box>
</Box> </Box>
))} ))}

6
src/components/TopBar/ItemContainer.js

@ -8,13 +8,13 @@ export default styled(Box).attrs({
px: 2, px: 2,
ml: 0, ml: 0,
justifyContent: 'center', justifyContent: 'center',
cursor: p => (p.interactive ? 'pointer' : 'default'), cursor: p => (p.isInteractive ? 'pointer' : 'default'),
})` })`
opacity: 0.7; opacity: 0.7;
&:hover { &:hover {
opacity: ${p => (p.interactive ? 0.85 : 0.7)}; opacity: ${p => (p.isInteractive ? 0.85 : 0.7)};
} }
&:active { &:active {
opacity: ${p => (p.interactive ? 1 : 0.7)}; opacity: ${p => (p.isInteractive ? 1 : 0.7)};
} }
` `

4
src/components/TopBar/index.js

@ -93,7 +93,7 @@ class TopBar extends PureComponent<Props> {
<Box justifyContent="center"> <Box justifyContent="center">
<Bar /> <Bar />
</Box> </Box>
<ItemContainer interactive onClick={this.navigateToSettings}> <ItemContainer isInteractive onClick={this.navigateToSettings}>
<IconSettings size={16} /> <IconSettings size={16} />
</ItemContainer> </ItemContainer>
{hasPassword && ( // FIXME this should be a dedicated component. therefore this component don't need to connect() {hasPassword && ( // FIXME this should be a dedicated component. therefore this component don't need to connect()
@ -101,7 +101,7 @@ class TopBar extends PureComponent<Props> {
<Box justifyContent="center"> <Box justifyContent="center">
<Bar /> <Bar />
</Box> </Box>
<ItemContainer interactive justifyContent="center" onClick={this.handleLock}> <ItemContainer isInteractive justifyContent="center" onClick={this.handleLock}>
<IconLock size={16} /> <IconLock size={16} />
</ItemContainer> </ItemContainer>
</Fragment> </Fragment>

96
src/components/base/Chart/Tooltip.js

@ -1,47 +1,35 @@
// @flow // @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 FormattedVal from 'components/base/FormattedVal' import FormattedVal from 'components/base/FormattedVal'
import Box from 'components/base/Box'
import type { Item } from './types' import type { Item } from './types'
/** const Container = styled(Box).attrs({
* we use inline style for more perfs, as tooltip may re-render numerous times px: 4,
*/ py: 3,
align: 'center',
const Arrow = () => ( })`
<svg background: white;
style={{ border: 1px solid #d8d8d8;
display: 'block', border-radius: 4px;
position: 'absolute', width: 150px;
left: '50%', box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.03);
bottom: 0, `
marginBottom: -10,
transform: 'translate(-50%, 0)',
}}
viewBox="0 0 14 6.2"
width={16}
height={16}
>
<path fill={themeColors.dark} d="m14 0-5.5 5.6c-0.8 0.8-2 0.8-2.8 0l-5.7-5.6" />
</svg>
)
const Tooltip = ({ const Tooltip = ({
d, item,
renderTooltip, renderTooltip,
fiat, account,
unit,
}: { }: {
d: Item, item: Item,
renderTooltip?: Function, renderTooltip?: Function,
fiat?: string, account?: Account,
unit?: Unit,
}) => ( }) => (
<div style={{ position: 'relative' }}> <div style={{ position: 'relative' }}>
<div <div
@ -51,32 +39,40 @@ const Tooltip = ({
left: 0, left: 0,
transform: `translate3d(-50%, 0, 0)`, transform: `translate3d(-50%, 0, 0)`,
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
marginBottom: 5, marginBottom: -5,
}} }}
> >
<TooltipContainer style={{ textAlign: 'center' }}> <Container style={{ textAlign: 'center' }}>
{renderTooltip ? ( {renderTooltip ? (
renderTooltip(d) renderTooltip(item)
) : ( ) : (
<FormattedVal <Fragment>
alwaysShowSign={false} <FormattedVal
color="white" color="dark"
showCode fontSize={5}
fiat={fiat} alwaysShowSign={false}
unit={unit} showCode
val={d.value} fiat="USD"
/> val={item.value}
/>
{account && (
<FormattedVal
color="grey"
fontSize={3}
alwaysShowSign={false}
showCode
unit={account.unit}
val={item.originalValue}
/>
)}
<Box ff="Open Sans|Regular" color="grey" fontSize={3} mt={2}>
{item.date.toISOString().substr(0, 10)}
</Box>
</Fragment>
)} )}
</TooltipContainer> </Container>
<Arrow />
</div> </div>
</div> </div>
) )
Tooltip.defaultProps = {
renderTooltip: undefined,
fiat: undefined,
unit: undefined,
}
export default Tooltip export default Tooltip

35
src/components/base/Chart/handleMouseEvents.js

@ -29,7 +29,7 @@ export default function handleMouseEvents({
renderTooltip?: Function, renderTooltip?: Function,
}) { }) {
const { MARGINS, HEIGHT, WIDTH, NODES, DATA, x, y } = ctx const { MARGINS, HEIGHT, WIDTH, NODES, DATA, x, y } = ctx
const { hideAxis, unit } = props const { account } = props
const bisectDate = d3.bisector(d => d.parsedDate).left const bisectDate = d3.bisector(d => d.parsedDate).left
@ -65,21 +65,15 @@ export default function handleMouseEvents({
NODES.tooltip NODES.tooltip
.style('transition', '100ms cubic-bezier(.61,1,.53,1) opacity') .style('transition', '100ms cubic-bezier(.61,1,.53,1) opacity')
.style('opacity', 1) .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) NODES.focus.style('opacity', 1)
if (!hideAxis) { NODES.xBar.style('opacity', 1)
NODES.xBar.style('opacity', 1)
NODES.yBar.style('opacity', 1)
}
} }
function mouseOut() { function mouseOut() {
NODES.tooltip.style('opacity', 0).style('transition', '100ms linear opacity') NODES.tooltip.style('opacity', 0).style('transition', '100ms linear opacity')
NODES.focus.style('opacity', 0) NODES.focus.style('opacity', 0)
if (!hideAxis) { NODES.xBar.style('opacity', 0)
NODES.xBar.style('opacity', 0)
NODES.yBar.style('opacity', 0)
}
} }
function mouseMove() { function mouseMove() {
@ -97,24 +91,17 @@ export default function handleMouseEvents({
renderToString( renderToString(
<Provider store={createStore({})}> <Provider store={createStore({})}>
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
<Tooltip unit={unit} renderTooltip={renderTooltip} d={d.ref} /> <Tooltip account={account} renderTooltip={renderTooltip} item={d.ref} />
</ThemeProvider> </ThemeProvider>
</Provider>, </Provider>,
), ),
) )
.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)`)
if (!hideAxis) { NODES.xBar
NODES.xBar .attr('x1', x(d.parsedDate))
.attr('x1', x(d.parsedDate)) .attr('x2', x(d.parsedDate))
.attr('x2', x(d.parsedDate)) .attr('y1', -30) // ensure that xbar is covered
.attr('y1', HEIGHT) .attr('y2', 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))
}
} }
return node return node

2
src/components/base/Chart/helpers.js

@ -16,7 +16,7 @@ export function generateColors(color) {
focus: color, focus: color,
gradientStart: cColor.fade(0.7), gradientStart: cColor.fade(0.7),
gradientStop: cColor.fade(1), gradientStop: cColor.fade(1),
focusBar: cColor.fade(0.5), focusBar: '#d8d8d8',
} }
} }

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

@ -18,7 +18,7 @@
* *
* <Chart * <Chart
* data={data} * data={data}
* interactive // Handle mouse events, display tooltip etc. * isInteractive // Handle mouse events, display tooltip etc.
* color="#5f8ced" // Main color for line, gradient, etc. * color="#5f8ced" // Main color for line, gradient, etc.
* height={300} // Fix height. Width is responsive to container. * height={300} // Fix height. Width is responsive to container.
* /> * />
@ -37,7 +37,7 @@ import React, { PureComponent } from 'react'
import * as d3 from 'd3' import * as d3 from 'd3'
import noop from 'lodash/noop' 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 refreshNodes from './refreshNodes'
import refreshDraw from './refreshDraw' import refreshDraw from './refreshDraw'
@ -48,7 +48,7 @@ import type { Data } from './types'
export type Props = { export type Props = {
data: Data, // eslint-disable-line react/no-unused-prop-types 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 id?: string, // eslint-disable-line react/no-unused-prop-types
height?: number, height?: number,
@ -56,7 +56,7 @@ export type Props = {
color?: string, // eslint-disable-line react/no-unused-prop-types color?: string, // eslint-disable-line react/no-unused-prop-types
hideAxis?: boolean, // eslint-disable-line react/no-unused-prop-types hideAxis?: boolean, // eslint-disable-line react/no-unused-prop-types
dateFormat?: string, // eslint-disable-line react/no-unused-prop-types dateFormat?: string, // eslint-disable-line react/no-unused-prop-types
interactive?: boolean, // eslint-disable-line react/no-unused-prop-types isInteractive?: boolean, // eslint-disable-line react/no-unused-prop-types
renderTooltip?: Function, // eslint-disable-line react/no-unused-prop-types renderTooltip?: Function, // eslint-disable-line react/no-unused-prop-types
} }
@ -67,9 +67,8 @@ class Chart extends PureComponent<Props> {
height: 400, height: 400,
hideAxis: false, hideAxis: false,
id: 'chart', id: 'chart',
interactive: true, isInteractive: true,
tickXScale: 'month', tickXScale: 'month',
unit: undefined,
} }
componentDidMount() { componentDidMount() {
@ -113,7 +112,7 @@ class Chart extends PureComponent<Props> {
this.refreshChart = prevProps => { this.refreshChart = prevProps => {
const { _node: node, props } = this const { _node: node, props } = this
const { data: raw, color, height, hideAxis, interactive, renderTooltip } = props const { data: raw, color, height, hideAxis, isInteractive, renderTooltip } = props
ctx.DATA = enrichData(raw) ctx.DATA = enrichData(raw)
@ -157,7 +156,7 @@ class Chart extends PureComponent<Props> {
// Mouse handler // Mouse handler
mouseHandler && mouseHandler.remove() // eslint-disable-line no-unused-expressions mouseHandler && mouseHandler.remove() // eslint-disable-line no-unused-expressions
if (interactive) { if (isInteractive) {
mouseHandler = handleMouseEvents({ mouseHandler = handleMouseEvents({
ctx, ctx,
props, props,

12
src/components/base/Chart/refreshDraw.js

@ -31,11 +31,11 @@ function getRenderTickX(selectedTime) {
export default function refreshDraw({ ctx, props }: { ctx: CTX, props: Props }) { export default function refreshDraw({ ctx, props }: { ctx: CTX, props: Props }) {
const { NODES, WIDTH, HEIGHT, MARGINS, COLORS, INVALIDATED, DATA, x, y } = ctx const { NODES, WIDTH, HEIGHT, MARGINS, COLORS, INVALIDATED, DATA, x, y } = ctx
const { hideAxis, interactive, tickXScale, unit } = props const { hideAxis, isInteractive, tickXScale, account } = props
const nbTicksX = getTickXCount(tickXScale) const nbTicksX = getTickXCount(tickXScale)
const renderTickX = getRenderTickX(tickXScale) const renderTickX = getRenderTickX(tickXScale)
const renderTickY = t => (unit ? formatShort(unit, t) : t) const renderTickY = t => (account ? formatShort(account.unit, t) : t)
const area = d3 const area = d3
.area() .area()
@ -62,12 +62,11 @@ export default function refreshDraw({ ctx, props }: { ctx: CTX, props: Props })
} }
if (INVALIDATED.color) { if (INVALIDATED.color) {
if (interactive) { if (isInteractive) {
// Update focus bar colors // Update focus bar colors
NODES.xBar.attr('stroke', COLORS.focusBar) NODES.xBar.attr('stroke', COLORS.focusBar)
NODES.yBar.attr('stroke', COLORS.focusBar)
// Update dot color // Update dot color
NODES.focus.attr('fill', COLORS.focus) NODES.focus.attr('stroke', COLORS.focus)
} }
// Update gradient color // Update gradient color
NODES.gradientStart.attr('stop-color', COLORS.gradientStart) NODES.gradientStart.attr('stop-color', COLORS.gradientStart)
@ -78,11 +77,10 @@ export default function refreshDraw({ ctx, props }: { ctx: CTX, props: Props })
} }
// Hide interactive things // Hide interactive things
if (interactive) { if (isInteractive) {
NODES.focus.style('opacity', 0) NODES.focus.style('opacity', 0)
NODES.tooltip.style('opacity', 0) NODES.tooltip.style('opacity', 0)
NODES.xBar.style('opacity', 0) NODES.xBar.style('opacity', 0)
NODES.yBar.style('opacity', 0)
} }
// Draw axis // Draw axis

23
src/components/base/Chart/refreshNodes.js

@ -10,7 +10,7 @@ const debug = d('Chart')
export default function refreshNodes({ ctx, node, props }: { ctx: CTX, node: any, props: Props }) { export default function refreshNodes({ ctx, node, props }: { ctx: CTX, node: any, props: Props }) {
const { NODES, COLORS } = ctx const { NODES, COLORS } = ctx
const { hideAxis, interactive, id } = props const { hideAxis, isInteractive, id } = props
// Container // Container
@ -26,20 +26,11 @@ export default function refreshNodes({ ctx, node, props }: { ctx: CTX, node: any
// Focus bars // Focus bars
ensure({ onlyIf: interactive, NODES, key: 'xBar' }, () => ensure({ onlyIf: isInteractive, NODES, key: 'xBar' }, () =>
NODES.wrapper NODES.wrapper
.append('line') .append('line')
.attr('stroke', COLORS.focusBar) .attr('stroke', COLORS.focusBar)
.attr('stroke-width', '1px') .attr('stroke-width', '1px'),
.attr('stroke-dasharray', '3, 2'),
)
ensure({ onlyIf: interactive, NODES, key: 'yBar' }, () =>
NODES.wrapper
.append('line')
.attr('stroke', COLORS.focusBar)
.attr('stroke-width', '1px')
.attr('stroke-dasharray', '3, 2'),
) )
// Gradient // Gradient
@ -84,7 +75,7 @@ export default function refreshNodes({ ctx, node, props }: { ctx: CTX, node: any
// Tooltip & focus point // Tooltip & focus point
ensure({ onlyIf: interactive, NODES, key: 'tooltip' }, () => ensure({ onlyIf: isInteractive, NODES, key: 'tooltip' }, () =>
d3 d3
.select(node) .select(node)
.append('div') .append('div')
@ -94,11 +85,13 @@ export default function refreshNodes({ ctx, node, props }: { ctx: CTX, node: any
.style('pointer-events', 'none'), .style('pointer-events', 'none'),
) )
ensure({ onlyIf: interactive, NODES, key: 'focus' }, () => ensure({ onlyIf: isInteractive, NODES, key: 'focus' }, () =>
NODES.wrapper NODES.wrapper
.append('g') .append('g')
.append('circle') .append('circle')
.attr('fill', COLORS.focus) .attr('fill', 'white')
.attr('stroke', COLORS.focus)
.attr('stroke-width', 2)
.attr('r', 4), .attr('r', 4),
) )

44
src/components/base/Chart/stories.js

@ -9,11 +9,17 @@ import { boolean, number } from '@storybook/addon-knobs'
import { color } from '@storybook/addon-knobs/react' import { color } from '@storybook/addon-knobs/react'
import Chart from 'components/base/Chart' import Chart from 'components/base/Chart'
import Box from 'components/base/Box'
const stories = storiesOf('Components/base', module) const stories = storiesOf('Components/base', module)
const data = generateRandomData(365) const data = generateRandomData(365)
const unit = getCryptoCurrencyById('bitcoin').units[0] const currency = getCryptoCurrencyById('bitcoin')
// $FlowFixMe
const fakeAccount = {
currency,
}
type State = { type State = {
start: number, start: number,
@ -32,23 +38,31 @@ class Wrapper extends Component<any, State> {
const { start, stop } = this.state const { start, stop } = this.state
return ( return (
<Fragment> <Fragment>
<input type="range" value={start} onChange={this.handleChange('start')} min={0} max={365} /> <Box mb={8} horizontal>
<input <input
type="range" type="range"
value={stop} value={start}
style={{ marginLeft: 10 }} onChange={this.handleChange('start')}
onChange={this.handleChange('stop')} min={0}
min={0} max={365}
max={365} />
/> <input
type="range"
value={stop}
style={{ marginLeft: 10 }}
onChange={this.handleChange('stop')}
min={0}
max={365}
/>
</Box>
<Chart <Chart
interactive={boolean('interactive', true)} isInteractive={boolean('isInteractive', true)}
hideAxis={boolean('hideAxis', false)} hideAxis={boolean('hideAxis', true)}
color={color('color', '#5f8ced')} color={color('color', '#5f8ced')}
data={data.slice(start, stop)} data={data.slice(start, stop)}
height={number('height', 300)} height={number('height', 300)}
unit={unit} account={fakeAccount}
/> />
</Fragment> </Fragment>
) )
@ -63,9 +77,11 @@ function generateRandomData(n) {
const data = [] const data = []
const chance = new Chance() const chance = new Chance()
while (!day.isSame(today)) { while (!day.isSame(today)) {
const value = chance.integer({ min: 0.5e8, max: 1e8 })
data.push({ data.push({
date: day.toDate(), date: day.toDate(),
value: chance.integer({ min: 0.5e8, max: 1e8 }), value,
originalValue: value,
}) })
day.add(1, 'day') day.add(1, 'day')
} }

1
src/components/base/Chart/types.js

@ -3,6 +3,7 @@
export type Item = { export type Item = {
date: Date, date: Date,
value: number, value: number,
originalValue: number,
} }
type EnrichedItem = { type EnrichedItem = {

Loading…
Cancel
Save