-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Setup preview * 🉑 POC Line chart (#4495) * Add nivo package * Add line chart * Add story for line chart * Fix styling * Chart setup * Style first preview * Correct chart previews * Fix slider mask * Scroll down of form change * Minor improvements on chart
- Loading branch information
Showing
17 changed files
with
971 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/atlas/src/components/_charts/LineChart/LineChart.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Meta, StoryFn } from '@storybook/react' | ||
|
||
import { LineChart, LineChartProps } from '@/components/_charts/LineChart/LineChart' | ||
|
||
export default { | ||
title: 'charts/LineChart', | ||
component: LineChart, | ||
} as Meta<LineChartProps> | ||
|
||
const Template: StoryFn<LineChartProps> = (args) => ( | ||
<div style={{ height: 400 }}> | ||
<LineChart {...args} /> | ||
</div> | ||
) | ||
|
||
export const Default = Template.bind({}) | ||
|
||
const data = [ | ||
{ | ||
'id': 'japan', | ||
'color': 'dodgerblue', | ||
'data': [ | ||
{ | ||
'x': 'Now', | ||
'y': 50, | ||
}, | ||
{ | ||
'x': '2M', | ||
'y': 50, | ||
}, | ||
{ | ||
'x': '3M', | ||
'y': 50, | ||
}, | ||
], | ||
}, | ||
{ | ||
'id': 'korea', | ||
'color': 'dodgerblue', | ||
'data': [ | ||
{ | ||
'x': '3M', | ||
'y': 50, | ||
}, | ||
{ | ||
'x': '3M', | ||
'y': 130, | ||
}, | ||
{ | ||
'x': '6M', | ||
'y': 160, | ||
}, | ||
{ | ||
'x': '9M', | ||
'y': 190, | ||
}, | ||
{ | ||
'x': '12M', | ||
'y': 220, | ||
}, | ||
{ | ||
'x': '15M', | ||
'y': 250, | ||
}, | ||
], | ||
}, | ||
] | ||
|
||
Default.args = { | ||
data, | ||
} |
75 changes: 75 additions & 0 deletions
75
packages/atlas/src/components/_charts/LineChart/LineChart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import styled from '@emotion/styled' | ||
import { LineSvgProps, Point, ResponsiveLine } from '@nivo/line' | ||
import { ReactNode } from 'react' | ||
|
||
import { cVar, sizes } from '@/styles' | ||
|
||
const defaultJoystreamProps: Omit<LineSvgProps, 'data'> = { | ||
isInteractive: true, | ||
useMesh: true, | ||
enablePoints: false, | ||
lineWidth: 2, | ||
margin: { top: 50, right: 110, bottom: 50, left: 60 }, | ||
yScale: { | ||
type: 'linear', | ||
min: 'auto', | ||
max: 'auto', | ||
stacked: false, | ||
reverse: false, | ||
}, | ||
axisTop: null, | ||
axisRight: null, | ||
axisBottom: { | ||
tickSize: 10, | ||
tickPadding: 10, | ||
}, | ||
axisLeft: { | ||
tickSize: 5, | ||
tickPadding: 5, | ||
tickValues: 6, | ||
}, | ||
colors: (d) => d.color, | ||
theme: { | ||
tooltip: { | ||
container: { | ||
background: cVar('colorBackgroundStrong'), | ||
}, | ||
}, | ||
axis: { | ||
ticks: { | ||
line: { | ||
stroke: cVar('colorBackgroundAlpha'), | ||
}, | ||
text: { | ||
fill: cVar('colorTextMuted'), | ||
font: cVar('typographyDesktopT100'), | ||
}, | ||
}, | ||
}, | ||
grid: { | ||
line: { | ||
stroke: cVar('colorBackgroundAlpha'), | ||
}, | ||
}, | ||
}, | ||
} | ||
export type LineChartProps = { | ||
tooltip?: (point: Point) => ReactNode | ||
} & Omit<LineSvgProps, 'tooltip'> | ||
export const LineChart = (props: LineChartProps) => { | ||
return ( | ||
<ResponsiveLine | ||
{...defaultJoystreamProps} | ||
{...props} | ||
tooltip={(point) => ( | ||
<ChartTooltip>{props.tooltip ? props.tooltip(point.point) : String(point.point.data.y)}</ChartTooltip> | ||
)} | ||
/> | ||
) | ||
} | ||
|
||
const ChartTooltip = styled.div` | ||
background-color: ${cVar('colorBackgroundStrong')}; | ||
padding: ${sizes(1)} ${sizes(2)}; | ||
border-radius: ${cVar('radiusSmall')}; | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './LineChart' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.