-
Notifications
You must be signed in to change notification settings - Fork 4
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 second Y axis support (#480)
* feat(D3 plugin): add second Y axis support * Fix y scale for dual axis * Add examples with dual Y axis to other series types * fix types * Slice test data * fix after review * fix axis with hidden series * Add axis index validation
- Loading branch information
Showing
34 changed files
with
1,826 additions
and
201 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
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,68 @@ | ||
import React from 'react'; | ||
|
||
import {dateTime} from '@gravity-ui/date-utils'; | ||
|
||
import {ChartKit} from '../../../../components/ChartKit'; | ||
import type {ChartKitWidgetData} from '../../../../types'; | ||
import {ExampleWrapper} from '../ExampleWrapper'; | ||
import marsWeatherData from '../mars-weather'; | ||
|
||
export const TwoYAxis = () => { | ||
const data = marsWeatherData as any[]; | ||
const pressureData = data.map((d) => ({ | ||
x: dateTime({input: d.terrestrial_date, format: 'YYYY-MM-DD'}).valueOf(), | ||
y: d.pressure, | ||
})); | ||
|
||
const tempData = data.map((d) => ({ | ||
x: dateTime({input: d.terrestrial_date, format: 'YYYY-MM-DD'}).valueOf(), | ||
y: d.max_temp - d.min_temp, | ||
})); | ||
|
||
const widgetData: ChartKitWidgetData = { | ||
series: { | ||
data: [ | ||
{ | ||
type: 'area', | ||
data: pressureData, | ||
name: 'Pressure', | ||
yAxis: 0, | ||
}, | ||
{ | ||
type: 'area', | ||
data: tempData, | ||
name: 'Temperature range', | ||
yAxis: 1, | ||
}, | ||
], | ||
}, | ||
yAxis: [ | ||
{ | ||
title: { | ||
text: 'Pressure', | ||
}, | ||
}, | ||
{ | ||
title: { | ||
text: 'Temperature range', | ||
}, | ||
}, | ||
], | ||
xAxis: { | ||
type: 'datetime', | ||
title: { | ||
text: 'Terrestrial date', | ||
}, | ||
ticks: {pixelInterval: 200}, | ||
}, | ||
title: { | ||
text: 'Mars weather', | ||
}, | ||
}; | ||
|
||
return ( | ||
<ExampleWrapper> | ||
<ChartKit type="d3" data={widgetData} /> | ||
</ExampleWrapper> | ||
); | ||
}; |
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,68 @@ | ||
import React from 'react'; | ||
|
||
import {dateTime} from '@gravity-ui/date-utils'; | ||
|
||
import {ChartKit} from '../../../../components/ChartKit'; | ||
import type {ChartKitWidgetData} from '../../../../types'; | ||
import {ExampleWrapper} from '../ExampleWrapper'; | ||
import marsWeatherData from '../mars-weather'; | ||
|
||
export const TwoYAxis = () => { | ||
const data = marsWeatherData as any[]; | ||
const pressureData = data.map((d) => ({ | ||
x: dateTime({input: d.terrestrial_date, format: 'YYYY-MM-DD'}).valueOf(), | ||
y: d.pressure, | ||
})); | ||
|
||
const tempData = data.map((d) => ({ | ||
x: dateTime({input: d.terrestrial_date, format: 'YYYY-MM-DD'}).valueOf(), | ||
y: d.max_temp - d.min_temp, | ||
})); | ||
|
||
const widgetData: ChartKitWidgetData = { | ||
series: { | ||
data: [ | ||
{ | ||
type: 'bar-x', | ||
data: pressureData, | ||
name: 'Pressure', | ||
yAxis: 0, | ||
}, | ||
{ | ||
type: 'bar-x', | ||
data: tempData, | ||
name: 'Temperature range', | ||
yAxis: 1, | ||
}, | ||
], | ||
}, | ||
yAxis: [ | ||
{ | ||
title: { | ||
text: 'Pressure', | ||
}, | ||
}, | ||
{ | ||
title: { | ||
text: 'Temperature range', | ||
}, | ||
}, | ||
], | ||
xAxis: { | ||
type: 'datetime', | ||
title: { | ||
text: 'Terrestrial date', | ||
}, | ||
ticks: {pixelInterval: 200}, | ||
}, | ||
title: { | ||
text: 'Mars weather', | ||
}, | ||
}; | ||
|
||
return ( | ||
<ExampleWrapper> | ||
<ChartKit type="d3" data={widgetData} /> | ||
</ExampleWrapper> | ||
); | ||
}; |
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,68 @@ | ||
import React from 'react'; | ||
|
||
import {dateTime} from '@gravity-ui/date-utils'; | ||
|
||
import {ChartKit} from '../../../../components/ChartKit'; | ||
import type {ChartKitWidgetData} from '../../../../types'; | ||
import {ExampleWrapper} from '../ExampleWrapper'; | ||
import marsWeatherData from '../mars-weather'; | ||
|
||
export const TwoYAxis = () => { | ||
const data = marsWeatherData as any[]; | ||
const minTempData = data.map((d) => ({ | ||
x: dateTime({input: d.terrestrial_date, format: 'YYYY-MM-DD'}).valueOf(), | ||
y: d.min_temp, | ||
})); | ||
|
||
const maxTempData = data.map((d) => ({ | ||
x: dateTime({input: d.terrestrial_date, format: 'YYYY-MM-DD'}).valueOf(), | ||
y: d.max_temp, | ||
})); | ||
|
||
const widgetData: ChartKitWidgetData = { | ||
series: { | ||
data: [ | ||
{ | ||
type: 'line', | ||
data: minTempData, | ||
name: 'Min Temperature', | ||
yAxis: 0, | ||
}, | ||
{ | ||
type: 'line', | ||
data: maxTempData, | ||
name: 'Max Temperature', | ||
yAxis: 1, | ||
}, | ||
], | ||
}, | ||
yAxis: [ | ||
{ | ||
title: { | ||
text: 'Min', | ||
}, | ||
}, | ||
{ | ||
title: { | ||
text: 'Max', | ||
}, | ||
}, | ||
], | ||
xAxis: { | ||
type: 'datetime', | ||
title: { | ||
text: 'Terrestrial date', | ||
}, | ||
ticks: {pixelInterval: 200}, | ||
}, | ||
title: { | ||
text: 'Mars weather', | ||
}, | ||
}; | ||
|
||
return ( | ||
<ExampleWrapper> | ||
<ChartKit type="d3" data={widgetData} /> | ||
</ExampleWrapper> | ||
); | ||
}; |
Oops, something went wrong.