-
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): html labels for most of series (#527)
* feat(D3 plugin): html labels for most of series * fix
- Loading branch information
Showing
40 changed files
with
629 additions
and
103 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,80 @@ | ||
import React from 'react'; | ||
|
||
import {Col, Container, Row} from '@gravity-ui/uikit'; | ||
import type {StoryObj} from '@storybook/react'; | ||
|
||
import {ChartKit} from '../../../../components/ChartKit'; | ||
import {Loader} from '../../../../components/Loader/Loader'; | ||
import {settings} from '../../../../libs'; | ||
import type {ChartKitWidgetData} from '../../../../types'; | ||
import {ExampleWrapper} from '../../examples/ExampleWrapper'; | ||
import {D3Plugin} from '../../index'; | ||
|
||
const AreaWithHtmlLabels = () => { | ||
const [loading, setLoading] = React.useState(true); | ||
|
||
React.useEffect(() => { | ||
settings.set({plugins: [D3Plugin]}); | ||
setLoading(false); | ||
}, []); | ||
|
||
if (loading) { | ||
return <Loader />; | ||
} | ||
|
||
const getLabelData = (value: string, color: string) => { | ||
const labelStyle = `background: ${color};color: #fff;padding: 4px;border-radius: 4px;`; | ||
return { | ||
label: `<span style="${labelStyle}">${value}</span>`, | ||
}; | ||
}; | ||
|
||
const widgetData: ChartKitWidgetData = { | ||
series: { | ||
data: [ | ||
{ | ||
type: 'area', | ||
name: 'Series 1', | ||
dataLabels: { | ||
enabled: true, | ||
html: true, | ||
}, | ||
data: [ | ||
{ | ||
x: 1, | ||
y: Math.random() * 1000, | ||
...getLabelData('First', '#4fc4b7'), | ||
}, | ||
{ | ||
x: 100, | ||
y: Math.random() * 1000, | ||
...getLabelData('Last', '#8ccce3'), | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
title: {text: 'Area with html labels'}, | ||
}; | ||
|
||
return ( | ||
<Container spaceRow={5}> | ||
<Row space={1}> | ||
<Col s={4}> | ||
<ExampleWrapper> | ||
<ChartKit type="d3" data={widgetData} /> | ||
</ExampleWrapper> | ||
</Col> | ||
</Row> | ||
</Container> | ||
); | ||
}; | ||
|
||
export const AreaWithHtmlLabelsStory: StoryObj<typeof AreaWithHtmlLabels> = { | ||
name: 'Html in labels', | ||
}; | ||
|
||
export default { | ||
title: 'Plugins/D3/Area', | ||
component: AreaWithHtmlLabels, | ||
}; |
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,82 @@ | ||
import React from 'react'; | ||
|
||
import {Col, Container, Row} from '@gravity-ui/uikit'; | ||
import type {StoryObj} from '@storybook/react'; | ||
|
||
import {ChartKit} from '../../../../components/ChartKit'; | ||
import {Loader} from '../../../../components/Loader/Loader'; | ||
import {settings} from '../../../../libs'; | ||
import type {ChartKitWidgetData} from '../../../../types'; | ||
import {ExampleWrapper} from '../../examples/ExampleWrapper'; | ||
import {D3Plugin} from '../../index'; | ||
|
||
const BarXWithHtmlLabels = () => { | ||
const [loading, setLoading] = React.useState(true); | ||
|
||
React.useEffect(() => { | ||
settings.set({plugins: [D3Plugin]}); | ||
setLoading(false); | ||
}, []); | ||
|
||
if (loading) { | ||
return <Loader />; | ||
} | ||
|
||
const getLabelData = (value: string, color: string) => { | ||
const labelStyle = `background: ${color};color: #fff;padding: 4px;border-radius: 4px;border: 1px solid #fff;`; | ||
return { | ||
label: `<span style="${labelStyle}">${value}</span>`, | ||
color, | ||
}; | ||
}; | ||
|
||
const widgetData: ChartKitWidgetData = { | ||
series: { | ||
data: [ | ||
{ | ||
type: 'bar-x', | ||
name: 'Series 1', | ||
dataLabels: { | ||
enabled: true, | ||
html: true, | ||
}, | ||
data: [ | ||
{ | ||
x: 0, | ||
y: Math.random() * 1000, | ||
...getLabelData('First', '#4fc4b7'), | ||
}, | ||
{ | ||
x: 1, | ||
y: Math.random() * 1000, | ||
...getLabelData('Last', '#8ccce3'), | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
xAxis: {type: 'category', categories: ['First', 'Second']}, | ||
title: {text: 'Bar-x with html labels'}, | ||
}; | ||
|
||
return ( | ||
<Container spaceRow={5}> | ||
<Row space={1}> | ||
<Col s={4}> | ||
<ExampleWrapper> | ||
<ChartKit type="d3" data={widgetData} /> | ||
</ExampleWrapper> | ||
</Col> | ||
</Row> | ||
</Container> | ||
); | ||
}; | ||
|
||
export const BarXWithHtmlLabelsStory: StoryObj<typeof BarXWithHtmlLabels> = { | ||
name: 'Html in labels', | ||
}; | ||
|
||
export default { | ||
title: 'Plugins/D3/Bar-x', | ||
component: BarXWithHtmlLabels, | ||
}; |
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,82 @@ | ||
import React from 'react'; | ||
|
||
import {Col, Container, Row} from '@gravity-ui/uikit'; | ||
import type {StoryObj} from '@storybook/react'; | ||
|
||
import {ChartKit} from '../../../../components/ChartKit'; | ||
import {Loader} from '../../../../components/Loader/Loader'; | ||
import {settings} from '../../../../libs'; | ||
import type {ChartKitWidgetData} from '../../../../types'; | ||
import {ExampleWrapper} from '../../examples/ExampleWrapper'; | ||
import {D3Plugin} from '../../index'; | ||
|
||
const BarYWithHtmlLabels = () => { | ||
const [loading, setLoading] = React.useState(true); | ||
|
||
React.useEffect(() => { | ||
settings.set({plugins: [D3Plugin]}); | ||
setLoading(false); | ||
}, []); | ||
|
||
if (loading) { | ||
return <Loader />; | ||
} | ||
|
||
const getLabelData = (value: string, color: string) => { | ||
const labelStyle = `background: ${color};color: #fff;padding: 4px;border-radius: 4px;border: 1px solid #fff;`; | ||
return { | ||
label: `<span style="${labelStyle}">${value}</span>`, | ||
color, | ||
}; | ||
}; | ||
|
||
const widgetData: ChartKitWidgetData = { | ||
series: { | ||
data: [ | ||
{ | ||
type: 'bar-y', | ||
name: 'Series 1', | ||
dataLabels: { | ||
enabled: true, | ||
html: true, | ||
}, | ||
data: [ | ||
{ | ||
y: 0, | ||
x: Math.random() * 1000, | ||
...getLabelData('First', '#4fc4b7'), | ||
}, | ||
{ | ||
y: 1, | ||
x: Math.random() * 1000, | ||
...getLabelData('Last', '#8ccce3'), | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
yAxis: [{type: 'category', categories: ['First', 'Second']}], | ||
title: {text: 'Bar-y with html labels'}, | ||
}; | ||
|
||
return ( | ||
<Container spaceRow={5}> | ||
<Row space={1}> | ||
<Col s={4}> | ||
<ExampleWrapper> | ||
<ChartKit type="d3" data={widgetData} /> | ||
</ExampleWrapper> | ||
</Col> | ||
</Row> | ||
</Container> | ||
); | ||
}; | ||
|
||
export const BarYWithHtmlLabelsStory: StoryObj<typeof BarYWithHtmlLabels> = { | ||
name: 'Html in labels', | ||
}; | ||
|
||
export default { | ||
title: 'Plugins/D3/Bar-y', | ||
component: BarYWithHtmlLabels, | ||
}; |
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,80 @@ | ||
import React from 'react'; | ||
|
||
import {Col, Container, Row} from '@gravity-ui/uikit'; | ||
import type {StoryObj} from '@storybook/react'; | ||
|
||
import {ChartKit} from '../../../../components/ChartKit'; | ||
import {Loader} from '../../../../components/Loader/Loader'; | ||
import {settings} from '../../../../libs'; | ||
import type {ChartKitWidgetData} from '../../../../types'; | ||
import {ExampleWrapper} from '../../examples/ExampleWrapper'; | ||
import {D3Plugin} from '../../index'; | ||
|
||
const LineWithHtmlLabels = () => { | ||
const [loading, setLoading] = React.useState(true); | ||
|
||
React.useEffect(() => { | ||
settings.set({plugins: [D3Plugin]}); | ||
setLoading(false); | ||
}, []); | ||
|
||
if (loading) { | ||
return <Loader />; | ||
} | ||
|
||
const getLabelData = (value: string, color: string) => { | ||
const labelStyle = `background: ${color};color: #fff;padding: 4px;border-radius: 4px;`; | ||
return { | ||
label: `<span style="${labelStyle}">${value}</span>`, | ||
}; | ||
}; | ||
|
||
const widgetData: ChartKitWidgetData = { | ||
series: { | ||
data: [ | ||
{ | ||
type: 'line', | ||
name: 'Series 1', | ||
dataLabels: { | ||
enabled: true, | ||
html: true, | ||
}, | ||
data: [ | ||
{ | ||
x: 1, | ||
y: Math.random() * 1000, | ||
...getLabelData('First', '#4fc4b7'), | ||
}, | ||
{ | ||
x: 100, | ||
y: Math.random() * 1000, | ||
...getLabelData('Last', '#8ccce3'), | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
title: {text: 'Line with html labels'}, | ||
}; | ||
|
||
return ( | ||
<Container spaceRow={5}> | ||
<Row space={1}> | ||
<Col s={4}> | ||
<ExampleWrapper> | ||
<ChartKit type="d3" data={widgetData} /> | ||
</ExampleWrapper> | ||
</Col> | ||
</Row> | ||
</Container> | ||
); | ||
}; | ||
|
||
export const LineWithHtmlLabelsStory: StoryObj<typeof LineWithHtmlLabels> = { | ||
name: 'Html in labels', | ||
}; | ||
|
||
export default { | ||
title: 'Plugins/D3/Line', | ||
component: LineWithHtmlLabels, | ||
}; |
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
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.