@mui/x-charts-premium 9.3.0 → 9.4.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/BarChartPremium/BarChartPremium.js +35 -5
- package/BarChartPremium/BarChartPremium.mjs +35 -5
- package/BarChartPremium/RangeBar/RangeBarPlot.d.mts +10 -0
- package/BarChartPremium/RangeBar/RangeBarPlot.d.ts +10 -0
- package/BarChartPremium/RangeBar/RangeBarPlot.js +59 -2
- package/BarChartPremium/RangeBar/RangeBarPlot.mjs +59 -2
- package/BarChartPremium/RangeBar/RangeBarWebGLPlot.d.mts +10 -0
- package/BarChartPremium/RangeBar/RangeBarWebGLPlot.d.ts +10 -0
- package/BarChartPremium/RangeBar/RangeBarWebGLPlot.js +82 -0
- package/BarChartPremium/RangeBar/RangeBarWebGLPlot.mjs +76 -0
- package/BarChartPremium/RangeBar/seriesConfig/extrema.js +3 -0
- package/BarChartPremium/RangeBar/seriesConfig/extrema.mjs +3 -0
- package/BarChartPremium/RangeBar/seriesConfig/seriesProcessor.js +2 -2
- package/BarChartPremium/RangeBar/seriesConfig/seriesProcessor.mjs +2 -2
- package/BarChartPremium/useBarChartPremiumProps.js +2 -1
- package/BarChartPremium/useBarChartPremiumProps.mjs +2 -1
- package/BarChartPremium/webgl/useBarWebGLPlotData.d.mts +2 -7
- package/BarChartPremium/webgl/useBarWebGLPlotData.d.ts +2 -7
- package/BarChartPremium/webgl/useBarWebGLPlotData.js +4 -151
- package/BarChartPremium/webgl/useBarWebGLPlotData.mjs +4 -150
- package/BarChartPremium/webgl/useWebGLBarLikePlotData.d.mts +39 -0
- package/BarChartPremium/webgl/useWebGLBarLikePlotData.d.ts +39 -0
- package/BarChartPremium/webgl/useWebGLBarLikePlotData.js +169 -0
- package/BarChartPremium/webgl/useWebGLBarLikePlotData.mjs +163 -0
- package/CHANGELOG.md +196 -0
- package/CandlestickChart/CandlestickChart.js +11 -2
- package/CandlestickChart/CandlestickChart.mjs +11 -2
- package/CandlestickChart/seriesConfig/extrema.js +3 -0
- package/CandlestickChart/seriesConfig/extrema.mjs +3 -0
- package/CandlestickChart/seriesConfig/seriesProcessor.js +2 -2
- package/CandlestickChart/seriesConfig/seriesProcessor.mjs +2 -2
- package/ChartsDataProviderPremium/ChartsDataProviderPremium.js +2 -2
- package/ChartsDataProviderPremium/ChartsDataProviderPremium.mjs +2 -2
- package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.d.mts +35 -0
- package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.d.ts +35 -0
- package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.js +125 -0
- package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.mjs +119 -0
- package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.plugins.d.mts +5 -0
- package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.plugins.d.ts +5 -0
- package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.plugins.js +10 -0
- package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.plugins.mjs +4 -0
- package/ChartsGeoDataProviderPremium/index.d.mts +3 -0
- package/ChartsGeoDataProviderPremium/index.d.ts +3 -0
- package/ChartsGeoDataProviderPremium/index.js +20 -0
- package/ChartsGeoDataProviderPremium/index.mjs +3 -0
- package/ChartsGeoDataProviderPremium/useChartsGeoDataProviderPremiumProps.d.mts +10 -0
- package/ChartsGeoDataProviderPremium/useChartsGeoDataProviderPremiumProps.d.ts +10 -0
- package/ChartsGeoDataProviderPremium/useChartsGeoDataProviderPremiumProps.js +49 -0
- package/ChartsGeoDataProviderPremium/useChartsGeoDataProviderPremiumProps.mjs +42 -0
- package/ChartsRadialDataProviderPremium/ChartsRadialDataProviderPremium.js +2 -2
- package/ChartsRadialDataProviderPremium/ChartsRadialDataProviderPremium.mjs +2 -2
- package/HeatmapPremium/HeatmapPremium.js +32 -2
- package/HeatmapPremium/HeatmapPremium.mjs +32 -2
- package/Map/FocusedMapShape.d.mts +4 -0
- package/Map/FocusedMapShape.d.ts +4 -0
- package/Map/FocusedMapShape.js +66 -0
- package/Map/FocusedMapShape.mjs +60 -0
- package/Map/GeoDataPlot.d.mts +26 -0
- package/Map/GeoDataPlot.d.ts +26 -0
- package/Map/GeoDataPlot.js +65 -0
- package/Map/GeoDataPlot.mjs +60 -0
- package/Map/Graticule.d.mts +1 -0
- package/Map/Graticule.d.ts +1 -0
- package/Map/Graticule.js +30 -0
- package/Map/Graticule.mjs +24 -0
- package/Map/MapShape.d.mts +10 -0
- package/Map/MapShape.d.ts +10 -0
- package/Map/MapShape.js +55 -0
- package/Map/MapShape.mjs +49 -0
- package/Map/MapShapePlot.d.mts +21 -0
- package/Map/MapShapePlot.d.ts +21 -0
- package/Map/MapShapePlot.js +86 -0
- package/Map/MapShapePlot.mjs +80 -0
- package/Map/index.d.mts +7 -0
- package/Map/index.d.ts +7 -0
- package/Map/index.js +60 -0
- package/Map/index.mjs +8 -0
- package/Map/seriesConfig/descriptionGetter.d.mts +3 -0
- package/Map/seriesConfig/descriptionGetter.d.ts +3 -0
- package/Map/seriesConfig/descriptionGetter.js +19 -0
- package/Map/seriesConfig/descriptionGetter.mjs +13 -0
- package/Map/seriesConfig/getColor.d.mts +3 -0
- package/Map/seriesConfig/getColor.d.ts +3 -0
- package/Map/seriesConfig/getColor.js +35 -0
- package/Map/seriesConfig/getColor.mjs +29 -0
- package/Map/seriesConfig/getSeriesWithDefaultValues.d.mts +3 -0
- package/Map/seriesConfig/getSeriesWithDefaultValues.d.ts +3 -0
- package/Map/seriesConfig/getSeriesWithDefaultValues.js +15 -0
- package/Map/seriesConfig/getSeriesWithDefaultValues.mjs +8 -0
- package/Map/seriesConfig/index.d.mts +2 -0
- package/Map/seriesConfig/index.d.ts +2 -0
- package/Map/seriesConfig/index.js +28 -0
- package/Map/seriesConfig/index.mjs +21 -0
- package/Map/seriesConfig/keyboardFocusHandler.d.mts +9 -0
- package/Map/seriesConfig/keyboardFocusHandler.d.ts +9 -0
- package/Map/seriesConfig/keyboardFocusHandler.js +19 -0
- package/Map/seriesConfig/keyboardFocusHandler.mjs +13 -0
- package/Map/seriesConfig/legend.d.mts +3 -0
- package/Map/seriesConfig/legend.d.ts +3 -0
- package/Map/seriesConfig/legend.js +28 -0
- package/Map/seriesConfig/legend.mjs +22 -0
- package/Map/seriesConfig/seriesProcessor.d.mts +3 -0
- package/Map/seriesConfig/seriesProcessor.d.ts +3 -0
- package/Map/seriesConfig/seriesProcessor.js +66 -0
- package/Map/seriesConfig/seriesProcessor.mjs +59 -0
- package/Map/seriesConfig/tooltip.d.mts +3 -0
- package/Map/seriesConfig/tooltip.d.ts +3 -0
- package/Map/seriesConfig/tooltip.js +33 -0
- package/Map/seriesConfig/tooltip.mjs +27 -0
- package/RadialLineChart/RadialLineHighlightPlot.d.mts +3 -2
- package/RadialLineChart/RadialLineHighlightPlot.d.ts +3 -2
- package/ScatterChartPremium/ScatterChartPremium.d.mts +2 -1
- package/ScatterChartPremium/ScatterChartPremium.d.ts +2 -1
- package/ScatterChartPremium/ScatterChartPremium.js +32 -2
- package/ScatterChartPremium/ScatterChartPremium.mjs +32 -2
- package/hooks/index.d.mts +4 -1
- package/hooks/index.d.ts +4 -1
- package/hooks/index.js +33 -0
- package/hooks/index.mjs +4 -1
- package/hooks/useGeoData.d.mts +6 -0
- package/hooks/useGeoData.d.ts +6 -0
- package/hooks/useGeoData.js +17 -0
- package/hooks/useGeoData.mjs +13 -0
- package/hooks/useGeoFeatureIndexesByName.d.mts +7 -0
- package/hooks/useGeoFeatureIndexesByName.d.ts +7 -0
- package/hooks/useGeoFeatureIndexesByName.js +19 -0
- package/hooks/useGeoFeatureIndexesByName.mjs +15 -0
- package/hooks/useGeoPath.d.mts +6 -0
- package/hooks/useGeoPath.d.ts +6 -0
- package/hooks/useGeoPath.js +17 -0
- package/hooks/useGeoPath.mjs +13 -0
- package/hooks/useMapShapeSeries.d.mts +34 -0
- package/hooks/useMapShapeSeries.d.ts +34 -0
- package/hooks/useMapShapeSeries.js +45 -0
- package/hooks/useMapShapeSeries.mjs +40 -0
- package/index.d.mts +2 -0
- package/index.d.ts +2 -0
- package/index.js +25 -1
- package/index.mjs +3 -1
- package/internals/plugins/useGeoProjection/index.d.mts +3 -0
- package/internals/plugins/useGeoProjection/index.d.ts +3 -0
- package/internals/plugins/useGeoProjection/index.js +38 -0
- package/internals/plugins/useGeoProjection/index.mjs +3 -0
- package/internals/plugins/useGeoProjection/useGeoProjection.d.mts +3 -0
- package/internals/plugins/useGeoProjection/useGeoProjection.d.ts +3 -0
- package/internals/plugins/useGeoProjection/useGeoProjection.js +58 -0
- package/internals/plugins/useGeoProjection/useGeoProjection.mjs +50 -0
- package/internals/plugins/useGeoProjection/useGeoProjection.selectors.d.mts +39 -0
- package/internals/plugins/useGeoProjection/useGeoProjection.selectors.d.ts +39 -0
- package/internals/plugins/useGeoProjection/useGeoProjection.selectors.js +135 -0
- package/internals/plugins/useGeoProjection/useGeoProjection.selectors.mjs +128 -0
- package/internals/plugins/useGeoProjection/useGeoProjection.types.d.mts +55 -0
- package/internals/plugins/useGeoProjection/useGeoProjection.types.d.ts +55 -0
- package/internals/plugins/useGeoProjection/useGeoProjection.types.js +5 -0
- package/internals/plugins/useGeoProjection/useGeoProjection.types.mjs +1 -0
- package/models/chartsSlotsComponentsPropsPremium.d.mts +1 -0
- package/models/chartsSlotsComponentsPropsPremium.d.ts +1 -0
- package/models/chartsSlotsComponentsPropsPremium.js +5 -0
- package/models/chartsSlotsComponentsPropsPremium.mjs +1 -0
- package/models/index.d.mts +2 -1
- package/models/index.d.ts +2 -1
- package/models/index.js +11 -0
- package/models/index.mjs +2 -1
- package/models/seriesType/index.d.mts +2 -1
- package/models/seriesType/index.d.ts +2 -1
- package/models/seriesType/index.js +11 -0
- package/models/seriesType/index.mjs +2 -1
- package/models/seriesType/mapShape.d.mts +105 -0
- package/models/seriesType/mapShape.d.ts +105 -0
- package/models/seriesType/mapShape.js +5 -0
- package/models/seriesType/mapShape.mjs +1 -0
- package/package.json +35 -7
- package/typeOverloads/modules.d.mts +16 -1
- package/typeOverloads/modules.d.ts +16 -1
- package/utils/webgl/useWebGLResizeObserver.js +3 -3
- 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
|
-
|
|
4
|
-
|
|
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
|
-
|
|
4
|
-
|
|
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
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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,39 @@
|
|
|
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
|
+
}
|
|
19
|
+
export interface WebGLBarLikePlotData {
|
|
20
|
+
centers: Float32Array;
|
|
21
|
+
halfSizes: Float32Array;
|
|
22
|
+
colors: Uint8Array;
|
|
23
|
+
cornerRadii: Float32Array;
|
|
24
|
+
count: number;
|
|
25
|
+
}
|
|
26
|
+
export interface UseWebGLBarLikePlotDataOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Series identifier passed to the highlight selector. Allows the shared
|
|
29
|
+
* implementation to be used for both `'bar'` and `'rangeBar'` series.
|
|
30
|
+
*/
|
|
31
|
+
highlightType: 'bar' | 'rangeBar';
|
|
32
|
+
/**
|
|
33
|
+
* When true, the border radius is applied to all four corners regardless of
|
|
34
|
+
* the per-item `borderRadiusSide` value. Range bars use this since they
|
|
35
|
+
* aren't stacked.
|
|
36
|
+
*/
|
|
37
|
+
fullRoundedCorners?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare function useWebGLBarLikePlotData<T extends WebGLBarLikeItem>(drawingArea: ChartDrawingArea, completedData: readonly WebGLBarLikeSeries<T>[], borderRadius: number, options: UseWebGLBarLikePlotDataOptions): WebGLBarLikePlotData;
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
}
|
|
19
|
+
export interface WebGLBarLikePlotData {
|
|
20
|
+
centers: Float32Array;
|
|
21
|
+
halfSizes: Float32Array;
|
|
22
|
+
colors: Uint8Array;
|
|
23
|
+
cornerRadii: Float32Array;
|
|
24
|
+
count: number;
|
|
25
|
+
}
|
|
26
|
+
export interface UseWebGLBarLikePlotDataOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Series identifier passed to the highlight selector. Allows the shared
|
|
29
|
+
* implementation to be used for both `'bar'` and `'rangeBar'` series.
|
|
30
|
+
*/
|
|
31
|
+
highlightType: 'bar' | 'rangeBar';
|
|
32
|
+
/**
|
|
33
|
+
* When true, the border radius is applied to all four corners regardless of
|
|
34
|
+
* the per-item `borderRadiusSide` value. Range bars use this since they
|
|
35
|
+
* aren't stacked.
|
|
36
|
+
*/
|
|
37
|
+
fullRoundedCorners?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare function useWebGLBarLikePlotData<T extends WebGLBarLikeItem>(drawingArea: ChartDrawingArea, completedData: readonly WebGLBarLikeSeries<T>[], borderRadius: number, options: UseWebGLBarLikePlotDataOptions): WebGLBarLikePlotData;
|
|
@@ -0,0 +1,169 @@
|
|
|
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
|
+
function setCornerRadii(radius, side, fullRounded, 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 (fullRounded) {
|
|
46
|
+
tl = radius;
|
|
47
|
+
tr = radius;
|
|
48
|
+
br = radius;
|
|
49
|
+
bl = radius;
|
|
50
|
+
} else if (side === 'top') {
|
|
51
|
+
tl = radius;
|
|
52
|
+
tr = radius;
|
|
53
|
+
} else if (side === 'bottom') {
|
|
54
|
+
br = radius;
|
|
55
|
+
bl = radius;
|
|
56
|
+
} else if (side === 'left') {
|
|
57
|
+
tl = radius;
|
|
58
|
+
bl = radius;
|
|
59
|
+
} else if (side === 'right') {
|
|
60
|
+
tr = radius;
|
|
61
|
+
br = radius;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
target[offset] = tl;
|
|
65
|
+
target[offset + 1] = tr;
|
|
66
|
+
target[offset + 2] = br;
|
|
67
|
+
target[offset + 3] = bl;
|
|
68
|
+
}
|
|
69
|
+
function useWebGLBarLikePlotData(drawingArea, completedData, borderRadius, options) {
|
|
70
|
+
const store = (0, _internals.useStore)();
|
|
71
|
+
const getHighlightState = store.use(_internals.selectorChartsHighlightStateCallback);
|
|
72
|
+
const poolRef = React.useRef(null);
|
|
73
|
+
const {
|
|
74
|
+
highlightType,
|
|
75
|
+
fullRoundedCorners = false
|
|
76
|
+
} = options;
|
|
77
|
+
return React.useMemo(() => {
|
|
78
|
+
let maxCount = 0;
|
|
79
|
+
for (let s = 0; s < completedData.length; s += 1) {
|
|
80
|
+
maxCount += completedData[s].data.length;
|
|
81
|
+
}
|
|
82
|
+
if (maxCount === 0) {
|
|
83
|
+
return EMPTY_DATA;
|
|
84
|
+
}
|
|
85
|
+
const pool = ensureCapacity(poolRef.current, maxCount);
|
|
86
|
+
poolRef.current = pool;
|
|
87
|
+
|
|
88
|
+
// Hoist invariants out of the hot loop.
|
|
89
|
+
const {
|
|
90
|
+
centers,
|
|
91
|
+
halfSizes,
|
|
92
|
+
colors,
|
|
93
|
+
cornerRadii
|
|
94
|
+
} = pool;
|
|
95
|
+
const drawingAreaLeft = drawingArea.left;
|
|
96
|
+
const drawingAreaTop = drawingArea.top;
|
|
97
|
+
let cursor = 0;
|
|
98
|
+
for (let s = 0; s < completedData.length; s += 1) {
|
|
99
|
+
const processed = completedData[s];
|
|
100
|
+
const seriesId = processed.seriesId;
|
|
101
|
+
const data = processed.data;
|
|
102
|
+
const dataLength = data.length;
|
|
103
|
+
for (let i = 0; i < dataLength; i += 1) {
|
|
104
|
+
const bar = data[i];
|
|
105
|
+
if (bar.hidden) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const value = bar.value;
|
|
109
|
+
if (value == null) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const w = bar.width;
|
|
113
|
+
const h = bar.height;
|
|
114
|
+
if (w <= 0 || h <= 0) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const halfW = w * 0.5;
|
|
118
|
+
const halfH = h * 0.5;
|
|
119
|
+
const c2 = cursor * 2;
|
|
120
|
+
centers[c2] = bar.x + halfW - drawingAreaLeft;
|
|
121
|
+
centers[c2 + 1] = bar.y + halfH - drawingAreaTop;
|
|
122
|
+
halfSizes[c2] = halfW;
|
|
123
|
+
halfSizes[c2 + 1] = halfH;
|
|
124
|
+
const rgba = (0, _parseColor.parseColor)(bar.color);
|
|
125
|
+
const c4 = cursor * 4;
|
|
126
|
+
let r = rgba[0];
|
|
127
|
+
let g = rgba[1];
|
|
128
|
+
let b = rgba[2];
|
|
129
|
+
let a = rgba[3];
|
|
130
|
+
const highlightState = getHighlightState({
|
|
131
|
+
type: highlightType,
|
|
132
|
+
seriesId,
|
|
133
|
+
dataIndex: bar.dataIndex
|
|
134
|
+
});
|
|
135
|
+
if (highlightState === 'highlighted') {
|
|
136
|
+
r = Math.min(255, r * HIGHLIGHTED_BRIGHTNESS);
|
|
137
|
+
g = Math.min(255, g * HIGHLIGHTED_BRIGHTNESS);
|
|
138
|
+
b = Math.min(255, b * HIGHLIGHTED_BRIGHTNESS);
|
|
139
|
+
} else if (highlightState === 'faded') {
|
|
140
|
+
a *= FADED_OPACITY;
|
|
141
|
+
}
|
|
142
|
+
colors[c4] = r;
|
|
143
|
+
colors[c4 + 1] = g;
|
|
144
|
+
colors[c4 + 2] = b;
|
|
145
|
+
colors[c4 + 3] = a;
|
|
146
|
+
const effectiveRadius = Math.min(borderRadius, halfW, halfH);
|
|
147
|
+
setCornerRadii(effectiveRadius, bar.borderRadiusSide, fullRoundedCorners, cornerRadii, c4);
|
|
148
|
+
cursor += 1;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (cursor === 0) {
|
|
152
|
+
return EMPTY_DATA;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Return fresh subarray views over the pooled buffers. New view refs each call
|
|
156
|
+
// (so React memoisation is correct and consumers can detect a change), but no
|
|
157
|
+
// new bytes allocated on the JS heap. The GPU upload short-circuits via the
|
|
158
|
+
// `lastUploaded === data` ref check on the program side when we hand the
|
|
159
|
+
// exact same view back across renders -- it won't fire here since each call
|
|
160
|
+
// produces a new view, but the contents have changed anyway in that case.
|
|
161
|
+
return {
|
|
162
|
+
centers: new Float32Array(centers.buffer, centers.byteOffset, cursor * 2),
|
|
163
|
+
halfSizes: new Float32Array(halfSizes.buffer, halfSizes.byteOffset, cursor * 2),
|
|
164
|
+
colors: new Uint8Array(colors.buffer, colors.byteOffset, cursor * 4),
|
|
165
|
+
cornerRadii: new Float32Array(cornerRadii.buffer, cornerRadii.byteOffset, cursor * 4),
|
|
166
|
+
count: cursor
|
|
167
|
+
};
|
|
168
|
+
}, [borderRadius, completedData, drawingArea.left, drawingArea.top, getHighlightState, highlightType, fullRoundedCorners]);
|
|
169
|
+
}
|