UNPKG

highcharts

Version:
1,576 lines (1,543 loc) 144 kB
/** * @license Highcharts JS v12.1.2 (2024-12-21) * @module highcharts/modules/boost-canvas * @requires highcharts * * Boost module * * (c) 2010-2024 Highsoft AS * Author: Torstein Honsi * * License: www.highcharts.com/license */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(root["_Highcharts"], root["_Highcharts"]["Color"]); else if(typeof define === 'function' && define.amd) define("highcharts/modules/boost-canvas", ["highcharts/highcharts"], function (amd1) {return factory(amd1,amd1["Color"]);}); else if(typeof exports === 'object') exports["highcharts/modules/boost-canvas"] = factory(root["_Highcharts"], root["_Highcharts"]["Color"]); else root["Highcharts"] = factory(root["Highcharts"], root["Highcharts"]["Color"]); })(typeof window === 'undefined' ? this : window, (__WEBPACK_EXTERNAL_MODULE__944__, __WEBPACK_EXTERNAL_MODULE__620__) => { return /******/ (() => { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ 620: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__620__; /***/ }), /***/ 944: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__944__; /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/compat get default export */ /******/ (() => { /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = (module) => { /******/ var getter = module && module.__esModule ? /******/ () => (module['default']) : /******/ () => (module); /******/ __webpack_require__.d(getter, { a: getter }); /******/ return getter; /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = (exports, definition) => { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (() => { /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) /******/ })(); /******/ /************************************************************************/ var __webpack_exports__ = {}; // EXPORTS __webpack_require__.d(__webpack_exports__, { "default": () => (/* binding */ boost_canvas_src) }); // EXTERNAL MODULE: external {"amd":["highcharts/highcharts"],"commonjs":["highcharts"],"commonjs2":["highcharts"],"root":["Highcharts"]} var highcharts_commonjs_highcharts_commonjs2_highcharts_root_Highcharts_ = __webpack_require__(944); var highcharts_commonjs_highcharts_commonjs2_highcharts_root_Highcharts_default = /*#__PURE__*/__webpack_require__.n(highcharts_commonjs_highcharts_commonjs2_highcharts_root_Highcharts_); ;// ./code/es-modules/Extensions/Boost/Boostables.js /* * * * (c) 2019-2024 Highsoft AS * * Boost module: stripped-down renderer for higher performance * * License: highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ /* * * * Constants * * */ // These are the series we allow boosting for. const Boostables = [ 'area', 'areaspline', 'arearange', 'column', 'columnrange', 'bar', 'line', 'scatter', 'heatmap', 'bubble', 'treemap' ]; /* * * * Default Export * * */ /* harmony default export */ const Boost_Boostables = (Boostables); ;// ./code/es-modules/Extensions/Boost/BoostableMap.js /* * * * (c) 2019-2024 Highsoft AS * * Boost module: stripped-down renderer for higher performance * * License: highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ /* * * * Imports * * */ /* * * * Constants * * */ // These are the series we allow boosting for. const BoostableMap = {}; Boost_Boostables.forEach((item) => { BoostableMap[item] = true; }); /* * * * Default Export * * */ /* harmony default export */ const Boost_BoostableMap = (BoostableMap); ;// ./code/es-modules/Extensions/Boost/BoostChart.js /* * * * (c) 2019-2024 Highsoft AS * * Boost module: stripped-down renderer for higher performance * * License: highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ const { composed } = (highcharts_commonjs_highcharts_commonjs2_highcharts_root_Highcharts_default()); const { addEvent, pick, pushUnique } = (highcharts_commonjs_highcharts_commonjs2_highcharts_root_Highcharts_default()); /* * * * Functions * * */ /** * @private */ function compose(ChartClass, wglMode) { if (wglMode && pushUnique(composed, 'Boost.Chart')) { ChartClass.prototype.callbacks.push(onChartCallback); } return ChartClass; } /** * Get the clip rectangle for a target, either a series or the chart. * For the chart, we need to consider the maximum extent of its Y axes, * in case of Highcharts Stock panes and navigator. * * @private * @function Highcharts.Chart#getBoostClipRect */ function getBoostClipRect(chart, target) { const navigator = chart.navigator; let clipBox = { x: chart.plotLeft, y: chart.plotTop, width: chart.plotWidth, height: chart.plotHeight }; if (navigator && chart.inverted) { // #17820, #20936 clipBox.width += navigator.top + navigator.height; if (!navigator.opposite) { clipBox.x = navigator.left; } } else if (navigator && !chart.inverted) { clipBox.height = navigator.top + navigator.height - chart.plotTop; } // Clipping of individual series (#11906, #19039). if (target.getClipBox) { const { xAxis, yAxis } = target; clipBox = target.getClipBox(); if (chart.inverted) { const lateral = clipBox.width; clipBox.width = clipBox.height; clipBox.height = lateral; clipBox.x = yAxis.pos; clipBox.y = xAxis.pos; } else { clipBox.x = xAxis.pos; clipBox.y = yAxis.pos; } } if (target === chart) { const verticalAxes = chart.inverted ? chart.xAxis : chart.yAxis; // #14444 if (verticalAxes.length <= 1) { clipBox.y = Math.min(verticalAxes[0].pos, clipBox.y); clipBox.height = (verticalAxes[0].pos - chart.plotTop + verticalAxes[0].len); } } return clipBox; } /** * Returns true if the chart is in series boost mode. * @private * @param {Highcharts.Chart} chart * Chart to check. * @return {boolean} * `true` if the chart is in series boost mode. */ function isChartSeriesBoosting(chart) { const allSeries = chart.series, boost = chart.boost = chart.boost || {}, boostOptions = chart.options.boost || {}, threshold = pick(boostOptions.seriesThreshold, 50); if (allSeries.length >= threshold) { return true; } if (allSeries.length === 1) { return false; } let allowBoostForce = boostOptions.allowForce; if (typeof allowBoostForce === 'undefined') { allowBoostForce = true; for (const axis of chart.xAxis) { if (pick(axis.min, -Infinity) > pick(axis.dataMin, -Infinity) || pick(axis.max, Infinity) < pick(axis.dataMax, Infinity)) { allowBoostForce = false; break; } } } if (typeof boost.forceChartBoost !== 'undefined') { if (allowBoostForce) { return boost.forceChartBoost; } boost.forceChartBoost = void 0; } // If there are more than five series currently boosting, // we should boost the whole chart to avoid running out of webgl contexts. let canBoostCount = 0, needBoostCount = 0, seriesOptions; for (const series of allSeries) { seriesOptions = series.options; // Don't count series with boostThreshold set to 0 // See #8950 // Also don't count if the series is hidden. // See #9046 if (seriesOptions.boostThreshold === 0 || series.visible === false) { continue; } // Don't count heatmap series as they are handled differently. // In the future we should make the heatmap/treemap path compatible // with forcing. See #9636. if (series.type === 'heatmap') { continue; } if (Boost_BoostableMap[series.type]) { ++canBoostCount; } if (patientMax(series.getColumn('x', true), seriesOptions.data, /// series.xData, series.points) >= (seriesOptions.boostThreshold || Number.MAX_VALUE)) { ++needBoostCount; } } boost.forceChartBoost = allowBoostForce && (( // Even when the series that need a boost are less than or equal // to 5, force a chart boost when all series are to be boosted. // See #18815 canBoostCount === allSeries.length && needBoostCount === canBoostCount) || needBoostCount > 5); return boost.forceChartBoost; } /** * Take care of the canvas blitting * @private */ function onChartCallback(chart) { /** * Convert chart-level canvas to image. * @private */ function canvasToSVG() { if (chart.boost && chart.boost.wgl && isChartSeriesBoosting(chart)) { chart.boost.wgl.render(chart); } } /** * Clear chart-level canvas. * @private */ function preRender() { // Reset force state chart.boost = chart.boost || {}; chart.boost.forceChartBoost = void 0; chart.boosted = false; // Clear the canvas if (!chart.axes.some((axis) => axis.isPanning)) { chart.boost.clear?.(); } if (chart.boost.canvas && chart.boost.wgl && isChartSeriesBoosting(chart)) { // Allocate chart.boost.wgl.allocateBuffer(chart); } // See #6518 + #6739 if (chart.boost.markerGroup && chart.xAxis && chart.xAxis.length > 0 && chart.yAxis && chart.yAxis.length > 0) { chart.boost.markerGroup.translate(chart.xAxis[0].pos, chart.yAxis[0].pos); } } addEvent(chart, 'predraw', preRender); // Use the load event rather than redraw, otherwise user load events will // fire too early (#18755) addEvent(chart, 'load', canvasToSVG, { order: -1 }); addEvent(chart, 'redraw', canvasToSVG); let prevX = -1; let prevY = -1; addEvent(chart.pointer, 'afterGetHoverData', (e) => { const series = e.hoverPoint?.series; chart.boost = chart.boost || {}; if (chart.boost.markerGroup && series) { const xAxis = chart.inverted ? series.yAxis : series.xAxis; const yAxis = chart.inverted ? series.xAxis : series.yAxis; if ((xAxis && xAxis.pos !== prevX) || (yAxis && yAxis.pos !== prevY)) { // #21176: If the axis is changed, hide teh halo without // animation to prevent flickering of halos sharing the // same marker group chart.series.forEach((s) => { s.halo?.hide(); }); // #10464: Keep the marker group position in sync with the // position of the hovered series axes since there is only // one shared marker group when boosting. chart.boost.markerGroup.translate(xAxis.pos, yAxis.pos); prevX = xAxis.pos; prevY = yAxis.pos; } } }); } /** * Tolerant max() function. * * @private * @param {...Array<Array<unknown>>} args * Max arguments * @return {number} * Max value */ function patientMax(...args) { let r = -Number.MAX_VALUE; args.forEach((t) => { if (typeof t !== 'undefined' && t !== null && typeof t.length !== 'undefined') { if (t.length > 0) { r = t.length; return true; } } }); return r; } /* * * * Default Export * * */ const BoostChart = { compose, getBoostClipRect, isChartSeriesBoosting }; /* harmony default export */ const Boost_BoostChart = (BoostChart); // EXTERNAL MODULE: external {"amd":["highcharts/highcharts","Color"],"commonjs":["highcharts","Color"],"commonjs2":["highcharts","Color"],"root":["Highcharts","Color"]} var highcharts_Color_commonjs_highcharts_Color_commonjs2_highcharts_Color_root_Highcharts_Color_ = __webpack_require__(620); var highcharts_Color_commonjs_highcharts_Color_commonjs2_highcharts_Color_root_Highcharts_Color_default = /*#__PURE__*/__webpack_require__.n(highcharts_Color_commonjs_highcharts_Color_commonjs2_highcharts_Color_root_Highcharts_Color_); ;// ./code/es-modules/Extensions/Boost/WGLDrawMode.js /* * * * (c) 2019-2024 Highsoft AS * * Boost module: stripped-down renderer for higher performance * * License: highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ /* * * * Constants * * */ const WGLDrawMode = { 'area': 'LINES', 'arearange': 'LINES', 'areaspline': 'LINES', 'column': 'LINES', 'columnrange': 'LINES', 'bar': 'LINES', 'line': 'LINE_STRIP', 'scatter': 'POINTS', 'heatmap': 'TRIANGLES', 'treemap': 'TRIANGLES', 'bubble': 'POINTS' }; /* * * * Default Export * * */ /* harmony default export */ const Boost_WGLDrawMode = (WGLDrawMode); ;// ./code/es-modules/Extensions/Boost/WGLShader.js /* * * * (c) 2019-2024 Highsoft AS * * Boost module: stripped-down renderer for higher performance * * License: highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ const { clamp, error, pick: WGLShader_pick } = (highcharts_commonjs_highcharts_commonjs2_highcharts_root_Highcharts_default()); /* * * * Constants * * */ const fragmentShader = [ /* eslint-disable max-len, @typescript-eslint/indent */ 'precision highp float;', 'uniform vec4 fillColor;', 'varying highp vec2 position;', 'varying highp vec4 vColor;', 'uniform sampler2D uSampler;', 'uniform bool isCircle;', 'uniform bool hasColor;', // 'vec4 toColor(float value, vec2 point) {', // 'return vec4(0.0, 0.0, 0.0, 0.0);', // '}', 'void main(void) {', 'vec4 col = fillColor;', 'vec4 tcol = texture2D(uSampler, gl_PointCoord.st);', 'if (hasColor) {', 'col = vColor;', '}', 'if (isCircle) {', 'col *= tcol;', 'if (tcol.r < 0.0) {', 'discard;', '} else {', 'gl_FragColor = col;', '}', '} else {', 'gl_FragColor = col;', '}', '}' /* eslint-enable max-len, @typescript-eslint/indent */ ].join('\n'); const vertexShader = [ /* eslint-disable max-len, @typescript-eslint/indent */ '#version 100', '#define LN10 2.302585092994046', 'precision highp float;', 'attribute vec4 aVertexPosition;', 'attribute vec4 aColor;', 'varying highp vec2 position;', 'varying highp vec4 vColor;', 'uniform mat4 uPMatrix;', 'uniform float pSize;', 'uniform float translatedThreshold;', 'uniform bool hasThreshold;', 'uniform bool skipTranslation;', 'uniform float xAxisTrans;', 'uniform float xAxisMin;', 'uniform float xAxisMinPad;', 'uniform float xAxisPointRange;', 'uniform float xAxisLen;', 'uniform bool xAxisPostTranslate;', 'uniform float xAxisOrdinalSlope;', 'uniform float xAxisOrdinalOffset;', 'uniform float xAxisPos;', 'uniform bool xAxisCVSCoord;', 'uniform bool xAxisIsLog;', 'uniform bool xAxisReversed;', 'uniform float yAxisTrans;', 'uniform float yAxisMin;', 'uniform float yAxisMinPad;', 'uniform float yAxisPointRange;', 'uniform float yAxisLen;', 'uniform bool yAxisPostTranslate;', 'uniform float yAxisOrdinalSlope;', 'uniform float yAxisOrdinalOffset;', 'uniform float yAxisPos;', 'uniform bool yAxisCVSCoord;', 'uniform bool yAxisIsLog;', 'uniform bool yAxisReversed;', 'uniform bool isBubble;', 'uniform bool bubbleSizeByArea;', 'uniform float bubbleZMin;', 'uniform float bubbleZMax;', 'uniform float bubbleZThreshold;', 'uniform float bubbleMinSize;', 'uniform float bubbleMaxSize;', 'uniform bool bubbleSizeAbs;', 'uniform bool isInverted;', 'float bubbleRadius(){', 'float value = aVertexPosition.w;', 'float zMax = bubbleZMax;', 'float zMin = bubbleZMin;', 'float radius = 0.0;', 'float pos = 0.0;', 'float zRange = zMax - zMin;', 'if (bubbleSizeAbs){', 'value = value - bubbleZThreshold;', 'zMax = max(zMax - bubbleZThreshold, zMin - bubbleZThreshold);', 'zMin = 0.0;', '}', 'if (value < zMin){', 'radius = bubbleZMin / 2.0 - 1.0;', '} else {', 'pos = zRange > 0.0 ? (value - zMin) / zRange : 0.5;', 'if (bubbleSizeByArea && pos > 0.0){', 'pos = sqrt(pos);', '}', 'radius = ceil(bubbleMinSize + pos * (bubbleMaxSize - bubbleMinSize)) / 2.0;', '}', 'return radius * 2.0;', '}', 'float translate(float val,', 'float pointPlacement,', 'float localA,', 'float localMin,', 'float minPixelPadding,', 'float pointRange,', 'float len,', 'bool cvsCoord,', 'bool isLog,', 'bool reversed', '){', 'float sign = 1.0;', 'float cvsOffset = 0.0;', 'if (cvsCoord) {', 'sign *= -1.0;', 'cvsOffset = len;', '}', 'if (isLog) {', 'val = log(val) / LN10;', '}', 'if (reversed) {', 'sign *= -1.0;', 'cvsOffset -= sign * len;', '}', 'return sign * (val - localMin) * localA + cvsOffset + ', '(sign * minPixelPadding);', // ' + localA * pointPlacement * pointRange;', '}', 'float xToPixels(float value) {', 'if (skipTranslation){', 'return value;// + xAxisPos;', '}', 'return translate(value, 0.0, xAxisTrans, xAxisMin, xAxisMinPad, xAxisPointRange, xAxisLen, xAxisCVSCoord, xAxisIsLog, xAxisReversed);// + xAxisPos;', '}', 'float yToPixels(float value, float checkTreshold) {', 'float v;', 'if (skipTranslation){', 'v = value;// + yAxisPos;', '} else {', 'v = translate(value, 0.0, yAxisTrans, yAxisMin, yAxisMinPad, yAxisPointRange, yAxisLen, yAxisCVSCoord, yAxisIsLog, yAxisReversed);// + yAxisPos;', 'if (v > yAxisLen) {', 'v = yAxisLen;', '}', '}', 'if (checkTreshold > 0.0 && hasThreshold) {', 'v = min(v, translatedThreshold);', '}', 'return v;', '}', 'void main(void) {', 'if (isBubble){', 'gl_PointSize = bubbleRadius();', '} else {', 'gl_PointSize = pSize;', '}', // 'gl_PointSize = 10.0;', 'vColor = aColor;', 'if (skipTranslation && isInverted) {', // If we get translated values from JS, just swap them (x, y) 'gl_Position = uPMatrix * vec4(aVertexPosition.y + yAxisPos, aVertexPosition.x + xAxisPos, 0.0, 1.0);', '} else if (isInverted) {', // But when calculating pixel positions directly, // swap axes and values (x, y) 'gl_Position = uPMatrix * vec4(yToPixels(aVertexPosition.y, aVertexPosition.z) + yAxisPos, xToPixels(aVertexPosition.x) + xAxisPos, 0.0, 1.0);', '} else {', 'gl_Position = uPMatrix * vec4(xToPixels(aVertexPosition.x) + xAxisPos, yToPixels(aVertexPosition.y, aVertexPosition.z) + yAxisPos, 0.0, 1.0);', '}', // 'gl_Position = uPMatrix * vec4(aVertexPosition.x, aVertexPosition.y, 0.0, 1.0);', '}' /* eslint-enable max-len, @typescript-eslint/indent */ ].join('\n'); /* * * * Class * * */ /* eslint-disable valid-jsdoc */ /** * A static shader mimicing axis translation functions found in Core/Axis * * @private * * @param {WebGLContext} gl * the context in which the shader is active */ class WGLShader { /* * * * Constructor * * */ constructor(gl) { // Error stack this.errors = []; this.uLocations = {}; this.gl = gl; if (gl && !this.createShader()) { return void 0; } } /* * * * Functions * * */ /** * Bind the shader. * This makes the shader the active one until another one is bound, * or until 0 is bound. * @private */ bind() { if (this.gl && this.shaderProgram) { this.gl.useProgram(this.shaderProgram); } } /** * Create the shader. * Loads the shader program statically defined above * @private */ createShader() { const v = this.stringToProgram(vertexShader, 'vertex'), f = this.stringToProgram(fragmentShader, 'fragment'), uloc = (n) => (this.gl.getUniformLocation(this.shaderProgram, n)); if (!v || !f) { this.shaderProgram = false; this.handleErrors(); return false; } this.shaderProgram = this.gl.createProgram(); this.gl.attachShader(this.shaderProgram, v); this.gl.attachShader(this.shaderProgram, f); this.gl.linkProgram(this.shaderProgram); if (!this.gl.getProgramParameter(this.shaderProgram, this.gl.LINK_STATUS)) { this.errors.push(this.gl.getProgramInfoLog(this.shaderProgram)); this.handleErrors(); this.shaderProgram = false; return false; } this.gl.useProgram(this.shaderProgram); this.gl.bindAttribLocation(this.shaderProgram, 0, 'aVertexPosition'); this.pUniform = uloc('uPMatrix'); this.psUniform = uloc('pSize'); this.fcUniform = uloc('fillColor'); this.isBubbleUniform = uloc('isBubble'); this.bubbleSizeAbsUniform = uloc('bubbleSizeAbs'); this.bubbleSizeAreaUniform = uloc('bubbleSizeByArea'); this.uSamplerUniform = uloc('uSampler'); this.skipTranslationUniform = uloc('skipTranslation'); this.isCircleUniform = uloc('isCircle'); this.isInverted = uloc('isInverted'); return true; } /** * Handle errors accumulated in errors stack * @private */ handleErrors() { if (this.errors.length) { error('[highcharts boost] shader error - ' + this.errors.join('\n')); } } /** * String to shader program * @private * @param {string} str * Program source * @param {string} type * Program type: either `vertex` or `fragment` */ stringToProgram(str, type) { const shader = this.gl.createShader(type === 'vertex' ? this.gl.VERTEX_SHADER : this.gl.FRAGMENT_SHADER); this.gl.shaderSource(shader, str); this.gl.compileShader(shader); if (!this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS)) { this.errors.push('when compiling ' + type + ' shader:\n' + this.gl.getShaderInfoLog(shader)); return false; } return shader; } /** * Destroy the shader * @private */ destroy() { if (this.gl && this.shaderProgram) { this.gl.deleteProgram(this.shaderProgram); this.shaderProgram = false; } } fillColorUniform() { return this.fcUniform; } /** * Get the shader program handle * @private * @return {WebGLProgram} * The handle for the program */ getProgram() { return this.shaderProgram; } pointSizeUniform() { return this.psUniform; } perspectiveUniform() { return this.pUniform; } /** * Flush * @private */ reset() { if (this.gl && this.shaderProgram) { this.gl.uniform1i(this.isBubbleUniform, 0); this.gl.uniform1i(this.isCircleUniform, 0); } } /** * Set bubble uniforms * @private * @param {Highcharts.Series} series * Series to use */ setBubbleUniforms(series, zCalcMin, zCalcMax, pixelRatio = 1) { const seriesOptions = series.options; let zMin = Number.MAX_VALUE, zMax = -Number.MAX_VALUE; if (this.gl && this.shaderProgram && series.is('bubble')) { const pxSizes = series.getPxExtremes(); zMin = WGLShader_pick(seriesOptions.zMin, clamp(zCalcMin, seriesOptions.displayNegative === false ? seriesOptions.zThreshold : -Number.MAX_VALUE, zMin)); zMax = WGLShader_pick(seriesOptions.zMax, Math.max(zMax, zCalcMax)); this.gl.uniform1i(this.isBubbleUniform, 1); this.gl.uniform1i(this.isCircleUniform, 1); this.gl.uniform1i(this.bubbleSizeAreaUniform, (series.options.sizeBy !== 'width')); this.gl.uniform1i(this.bubbleSizeAbsUniform, series.options .sizeByAbsoluteValue); this.setUniform('bubbleMinSize', pxSizes.minPxSize * pixelRatio); this.setUniform('bubbleMaxSize', pxSizes.maxPxSize * pixelRatio); this.setUniform('bubbleZMin', zMin); this.setUniform('bubbleZMax', zMax); this.setUniform('bubbleZThreshold', series.options.zThreshold); } } /** * Set the Color uniform. * @private * @param {Array<number>} color * Array with RGBA values. */ setColor(color) { if (this.gl && this.shaderProgram) { this.gl.uniform4f(this.fcUniform, color[0] / 255.0, color[1] / 255.0, color[2] / 255.0, color[3]); } } /** * Enable/disable circle drawing * @private */ setDrawAsCircle(flag) { if (this.gl && this.shaderProgram) { this.gl.uniform1i(this.isCircleUniform, flag ? 1 : 0); } } /** * Set if inversion state * @private * @param {number} flag * Inversion flag */ setInverted(flag) { if (this.gl && this.shaderProgram) { this.gl.uniform1i(this.isInverted, flag); } } /** * Set the perspective matrix * @private * @param {Float32List} m * Matrix 4 x 4 */ setPMatrix(m) { if (this.gl && this.shaderProgram) { this.gl.uniformMatrix4fv(this.pUniform, false, m); } } /** * Set the point size. * @private * @param {number} p * Point size */ setPointSize(p) { if (this.gl && this.shaderProgram) { this.gl.uniform1f(this.psUniform, p); } } /** * Set skip translation * @private */ setSkipTranslation(flag) { if (this.gl && this.shaderProgram) { this.gl.uniform1i(this.skipTranslationUniform, flag === true ? 1 : 0); } } /** * Set the active texture * @private * @param {number} texture * Texture to activate */ setTexture(texture) { if (this.gl && this.shaderProgram) { this.gl.uniform1i(this.uSamplerUniform, texture); } } /** * Set a uniform value. * This uses a hash map to cache uniform locations. * @private * @param {string} name * Name of the uniform to set. * @param {number} val * Value to set */ setUniform(name, val) { if (this.gl && this.shaderProgram) { const u = this.uLocations[name] = (this.uLocations[name] || this.gl.getUniformLocation(this.shaderProgram, name)); this.gl.uniform1f(u, val); } } } /* * * * Default Export * * */ /* harmony default export */ const Boost_WGLShader = (WGLShader); ;// ./code/es-modules/Extensions/Boost/WGLVertexBuffer.js /* * * * (c) 2019-2024 Highsoft AS * * Boost module: stripped-down renderer for higher performance * * License: highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ /* * * * Class * * */ /** * Vertex Buffer abstraction. * A vertex buffer is a set of vertices which are passed to the GPU * in a single call. * * @private * @class * @name WGLVertexBuffer * * @param {WebGLContext} gl * Context in which to create the buffer. * @param {WGLShader} shader * Shader to use. */ class WGLVertexBuffer { /* * * * Constructor * * */ constructor(gl, shader, dataComponents /* , type */ ) { /* * * * Properties * * */ this.buffer = false; this.iterator = 0; this.preAllocated = false; this.vertAttribute = false; this.components = dataComponents || 2; this.dataComponents = dataComponents; this.gl = gl; this.shader = shader; } /* * * * Functions * * */ /** * Note about pre-allocated buffers: * - This is slower for charts with many series * @private */ allocate(size) { this.iterator = -1; this.preAllocated = new Float32Array(size * 4); } /** * Bind the buffer * @private */ bind() { if (!this.buffer) { return false; } /// gl.bindAttribLocation(shader.program(), 0, 'aVertexPosition'); // gl.enableVertexAttribArray(vertAttribute); // gl.bindBuffer(gl.ARRAY_BUFFER, buffer); this.gl.vertexAttribPointer(this.vertAttribute, this.components, this.gl.FLOAT, false, 0, 0); /// gl.enableVertexAttribArray(vertAttribute); } /** * Build the buffer * @private * @param {Array<number>} dataIn * Zero padded array of indices * @param {string} attrib * Name of the Attribute to bind the buffer to * @param {number} dataComponents * Number of components per. indice */ build(dataIn, attrib, dataComponents) { let farray; this.data = dataIn || []; if ((!this.data || this.data.length === 0) && !this.preAllocated) { /// console.error('trying to render empty vbuffer'); this.destroy(); return false; } this.components = dataComponents || this.components; if (this.buffer) { this.gl.deleteBuffer(this.buffer); } if (!this.preAllocated) { farray = new Float32Array(this.data); } this.buffer = this.gl.createBuffer(); this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.buffer); this.gl.bufferData(this.gl.ARRAY_BUFFER, this.preAllocated || farray, this.gl.STATIC_DRAW); /// gl.bindAttribLocation(shader.program(), 0, 'aVertexPosition'); this.vertAttribute = this.gl .getAttribLocation(this.shader.getProgram(), attrib); this.gl.enableVertexAttribArray(this.vertAttribute); // Trigger cleanup farray = false; return true; } /** * @private */ destroy() { if (this.buffer) { this.gl.deleteBuffer(this.buffer); this.buffer = false; this.vertAttribute = false; } this.iterator = 0; this.components = this.dataComponents || 2; this.data = []; } /** * Adds data to the pre-allocated buffer. * @private * @param {number} x * X data * @param {number} y * Y data * @param {number} a * A data * @param {number} b * B data */ push(x, y, a, b) { if (this.preAllocated) { // && iterator <= preAllocated.length - 4) { this.preAllocated[++this.iterator] = x; this.preAllocated[++this.iterator] = y; this.preAllocated[++this.iterator] = a; this.preAllocated[++this.iterator] = b; } } /** * Render the buffer * * @private * @param {number} from * Start indice. * @param {number} to * End indice. * @param {WGLDrawModeValue} drawMode * Draw mode. */ render(from, to, drawMode) { const length = this.preAllocated ? this.preAllocated.length : this.data.length; if (!this.buffer) { return false; } if (!length) { return false; } if (!from || from > length || from < 0) { from = 0; } if (!to || to > length) { to = length; } if (from >= to) { return false; } drawMode = drawMode || 'POINTS'; this.gl.drawArrays(this.gl[drawMode], from / this.components, (to - from) / this.components); return true; } } /* * * * Default Export * * */ /* harmony default export */ const Boost_WGLVertexBuffer = (WGLVertexBuffer); ;// ./code/es-modules/Extensions/Boost/WGLRenderer.js /* * * * (c) 2019-2024 Highsoft AS * * Boost module: stripped-down renderer for higher performance * * License: highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ const { parse: color } = (highcharts_Color_commonjs_highcharts_Color_commonjs2_highcharts_Color_root_Highcharts_Color_default()); const { doc, win } = (highcharts_commonjs_highcharts_commonjs2_highcharts_root_Highcharts_default()); const { isNumber, isObject, merge, objectEach, pick: WGLRenderer_pick } = (highcharts_commonjs_highcharts_commonjs2_highcharts_root_Highcharts_default()); /* * * * Constants * * */ // Things to draw as "rectangles" (i.e lines) const asBar = { 'column': true, 'columnrange': true, 'bar': true, 'area': true, 'areaspline': true, 'arearange': true }; const asCircle = { 'scatter': true, 'bubble': true }; const contexts = [ 'webgl', 'experimental-webgl', 'moz-webgl', 'webkit-3d' ]; /* * * * Class * * */ /* eslint-disable valid-jsdoc */ /** * Main renderer. Used to render series. * * Notes to self: * - May be able to build a point map by rendering to a separate canvas and * encoding values in the color data. * - Need to figure out a way to transform the data quicker * * @private * * @param {Function} postRenderCallback */ class WGLRenderer { /* * * * Static Functions * * */ /** * Returns an orthographic perspective matrix * @private * @param {number} width * the width of the viewport in pixels * @param {number} height * the height of the viewport in pixels */ static orthoMatrix(width, height) { const near = 0, far = 1; return [ 2 / width, 0, 0, 0, 0, -(2 / height), 0, 0, 0, 0, -2 / (far - near), 0, -1, 1, -(far + near) / (far - near), 1 ]; } /** * @private */ static seriesPointCount(series) { let isStacked, xData, s; if (series.boosted) { isStacked = !!series.options.stacking; xData = ((series.getColumn('x').length ? series.getColumn('x') : void 0) || series.options.xData || series.getColumn('x', true)); s = (isStacked ? series.data : (xData || series.options.data)) .length; if (series.type === 'treemap') { s *= 12; } else if (series.type === 'heatmap') { s *= 6; } else if (asBar[series.type]) { s *= 2; } return s; } return 0; } /* * * * Constructor * * */ constructor(postRenderCallback) { /** * The data to render - array of coordinates. * Repeating sequence of [x, y, checkThreshold, pointSize]. */ this.data = []; // Height of our viewport in pixels this.height = 0; // Is it inited? this.isInited = false; // The marker data this.markerData = []; // The series stack this.series = []; // Texture handles this.textureHandles = {}; // Width of our viewport in pixels this.width = 0; this.postRenderCallback = postRenderCallback; this.settings = { pointSize: 1, lineWidth: 1, fillColor: '#AA00AA', useAlpha: true, usePreallocated: false, useGPUTranslations: false, debug: { timeRendering: false, timeSeriesProcessing: false, timeSetup: false, timeBufferCopy: false, timeKDTree: false, showSkipSummary: false } }; } /* * * * Functions * * */ /** * @private */ getPixelRatio() { return this.settings.pixelRatio || win.devicePixelRatio || 1; } /** * @private */ setOptions(options) { // The pixelRatio defaults to 1. This is an antipattern, we should // refactor the Boost options to include an object of default options as // base for the merge, like other components. if (!('pixelRatio' in options)) { options.pixelRatio = 1; } merge(true, this.settings, options); } /** * Allocate a float buffer to fit all series * @private */ allocateBuffer(chart) { const vbuffer = this.vbuffer; let s = 0; if (!this.settings.usePreallocated) { return; } chart.series.forEach((series) => { if (series.boosted) { s += WGLRenderer.seriesPointCount(series); } }); vbuffer && vbuffer.allocate(s); } /** * @private */ allocateBufferForSingleSeries(series) { const vbuffer = this.vbuffer; let s = 0; if (!this.settings.usePreallocated) { return; } if (series.boosted) { s = WGLRenderer.seriesPointCount(series); } vbuffer && vbuffer.allocate(s); } /** * Clear the depth and color buffer * @private */ clear() { const gl = this.gl; gl && gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); } /** * Push data for a single series * This calculates additional vertices and transforms the data to be * aligned correctly in memory * @private */ pushSeriesData(series, inst) { const data = this.data, settings = this.settings, vbuffer = this.vbuffer, isRange = (series.pointArrayMap && series.pointArrayMap.join(',') === 'low,high'), { chart, options, sorted, xAxis, yAxis } = series, isStacked = !!options.stacking, rawData = options.data, xExtremes = series.xAxis.getExtremes(), // Taking into account the offset of the min point #19497 xMin = xExtremes.min - (series.xAxis.minPointOffset || 0), xMax = xExtremes.max + (series.xAxis.minPointOffset || 0), yExtremes = series.yAxis.getExtremes(), yMin = yExtremes.min - (series.yAxis.minPointOffset || 0), yMax = yExtremes.max + (series.yAxis.minPointOffset || 0), xData = (series.getColumn('x').length ? series.getColumn('x') : void 0) || options.xData || series.getColumn('x', true), yData = (series.getColumn('y').length ? series.getColumn('y') : void 0) || options.yData || series.getColumn('y', true), zData = (series.getColumn('z').length ? series.getColumn('z') : void 0) || options.zData || series.getColumn('z', true), useRaw = !xData || xData.length === 0, /// threshold = options.threshold, // yBottom = chart.yAxis[0].getThreshold(threshold), // hasThreshold = isNumber(threshold), // colorByPoint = series.options.colorByPoint, // This is required for color by point, so make sure this is // uncommented if enabling that // colorIndex = 0, // Required for color axis support // caxis, connectNulls = options.connectNulls, // For some reason eslint/TypeScript don't pick up that this is // actually used: --- bre1470: it is never read, just set // maxVal: (number|undefined), // eslint-disable-line no-unused-vars points = series.points || false, sdata = isStacked ? series.data : (xData || rawData), closestLeft = { x: Number.MAX_VALUE, y: 0 }, closestRight = { x: -Number.MAX_VALUE, y: 0 }, cullXThreshold = 1, cullYThreshold = 1, chartDestroyed = typeof chart.index === 'undefined', drawAsBar = asBar[series.type], zoneAxis = options.zoneAxis || 'y', zones = options.zones || false, threshold = options.threshold, pixelRatio = this.getPixelRatio(); let plotWidth = series.chart.plotWidth, lastX = false, lastY = false, minVal, scolor, // skipped = 0, hadPoints = false, // The following are used in the builder while loop x, y, d, z, i = -1, px = false, nx = false, low, nextInside = false, prevInside = false, pcolor = false, isXInside = false, isYInside = true, firstPoint = true, zoneColors, zoneDefColor = false, gapSize = false, vlen = 0; if (options.boostData && options.boostData.length > 0) { return; } if (options.gapSize) { gapSize = options.gapUnit !== 'value' ? options.gapSize * series.closestPointRange : options.gapSize; } if (zones) { zoneColors = []; zones.forEach((zone, i) => { if (zone.color) { const zoneColor = color(zone.color).rgba; zoneColor[0] /= 255.0; zoneColor[1] /= 255.0; zoneColor[2] /= 255.0; zoneColors[i] = zoneColor; if (!zoneDefColor && typeof zone.value === 'undefined') { zoneDefColor = zoneColor; } } }); if (!zoneDefColor) { const seriesColor = ((series.pointAttribs && series.pointAttribs().fill) || series.color); zoneDefColor = color(seriesColor).rgba; zoneDefColor[0] /= 255.0; zoneDefColor[1] /= 255.0; zoneDefColor[2] /= 255.0; } } if (chart.inverted) { plotWidth = series.chart.plotHeight; } series.closestPointRangePx = Number.MAX_VALUE; /** * Push color to color buffer - need to do this per vertex. * @private */ const pushColor = (color) => { if (color) { inst.colorData.push(color[0]); inst.colorData.push(color[1]); inst.colorData.push(color[2]); inst.colorData.push(color[3]); } }; /** * Push a vertice to the data buffer. * @private */ const vertice = (x, y, checkTreshold, pointSize = 1, color) => { pushColor(color); // Correct for pixel ratio if (pixelRatio !== 1 && (!settings.useGPUTranslations || inst.skipTranslation)) { x *= pixelRatio; y *= pixelRatio; pointSize *= pixelRatio; } if (settings.usePreallocated && vbuffer) { vbuffer.push(x, y, checkTreshold ? 1 : 0, pointSize); vlen += 4; } else { data.push(x); data.push(y); data.push(checkTreshold ? pixelRatio : 0); data.push(pointSize); } }; /** * @private */ const closeSegment = () => { if (inst.segments.length) { inst.segments[inst.segments.length - 1].to = data.length || vlen; } }; /** * Create a new segment for the current set. * @private */ const beginSegment = () => { // Insert a segment on the series. // A segment is just a start indice. // When adding a segment, if one exists from before, it should // set the previous segment's end if (inst.segments.length && inst.segments[inst.segments.length - 1].from === (data.length || vlen)) { return; } closeSegment(); inst.segments.push({ from: data.length || vlen }); }; /** * Push a rectangle to the data buffer. * @private */ const pushRect = (x, y, w, h, color) => { pushColor(color); vertice(x + w, y); pushColor(color); vertice(x, y); pushColor(color); vertice(x, y + h); pushColor(color); vertice(x, y + h); pushColor(color); vertice(x + w, y + h); pushColor(color); vertice(x + w, y); }; // Create the first segment beginSegment(); // Special case for point shapes if (points && points.length > 0) { // If we're doing points, we assume that the points are already // translated, so we skip the shader translation. inst.skipTranslation = true; // Force triangle draw mode inst.drawMode = 'TRIANGLES'; // We don't have a z component in the shader, so we need to sort. if (points[0].node && points[0].node.levelDynamic) { points.sort((a, b) => { if (a.node) { if (a.node.levelDynamic > b.node.levelDynamic) { return 1; } if (a.node.levelDynamic < b.node.levelDynamic) { return -1; } } return 0; }); } points.forEach((point) => { const plotY = point.plotY; let swidth, pointAttr; if (typeof plotY !== 'undefined' && !isNaN(plotY) && point.y !== null && point.shapeArgs) { let { x = 0, y = 0, width = 0, height = 0 } = point.shapeArgs; pointAttr = chart.styledMode ? point.series .colorAttribs(point) : pointAttr = point.series.pointAttribs(point); swidth = pointAttr['stroke-width'] || 0; // Handle point colors pcolor = color(pointAttr.fill).rgba; pcolor[0] /= 255.0; pcolor[1] /= 255.0; pcolor[2] /= 255.0; // So there are two ways of doing this. Either we can // create a rectangle of two triangles, or we can do a // point and use point size. Latter is faster, but // only supports squares. So we're doing triangles. // We could also use one color per. vertice to get // better color interpolation. // If there's stroking, we do an additional rect if (series.is('treemap')) { swidth = swidth || 1; scolor = color(pointAttr.stroke).rgba; scolor[0] /= 255.0; scolor[1] /= 255.0; scolor[2] /= 255.0; pushRect(x, y, width, height, scolor); swidth /= 2; } // } else { // swidth = 0; // } // Fixes issues with inverted heatmaps (see #6981). The root // cause is that the coordinate system is flipped. In other // words, instead of [0,0] being top-left, it's // bottom-right. This causes a vertical and horizontal flip // in the resulting image, making it rotated 180 degrees. if (series.is('heatmap') && chart.inverted) { x = xAxis.len - x; y = yAxis.len - y;