-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
BoostSeries.ts
1379 lines (1208 loc) · 37.6 KB
/
BoostSeries.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* *
*
* Copyright (c) 2019-2021 Highsoft AS
*
* Boost module: stripped-down renderer for higher performance
*
* License: highcharts.com/license
*
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
*
* */
'use strict';
/* *
*
* Imports
*
* */
import type { BoostChartComposition } from './BoostChart';
import type {
BoostTargetAdditions,
BoostTargetObject
} from './BoostTargetObject';
import type Chart from '../../Core/Chart/Chart';
import type DataExtremesObject from '../../Core/Series/DataExtremesObject';
import type LineSeries from '../../Series/Line/LineSeries';
import type Point from '../../Core/Series/Point';
import type {
PointOptions,
PointShortOptions
} from '../../Core/Series/PointOptions';
import type Series from '../../Core/Series/Series';
import type SeriesRegistry from '../../Core/Series/SeriesRegistry';
import type { SeriesTypePlotOptions } from '../../Core/Series/SeriesType';
import type SVGAttributes from '../../Core/Renderer/SVG/SVGAttributes';
import type SVGElement from '../../Core/Renderer/SVG/SVGElement';
import type SVGPath from '../../Core/Renderer/SVG/SVGPath';
import BoostableMap from './BoostableMap.js';
import Boostables from './Boostables.js';
import BoostChart from './BoostChart.js';
const {
getBoostClipRect,
isChartSeriesBoosting
} = BoostChart;
import D from '../../Core/Defaults.js';
const { getOptions } = D;
import H from '../../Core/Globals.js';
const {
doc,
noop,
win
} = H;
import U from '../../Core/Utilities.js';
const {
addEvent,
destroyObjectProperties,
error,
extend,
fireEvent,
isArray,
isNumber,
pick,
wrap,
defined
} = U;
import WGLRenderer from './WGLRenderer.js';
/* *
*
* Declarations
*
* */
declare module '../../Core/Series/SeriesLike' {
interface SeriesLike extends BoostTargetObject {
boosted?: boolean;
boost?: BoostSeriesAdditions;
fill?: boolean;
fillOpacity?: boolean;
sampling?: boolean;
}
}
declare module '../../Core/Series/SeriesOptions' {
interface SeriesOptions {
boostData?: Array<unknown>;
xData?: Array<number>;
yData?: Array<(number|null)>;
}
}
interface BoostAlteredObject {
own: boolean;
prop: ('allowDG'|'directTouch'|'stickyTracking');
val: unknown;
value?: unknown;
}
interface BoostPointMockup {
destroy(): void;
x: (false|number);
clientX: number;
dist?: number;
distX?: number;
plotX: number;
plotY: number;
i: number;
percentage: number;
}
interface BoostSeriesAdditions extends BoostTargetAdditions {
altered?: Array<BoostAlteredObject>;
getPoint(boostPoint: (BoostPointMockup|Point)): BoostPointComposition;
}
export declare class BoostPointComposition extends Point {
series: BoostSeriesComposition;
init(
series: BoostSeriesComposition,
options: (PointOptions|PointShortOptions),
x?: number
): BoostPointComposition;
}
export declare class BoostSeriesComposition extends Series {
boosted?: boolean;
boost: BoostSeriesAdditions;
chart: BoostChartComposition;
pointClass: typeof BoostPointComposition;
}
/* *
*
* Constants
*
* */
const CHUNK_SIZE = 3000;
const composedMembers: Array<unknown> = [];
/* *
*
* Variables
*
* */
let index: (number|string),
mainCanvas: (HTMLCanvasElement|undefined);
/* *
*
* Functions
*
* */
/**
* @private
*/
function allocateIfNotSeriesBoosting(
renderer: WGLRenderer,
series: Series
): void {
const boost = series.boost;
if (renderer &&
boost &&
boost.target &&
boost.canvas &&
!isChartSeriesBoosting(series.chart)
) {
renderer.allocateBufferForSingleSeries(series);
}
}
/**
* Return true if ths boost.enabled option is true
*
* @private
* @param {Highcharts.Chart} chart
* The chart
* @return {boolean}
* True, if boost is enabled.
*/
function boostEnabled(chart: Chart): boolean {
return pick(
(
chart &&
chart.options &&
chart.options.boost &&
chart.options.boost.enabled
),
true
);
}
/**
* @private
*/
function compose<T extends typeof Series>(
SeriesClass: T,
seriesTypes: typeof SeriesRegistry.seriesTypes,
wglMode?: boolean
): (T&typeof BoostSeriesComposition) {
if (U.pushUnique(composedMembers, SeriesClass)) {
addEvent(SeriesClass, 'destroy', onSeriesDestroy);
addEvent(SeriesClass, 'hide', onSeriesHide);
const seriesProto = SeriesClass.prototype as BoostSeriesComposition;
if (wglMode) {
seriesProto.renderCanvas = seriesRenderCanvas;
}
wrap(seriesProto, 'getExtremes', wrapSeriesGetExtremes);
wrap(seriesProto, 'processData', wrapSeriesProcessData);
wrap(seriesProto, 'searchPoint', wrapSeriesSearchPoint);
(
[
'translate',
'generatePoints',
'drawTracker',
'drawPoints',
'render'
] as Array<(
'translate'|
'generatePoints'|
'drawTracker'|
'drawPoints'|
'render'
)>
).forEach((method): void =>
wrapSeriesFunctions(seriesProto, seriesTypes, method)
);
}
if (U.pushUnique(composedMembers, getOptions)) {
const plotOptions =
getOptions().plotOptions as SeriesTypePlotOptions;
// Set default options
Boostables.forEach((type: string): void => {
const typePlotOptions = plotOptions[type];
if (typePlotOptions) {
typePlotOptions.boostThreshold = 5000;
typePlotOptions.boostData = [];
seriesTypes[type].prototype.fillOpacity = true;
}
});
}
if (wglMode) {
const {
area: AreaSeries,
areaspline: AreaSplineSeries,
bubble: BubbleSeries,
column: ColumnSeries,
heatmap: HeatmapSeries,
scatter: ScatterSeries,
treemap: TreemapSeries
} = seriesTypes;
if (
AreaSeries &&
U.pushUnique(composedMembers, AreaSeries)
) {
extend(AreaSeries.prototype, {
fill: true,
fillOpacity: true,
sampling: true
});
}
if (
AreaSplineSeries &&
U.pushUnique(composedMembers, AreaSplineSeries)
) {
extend(AreaSplineSeries.prototype, {
fill: true,
fillOpacity: true,
sampling: true
});
}
if (
BubbleSeries &&
U.pushUnique(composedMembers, BubbleSeries)
) {
const bubbleProto = BubbleSeries.prototype;
// By default, the bubble series does not use the KD-tree, so force
// it to.
delete (bubbleProto as Partial<Series>).buildKDTree;
// seriesTypes.bubble.prototype.directTouch = false;
// Needed for markers to work correctly
wrap(
bubbleProto,
'markerAttribs',
function (
this: typeof bubbleProto,
proceed: Function
): boolean {
if (this.boosted) {
return false;
}
return proceed.apply(this, [].slice.call(arguments, 1));
}
);
}
if (
ColumnSeries &&
U.pushUnique(composedMembers, ColumnSeries)
) {
extend(ColumnSeries.prototype, {
fill: true,
sampling: true
});
}
if (
ScatterSeries &&
U.pushUnique(composedMembers, ScatterSeries)
) {
ScatterSeries.prototype.fill = true;
}
// We need to handle heatmaps separatly, since we can't perform the
// size/color calculations in the shader easily.
// @todo This likely needs future optimization.
[HeatmapSeries, TreemapSeries].forEach((SC): void => {
if (SC && U.pushUnique(composedMembers, SC)) {
wrap(SC.prototype, 'drawPoints', wrapSeriesDrawPoints);
}
});
}
return SeriesClass as (T&typeof BoostSeriesComposition);
}
/**
* Create a canvas + context and attach it to the target
*
* @private
* @function createAndAttachRenderer
*
* @param {Highcharts.Chart} chart
* the chart
*
* @param {Highcharts.Series} series
* the series
*
* @return {Highcharts.BoostGLRenderer}
* the canvas renderer
*/
function createAndAttachRenderer(
chart: Chart,
series: Series
): WGLRenderer {
const ChartClass = chart.constructor as typeof Chart,
targetGroup = chart.seriesGroup || series.group,
alpha = 1;
let width = chart.chartWidth,
height = chart.chartHeight,
target: BoostTargetObject = chart,
foSupported: boolean = typeof SVGForeignObjectElement !== 'undefined';
if (isChartSeriesBoosting(chart)) {
target = chart;
} else {
target = series;
}
const boost: Required<BoostTargetAdditions> = target.boost =
target.boost as Required<BoostTargetAdditions> ||
{} as Required<BoostTargetAdditions>;
// Support for foreignObject is flimsy as best.
// IE does not support it, and Chrome has a bug which messes up
// the canvas draw order.
// As such, we force the Image fallback for now, but leaving the
// actual Canvas path in-place in case this changes in the future.
foSupported = false;
if (!mainCanvas) {
mainCanvas = doc.createElement('canvas');
}
if (!boost.target) {
boost.canvas = mainCanvas;
// Fall back to image tag if foreignObject isn't supported,
// or if we're exporting.
if (chart.renderer.forExport || !foSupported) {
target.renderTarget = boost.target = chart.renderer.image(
'',
0,
0,
width,
height
)
.addClass('highcharts-boost-canvas')
.add(targetGroup);
boost.clear = function (): void {
boost.target.attr({
// Insert a blank pixel (#17182)
/* eslint-disable-next-line max-len*/
href: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='
});
};
boost.copy = function (): void {
boost.resize();
boost.target.attr({
href: boost.canvas.toDataURL('image/png')
});
};
} else {
boost.targetFo = chart.renderer
.createElement('foreignObject')
.add(targetGroup);
target.renderTarget = boost.target =
doc.createElement('canvas') as any;
boost.targetCtx = boost.target.getContext('2d');
boost.targetFo.element.appendChild(boost.target as any);
boost.clear = function (): void {
boost.target.width = boost.canvas.width;
boost.target.height = boost.canvas.height;
};
boost.copy = function (): void {
boost.target.width = boost.canvas.width;
boost.target.height = boost.canvas.height;
boost.targetCtx.drawImage(boost.canvas, 0, 0);
};
}
boost.resize = function (): void {
width = chart.chartWidth;
height = chart.chartHeight;
(boost.targetFo || boost.target)
.attr({
x: 0,
y: 0,
width,
height
})
.css({
pointerEvents: 'none',
mixedBlendMode: 'normal',
opacity: alpha
} as any);
if (target instanceof ChartClass) {
(target.boost as any).markerGroup.translate(
chart.plotLeft,
chart.plotTop
);
}
};
boost.clipRect = chart.renderer.clipRect();
(boost.targetFo || boost.target)
.attr({
// Set the z index of the boost target to that of the last
// series using it. This logic is not perfect, as it will not
// handle interleaved series with boost enabled or disabled. But
// it will cover the most common use case of one or more
// successive boosted or non-boosted series (#9819).
zIndex: series.options.zIndex
})
.clip(boost.clipRect);
if (target instanceof ChartClass) {
(target.boost as any).markerGroup = target.renderer
.g()
.add(targetGroup)
.translate(series.xAxis.pos, series.yAxis.pos);
}
}
boost.canvas.width = width;
boost.canvas.height = height;
if (boost.clipRect) {
boost.clipRect.attr(getBoostClipRect(chart, target));
}
boost.resize();
boost.clear();
if (!boost.wgl) {
boost.wgl = new WGLRenderer((wgl): void => {
if (wgl.settings.debug.timeBufferCopy) {
console.time('buffer copy'); // eslint-disable-line no-console
}
boost.copy();
if (wgl.settings.debug.timeBufferCopy) {
console.timeEnd('buffer copy'); // eslint-disable-line no-console
}
});
if (!boost.wgl.init(boost.canvas)) {
// The OGL renderer couldn't be inited.
// This likely means a shader error as we wouldn't get to this point
// if there was no WebGL support.
error('[highcharts boost] - unable to init WebGL renderer');
}
// target.ogl.clear();
boost.wgl.setOptions(chart.options.boost || {});
if (target instanceof ChartClass) {
boost.wgl.allocateBuffer(chart);
}
}
boost.wgl.setSize(width, height);
return boost.wgl;
}
/**
* If implemented in the core, parts of this can probably be
* shared with other similar methods in Highcharts.
* @private
* @function Highcharts.Series#destroyGraphics
*/
function destroyGraphics(
series: Series
): void {
const points = series.points;
if (points) {
let point: Point,
i: number;
for (i = 0; i < points.length; i = i + 1) {
point = points[i];
if (point && point.destroyElements) {
point.destroyElements(); // #7557
}
}
}
(
['graph', 'area', 'tracker'] as
Array<('graph'|'area'|'tracker')>
).forEach((prop): void => {
const seriesProp = series[prop];
if (seriesProp) {
series[prop] = seriesProp.destroy();
}
});
series.zones.forEach(destroyObjectProperties);
}
/**
* An "async" foreach loop. Uses a setTimeout to keep the loop from blocking the
* UI thread.
*
* @private
* @param {Array<unknown>} arr
* The array to loop through.
* @param {Function} fn
* The callback to call for each item.
* @param {Function} finalFunc
* The callback to call when done.
* @param {number} [chunkSize]
* The number of iterations per timeout.
* @param {number} [i]
* The current index.
* @param {boolean} [noTimeout]
* Set to true to skip timeouts.
*/
function eachAsync(
arr: Array<unknown>,
fn: Function,
finalFunc: Function,
chunkSize?: number,
i?: number,
noTimeout?: boolean
): void {
i = i || 0;
chunkSize = chunkSize || CHUNK_SIZE;
const threshold = i + chunkSize;
let proceed = true;
while (proceed && i < threshold && i < arr.length) {
proceed = fn(arr[i], i);
++i;
}
if (proceed) {
if (i < arr.length) {
if (noTimeout) {
eachAsync(arr, fn, finalFunc, chunkSize, i, noTimeout);
} else if (win.requestAnimationFrame) {
// If available, do requestAnimationFrame - shaves off a few ms
win.requestAnimationFrame(function (): void {
eachAsync(arr, fn, finalFunc, chunkSize, i);
});
} else {
setTimeout(eachAsync, 0, arr, fn, finalFunc, chunkSize, i);
}
} else if (finalFunc) {
finalFunc();
}
}
}
/**
* Enter boost mode and apply boost-specific properties.
* @private
* @function Highcharts.Series#enterBoost
*/
function enterBoost(
series: Series
): void {
series.boost = series.boost || {
// faster than a series bind:
getPoint: ((bp): BoostPointComposition => getPoint(series, bp))
};
const alteredByBoost: Array<BoostAlteredObject> = series.boost.altered = [];
// Save the original values, including whether it was an own
// property or inherited from the prototype.
(
['allowDG', 'directTouch', 'stickyTracking'] as
Array<('allowDG'|'directTouch'|'stickyTracking')>
).forEach((prop): void => {
alteredByBoost.push({
prop: prop,
val: series[prop],
own: Object.hasOwnProperty.call(series, prop)
});
});
series.allowDG = false;
series.directTouch = false;
series.stickyTracking = true;
// Prevent animation when zooming in on boosted series(#13421).
series.finishedAnimating = true;
// Hide series label if any
if (series.labelBySeries) {
series.labelBySeries = series.labelBySeries.destroy();
}
}
/**
* Exit from boost mode and restore non-boost properties.
* @private
* @function Highcharts.Series#exitBoost
*/
function exitBoost(
series: Series
): void {
const boost = series.boost;
// Reset instance properties and/or delete instance properties and go back
// to prototype
if (boost) {
(boost.altered || []).forEach((setting): void => {
if (setting.own) {
series[setting.prop] = setting.val as any;
} else {
// Revert to prototype
delete series[setting.prop];
}
});
// Clear previous run
if (boost.clear) {
boost.clear();
}
}
}
/**
* @private
* @function Highcharts.Series#hasExtremes
*/
function hasExtremes(
series: Series,
checkX?: boolean
): boolean {
const options = series.options,
data: Array<(PointOptions|PointShortOptions)> = options.data as any,
xAxis = series.xAxis && series.xAxis.options,
yAxis = series.yAxis && series.yAxis.options,
colorAxis = series.colorAxis && series.colorAxis.options;
return data.length > (options.boostThreshold || Number.MAX_VALUE) &&
// Defined yAxis extremes
isNumber(yAxis.min) &&
isNumber(yAxis.max) &&
// Defined (and required) xAxis extremes
(!checkX ||
(isNumber(xAxis.min) && isNumber(xAxis.max))
) &&
// Defined (e.g. heatmap) colorAxis extremes
(!colorAxis ||
(isNumber(colorAxis.min) && isNumber(colorAxis.max))
);
}
/**
* Extend series.destroy to also remove the fake k-d-tree points (#5137).
* Normally this is handled by Series.destroy that calls Point.destroy,
* but the fake search points are not registered like that.
* @private
*/
function onSeriesDestroy(
this: Series
): void {
const series = this,
chart = series.chart;
if (
chart.boost &&
chart.boost.markerGroup === series.markerGroup
) {
series.markerGroup = null as any;
}
if (chart.hoverPoints) {
chart.hoverPoints = chart.hoverPoints.filter(function (
point: Point
): boolean {
return point.series === series;
});
}
if (chart.hoverPoint && chart.hoverPoint.series === series) {
chart.hoverPoint = null as any;
}
}
/**
* @private
*/
function onSeriesHide(
this: Series
): void {
const boost = this.boost;
if (boost && boost.canvas && boost.target) {
if (boost.wgl) {
boost.wgl.clear();
}
if (boost.clear) {
boost.clear();
}
}
}
/**
* Performs the actual render if the renderer is
* attached to the series.
* @private
*/
function renderIfNotSeriesBoosting(series: Series): void {
const boost = series.boost;
if (
boost &&
boost.canvas &&
boost.target &&
boost.wgl &&
!isChartSeriesBoosting(series.chart)
) {
boost.wgl.render(series.chart);
}
}
/**
* Return a full Point object based on the index.
* The boost module uses stripped point objects for performance reasons.
* @private
* @param {object|Highcharts.Point} boostPoint
* A stripped-down point object
* @return {Highcharts.Point}
* A Point object as per https://api.highcharts.com/highcharts#Point
*/
function getPoint(
series: Series,
boostPoint: (BoostPointMockup|Point)
): BoostPointComposition {
const seriesOptions = series.options,
xAxis = series.xAxis,
PointClass = series.pointClass;
if (boostPoint instanceof PointClass) {
return boostPoint as BoostPointComposition;
}
const xData = (
series.xData ||
seriesOptions.xData ||
series.processedXData ||
false
),
point = (new PointClass()).init(
series as BoostSeriesComposition,
(series.options.data as any)[boostPoint.i],
xData ? xData[boostPoint.i] : void 0
) as BoostPointComposition;
point.category = pick(
xAxis.categories ?
xAxis.categories[point.x] :
point.x, // @todo simplify
point.x
);
point.dist = boostPoint.dist;
point.distX = boostPoint.distX;
point.plotX = boostPoint.plotX;
point.plotY = boostPoint.plotY;
point.index = boostPoint.i;
point.percentage = boostPoint.percentage;
point.isInside = series.isPointInside(point);
return point;
}
/**
* @private
* @function Highcharts.Series#renderCanvas
*/
function seriesRenderCanvas(this: Series): void {
const options = this.options || {},
chart = this.chart,
xAxis = this.xAxis,
yAxis = this.yAxis,
xData = options.xData || this.processedXData,
yData = options.yData || this.processedYData,
rawData = options.data,
xExtremes = xAxis.getExtremes(),
// Taking into account the offset of the min point #19497
xMin = xExtremes.min - (xAxis.minPointOffset || 0),
xMax = xExtremes.max + (xAxis.minPointOffset || 0),
yExtremes = yAxis.getExtremes(),
yMin = yExtremes.min - (yAxis.minPointOffset || 0),
yMax = yExtremes.max + (yAxis.minPointOffset || 0),
pointTaken: Record<string, boolean> = {},
sampling = !!this.sampling,
enableMouseTracking = options.enableMouseTracking,
threshold: number = options.threshold as any,
isRange = this.pointArrayMap &&
this.pointArrayMap.join(',') === 'low,high',
isStacked = !!options.stacking,
cropStart = this.cropStart || 0,
requireSorting = this.requireSorting,
useRaw = !xData,
compareX = options.findNearestPointBy === 'x',
xDataFull = (
this.xData ||
this.options.xData ||
this.processedXData ||
false
);
let renderer: WGLRenderer = false as any,
lastClientX: (number|undefined),
yBottom = yAxis.getThreshold(threshold),
minVal: (number|undefined),
maxVal: (number|undefined),
minI: (number|undefined),
maxI: (number|undefined);
// Get or create the renderer
renderer = createAndAttachRenderer(chart, this);
chart.boosted = true;
if (!this.visible) {
return;
}
// If we are zooming out from SVG mode, destroy the graphics
if (this.points || this.graph) {
destroyGraphics(this);
}
// If we're rendering per. series we should create the marker groups
// as usual.
if (!isChartSeriesBoosting(chart)) {
// If all series were boosting, but are not anymore
// restore private markerGroup
if (
chart.boost &&
this.markerGroup === chart.boost.markerGroup
) {
this.markerGroup = void 0;
}
this.markerGroup = this.plotGroup(
'markerGroup',
'markers',
true as any,
1,
chart.seriesGroup
);
} else {
// If series has a private markeGroup, remove that
// and use common markerGroup
if (
this.markerGroup &&
this.markerGroup !== chart.boost.markerGroup
) {
this.markerGroup.destroy();
}
// Use a single group for the markers
this.markerGroup = chart.boost.markerGroup;
// When switching from chart boosting mode, destroy redundant
// series boosting targets
if (this.boost && this.boost.target) {
this.renderTarget = this.boost.target = this.boost.target.destroy();
}
}
const points: Array<BoostPointMockup> = this.points = [],
addKDPoint = (
clientX: number,
plotY: number,
i: number,
percentage: number
): void => {
const x = xDataFull ? xDataFull[cropStart + i] : false,
pushPoint = (plotX: number): void => {
if (chart.inverted) {
plotX = xAxis.len - plotX;
plotY = yAxis.len - plotY;
}
points.push({
destroy: noop,
x: x,
clientX: plotX,
plotX: plotX,
plotY: plotY,
i: cropStart + i,
percentage: percentage
});
};
// We need to do ceil on the clientX to make things
// snap to pixel values. The renderer will frequently
// draw stuff on "sub-pixels".
clientX = Math.ceil(clientX);
// Shaves off about 60ms compared to repeated concatenation
index = compareX ? clientX : clientX + ',' + plotY;
// The k-d tree requires series points.
// Reduce the amount of points, since the time to build the
// tree increases exponentially.
if (enableMouseTracking) {
if (!pointTaken[index]) {
pointTaken[index] = true;
pushPoint(clientX);
} else if (x === xDataFull[xDataFull.length - 1]) {
// If the last point is on the same pixel as the last
// tracked point, swap them. (#18856)
points.length--;
pushPoint(clientX);
}
}
};
// Do not start building while drawing
this.buildKDTree = noop;