@mui/x-charts-pro 8.11.2 → 8.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BarChartPro/BarChartPro.d.ts +2 -2
- package/BarChartPro/BarChartPro.js +1 -0
- package/BarChartPro/BarChartPro.plugins.d.ts +3 -3
- package/BarChartPro/BarChartPro.plugins.js +1 -1
- package/BarChartPro/index.d.ts +2 -1
- package/BarChartPro/index.js +11 -0
- package/CHANGELOG.md +231 -0
- package/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
- package/ChartZoomSlider/internals/ChartAxisZoomSliderThumb.js +2 -2
- package/FunnelChart/FunnelChart.d.ts +2 -2
- package/FunnelChart/FunnelChart.plugins.d.ts +2 -2
- package/FunnelChart/FunnelPlot.js +2 -2
- package/FunnelChart/funnelAxisPlugin/computeAxisValue.js +1 -1
- package/FunnelChart/index.d.ts +1 -0
- package/FunnelChart/index.js +12 -0
- package/FunnelChart/useFunnelChartProps.d.ts +2 -2
- package/FunnelChart/useFunnelChartProps.js +4 -3
- package/Heatmap/Heatmap.d.ts +2 -2
- package/Heatmap/Heatmap.js +2 -1
- package/Heatmap/Heatmap.plugins.d.ts +2 -2
- package/Heatmap/index.d.ts +1 -0
- package/Heatmap/index.js +12 -0
- package/LineChartPro/LineChartPro.d.ts +2 -2
- package/LineChartPro/LineChartPro.js +1 -0
- package/LineChartPro/LineChartPro.plugins.d.ts +3 -3
- package/LineChartPro/LineChartPro.plugins.js +1 -1
- package/LineChartPro/index.d.ts +2 -1
- package/LineChartPro/index.js +11 -0
- package/PieChartPro/PieChartPro.js +2 -0
- package/PieChartPro/PieChartPro.plugins.d.ts +2 -2
- package/PieChartPro/index.d.ts +2 -1
- package/PieChartPro/index.js +11 -0
- package/RadarChartPro/RadarChartPro.d.ts +2 -2
- package/RadarChartPro/RadarChartPro.plugins.d.ts +2 -2
- package/RadarChartPro/index.d.ts +2 -1
- package/RadarChartPro/index.js +11 -0
- package/SankeyChart/SankeyChart.d.ts +2 -2
- package/SankeyChart/SankeyChart.js +4 -1
- package/SankeyChart/SankeyChart.plugins.d.ts +3 -2
- package/SankeyChart/SankeyChart.plugins.js +2 -4
- package/SankeyChart/SankeyLinkLabel.js +12 -1
- package/SankeyChart/calculateSankeyLayout.js +8 -2
- package/SankeyChart/sankey.types.d.ts +55 -5
- package/SankeyChart/seriesConfig/getSeriesWithDefaultValues.js +2 -0
- package/SankeyChart/seriesConfig/tooltipGetter.js +13 -3
- package/SankeyChart/useSankeyChartProps.d.ts +2 -2
- package/SankeyChart/useSankeyChartProps.js +4 -3
- package/ScatterChartPro/ScatterChartPro.d.ts +2 -2
- package/ScatterChartPro/ScatterChartPro.js +13 -2
- package/ScatterChartPro/ScatterChartPro.plugins.d.ts +3 -3
- package/ScatterChartPro/ScatterChartPro.plugins.js +1 -1
- package/ScatterChartPro/index.d.ts +2 -1
- package/ScatterChartPro/index.js +11 -0
- package/context/ChartProApi.d.ts +14 -12
- package/esm/BarChartPro/BarChartPro.d.ts +2 -2
- package/esm/BarChartPro/BarChartPro.js +1 -0
- package/esm/BarChartPro/BarChartPro.plugins.d.ts +3 -3
- package/esm/BarChartPro/BarChartPro.plugins.js +2 -2
- package/esm/BarChartPro/index.d.ts +2 -1
- package/esm/BarChartPro/index.js +2 -1
- package/esm/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
- package/esm/ChartZoomSlider/internals/ChartAxisZoomSliderThumb.js +2 -2
- package/esm/FunnelChart/FunnelChart.d.ts +2 -2
- package/esm/FunnelChart/FunnelChart.plugins.d.ts +2 -2
- package/esm/FunnelChart/FunnelPlot.js +3 -3
- package/esm/FunnelChart/funnelAxisPlugin/computeAxisValue.js +2 -2
- package/esm/FunnelChart/index.d.ts +1 -0
- package/esm/FunnelChart/index.js +1 -0
- package/esm/FunnelChart/useFunnelChartProps.d.ts +2 -2
- package/esm/FunnelChart/useFunnelChartProps.js +4 -3
- package/esm/Heatmap/Heatmap.d.ts +2 -2
- package/esm/Heatmap/Heatmap.js +2 -1
- package/esm/Heatmap/Heatmap.plugins.d.ts +2 -2
- package/esm/Heatmap/index.d.ts +1 -0
- package/esm/Heatmap/index.js +1 -0
- package/esm/LineChartPro/LineChartPro.d.ts +2 -2
- package/esm/LineChartPro/LineChartPro.js +1 -0
- package/esm/LineChartPro/LineChartPro.plugins.d.ts +3 -3
- package/esm/LineChartPro/LineChartPro.plugins.js +2 -2
- package/esm/LineChartPro/index.d.ts +2 -1
- package/esm/LineChartPro/index.js +2 -1
- package/esm/PieChartPro/PieChartPro.js +2 -0
- package/esm/PieChartPro/PieChartPro.plugins.d.ts +2 -2
- package/esm/PieChartPro/index.d.ts +2 -1
- package/esm/PieChartPro/index.js +2 -1
- package/esm/RadarChartPro/RadarChartPro.d.ts +2 -2
- package/esm/RadarChartPro/RadarChartPro.plugins.d.ts +2 -2
- package/esm/RadarChartPro/index.d.ts +2 -1
- package/esm/RadarChartPro/index.js +2 -1
- package/esm/SankeyChart/SankeyChart.d.ts +2 -2
- package/esm/SankeyChart/SankeyChart.js +4 -1
- package/esm/SankeyChart/SankeyChart.plugins.d.ts +3 -2
- package/esm/SankeyChart/SankeyChart.plugins.js +2 -6
- package/esm/SankeyChart/SankeyLinkLabel.js +12 -1
- package/esm/SankeyChart/calculateSankeyLayout.js +8 -2
- package/esm/SankeyChart/sankey.types.d.ts +55 -5
- package/esm/SankeyChart/seriesConfig/getSeriesWithDefaultValues.js +2 -0
- package/esm/SankeyChart/seriesConfig/tooltipGetter.js +13 -3
- package/esm/SankeyChart/useSankeyChartProps.d.ts +2 -2
- package/esm/SankeyChart/useSankeyChartProps.js +4 -3
- package/esm/ScatterChartPro/ScatterChartPro.d.ts +2 -2
- package/esm/ScatterChartPro/ScatterChartPro.js +13 -2
- package/esm/ScatterChartPro/ScatterChartPro.plugins.d.ts +3 -3
- package/esm/ScatterChartPro/ScatterChartPro.plugins.js +2 -2
- package/esm/ScatterChartPro/index.d.ts +2 -1
- package/esm/ScatterChartPro/index.js +2 -1
- package/esm/context/ChartProApi.d.ts +14 -12
- package/esm/index.d.ts +1 -0
- package/esm/index.js +2 -1
- package/esm/internals/material/components/BasePopper.js +2 -2
- package/esm/internals/plugins/useChartProExport/common.d.ts +5 -1
- package/esm/internals/plugins/useChartProExport/common.js +13 -0
- package/esm/internals/plugins/useChartProExport/exportImage.d.ts +1 -1
- package/esm/internals/plugins/useChartProExport/exportImage.js +23 -17
- package/esm/internals/plugins/useChartProExport/print.js +2 -3
- package/esm/internals/plugins/useChartProExport/useChartProExport.js +4 -2
- package/esm/internals/plugins/useChartProExport/useChartProExport.types.d.ts +1 -2
- package/esm/plugins/index.d.ts +3 -0
- package/esm/plugins/index.js +3 -0
- package/index.d.ts +1 -0
- package/index.js +13 -1
- package/internals/material/components/BasePopper.js +2 -2
- package/internals/plugins/useChartProExport/common.d.ts +5 -1
- package/internals/plugins/useChartProExport/common.js +14 -0
- package/internals/plugins/useChartProExport/exportImage.d.ts +1 -1
- package/internals/plugins/useChartProExport/exportImage.js +22 -16
- package/internals/plugins/useChartProExport/print.js +2 -3
- package/internals/plugins/useChartProExport/useChartProExport.js +4 -2
- package/internals/plugins/useChartProExport/useChartProExport.types.d.ts +1 -2
- package/package.json +6 -6
- package/plugins/index.d.ts +3 -0
- package/plugins/index.js +35 -0
|
@@ -127,6 +127,7 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
127
127
|
* @default false
|
|
128
128
|
*/
|
|
129
129
|
disableVoronoi: PropTypes.bool,
|
|
130
|
+
enableKeyboardNavigation: PropTypes.bool,
|
|
130
131
|
/**
|
|
131
132
|
* Option to display a cartesian grid in the background.
|
|
132
133
|
*/
|
|
@@ -210,6 +211,15 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
210
211
|
* @param {ZoomData[]} zoomData Updated zoom data.
|
|
211
212
|
*/
|
|
212
213
|
onZoomChange: PropTypes.func,
|
|
214
|
+
/**
|
|
215
|
+
* The type of renderer to use for the scatter plot.
|
|
216
|
+
* - `svg-single`: Renders every scatter item in a `<circle />` element.
|
|
217
|
+
* - `svg-batch`: Batch renders scatter items in `<path />` elements for better performance with large datasets, at the cost of some limitations.
|
|
218
|
+
* Read more: https://mui.com/x/react-charts/scatter/#performance
|
|
219
|
+
*
|
|
220
|
+
* @default 'svg-single'
|
|
221
|
+
*/
|
|
222
|
+
renderer: PropTypes.oneOf(['svg-batch', 'svg-single']),
|
|
213
223
|
/**
|
|
214
224
|
* The series to display in the scatter chart.
|
|
215
225
|
* An array of [[ScatterSeries]] objects.
|
|
@@ -239,10 +249,11 @@ process.env.NODE_ENV !== "production" ? ScatterChartPro.propTypes = {
|
|
|
239
249
|
theme: PropTypes.oneOf(['dark', 'light']),
|
|
240
250
|
title: PropTypes.string,
|
|
241
251
|
/**
|
|
242
|
-
* Defines the
|
|
252
|
+
* Defines the maximum distance between a scatter point and the pointer that triggers the interaction.
|
|
253
|
+
* If set to `'item'`, the radius is the `markerSize`.
|
|
243
254
|
* If `undefined`, the radius is assumed to be infinite.
|
|
244
255
|
*/
|
|
245
|
-
voronoiMaxRadius: PropTypes.number,
|
|
256
|
+
voronoiMaxRadius: PropTypes.oneOfType([PropTypes.oneOf(['item']), PropTypes.number]),
|
|
246
257
|
/**
|
|
247
258
|
* The width of the chart in px. If not defined, it takes the width of the parent element.
|
|
248
259
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UseChartZAxisSignature, UseChartCartesianAxisSignature, UseChartInteractionSignature, UseChartHighlightSignature,
|
|
1
|
+
import { UseChartZAxisSignature, UseChartCartesianAxisSignature, UseChartInteractionSignature, UseChartHighlightSignature, UseChartClosestPointSignature, UseChartKeyboardNavigationSignature, ConvertSignaturesIntoPlugins } from '@mui/x-charts/internals';
|
|
2
2
|
import { UseChartProExportSignature } from "../internals/plugins/useChartProExport/index.js";
|
|
3
3
|
import { UseChartProZoomSignature } from "../internals/plugins/useChartProZoom/index.js";
|
|
4
|
-
export type
|
|
5
|
-
export declare const SCATTER_CHART_PRO_PLUGINS: ConvertSignaturesIntoPlugins<
|
|
4
|
+
export type ScatterChartProPluginSignatures = [UseChartZAxisSignature, UseChartCartesianAxisSignature<'scatter'>, UseChartInteractionSignature, UseChartHighlightSignature, UseChartClosestPointSignature, UseChartKeyboardNavigationSignature, UseChartProZoomSignature, UseChartProExportSignature];
|
|
5
|
+
export declare const SCATTER_CHART_PRO_PLUGINS: ConvertSignaturesIntoPlugins<ScatterChartProPluginSignatures>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight,
|
|
1
|
+
import { useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartClosestPoint, useChartKeyboardNavigation } from '@mui/x-charts/internals';
|
|
2
2
|
import { useChartProExport } from "../internals/plugins/useChartProExport/index.js";
|
|
3
3
|
import { useChartProZoom } from "../internals/plugins/useChartProZoom/index.js";
|
|
4
|
-
export const SCATTER_CHART_PRO_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight,
|
|
4
|
+
export const SCATTER_CHART_PRO_PLUGINS = [useChartZAxis, useChartCartesianAxis, useChartInteraction, useChartHighlight, useChartClosestPoint, useChartKeyboardNavigation, useChartProZoom, useChartProExport];
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./ScatterChartPro.js";
|
|
1
|
+
export * from "./ScatterChartPro.js";
|
|
2
|
+
export * from "./ScatterChartPro.plugins.js";
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./ScatterChartPro.js";
|
|
1
|
+
export * from "./ScatterChartPro.js";
|
|
2
|
+
export * from "./ScatterChartPro.plugins.js";
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { ChartAnyPluginSignature, ChartPublicAPI } from '@mui/x-charts/internals';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { HeatmapPluginSignatures } from "../Heatmap/Heatmap.plugins.js";
|
|
3
|
+
import { LineChartProPluginSignatures } from "../LineChartPro/LineChartPro.plugins.js";
|
|
4
|
+
import { ScatterChartProPluginSignatures } from "../ScatterChartPro/ScatterChartPro.plugins.js";
|
|
5
|
+
import { BarChartProPluginSignatures } from "../BarChartPro/BarChartPro.plugins.js";
|
|
6
6
|
import { AllPluginSignatures, DefaultPluginSignatures } from "../internals/plugins/allPlugins.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { FunnelChartPluginSignatures } from "../FunnelChart/FunnelChart.plugins.js";
|
|
8
|
+
import { RadarChartProPluginSignatures } from "../RadarChartPro/RadarChartPro.plugins.js";
|
|
9
9
|
import { PieChartProPluginSignatures } from "../PieChartPro/PieChartPro.plugins.js";
|
|
10
|
+
import { SankeyChartPluginSignatures } from "../SankeyChart/SankeyChart.plugins.js";
|
|
10
11
|
export type ProPluginsPerSeriesType = {
|
|
11
|
-
heatmap:
|
|
12
|
-
line:
|
|
13
|
-
scatter:
|
|
14
|
-
bar:
|
|
15
|
-
funnel:
|
|
16
|
-
radar:
|
|
12
|
+
heatmap: HeatmapPluginSignatures;
|
|
13
|
+
line: LineChartProPluginSignatures;
|
|
14
|
+
scatter: ScatterChartProPluginSignatures;
|
|
15
|
+
bar: BarChartProPluginSignatures;
|
|
16
|
+
funnel: FunnelChartPluginSignatures;
|
|
17
|
+
radar: RadarChartProPluginSignatures;
|
|
17
18
|
pie: PieChartProPluginSignatures;
|
|
19
|
+
sankey: SankeyChartPluginSignatures;
|
|
18
20
|
composition: DefaultPluginSignatures;
|
|
19
21
|
};
|
|
20
22
|
/**
|
package/esm/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export * from "./constants/index.js";
|
|
|
26
26
|
export * from "./hooks/index.js";
|
|
27
27
|
export * from "./context/index.js";
|
|
28
28
|
export * from "./models/index.js";
|
|
29
|
+
export * from "./plugins/index.js";
|
|
29
30
|
export * from "./colorPalettes/index.js";
|
|
30
31
|
export * from "./Heatmap/index.js";
|
|
31
32
|
export { ChartContainerPro } from "./ChartContainerPro/index.js";
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-charts-pro v8.
|
|
2
|
+
* @mui/x-charts-pro v8.12.0
|
|
3
3
|
*
|
|
4
4
|
* @license SEE LICENSE IN LICENSE
|
|
5
5
|
* This source code is licensed under the SEE LICENSE IN LICENSE license found in the
|
|
@@ -37,6 +37,7 @@ export * from "./constants/index.js";
|
|
|
37
37
|
export * from "./hooks/index.js";
|
|
38
38
|
export * from "./context/index.js";
|
|
39
39
|
export * from "./models/index.js";
|
|
40
|
+
export * from "./plugins/index.js";
|
|
40
41
|
// Locales should be imported from `@mui/x-charts-pro/locales`
|
|
41
42
|
// export * from './locales';
|
|
42
43
|
export * from "./colorPalettes/index.js";
|
|
@@ -54,7 +54,7 @@ export function BasePopper(props) {
|
|
|
54
54
|
transition,
|
|
55
55
|
placement
|
|
56
56
|
} = props,
|
|
57
|
-
|
|
57
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
58
58
|
const modifiers = React.useMemo(() => {
|
|
59
59
|
const result = [{
|
|
60
60
|
name: 'preventOverflow',
|
|
@@ -116,7 +116,7 @@ export function BasePopper(props) {
|
|
|
116
116
|
transition: transition,
|
|
117
117
|
placement: placement,
|
|
118
118
|
modifiers: modifiers
|
|
119
|
-
},
|
|
119
|
+
}, other, {
|
|
120
120
|
children: content
|
|
121
121
|
}));
|
|
122
122
|
}
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export declare function createExportIframe(title?: string): HTMLIFrameElement;
|
|
1
|
+
export declare function createExportIframe(title?: string): HTMLIFrameElement;
|
|
2
|
+
/**
|
|
3
|
+
* Applies styles to an element and returns the previous styles.
|
|
4
|
+
*/
|
|
5
|
+
export declare function applyStyles(element: HTMLElement | SVGElement, styles: Record<string, string | null>): Record<string, string | null>;
|
|
@@ -5,4 +5,17 @@ export function createExportIframe(title) {
|
|
|
5
5
|
iframeEl.style.height = '0px';
|
|
6
6
|
iframeEl.title = title || document.title;
|
|
7
7
|
return iframeEl;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Applies styles to an element and returns the previous styles.
|
|
12
|
+
*/
|
|
13
|
+
export function applyStyles(element, styles) {
|
|
14
|
+
const previousStyles = {};
|
|
15
|
+
Object.entries(styles).forEach(([key, value]) => {
|
|
16
|
+
const prev = element.style.getPropertyValue(key);
|
|
17
|
+
previousStyles[key] = prev;
|
|
18
|
+
element.style.setProperty(key, value);
|
|
19
|
+
});
|
|
20
|
+
return previousStyles;
|
|
8
21
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ChartImageExportOptions } from "./useChartProExport.types.js";
|
|
2
2
|
export declare const getDrawDocument: () => Promise<typeof import("rasterizehtml").drawDocument>;
|
|
3
|
-
export declare function exportImage(element: HTMLElement | SVGElement, params?: ChartImageExportOptions): Promise<void>;
|
|
3
|
+
export declare function exportImage(element: HTMLElement | SVGElement, svg: SVGElement, params?: ChartImageExportOptions): Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ownerDocument from '@mui/utils/ownerDocument';
|
|
2
2
|
import { loadStyleSheets } from '@mui/x-internals/export';
|
|
3
|
-
import { createExportIframe } from "./common.js";
|
|
3
|
+
import { applyStyles, createExportIframe } from "./common.js";
|
|
4
4
|
import { defaultOnBeforeExport } from "./defaults.js";
|
|
5
5
|
export const getDrawDocument = async () => {
|
|
6
6
|
try {
|
|
@@ -12,7 +12,7 @@ export const getDrawDocument = async () => {
|
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
-
export async function exportImage(element, params) {
|
|
15
|
+
export async function exportImage(element, svg, params) {
|
|
16
16
|
const {
|
|
17
17
|
fileName,
|
|
18
18
|
type = 'image/png',
|
|
@@ -21,18 +21,14 @@ export async function exportImage(element, params) {
|
|
|
21
21
|
copyStyles = true
|
|
22
22
|
} = params ?? {};
|
|
23
23
|
const drawDocumentPromise = getDrawDocument();
|
|
24
|
-
const {
|
|
25
|
-
width,
|
|
26
|
-
height
|
|
27
|
-
} = element.getBoundingClientRect();
|
|
28
24
|
const doc = ownerDocument(element);
|
|
29
|
-
const canvas = document.createElement('canvas');
|
|
30
|
-
const ratio = window.devicePixelRatio || 1;
|
|
31
|
-
canvas.width = width * ratio;
|
|
32
|
-
canvas.height = height * ratio;
|
|
33
|
-
canvas.style.width = `${width}px`;
|
|
34
|
-
canvas.style.height = `${height}px`;
|
|
35
25
|
const iframe = createExportIframe(fileName);
|
|
26
|
+
/* We apply the min/max width and height to ensure the SVG doesn't resize in the export.
|
|
27
|
+
* We apply to the original SVG so that the cloned tree will contain the styles and revert these
|
|
28
|
+
* styles changes after the chart is cloned. */
|
|
29
|
+
const previousStyles = applyStyles(svg, {
|
|
30
|
+
width: `${svg.getBoundingClientRect().width}px`
|
|
31
|
+
});
|
|
36
32
|
let resolve;
|
|
37
33
|
const iframeLoadPromise = new Promise(res => {
|
|
38
34
|
resolve = res;
|
|
@@ -40,10 +36,12 @@ export async function exportImage(element, params) {
|
|
|
40
36
|
iframe.onload = async () => {
|
|
41
37
|
const exportDoc = iframe.contentDocument;
|
|
42
38
|
const elementClone = element.cloneNode(true);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
exportDoc.body.innerHTML = container.innerHTML;
|
|
39
|
+
applyStyles(svg, previousStyles);
|
|
40
|
+
exportDoc.body.replaceChildren(elementClone);
|
|
46
41
|
exportDoc.body.style.margin = '0px';
|
|
42
|
+
/* The body's parent has a width of 0, so we use fit-content to ensure that the body adjusts its width to the width
|
|
43
|
+
* of its children. */
|
|
44
|
+
exportDoc.body.style.width = 'fit-content';
|
|
47
45
|
const rootCandidate = element.getRootNode();
|
|
48
46
|
const root = rootCandidate.constructor.name === 'ShadowRoot' ? rootCandidate : doc;
|
|
49
47
|
if (copyStyles) {
|
|
@@ -55,6 +53,15 @@ export async function exportImage(element, params) {
|
|
|
55
53
|
await iframeLoadPromise;
|
|
56
54
|
await onBeforeExport(iframe);
|
|
57
55
|
const drawDocument = await drawDocumentPromise;
|
|
56
|
+
|
|
57
|
+
/* Use the size from the export body in case `onBeforeExport` adds some elements that should be in the export. */
|
|
58
|
+
const exportDocBodySize = iframe.contentDocument.body.getBoundingClientRect();
|
|
59
|
+
const canvas = document.createElement('canvas');
|
|
60
|
+
const ratio = window.devicePixelRatio || 1;
|
|
61
|
+
canvas.width = exportDocBodySize.width * ratio;
|
|
62
|
+
canvas.height = exportDocBodySize.height * ratio;
|
|
63
|
+
canvas.style.width = `${exportDocBodySize.width}px`;
|
|
64
|
+
canvas.style.height = `${exportDocBodySize.height}px`;
|
|
58
65
|
try {
|
|
59
66
|
await drawDocument(iframe.contentDocument, canvas, {
|
|
60
67
|
// Handle retina displays: https://github.com/cburgmer/rasterizeHTML.js/blob/262b3404d1c469ce4a7750a2976dec09b8ae2d6c/examples/retina.html#L71
|
|
@@ -67,9 +74,9 @@ export async function exportImage(element, params) {
|
|
|
67
74
|
const blobPromise = new Promise(res => {
|
|
68
75
|
resolveBlobPromise = res;
|
|
69
76
|
});
|
|
70
|
-
canvas.toBlob(blob => resolveBlobPromise(blob), type, quality);
|
|
71
77
|
let blob;
|
|
72
78
|
try {
|
|
79
|
+
canvas.toBlob(b => resolveBlobPromise(b), type, quality);
|
|
73
80
|
blob = await blobPromise;
|
|
74
81
|
} catch (error) {
|
|
75
82
|
throw new Error('MUI X Charts: Failed to create blob from canvas.', {
|
|
@@ -78,7 +85,6 @@ export async function exportImage(element, params) {
|
|
|
78
85
|
}
|
|
79
86
|
if (!blob) {
|
|
80
87
|
throw new Error('MUI X Charts: Failed to create blob from canvas.');
|
|
81
|
-
return;
|
|
82
88
|
}
|
|
83
89
|
const url = URL.createObjectURL(blob);
|
|
84
90
|
triggerDownload(url, fileName || document.title);
|
|
@@ -12,9 +12,8 @@ export function printChart(element, {
|
|
|
12
12
|
printWindow.onload = async () => {
|
|
13
13
|
const printDoc = printWindow.contentDocument;
|
|
14
14
|
const elementClone = element.cloneNode(true);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
printDoc.body.innerHTML = container.innerHTML;
|
|
15
|
+
printDoc.body.replaceChildren(elementClone);
|
|
16
|
+
printDoc.body.style.margin = '0px';
|
|
18
17
|
const rootCandidate = element.getRootNode();
|
|
19
18
|
const root = rootCandidate.constructor.name === 'ShadowRoot' ? rootCandidate : doc;
|
|
20
19
|
if (copyStyles) {
|
|
@@ -13,6 +13,7 @@ function waitForAnimationFrame() {
|
|
|
13
13
|
}
|
|
14
14
|
export const useChartProExport = ({
|
|
15
15
|
chartRootRef,
|
|
16
|
+
svgRef,
|
|
16
17
|
instance
|
|
17
18
|
}) => {
|
|
18
19
|
const exportAsPrint = async options => {
|
|
@@ -32,12 +33,13 @@ export const useChartProExport = ({
|
|
|
32
33
|
};
|
|
33
34
|
const exportAsImage = async options => {
|
|
34
35
|
const chartRoot = chartRootRef.current;
|
|
35
|
-
|
|
36
|
+
const svg = svgRef.current;
|
|
37
|
+
if (chartRoot && svg) {
|
|
36
38
|
const enableAnimation = instance.disableAnimation();
|
|
37
39
|
try {
|
|
38
40
|
// Wait for animation frame to ensure the animation finished
|
|
39
41
|
await waitForAnimationFrame();
|
|
40
|
-
await exportImage(chartRoot, options);
|
|
42
|
+
await exportImage(chartRoot, svg, options);
|
|
41
43
|
} catch (error) {
|
|
42
44
|
console.error('MUI X Charts: Error exporting chart as image:', error);
|
|
43
45
|
} finally {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChartPluginSignature } from '@mui/x-charts/internals';
|
|
2
2
|
export interface UseChartProExportParameters {}
|
|
3
3
|
export type UseChartProExportDefaultizedParameters = UseChartProExportParameters;
|
|
4
4
|
export interface UseChartProExportState {
|
|
@@ -74,5 +74,4 @@ export type UseChartProExportSignature = ChartPluginSignature<{
|
|
|
74
74
|
state: UseChartProExportState;
|
|
75
75
|
publicAPI: UseChartProExportPublicApi;
|
|
76
76
|
instance: UseChartProExportInstance;
|
|
77
|
-
dependencies: [UseChartSeriesSignature, UseChartCartesianAxisSignature];
|
|
78
77
|
}>;
|
package/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export * from "./constants/index.js";
|
|
|
26
26
|
export * from "./hooks/index.js";
|
|
27
27
|
export * from "./context/index.js";
|
|
28
28
|
export * from "./models/index.js";
|
|
29
|
+
export * from "./plugins/index.js";
|
|
29
30
|
export * from "./colorPalettes/index.js";
|
|
30
31
|
export * from "./Heatmap/index.js";
|
|
31
32
|
export { ChartContainerPro } from "./ChartContainerPro/index.js";
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-charts-pro v8.
|
|
2
|
+
* @mui/x-charts-pro v8.12.0
|
|
3
3
|
*
|
|
4
4
|
* @license SEE LICENSE IN LICENSE
|
|
5
5
|
* This source code is licensed under the SEE LICENSE IN LICENSE license found in the
|
|
@@ -344,6 +344,18 @@ Object.keys(_models).forEach(function (key) {
|
|
|
344
344
|
}
|
|
345
345
|
});
|
|
346
346
|
});
|
|
347
|
+
var _plugins = require("./plugins");
|
|
348
|
+
Object.keys(_plugins).forEach(function (key) {
|
|
349
|
+
if (key === "default" || key === "__esModule") return;
|
|
350
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
351
|
+
if (key in exports && exports[key] === _plugins[key]) return;
|
|
352
|
+
Object.defineProperty(exports, key, {
|
|
353
|
+
enumerable: true,
|
|
354
|
+
get: function () {
|
|
355
|
+
return _plugins[key];
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
});
|
|
347
359
|
var _colorPalettes = require("./colorPalettes");
|
|
348
360
|
Object.keys(_colorPalettes).forEach(function (key) {
|
|
349
361
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -62,7 +62,7 @@ function BasePopper(props) {
|
|
|
62
62
|
transition,
|
|
63
63
|
placement
|
|
64
64
|
} = props,
|
|
65
|
-
|
|
65
|
+
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
66
66
|
const modifiers = React.useMemo(() => {
|
|
67
67
|
const result = [{
|
|
68
68
|
name: 'preventOverflow',
|
|
@@ -124,7 +124,7 @@ function BasePopper(props) {
|
|
|
124
124
|
transition: transition,
|
|
125
125
|
placement: placement,
|
|
126
126
|
modifiers: modifiers
|
|
127
|
-
},
|
|
127
|
+
}, other, {
|
|
128
128
|
children: content
|
|
129
129
|
}));
|
|
130
130
|
}
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export declare function createExportIframe(title?: string): HTMLIFrameElement;
|
|
1
|
+
export declare function createExportIframe(title?: string): HTMLIFrameElement;
|
|
2
|
+
/**
|
|
3
|
+
* Applies styles to an element and returns the previous styles.
|
|
4
|
+
*/
|
|
5
|
+
export declare function applyStyles(element: HTMLElement | SVGElement, styles: Record<string, string | null>): Record<string, string | null>;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.applyStyles = applyStyles;
|
|
6
7
|
exports.createExportIframe = createExportIframe;
|
|
7
8
|
function createExportIframe(title) {
|
|
8
9
|
const iframeEl = document.createElement('iframe');
|
|
@@ -11,4 +12,17 @@ function createExportIframe(title) {
|
|
|
11
12
|
iframeEl.style.height = '0px';
|
|
12
13
|
iframeEl.title = title || document.title;
|
|
13
14
|
return iframeEl;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Applies styles to an element and returns the previous styles.
|
|
19
|
+
*/
|
|
20
|
+
function applyStyles(element, styles) {
|
|
21
|
+
const previousStyles = {};
|
|
22
|
+
Object.entries(styles).forEach(([key, value]) => {
|
|
23
|
+
const prev = element.style.getPropertyValue(key);
|
|
24
|
+
previousStyles[key] = prev;
|
|
25
|
+
element.style.setProperty(key, value);
|
|
26
|
+
});
|
|
27
|
+
return previousStyles;
|
|
14
28
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ChartImageExportOptions } from "./useChartProExport.types.js";
|
|
2
2
|
export declare const getDrawDocument: () => Promise<typeof import("rasterizehtml").drawDocument>;
|
|
3
|
-
export declare function exportImage(element: HTMLElement | SVGElement, params?: ChartImageExportOptions): Promise<void>;
|
|
3
|
+
export declare function exportImage(element: HTMLElement | SVGElement, svg: SVGElement, params?: ChartImageExportOptions): Promise<void>;
|
|
@@ -22,7 +22,7 @@ const getDrawDocument = async () => {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
exports.getDrawDocument = getDrawDocument;
|
|
25
|
-
async function exportImage(element, params) {
|
|
25
|
+
async function exportImage(element, svg, params) {
|
|
26
26
|
const {
|
|
27
27
|
fileName,
|
|
28
28
|
type = 'image/png',
|
|
@@ -31,18 +31,14 @@ async function exportImage(element, params) {
|
|
|
31
31
|
copyStyles = true
|
|
32
32
|
} = params ?? {};
|
|
33
33
|
const drawDocumentPromise = getDrawDocument();
|
|
34
|
-
const {
|
|
35
|
-
width,
|
|
36
|
-
height
|
|
37
|
-
} = element.getBoundingClientRect();
|
|
38
34
|
const doc = (0, _ownerDocument.default)(element);
|
|
39
|
-
const canvas = document.createElement('canvas');
|
|
40
|
-
const ratio = window.devicePixelRatio || 1;
|
|
41
|
-
canvas.width = width * ratio;
|
|
42
|
-
canvas.height = height * ratio;
|
|
43
|
-
canvas.style.width = `${width}px`;
|
|
44
|
-
canvas.style.height = `${height}px`;
|
|
45
35
|
const iframe = (0, _common.createExportIframe)(fileName);
|
|
36
|
+
/* We apply the min/max width and height to ensure the SVG doesn't resize in the export.
|
|
37
|
+
* We apply to the original SVG so that the cloned tree will contain the styles and revert these
|
|
38
|
+
* styles changes after the chart is cloned. */
|
|
39
|
+
const previousStyles = (0, _common.applyStyles)(svg, {
|
|
40
|
+
width: `${svg.getBoundingClientRect().width}px`
|
|
41
|
+
});
|
|
46
42
|
let resolve;
|
|
47
43
|
const iframeLoadPromise = new Promise(res => {
|
|
48
44
|
resolve = res;
|
|
@@ -50,10 +46,12 @@ async function exportImage(element, params) {
|
|
|
50
46
|
iframe.onload = async () => {
|
|
51
47
|
const exportDoc = iframe.contentDocument;
|
|
52
48
|
const elementClone = element.cloneNode(true);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
exportDoc.body.innerHTML = container.innerHTML;
|
|
49
|
+
(0, _common.applyStyles)(svg, previousStyles);
|
|
50
|
+
exportDoc.body.replaceChildren(elementClone);
|
|
56
51
|
exportDoc.body.style.margin = '0px';
|
|
52
|
+
/* The body's parent has a width of 0, so we use fit-content to ensure that the body adjusts its width to the width
|
|
53
|
+
* of its children. */
|
|
54
|
+
exportDoc.body.style.width = 'fit-content';
|
|
57
55
|
const rootCandidate = element.getRootNode();
|
|
58
56
|
const root = rootCandidate.constructor.name === 'ShadowRoot' ? rootCandidate : doc;
|
|
59
57
|
if (copyStyles) {
|
|
@@ -65,6 +63,15 @@ async function exportImage(element, params) {
|
|
|
65
63
|
await iframeLoadPromise;
|
|
66
64
|
await onBeforeExport(iframe);
|
|
67
65
|
const drawDocument = await drawDocumentPromise;
|
|
66
|
+
|
|
67
|
+
/* Use the size from the export body in case `onBeforeExport` adds some elements that should be in the export. */
|
|
68
|
+
const exportDocBodySize = iframe.contentDocument.body.getBoundingClientRect();
|
|
69
|
+
const canvas = document.createElement('canvas');
|
|
70
|
+
const ratio = window.devicePixelRatio || 1;
|
|
71
|
+
canvas.width = exportDocBodySize.width * ratio;
|
|
72
|
+
canvas.height = exportDocBodySize.height * ratio;
|
|
73
|
+
canvas.style.width = `${exportDocBodySize.width}px`;
|
|
74
|
+
canvas.style.height = `${exportDocBodySize.height}px`;
|
|
68
75
|
try {
|
|
69
76
|
await drawDocument(iframe.contentDocument, canvas, {
|
|
70
77
|
// Handle retina displays: https://github.com/cburgmer/rasterizeHTML.js/blob/262b3404d1c469ce4a7750a2976dec09b8ae2d6c/examples/retina.html#L71
|
|
@@ -77,9 +84,9 @@ async function exportImage(element, params) {
|
|
|
77
84
|
const blobPromise = new Promise(res => {
|
|
78
85
|
resolveBlobPromise = res;
|
|
79
86
|
});
|
|
80
|
-
canvas.toBlob(blob => resolveBlobPromise(blob), type, quality);
|
|
81
87
|
let blob;
|
|
82
88
|
try {
|
|
89
|
+
canvas.toBlob(b => resolveBlobPromise(b), type, quality);
|
|
83
90
|
blob = await blobPromise;
|
|
84
91
|
} catch (error) {
|
|
85
92
|
throw new Error('MUI X Charts: Failed to create blob from canvas.', {
|
|
@@ -88,7 +95,6 @@ async function exportImage(element, params) {
|
|
|
88
95
|
}
|
|
89
96
|
if (!blob) {
|
|
90
97
|
throw new Error('MUI X Charts: Failed to create blob from canvas.');
|
|
91
|
-
return;
|
|
92
98
|
}
|
|
93
99
|
const url = URL.createObjectURL(blob);
|
|
94
100
|
triggerDownload(url, fileName || document.title);
|
|
@@ -19,9 +19,8 @@ function printChart(element, {
|
|
|
19
19
|
printWindow.onload = async () => {
|
|
20
20
|
const printDoc = printWindow.contentDocument;
|
|
21
21
|
const elementClone = element.cloneNode(true);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
printDoc.body.innerHTML = container.innerHTML;
|
|
22
|
+
printDoc.body.replaceChildren(elementClone);
|
|
23
|
+
printDoc.body.style.margin = '0px';
|
|
25
24
|
const rootCandidate = element.getRootNode();
|
|
26
25
|
const root = rootCandidate.constructor.name === 'ShadowRoot' ? rootCandidate : doc;
|
|
27
26
|
if (copyStyles) {
|
|
@@ -20,6 +20,7 @@ function waitForAnimationFrame() {
|
|
|
20
20
|
}
|
|
21
21
|
const useChartProExport = ({
|
|
22
22
|
chartRootRef,
|
|
23
|
+
svgRef,
|
|
23
24
|
instance
|
|
24
25
|
}) => {
|
|
25
26
|
const exportAsPrint = async options => {
|
|
@@ -39,12 +40,13 @@ const useChartProExport = ({
|
|
|
39
40
|
};
|
|
40
41
|
const exportAsImage = async options => {
|
|
41
42
|
const chartRoot = chartRootRef.current;
|
|
42
|
-
|
|
43
|
+
const svg = svgRef.current;
|
|
44
|
+
if (chartRoot && svg) {
|
|
43
45
|
const enableAnimation = instance.disableAnimation();
|
|
44
46
|
try {
|
|
45
47
|
// Wait for animation frame to ensure the animation finished
|
|
46
48
|
await waitForAnimationFrame();
|
|
47
|
-
await (0, _exportImage.exportImage)(chartRoot, options);
|
|
49
|
+
await (0, _exportImage.exportImage)(chartRoot, svg, options);
|
|
48
50
|
} catch (error) {
|
|
49
51
|
console.error('MUI X Charts: Error exporting chart as image:', error);
|
|
50
52
|
} finally {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChartPluginSignature } from '@mui/x-charts/internals';
|
|
2
2
|
export interface UseChartProExportParameters {}
|
|
3
3
|
export type UseChartProExportDefaultizedParameters = UseChartProExportParameters;
|
|
4
4
|
export interface UseChartProExportState {
|
|
@@ -74,5 +74,4 @@ export type UseChartProExportSignature = ChartPluginSignature<{
|
|
|
74
74
|
state: UseChartProExportState;
|
|
75
75
|
publicAPI: UseChartProExportPublicApi;
|
|
76
76
|
instance: UseChartProExportInstance;
|
|
77
|
-
dependencies: [UseChartSeriesSignature, UseChartCartesianAxisSignature];
|
|
78
77
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-charts-pro",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.12.0",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "The Pro plan edition of the MUI X Charts components.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"@mui/utils": "^7.3.2",
|
|
32
32
|
"clsx": "^2.1.1",
|
|
33
33
|
"prop-types": "^15.8.1",
|
|
34
|
-
"@mui/x-charts
|
|
35
|
-
"@mui/x-
|
|
36
|
-
"@mui/x-
|
|
37
|
-
"@mui/x-
|
|
38
|
-
"@mui/x-
|
|
34
|
+
"@mui/x-charts": "8.12.0",
|
|
35
|
+
"@mui/x-charts-vendor": "8.12.0",
|
|
36
|
+
"@mui/x-license": "8.12.0",
|
|
37
|
+
"@mui/x-internal-gestures": "0.3.0",
|
|
38
|
+
"@mui/x-internals": "8.12.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@emotion/react": "^11.9.0",
|
package/plugins/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
useChartProExport: true,
|
|
8
|
+
useChartProZoom: true
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "useChartProExport", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _useChartProExport.useChartProExport;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "useChartProZoom", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _useChartProZoom.useChartProZoom;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
var _plugins = require("@mui/x-charts/plugins");
|
|
23
|
+
Object.keys(_plugins).forEach(function (key) {
|
|
24
|
+
if (key === "default" || key === "__esModule") return;
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
26
|
+
if (key in exports && exports[key] === _plugins[key]) return;
|
|
27
|
+
Object.defineProperty(exports, key, {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () {
|
|
30
|
+
return _plugins[key];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
var _useChartProExport = require("../internals/plugins/useChartProExport");
|
|
35
|
+
var _useChartProZoom = require("../internals/plugins/useChartProZoom");
|