@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.
- package/BarChartPremium/webgl/BarWebGLProgram.d.mts +4 -5
- package/BarChartPremium/webgl/BarWebGLProgram.d.ts +4 -5
- package/BarChartPremium/webgl/BarWebGLProgram.js +24 -65
- package/BarChartPremium/webgl/BarWebGLProgram.mjs +24 -65
- package/BarChartPremium/webgl/shaders.d.mts +1 -1
- package/BarChartPremium/webgl/shaders.d.ts +1 -1
- package/BarChartPremium/webgl/shaders.js +2 -15
- package/BarChartPremium/webgl/shaders.mjs +3 -15
- package/CHANGELOG.md +130 -1
- package/ChartsDataProviderPremium/ChartsDataProviderPremium.js +2 -2
- package/ChartsDataProviderPremium/ChartsDataProviderPremium.mjs +2 -2
- package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.js +2 -2
- package/ChartsGeoDataProviderPremium/ChartsGeoDataProviderPremium.mjs +2 -2
- package/ChartsRadialDataProviderPremium/ChartsRadialDataProviderPremium.js +2 -2
- package/ChartsRadialDataProviderPremium/ChartsRadialDataProviderPremium.mjs +2 -2
- package/HeatmapPremium/webgl/HeatmapWebGLProgram.js +12 -37
- package/HeatmapPremium/webgl/HeatmapWebGLProgram.mjs +12 -37
- package/HeatmapPremium/webgl/shaders.d.mts +3 -3
- package/HeatmapPremium/webgl/shaders.d.ts +3 -3
- package/HeatmapPremium/webgl/shaders.js +12 -15
- package/HeatmapPremium/webgl/shaders.mjs +13 -15
- package/HeatmapPremium/webgl/useHeatmapPlotData.js +3 -8
- package/HeatmapPremium/webgl/useHeatmapPlotData.mjs +3 -8
- package/Map/FocusedMapShape.js +5 -1
- package/Map/FocusedMapShape.mjs +5 -1
- package/Map/MapImagePlot.d.mts +39 -0
- package/Map/MapImagePlot.d.ts +39 -0
- package/Map/MapImagePlot.js +138 -0
- package/Map/MapImagePlot.mjs +132 -0
- package/Map/MapShape.d.mts +1 -1
- package/Map/MapShape.d.ts +1 -1
- package/Map/MapShape.js +6 -6
- package/Map/MapShape.mjs +6 -6
- package/Map/MapShapePlot.d.mts +8 -0
- package/Map/MapShapePlot.d.ts +8 -0
- package/Map/MapShapePlot.js +17 -5
- package/Map/MapShapePlot.mjs +17 -5
- package/Map/index.d.mts +1 -0
- package/Map/index.d.ts +1 -0
- package/Map/index.js +11 -0
- package/Map/index.mjs +1 -0
- package/Map/reprojectEquirectangularImage.d.mts +60 -0
- package/Map/reprojectEquirectangularImage.d.ts +60 -0
- package/Map/reprojectEquirectangularImage.js +116 -0
- package/Map/reprojectEquirectangularImage.mjs +110 -0
- package/Map/seriesConfig/descriptionGetter.js +5 -1
- package/Map/seriesConfig/descriptionGetter.mjs +5 -1
- package/Map/seriesConfig/getColor.js +18 -6
- package/Map/seriesConfig/getColor.mjs +18 -6
- package/Map/seriesConfig/highlight.d.mts +10 -0
- package/Map/seriesConfig/highlight.d.ts +10 -0
- package/Map/seriesConfig/highlight.js +52 -0
- package/Map/seriesConfig/highlight.mjs +45 -0
- package/Map/seriesConfig/identifierCleaner.d.mts +3 -0
- package/Map/seriesConfig/identifierCleaner.d.ts +3 -0
- package/Map/seriesConfig/identifierCleaner.js +14 -0
- package/Map/seriesConfig/identifierCleaner.mjs +8 -0
- package/Map/seriesConfig/identifierSerializer.d.mts +3 -0
- package/Map/seriesConfig/identifierSerializer.d.ts +3 -0
- package/Map/seriesConfig/identifierSerializer.js +12 -0
- package/Map/seriesConfig/identifierSerializer.mjs +6 -0
- package/Map/seriesConfig/index.js +8 -6
- package/Map/seriesConfig/index.mjs +7 -5
- package/Map/seriesConfig/keyboardFocusHandler.d.mts +0 -6
- package/Map/seriesConfig/keyboardFocusHandler.d.ts +0 -6
- package/Map/seriesConfig/keyboardFocusHandler.js +40 -7
- package/Map/seriesConfig/keyboardFocusHandler.mjs +41 -8
- package/Map/seriesConfig/seriesProcessor.js +11 -2
- package/Map/seriesConfig/seriesProcessor.mjs +11 -2
- package/Map/seriesConfig/tooltip.js +8 -4
- package/Map/seriesConfig/tooltip.mjs +8 -4
- package/Map/seriesConfig/tooltipPosition.d.mts +8 -3
- package/Map/seriesConfig/tooltipPosition.d.ts +8 -3
- package/Map/seriesConfig/tooltipPosition.js +21 -27
- package/Map/seriesConfig/tooltipPosition.mjs +22 -27
- package/ScatterChartPremium/webgl/ScatterWebGLProgram.d.mts +0 -2
- package/ScatterChartPremium/webgl/ScatterWebGLProgram.d.ts +0 -2
- package/ScatterChartPremium/webgl/ScatterWebGLProgram.js +23 -81
- package/ScatterChartPremium/webgl/ScatterWebGLProgram.mjs +23 -81
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/internals/createGetVisibleCoordinate.d.mts +14 -0
- package/internals/createGetVisibleCoordinate.d.ts +14 -0
- package/internals/createGetVisibleCoordinate.js +66 -0
- package/internals/createGetVisibleCoordinate.mjs +60 -0
- package/models/seriesType/mapShape.d.mts +2 -1
- package/models/seriesType/mapShape.d.ts +2 -1
- package/package.json +5 -5
- package/utils/webgl/glsl.d.mts +15 -0
- package/utils/webgl/glsl.d.ts +15 -0
- package/utils/webgl/glsl.js +34 -0
- package/utils/webgl/glsl.mjs +28 -0
- package/utils/webgl/instancedAttribute.d.mts +28 -0
- package/utils/webgl/instancedAttribute.d.ts +28 -0
- package/utils/webgl/instancedAttribute.js +57 -0
- package/utils/webgl/instancedAttribute.mjs +50 -0
- package/utils/webgl/utils.d.mts +21 -2
- package/utils/webgl/utils.d.ts +21 -2
- package/utils/webgl/utils.js +44 -8
- package/utils/webgl/utils.mjs +41 -7
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
|
|
2
3
|
import { incompleteDatasetKeysError } from '@mui/x-charts/internals';
|
|
3
4
|
const defaultValueFormatter = v => v == null ? '' : String(v.value);
|
|
4
5
|
const seriesProcessor = ({
|
|
@@ -34,16 +35,24 @@ const seriesProcessor = ({
|
|
|
34
35
|
} else {
|
|
35
36
|
data = input.data ?? [];
|
|
36
37
|
}
|
|
38
|
+
const lookupByName = new Map();
|
|
39
|
+
data.forEach((item, index) => {
|
|
40
|
+
if (lookupByName.has(item.name)) {
|
|
41
|
+
throw new Error(process.env.NODE_ENV !== "production" ? `MUI X Charts: Series "${seriesId}" has a duplicated name "${item.name}".\n` + `Map shapes are identified by their name, so duplicates cannot be told apart for coloring, tooltips, and highlighting.\n` + `Ensure each data entry has a unique name.` : _formatErrorMessage(294, seriesId, item.name));
|
|
42
|
+
}
|
|
43
|
+
lookupByName.set(item.name, index);
|
|
44
|
+
});
|
|
37
45
|
defaultizedSeries[seriesId] = _extends({
|
|
38
46
|
labelMarkType: 'square'
|
|
39
47
|
}, input, {
|
|
40
|
-
data: data.map(
|
|
48
|
+
data: data.map(item => _extends({}, item, {
|
|
41
49
|
hidden: !isItemVisible?.({
|
|
42
50
|
type: 'mapShape',
|
|
43
51
|
seriesId,
|
|
44
|
-
|
|
52
|
+
name: item.name
|
|
45
53
|
})
|
|
46
54
|
})),
|
|
55
|
+
lookupByName,
|
|
47
56
|
hidden: !isItemVisible?.({
|
|
48
57
|
type: 'mapShape',
|
|
49
58
|
seriesId
|
|
@@ -10,20 +10,24 @@ const tooltipGetter = ({
|
|
|
10
10
|
getColor,
|
|
11
11
|
identifier
|
|
12
12
|
}) => {
|
|
13
|
-
if (!identifier || identifier.
|
|
13
|
+
if (!identifier || identifier.name === undefined) {
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
|
-
const
|
|
16
|
+
const index = series.lookupByName.get(identifier.name);
|
|
17
|
+
if (index === undefined) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const point = series.data[index];
|
|
17
21
|
if (point == null) {
|
|
18
22
|
return null;
|
|
19
23
|
}
|
|
20
|
-
const color = getColor(identifier.
|
|
24
|
+
const color = getColor(identifier.name);
|
|
21
25
|
if (color === null) {
|
|
22
26
|
return null;
|
|
23
27
|
}
|
|
24
28
|
const label = (0, _internals.getLabel)(point.label ?? point.name, 'tooltip');
|
|
25
29
|
const formattedValue = series.valueFormatter(point, {
|
|
26
|
-
dataIndex:
|
|
30
|
+
dataIndex: index
|
|
27
31
|
});
|
|
28
32
|
return {
|
|
29
33
|
identifier,
|
|
@@ -4,20 +4,24 @@ const tooltipGetter = ({
|
|
|
4
4
|
getColor,
|
|
5
5
|
identifier
|
|
6
6
|
}) => {
|
|
7
|
-
if (!identifier || identifier.
|
|
7
|
+
if (!identifier || identifier.name === undefined) {
|
|
8
8
|
return null;
|
|
9
9
|
}
|
|
10
|
-
const
|
|
10
|
+
const index = series.lookupByName.get(identifier.name);
|
|
11
|
+
if (index === undefined) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const point = series.data[index];
|
|
11
15
|
if (point == null) {
|
|
12
16
|
return null;
|
|
13
17
|
}
|
|
14
|
-
const color = getColor(identifier.
|
|
18
|
+
const color = getColor(identifier.name);
|
|
15
19
|
if (color === null) {
|
|
16
20
|
return null;
|
|
17
21
|
}
|
|
18
22
|
const label = getLabel(point.label ?? point.name, 'tooltip');
|
|
19
23
|
const formattedValue = series.valueFormatter(point, {
|
|
20
|
-
dataIndex:
|
|
24
|
+
dataIndex: index
|
|
21
25
|
});
|
|
22
26
|
return {
|
|
23
27
|
identifier,
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { TooltipItemPositionSelector } from '@mui/x-charts/internals';
|
|
2
|
+
/**
|
|
3
|
+
* Positions a map shape tooltip from the geo projection. It lives in the map
|
|
4
|
+
* series config (rather than the core tooltip plugin) so the geo projection is a
|
|
5
|
+
* tracked dependency and d3-geo is only bundled with map charts.
|
|
6
|
+
*/
|
|
7
|
+
declare const selectorTooltipItemPosition: TooltipItemPositionSelector;
|
|
8
|
+
export default selectorTooltipItemPosition;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { TooltipItemPositionSelector } from '@mui/x-charts/internals';
|
|
2
|
+
/**
|
|
3
|
+
* Positions a map shape tooltip from the geo projection. It lives in the map
|
|
4
|
+
* series config (rather than the core tooltip plugin) so the geo projection is a
|
|
5
|
+
* tracked dependency and d3-geo is only bundled with map charts.
|
|
6
|
+
*/
|
|
7
|
+
declare const selectorTooltipItemPosition: TooltipItemPositionSelector;
|
|
8
|
+
export default selectorTooltipItemPosition;
|
|
@@ -5,39 +5,33 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _d3Geo = require("@mui/x-charts-vendor/d3-geo");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
var _store = require("@mui/x-internals/store");
|
|
9
|
+
var _internals = require("@mui/x-charts/internals");
|
|
10
|
+
/**
|
|
11
|
+
* Positions a map shape tooltip from the geo projection. It lives in the map
|
|
12
|
+
* series config (rather than the core tooltip plugin) so the geo projection is a
|
|
13
|
+
* tracked dependency and d3-geo is only bundled with map charts.
|
|
14
|
+
*/
|
|
15
|
+
const selectorTooltipItemPosition = (0, _store.createSelectorMemoized)(_internals.selectorChartsTooltipItem, _internals.useGeoProjectionSelectors.selectorGeoTooltipPosition,
|
|
16
|
+
// `selectorChartsTooltipItem` is typed with the community series types, which
|
|
17
|
+
// don't include `mapShape`, so the identifier is matched structurally here.
|
|
18
|
+
(identifier, {
|
|
19
|
+
projection,
|
|
20
|
+
geoData,
|
|
21
|
+
featureIndexesByName
|
|
22
|
+
}, position) => {
|
|
23
|
+
if (identifier?.type !== 'mapShape' || identifier.name === undefined) {
|
|
16
24
|
return null;
|
|
17
25
|
}
|
|
18
|
-
const itemSeries = series.mapShape?.series[identifier.seriesId];
|
|
19
|
-
if (itemSeries == null) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
if (axesConfig.geo === undefined) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
const {
|
|
26
|
-
projection,
|
|
27
|
-
geoData,
|
|
28
|
-
featureIndexesByName
|
|
29
|
-
} = axesConfig.geo;
|
|
30
26
|
if (projection == null || geoData == null) {
|
|
31
27
|
return null;
|
|
32
28
|
}
|
|
33
|
-
const featureIndex = featureIndexesByName.get(
|
|
29
|
+
const featureIndex = featureIndexesByName.get(identifier.name)?.[0];
|
|
34
30
|
if (featureIndex === undefined) {
|
|
35
31
|
return null;
|
|
36
32
|
}
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const [[x0, y0], [x1, y1]] = path.bounds(feature);
|
|
40
|
-
switch (placement) {
|
|
33
|
+
const [[x0, y0], [x1, y1]] = (0, _d3Geo.geoPath)(projection).bounds(geoData.features[featureIndex]);
|
|
34
|
+
switch (position) {
|
|
41
35
|
case 'right':
|
|
42
36
|
return {
|
|
43
37
|
x: x1,
|
|
@@ -60,5 +54,5 @@ const tooltipItemPositionGetter = params => {
|
|
|
60
54
|
y: y0
|
|
61
55
|
};
|
|
62
56
|
}
|
|
63
|
-
};
|
|
64
|
-
var _default = exports.default =
|
|
57
|
+
});
|
|
58
|
+
var _default = exports.default = selectorTooltipItemPosition;
|
|
@@ -1,37 +1,32 @@
|
|
|
1
1
|
import { geoPath } from '@mui/x-charts-vendor/d3-geo';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import { createSelectorMemoized } from '@mui/x-internals/store';
|
|
3
|
+
import { selectorChartsTooltipItem, useGeoProjectionSelectors } from '@mui/x-charts/internals';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Positions a map shape tooltip from the geo projection. It lives in the map
|
|
7
|
+
* series config (rather than the core tooltip plugin) so the geo projection is a
|
|
8
|
+
* tracked dependency and d3-geo is only bundled with map charts.
|
|
9
|
+
*/
|
|
10
|
+
const selectorTooltipItemPosition = createSelectorMemoized(selectorChartsTooltipItem, useGeoProjectionSelectors.selectorGeoTooltipPosition,
|
|
11
|
+
// `selectorChartsTooltipItem` is typed with the community series types, which
|
|
12
|
+
// don't include `mapShape`, so the identifier is matched structurally here.
|
|
13
|
+
(identifier, {
|
|
14
|
+
projection,
|
|
15
|
+
geoData,
|
|
16
|
+
featureIndexesByName
|
|
17
|
+
}, position) => {
|
|
18
|
+
if (identifier?.type !== 'mapShape' || identifier.name === undefined) {
|
|
10
19
|
return null;
|
|
11
20
|
}
|
|
12
|
-
const itemSeries = series.mapShape?.series[identifier.seriesId];
|
|
13
|
-
if (itemSeries == null) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
if (axesConfig.geo === undefined) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
const {
|
|
20
|
-
projection,
|
|
21
|
-
geoData,
|
|
22
|
-
featureIndexesByName
|
|
23
|
-
} = axesConfig.geo;
|
|
24
21
|
if (projection == null || geoData == null) {
|
|
25
22
|
return null;
|
|
26
23
|
}
|
|
27
|
-
const featureIndex = featureIndexesByName.get(
|
|
24
|
+
const featureIndex = featureIndexesByName.get(identifier.name)?.[0];
|
|
28
25
|
if (featureIndex === undefined) {
|
|
29
26
|
return null;
|
|
30
27
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const [[x0, y0], [x1, y1]] = path.bounds(feature);
|
|
34
|
-
switch (placement) {
|
|
28
|
+
const [[x0, y0], [x1, y1]] = geoPath(projection).bounds(geoData.features[featureIndex]);
|
|
29
|
+
switch (position) {
|
|
35
30
|
case 'right':
|
|
36
31
|
return {
|
|
37
32
|
x: x1,
|
|
@@ -54,5 +49,5 @@ const tooltipItemPositionGetter = params => {
|
|
|
54
49
|
y: y0
|
|
55
50
|
};
|
|
56
51
|
}
|
|
57
|
-
};
|
|
58
|
-
export default
|
|
52
|
+
});
|
|
53
|
+
export default selectorTooltipItemPosition;
|
|
@@ -5,32 +5,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ScatterWebGLProgram = void 0;
|
|
7
7
|
var _utils = require("../../utils/webgl/utils");
|
|
8
|
+
var _instancedAttribute = require("../../utils/webgl/instancedAttribute");
|
|
8
9
|
var _shaders = require("./shaders");
|
|
9
|
-
const QUAD_VERTICES = new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]);
|
|
10
10
|
class ScatterWebGLProgram {
|
|
11
11
|
shaders = [];
|
|
12
|
+
|
|
13
|
+
/* Colors come in as Uint8 [0, 255]; normalized=true makes the GPU read them back as vec4 in [0, 1]. */
|
|
14
|
+
|
|
12
15
|
constructor(gl) {
|
|
13
16
|
this.gl = gl;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const prog = initializeProgram(gl, _shaders.scatterVertexShader, _shaders.scatterFragmentShader);
|
|
20
|
-
this.program = prog.program;
|
|
21
|
-
this.shaders.push(prog.vertexShader, prog.fragmentShader);
|
|
17
|
+
(0, _utils.setupStandardBlending)(gl);
|
|
18
|
+
const linked = (0, _utils.linkProgram)(gl, _shaders.scatterVertexShader, _shaders.scatterFragmentShader);
|
|
19
|
+
this.program = linked.program;
|
|
20
|
+
this.shaders.push(...linked.shaders);
|
|
21
|
+
this.quadBuffer = (0, _utils.uploadQuadBuffer)(gl);
|
|
22
22
|
this.vao = gl.createVertexArray();
|
|
23
23
|
gl.bindVertexArray(this.vao);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
gl.enableVertexAttribArray(aPosition);
|
|
29
|
-
gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, 0, 0);
|
|
30
|
-
this.centers = this.setupInstancedAttribute('a_center', 2, gl.FLOAT, false);
|
|
31
|
-
this.sizes = this.setupInstancedAttribute('a_size', 1, gl.FLOAT, false);
|
|
32
|
-
// Colors come in as Uint8 [0, 255]; normalized=true makes the GPU read them back as vec4 in [0, 1].
|
|
33
|
-
this.colors = this.setupInstancedAttribute('a_color', 4, gl.UNSIGNED_BYTE, true);
|
|
24
|
+
(0, _utils.bindQuadBuffer)(gl, this.program, this.quadBuffer);
|
|
25
|
+
this.centers = (0, _instancedAttribute.createInstancedAttribute)(gl, this.program, 'a_center', 2);
|
|
26
|
+
this.sizes = (0, _instancedAttribute.createInstancedAttribute)(gl, this.program, 'a_size', 1);
|
|
27
|
+
this.colors = (0, _instancedAttribute.createInstancedAttribute)(gl, this.program, 'a_color', 4, gl.UNSIGNED_BYTE, true);
|
|
34
28
|
gl.bindVertexArray(null);
|
|
35
29
|
}
|
|
36
30
|
setResolution(width, height) {
|
|
@@ -41,9 +35,12 @@ class ScatterWebGLProgram {
|
|
|
41
35
|
gl.uniform2f(gl.getUniformLocation(this.program, 'u_resolution'), width, height);
|
|
42
36
|
}
|
|
43
37
|
plot(plotData) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this
|
|
38
|
+
const {
|
|
39
|
+
gl
|
|
40
|
+
} = this;
|
|
41
|
+
(0, _utils.uploadGrowableBuffer)(gl, this.centers.buffer, plotData.centers);
|
|
42
|
+
(0, _utils.uploadGrowableBuffer)(gl, this.sizes.buffer, plotData.sizes);
|
|
43
|
+
(0, _utils.uploadGrowableBuffer)(gl, this.colors.buffer, plotData.colors);
|
|
47
44
|
}
|
|
48
45
|
render(plotData) {
|
|
49
46
|
if (plotData.pointCount === 0) {
|
|
@@ -64,66 +61,11 @@ class ScatterWebGLProgram {
|
|
|
64
61
|
} = this;
|
|
65
62
|
gl.deleteProgram(this.program);
|
|
66
63
|
gl.deleteVertexArray(this.vao);
|
|
67
|
-
gl.deleteBuffer(this.centers.buffer);
|
|
68
|
-
gl.deleteBuffer(this.sizes.buffer);
|
|
69
|
-
gl.deleteBuffer(this.colors.buffer);
|
|
64
|
+
gl.deleteBuffer(this.centers.buffer.buffer);
|
|
65
|
+
gl.deleteBuffer(this.sizes.buffer.buffer);
|
|
66
|
+
gl.deleteBuffer(this.colors.buffer.buffer);
|
|
70
67
|
gl.deleteBuffer(this.quadBuffer);
|
|
71
68
|
this.shaders.forEach(shader => gl.deleteShader(shader));
|
|
72
69
|
}
|
|
73
|
-
|
|
74
|
-
// Assumes the owning VAO (Vertex Array Object) is already bound.
|
|
75
|
-
setupInstancedAttribute(name, size, glType, normalized) {
|
|
76
|
-
const {
|
|
77
|
-
gl,
|
|
78
|
-
program
|
|
79
|
-
} = this;
|
|
80
|
-
const buffer = gl.createBuffer();
|
|
81
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
82
|
-
const location = gl.getAttribLocation(program, name);
|
|
83
|
-
gl.enableVertexAttribArray(location);
|
|
84
|
-
gl.vertexAttribPointer(location, size, glType, normalized, 0, 0);
|
|
85
|
-
gl.vertexAttribDivisor(location, 1);
|
|
86
|
-
return {
|
|
87
|
-
buffer,
|
|
88
|
-
size,
|
|
89
|
-
glType,
|
|
90
|
-
capacityBytes: 0,
|
|
91
|
-
lastUploaded: null
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
uploadBuffer(target, data) {
|
|
95
|
-
if (target.lastUploaded === data) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const {
|
|
99
|
-
gl
|
|
100
|
-
} = this;
|
|
101
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, target.buffer);
|
|
102
|
-
if (data.byteLength <= target.capacityBytes) {
|
|
103
|
-
gl.bufferSubData(gl.ARRAY_BUFFER, 0, data);
|
|
104
|
-
} else {
|
|
105
|
-
gl.bufferData(gl.ARRAY_BUFFER, data, gl.DYNAMIC_DRAW);
|
|
106
|
-
target.capacityBytes = data.byteLength;
|
|
107
|
-
}
|
|
108
|
-
target.lastUploaded = data;
|
|
109
|
-
}
|
|
110
70
|
}
|
|
111
|
-
exports.ScatterWebGLProgram = ScatterWebGLProgram;
|
|
112
|
-
function initializeProgram(gl, vertexShaderSource, fragmentShaderSource) {
|
|
113
|
-
const program = gl.createProgram();
|
|
114
|
-
const vertexShader = (0, _utils.compileShader)(gl, vertexShaderSource, gl.VERTEX_SHADER);
|
|
115
|
-
const fragmentShader = (0, _utils.compileShader)(gl, fragmentShaderSource, gl.FRAGMENT_SHADER);
|
|
116
|
-
gl.attachShader(program, vertexShader);
|
|
117
|
-
gl.attachShader(program, fragmentShader);
|
|
118
|
-
gl.linkProgram(program);
|
|
119
|
-
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
120
|
-
console.error(`Program linking failed: ${gl.getProgramInfoLog(program)}`);
|
|
121
|
-
console.error(`Vertex shader info-log: ${gl.getShaderInfoLog(vertexShader)}`);
|
|
122
|
-
console.error(`Fragment shader info-log: ${gl.getShaderInfoLog(fragmentShader)}`);
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
program,
|
|
126
|
-
vertexShader,
|
|
127
|
-
fragmentShader
|
|
128
|
-
};
|
|
129
|
-
}
|
|
71
|
+
exports.ScatterWebGLProgram = ScatterWebGLProgram;
|
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bindQuadBuffer, linkProgram, logWebGLErrors, setupStandardBlending, uploadGrowableBuffer, uploadQuadBuffer } from "../../utils/webgl/utils.mjs";
|
|
2
|
+
import { createInstancedAttribute } from "../../utils/webgl/instancedAttribute.mjs";
|
|
2
3
|
import { scatterVertexShader, scatterFragmentShader } from "./shaders.mjs";
|
|
3
|
-
const QUAD_VERTICES = new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]);
|
|
4
4
|
export class ScatterWebGLProgram {
|
|
5
5
|
shaders = [];
|
|
6
|
+
|
|
7
|
+
/* Colors come in as Uint8 [0, 255]; normalized=true makes the GPU read them back as vec4 in [0, 1]. */
|
|
8
|
+
|
|
6
9
|
constructor(gl) {
|
|
7
10
|
this.gl = gl;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
this.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const prog = initializeProgram(gl, scatterVertexShader, scatterFragmentShader);
|
|
14
|
-
this.program = prog.program;
|
|
15
|
-
this.shaders.push(prog.vertexShader, prog.fragmentShader);
|
|
11
|
+
setupStandardBlending(gl);
|
|
12
|
+
const linked = linkProgram(gl, scatterVertexShader, scatterFragmentShader);
|
|
13
|
+
this.program = linked.program;
|
|
14
|
+
this.shaders.push(...linked.shaders);
|
|
15
|
+
this.quadBuffer = uploadQuadBuffer(gl);
|
|
16
16
|
this.vao = gl.createVertexArray();
|
|
17
17
|
gl.bindVertexArray(this.vao);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
gl.enableVertexAttribArray(aPosition);
|
|
23
|
-
gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, 0, 0);
|
|
24
|
-
this.centers = this.setupInstancedAttribute('a_center', 2, gl.FLOAT, false);
|
|
25
|
-
this.sizes = this.setupInstancedAttribute('a_size', 1, gl.FLOAT, false);
|
|
26
|
-
// Colors come in as Uint8 [0, 255]; normalized=true makes the GPU read them back as vec4 in [0, 1].
|
|
27
|
-
this.colors = this.setupInstancedAttribute('a_color', 4, gl.UNSIGNED_BYTE, true);
|
|
18
|
+
bindQuadBuffer(gl, this.program, this.quadBuffer);
|
|
19
|
+
this.centers = createInstancedAttribute(gl, this.program, 'a_center', 2);
|
|
20
|
+
this.sizes = createInstancedAttribute(gl, this.program, 'a_size', 1);
|
|
21
|
+
this.colors = createInstancedAttribute(gl, this.program, 'a_color', 4, gl.UNSIGNED_BYTE, true);
|
|
28
22
|
gl.bindVertexArray(null);
|
|
29
23
|
}
|
|
30
24
|
setResolution(width, height) {
|
|
@@ -35,9 +29,12 @@ export class ScatterWebGLProgram {
|
|
|
35
29
|
gl.uniform2f(gl.getUniformLocation(this.program, 'u_resolution'), width, height);
|
|
36
30
|
}
|
|
37
31
|
plot(plotData) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this
|
|
32
|
+
const {
|
|
33
|
+
gl
|
|
34
|
+
} = this;
|
|
35
|
+
uploadGrowableBuffer(gl, this.centers.buffer, plotData.centers);
|
|
36
|
+
uploadGrowableBuffer(gl, this.sizes.buffer, plotData.sizes);
|
|
37
|
+
uploadGrowableBuffer(gl, this.colors.buffer, plotData.colors);
|
|
41
38
|
}
|
|
42
39
|
render(plotData) {
|
|
43
40
|
if (plotData.pointCount === 0) {
|
|
@@ -58,65 +55,10 @@ export class ScatterWebGLProgram {
|
|
|
58
55
|
} = this;
|
|
59
56
|
gl.deleteProgram(this.program);
|
|
60
57
|
gl.deleteVertexArray(this.vao);
|
|
61
|
-
gl.deleteBuffer(this.centers.buffer);
|
|
62
|
-
gl.deleteBuffer(this.sizes.buffer);
|
|
63
|
-
gl.deleteBuffer(this.colors.buffer);
|
|
58
|
+
gl.deleteBuffer(this.centers.buffer.buffer);
|
|
59
|
+
gl.deleteBuffer(this.sizes.buffer.buffer);
|
|
60
|
+
gl.deleteBuffer(this.colors.buffer.buffer);
|
|
64
61
|
gl.deleteBuffer(this.quadBuffer);
|
|
65
62
|
this.shaders.forEach(shader => gl.deleteShader(shader));
|
|
66
63
|
}
|
|
67
|
-
|
|
68
|
-
// Assumes the owning VAO (Vertex Array Object) is already bound.
|
|
69
|
-
setupInstancedAttribute(name, size, glType, normalized) {
|
|
70
|
-
const {
|
|
71
|
-
gl,
|
|
72
|
-
program
|
|
73
|
-
} = this;
|
|
74
|
-
const buffer = gl.createBuffer();
|
|
75
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
76
|
-
const location = gl.getAttribLocation(program, name);
|
|
77
|
-
gl.enableVertexAttribArray(location);
|
|
78
|
-
gl.vertexAttribPointer(location, size, glType, normalized, 0, 0);
|
|
79
|
-
gl.vertexAttribDivisor(location, 1);
|
|
80
|
-
return {
|
|
81
|
-
buffer,
|
|
82
|
-
size,
|
|
83
|
-
glType,
|
|
84
|
-
capacityBytes: 0,
|
|
85
|
-
lastUploaded: null
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
uploadBuffer(target, data) {
|
|
89
|
-
if (target.lastUploaded === data) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const {
|
|
93
|
-
gl
|
|
94
|
-
} = this;
|
|
95
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, target.buffer);
|
|
96
|
-
if (data.byteLength <= target.capacityBytes) {
|
|
97
|
-
gl.bufferSubData(gl.ARRAY_BUFFER, 0, data);
|
|
98
|
-
} else {
|
|
99
|
-
gl.bufferData(gl.ARRAY_BUFFER, data, gl.DYNAMIC_DRAW);
|
|
100
|
-
target.capacityBytes = data.byteLength;
|
|
101
|
-
}
|
|
102
|
-
target.lastUploaded = data;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function initializeProgram(gl, vertexShaderSource, fragmentShaderSource) {
|
|
106
|
-
const program = gl.createProgram();
|
|
107
|
-
const vertexShader = compileShader(gl, vertexShaderSource, gl.VERTEX_SHADER);
|
|
108
|
-
const fragmentShader = compileShader(gl, fragmentShaderSource, gl.FRAGMENT_SHADER);
|
|
109
|
-
gl.attachShader(program, vertexShader);
|
|
110
|
-
gl.attachShader(program, fragmentShader);
|
|
111
|
-
gl.linkProgram(program);
|
|
112
|
-
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
113
|
-
console.error(`Program linking failed: ${gl.getProgramInfoLog(program)}`);
|
|
114
|
-
console.error(`Vertex shader info-log: ${gl.getShaderInfoLog(vertexShader)}`);
|
|
115
|
-
console.error(`Fragment shader info-log: ${gl.getShaderInfoLog(fragmentShader)}`);
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
program,
|
|
119
|
-
vertexShader,
|
|
120
|
-
fragmentShader
|
|
121
|
-
};
|
|
122
64
|
}
|
package/index.js
CHANGED
package/index.mjs
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GeoProjection } from '@mui/x-charts-vendor/d3-geo';
|
|
2
|
+
/**
|
|
3
|
+
* Builds a test that maps a device pixel to its `[lon, lat]`, or `null` when the
|
|
4
|
+
* pixel is not part of the visible map. It combines two clips that `projection.invert`
|
|
5
|
+
* alone misses:
|
|
6
|
+
*
|
|
7
|
+
* - the **post-clip** (cartesian) stream rejects device pixels outside the clip
|
|
8
|
+
* rectangle — relevant once the map is panned/zoomed with a `clipExtent`;
|
|
9
|
+
* - streaming the inverted coordinate **back** through the projection applies the
|
|
10
|
+
* pre-clip (spherical) boundary and checks the round trip: azimuthal projections
|
|
11
|
+
* clamp `invert` outside the visible disk to the limb, and those clamped points do
|
|
12
|
+
* not project back to the pixel they came from.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createGetVisibleCoordinate(projection: GeoProjection): ([deviceX, deviceY]: [number, number]) => [number, number] | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GeoProjection } from '@mui/x-charts-vendor/d3-geo';
|
|
2
|
+
/**
|
|
3
|
+
* Builds a test that maps a device pixel to its `[lon, lat]`, or `null` when the
|
|
4
|
+
* pixel is not part of the visible map. It combines two clips that `projection.invert`
|
|
5
|
+
* alone misses:
|
|
6
|
+
*
|
|
7
|
+
* - the **post-clip** (cartesian) stream rejects device pixels outside the clip
|
|
8
|
+
* rectangle — relevant once the map is panned/zoomed with a `clipExtent`;
|
|
9
|
+
* - streaming the inverted coordinate **back** through the projection applies the
|
|
10
|
+
* pre-clip (spherical) boundary and checks the round trip: azimuthal projections
|
|
11
|
+
* clamp `invert` outside the visible disk to the limb, and those clamped points do
|
|
12
|
+
* not project back to the pixel they came from.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createGetVisibleCoordinate(projection: GeoProjection): ([deviceX, deviceY]: [number, number]) => [number, number] | null;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createGetVisibleCoordinate = createGetVisibleCoordinate;
|
|
7
|
+
// A `GeoStream` sink that only records whether a point passed through (and where),
|
|
8
|
+
// so a projection/clip pipeline can be probed one point at a time.
|
|
9
|
+
|
|
10
|
+
function createPointSink() {
|
|
11
|
+
const sink = {
|
|
12
|
+
hit: false,
|
|
13
|
+
x: 0,
|
|
14
|
+
y: 0,
|
|
15
|
+
point(x, y) {
|
|
16
|
+
sink.hit = true;
|
|
17
|
+
sink.x = x;
|
|
18
|
+
sink.y = y;
|
|
19
|
+
},
|
|
20
|
+
lineStart() {},
|
|
21
|
+
lineEnd() {},
|
|
22
|
+
polygonStart() {},
|
|
23
|
+
polygonEnd() {}
|
|
24
|
+
};
|
|
25
|
+
return sink;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Builds a test that maps a device pixel to its `[lon, lat]`, or `null` when the
|
|
30
|
+
* pixel is not part of the visible map. It combines two clips that `projection.invert`
|
|
31
|
+
* alone misses:
|
|
32
|
+
*
|
|
33
|
+
* - the **post-clip** (cartesian) stream rejects device pixels outside the clip
|
|
34
|
+
* rectangle — relevant once the map is panned/zoomed with a `clipExtent`;
|
|
35
|
+
* - streaming the inverted coordinate **back** through the projection applies the
|
|
36
|
+
* pre-clip (spherical) boundary and checks the round trip: azimuthal projections
|
|
37
|
+
* clamp `invert` outside the visible disk to the limb, and those clamped points do
|
|
38
|
+
* not project back to the pixel they came from.
|
|
39
|
+
*/
|
|
40
|
+
function createGetVisibleCoordinate(projection) {
|
|
41
|
+
const invert = projection.invert;
|
|
42
|
+
const forwardSink = createPointSink();
|
|
43
|
+
const forwardStream = projection.stream(forwardSink);
|
|
44
|
+
const postClip = projection.postclip?.();
|
|
45
|
+
const clipSink = createPointSink();
|
|
46
|
+
const clipStream = postClip?.(clipSink);
|
|
47
|
+
return ([deviceX, deviceY]) => {
|
|
48
|
+
if (clipStream) {
|
|
49
|
+
clipSink.hit = false;
|
|
50
|
+
clipStream.point(deviceX, deviceY);
|
|
51
|
+
if (!clipSink.hit) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const coordinates = invert([deviceX, deviceY]);
|
|
56
|
+
if (!coordinates) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
forwardSink.hit = false;
|
|
60
|
+
forwardStream.point(coordinates[0], coordinates[1]);
|
|
61
|
+
if (!forwardSink.hit || Math.abs(forwardSink.x - deviceX) > 0.5 || Math.abs(forwardSink.y - deviceY) > 0.5) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
return coordinates;
|
|
65
|
+
};
|
|
66
|
+
}
|