-
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): add logarithmic type for x and y axes (#493)
* feat(D3 plugin): add logarithmic type for x and y axes * fix type
- Loading branch information
Showing
5 changed files
with
120 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
|
||
import {StoryObj} from '@storybook/react'; | ||
|
||
import {D3Plugin} from '../..'; | ||
import {Loader} from '../../../../components/Loader/Loader'; | ||
import {settings} from '../../../../libs'; | ||
import {LineWithLogarithmicAxis} from '../../examples/line/LogarithmicAxis'; | ||
|
||
const ChartStory = ({Chart}: {Chart: React.FC}) => { | ||
const [loading, setLoading] = React.useState(true); | ||
|
||
React.useEffect(() => { | ||
settings.set({plugins: [D3Plugin]}); | ||
setLoading(false); | ||
}, []); | ||
|
||
if (loading) { | ||
return <Loader />; | ||
} | ||
|
||
return ( | ||
<div | ||
style={{ | ||
height: '80vh', | ||
width: '100%', | ||
}} | ||
> | ||
<Chart /> | ||
</div> | ||
); | ||
}; | ||
|
||
export const LogarithmicAxis: StoryObj<typeof ChartStory> = { | ||
name: 'Logarithmic axis', | ||
args: { | ||
Chart: LineWithLogarithmicAxis, | ||
}, | ||
}; | ||
|
||
export default { | ||
title: 'Plugins/D3/Line', | ||
component: ChartStory, | ||
}; |
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,56 @@ | ||
import React from 'react'; | ||
|
||
import {Col, Container, Row, Text} from '@gravity-ui/uikit'; | ||
import {randomNormal} from 'd3'; | ||
|
||
import {ChartKit} from '../../../../components/ChartKit'; | ||
import {ChartKitWidgetData} from '../../../../types'; | ||
import {ExampleWrapper} from '../ExampleWrapper'; | ||
|
||
export const LineWithLogarithmicAxis = () => { | ||
const randomY = randomNormal(0, 100); | ||
const widgetData: ChartKitWidgetData = { | ||
series: { | ||
data: [ | ||
{ | ||
type: 'line', | ||
name: 'Line series', | ||
data: new Array(25).fill(null).map((_, index) => ({ | ||
x: index, | ||
y: Math.abs(randomY()), | ||
})), | ||
}, | ||
], | ||
}, | ||
}; | ||
const lineWidgetData: ChartKitWidgetData = {...widgetData, title: {text: 'line'}}; | ||
const logarithmicWidgetData: ChartKitWidgetData = { | ||
...widgetData, | ||
title: {text: 'logarithmic'}, | ||
yAxis: [ | ||
{ | ||
type: 'logarithmic', | ||
}, | ||
], | ||
}; | ||
|
||
return ( | ||
<Container spaceRow={5}> | ||
<Row space={1}> | ||
<Text variant="header-2">logarithmic VS line</Text> | ||
</Row> | ||
<Row space={3}> | ||
<Col s={12} m={6}> | ||
<ExampleWrapper> | ||
<ChartKit type="d3" data={lineWidgetData} /> | ||
</ExampleWrapper> | ||
</Col> | ||
<Col s={12} m={6}> | ||
<ExampleWrapper> | ||
<ChartKit type="d3" data={logarithmicWidgetData} /> | ||
</ExampleWrapper> | ||
</Col> | ||
</Row> | ||
</Container> | ||
); | ||
}; |
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