@mui/x-charts-premium 9.7.0 → 9.8.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.
Files changed (100) hide show
  1. package/BarChartPremium/webgl/BarWebGLProgram.d.mts +4 -5
  2. package/BarChartPremium/webgl/BarWebGLProgram.d.ts +4 -5
  3. package/BarChartPremium/webgl/BarWebGLProgram.js +24 -65
  4. package/BarChartPremium/webgl/BarWebGLProgram.mjs +24 -65
  5. package/BarChartPremium/webgl/shaders.d.mts +1 -1
  6. package/BarChartPremium/webgl/shaders.d.ts +1 -1
  7. package/BarChartPremium/webgl/shaders.js +2 -15
  8. package/BarChartPremium/webgl/shaders.mjs +3 -15
  9. package/CHANGELOG.md +130 -1
  10. package/ChartsDataProviderPremium/ChartsDataProviderPremium.js +2 -2
  11. package/ChartsDataProviderPremium/ChartsDataProviderPremium.mjs +2 -2
  12. package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.js +2 -2
  13. package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.mjs +2 -2
  14. package/ChartsRadialDataProviderPremium/ChartsRadialDataProviderPremium.js +2 -2
  15. package/ChartsRadialDataProviderPremium/ChartsRadialDataProviderPremium.mjs +2 -2
  16. package/HeatmapPremium/webgl/HeatmapWebGLProgram.js +12 -37
  17. package/HeatmapPremium/webgl/HeatmapWebGLProgram.mjs +12 -37
  18. package/HeatmapPremium/webgl/shaders.d.mts +3 -3
  19. package/HeatmapPremium/webgl/shaders.d.ts +3 -3
  20. package/HeatmapPremium/webgl/shaders.js +12 -15
  21. package/HeatmapPremium/webgl/shaders.mjs +13 -15
  22. package/HeatmapPremium/webgl/useHeatmapPlotData.js +3 -8
  23. package/HeatmapPremium/webgl/useHeatmapPlotData.mjs +3 -8
  24. package/Map/FocusedMapShape.js +5 -1
  25. package/Map/FocusedMapShape.mjs +5 -1
  26. package/Map/MapImagePlot.d.mts +39 -0
  27. package/Map/MapImagePlot.d.ts +39 -0
  28. package/Map/MapImagePlot.js +138 -0
  29. package/Map/MapImagePlot.mjs +132 -0
  30. package/Map/MapShape.d.mts +1 -1
  31. package/Map/MapShape.d.ts +1 -1
  32. package/Map/MapShape.js +6 -6
  33. package/Map/MapShape.mjs +6 -6
  34. package/Map/MapShapePlot.d.mts +8 -0
  35. package/Map/MapShapePlot.d.ts +8 -0
  36. package/Map/MapShapePlot.js +17 -5
  37. package/Map/MapShapePlot.mjs +17 -5
  38. package/Map/index.d.mts +1 -0
  39. package/Map/index.d.ts +1 -0
  40. package/Map/index.js +11 -0
  41. package/Map/index.mjs +1 -0
  42. package/Map/reprojectEquirectangularImage.d.mts +60 -0
  43. package/Map/reprojectEquirectangularImage.d.ts +60 -0
  44. package/Map/reprojectEquirectangularImage.js +116 -0
  45. package/Map/reprojectEquirectangularImage.mjs +110 -0
  46. package/Map/seriesConfig/descriptionGetter.js +5 -1
  47. package/Map/seriesConfig/descriptionGetter.mjs +5 -1
  48. package/Map/seriesConfig/getColor.js +18 -6
  49. package/Map/seriesConfig/getColor.mjs +18 -6
  50. package/Map/seriesConfig/highlight.d.mts +10 -0
  51. package/Map/seriesConfig/highlight.d.ts +10 -0
  52. package/Map/seriesConfig/highlight.js +52 -0
  53. package/Map/seriesConfig/highlight.mjs +45 -0
  54. package/Map/seriesConfig/identifierCleaner.d.mts +3 -0
  55. package/Map/seriesConfig/identifierCleaner.d.ts +3 -0
  56. package/Map/seriesConfig/identifierCleaner.js +14 -0
  57. package/Map/seriesConfig/identifierCleaner.mjs +8 -0
  58. package/Map/seriesConfig/identifierSerializer.d.mts +3 -0
  59. package/Map/seriesConfig/identifierSerializer.d.ts +3 -0
  60. package/Map/seriesConfig/identifierSerializer.js +12 -0
  61. package/Map/seriesConfig/identifierSerializer.mjs +6 -0
  62. package/Map/seriesConfig/index.js +8 -6
  63. package/Map/seriesConfig/index.mjs +7 -5
  64. package/Map/seriesConfig/keyboardFocusHandler.d.mts +0 -6
  65. package/Map/seriesConfig/keyboardFocusHandler.d.ts +0 -6
  66. package/Map/seriesConfig/keyboardFocusHandler.js +40 -7
  67. package/Map/seriesConfig/keyboardFocusHandler.mjs +41 -8
  68. package/Map/seriesConfig/seriesProcessor.js +11 -2
  69. package/Map/seriesConfig/seriesProcessor.mjs +11 -2
  70. package/Map/seriesConfig/tooltip.js +8 -4
  71. package/Map/seriesConfig/tooltip.mjs +8 -4
  72. package/Map/seriesConfig/tooltipPosition.d.mts +8 -3
  73. package/Map/seriesConfig/tooltipPosition.d.ts +8 -3
  74. package/Map/seriesConfig/tooltipPosition.js +21 -27
  75. package/Map/seriesConfig/tooltipPosition.mjs +22 -27
  76. package/ScatterChartPremium/webgl/ScatterWebGLProgram.d.mts +0 -2
  77. package/ScatterChartPremium/webgl/ScatterWebGLProgram.d.ts +0 -2
  78. package/ScatterChartPremium/webgl/ScatterWebGLProgram.js +23 -81
  79. package/ScatterChartPremium/webgl/ScatterWebGLProgram.mjs +23 -81
  80. package/index.js +1 -1
  81. package/index.mjs +1 -1
  82. package/internals/createGetVisibleCoordinate.d.mts +14 -0
  83. package/internals/createGetVisibleCoordinate.d.ts +14 -0
  84. package/internals/createGetVisibleCoordinate.js +66 -0
  85. package/internals/createGetVisibleCoordinate.mjs +60 -0
  86. package/models/seriesType/mapShape.d.mts +2 -1
  87. package/models/seriesType/mapShape.d.ts +2 -1
  88. package/package.json +5 -5
  89. package/utils/webgl/glsl.d.mts +15 -0
  90. package/utils/webgl/glsl.d.ts +15 -0
  91. package/utils/webgl/glsl.js +34 -0
  92. package/utils/webgl/glsl.mjs +28 -0
  93. package/utils/webgl/instancedAttribute.d.mts +28 -0
  94. package/utils/webgl/instancedAttribute.d.ts +28 -0
  95. package/utils/webgl/instancedAttribute.js +57 -0
  96. package/utils/webgl/instancedAttribute.mjs +50 -0
  97. package/utils/webgl/utils.d.mts +21 -2
  98. package/utils/webgl/utils.d.ts +21 -2
  99. package/utils/webgl/utils.js +44 -8
  100. package/utils/webgl/utils.mjs +41 -7
@@ -0,0 +1,132 @@
1
+ 'use client';
2
+
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
+ const _excluded = ["href", "imageBounds", "onReady"];
6
+ import * as React from 'react';
7
+ import PropTypes from 'prop-types';
8
+ import { useDrawingArea } from '@mui/x-charts/hooks';
9
+ import { useGeoPath } from "../hooks/useGeoPath.mjs";
10
+ import { reprojectEquirectangularImage } from "./reprojectEquirectangularImage.mjs";
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ const FULL_GLOBE = [[-180, -90], [180, 90]];
13
+ /**
14
+ * Renders a raster base map (for example a satellite mosaic) under the series,
15
+ * reprojected to match the chart's `projection` so it follows the geography
16
+ * instead of being a flat rectangle. Pixels outside the projection's visible
17
+ * footprint are left transparent.
18
+ *
19
+ * The source image is loaded only when `href` changes; changing the projection or
20
+ * resizing reuses the decoded image and only re-runs the (synchronous) canvas
21
+ * reprojection.
22
+ *
23
+ * The source image is assumed to be equirectangular; use `imageBounds` when it
24
+ * does not cover the whole globe. Any other SVG image attribute is forwarded to
25
+ * the underlying element.
26
+ */
27
+ function MapImagePlot(props) {
28
+ const {
29
+ href,
30
+ imageBounds,
31
+ onReady
32
+ } = props,
33
+ other = _objectWithoutPropertiesLoose(props, _excluded);
34
+ const path = useGeoPath();
35
+ const {
36
+ left,
37
+ top,
38
+ width,
39
+ height
40
+ } = useDrawingArea();
41
+ const [image, setImage] = React.useState(null);
42
+ const [dataUrl, setDataUrl] = React.useState(null);
43
+ const projection = path?.projection?.();
44
+ const [[west, south], [east, north]] = imageBounds ?? FULL_GLOBE;
45
+
46
+ // Keep the latest `onReady` without making it a reprojection dependency.
47
+ const onReadyRef = React.useRef(onReady);
48
+ React.useEffect(() => {
49
+ onReadyRef.current = onReady;
50
+ });
51
+
52
+ // Load (decode) the source image only when `href` changes. Clearing the image
53
+ // first hides the now-stale raster until the new one is ready.
54
+ React.useEffect(() => {
55
+ setImage(null);
56
+ if (!href) {
57
+ return undefined;
58
+ }
59
+ let cancelled = false;
60
+ const nextImage = new Image();
61
+ nextImage.crossOrigin = 'anonymous';
62
+ nextImage.onload = () => {
63
+ if (!cancelled) {
64
+ setImage(nextImage);
65
+ }
66
+ };
67
+ nextImage.src = href;
68
+ return () => {
69
+ cancelled = true;
70
+ };
71
+ }, [href]);
72
+
73
+ // Reproject whenever the decoded image, projection, drawing area, or bounds
74
+ // change. This is synchronous, so switching projection does not reload `href`.
75
+ React.useEffect(() => {
76
+ if (!image || !projection || typeof projection.invert !== 'function' || width <= 0 || height <= 0) {
77
+ setDataUrl(null);
78
+ onReadyRef.current?.(null);
79
+ return;
80
+ }
81
+ const url = reprojectEquirectangularImage({
82
+ image,
83
+ projection,
84
+ area: {
85
+ left,
86
+ top,
87
+ width,
88
+ height
89
+ },
90
+ imageBounds: [[west, south], [east, north]]
91
+ });
92
+ setDataUrl(url);
93
+ onReadyRef.current?.(url);
94
+ }, [image, projection, left, top, width, height, west, south, east, north]);
95
+ if (!dataUrl) {
96
+ return null;
97
+ }
98
+
99
+ // Spread first so forwarded attributes can't override the computed geometry/href
100
+ // and break the alignment with the projection.
101
+ return /*#__PURE__*/_jsx("image", _extends({}, other, {
102
+ href: dataUrl,
103
+ x: left,
104
+ y: top,
105
+ width: width,
106
+ height: height
107
+ }));
108
+ }
109
+ process.env.NODE_ENV !== "production" ? MapImagePlot.propTypes /* remove-proptypes */ = {
110
+ // ----------------------------- Warning --------------------------------
111
+ // | These PropTypes are generated from the TypeScript type definitions |
112
+ // | To update them edit the TypeScript types and run "pnpm proptypes" |
113
+ // ----------------------------------------------------------------------
114
+ /**
115
+ * URL of the image to render as the base map.
116
+ * Must be same-origin (or CORS-enabled) so it can be reprojected on a canvas.
117
+ */
118
+ href: PropTypes.string,
119
+ /**
120
+ * Geographic extent the source image covers, as `[[west, south], [east, north]]`.
121
+ * The image is assumed to be in the equirectangular (plate carrée) projection.
122
+ * If `west` is greater than `east`, the range wraps across the antimeridian.
123
+ * @default [[-180, -90], [180, 90]]
124
+ */
125
+ imageBounds: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number.isRequired).isRequired),
126
+ /**
127
+ * Called after each reprojection.
128
+ * @param {string | null} dataUrl The reprojected raster as a data URL, or `null` when it could not be produced.
129
+ */
130
+ onReady: PropTypes.func
131
+ } : void 0;
132
+ export { MapImagePlot };
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import type { SeriesId } from '@mui/x-charts/internals';
3
3
  export type MapShapeProps = Omit<React.SVGProps<SVGPathElement>, 'ref'> & {
4
4
  seriesId: SeriesId;
5
- dataIndex: number;
5
+ featureName: string;
6
6
  d: string;
7
7
  color: string;
8
8
  };
package/Map/MapShape.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import type { SeriesId } from '@mui/x-charts/internals';
3
3
  export type MapShapeProps = Omit<React.SVGProps<SVGPathElement>, 'ref'> & {
4
4
  seriesId: SeriesId;
5
- dataIndex: number;
5
+ featureName: string;
6
6
  d: string;
7
7
  color: string;
8
8
  };
package/Map/MapShape.js CHANGED
@@ -15,7 +15,7 @@ var _styles = require("@mui/material/styles");
15
15
  var _internals = require("@mui/x-charts/internals");
16
16
  var _hooks = require("../hooks");
17
17
  var _jsxRuntime = require("react/jsx-runtime");
18
- const _excluded = ["seriesId", "dataIndex", "d", "color", "onClick"];
18
+ const _excluded = ["seriesId", "featureName", "d", "color", "onClick"];
19
19
  const MapShapeRoot = (0, _styles.styled)('path', {
20
20
  name: 'MuiMapShape',
21
21
  slot: 'Root'
@@ -27,7 +27,7 @@ const MapShapeRoot = (0, _styles.styled)('path', {
27
27
  function MapShape(props) {
28
28
  const {
29
29
  seriesId,
30
- dataIndex,
30
+ featureName,
31
31
  d,
32
32
  color,
33
33
  onClick
@@ -36,8 +36,8 @@ function MapShape(props) {
36
36
  const identifier = React.useMemo(() => ({
37
37
  type: 'mapShape',
38
38
  seriesId,
39
- dataIndex
40
- }), [seriesId, dataIndex]);
39
+ name: featureName
40
+ }), [seriesId, featureName]);
41
41
  const interactionProps = (0, _internals.useInteractionItemProps)(identifier);
42
42
  const highlightState = (0, _hooks.useItemHighlightState)(identifier);
43
43
  const isHighlighted = highlightState === 'highlighted';
@@ -47,7 +47,7 @@ function MapShape(props) {
47
47
  fill: color,
48
48
  onClick: onClick,
49
49
  cursor: onClick ? 'pointer' : 'unset',
50
- "data-index": dataIndex,
50
+ "data-name": featureName,
51
51
  "data-highlighted": isHighlighted || undefined,
52
52
  "data-faded": isFaded || undefined,
53
53
  filter: isHighlighted ? 'brightness(120%)' : undefined,
@@ -59,6 +59,6 @@ process.env.NODE_ENV !== "production" ? MapShape.propTypes /* remove-proptypes *
59
59
  // | These PropTypes are generated from the TypeScript type definitions |
60
60
  // | To update them edit the TypeScript types and run "pnpm proptypes" |
61
61
  // ----------------------------------------------------------------------
62
- dataIndex: _propTypes.default.number.isRequired,
62
+ featureName: _propTypes.default.string.isRequired,
63
63
  seriesId: _propTypes.default.string.isRequired
64
64
  } : void 0;
package/Map/MapShape.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["seriesId", "dataIndex", "d", "color", "onClick"];
5
+ const _excluded = ["seriesId", "featureName", "d", "color", "onClick"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import { styled } from '@mui/material/styles';
@@ -20,7 +20,7 @@ const MapShapeRoot = styled('path', {
20
20
  function MapShape(props) {
21
21
  const {
22
22
  seriesId,
23
- dataIndex,
23
+ featureName,
24
24
  d,
25
25
  color,
26
26
  onClick
@@ -29,8 +29,8 @@ function MapShape(props) {
29
29
  const identifier = React.useMemo(() => ({
30
30
  type: 'mapShape',
31
31
  seriesId,
32
- dataIndex
33
- }), [seriesId, dataIndex]);
32
+ name: featureName
33
+ }), [seriesId, featureName]);
34
34
  const interactionProps = useInteractionItemProps(identifier);
35
35
  const highlightState = useItemHighlightState(identifier);
36
36
  const isHighlighted = highlightState === 'highlighted';
@@ -40,7 +40,7 @@ function MapShape(props) {
40
40
  fill: color,
41
41
  onClick: onClick,
42
42
  cursor: onClick ? 'pointer' : 'unset',
43
- "data-index": dataIndex,
43
+ "data-name": featureName,
44
44
  "data-highlighted": isHighlighted || undefined,
45
45
  "data-faded": isFaded || undefined,
46
46
  filter: isHighlighted ? 'brightness(120%)' : undefined,
@@ -52,7 +52,7 @@ process.env.NODE_ENV !== "production" ? MapShape.propTypes /* remove-proptypes *
52
52
  // | These PropTypes are generated from the TypeScript type definitions |
53
53
  // | To update them edit the TypeScript types and run "pnpm proptypes" |
54
54
  // ----------------------------------------------------------------------
55
- dataIndex: PropTypes.number.isRequired,
55
+ featureName: PropTypes.string.isRequired,
56
56
  seriesId: PropTypes.string.isRequired
57
57
  } : void 0;
58
58
  export { MapShape };
@@ -1,4 +1,12 @@
1
+ import * as React from 'react';
2
+ import type { MapShapeItemIdentifier } from "../models/seriesType/mapShape.mjs";
1
3
  export interface MapShapePlotProps {
4
+ /**
5
+ * Callback fired when clicking on a map shape.
6
+ * @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
7
+ * @param {MapShapeItemIdentifier} mapShapeItemIdentifier The identifier of the clicked map shape.
8
+ */
9
+ onItemClick?: (event: React.MouseEvent<SVGPathElement, MouseEvent>, mapShapeItemIdentifier: MapShapeItemIdentifier) => void;
2
10
  className?: string;
3
11
  /**
4
12
  * Fill color applied to every feature path. Overrides item and series colors.
@@ -1,4 +1,12 @@
1
+ import * as React from 'react';
2
+ import type { MapShapeItemIdentifier } from "../models/seriesType/mapShape.js";
1
3
  export interface MapShapePlotProps {
4
+ /**
5
+ * Callback fired when clicking on a map shape.
6
+ * @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
7
+ * @param {MapShapeItemIdentifier} mapShapeItemIdentifier The identifier of the clicked map shape.
8
+ */
9
+ onItemClick?: (event: React.MouseEvent<SVGPathElement, MouseEvent>, mapShapeItemIdentifier: MapShapeItemIdentifier) => void;
2
10
  className?: string;
3
11
  /**
4
12
  * Fill color applied to every feature path. Overrides item and series colors.
@@ -26,7 +26,8 @@ function MapShapePlot(props) {
26
26
  className,
27
27
  fill,
28
28
  stroke = 'none',
29
- strokeWidth = 1
29
+ strokeWidth = 1,
30
+ onItemClick
30
31
  } = props;
31
32
  const geoData = (0, _useGeoData.useGeoData)();
32
33
  const path = (0, _useGeoPath.useGeoPath)();
@@ -56,7 +57,7 @@ function MapShapePlot(props) {
56
57
  const colorGetter = _seriesConfig.mapShapeSeriesConfig.colorProcessor(seriesItem, undefined, undefined, colorAxis);
57
58
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
58
59
  "data-series": id,
59
- children: data.map((item, dataIndex) => {
60
+ children: data.map(item => {
60
61
  if (item.hidden) {
61
62
  return null;
62
63
  }
@@ -68,17 +69,22 @@ function MapShapePlot(props) {
68
69
  children: featureIndexes.map(featureIndex => {
69
70
  const feature = geoData.features[featureIndex];
70
71
  const d = path(feature);
71
- const color = fill ?? colorGetter(dataIndex);
72
+ const color = fill ?? colorGetter(item.name);
72
73
  if (!d || color === null) {
73
74
  return null;
74
75
  }
75
76
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_MapShape.MapShape, {
76
77
  seriesId: id,
77
- dataIndex: dataIndex,
78
+ featureName: item.name,
78
79
  d: d,
79
80
  color: color,
80
81
  stroke: stroke,
81
- strokeWidth: strokeWidth
82
+ strokeWidth: strokeWidth,
83
+ onClick: onItemClick && (event => onItemClick(event, {
84
+ type: 'mapShape',
85
+ seriesId: id,
86
+ name: item.name
87
+ }))
82
88
  }, featureIndex);
83
89
  })
84
90
  }, item.name);
@@ -97,6 +103,12 @@ process.env.NODE_ENV !== "production" ? MapShapePlot.propTypes /* remove-proptyp
97
103
  * Fill color applied to every feature path. Overrides item and series colors.
98
104
  */
99
105
  fill: _propTypes.default.string,
106
+ /**
107
+ * Callback fired when clicking on a map shape.
108
+ * @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
109
+ * @param {MapShapeItemIdentifier} mapShapeItemIdentifier The identifier of the clicked map shape.
110
+ */
111
+ onItemClick: _propTypes.default.func,
100
112
  /**
101
113
  * Stroke color applied to every feature path.
102
114
  * @default 'none'
@@ -19,7 +19,8 @@ function MapShapePlot(props) {
19
19
  className,
20
20
  fill,
21
21
  stroke = 'none',
22
- strokeWidth = 1
22
+ strokeWidth = 1,
23
+ onItemClick
23
24
  } = props;
24
25
  const geoData = useGeoData();
25
26
  const path = useGeoPath();
@@ -49,7 +50,7 @@ function MapShapePlot(props) {
49
50
  const colorGetter = mapShapeSeriesConfig.colorProcessor(seriesItem, undefined, undefined, colorAxis);
50
51
  return /*#__PURE__*/_jsx("g", {
51
52
  "data-series": id,
52
- children: data.map((item, dataIndex) => {
53
+ children: data.map(item => {
53
54
  if (item.hidden) {
54
55
  return null;
55
56
  }
@@ -61,17 +62,22 @@ function MapShapePlot(props) {
61
62
  children: featureIndexes.map(featureIndex => {
62
63
  const feature = geoData.features[featureIndex];
63
64
  const d = path(feature);
64
- const color = fill ?? colorGetter(dataIndex);
65
+ const color = fill ?? colorGetter(item.name);
65
66
  if (!d || color === null) {
66
67
  return null;
67
68
  }
68
69
  return /*#__PURE__*/_jsx(MapShape, {
69
70
  seriesId: id,
70
- dataIndex: dataIndex,
71
+ featureName: item.name,
71
72
  d: d,
72
73
  color: color,
73
74
  stroke: stroke,
74
- strokeWidth: strokeWidth
75
+ strokeWidth: strokeWidth,
76
+ onClick: onItemClick && (event => onItemClick(event, {
77
+ type: 'mapShape',
78
+ seriesId: id,
79
+ name: item.name
80
+ }))
75
81
  }, featureIndex);
76
82
  })
77
83
  }, item.name);
@@ -90,6 +96,12 @@ process.env.NODE_ENV !== "production" ? MapShapePlot.propTypes /* remove-proptyp
90
96
  * Fill color applied to every feature path. Overrides item and series colors.
91
97
  */
92
98
  fill: PropTypes.string,
99
+ /**
100
+ * Callback fired when clicking on a map shape.
101
+ * @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
102
+ * @param {MapShapeItemIdentifier} mapShapeItemIdentifier The identifier of the clicked map shape.
103
+ */
104
+ onItemClick: PropTypes.func,
93
105
  /**
94
106
  * Stroke color applied to every feature path.
95
107
  * @default 'none'
package/Map/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { useGeoProjectionTypes } from '@mui/x-charts/internals';
2
2
  export * from "./GeoDataPlot.mjs";
3
+ export * from "./MapImagePlot.mjs";
3
4
  export * from "./MapShapePlot.mjs";
4
5
  export * from "./MapShape.mjs";
5
6
  export * from "./FocusedMapShape.mjs";
package/Map/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { useGeoProjectionTypes } from '@mui/x-charts/internals';
2
2
  export * from "./GeoDataPlot.js";
3
+ export * from "./MapImagePlot.js";
3
4
  export * from "./MapShapePlot.js";
4
5
  export * from "./MapShape.js";
5
6
  export * from "./FocusedMapShape.js";
package/Map/index.js CHANGED
@@ -14,6 +14,17 @@ Object.keys(_GeoDataPlot).forEach(function (key) {
14
14
  }
15
15
  });
16
16
  });
17
+ var _MapImagePlot = require("./MapImagePlot");
18
+ Object.keys(_MapImagePlot).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _MapImagePlot[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _MapImagePlot[key];
25
+ }
26
+ });
27
+ });
17
28
  var _MapShapePlot = require("./MapShapePlot");
18
29
  Object.keys(_MapShapePlot).forEach(function (key) {
19
30
  if (key === "default" || key === "__esModule") return;
package/Map/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./GeoDataPlot.mjs";
2
+ export * from "./MapImagePlot.mjs";
2
3
  export * from "./MapShapePlot.mjs";
3
4
  export * from "./MapShape.mjs";
4
5
  export * from "./FocusedMapShape.mjs";
@@ -0,0 +1,60 @@
1
+ import type { GeoProjection } from '@mui/x-charts-vendor/d3-geo';
2
+ export interface ReprojectEquirectangularImageParams {
3
+ /**
4
+ * A fully-loaded image whose pixels are in the equirectangular (plate carrée)
5
+ * projection — longitude maps linearly to x, latitude linearly to y.
6
+ */
7
+ image: HTMLImageElement;
8
+ /**
9
+ * The chart projection. Must expose `invert`; otherwise reprojection is impossible.
10
+ */
11
+ projection: GeoProjection;
12
+ /**
13
+ * The chart drawing area, in SVG coordinates. `left`/`top` are the offset of the
14
+ * drawing area inside the SVG, which the projection already accounts for.
15
+ */
16
+ area: {
17
+ left: number;
18
+ top: number;
19
+ width: number;
20
+ height: number;
21
+ };
22
+ /**
23
+ * Geographic extent the source image covers, as `[[west, south], [east, north]]`
24
+ * in degrees. `west > east` is allowed and means the range wraps across the antimeridian.
25
+ */
26
+ imageBounds: [[number, number], [number, number]];
27
+ }
28
+ /**
29
+ * Warps an equirectangular raster so it matches an arbitrary d3-geo `projection`,
30
+ * returning the result as a PNG data URL (or `null` when it cannot be produced).
31
+ *
32
+ * ### Why inverse mapping
33
+ *
34
+ * Forward-projecting each *source* pixel to the screen leaves holes and overlaps,
35
+ * because the mapping is non-linear and area-distorting. Instead we walk every
36
+ * *destination* pixel and pull the color it should show from the source — inverse
37
+ * (destination-to-source) resampling, which fills the output exactly once.
38
+ *
39
+ * ### Algorithm
40
+ *
41
+ * For each destination pixel `(px, py)` of the drawing area:
42
+ *
43
+ * 1. Convert it to SVG coordinates `(left + px, top + py)` and resolve it to a
44
+ * `[lon, lat]` coordinate with {@link createVisibleCoordinate}, which returns
45
+ * `null` for pixels outside the visible map (post-clip and the spherical
46
+ * round-trip), leaving them transparent.
47
+ * 2. Discard coordinates outside `imageBounds` (no source data there).
48
+ * 3. Map `[lon, lat]` to a source pixel with nearest-neighbor sampling (the image
49
+ * being equirectangular, both axes are linear) and copy its RGBA.
50
+ *
51
+ * ### Failure modes
52
+ *
53
+ * Returns `null` when a 2D canvas context is unavailable, or when reading the
54
+ * source pixels throws because a cross-origin image without CORS headers has
55
+ * tainted the canvas.
56
+ *
57
+ * Complexity is `O(width × height)`; callers should treat it as a per-resize
58
+ * computation rather than a per-frame one.
59
+ */
60
+ export declare function reprojectEquirectangularImage(params: ReprojectEquirectangularImageParams): string | null;
@@ -0,0 +1,60 @@
1
+ import type { GeoProjection } from '@mui/x-charts-vendor/d3-geo';
2
+ export interface ReprojectEquirectangularImageParams {
3
+ /**
4
+ * A fully-loaded image whose pixels are in the equirectangular (plate carrée)
5
+ * projection — longitude maps linearly to x, latitude linearly to y.
6
+ */
7
+ image: HTMLImageElement;
8
+ /**
9
+ * The chart projection. Must expose `invert`; otherwise reprojection is impossible.
10
+ */
11
+ projection: GeoProjection;
12
+ /**
13
+ * The chart drawing area, in SVG coordinates. `left`/`top` are the offset of the
14
+ * drawing area inside the SVG, which the projection already accounts for.
15
+ */
16
+ area: {
17
+ left: number;
18
+ top: number;
19
+ width: number;
20
+ height: number;
21
+ };
22
+ /**
23
+ * Geographic extent the source image covers, as `[[west, south], [east, north]]`
24
+ * in degrees. `west > east` is allowed and means the range wraps across the antimeridian.
25
+ */
26
+ imageBounds: [[number, number], [number, number]];
27
+ }
28
+ /**
29
+ * Warps an equirectangular raster so it matches an arbitrary d3-geo `projection`,
30
+ * returning the result as a PNG data URL (or `null` when it cannot be produced).
31
+ *
32
+ * ### Why inverse mapping
33
+ *
34
+ * Forward-projecting each *source* pixel to the screen leaves holes and overlaps,
35
+ * because the mapping is non-linear and area-distorting. Instead we walk every
36
+ * *destination* pixel and pull the color it should show from the source — inverse
37
+ * (destination-to-source) resampling, which fills the output exactly once.
38
+ *
39
+ * ### Algorithm
40
+ *
41
+ * For each destination pixel `(px, py)` of the drawing area:
42
+ *
43
+ * 1. Convert it to SVG coordinates `(left + px, top + py)` and resolve it to a
44
+ * `[lon, lat]` coordinate with {@link createVisibleCoordinate}, which returns
45
+ * `null` for pixels outside the visible map (post-clip and the spherical
46
+ * round-trip), leaving them transparent.
47
+ * 2. Discard coordinates outside `imageBounds` (no source data there).
48
+ * 3. Map `[lon, lat]` to a source pixel with nearest-neighbor sampling (the image
49
+ * being equirectangular, both axes are linear) and copy its RGBA.
50
+ *
51
+ * ### Failure modes
52
+ *
53
+ * Returns `null` when a 2D canvas context is unavailable, or when reading the
54
+ * source pixels throws because a cross-origin image without CORS headers has
55
+ * tainted the canvas.
56
+ *
57
+ * Complexity is `O(width × height)`; callers should treat it as a per-resize
58
+ * computation rather than a per-frame one.
59
+ */
60
+ export declare function reprojectEquirectangularImage(params: ReprojectEquirectangularImageParams): string | null;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.reprojectEquirectangularImage = reprojectEquirectangularImage;
7
+ var _createGetVisibleCoordinate = require("../internals/createGetVisibleCoordinate");
8
+ /**
9
+ * Warps an equirectangular raster so it matches an arbitrary d3-geo `projection`,
10
+ * returning the result as a PNG data URL (or `null` when it cannot be produced).
11
+ *
12
+ * ### Why inverse mapping
13
+ *
14
+ * Forward-projecting each *source* pixel to the screen leaves holes and overlaps,
15
+ * because the mapping is non-linear and area-distorting. Instead we walk every
16
+ * *destination* pixel and pull the color it should show from the source — inverse
17
+ * (destination-to-source) resampling, which fills the output exactly once.
18
+ *
19
+ * ### Algorithm
20
+ *
21
+ * For each destination pixel `(px, py)` of the drawing area:
22
+ *
23
+ * 1. Convert it to SVG coordinates `(left + px, top + py)` and resolve it to a
24
+ * `[lon, lat]` coordinate with {@link createVisibleCoordinate}, which returns
25
+ * `null` for pixels outside the visible map (post-clip and the spherical
26
+ * round-trip), leaving them transparent.
27
+ * 2. Discard coordinates outside `imageBounds` (no source data there).
28
+ * 3. Map `[lon, lat]` to a source pixel with nearest-neighbor sampling (the image
29
+ * being equirectangular, both axes are linear) and copy its RGBA.
30
+ *
31
+ * ### Failure modes
32
+ *
33
+ * Returns `null` when a 2D canvas context is unavailable, or when reading the
34
+ * source pixels throws because a cross-origin image without CORS headers has
35
+ * tainted the canvas.
36
+ *
37
+ * Complexity is `O(width × height)`; callers should treat it as a per-resize
38
+ * computation rather than a per-frame one.
39
+ */
40
+ function reprojectEquirectangularImage(params) {
41
+ const {
42
+ image,
43
+ projection,
44
+ area,
45
+ imageBounds
46
+ } = params;
47
+ if (typeof projection.invert !== 'function') {
48
+ return null;
49
+ }
50
+ const getVisibleCoordinate = (0, _createGetVisibleCoordinate.createGetVisibleCoordinate)(projection);
51
+ const {
52
+ left,
53
+ top
54
+ } = area;
55
+ const outWidth = Math.max(1, Math.round(area.width));
56
+ const outHeight = Math.max(1, Math.round(area.height));
57
+ const [[west, south], [east, north]] = imageBounds;
58
+ const source = document.createElement('canvas');
59
+ source.width = image.naturalWidth;
60
+ source.height = image.naturalHeight;
61
+ const sourceCtx = source.getContext('2d');
62
+ const output = document.createElement('canvas');
63
+ output.width = outWidth;
64
+ output.height = outHeight;
65
+ const outputCtx = output.getContext('2d');
66
+ if (!sourceCtx || !outputCtx) {
67
+ return null;
68
+ }
69
+ sourceCtx.drawImage(image, 0, 0);
70
+ let sourcePixels;
71
+ try {
72
+ sourcePixels = sourceCtx.getImageData(0, 0, source.width, source.height);
73
+ } catch {
74
+ // Cross-origin image without CORS taints the canvas: bail out.
75
+ return null;
76
+ }
77
+ const sourceWidth = source.width;
78
+ const sourceHeight = source.height;
79
+ const target = outputCtx.createImageData(outWidth, outHeight);
80
+
81
+ // `west > east` means the source wraps across the antimeridian (e.g. 170°E..-170°E).
82
+ const lonWraps = east < west;
83
+ const lonSpan = lonWraps ? east - west + 360 : east - west;
84
+ for (let py = 0; py < outHeight; py += 1) {
85
+ for (let px = 0; px < outWidth; px += 1) {
86
+ // 1. Destination pixel -> geographic coordinate, or skip if not on the map.
87
+ const coordinates = getVisibleCoordinate([left + px, top + py]);
88
+ if (!coordinates) {
89
+ continue;
90
+ }
91
+ const [lon, lat] = coordinates;
92
+
93
+ // 2. Outside the source image extent: nothing to sample.
94
+ const insideLon = lonWraps ? lon >= west || lon <= east : lon >= west && lon <= east;
95
+ if (!insideLon || lat < south || lat > north) {
96
+ continue;
97
+ }
98
+
99
+ // 3. Geographic coordinate -> source pixel (nearest neighbor). When the
100
+ // bounds wrap, longitudes past the antimeridian are offset by a full turn.
101
+ const lonOffset = lonWraps && lon <= east ? lon - west + 360 : lon - west;
102
+ let sx = Math.floor(lonOffset / lonSpan * sourceWidth);
103
+ let sy = Math.floor((north - lat) / (north - south) * sourceHeight);
104
+ sx = Math.min(Math.max(sx, 0), sourceWidth - 1);
105
+ sy = Math.min(Math.max(sy, 0), sourceHeight - 1);
106
+ const sourceIndex = (sy * sourceWidth + sx) * 4;
107
+ const targetIndex = (py * outWidth + px) * 4;
108
+ target.data[targetIndex] = sourcePixels.data[sourceIndex];
109
+ target.data[targetIndex + 1] = sourcePixels.data[sourceIndex + 1];
110
+ target.data[targetIndex + 2] = sourcePixels.data[sourceIndex + 2];
111
+ target.data[targetIndex + 3] = sourcePixels.data[sourceIndex + 3];
112
+ }
113
+ }
114
+ outputCtx.putImageData(target, 0, 0);
115
+ return output.toDataURL();
116
+ }