AreaRangeSeries.js
22.7 KB
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
/**
* (c) 2010-2018 Torstein Honsi
*
* License: www.highcharts.com/license
*/
'use strict';
import H from '../parts/Globals.js';
import '../parts/Utilities.js';
import '../parts/Options.js';
import '../parts/Series.js';
var each = H.each,
noop = H.noop,
pick = H.pick,
extend = H.extend,
isArray = H.isArray,
defined = H.defined,
Series = H.Series,
seriesType = H.seriesType,
seriesTypes = H.seriesTypes,
seriesProto = Series.prototype,
pointProto = H.Point.prototype;
/**
* The area range series is a carteseian series with higher and lower values
* for each point along an X axis, where the area between the values is shaded.
* Requires `highcharts-more.js`.
*
* @extends plotOptions.area
* @product highcharts highstock
* @sample {highcharts} highcharts/demo/arearange/
* Area range chart
* @sample {highstock} stock/demo/arearange/
* Area range chart
* @excluding stack,stacking
* @optionparent plotOptions.arearange
*/
seriesType('arearange', 'area', {
/**
* Whether to apply a drop shadow to the graph line. Since 2.3 the shadow
* can be an object configuration containing `color`, `offsetX`, `offsetY`,
* `opacity` and `width`.
*
* @type {Boolean|Object}
* @product highcharts
* @apioption plotOptions.arearange.shadow
*/
/**
* Pixel width of the arearange graph line.
*
* @since 2.3.0
* @product highcharts highstock
*/
lineWidth: 1,
threshold: null,
tooltip: {
pointFormat: '<span style="color:{series.color}">\u25CF</span> {series.name}: <b>{point.low}</b> - <b>{point.high}</b><br/>' // eslint-disable-line no-dupe-keys
},
/**
* Whether the whole area or just the line should respond to mouseover
* tooltips and other mouse or touch events.
*
* @since 2.3.0
* @product highcharts highstock
*/
trackByArea: true,
/**
* Extended data labels for range series types. Range series data labels
* have no `x` and `y` options. Instead, they have `xLow`, `xHigh`,
* `yLow` and `yHigh` options to allow the higher and lower data label
* sets individually.
*
* @type {Object}
* @extends plotOptions.series.dataLabels
* @excluding x,y
* @since 2.3.0
* @product highcharts highstock
*/
dataLabels: {
align: null,
verticalAlign: null,
/**
* X offset of the lower data labels relative to the point value.
*
* @sample {highcharts} highcharts/plotoptions/arearange-datalabels/
* Data labels on range series
* @sample {highstock} highcharts/plotoptions/arearange-datalabels/
* Data labels on range series
* @since 2.3.0
* @product highcharts highstock
*/
xLow: 0,
/**
* X offset of the higher data labels relative to the point value.
*
* @sample {highcharts|highstock}
* highcharts/plotoptions/arearange-datalabels/
* Data labels on range series
* @since 2.3.0
* @product highcharts highstock
*/
xHigh: 0,
/**
* Y offset of the lower data labels relative to the point value.
*
* @sample {highcharts|highstock}
* highcharts/plotoptions/arearange-datalabels/
* Data labels on range series
* @default 16
* @since 2.3.0
* @product highcharts highstock
*/
yLow: 0,
/**
* Y offset of the higher data labels relative to the point value.
*
* @sample {highcharts|highstock}
* highcharts/plotoptions/arearange-datalabels/
* Data labels on range series
* @default -6
* @since 2.3.0
* @product highcharts highstock
*/
yHigh: 0
}
// Prototype members
}, {
pointArrayMap: ['low', 'high'],
toYData: function (point) {
return [point.low, point.high];
},
pointValKey: 'low',
deferTranslatePolar: true,
/**
* Translate a point's plotHigh from the internal angle and radius
* measures to true plotHigh coordinates. This is an addition of the
* toXY method found in Polar.js, because it runs too early for
* arearanges to be considered (#3419).
*/
highToXY: function (point) {
// Find the polar plotX and plotY
var chart = this.chart,
xy = this.xAxis.postTranslate(
point.rectPlotX,
this.yAxis.len - point.plotHigh
);
point.plotHighX = xy.x - chart.plotLeft;
point.plotHigh = xy.y - chart.plotTop;
point.plotLowX = point.plotX;
},
/**
* Translate data points from raw values x and y to plotX and plotY
*/
translate: function () {
var series = this,
yAxis = series.yAxis,
hasModifyValue = !!series.modifyValue;
seriesTypes.area.prototype.translate.apply(series);
// Set plotLow and plotHigh
each(series.points, function (point) {
var low = point.low,
high = point.high,
plotY = point.plotY;
if (high === null || low === null) {
point.isNull = true;
point.plotY = null;
} else {
point.plotLow = plotY;
point.plotHigh = yAxis.translate(
hasModifyValue ? series.modifyValue(high, point) : high,
0,
1,
0,
1
);
if (hasModifyValue) {
point.yBottom = point.plotHigh;
}
}
});
// Postprocess plotHigh
if (this.chart.polar) {
each(this.points, function (point) {
series.highToXY(point);
point.tooltipPos = [
(point.plotHighX + point.plotLowX) / 2,
(point.plotHigh + point.plotLow) / 2
];
});
}
},
/**
* Extend the line series' getSegmentPath method by applying the segment
* path to both lower and higher values of the range
*/
getGraphPath: function (points) {
var highPoints = [],
highAreaPoints = [],
i,
getGraphPath = seriesTypes.area.prototype.getGraphPath,
point,
pointShim,
linePath,
lowerPath,
options = this.options,
connectEnds = this.chart.polar && options.connectEnds !== false,
connectNulls = options.connectNulls,
step = options.step,
higherPath,
higherAreaPath;
points = points || this.points;
i = points.length;
/**
* Create the top line and the top part of the area fill. The area
* fill compensates for null points by drawing down to the lower graph,
* moving across the null gap and starting again at the lower graph.
*/
i = points.length;
while (i--) {
point = points[i];
if (
!point.isNull &&
!connectEnds &&
!connectNulls &&
(!points[i + 1] || points[i + 1].isNull)
) {
highAreaPoints.push({
plotX: point.plotX,
plotY: point.plotY,
doCurve: false // #5186, gaps in areasplinerange fill
});
}
pointShim = {
polarPlotY: point.polarPlotY,
rectPlotX: point.rectPlotX,
yBottom: point.yBottom,
// plotHighX is for polar charts
plotX: pick(point.plotHighX, point.plotX),
plotY: point.plotHigh,
isNull: point.isNull
};
highAreaPoints.push(pointShim);
highPoints.push(pointShim);
if (
!point.isNull &&
!connectEnds &&
!connectNulls &&
(!points[i - 1] || points[i - 1].isNull)
) {
highAreaPoints.push({
plotX: point.plotX,
plotY: point.plotY,
doCurve: false // #5186, gaps in areasplinerange fill
});
}
}
// Get the paths
lowerPath = getGraphPath.call(this, points);
if (step) {
if (step === true) {
step = 'left';
}
options.step = {
left: 'right',
center: 'center',
right: 'left'
}[step]; // swap for reading in getGraphPath
}
higherPath = getGraphPath.call(this, highPoints);
higherAreaPath = getGraphPath.call(this, highAreaPoints);
options.step = step;
// Create a line on both top and bottom of the range
linePath = [].concat(lowerPath, higherPath);
// For the area path, we need to change the 'move' statement
// into 'lineTo' or 'curveTo'
if (!this.chart.polar && higherAreaPath[0] === 'M') {
higherAreaPath[0] = 'L'; // this probably doesn't work for spline
}
this.graphPath = linePath;
this.areaPath = lowerPath.concat(higherAreaPath);
// Prepare for sideways animation
linePath.isArea = true;
linePath.xMap = lowerPath.xMap;
this.areaPath.xMap = lowerPath.xMap;
return linePath;
},
/**
* Extend the basic drawDataLabels method by running it for both lower
* and higher values.
*/
drawDataLabels: function () {
var data = this.points,
length = data.length,
i,
originalDataLabels = [],
dataLabelOptions = this.options.dataLabels,
point,
up,
inverted = this.chart.inverted,
upperDataLabelOptions,
lowerDataLabelOptions;
// Split into upper and lower options. If data labels is an array, the
// first element is the upper label, the second is the lower.
//
// TODO: We want to change this and allow multiple labels for both upper
// and lower values in the future - introducing some options for which
// point value to use as Y for the dataLabel, so that this could be
// handled in Series.drawDataLabels. This would also improve performance
// since we now have to loop over all the points multiple times to work
// around the data label logic.
if (isArray(dataLabelOptions)) {
if (dataLabelOptions.length > 1) {
upperDataLabelOptions = dataLabelOptions[0];
lowerDataLabelOptions = dataLabelOptions[1];
} else {
upperDataLabelOptions = dataLabelOptions[0];
lowerDataLabelOptions = { enabled: false };
}
} else {
upperDataLabelOptions = extend({}, dataLabelOptions); // Make copy;
upperDataLabelOptions.x = dataLabelOptions.xHigh;
upperDataLabelOptions.y = dataLabelOptions.yHigh;
lowerDataLabelOptions = extend({}, dataLabelOptions); // Make copy
lowerDataLabelOptions.x = dataLabelOptions.xLow;
lowerDataLabelOptions.y = dataLabelOptions.yLow;
}
// Draw upper labels
if (upperDataLabelOptions.enabled || this._hasPointLabels) {
// Set preliminary values for plotY and dataLabel
// and draw the upper labels
i = length;
while (i--) {
point = data[i];
if (point) {
up = upperDataLabelOptions.inside ?
point.plotHigh < point.plotLow :
point.plotHigh > point.plotLow;
point.y = point.high;
point._plotY = point.plotY;
point.plotY = point.plotHigh;
// Store original data labels and set preliminary label
// objects to be picked up in the uber method
originalDataLabels[i] = point.dataLabel;
point.dataLabel = point.dataLabelUpper;
// Set the default offset
point.below = up;
if (inverted) {
if (!upperDataLabelOptions.align) {
upperDataLabelOptions.align = up ? 'right' : 'left';
}
} else {
if (!upperDataLabelOptions.verticalAlign) {
upperDataLabelOptions.verticalAlign = up ?
'top' :
'bottom';
}
}
}
}
this.options.dataLabels = upperDataLabelOptions;
if (seriesProto.drawDataLabels) {
seriesProto.drawDataLabels.apply(this, arguments); // #1209
}
// Reset state after the upper labels were created. Move
// it to point.dataLabelUpper and reassign the originals.
// We do this here to support not drawing a lower label.
i = length;
while (i--) {
point = data[i];
if (point) {
point.dataLabelUpper = point.dataLabel;
point.dataLabel = originalDataLabels[i];
delete point.dataLabels;
point.y = point.low;
point.plotY = point._plotY;
}
}
}
// Draw lower labels
if (lowerDataLabelOptions.enabled || this._hasPointLabels) {
i = length;
while (i--) {
point = data[i];
if (point) {
up = lowerDataLabelOptions.inside ?
point.plotHigh < point.plotLow :
point.plotHigh > point.plotLow;
// Set the default offset
point.below = !up;
if (inverted) {
if (!lowerDataLabelOptions.align) {
lowerDataLabelOptions.align = up ? 'left' : 'right';
}
} else {
if (!lowerDataLabelOptions.verticalAlign) {
lowerDataLabelOptions.verticalAlign = up ?
'bottom' :
'top';
}
}
}
}
this.options.dataLabels = lowerDataLabelOptions;
if (seriesProto.drawDataLabels) {
seriesProto.drawDataLabels.apply(this, arguments);
}
}
// Merge upper and lower into point.dataLabels for later destroying
if (upperDataLabelOptions.enabled) {
i = length;
while (i--) {
point = data[i];
if (point && point.dataLabelUpper) {
point.dataLabels = [point.dataLabelUpper, point.dataLabel];
}
}
}
// Reset options
this.options.dataLabels = dataLabelOptions;
},
alignDataLabel: function () {
seriesTypes.column.prototype.alignDataLabel.apply(this, arguments);
},
drawPoints: function () {
var series = this,
pointLength = series.points.length,
point,
i;
// Draw bottom points
seriesProto.drawPoints.apply(series, arguments);
// Prepare drawing top points
i = 0;
while (i < pointLength) {
point = series.points[i];
// Save original props to be overridden by temporary props for top
// points
point.origProps = {
plotY: point.plotY,
plotX: point.plotX,
isInside: point.isInside,
negative: point.negative,
zone: point.zone,
y: point.y
};
point.lowerGraphic = point.graphic;
point.graphic = point.upperGraphic;
point.plotY = point.plotHigh;
if (defined(point.plotHighX)) {
point.plotX = point.plotHighX;
}
point.y = point.high;
point.negative = point.high < (series.options.threshold || 0);
point.zone = series.zones.length && point.getZone();
if (!series.chart.polar) {
point.isInside = point.isTopInside = (
point.plotY !== undefined &&
point.plotY >= 0 &&
point.plotY <= series.yAxis.len && // #3519
point.plotX >= 0 &&
point.plotX <= series.xAxis.len
);
}
i++;
}
// Draw top points
seriesProto.drawPoints.apply(series, arguments);
// Reset top points preliminary modifications
i = 0;
while (i < pointLength) {
point = series.points[i];
point.upperGraphic = point.graphic;
point.graphic = point.lowerGraphic;
H.extend(point, point.origProps);
delete point.origProps;
i++;
}
},
setStackedPoints: noop
}, {
setState: function () {
var prevState = this.state,
series = this.series,
isPolar = series.chart.polar;
if (!defined(this.plotHigh)) {
// Boost doesn't calculate plotHigh
this.plotHigh = series.yAxis.toPixels(this.high, true);
}
if (!defined(this.plotLow)) {
// Boost doesn't calculate plotLow
this.plotLow = this.plotY = series.yAxis.toPixels(this.low, true);
}
if (series.stateMarkerGraphic) {
series.lowerStateMarkerGraphic = series.stateMarkerGraphic;
series.stateMarkerGraphic = series.upperStateMarkerGraphic;
}
// Change state also for the top marker
this.graphic = this.upperGraphic;
this.plotY = this.plotHigh;
if (isPolar) {
this.plotX = this.plotHighX;
}
// Top state:
pointProto.setState.apply(this, arguments);
this.state = prevState;
// Now restore defaults
this.plotY = this.plotLow;
this.graphic = this.lowerGraphic;
if (isPolar) {
this.plotX = this.plotLowX;
}
if (series.stateMarkerGraphic) {
series.upperStateMarkerGraphic = series.stateMarkerGraphic;
series.stateMarkerGraphic = series.lowerStateMarkerGraphic;
// Lower marker is stored at stateMarkerGraphic
// to avoid reference duplication (#7021)
series.lowerStateMarkerGraphic = undefined;
}
pointProto.setState.apply(this, arguments);
},
haloPath: function () {
var isPolar = this.series.chart.polar,
path = [];
// Bottom halo
this.plotY = this.plotLow;
if (isPolar) {
this.plotX = this.plotLowX;
}
if (this.isInside) {
path = pointProto.haloPath.apply(this, arguments);
}
// Top halo
this.plotY = this.plotHigh;
if (isPolar) {
this.plotX = this.plotHighX;
}
if (this.isTopInside) {
path = path.concat(
pointProto.haloPath.apply(this, arguments)
);
}
return path;
},
destroyElements: function () {
var graphics = ['lowerGraphic', 'upperGraphic'];
each(graphics, function (graphicName) {
if (this[graphicName]) {
this[graphicName] = this[graphicName].destroy();
}
}, this);
// Clear graphic for states, removed in the above each:
this.graphic = null;
return pointProto.destroyElements.apply(this, arguments);
}
});
/**
* A `arearange` series. If the [type](#series.arearange.type) option
* is not specified, it is inherited from [chart.type](#chart.type).
*
*
* @type {Object}
* @extends series,plotOptions.arearange
* @excluding dataParser,dataURL,stack,stacking
* @product highcharts highstock
* @apioption series.arearange
*/
/**
* An array of data points for the series. For the `arearange` series
* type, points can be given in the following ways:
*
* 1. An array of arrays with 3 or 2 values. In this case, the values
* correspond to `x,low,high`. If the first value is a string, it is
* applied as the name of the point, and the `x` value is inferred.
* The `x` value can also be omitted, in which case the inner arrays
* should be of length 2\. Then the `x` value is automatically calculated,
* either starting at 0 and incremented by 1, or from `pointStart`
* and `pointInterval` given in the series options.
*
* ```js
* data: [
* [0, 8, 3],
* [1, 1, 1],
* [2, 6, 8]
* ]
* ```
*
* 2. An array of objects with named values. The following snippet shows only a
* few settings, see the complete options set below. If the total number of data
* points exceeds the series'
* [turboThreshold](#series.arearange.turboThreshold),
* this option is not available.
*
* ```js
* data: [{
* x: 1,
* low: 9,
* high: 0,
* name: "Point2",
* color: "#00FF00"
* }, {
* x: 1,
* low: 3,
* high: 4,
* name: "Point1",
* color: "#FF00FF"
* }]
* ```
*
* @type {Array<Object|Array>}
* @extends series.line.data
* @excluding marker,y
* @sample {highcharts} highcharts/chart/reflow-true/
* Numerical values
* @sample {highcharts} highcharts/series/data-array-of-arrays/
* Arrays of numeric x and y
* @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
* Arrays of datetime x and y
* @sample {highcharts} highcharts/series/data-array-of-name-value/
* Arrays of point.name and y
* @sample {highcharts} highcharts/series/data-array-of-objects/
* Config objects
* @product highcharts highstock
* @apioption series.arearange.data
*/
/**
* The high or maximum value for each data point.
*
* @type {Number}
* @product highcharts highstock
* @apioption series.arearange.data.high
*/
/**
* The low or minimum value for each data point.
*
* @type {Number}
* @product highcharts highstock
* @apioption series.arearange.data.low
*/
/**
* @excluding x,y
* @product highcharts highstock
* @apioption series.arearange.dataLabels
*/