@mui/x-charts-premium 9.3.0 → 9.5.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 (212) hide show
  1. package/BarChartPremium/BarChartPremium.js +35 -5
  2. package/BarChartPremium/BarChartPremium.mjs +35 -5
  3. package/BarChartPremium/RangeBar/RangeBarPlot.d.mts +10 -0
  4. package/BarChartPremium/RangeBar/RangeBarPlot.d.ts +10 -0
  5. package/BarChartPremium/RangeBar/RangeBarPlot.js +59 -2
  6. package/BarChartPremium/RangeBar/RangeBarPlot.mjs +59 -2
  7. package/BarChartPremium/RangeBar/RangeBarWebGLPlot.d.mts +10 -0
  8. package/BarChartPremium/RangeBar/RangeBarWebGLPlot.d.ts +10 -0
  9. package/BarChartPremium/RangeBar/RangeBarWebGLPlot.js +82 -0
  10. package/BarChartPremium/RangeBar/RangeBarWebGLPlot.mjs +76 -0
  11. package/BarChartPremium/RangeBar/seriesConfig/extrema.js +3 -0
  12. package/BarChartPremium/RangeBar/seriesConfig/extrema.mjs +3 -0
  13. package/BarChartPremium/RangeBar/seriesConfig/seriesProcessor.js +2 -2
  14. package/BarChartPremium/RangeBar/seriesConfig/seriesProcessor.mjs +2 -2
  15. package/BarChartPremium/useBarChartPremiumProps.js +2 -1
  16. package/BarChartPremium/useBarChartPremiumProps.mjs +2 -1
  17. package/BarChartPremium/webgl/useBarWebGLPlotData.d.mts +2 -7
  18. package/BarChartPremium/webgl/useBarWebGLPlotData.d.ts +2 -7
  19. package/BarChartPremium/webgl/useBarWebGLPlotData.js +4 -151
  20. package/BarChartPremium/webgl/useBarWebGLPlotData.mjs +4 -150
  21. package/BarChartPremium/webgl/useWebGLBarLikePlotData.d.mts +40 -0
  22. package/BarChartPremium/webgl/useWebGLBarLikePlotData.d.ts +40 -0
  23. package/BarChartPremium/webgl/useWebGLBarLikePlotData.js +228 -0
  24. package/BarChartPremium/webgl/useWebGLBarLikePlotData.mjs +222 -0
  25. package/CHANGELOG.md +296 -0
  26. package/CandlestickChart/CandlestickChart.js +11 -2
  27. package/CandlestickChart/CandlestickChart.mjs +11 -2
  28. package/CandlestickChart/index.d.mts +11 -2
  29. package/CandlestickChart/index.d.ts +11 -2
  30. package/CandlestickChart/index.js +15 -3
  31. package/CandlestickChart/index.mjs +16 -2
  32. package/CandlestickChart/seriesConfig/extrema.js +3 -0
  33. package/CandlestickChart/seriesConfig/extrema.mjs +3 -0
  34. package/CandlestickChart/seriesConfig/seriesProcessor.js +2 -2
  35. package/CandlestickChart/seriesConfig/seriesProcessor.mjs +2 -2
  36. package/ChartsDataProviderPremium/ChartsDataProviderPremium.js +2 -2
  37. package/ChartsDataProviderPremium/ChartsDataProviderPremium.mjs +2 -2
  38. package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.d.mts +35 -0
  39. package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.d.ts +35 -0
  40. package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.js +125 -0
  41. package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.mjs +119 -0
  42. package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.plugins.d.mts +5 -0
  43. package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.plugins.d.ts +5 -0
  44. package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.plugins.js +10 -0
  45. package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.plugins.mjs +4 -0
  46. package/ChartsGeoDataProviderPremium/index.d.mts +3 -0
  47. package/ChartsGeoDataProviderPremium/index.d.ts +3 -0
  48. package/ChartsGeoDataProviderPremium/index.js +20 -0
  49. package/ChartsGeoDataProviderPremium/index.mjs +3 -0
  50. package/ChartsGeoDataProviderPremium/useChartsGeoDataProviderPremiumProps.d.mts +10 -0
  51. package/ChartsGeoDataProviderPremium/useChartsGeoDataProviderPremiumProps.d.ts +10 -0
  52. package/ChartsGeoDataProviderPremium/useChartsGeoDataProviderPremiumProps.js +49 -0
  53. package/ChartsGeoDataProviderPremium/useChartsGeoDataProviderPremiumProps.mjs +42 -0
  54. package/ChartsRadialDataProviderPremium/ChartsRadialDataProviderPremium.js +2 -2
  55. package/ChartsRadialDataProviderPremium/ChartsRadialDataProviderPremium.mjs +2 -2
  56. package/HeatmapPremium/HeatmapPremium.js +32 -2
  57. package/HeatmapPremium/HeatmapPremium.mjs +32 -2
  58. package/Map/FocusedMapShape.d.mts +4 -0
  59. package/Map/FocusedMapShape.d.ts +4 -0
  60. package/Map/FocusedMapShape.js +66 -0
  61. package/Map/FocusedMapShape.mjs +60 -0
  62. package/Map/GeoDataPlot.d.mts +26 -0
  63. package/Map/GeoDataPlot.d.ts +26 -0
  64. package/Map/GeoDataPlot.js +65 -0
  65. package/Map/GeoDataPlot.mjs +60 -0
  66. package/Map/Graticule.d.mts +1 -0
  67. package/Map/Graticule.d.ts +1 -0
  68. package/Map/Graticule.js +30 -0
  69. package/Map/Graticule.mjs +24 -0
  70. package/Map/MapShape.d.mts +10 -0
  71. package/Map/MapShape.d.ts +10 -0
  72. package/Map/MapShape.js +55 -0
  73. package/Map/MapShape.mjs +49 -0
  74. package/Map/MapShapePlot.d.mts +21 -0
  75. package/Map/MapShapePlot.d.ts +21 -0
  76. package/Map/MapShapePlot.js +86 -0
  77. package/Map/MapShapePlot.mjs +80 -0
  78. package/Map/index.d.mts +7 -0
  79. package/Map/index.d.ts +7 -0
  80. package/Map/index.js +60 -0
  81. package/Map/index.mjs +8 -0
  82. package/Map/seriesConfig/descriptionGetter.d.mts +3 -0
  83. package/Map/seriesConfig/descriptionGetter.d.ts +3 -0
  84. package/Map/seriesConfig/descriptionGetter.js +19 -0
  85. package/Map/seriesConfig/descriptionGetter.mjs +13 -0
  86. package/Map/seriesConfig/getColor.d.mts +3 -0
  87. package/Map/seriesConfig/getColor.d.ts +3 -0
  88. package/Map/seriesConfig/getColor.js +35 -0
  89. package/Map/seriesConfig/getColor.mjs +29 -0
  90. package/Map/seriesConfig/getSeriesWithDefaultValues.d.mts +3 -0
  91. package/Map/seriesConfig/getSeriesWithDefaultValues.d.ts +3 -0
  92. package/Map/seriesConfig/getSeriesWithDefaultValues.js +15 -0
  93. package/Map/seriesConfig/getSeriesWithDefaultValues.mjs +8 -0
  94. package/Map/seriesConfig/index.d.mts +2 -0
  95. package/Map/seriesConfig/index.d.ts +2 -0
  96. package/Map/seriesConfig/index.js +28 -0
  97. package/Map/seriesConfig/index.mjs +21 -0
  98. package/Map/seriesConfig/keyboardFocusHandler.d.mts +9 -0
  99. package/Map/seriesConfig/keyboardFocusHandler.d.ts +9 -0
  100. package/Map/seriesConfig/keyboardFocusHandler.js +19 -0
  101. package/Map/seriesConfig/keyboardFocusHandler.mjs +13 -0
  102. package/Map/seriesConfig/legend.d.mts +3 -0
  103. package/Map/seriesConfig/legend.d.ts +3 -0
  104. package/Map/seriesConfig/legend.js +28 -0
  105. package/Map/seriesConfig/legend.mjs +22 -0
  106. package/Map/seriesConfig/seriesProcessor.d.mts +3 -0
  107. package/Map/seriesConfig/seriesProcessor.d.ts +3 -0
  108. package/Map/seriesConfig/seriesProcessor.js +66 -0
  109. package/Map/seriesConfig/seriesProcessor.mjs +59 -0
  110. package/Map/seriesConfig/tooltip.d.mts +3 -0
  111. package/Map/seriesConfig/tooltip.d.ts +3 -0
  112. package/Map/seriesConfig/tooltip.js +33 -0
  113. package/Map/seriesConfig/tooltip.mjs +27 -0
  114. package/RadialBarChart/RadialBarChart.d.mts +1 -1
  115. package/RadialBarChart/RadialBarChart.d.ts +1 -1
  116. package/RadialBarChart/RadialBarChart.js +2 -2
  117. package/RadialBarChart/RadialBarChart.mjs +1 -1
  118. package/RadialBarChart/index.d.mts +4 -0
  119. package/RadialBarChart/index.d.ts +4 -0
  120. package/RadialBarChart/index.js +8 -1
  121. package/RadialBarChart/index.mjs +6 -0
  122. package/RadialLineChart/RadialLineChart.d.mts +1 -1
  123. package/RadialLineChart/RadialLineChart.d.ts +1 -1
  124. package/RadialLineChart/RadialLineChart.js +4 -4
  125. package/RadialLineChart/RadialLineChart.mjs +5 -5
  126. package/RadialLineChart/RadialLineHighlightPlot.d.mts +3 -2
  127. package/RadialLineChart/RadialLineHighlightPlot.d.ts +3 -2
  128. package/RadialLineChart/index.d.mts +4 -0
  129. package/RadialLineChart/index.d.ts +4 -0
  130. package/RadialLineChart/index.js +16 -1
  131. package/RadialLineChart/index.mjs +6 -0
  132. package/ScatterChartPremium/ScatterChartPremium.d.mts +2 -1
  133. package/ScatterChartPremium/ScatterChartPremium.d.ts +2 -1
  134. package/ScatterChartPremium/ScatterChartPremium.js +36 -4
  135. package/ScatterChartPremium/ScatterChartPremium.mjs +37 -5
  136. package/ScatterChartPremium/ScatterChartPremium.plugins.d.mts +1 -1
  137. package/ScatterChartPremium/ScatterChartPremium.plugins.d.ts +1 -1
  138. package/ScatterChartPremium/ScatterPlotPremium.d.mts +2 -2
  139. package/ScatterChartPremium/ScatterPlotPremium.d.ts +2 -2
  140. package/hooks/index.d.mts +4 -1
  141. package/hooks/index.d.ts +4 -1
  142. package/hooks/index.js +33 -0
  143. package/hooks/index.mjs +4 -1
  144. package/hooks/useGeoData.d.mts +6 -0
  145. package/hooks/useGeoData.d.ts +6 -0
  146. package/hooks/useGeoData.js +17 -0
  147. package/hooks/useGeoData.mjs +13 -0
  148. package/hooks/useGeoFeatureIndexesByName.d.mts +7 -0
  149. package/hooks/useGeoFeatureIndexesByName.d.ts +7 -0
  150. package/hooks/useGeoFeatureIndexesByName.js +19 -0
  151. package/hooks/useGeoFeatureIndexesByName.mjs +15 -0
  152. package/hooks/useGeoPath.d.mts +6 -0
  153. package/hooks/useGeoPath.d.ts +6 -0
  154. package/hooks/useGeoPath.js +17 -0
  155. package/hooks/useGeoPath.mjs +13 -0
  156. package/hooks/useMapShapeSeries.d.mts +34 -0
  157. package/hooks/useMapShapeSeries.d.ts +34 -0
  158. package/hooks/useMapShapeSeries.js +45 -0
  159. package/hooks/useMapShapeSeries.mjs +40 -0
  160. package/index.d.mts +3 -1
  161. package/index.d.ts +3 -1
  162. package/index.js +32 -1
  163. package/index.mjs +4 -2
  164. package/internals/plugins/allPlugins.d.mts +5 -5
  165. package/internals/plugins/allPlugins.d.ts +5 -5
  166. package/internals/plugins/allPlugins.js +2 -2
  167. package/internals/plugins/allPlugins.mjs +3 -3
  168. package/internals/plugins/useGeoProjection/index.d.mts +3 -0
  169. package/internals/plugins/useGeoProjection/index.d.ts +3 -0
  170. package/internals/plugins/useGeoProjection/index.js +38 -0
  171. package/internals/plugins/useGeoProjection/index.mjs +3 -0
  172. package/internals/plugins/useGeoProjection/useGeoProjection.d.mts +3 -0
  173. package/internals/plugins/useGeoProjection/useGeoProjection.d.ts +3 -0
  174. package/internals/plugins/useGeoProjection/useGeoProjection.js +58 -0
  175. package/internals/plugins/useGeoProjection/useGeoProjection.mjs +50 -0
  176. package/internals/plugins/useGeoProjection/useGeoProjection.selectors.d.mts +39 -0
  177. package/internals/plugins/useGeoProjection/useGeoProjection.selectors.d.ts +39 -0
  178. package/internals/plugins/useGeoProjection/useGeoProjection.selectors.js +135 -0
  179. package/internals/plugins/useGeoProjection/useGeoProjection.selectors.mjs +128 -0
  180. package/internals/plugins/useGeoProjection/useGeoProjection.types.d.mts +55 -0
  181. package/internals/plugins/useGeoProjection/useGeoProjection.types.d.ts +55 -0
  182. package/internals/plugins/useGeoProjection/useGeoProjection.types.js +5 -0
  183. package/internals/plugins/useGeoProjection/useGeoProjection.types.mjs +1 -0
  184. package/models/chartsSlotsComponentsPropsPremium.d.mts +1 -0
  185. package/models/chartsSlotsComponentsPropsPremium.d.ts +1 -0
  186. package/models/chartsSlotsComponentsPropsPremium.js +5 -0
  187. package/models/chartsSlotsComponentsPropsPremium.mjs +1 -0
  188. package/models/index.d.mts +2 -1
  189. package/models/index.d.ts +2 -1
  190. package/models/index.js +11 -0
  191. package/models/index.mjs +2 -1
  192. package/models/seriesType/index.d.mts +2 -1
  193. package/models/seriesType/index.d.ts +2 -1
  194. package/models/seriesType/index.js +11 -0
  195. package/models/seriesType/index.mjs +2 -1
  196. package/models/seriesType/mapShape.d.mts +105 -0
  197. package/models/seriesType/mapShape.d.ts +105 -0
  198. package/models/seriesType/mapShape.js +5 -0
  199. package/models/seriesType/mapShape.mjs +1 -0
  200. package/models/seriesType/ohlc.d.mts +1 -1
  201. package/models/seriesType/ohlc.d.ts +1 -1
  202. package/models/seriesType/radialBar.d.mts +1 -1
  203. package/models/seriesType/radialBar.d.ts +1 -1
  204. package/models/seriesType/radialLine.d.mts +1 -1
  205. package/models/seriesType/radialLine.d.ts +1 -1
  206. package/models/seriesType/rangeBar.d.mts +1 -1
  207. package/models/seriesType/rangeBar.d.ts +1 -1
  208. package/package.json +34 -6
  209. package/typeOverloads/modules.d.mts +16 -1
  210. package/typeOverloads/modules.d.ts +16 -1
  211. package/utils/webgl/useWebGLResizeObserver.js +3 -3
  212. package/utils/webgl/useWebGLResizeObserver.mjs +2 -2
@@ -1,10 +1,5 @@
1
1
  import { type ChartDrawingArea } from '@mui/x-charts/hooks';
2
2
  import { type ProcessedBarSeriesData } from '@mui/x-charts/internals';
3
- export interface BarWebGLPlotData {
4
- centers: Float32Array;
5
- halfSizes: Float32Array;
6
- colors: Uint8Array;
7
- cornerRadii: Float32Array;
8
- count: number;
9
- }
3
+ import { type WebGLBarLikePlotData } from "./useWebGLBarLikePlotData.mjs";
4
+ export type BarWebGLPlotData = WebGLBarLikePlotData;
10
5
  export declare function useBarWebGLPlotData(drawingArea: ChartDrawingArea, completedData: ProcessedBarSeriesData[], borderRadius: number): BarWebGLPlotData;
@@ -1,10 +1,5 @@
1
1
  import { type ChartDrawingArea } from '@mui/x-charts/hooks';
2
2
  import { type ProcessedBarSeriesData } from '@mui/x-charts/internals';
3
- export interface BarWebGLPlotData {
4
- centers: Float32Array;
5
- halfSizes: Float32Array;
6
- colors: Uint8Array;
7
- cornerRadii: Float32Array;
8
- count: number;
9
- }
3
+ import { type WebGLBarLikePlotData } from "./useWebGLBarLikePlotData.js";
4
+ export type BarWebGLPlotData = WebGLBarLikePlotData;
10
5
  export declare function useBarWebGLPlotData(drawingArea: ChartDrawingArea, completedData: ProcessedBarSeriesData[], borderRadius: number): BarWebGLPlotData;
@@ -1,160 +1,13 @@
1
1
  "use strict";
2
2
  'use client';
3
3
 
4
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.useBarWebGLPlotData = useBarWebGLPlotData;
9
- var React = _interopRequireWildcard(require("react"));
10
- var _internals = require("@mui/x-charts/internals");
11
- var _parseColor = require("../../utils/webgl/parseColor");
12
- const EMPTY_FLOAT32 = new Float32Array(0);
13
- const EMPTY_UINT8 = new Uint8Array(0);
14
- const EMPTY_DATA = {
15
- centers: EMPTY_FLOAT32,
16
- halfSizes: EMPTY_FLOAT32,
17
- colors: EMPTY_UINT8,
18
- cornerRadii: EMPTY_FLOAT32,
19
- count: 0
20
- };
21
- function ensureCapacity(pool, maxCount) {
22
- if (pool !== null && pool.colors.length >= maxCount * 4) {
23
- return pool;
24
- }
25
- return {
26
- centers: new Float32Array(maxCount * 2),
27
- halfSizes: new Float32Array(maxCount * 2),
28
- colors: new Uint8Array(maxCount * 4),
29
- cornerRadii: new Float32Array(maxCount * 4)
30
- };
31
- }
32
-
33
- // Mirrors SVG highlight styling: highlighted -> CSS `brightness(120%)`,
34
- // faded -> opacity 0.3. Baking these into the per-bar color array means we
35
- // don't need a separate per-instance attribute on the GPU side.
36
- const HIGHLIGHTED_BRIGHTNESS = 1.2;
37
- const FADED_OPACITY = 0.3;
38
- function setCornerRadii(radius, side, target, offset) {
39
- // CSS order: top-left, top-right, bottom-right, bottom-left.
40
- let tl = 0;
41
- let tr = 0;
42
- let br = 0;
43
- let bl = 0;
44
- if (radius > 0) {
45
- if (side === 'top') {
46
- tl = radius;
47
- tr = radius;
48
- } else if (side === 'bottom') {
49
- br = radius;
50
- bl = radius;
51
- } else if (side === 'left') {
52
- tl = radius;
53
- bl = radius;
54
- } else if (side === 'right') {
55
- tr = radius;
56
- br = radius;
57
- }
58
- }
59
- target[offset] = tl;
60
- target[offset + 1] = tr;
61
- target[offset + 2] = br;
62
- target[offset + 3] = bl;
63
- }
8
+ var _useWebGLBarLikePlotData = require("./useWebGLBarLikePlotData");
64
9
  function useBarWebGLPlotData(drawingArea, completedData, borderRadius) {
65
- const store = (0, _internals.useStore)();
66
- const getHighlightState = store.use(_internals.selectorChartsHighlightStateCallback);
67
- const poolRef = React.useRef(null);
68
- return React.useMemo(() => {
69
- let maxCount = 0;
70
- for (let s = 0; s < completedData.length; s += 1) {
71
- maxCount += completedData[s].data.length;
72
- }
73
- if (maxCount === 0) {
74
- return EMPTY_DATA;
75
- }
76
- const pool = ensureCapacity(poolRef.current, maxCount);
77
- poolRef.current = pool;
78
-
79
- // Hoist invariants out of the hot loop.
80
- const {
81
- centers,
82
- halfSizes,
83
- colors,
84
- cornerRadii
85
- } = pool;
86
- const drawingAreaLeft = drawingArea.left;
87
- const drawingAreaTop = drawingArea.top;
88
- let cursor = 0;
89
- for (let s = 0; s < completedData.length; s += 1) {
90
- const processed = completedData[s];
91
- const seriesId = processed.seriesId;
92
- const data = processed.data;
93
- const dataLength = data.length;
94
- for (let i = 0; i < dataLength; i += 1) {
95
- const bar = data[i];
96
- if (bar.hidden) {
97
- continue;
98
- }
99
- const value = bar.value;
100
- if (value == null) {
101
- continue;
102
- }
103
- const w = bar.width;
104
- const h = bar.height;
105
- if (w <= 0 || h <= 0) {
106
- continue;
107
- }
108
- const halfW = w * 0.5;
109
- const halfH = h * 0.5;
110
- const c2 = cursor * 2;
111
- centers[c2] = bar.x + halfW - drawingAreaLeft;
112
- centers[c2 + 1] = bar.y + halfH - drawingAreaTop;
113
- halfSizes[c2] = halfW;
114
- halfSizes[c2 + 1] = halfH;
115
- const rgba = (0, _parseColor.parseColor)(bar.color);
116
- const c4 = cursor * 4;
117
- let r = rgba[0];
118
- let g = rgba[1];
119
- let b = rgba[2];
120
- let a = rgba[3];
121
- const highlightState = getHighlightState({
122
- type: 'bar',
123
- seriesId,
124
- dataIndex: bar.dataIndex
125
- });
126
- if (highlightState === 'highlighted') {
127
- r = Math.min(255, r * HIGHLIGHTED_BRIGHTNESS);
128
- g = Math.min(255, g * HIGHLIGHTED_BRIGHTNESS);
129
- b = Math.min(255, b * HIGHLIGHTED_BRIGHTNESS);
130
- } else if (highlightState === 'faded') {
131
- a *= FADED_OPACITY;
132
- }
133
- colors[c4] = r;
134
- colors[c4 + 1] = g;
135
- colors[c4 + 2] = b;
136
- colors[c4 + 3] = a;
137
- const effectiveRadius = Math.min(borderRadius, halfW, halfH);
138
- setCornerRadii(effectiveRadius, bar.borderRadiusSide, cornerRadii, c4);
139
- cursor += 1;
140
- }
141
- }
142
- if (cursor === 0) {
143
- return EMPTY_DATA;
144
- }
145
-
146
- // Return fresh subarray views over the pooled buffers. New view refs each call
147
- // (so React memoisation is correct and consumers can detect a change), but no
148
- // new bytes allocated on the JS heap. The GPU upload short-circuits via the
149
- // `lastUploaded === data` ref check on the program side when we hand the
150
- // exact same view back across renders -- it won't fire here since each call
151
- // produces a new view, but the contents have changed anyway in that case.
152
- return {
153
- centers: new Float32Array(centers.buffer, centers.byteOffset, cursor * 2),
154
- halfSizes: new Float32Array(halfSizes.buffer, halfSizes.byteOffset, cursor * 2),
155
- colors: new Uint8Array(colors.buffer, colors.byteOffset, cursor * 4),
156
- cornerRadii: new Float32Array(cornerRadii.buffer, cornerRadii.byteOffset, cursor * 4),
157
- count: cursor
158
- };
159
- }, [borderRadius, completedData, drawingArea.left, drawingArea.top, getHighlightState]);
10
+ return (0, _useWebGLBarLikePlotData.useWebGLBarLikePlotData)(drawingArea, completedData, borderRadius, {
11
+ highlightType: 'bar'
12
+ });
160
13
  }
@@ -1,154 +1,8 @@
1
1
  'use client';
2
2
 
3
- import * as React from 'react';
4
- import { selectorChartsHighlightStateCallback, useStore } from '@mui/x-charts/internals';
5
- import { parseColor } from "../../utils/webgl/parseColor.mjs";
6
- const EMPTY_FLOAT32 = new Float32Array(0);
7
- const EMPTY_UINT8 = new Uint8Array(0);
8
- const EMPTY_DATA = {
9
- centers: EMPTY_FLOAT32,
10
- halfSizes: EMPTY_FLOAT32,
11
- colors: EMPTY_UINT8,
12
- cornerRadii: EMPTY_FLOAT32,
13
- count: 0
14
- };
15
- function ensureCapacity(pool, maxCount) {
16
- if (pool !== null && pool.colors.length >= maxCount * 4) {
17
- return pool;
18
- }
19
- return {
20
- centers: new Float32Array(maxCount * 2),
21
- halfSizes: new Float32Array(maxCount * 2),
22
- colors: new Uint8Array(maxCount * 4),
23
- cornerRadii: new Float32Array(maxCount * 4)
24
- };
25
- }
26
-
27
- // Mirrors SVG highlight styling: highlighted -> CSS `brightness(120%)`,
28
- // faded -> opacity 0.3. Baking these into the per-bar color array means we
29
- // don't need a separate per-instance attribute on the GPU side.
30
- const HIGHLIGHTED_BRIGHTNESS = 1.2;
31
- const FADED_OPACITY = 0.3;
32
- function setCornerRadii(radius, side, target, offset) {
33
- // CSS order: top-left, top-right, bottom-right, bottom-left.
34
- let tl = 0;
35
- let tr = 0;
36
- let br = 0;
37
- let bl = 0;
38
- if (radius > 0) {
39
- if (side === 'top') {
40
- tl = radius;
41
- tr = radius;
42
- } else if (side === 'bottom') {
43
- br = radius;
44
- bl = radius;
45
- } else if (side === 'left') {
46
- tl = radius;
47
- bl = radius;
48
- } else if (side === 'right') {
49
- tr = radius;
50
- br = radius;
51
- }
52
- }
53
- target[offset] = tl;
54
- target[offset + 1] = tr;
55
- target[offset + 2] = br;
56
- target[offset + 3] = bl;
57
- }
3
+ import { useWebGLBarLikePlotData } from "./useWebGLBarLikePlotData.mjs";
58
4
  export function useBarWebGLPlotData(drawingArea, completedData, borderRadius) {
59
- const store = useStore();
60
- const getHighlightState = store.use(selectorChartsHighlightStateCallback);
61
- const poolRef = React.useRef(null);
62
- return React.useMemo(() => {
63
- let maxCount = 0;
64
- for (let s = 0; s < completedData.length; s += 1) {
65
- maxCount += completedData[s].data.length;
66
- }
67
- if (maxCount === 0) {
68
- return EMPTY_DATA;
69
- }
70
- const pool = ensureCapacity(poolRef.current, maxCount);
71
- poolRef.current = pool;
72
-
73
- // Hoist invariants out of the hot loop.
74
- const {
75
- centers,
76
- halfSizes,
77
- colors,
78
- cornerRadii
79
- } = pool;
80
- const drawingAreaLeft = drawingArea.left;
81
- const drawingAreaTop = drawingArea.top;
82
- let cursor = 0;
83
- for (let s = 0; s < completedData.length; s += 1) {
84
- const processed = completedData[s];
85
- const seriesId = processed.seriesId;
86
- const data = processed.data;
87
- const dataLength = data.length;
88
- for (let i = 0; i < dataLength; i += 1) {
89
- const bar = data[i];
90
- if (bar.hidden) {
91
- continue;
92
- }
93
- const value = bar.value;
94
- if (value == null) {
95
- continue;
96
- }
97
- const w = bar.width;
98
- const h = bar.height;
99
- if (w <= 0 || h <= 0) {
100
- continue;
101
- }
102
- const halfW = w * 0.5;
103
- const halfH = h * 0.5;
104
- const c2 = cursor * 2;
105
- centers[c2] = bar.x + halfW - drawingAreaLeft;
106
- centers[c2 + 1] = bar.y + halfH - drawingAreaTop;
107
- halfSizes[c2] = halfW;
108
- halfSizes[c2 + 1] = halfH;
109
- const rgba = parseColor(bar.color);
110
- const c4 = cursor * 4;
111
- let r = rgba[0];
112
- let g = rgba[1];
113
- let b = rgba[2];
114
- let a = rgba[3];
115
- const highlightState = getHighlightState({
116
- type: 'bar',
117
- seriesId,
118
- dataIndex: bar.dataIndex
119
- });
120
- if (highlightState === 'highlighted') {
121
- r = Math.min(255, r * HIGHLIGHTED_BRIGHTNESS);
122
- g = Math.min(255, g * HIGHLIGHTED_BRIGHTNESS);
123
- b = Math.min(255, b * HIGHLIGHTED_BRIGHTNESS);
124
- } else if (highlightState === 'faded') {
125
- a *= FADED_OPACITY;
126
- }
127
- colors[c4] = r;
128
- colors[c4 + 1] = g;
129
- colors[c4 + 2] = b;
130
- colors[c4 + 3] = a;
131
- const effectiveRadius = Math.min(borderRadius, halfW, halfH);
132
- setCornerRadii(effectiveRadius, bar.borderRadiusSide, cornerRadii, c4);
133
- cursor += 1;
134
- }
135
- }
136
- if (cursor === 0) {
137
- return EMPTY_DATA;
138
- }
139
-
140
- // Return fresh subarray views over the pooled buffers. New view refs each call
141
- // (so React memoisation is correct and consumers can detect a change), but no
142
- // new bytes allocated on the JS heap. The GPU upload short-circuits via the
143
- // `lastUploaded === data` ref check on the program side when we hand the
144
- // exact same view back across renders -- it won't fire here since each call
145
- // produces a new view, but the contents have changed anyway in that case.
146
- return {
147
- centers: new Float32Array(centers.buffer, centers.byteOffset, cursor * 2),
148
- halfSizes: new Float32Array(halfSizes.buffer, halfSizes.byteOffset, cursor * 2),
149
- colors: new Uint8Array(colors.buffer, colors.byteOffset, cursor * 4),
150
- cornerRadii: new Float32Array(cornerRadii.buffer, cornerRadii.byteOffset, cursor * 4),
151
- count: cursor
152
- };
153
- }, [borderRadius, completedData, drawingArea.left, drawingArea.top, getHighlightState]);
5
+ return useWebGLBarLikePlotData(drawingArea, completedData, borderRadius, {
6
+ highlightType: 'bar'
7
+ });
154
8
  }
@@ -0,0 +1,40 @@
1
+ import { type ChartDrawingArea } from '@mui/x-charts/hooks';
2
+ import { type BorderRadiusSide } from '@mui/x-charts/internals';
3
+ import { type SeriesId } from '@mui/x-charts/models';
4
+ export interface WebGLBarLikeItem {
5
+ x: number;
6
+ y: number;
7
+ width: number;
8
+ height: number;
9
+ value: unknown;
10
+ hidden: boolean;
11
+ color: string;
12
+ dataIndex: number;
13
+ borderRadiusSide?: BorderRadiusSide;
14
+ }
15
+ export interface WebGLBarLikeSeries<T extends WebGLBarLikeItem> {
16
+ seriesId: SeriesId;
17
+ data: readonly T[];
18
+ layout?: 'vertical' | 'horizontal';
19
+ }
20
+ export interface WebGLBarLikePlotData {
21
+ centers: Float32Array;
22
+ halfSizes: Float32Array;
23
+ colors: Uint8Array;
24
+ cornerRadii: Float32Array;
25
+ count: number;
26
+ }
27
+ export interface UseWebGLBarLikePlotDataOptions {
28
+ /**
29
+ * Series identifier passed to the highlight selector. Allows the shared
30
+ * implementation to be used for both `'bar'` and `'rangeBar'` series.
31
+ */
32
+ highlightType: 'bar' | 'rangeBar';
33
+ /**
34
+ * When true, the border radius is applied to all four corners regardless of
35
+ * the per-item `borderRadiusSide` value. Range bars use this since they
36
+ * aren't stacked.
37
+ */
38
+ fullRoundedCorners?: boolean;
39
+ }
40
+ export declare function useWebGLBarLikePlotData<T extends WebGLBarLikeItem>(drawingArea: ChartDrawingArea, completedData: readonly WebGLBarLikeSeries<T>[], borderRadius: number, options: UseWebGLBarLikePlotDataOptions): WebGLBarLikePlotData;
@@ -0,0 +1,40 @@
1
+ import { type ChartDrawingArea } from '@mui/x-charts/hooks';
2
+ import { type BorderRadiusSide } from '@mui/x-charts/internals';
3
+ import { type SeriesId } from '@mui/x-charts/models';
4
+ export interface WebGLBarLikeItem {
5
+ x: number;
6
+ y: number;
7
+ width: number;
8
+ height: number;
9
+ value: unknown;
10
+ hidden: boolean;
11
+ color: string;
12
+ dataIndex: number;
13
+ borderRadiusSide?: BorderRadiusSide;
14
+ }
15
+ export interface WebGLBarLikeSeries<T extends WebGLBarLikeItem> {
16
+ seriesId: SeriesId;
17
+ data: readonly T[];
18
+ layout?: 'vertical' | 'horizontal';
19
+ }
20
+ export interface WebGLBarLikePlotData {
21
+ centers: Float32Array;
22
+ halfSizes: Float32Array;
23
+ colors: Uint8Array;
24
+ cornerRadii: Float32Array;
25
+ count: number;
26
+ }
27
+ export interface UseWebGLBarLikePlotDataOptions {
28
+ /**
29
+ * Series identifier passed to the highlight selector. Allows the shared
30
+ * implementation to be used for both `'bar'` and `'rangeBar'` series.
31
+ */
32
+ highlightType: 'bar' | 'rangeBar';
33
+ /**
34
+ * When true, the border radius is applied to all four corners regardless of
35
+ * the per-item `borderRadiusSide` value. Range bars use this since they
36
+ * aren't stacked.
37
+ */
38
+ fullRoundedCorners?: boolean;
39
+ }
40
+ export declare function useWebGLBarLikePlotData<T extends WebGLBarLikeItem>(drawingArea: ChartDrawingArea, completedData: readonly WebGLBarLikeSeries<T>[], borderRadius: number, options: UseWebGLBarLikePlotDataOptions): WebGLBarLikePlotData;
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useWebGLBarLikePlotData = useWebGLBarLikePlotData;
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _internals = require("@mui/x-charts/internals");
11
+ var _parseColor = require("../../utils/webgl/parseColor");
12
+ const EMPTY_FLOAT32 = new Float32Array(0);
13
+ const EMPTY_UINT8 = new Uint8Array(0);
14
+ const EMPTY_DATA = {
15
+ centers: EMPTY_FLOAT32,
16
+ halfSizes: EMPTY_FLOAT32,
17
+ colors: EMPTY_UINT8,
18
+ cornerRadii: EMPTY_FLOAT32,
19
+ count: 0
20
+ };
21
+ function ensureCapacity(pool, maxCount) {
22
+ if (pool !== null && pool.colors.length >= maxCount * 4) {
23
+ return pool;
24
+ }
25
+ return {
26
+ centers: new Float32Array(maxCount * 2),
27
+ halfSizes: new Float32Array(maxCount * 2),
28
+ colors: new Uint8Array(maxCount * 4),
29
+ cornerRadii: new Float32Array(maxCount * 4)
30
+ };
31
+ }
32
+
33
+ // Mirrors SVG highlight styling: highlighted -> CSS `brightness(120%)`,
34
+ // faded -> opacity 0.3. Baking these into the per-bar color array means we
35
+ // don't need a separate per-instance attribute on the GPU side.
36
+ const HIGHLIGHTED_BRIGHTNESS = 1.2;
37
+ const FADED_OPACITY = 0.3;
38
+ // Gaps below this (CSS px) get filled by expanding band half-size to half the
39
+ // step, avoiding sub-pixel hairlines from the rasterizer.
40
+ const GAP_FILL_THRESHOLD_PX = 1;
41
+ // Floor to keep thin quads from falling between pixel centers and getting
42
+ // culled at extreme zoom-out.
43
+ const MIN_BAND_HALF_SIZE_PX = 0.5;
44
+ function setCornerRadii(radius, side, fullRounded, target, offset) {
45
+ // CSS order: top-left, top-right, bottom-right, bottom-left.
46
+ let tl = 0;
47
+ let tr = 0;
48
+ let br = 0;
49
+ let bl = 0;
50
+ if (radius > 0) {
51
+ if (fullRounded) {
52
+ tl = radius;
53
+ tr = radius;
54
+ br = radius;
55
+ bl = radius;
56
+ } else if (side === 'top') {
57
+ tl = radius;
58
+ tr = radius;
59
+ } else if (side === 'bottom') {
60
+ br = radius;
61
+ bl = radius;
62
+ } else if (side === 'left') {
63
+ tl = radius;
64
+ bl = radius;
65
+ } else if (side === 'right') {
66
+ tr = radius;
67
+ br = radius;
68
+ }
69
+ }
70
+ target[offset] = tl;
71
+ target[offset + 1] = tr;
72
+ target[offset + 2] = br;
73
+ target[offset + 3] = bl;
74
+ }
75
+ function useWebGLBarLikePlotData(drawingArea, completedData, borderRadius, options) {
76
+ const store = (0, _internals.useStore)();
77
+ const getHighlightState = store.use(_internals.selectorChartsHighlightStateCallback);
78
+ const poolRef = React.useRef(null);
79
+ const {
80
+ highlightType,
81
+ fullRoundedCorners = false
82
+ } = options;
83
+ return React.useMemo(() => {
84
+ let maxCount = 0;
85
+ for (let s = 0; s < completedData.length; s += 1) {
86
+ maxCount += completedData[s].data.length;
87
+ }
88
+ if (maxCount === 0) {
89
+ return EMPTY_DATA;
90
+ }
91
+ const pool = ensureCapacity(poolRef.current, maxCount);
92
+ poolRef.current = pool;
93
+
94
+ // Hoist invariants out of the hot loop.
95
+ const {
96
+ centers,
97
+ halfSizes,
98
+ colors,
99
+ cornerRadii
100
+ } = pool;
101
+ const drawingAreaLeft = drawingArea.left;
102
+ const drawingAreaTop = drawingArea.top;
103
+ let cursor = 0;
104
+ for (let seriesIndex = 0; seriesIndex < completedData.length; seriesIndex += 1) {
105
+ const processed = completedData[seriesIndex];
106
+ const seriesId = processed.seriesId;
107
+ const data = processed.data;
108
+ const dataLength = data.length;
109
+ const bandIsY = processed.layout === 'horizontal';
110
+
111
+ // `hidden` is series-level (mirrored onto every bar by useBarPlotData);
112
+ // peek at the first bar to skip the whole series.
113
+ if (dataLength === 0 || data[0].hidden) {
114
+ continue;
115
+ }
116
+
117
+ // Probe 1 = bar size; probe 2 = center-to-center step. Track dataIndex
118
+ // so null bars between probes don't inflate the step.
119
+ let probe = null;
120
+ let probeIndex = 0;
121
+ let probe2 = null;
122
+ let probe2Index = 0;
123
+ for (let i = 0; i < dataLength; i += 1) {
124
+ const candidate = data[i];
125
+ if (candidate.value != null && candidate.width > 0 && candidate.height > 0) {
126
+ if (probe === null) {
127
+ probe = candidate;
128
+ probeIndex = i;
129
+ } else {
130
+ probe2 = candidate;
131
+ probe2Index = i;
132
+ break;
133
+ }
134
+ }
135
+ }
136
+ if (probe === null) {
137
+ continue;
138
+ }
139
+
140
+ // Round to whole pixels so the rendered half-size stays stable across
141
+ // zoom steps; sub-pixel jitter causes an "accordion" effect.
142
+ const rawBarSize = bandIsY ? probe.height : probe.width;
143
+ const barSize = Math.round(rawBarSize);
144
+ let step;
145
+ if (probe2 === null) {
146
+ step = barSize;
147
+ } else {
148
+ const indexGap = probe2Index - probeIndex;
149
+ const span = bandIsY ? probe2.y - probe.y : probe2.x - probe.x;
150
+ step = span / indexGap;
151
+ }
152
+ // Use the linear lower bound of the gap (`step - rawBarSize - 0.5`)
153
+ // rather than `step - barSize`: rounding makes the discrete gap jump by
154
+ // 1px at zoom boundaries, flipping `fillGap` and causing visible
155
+ // oscillation. The lower bound is continuous in zoom.
156
+ const gapLowerBound = step - rawBarSize - 0.5;
157
+ const fillGap = gapLowerBound > 0 && gapLowerBound < GAP_FILL_THRESHOLD_PX;
158
+ let bandHalfRender = fillGap ? step * 0.5 : barSize * 0.5;
159
+ if (bandHalfRender < MIN_BAND_HALF_SIZE_PX) {
160
+ bandHalfRender = MIN_BAND_HALF_SIZE_PX;
161
+ }
162
+ for (let i = 0; i < dataLength; i += 1) {
163
+ const bar = data[i];
164
+ const value = bar.value;
165
+ if (value == null) {
166
+ continue;
167
+ }
168
+ const w = bar.width;
169
+ const h = bar.height;
170
+ if (w <= 0 || h <= 0) {
171
+ continue;
172
+ }
173
+ const halfW = w * 0.5;
174
+ const halfH = h * 0.5;
175
+ // Value axis stays exact; band axis uses the per-series override.
176
+ const renderHalfW = bandIsY ? halfW : bandHalfRender;
177
+ const renderHalfH = bandIsY ? bandHalfRender : halfH;
178
+ const c2 = cursor * 2;
179
+ centers[c2] = bar.x + halfW - drawingAreaLeft;
180
+ centers[c2 + 1] = bar.y + halfH - drawingAreaTop;
181
+ halfSizes[c2] = renderHalfW;
182
+ halfSizes[c2 + 1] = renderHalfH;
183
+ const rgba = (0, _parseColor.parseColor)(bar.color);
184
+ const c4 = cursor * 4;
185
+ let r = rgba[0];
186
+ let g = rgba[1];
187
+ let b = rgba[2];
188
+ let a = rgba[3];
189
+ const highlightState = getHighlightState({
190
+ type: highlightType,
191
+ seriesId,
192
+ dataIndex: bar.dataIndex
193
+ });
194
+ if (highlightState === 'highlighted') {
195
+ r = Math.min(255, r * HIGHLIGHTED_BRIGHTNESS);
196
+ g = Math.min(255, g * HIGHLIGHTED_BRIGHTNESS);
197
+ b = Math.min(255, b * HIGHLIGHTED_BRIGHTNESS);
198
+ } else if (highlightState === 'faded') {
199
+ a *= FADED_OPACITY;
200
+ }
201
+ colors[c4] = r;
202
+ colors[c4 + 1] = g;
203
+ colors[c4 + 2] = b;
204
+ colors[c4 + 3] = a;
205
+ const effectiveRadius = Math.min(borderRadius, halfW, halfH);
206
+ setCornerRadii(effectiveRadius, bar.borderRadiusSide, fullRoundedCorners, cornerRadii, c4);
207
+ cursor += 1;
208
+ }
209
+ }
210
+ if (cursor === 0) {
211
+ return EMPTY_DATA;
212
+ }
213
+
214
+ // Return fresh subarray views over the pooled buffers. New view refs each call
215
+ // (so React memoisation is correct and consumers can detect a change), but no
216
+ // new bytes allocated on the JS heap. The GPU upload short-circuits via the
217
+ // `lastUploaded === data` ref check on the program side when we hand the
218
+ // exact same view back across renders -- it won't fire here since each call
219
+ // produces a new view, but the contents have changed anyway in that case.
220
+ return {
221
+ centers: new Float32Array(centers.buffer, centers.byteOffset, cursor * 2),
222
+ halfSizes: new Float32Array(halfSizes.buffer, halfSizes.byteOffset, cursor * 2),
223
+ colors: new Uint8Array(colors.buffer, colors.byteOffset, cursor * 4),
224
+ cornerRadii: new Float32Array(cornerRadii.buffer, cornerRadii.byteOffset, cursor * 4),
225
+ count: cursor
226
+ };
227
+ }, [borderRadius, completedData, drawingArea.left, drawingArea.top, getHighlightState, highlightType, fullRoundedCorners]);
228
+ }