-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[charts] Let the
useXxxSeries
support array of ids and document them (
- Loading branch information
Showing
34 changed files
with
676 additions
and
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { useHeatmapSeries } from './useSeries'; | ||
export { useHeatmapSeries } from './useHeatmapSeries'; | ||
export * from './zoom'; |
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,64 @@ | ||
import { renderHook } from '@mui/internal-test-utils'; | ||
import { expect } from 'chai'; | ||
import * as React from 'react'; | ||
import { useHeatmapSeries } from './useHeatmapSeries'; | ||
import { Heatmap } from '../Heatmap'; | ||
import { HeatmapSeriesType } from '../models'; | ||
|
||
describe('useHeatmapSeries', () => { | ||
const mockSeries: HeatmapSeriesType[] = [ | ||
{ | ||
type: 'heatmap', | ||
id: '1', | ||
data: [ | ||
[0, 0, 10], | ||
[0, 1, 20], | ||
[0, 2, 40], | ||
], | ||
}, | ||
{ | ||
type: 'heatmap', | ||
id: '2', | ||
data: [ | ||
[3, 2, 20], | ||
[3, 3, 70], | ||
[3, 4, 90], | ||
], | ||
}, | ||
]; | ||
|
||
const defaultProps = { | ||
series: mockSeries, | ||
height: 400, | ||
width: 400, | ||
xAxis: [{ data: [1, 2, 3, 4] }], | ||
yAxis: [{ data: ['A', 'B', 'C', 'D', 'E'] }], | ||
}; | ||
|
||
const options: any = { | ||
wrapper: ({ children }: { children: React.ReactElement }) => { | ||
return <Heatmap {...defaultProps}>{children}</Heatmap>; | ||
}, | ||
}; | ||
|
||
it('should return all heatmap series when no seriesIds are provided', () => { | ||
const { result } = renderHook(() => useHeatmapSeries(), options); | ||
expect(result.current?.seriesOrder).to.deep.equal(['1', '2']); | ||
expect(Object.keys(result.current?.series ?? {})).to.deep.equal(['1', '2']); | ||
}); | ||
|
||
it('should return the specific heatmap series when a single seriesId is provided', () => { | ||
const { result } = renderHook(() => useHeatmapSeries('1'), options); | ||
expect(result.current?.id).to.deep.equal(mockSeries[0].id); | ||
}); | ||
|
||
it('should return the specific heatmap series when multiple seriesIds are provided', () => { | ||
const { result } = renderHook(() => useHeatmapSeries(['2', '1']), options); | ||
expect(result.current?.map((v) => v?.id)).to.deep.equal([mockSeries[1].id, mockSeries[0].id]); | ||
}); | ||
|
||
it('should return undefined series when invalid seriesIds are provided', () => { | ||
const { result } = renderHook(() => useHeatmapSeries(['1', '3']), options); | ||
expect(result.current?.map((v) => v?.id)).to.deep.equal([mockSeries[0].id, undefined]); | ||
}); | ||
}); |
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,37 @@ | ||
'use client'; | ||
import { | ||
createSeriesSelectorsOfType, | ||
ProcessedSeries, | ||
SeriesId, | ||
ChartSeriesDefaultized, | ||
} from '@mui/x-charts/internals'; | ||
|
||
const selectorSeries = createSeriesSelectorsOfType('heatmap'); | ||
|
||
/** | ||
* Get access to the internal state of heatmap series. | ||
* The returned object contains: | ||
* - series: a mapping from ids to series attributes. | ||
* - seriesOrder: the array of series ids. | ||
* @returns {{ series: Record<SeriesId, DefaultizedHeatmapSeriesType>; seriesOrder: SeriesId[]; } | undefined} heatmapSeries | ||
*/ | ||
export function useHeatmapSeries(): ProcessedSeries['heatmap']; | ||
/** | ||
* Get access to the internal state of heatmap series. | ||
* | ||
* @param {SeriesId} seriesId The id of the series to get. | ||
* @returns {ChartSeriesDefaultized<'heatmap'> | undefined} heatmapSeries | ||
*/ | ||
export function useHeatmapSeries(seriesId: SeriesId): ChartSeriesDefaultized<'heatmap'> | undefined; | ||
/** | ||
* Get access to the internal state of heatmap series. | ||
* | ||
* @param {SeriesId[]} seriesIds The ids of the series to get. Order is preserved. | ||
* @returns {ChartSeriesDefaultized<'heatmap'>[] | undefined} heatmapSeries | ||
*/ | ||
export function useHeatmapSeries( | ||
seriesIds: SeriesId[], | ||
): (ChartSeriesDefaultized<'heatmap'> | undefined)[]; | ||
export function useHeatmapSeries(seriesIds?: SeriesId | SeriesId[]) { | ||
return selectorSeries(seriesIds); | ||
} |
This file was deleted.
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
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
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,54 @@ | ||
import { renderHook } from '@mui/internal-test-utils'; | ||
import { expect } from 'chai'; | ||
import * as React from 'react'; | ||
import { useBarSeries } from './useBarSeries'; | ||
import { BarSeriesType } from '../models'; | ||
import { BarChart } from '../BarChart'; | ||
|
||
describe('useBarSeries', () => { | ||
const mockSeries: BarSeriesType[] = [ | ||
{ | ||
type: 'bar', | ||
id: '1', | ||
data: [1, 2, 3], | ||
}, | ||
{ | ||
type: 'bar', | ||
id: '2', | ||
data: [4, 5, 6], | ||
}, | ||
]; | ||
|
||
const defaultProps = { | ||
series: mockSeries, | ||
height: 400, | ||
width: 400, | ||
}; | ||
|
||
const options: any = { | ||
wrapper: ({ children }: { children: React.ReactElement }) => { | ||
return <BarChart {...defaultProps}>{children}</BarChart>; | ||
}, | ||
}; | ||
|
||
it('should return all bar series when no seriesIds are provided', () => { | ||
const { result } = renderHook(() => useBarSeries(), options); | ||
expect(result.current?.seriesOrder).to.deep.equal(['1', '2']); | ||
expect(Object.keys(result.current?.series ?? {})).to.deep.equal(['1', '2']); | ||
}); | ||
|
||
it('should return the specific bar series when a single seriesId is provided', () => { | ||
const { result } = renderHook(() => useBarSeries('1'), options); | ||
expect(result.current?.id).to.deep.equal(mockSeries[0].id); | ||
}); | ||
|
||
it('should return the specific bar series when multiple seriesIds are provided', () => { | ||
const { result } = renderHook(() => useBarSeries(['2', '1']), options); | ||
expect(result.current?.map((v) => v?.id)).to.deep.equal([mockSeries[1].id, mockSeries[0].id]); | ||
}); | ||
|
||
it('should return undefined series when invalid seriesIds are provided', () => { | ||
const { result } = renderHook(() => useBarSeries(['1', '3']), options); | ||
expect(result.current?.map((v) => v?.id)).to.deep.equal([mockSeries[0].id, undefined]); | ||
}); | ||
}); |
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,33 @@ | ||
'use client'; | ||
import { ProcessedSeries } from '../internals/plugins/corePlugins/useChartSeries/useChartSeries.types'; | ||
import { SeriesId } from '../models/seriesType/common'; | ||
import { ChartSeriesDefaultized } from '../models/seriesType/config'; | ||
import { createSeriesSelectorsOfType } from '../internals/createSeriesSelectorOfType'; | ||
|
||
const selectorSeries = createSeriesSelectorsOfType('bar'); | ||
|
||
/** | ||
* Get access to the internal state of bar series. | ||
* The returned object contains: | ||
* - series: a mapping from ids to series attributes. | ||
* - seriesOrder: the array of series ids. | ||
* @returns {{ series: Record<SeriesId, DefaultizedBarSeriesType>; seriesOrder: SeriesId[]; } | undefined} barSeries | ||
*/ | ||
export function useBarSeries(): ProcessedSeries['bar']; | ||
/** | ||
* Get access to the internal state of bar series. | ||
* | ||
* @param {SeriesId} seriesId The id of the series to get. | ||
* @returns {ChartSeriesDefaultized<'bar'> | undefined} barSeries | ||
*/ | ||
export function useBarSeries(seriesId: SeriesId): ChartSeriesDefaultized<'bar'> | undefined; | ||
/** | ||
* Get access to the internal state of bar series. | ||
* | ||
* @param {SeriesId[]} seriesIds The ids of the series to get. Order is preserved. | ||
* @returns {ChartSeriesDefaultized<'bar'>[] | undefined} barSeries | ||
*/ | ||
export function useBarSeries(seriesIds: SeriesId[]): (ChartSeriesDefaultized<'bar'> | undefined)[]; | ||
export function useBarSeries(seriesIds?: SeriesId | SeriesId[]) { | ||
return selectorSeries(seriesIds); | ||
} |
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.