@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,17 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bindQuadBuffer, createGrowableBuffer, linkProgram, logWebGLErrors, setupStandardBlending, uploadGrowableBuffer, uploadQuadBuffer } from "../../utils/webgl/utils.mjs";
|
|
2
|
+
import { bindInstancedAttribute } from "../../utils/webgl/instancedAttribute.mjs";
|
|
2
3
|
import { heatmapFragmentShaderSourceNoBorderRadius, heatmapFragmentShaderSourceWithBorderRadius, heatmapVertexShaderSource } from "./shaders.mjs";
|
|
3
|
-
const QUAD_VERTICES = new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]);
|
|
4
4
|
export class HeatmapWebGLProgram {
|
|
5
5
|
shaders = [];
|
|
6
6
|
constructor(gl) {
|
|
7
7
|
this.gl = gl;
|
|
8
|
-
/*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
12
|
-
this.quadBuffer = gl.createBuffer();
|
|
13
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, this.quadBuffer);
|
|
14
|
-
gl.bufferData(gl.ARRAY_BUFFER, QUAD_VERTICES, gl.STATIC_DRAW);
|
|
8
|
+
/* These are global to the WebGL context and need to be set only once. */
|
|
9
|
+
setupStandardBlending(gl);
|
|
10
|
+
this.quadBuffer = uploadQuadBuffer(gl);
|
|
15
11
|
this.centers = createGrowableBuffer(gl);
|
|
16
12
|
this.colors = createGrowableBuffer(gl);
|
|
17
13
|
this.saturations = createGrowableBuffer(gl);
|
|
@@ -23,28 +19,16 @@ export class HeatmapWebGLProgram {
|
|
|
23
19
|
}
|
|
24
20
|
buildVariant(fragmentShaderSource) {
|
|
25
21
|
const gl = this.gl;
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const fragmentShader = attachShader(gl, program, fragmentShaderSource, gl.FRAGMENT_SHADER);
|
|
30
|
-
gl.linkProgram(program);
|
|
31
|
-
|
|
32
|
-
/* https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#dont_check_shader_compile_status_unless_linking_fails */
|
|
33
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
34
|
-
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
35
|
-
console.error(`Program linking failed: ${gl.getProgramInfoLog(program)}`);
|
|
36
|
-
console.error(`Vertex shader info-log: ${gl.getShaderInfoLog(vertexShader)}`);
|
|
37
|
-
console.error(`Fragment shader info-log: ${gl.getShaderInfoLog(fragmentShader)}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
this.shaders.push(vertexShader, fragmentShader);
|
|
22
|
+
const linked = linkProgram(gl, heatmapVertexShaderSource, fragmentShaderSource);
|
|
23
|
+
this.shaders.push(...linked.shaders);
|
|
24
|
+
const program = linked.program;
|
|
41
25
|
const vao = gl.createVertexArray();
|
|
42
26
|
gl.bindVertexArray(vao);
|
|
43
|
-
|
|
44
|
-
|
|
27
|
+
bindQuadBuffer(gl, program, this.quadBuffer);
|
|
28
|
+
bindInstancedAttribute(gl, program, 'a_center', this.centers, 2);
|
|
45
29
|
/* Colors are uploaded as Uint8(Clamped)Array; shader sees normalized [0, 1] floats. */
|
|
46
|
-
|
|
47
|
-
|
|
30
|
+
bindInstancedAttribute(gl, program, 'a_color', this.colors, 4, gl.UNSIGNED_BYTE, true);
|
|
31
|
+
bindInstancedAttribute(gl, program, 'a_saturation', this.saturations, 1);
|
|
48
32
|
gl.bindVertexArray(null);
|
|
49
33
|
return {
|
|
50
34
|
program,
|
|
@@ -113,13 +97,4 @@ export class HeatmapWebGLProgram {
|
|
|
113
97
|
gl.deleteVertexArray(this.roundedVariant.vao);
|
|
114
98
|
this.shaders.forEach(shader => gl.deleteShader(shader));
|
|
115
99
|
}
|
|
116
|
-
}
|
|
117
|
-
function bindAttribute(gl, program, name, buffer, size, divisor, type = gl.FLOAT, normalized = false) {
|
|
118
|
-
const location = gl.getAttribLocation(program, name);
|
|
119
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
120
|
-
gl.enableVertexAttribArray(location);
|
|
121
|
-
gl.vertexAttribPointer(location, size, type, normalized, 0, 0);
|
|
122
|
-
if (divisor !== 0) {
|
|
123
|
-
gl.vertexAttribDivisor(location, divisor);
|
|
124
|
-
}
|
|
125
100
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const heatmapVertexShaderSource = "\n precision mediump float;\n \n attribute vec2 a_position;\n attribute vec2 a_center;\n attribute vec4 a_color;\n attribute float a_saturation;\n
|
|
2
|
-
export declare const heatmapFragmentShaderSourceNoBorderRadius = "\n precision mediump float;\n
|
|
3
|
-
export declare const heatmapFragmentShaderSourceWithBorderRadius = "\n precision mediump float;\n\n varying vec4 v_color;\n varying vec2 v_pos;\n\n uniform vec2 u_dimensions;\n uniform float u_borderRadius;\n\n float roundedBoxSDF(vec2 pos, vec2
|
|
1
|
+
export declare const heatmapVertexShaderSource = "\n precision mediump float;\n \n attribute vec2 a_position;\n attribute vec2 a_center;\n attribute vec4 a_color;\n attribute float a_saturation;\n\n varying vec4 v_color;\n varying vec2 v_pos;\n\n uniform vec2 u_dimensions;\n uniform vec2 u_resolution;\n // https://tsev.dev/posts/2020-06-19-colour-correction-with-webgl/\n vec3 adjust_saturation(vec3 color, float value) {\n // https://www.w3.org/TR/WCAG22/#dfn-relative-luminance\n const vec3 luminosityFactor = vec3(0.2126, 0.7152, 0.0722);\n vec3 grayscale = vec3(dot(color, luminosityFactor));\n\n return mix(grayscale, color, 1.0 + value);\n }\n\n void main() {\n // Convert from pixels to clip space (-1 to 1)\n vec2 position = a_center + a_position * u_dimensions / 2.0;\n vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0;\n gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);\n\n v_color = vec4(adjust_saturation(a_color.rgb, a_saturation), 1.0);\n v_pos = a_position * u_dimensions / 2.0;\n }\n ";
|
|
2
|
+
export declare const heatmapFragmentShaderSourceNoBorderRadius = "\n precision mediump float;\n\n varying vec4 v_color;\n\n void main() {\n gl_FragColor = v_color;\n }\n ";
|
|
3
|
+
export declare const heatmapFragmentShaderSourceWithBorderRadius = "\n precision mediump float;\n\n varying vec4 v_color;\n varying vec2 v_pos;\n\n uniform vec2 u_dimensions;\n uniform float u_borderRadius;\n\n \n float roundedBoxSDF(vec2 pos, vec2 halfSize, vec4 r) {\n float radius;\n if (pos.x < 0.0) {\n radius = pos.y < 0.0 ? r.x : r.w;\n } else {\n radius = pos.y < 0.0 ? r.y : r.z;\n }\n\n vec2 q = abs(pos) - halfSize + radius;\n return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - radius;\n }\n \n\n void main() {\n // Calculate distance from rounded rectangle edge\n float dist = roundedBoxSDF(v_pos, u_dimensions / 2.0, vec4(u_borderRadius));\n\n // Create smooth alpha based on distance\n float alpha = 1.0 - smoothstep(-0.5, 0.5, dist);\n\n gl_FragColor = vec4(v_color.rgb, v_color.a * alpha);\n }\n ";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const heatmapVertexShaderSource = "\n precision mediump float;\n \n attribute vec2 a_position;\n attribute vec2 a_center;\n attribute vec4 a_color;\n attribute float a_saturation;\n
|
|
2
|
-
export declare const heatmapFragmentShaderSourceNoBorderRadius = "\n precision mediump float;\n
|
|
3
|
-
export declare const heatmapFragmentShaderSourceWithBorderRadius = "\n precision mediump float;\n\n varying vec4 v_color;\n varying vec2 v_pos;\n\n uniform vec2 u_dimensions;\n uniform float u_borderRadius;\n\n float roundedBoxSDF(vec2 pos, vec2
|
|
1
|
+
export declare const heatmapVertexShaderSource = "\n precision mediump float;\n \n attribute vec2 a_position;\n attribute vec2 a_center;\n attribute vec4 a_color;\n attribute float a_saturation;\n\n varying vec4 v_color;\n varying vec2 v_pos;\n\n uniform vec2 u_dimensions;\n uniform vec2 u_resolution;\n // https://tsev.dev/posts/2020-06-19-colour-correction-with-webgl/\n vec3 adjust_saturation(vec3 color, float value) {\n // https://www.w3.org/TR/WCAG22/#dfn-relative-luminance\n const vec3 luminosityFactor = vec3(0.2126, 0.7152, 0.0722);\n vec3 grayscale = vec3(dot(color, luminosityFactor));\n\n return mix(grayscale, color, 1.0 + value);\n }\n\n void main() {\n // Convert from pixels to clip space (-1 to 1)\n vec2 position = a_center + a_position * u_dimensions / 2.0;\n vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0;\n gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);\n\n v_color = vec4(adjust_saturation(a_color.rgb, a_saturation), 1.0);\n v_pos = a_position * u_dimensions / 2.0;\n }\n ";
|
|
2
|
+
export declare const heatmapFragmentShaderSourceNoBorderRadius = "\n precision mediump float;\n\n varying vec4 v_color;\n\n void main() {\n gl_FragColor = v_color;\n }\n ";
|
|
3
|
+
export declare const heatmapFragmentShaderSourceWithBorderRadius = "\n precision mediump float;\n\n varying vec4 v_color;\n varying vec2 v_pos;\n\n uniform vec2 u_dimensions;\n uniform float u_borderRadius;\n\n \n float roundedBoxSDF(vec2 pos, vec2 halfSize, vec4 r) {\n float radius;\n if (pos.x < 0.0) {\n radius = pos.y < 0.0 ? r.x : r.w;\n } else {\n radius = pos.y < 0.0 ? r.y : r.z;\n }\n\n vec2 q = abs(pos) - halfSize + radius;\n return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - radius;\n }\n \n\n void main() {\n // Calculate distance from rounded rectangle edge\n float dist = roundedBoxSDF(v_pos, u_dimensions / 2.0, vec4(u_borderRadius));\n\n // Create smooth alpha based on distance\n float alpha = 1.0 - smoothstep(-0.5, 0.5, dist);\n\n gl_FragColor = vec4(v_color.rgb, v_color.a * alpha);\n }\n ";
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.heatmapVertexShaderSource = exports.heatmapFragmentShaderSourceWithBorderRadius = exports.heatmapFragmentShaderSourceNoBorderRadius = void 0;
|
|
7
|
+
var _glsl = require("../../utils/webgl/glsl");
|
|
7
8
|
// language=Glsl
|
|
8
9
|
const heatmapVertexShaderSource = exports.heatmapVertexShaderSource = /* glsl */`
|
|
9
10
|
precision mediump float;
|
|
@@ -12,28 +13,27 @@ const heatmapVertexShaderSource = exports.heatmapVertexShaderSource = /* glsl */
|
|
|
12
13
|
attribute vec2 a_center;
|
|
13
14
|
attribute vec4 a_color;
|
|
14
15
|
attribute float a_saturation;
|
|
15
|
-
|
|
16
|
+
|
|
16
17
|
varying vec4 v_color;
|
|
17
18
|
varying vec2 v_pos;
|
|
18
|
-
|
|
19
|
+
|
|
19
20
|
uniform vec2 u_dimensions;
|
|
20
21
|
uniform vec2 u_resolution;
|
|
21
|
-
|
|
22
22
|
// https://tsev.dev/posts/2020-06-19-colour-correction-with-webgl/
|
|
23
23
|
vec3 adjust_saturation(vec3 color, float value) {
|
|
24
24
|
// https://www.w3.org/TR/WCAG22/#dfn-relative-luminance
|
|
25
25
|
const vec3 luminosityFactor = vec3(0.2126, 0.7152, 0.0722);
|
|
26
26
|
vec3 grayscale = vec3(dot(color, luminosityFactor));
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
return mix(grayscale, color, 1.0 + value);
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
void main() {
|
|
32
32
|
// Convert from pixels to clip space (-1 to 1)
|
|
33
33
|
vec2 position = a_center + a_position * u_dimensions / 2.0;
|
|
34
34
|
vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0;
|
|
35
35
|
gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
v_color = vec4(adjust_saturation(a_color.rgb, a_saturation), 1.0);
|
|
38
38
|
v_pos = a_position * u_dimensions / 2.0;
|
|
39
39
|
}
|
|
@@ -42,9 +42,9 @@ const heatmapVertexShaderSource = exports.heatmapVertexShaderSource = /* glsl */
|
|
|
42
42
|
// language=Glsl
|
|
43
43
|
const heatmapFragmentShaderSourceNoBorderRadius = exports.heatmapFragmentShaderSourceNoBorderRadius = /* glsl */`
|
|
44
44
|
precision mediump float;
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
varying vec4 v_color;
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
void main() {
|
|
49
49
|
gl_FragColor = v_color;
|
|
50
50
|
}
|
|
@@ -60,18 +60,15 @@ const heatmapFragmentShaderSourceWithBorderRadius = exports.heatmapFragmentShade
|
|
|
60
60
|
uniform vec2 u_dimensions;
|
|
61
61
|
uniform float u_borderRadius;
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
vec2 q = abs(pos) - half_size + radius;
|
|
65
|
-
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - radius;
|
|
66
|
-
}
|
|
63
|
+
${_glsl.ROUNDED_BOX_SDF_GLSL}
|
|
67
64
|
|
|
68
65
|
void main() {
|
|
69
66
|
// Calculate distance from rounded rectangle edge
|
|
70
|
-
float dist = roundedBoxSDF(v_pos, u_dimensions / 2.0, u_borderRadius);
|
|
71
|
-
|
|
67
|
+
float dist = roundedBoxSDF(v_pos, u_dimensions / 2.0, vec4(u_borderRadius));
|
|
68
|
+
|
|
72
69
|
// Create smooth alpha based on distance
|
|
73
70
|
float alpha = 1.0 - smoothstep(-0.5, 0.5, dist);
|
|
74
|
-
|
|
71
|
+
|
|
75
72
|
gl_FragColor = vec4(v_color.rgb, v_color.a * alpha);
|
|
76
73
|
}
|
|
77
74
|
`;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ROUNDED_BOX_SDF_GLSL } from "../../utils/webgl/glsl.mjs";
|
|
2
|
+
|
|
1
3
|
// language=Glsl
|
|
2
4
|
export const heatmapVertexShaderSource = /* glsl */`
|
|
3
5
|
precision mediump float;
|
|
@@ -6,28 +8,27 @@ export const heatmapVertexShaderSource = /* glsl */`
|
|
|
6
8
|
attribute vec2 a_center;
|
|
7
9
|
attribute vec4 a_color;
|
|
8
10
|
attribute float a_saturation;
|
|
9
|
-
|
|
11
|
+
|
|
10
12
|
varying vec4 v_color;
|
|
11
13
|
varying vec2 v_pos;
|
|
12
|
-
|
|
14
|
+
|
|
13
15
|
uniform vec2 u_dimensions;
|
|
14
16
|
uniform vec2 u_resolution;
|
|
15
|
-
|
|
16
17
|
// https://tsev.dev/posts/2020-06-19-colour-correction-with-webgl/
|
|
17
18
|
vec3 adjust_saturation(vec3 color, float value) {
|
|
18
19
|
// https://www.w3.org/TR/WCAG22/#dfn-relative-luminance
|
|
19
20
|
const vec3 luminosityFactor = vec3(0.2126, 0.7152, 0.0722);
|
|
20
21
|
vec3 grayscale = vec3(dot(color, luminosityFactor));
|
|
21
|
-
|
|
22
|
+
|
|
22
23
|
return mix(grayscale, color, 1.0 + value);
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
+
|
|
25
26
|
void main() {
|
|
26
27
|
// Convert from pixels to clip space (-1 to 1)
|
|
27
28
|
vec2 position = a_center + a_position * u_dimensions / 2.0;
|
|
28
29
|
vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0;
|
|
29
30
|
gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
|
|
30
|
-
|
|
31
|
+
|
|
31
32
|
v_color = vec4(adjust_saturation(a_color.rgb, a_saturation), 1.0);
|
|
32
33
|
v_pos = a_position * u_dimensions / 2.0;
|
|
33
34
|
}
|
|
@@ -36,9 +37,9 @@ export const heatmapVertexShaderSource = /* glsl */`
|
|
|
36
37
|
// language=Glsl
|
|
37
38
|
export const heatmapFragmentShaderSourceNoBorderRadius = /* glsl */`
|
|
38
39
|
precision mediump float;
|
|
39
|
-
|
|
40
|
+
|
|
40
41
|
varying vec4 v_color;
|
|
41
|
-
|
|
42
|
+
|
|
42
43
|
void main() {
|
|
43
44
|
gl_FragColor = v_color;
|
|
44
45
|
}
|
|
@@ -54,18 +55,15 @@ export const heatmapFragmentShaderSourceWithBorderRadius = /* glsl */`
|
|
|
54
55
|
uniform vec2 u_dimensions;
|
|
55
56
|
uniform float u_borderRadius;
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
vec2 q = abs(pos) - half_size + radius;
|
|
59
|
-
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - radius;
|
|
60
|
-
}
|
|
58
|
+
${ROUNDED_BOX_SDF_GLSL}
|
|
61
59
|
|
|
62
60
|
void main() {
|
|
63
61
|
// Calculate distance from rounded rectangle edge
|
|
64
|
-
float dist = roundedBoxSDF(v_pos, u_dimensions / 2.0, u_borderRadius);
|
|
65
|
-
|
|
62
|
+
float dist = roundedBoxSDF(v_pos, u_dimensions / 2.0, vec4(u_borderRadius));
|
|
63
|
+
|
|
66
64
|
// Create smooth alpha based on distance
|
|
67
65
|
float alpha = 1.0 - smoothstep(-0.5, 0.5, dist);
|
|
68
|
-
|
|
66
|
+
|
|
69
67
|
gl_FragColor = vec4(v_color.rgb, v_color.a * alpha);
|
|
70
68
|
}
|
|
71
69
|
`;
|
|
@@ -10,15 +10,10 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
10
10
|
var _hooks = require("@mui/x-charts/hooks");
|
|
11
11
|
var _internals = require("@mui/x-charts/internals");
|
|
12
12
|
var _parseColor = require("../../utils/webgl/parseColor");
|
|
13
|
+
var _utils = require("../../utils/webgl/utils");
|
|
13
14
|
/* Far enough off-canvas that the rect is never visible; used for invalid x/y entries.
|
|
14
15
|
* Avoids coupling the position pass to the color/saturation passes. */
|
|
15
16
|
const OFFSCREEN = -1e9;
|
|
16
|
-
function ensurePoolFloat32(pool, n) {
|
|
17
|
-
if (pool && pool.length >= n) {
|
|
18
|
-
return pool;
|
|
19
|
-
}
|
|
20
|
-
return new Float32Array(n);
|
|
21
|
-
}
|
|
22
17
|
function useHeatmapPlotData(drawingArea, series, xScale, yScale) {
|
|
23
18
|
const width = xScale.bandwidth();
|
|
24
19
|
const height = yScale.bandwidth();
|
|
@@ -52,7 +47,7 @@ function useHeatmapPlotData(drawingArea, series, xScale, yScale) {
|
|
|
52
47
|
const saturationsPoolRef = React.useRef(null);
|
|
53
48
|
const saturations = React.useMemo(() => {
|
|
54
49
|
const n = series.data.length;
|
|
55
|
-
const pool =
|
|
50
|
+
const pool = (0, _utils.ensurePool)(saturationsPoolRef.current, n, Float32Array);
|
|
56
51
|
saturationsPoolRef.current = pool;
|
|
57
52
|
for (let dataIndex = 0; dataIndex < n; dataIndex += 1) {
|
|
58
53
|
const item = series.data[dataIndex];
|
|
@@ -79,7 +74,7 @@ function useHeatmapPlotData(drawingArea, series, xScale, yScale) {
|
|
|
79
74
|
const centersPoolRef = React.useRef(null);
|
|
80
75
|
const centers = React.useMemo(() => {
|
|
81
76
|
const n = series.data.length;
|
|
82
|
-
const pool =
|
|
77
|
+
const pool = (0, _utils.ensurePool)(centersPoolRef.current, n * 2, Float32Array);
|
|
83
78
|
centersPoolRef.current = pool;
|
|
84
79
|
const left = drawingArea.left;
|
|
85
80
|
const top = drawingArea.top;
|
|
@@ -4,16 +4,11 @@ import * as React from 'react';
|
|
|
4
4
|
import { useZColorScale } from '@mui/x-charts/hooks';
|
|
5
5
|
import { selectorChartsHighlightStateCallback, useStore } from '@mui/x-charts/internals';
|
|
6
6
|
import { parseColor } from "../../utils/webgl/parseColor.mjs";
|
|
7
|
+
import { ensurePool } from "../../utils/webgl/utils.mjs";
|
|
7
8
|
|
|
8
9
|
/* Far enough off-canvas that the rect is never visible; used for invalid x/y entries.
|
|
9
10
|
* Avoids coupling the position pass to the color/saturation passes. */
|
|
10
11
|
const OFFSCREEN = -1e9;
|
|
11
|
-
function ensurePoolFloat32(pool, n) {
|
|
12
|
-
if (pool && pool.length >= n) {
|
|
13
|
-
return pool;
|
|
14
|
-
}
|
|
15
|
-
return new Float32Array(n);
|
|
16
|
-
}
|
|
17
12
|
export function useHeatmapPlotData(drawingArea, series, xScale, yScale) {
|
|
18
13
|
const width = xScale.bandwidth();
|
|
19
14
|
const height = yScale.bandwidth();
|
|
@@ -47,7 +42,7 @@ export function useHeatmapPlotData(drawingArea, series, xScale, yScale) {
|
|
|
47
42
|
const saturationsPoolRef = React.useRef(null);
|
|
48
43
|
const saturations = React.useMemo(() => {
|
|
49
44
|
const n = series.data.length;
|
|
50
|
-
const pool =
|
|
45
|
+
const pool = ensurePool(saturationsPoolRef.current, n, Float32Array);
|
|
51
46
|
saturationsPoolRef.current = pool;
|
|
52
47
|
for (let dataIndex = 0; dataIndex < n; dataIndex += 1) {
|
|
53
48
|
const item = series.data[dataIndex];
|
|
@@ -74,7 +69,7 @@ export function useHeatmapPlotData(drawingArea, series, xScale, yScale) {
|
|
|
74
69
|
const centersPoolRef = React.useRef(null);
|
|
75
70
|
const centers = React.useMemo(() => {
|
|
76
71
|
const n = series.data.length;
|
|
77
|
-
const pool =
|
|
72
|
+
const pool = ensurePool(centersPoolRef.current, n * 2, Float32Array);
|
|
78
73
|
centersPoolRef.current = pool;
|
|
79
74
|
const left = drawingArea.left;
|
|
80
75
|
const top = drawingArea.top;
|
package/Map/FocusedMapShape.js
CHANGED
|
@@ -42,7 +42,11 @@ function FocusedMapShape() {
|
|
|
42
42
|
if (!seriesItem || seriesItem.hidden) {
|
|
43
43
|
return null;
|
|
44
44
|
}
|
|
45
|
-
const
|
|
45
|
+
const dataIndex = seriesItem.lookupByName.get(focusedItem.name);
|
|
46
|
+
if (dataIndex === undefined) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const dataItem = seriesItem.data[dataIndex];
|
|
46
50
|
if (!dataItem || dataItem.hidden) {
|
|
47
51
|
return null;
|
|
48
52
|
}
|
package/Map/FocusedMapShape.mjs
CHANGED
|
@@ -36,7 +36,11 @@ export function FocusedMapShape() {
|
|
|
36
36
|
if (!seriesItem || seriesItem.hidden) {
|
|
37
37
|
return null;
|
|
38
38
|
}
|
|
39
|
-
const
|
|
39
|
+
const dataIndex = seriesItem.lookupByName.get(focusedItem.name);
|
|
40
|
+
if (dataIndex === undefined) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const dataItem = seriesItem.data[dataIndex];
|
|
40
44
|
if (!dataItem || dataItem.hidden) {
|
|
41
45
|
return null;
|
|
42
46
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface MapImagePlotProps extends React.SVGProps<SVGImageElement> {
|
|
3
|
+
/**
|
|
4
|
+
* URL of the image to render as the base map.
|
|
5
|
+
* Must be same-origin (or CORS-enabled) so it can be reprojected on a canvas.
|
|
6
|
+
*/
|
|
7
|
+
href?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Geographic extent the source image covers, as `[[west, south], [east, north]]`.
|
|
10
|
+
* The image is assumed to be in the equirectangular (plate carrée) projection.
|
|
11
|
+
* If `west` is greater than `east`, the range wraps across the antimeridian.
|
|
12
|
+
* @default [[-180, -90], [180, 90]]
|
|
13
|
+
*/
|
|
14
|
+
imageBounds?: [[number, number], [number, number]];
|
|
15
|
+
/**
|
|
16
|
+
* Called after each reprojection.
|
|
17
|
+
* @param {string | null} dataUrl The reprojected raster as a data URL, or `null` when it could not be produced.
|
|
18
|
+
*/
|
|
19
|
+
onReady?: (dataUrl: string | null) => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Renders a raster base map (for example a satellite mosaic) under the series,
|
|
23
|
+
* reprojected to match the chart's `projection` so it follows the geography
|
|
24
|
+
* instead of being a flat rectangle. Pixels outside the projection's visible
|
|
25
|
+
* footprint are left transparent.
|
|
26
|
+
*
|
|
27
|
+
* The source image is loaded only when `href` changes; changing the projection or
|
|
28
|
+
* resizing reuses the decoded image and only re-runs the (synchronous) canvas
|
|
29
|
+
* reprojection.
|
|
30
|
+
*
|
|
31
|
+
* The source image is assumed to be equirectangular; use `imageBounds` when it
|
|
32
|
+
* does not cover the whole globe. Any other SVG image attribute is forwarded to
|
|
33
|
+
* the underlying element.
|
|
34
|
+
*/
|
|
35
|
+
declare function MapImagePlot(props: MapImagePlotProps): import("react/jsx-runtime").JSX.Element | null;
|
|
36
|
+
declare namespace MapImagePlot {
|
|
37
|
+
var propTypes: any;
|
|
38
|
+
}
|
|
39
|
+
export { MapImagePlot };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface MapImagePlotProps extends React.SVGProps<SVGImageElement> {
|
|
3
|
+
/**
|
|
4
|
+
* URL of the image to render as the base map.
|
|
5
|
+
* Must be same-origin (or CORS-enabled) so it can be reprojected on a canvas.
|
|
6
|
+
*/
|
|
7
|
+
href?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Geographic extent the source image covers, as `[[west, south], [east, north]]`.
|
|
10
|
+
* The image is assumed to be in the equirectangular (plate carrée) projection.
|
|
11
|
+
* If `west` is greater than `east`, the range wraps across the antimeridian.
|
|
12
|
+
* @default [[-180, -90], [180, 90]]
|
|
13
|
+
*/
|
|
14
|
+
imageBounds?: [[number, number], [number, number]];
|
|
15
|
+
/**
|
|
16
|
+
* Called after each reprojection.
|
|
17
|
+
* @param {string | null} dataUrl The reprojected raster as a data URL, or `null` when it could not be produced.
|
|
18
|
+
*/
|
|
19
|
+
onReady?: (dataUrl: string | null) => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Renders a raster base map (for example a satellite mosaic) under the series,
|
|
23
|
+
* reprojected to match the chart's `projection` so it follows the geography
|
|
24
|
+
* instead of being a flat rectangle. Pixels outside the projection's visible
|
|
25
|
+
* footprint are left transparent.
|
|
26
|
+
*
|
|
27
|
+
* The source image is loaded only when `href` changes; changing the projection or
|
|
28
|
+
* resizing reuses the decoded image and only re-runs the (synchronous) canvas
|
|
29
|
+
* reprojection.
|
|
30
|
+
*
|
|
31
|
+
* The source image is assumed to be equirectangular; use `imageBounds` when it
|
|
32
|
+
* does not cover the whole globe. Any other SVG image attribute is forwarded to
|
|
33
|
+
* the underlying element.
|
|
34
|
+
*/
|
|
35
|
+
declare function MapImagePlot(props: MapImagePlotProps): import("react/jsx-runtime").JSX.Element | null;
|
|
36
|
+
declare namespace MapImagePlot {
|
|
37
|
+
var propTypes: any;
|
|
38
|
+
}
|
|
39
|
+
export { MapImagePlot };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.MapImagePlot = MapImagePlot;
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
12
|
+
var React = _interopRequireWildcard(require("react"));
|
|
13
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
14
|
+
var _hooks = require("@mui/x-charts/hooks");
|
|
15
|
+
var _useGeoPath = require("../hooks/useGeoPath");
|
|
16
|
+
var _reprojectEquirectangularImage = require("./reprojectEquirectangularImage");
|
|
17
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
+
const _excluded = ["href", "imageBounds", "onReady"];
|
|
19
|
+
const FULL_GLOBE = [[-180, -90], [180, 90]];
|
|
20
|
+
/**
|
|
21
|
+
* Renders a raster base map (for example a satellite mosaic) under the series,
|
|
22
|
+
* reprojected to match the chart's `projection` so it follows the geography
|
|
23
|
+
* instead of being a flat rectangle. Pixels outside the projection's visible
|
|
24
|
+
* footprint are left transparent.
|
|
25
|
+
*
|
|
26
|
+
* The source image is loaded only when `href` changes; changing the projection or
|
|
27
|
+
* resizing reuses the decoded image and only re-runs the (synchronous) canvas
|
|
28
|
+
* reprojection.
|
|
29
|
+
*
|
|
30
|
+
* The source image is assumed to be equirectangular; use `imageBounds` when it
|
|
31
|
+
* does not cover the whole globe. Any other SVG image attribute is forwarded to
|
|
32
|
+
* the underlying element.
|
|
33
|
+
*/
|
|
34
|
+
function MapImagePlot(props) {
|
|
35
|
+
const {
|
|
36
|
+
href,
|
|
37
|
+
imageBounds,
|
|
38
|
+
onReady
|
|
39
|
+
} = props,
|
|
40
|
+
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
41
|
+
const path = (0, _useGeoPath.useGeoPath)();
|
|
42
|
+
const {
|
|
43
|
+
left,
|
|
44
|
+
top,
|
|
45
|
+
width,
|
|
46
|
+
height
|
|
47
|
+
} = (0, _hooks.useDrawingArea)();
|
|
48
|
+
const [image, setImage] = React.useState(null);
|
|
49
|
+
const [dataUrl, setDataUrl] = React.useState(null);
|
|
50
|
+
const projection = path?.projection?.();
|
|
51
|
+
const [[west, south], [east, north]] = imageBounds ?? FULL_GLOBE;
|
|
52
|
+
|
|
53
|
+
// Keep the latest `onReady` without making it a reprojection dependency.
|
|
54
|
+
const onReadyRef = React.useRef(onReady);
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
onReadyRef.current = onReady;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Load (decode) the source image only when `href` changes. Clearing the image
|
|
60
|
+
// first hides the now-stale raster until the new one is ready.
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
setImage(null);
|
|
63
|
+
if (!href) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
let cancelled = false;
|
|
67
|
+
const nextImage = new Image();
|
|
68
|
+
nextImage.crossOrigin = 'anonymous';
|
|
69
|
+
nextImage.onload = () => {
|
|
70
|
+
if (!cancelled) {
|
|
71
|
+
setImage(nextImage);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
nextImage.src = href;
|
|
75
|
+
return () => {
|
|
76
|
+
cancelled = true;
|
|
77
|
+
};
|
|
78
|
+
}, [href]);
|
|
79
|
+
|
|
80
|
+
// Reproject whenever the decoded image, projection, drawing area, or bounds
|
|
81
|
+
// change. This is synchronous, so switching projection does not reload `href`.
|
|
82
|
+
React.useEffect(() => {
|
|
83
|
+
if (!image || !projection || typeof projection.invert !== 'function' || width <= 0 || height <= 0) {
|
|
84
|
+
setDataUrl(null);
|
|
85
|
+
onReadyRef.current?.(null);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const url = (0, _reprojectEquirectangularImage.reprojectEquirectangularImage)({
|
|
89
|
+
image,
|
|
90
|
+
projection,
|
|
91
|
+
area: {
|
|
92
|
+
left,
|
|
93
|
+
top,
|
|
94
|
+
width,
|
|
95
|
+
height
|
|
96
|
+
},
|
|
97
|
+
imageBounds: [[west, south], [east, north]]
|
|
98
|
+
});
|
|
99
|
+
setDataUrl(url);
|
|
100
|
+
onReadyRef.current?.(url);
|
|
101
|
+
}, [image, projection, left, top, width, height, west, south, east, north]);
|
|
102
|
+
if (!dataUrl) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Spread first so forwarded attributes can't override the computed geometry/href
|
|
107
|
+
// and break the alignment with the projection.
|
|
108
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("image", (0, _extends2.default)({}, other, {
|
|
109
|
+
href: dataUrl,
|
|
110
|
+
x: left,
|
|
111
|
+
y: top,
|
|
112
|
+
width: width,
|
|
113
|
+
height: height
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
process.env.NODE_ENV !== "production" ? MapImagePlot.propTypes /* remove-proptypes */ = {
|
|
117
|
+
// ----------------------------- Warning --------------------------------
|
|
118
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
119
|
+
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
120
|
+
// ----------------------------------------------------------------------
|
|
121
|
+
/**
|
|
122
|
+
* URL of the image to render as the base map.
|
|
123
|
+
* Must be same-origin (or CORS-enabled) so it can be reprojected on a canvas.
|
|
124
|
+
*/
|
|
125
|
+
href: _propTypes.default.string,
|
|
126
|
+
/**
|
|
127
|
+
* Geographic extent the source image covers, as `[[west, south], [east, north]]`.
|
|
128
|
+
* The image is assumed to be in the equirectangular (plate carrée) projection.
|
|
129
|
+
* If `west` is greater than `east`, the range wraps across the antimeridian.
|
|
130
|
+
* @default [[-180, -90], [180, 90]]
|
|
131
|
+
*/
|
|
132
|
+
imageBounds: _propTypes.default.arrayOf(_propTypes.default.arrayOf(_propTypes.default.number.isRequired).isRequired),
|
|
133
|
+
/**
|
|
134
|
+
* Called after each reprojection.
|
|
135
|
+
* @param {string | null} dataUrl The reprojected raster as a data URL, or `null` when it could not be produced.
|
|
136
|
+
*/
|
|
137
|
+
onReady: _propTypes.default.func
|
|
138
|
+
} : void 0;
|