-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[charts-pro] Allow exporting a heatmap chart #17916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0d2f117
[charts-pro] allow exporting a heatmap chart
bernardobelchior 4771210
Add docs showcasing heatmap export
bernardobelchior 839edfb
Gen types, fix static.
bernardobelchior 2184f94
Add composition field
bernardobelchior be4fe4c
Fix print chart demo
bernardobelchior 86b9995
Fix ChartProApi
bernardobelchior cf5411c
Add legend to demo. Remove ChartsRootSurface.
bernardobelchior 3d939ec
Revert chartRootRef type change
bernardobelchior File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,22 @@ | ||
export const heatmapData = [ | ||
[0, 0, 10], | ||
[0, 1, 20], | ||
[0, 2, 40], | ||
[0, 3, 90], | ||
[0, 4, 70], | ||
[1, 0, 30], | ||
[1, 1, 50], | ||
[1, 2, 10], | ||
[1, 3, 70], | ||
[1, 4, 40], | ||
[2, 0, 50], | ||
[2, 1, 20], | ||
[2, 2, 90], | ||
[2, 3, 20], | ||
[2, 4, 70], | ||
[3, 0, 40], | ||
[3, 1, 50], | ||
[3, 2, 20], | ||
[3, 3, 70], | ||
[3, 4, 90], | ||
]; |
This file contains hidden or 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,24 @@ | ||
import { HeatmapValueType } from '@mui/x-charts-pro/models'; | ||
|
||
export const heatmapData: HeatmapValueType[] = [ | ||
[0, 0, 10], | ||
[0, 1, 20], | ||
[0, 2, 40], | ||
[0, 3, 90], | ||
[0, 4, 70], | ||
[1, 0, 30], | ||
[1, 1, 50], | ||
[1, 2, 10], | ||
[1, 3, 70], | ||
[1, 4, 40], | ||
[2, 0, 50], | ||
[2, 1, 20], | ||
[2, 2, 90], | ||
[2, 3, 20], | ||
[2, 4, 70], | ||
[3, 0, 40], | ||
[3, 1, 50], | ||
[3, 2, 20], | ||
[3, 3, 70], | ||
[3, 4, 90], | ||
]; |
This file contains hidden or 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
28 changes: 28 additions & 0 deletions
28
packages/x-charts-pro/src/ChartContainerPro/ChartProApi.ts
This file contains hidden or 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,28 @@ | ||
import { ChartAnyPluginSignature, ChartPublicAPI } from '@mui/x-charts/internals'; | ||
import { HeatmapPluginsSignatures } from '../Heatmap/Heatmap.plugins'; | ||
import { LineChartProPluginsSignatures } from '../LineChartPro/LineChartPro.plugins'; | ||
import { ScatterChartProPluginsSignatures } from '../ScatterChartPro/ScatterChartPro.plugins'; | ||
import { BarChartProPluginsSignatures } from '../BarChartPro/BarChartPro.plugins'; | ||
import { AllPluginSignatures, DefaultPluginSignatures } from '../internals/plugins/allPlugins'; | ||
|
||
type PluginsPerSeriesType = { | ||
heatmap: HeatmapPluginsSignatures; | ||
line: LineChartProPluginsSignatures; | ||
scatter: ScatterChartProPluginsSignatures; | ||
bar: BarChartProPluginsSignatures; | ||
/* Special value when creating a chart using composition. */ | ||
composition: DefaultPluginSignatures; | ||
}; | ||
|
||
/** | ||
* The API of the chart `apiRef` object. | ||
* The chart type can be passed as the first generic parameter to narrow down the API to the specific chart type. | ||
* @example ChartProApi<'bar'> | ||
*/ | ||
export type ChartProApi< | ||
TSeries extends keyof PluginsPerSeriesType | undefined = undefined, | ||
TSignatures extends | ||
readonly ChartAnyPluginSignature[] = TSeries extends keyof PluginsPerSeriesType | ||
? PluginsPerSeriesType[TSeries] | ||
: AllPluginSignatures, | ||
> = ChartPublicAPI<TSignatures>; |
This file contains hidden or 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,3 +1,4 @@ | ||
import '../typeOverloads'; | ||
|
||
export * from './ChartContainerPro'; | ||
export * from './ChartProApi'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, I don't think we can keep the current API for
ChartProApi
. Either we create a new type, or we need to accept this breaking change as a bug fix.It is a bug because invalid types are accepted. For example, the heatmap's
apiRef
doesn't contain asetZoomData
property, but the type says it does.It's unlikely a lot of people are using it as it was released in v8.1.0, but it's technically a breaking change if we don't flag it as a bug.
Another option would be to create another type to avoid breaking users and deprecate this one. What are your thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could just go with the generic one but still allow users to narrow the types with the
<'seriesType'>
notation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't work either. I suppose it's the same issue as trying to pass a
RefObject<HTMLElement>
to aHTMLDivElement
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it, if the issue is that you are passing a wide type but it expects a narrow type, just make the expectation wide, so it can accept a narrow one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I managed to make it work.
I thought it was another case of this issue with
HTMLDivElement
andHTMLElement
:I've kept the
ChartProApi<'line'>
here because we should encourage users to use it, but it's usable without it as well:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice