-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chart): SKFP-692 add pie and chart graphics
- Loading branch information
Showing
11 changed files
with
838 additions
and
6 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@import "theme.template"; | ||
|
||
.barChartWrapper { | ||
height: 100%; | ||
position: relative;; | ||
width: 100%; | ||
text-align: center; | ||
|
||
.barChartContent { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
text-align: center; | ||
|
||
} | ||
|
||
*[class$="-typography"] { | ||
margin: 0; | ||
} | ||
|
||
.title { | ||
font-size: 12px; | ||
color: $chart-title-color; | ||
} | ||
} | ||
|
||
|
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,42 @@ | ||
import React from 'react'; | ||
import { BarDatum, BarSvgProps, ResponsiveBar } from '@nivo/bar'; | ||
import { Typography } from 'antd'; | ||
|
||
import styles from './index.module.scss'; | ||
|
||
type TBarChart = Omit<BarSvgProps<BarDatum>, 'width' | 'height'> & { | ||
title?: string; | ||
}; | ||
|
||
const { Title } = Typography; | ||
|
||
const BarChart = ({ | ||
margin = { bottom: 12, left: 24, right: 24, top: 12 }, | ||
onMouseEnter, | ||
colorBy = 'indexValue', | ||
title, | ||
...rest | ||
}: TBarChart): JSX.Element => ( | ||
<div className={styles.barChartWrapper}> | ||
<div className={styles.barChartContent}> | ||
{title && ( | ||
<Title className={styles.title} level={5}> | ||
{title} | ||
</Title> | ||
)} | ||
<ResponsiveBar | ||
colorBy={colorBy} | ||
margin={margin} | ||
onMouseEnter={(_: any, e: any) => { | ||
if (onMouseEnter) { | ||
onMouseEnter(_, e); | ||
} | ||
e.target.style.cursor = 'pointer'; | ||
}} | ||
{...rest} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
|
||
export default BarChart; |
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,24 @@ | ||
@import "theme.template"; | ||
|
||
.pieChartWrapper { | ||
height: 100%; | ||
position: relative;; | ||
width: 100%; | ||
text-align: center; | ||
|
||
.pieChartContent { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
*[class$="-typography"] { | ||
margin: 0; | ||
} | ||
|
||
.title { | ||
font-size: 12px; | ||
color: $chart-title-color; | ||
} | ||
} | ||
|
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,52 @@ | ||
import React from 'react'; | ||
import { DefaultRawDatum, PieSvgProps, ResponsivePie } from '@nivo/pie'; | ||
import { BasicTooltip } from '@nivo/tooltip'; | ||
import { Typography } from 'antd'; | ||
|
||
import styles from './index.module.scss'; | ||
|
||
export type TPieChart = Omit<PieSvgProps<DefaultRawDatum>, 'width' | 'height'> & { | ||
title?: string; | ||
margin?: { | ||
top: number; | ||
bottom: number; | ||
left: number; | ||
right: number; | ||
}; | ||
}; | ||
|
||
const { Title } = Typography; | ||
|
||
const PieChart = ({ | ||
margin = { bottom: 16, left: 24, right: 24, top: 16 }, | ||
onMouseEnter, | ||
title, | ||
...rest | ||
}: TPieChart): JSX.Element => ( | ||
<div className={styles.pieChartWrapper}> | ||
<div className={styles.pieChartContent}> | ||
<ResponsivePie | ||
enableArcLabels={false} | ||
enableArcLinkLabels={false} | ||
margin={margin} | ||
onMouseEnter={(_: any, e: any) => { | ||
if (onMouseEnter) { | ||
onMouseEnter(_, e); | ||
} | ||
e.target.style.cursor = 'pointer'; | ||
}} | ||
tooltip={(value) => ( | ||
<BasicTooltip color={value.datum.color} id={value.datum.id.toString()} value={value.datum.value} /> | ||
)} | ||
{...rest} | ||
/> | ||
{title && ( | ||
<Title className={styles.title} level={5}> | ||
{title} | ||
</Title> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
|
||
export default PieChart; |
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
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,44 @@ | ||
import BarChart from '@ferlab/ui/components/Charts/Bar'; | ||
import { Meta } from "@storybook/react/types-6-0"; | ||
import React from "react"; | ||
|
||
const data = [ | ||
{ | ||
"id": "1", | ||
"label": "label 1", | ||
"value": 6560 | ||
}, | ||
{ | ||
"id": "2", | ||
"label": "label 2", | ||
"value": 2966 | ||
}, | ||
{ | ||
"id": "3", | ||
"label": "label 3", | ||
"value": 2096 | ||
}, | ||
{ | ||
"id": "4", | ||
"label": "label 4", | ||
"value": 1681 | ||
} | ||
] | ||
|
||
export default { | ||
title: "@ferlab/Components/Charts/Bar", | ||
component: BarChart, | ||
decorators: [ | ||
(Story) => ( | ||
<> | ||
<h2>{Story}</h2> | ||
<Story /> | ||
</> | ||
), | ||
], | ||
} as Meta; | ||
|
||
|
||
export const BarChartStory = () => ( | ||
<BarChart title="Bar Chart Example" data={data} /> | ||
); |
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,44 @@ | ||
import PieChart from '@ferlab/ui/components/Charts/Pie'; | ||
import { Meta } from "@storybook/react/types-6-0"; | ||
import React from "react"; | ||
|
||
const data = [ | ||
{ | ||
"id": "1", | ||
"label": "label 1", | ||
"value": 6560 | ||
}, | ||
{ | ||
"id": "2", | ||
"label": "label 2", | ||
"value": 2966 | ||
}, | ||
{ | ||
"id": "3", | ||
"label": "label 3", | ||
"value": 2096 | ||
}, | ||
{ | ||
"id": "4", | ||
"label": "label 4", | ||
"value": 1681 | ||
} | ||
] | ||
|
||
export default { | ||
title: "@ferlab/Components/Charts/Pie", | ||
component: PieChart, | ||
decorators: [ | ||
(Story) => ( | ||
<> | ||
<h2>{Story}</h2> | ||
<Story /> | ||
</> | ||
), | ||
], | ||
} as Meta; | ||
|
||
|
||
export const PieChartBaseStory = () => ( | ||
<PieChart title="Pie Chart Example" data={data} /> | ||
); |