-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(D3 plugin): grouped bar-x series (#272)
* feat(D3 plugin): grouped bar-x series * fix story * fix stories
- Loading branch information
Showing
9 changed files
with
475 additions
and
174 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import React from 'react'; | ||
import {Meta, Story} from '@storybook/react'; | ||
import {object, withKnobs} from '@storybook/addon-knobs'; | ||
import {Button} from '@gravity-ui/uikit'; | ||
import {settings} from '../../../../libs'; | ||
import {ChartKit} from '../../../../components/ChartKit'; | ||
import type {ChartKitWidgetData, ChartKitRef} from '../../../../types'; | ||
import {D3Plugin} from '../..'; | ||
|
||
const Template: Story = () => { | ||
const [shown, setShown] = React.useState(false); | ||
const chartkitRef = React.useRef<ChartKitRef>(); | ||
const data: ChartKitWidgetData = { | ||
tooltip: {enabled: true}, | ||
title: {text: 'Grouped'}, | ||
xAxis: { | ||
type: 'category', | ||
categories: ['A', 'B', 'C'], | ||
labels: {enabled: true}, | ||
}, | ||
yAxis: [ | ||
{ | ||
type: 'linear', | ||
labels: {enabled: true}, | ||
min: 0, | ||
}, | ||
], | ||
series: { | ||
data: [ | ||
{ | ||
type: 'bar-x', | ||
visible: true, | ||
data: [ | ||
{ | ||
x: 'A', | ||
y: 10, | ||
}, | ||
{ | ||
x: 'B', | ||
y: 80, | ||
}, | ||
{ | ||
x: 'C', | ||
y: 25, | ||
}, | ||
], | ||
name: 'Min', | ||
dataLabels: { | ||
enabled: true, | ||
}, | ||
}, | ||
{ | ||
type: 'bar-x', | ||
visible: true, | ||
data: [ | ||
{ | ||
x: 'A', | ||
y: 110, | ||
}, | ||
{ | ||
x: 'B', | ||
y: 80, | ||
}, | ||
{ | ||
x: 'C', | ||
y: 200, | ||
}, | ||
], | ||
name: 'Mid', | ||
dataLabels: { | ||
enabled: true, | ||
}, | ||
}, | ||
{ | ||
type: 'bar-x', | ||
visible: true, | ||
data: [ | ||
{ | ||
x: 'A', | ||
y: 410, | ||
}, | ||
{ | ||
x: 'B', | ||
y: 580, | ||
}, | ||
{ | ||
x: 'C', | ||
y: 205, | ||
}, | ||
], | ||
name: 'Max', | ||
dataLabels: { | ||
enabled: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
if (!shown) { | ||
settings.set({plugins: [D3Plugin]}); | ||
return <Button onClick={() => setShown(true)}>Show chart</Button>; | ||
} | ||
|
||
return ( | ||
<div | ||
style={{ | ||
height: '80vh', | ||
width: '100%', | ||
}} | ||
> | ||
<ChartKit ref={chartkitRef} type="d3" data={object<ChartKitWidgetData>('data', data)} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export const Grouped = Template.bind({}); | ||
|
||
const meta: Meta = { | ||
title: 'Plugins/D3/Bar-X', | ||
decorators: [withKnobs], | ||
}; | ||
|
||
export default meta; |
142 changes: 142 additions & 0 deletions
142
src/plugins/d3/__stories__/bar-x/GroupedAndStacked.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,142 @@ | ||
import React from 'react'; | ||
import {Meta, Story} from '@storybook/react'; | ||
import {object, withKnobs} from '@storybook/addon-knobs'; | ||
import {Button} from '@gravity-ui/uikit'; | ||
import {settings} from '../../../../libs'; | ||
import {ChartKit} from '../../../../components/ChartKit'; | ||
import type {ChartKitWidgetData, ChartKitRef} from '../../../../types'; | ||
import {D3Plugin} from '../..'; | ||
|
||
const Template: Story = () => { | ||
const [shown, setShown] = React.useState(false); | ||
const chartkitRef = React.useRef<ChartKitRef>(); | ||
const data: ChartKitWidgetData = { | ||
tooltip: {enabled: true}, | ||
title: {text: 'Grouped and stacked'}, | ||
xAxis: { | ||
type: 'category', | ||
categories: ['A', 'B', 'C'], | ||
labels: {enabled: true}, | ||
}, | ||
yAxis: [ | ||
{ | ||
type: 'linear', | ||
labels: {enabled: true}, | ||
min: 0, | ||
}, | ||
], | ||
series: { | ||
data: [ | ||
{ | ||
type: 'bar-x', | ||
visible: true, | ||
stacking: 'normal', | ||
data: [ | ||
{ | ||
x: 'A', | ||
y: 100, | ||
}, | ||
{ | ||
x: 'B', | ||
y: 805, | ||
}, | ||
{ | ||
x: 'C', | ||
y: 250, | ||
}, | ||
], | ||
stackId: 'stack1', | ||
name: 'Base1', | ||
}, | ||
{ | ||
type: 'bar-x', | ||
visible: true, | ||
stacking: 'normal', | ||
data: [ | ||
{ | ||
x: 'A', | ||
y: 40, | ||
}, | ||
{ | ||
x: 'B', | ||
y: 80, | ||
}, | ||
{ | ||
x: 'C', | ||
y: 25, | ||
}, | ||
], | ||
stackId: 'stack1', | ||
name: 'Extended1', | ||
}, | ||
{ | ||
type: 'bar-x', | ||
visible: true, | ||
stacking: 'normal', | ||
data: [ | ||
{ | ||
x: 'A', | ||
y: 110, | ||
}, | ||
{ | ||
x: 'B', | ||
y: 80, | ||
}, | ||
{ | ||
x: 'C', | ||
y: 200, | ||
}, | ||
], | ||
stackId: 'stack2', | ||
name: 'Base2', | ||
}, | ||
{ | ||
type: 'bar-x', | ||
visible: true, | ||
stacking: 'normal', | ||
data: [ | ||
{ | ||
x: 'A', | ||
y: 110, | ||
}, | ||
{ | ||
x: 'B', | ||
y: 80, | ||
}, | ||
{ | ||
x: 'C', | ||
y: 200, | ||
}, | ||
], | ||
stackId: 'stack2', | ||
name: 'Extended2', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
if (!shown) { | ||
settings.set({plugins: [D3Plugin]}); | ||
return <Button onClick={() => setShown(true)}>Show chart</Button>; | ||
} | ||
|
||
return ( | ||
<div | ||
style={{ | ||
height: '80vh', | ||
width: '100%', | ||
}} | ||
> | ||
<ChartKit ref={chartkitRef} type="d3" data={object<ChartKitWidgetData>('data', data)} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export const GroupedAndStacked = Template.bind({}); | ||
|
||
const meta: Meta = { | ||
title: 'Plugins/D3/Bar-X', | ||
decorators: [withKnobs], | ||
}; | ||
|
||
export default meta; |
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
File renamed without changes.
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.