xrange.src.js
22.8 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
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
/**
* @license Highcharts JS v6.2.0 (2018-10-17)
* X-range series
*
* (c) 2010-2018 Torstein Honsi, Lars A. V. Cabrera
*
* License: www.highcharts.com/license
*/
'use strict';
(function (factory) {
if (typeof module === 'object' && module.exports) {
module.exports = factory;
} else if (typeof define === 'function' && define.amd) {
define(function () {
return factory;
});
} else {
factory(Highcharts);
}
}(function (Highcharts) {
(function (H) {
/**
* X-range series module
*
* (c) 2010-2018 Torstein Honsi, Lars A. V. Cabrera
*
* License: www.highcharts.com/license
*/
var addEvent = H.addEvent,
defined = H.defined,
color = H.Color,
columnType = H.seriesTypes.column,
each = H.each,
isNumber = H.isNumber,
isObject = H.isObject,
merge = H.merge,
pick = H.pick,
seriesType = H.seriesType,
seriesTypes = H.seriesTypes,
Axis = H.Axis,
Point = H.Point,
Series = H.Series;
/**
* Return color of a point based on its category.
*
* @param {object} series The series which the point belongs to.
* @param {object} point The point to calculate its color for.
* @returns {object} Returns an object containing the properties color and
* colorIndex.
*/
var getColorByCategory = function getColorByCategory(series, point) {
var colors = series.options.colors || series.chart.options.colors,
colorCount = colors ?
colors.length :
series.chart.options.chart.colorCount,
colorIndex = point.y % colorCount,
color = colors && colors[colorIndex];
return {
colorIndex: colorIndex,
color: color
};
};
/**
* @private
* @class
* @name Highcharts.seriesTypes.xrange
*
* @augments Highcharts.Series
*/
seriesType('xrange', 'column'
/**
* The X-range series displays ranges on the X axis, typically time intervals
* with a start and end date.
*
* @extends {plotOptions.column}
* @excluding boostThreshold,crisp,cropThreshold,depth,edgeColor,edgeWidth,
* findNearestPointBy,getExtremesFromAll,negativeColor,
* pointInterval,pointIntervalUnit,pointPlacement,
* pointRange,pointStart,softThreshold,stacking,threshold,data
* @product highcharts highstock gantt
* @sample {highcharts} highcharts/demo/x-range/
* X-range
* @sample {highcharts} highcharts/css/x-range/
* Styled mode X-range
* @sample {highcharts} highcharts/chart/inverted-xrange/
* Inverted X-range
* @since 6.0.0
* @product highcharts highstock
* @optionparent plotOptions.xrange
*/
, {
/**
* A partial fill for each point, typically used to visualize how much of
* a task is performed. The partial fill object can be set either on series
* or point level.
*
* @sample {highcharts} highcharts/demo/x-range
* X-range with partial fill
*
* @product highcharts highstock gantt
* @apioption plotOptions.xrange.partialFill
*/
/**
* The fill color to be used for partial fills. Defaults to a darker shade
* of the point color.
*
* @type {Highcharts.ColorString}
* @product highcharts highstock gantt
* @apioption plotOptions.xrange.partialFill.fill
*/
/**
* A partial fill for each point, typically used to visualize how much of
* a task is performed. The partial fill object can be set either on series
* or point level.
*
* @sample {highcharts} highcharts/demo/x-range
* X-range with partial fill
* @type {Object}
* @extends plotOptions.xrange.partialFill
* @apioption series.xrange.data.partialFill
*/
/**
* In an X-range series, this option makes all points of the same Y-axis
* category the same color.
*/
colorByPoint: true,
dataLabels: {
verticalAlign: 'middle',
inside: true,
/**
* The default formatter for X-range data labels displays the percentage
* of the partial fill amount.
*
* @type {Highcharts.FormatterCallbackFunction}
* @default function () { return (amount * 100) + '%'; }
*/
formatter: function () {
var point = this.point,
amount = point.partialFill;
if (isObject(amount)) {
amount = amount.amount;
}
if (!defined(amount)) {
amount = 0;
}
return (amount * 100) + '%';
}
},
tooltip: {
headerFormat: '<span style="font-size: 0.85em">{point.x} - {point.x2}</span><br/>',
pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.yCategory}</b><br/>'
},
borderRadius: 3,
pointRange: 0
}, {
type: 'xrange',
parallelArrays: ['x', 'x2', 'y'],
requireSorting: false,
animate: seriesTypes.line.prototype.animate,
cropShoulder: 1,
getExtremesFromAll: true,
autoIncrement: H.noop,
/**
* Borrow the column series metrics, but with swapped axes. This gives free
* access to features like groupPadding, grouping, pointWidth etc.
*
* @private
* @function Higcharts.seriesTypes.xrange#getColumnMetrics
*
* @return {Highcharts.ColumnMetricsObject}
*/
getColumnMetrics: function () {
var metrics,
chart = this.chart;
function swapAxes() {
each(chart.series, function (s) {
var xAxis = s.xAxis;
s.xAxis = s.yAxis;
s.yAxis = xAxis;
});
}
swapAxes();
metrics = columnType.prototype.getColumnMetrics.call(this);
swapAxes();
return metrics;
},
/**
* Override cropData to show a point where x or x2 is outside visible range,
* but one of them is inside.
*
* @private
* @function Highcharts.seriesTypes.xrange#cropData
*
* @param {Array<number>} xData
*
* @param {Array<number>} yData
*
* @param {number} min
*
* @param {number} max
*
* @param {number} [cropShoulder]
*
* @return {*}
*/
cropData: function (xData, yData, min, max) {
// Replace xData with x2Data to find the appropriate cropStart
var cropData = Series.prototype.cropData,
crop = cropData.call(this, this.x2Data, yData, min, max);
// Re-insert the cropped xData
crop.xData = xData.slice(crop.start, crop.end);
return crop;
},
/**
* @private
* @function Highcharts.seriesTypes.xrange#translatePoint
*
* @param {Highcharts.Point} point
*/
translatePoint: function (point) {
var series = this,
xAxis = series.xAxis,
yAxis = series.yAxis,
metrics = series.columnMetrics,
options = series.options,
minPointLength = options.minPointLength || 0,
plotX = point.plotX,
posX = pick(point.x2, point.x + (point.len || 0)),
plotX2 = xAxis.translate(posX, 0, 0, 0, 1),
length = Math.abs(plotX2 - plotX),
widthDifference,
shapeArgs,
partialFill,
inverted = this.chart.inverted,
borderWidth = pick(options.borderWidth, 1),
crisper = borderWidth % 2 / 2,
yOffset = metrics.offset,
pointHeight = Math.round(metrics.width),
dlLeft,
dlRight,
dlWidth;
if (minPointLength) {
widthDifference = minPointLength - length;
if (widthDifference < 0) {
widthDifference = 0;
}
plotX -= widthDifference / 2;
plotX2 += widthDifference / 2;
}
plotX = Math.max(plotX, -10);
plotX2 = Math.min(Math.max(plotX2, -10), xAxis.len + 10);
// Handle individual pointWidth
if (defined(point.options.pointWidth)) {
yOffset -= (Math.ceil(point.options.pointWidth) - pointHeight) / 2;
pointHeight = Math.ceil(point.options.pointWidth);
}
// Apply pointPlacement to the Y axis
if (
options.pointPlacement &&
isNumber(point.plotY) &&
yAxis.categories
) {
point.plotY = yAxis
.translate(point.y, 0, 1, 0, 1, options.pointPlacement);
}
point.shapeArgs = {
x: Math.floor(Math.min(plotX, plotX2)) + crisper,
y: Math.floor(point.plotY + yOffset) + crisper,
width: Math.round(Math.abs(plotX2 - plotX)),
height: pointHeight,
r: series.options.borderRadius
};
// Align data labels inside the shape and inside the plot area
dlLeft = point.shapeArgs.x;
dlRight = dlLeft + point.shapeArgs.width;
if (dlLeft < 0 || dlRight > xAxis.len) {
dlLeft = Math.min(xAxis.len, Math.max(0, dlLeft));
dlRight = Math.max(0, Math.min(dlRight, xAxis.len));
dlWidth = dlRight - dlLeft;
point.dlBox = merge(point.shapeArgs, {
x: dlLeft,
width: dlRight - dlLeft,
centerX: dlWidth ? dlWidth / 2 : null
});
} else {
point.dlBox = null;
}
// Tooltip position
point.tooltipPos[0] += inverted ? 0 : length / 2;
point.tooltipPos[1] -= inverted ? -length / 2 : metrics.width / 2;
// Add a partShapeArgs to the point, based on the shapeArgs property
partialFill = point.partialFill;
if (partialFill) {
// Get the partial fill amount
if (isObject(partialFill)) {
partialFill = partialFill.amount;
}
// If it was not a number, assume 0
if (!isNumber(partialFill)) {
partialFill = 0;
}
shapeArgs = point.shapeArgs;
point.partShapeArgs = {
x: shapeArgs.x,
y: shapeArgs.y,
width: shapeArgs.width,
height: shapeArgs.height,
r: series.options.borderRadius
};
point.clipRectArgs = {
x: shapeArgs.x,
y: shapeArgs.y,
width: Math.max(
Math.round(
length * partialFill +
(point.plotX - plotX)
),
0
),
height: shapeArgs.height
};
}
// Category from Y axis
if (yAxis.categories) {
point.category = yAxis.categories[point.y];
}
},
/**
* @private
* @function Highcharts.seriesTypes.xrange#translate
*/
translate: function () {
columnType.prototype.translate.apply(this, arguments);
each(this.points, function (point) {
this.translatePoint(point);
}, this);
},
/**
* Draws a single point in the series. Needed for partial fill.
*
* This override turns point.graphic into a group containing the original
* graphic and an overlay displaying the partial fill.
*
* @private
* @function Highcharts.seriesTypes.xrange#drawPoint
*
* @param {Highcharts.Point} point
* An instance of Point in the series.
*
* @param {"animate"|"attr"} verb
* 'animate' (animates changes) or 'attr' (sets options)
*/
drawPoint: function (point, verb) {
var series = this,
seriesOpts = series.options,
renderer = series.chart.renderer,
graphic = point.graphic,
type = point.shapeType,
shapeArgs = point.shapeArgs,
partShapeArgs = point.partShapeArgs,
clipRectArgs = point.clipRectArgs,
pfOptions = point.partialFill,
fill,
state = point.selected && 'select',
cutOff = seriesOpts.stacking && !seriesOpts.borderRadius;
if (!point.isNull) {
// Original graphic
if (graphic) { // update
point.graphicOriginal[verb](
merge(shapeArgs)
);
} else {
point.graphic = graphic = renderer.g('point')
.addClass(point.getClassName())
.add(point.group || series.group);
point.graphicOriginal = renderer[type](shapeArgs)
.addClass(point.getClassName())
.addClass('highcharts-partfill-original')
.add(graphic);
}
// Partial fill graphic
if (partShapeArgs) {
if (point.graphicOverlay) {
point.graphicOverlay[verb](
merge(partShapeArgs)
);
point.clipRect.animate(
merge(clipRectArgs)
);
} else {
point.clipRect = renderer.clipRect(
clipRectArgs.x,
clipRectArgs.y,
clipRectArgs.width,
clipRectArgs.height
);
point.graphicOverlay = renderer[type](partShapeArgs)
.addClass('highcharts-partfill-overlay')
.add(graphic)
.clip(point.clipRect);
}
}
// Presentational
point.graphicOriginal
.attr(series.pointAttribs(point, state))
.shadow(seriesOpts.shadow, null, cutOff);
if (partShapeArgs) {
// Ensure pfOptions is an object
if (!isObject(pfOptions)) {
pfOptions = {};
}
if (isObject(seriesOpts.partialFill)) {
pfOptions = merge(pfOptions, seriesOpts.partialFill);
}
fill = (
pfOptions.fill ||
color(point.color || series.color).brighten(-0.3).get()
);
point.graphicOverlay
.attr(series.pointAttribs(point, state))
.attr({
'fill': fill
})
.shadow(seriesOpts.shadow, null, cutOff);
}
} else if (graphic) {
point.graphic = graphic.destroy(); // #1269
}
},
/**
* @private
* @function Highcharts.seriesTypes.xrange#drawPoints
*/
drawPoints: function () {
var series = this,
verb = series.getAnimationVerb();
// Draw the columns
each(series.points, function (point) {
series.drawPoint(point, verb);
});
},
/**
* Returns "animate", or "attr" if the number of points is above the
* animation limit.
*
* @private
* @function Highcharts.seriesTypes.xrange#getAnimationVerb
*
* @return {string}
*/
getAnimationVerb: function () {
return this.chart.pointCount < (this.options.animationLimit || 250) ?
'animate' : 'attr';
}
/**
* Override to remove stroke from points.
* For partial fill.
*
* @ignore
* @private
* @function Highcharts.seriesTypes.xrange#pointAttribs
*
* @return {*}
* /
pointAttribs: function () {
var series = this,
retVal = columnType.prototype.pointAttribs.apply(series, arguments);
//retVal['stroke-width'] = 0;
return retVal;
}
//*/
}, { // Point class properties
/**
* Extend applyOptions so that `colorByPoint` for x-range means that one
* color is applied per Y axis category.
*
* @private
* @function Highcharts.Point#applyOptions
*
* @return {Highcharts.Series}
*/
applyOptions: function () {
var point = Point.prototype.applyOptions.apply(this, arguments),
series = point.series,
colorByPoint;
if (series.options.colorByPoint && !point.options.color) {
colorByPoint = getColorByCategory(series, point);
point.color = colorByPoint.color;
if (!point.options.colorIndex) {
point.colorIndex = colorByPoint.colorIndex;
}
}
return point;
},
/**
* Extend init to have y default to 0.
*
* @private
* @function Highcharts.Point#init
*
* @return {Highcharts.Series}
*/
init: function () {
Point.prototype.init.apply(this, arguments);
if (!this.y) {
this.y = 0;
}
return this;
},
/**
* @private
* @function Highcharts.Point#setState
*/
setState: function () {
Point.prototype.setState.apply(this, arguments);
this.series.drawPoint(this, this.series.getAnimationVerb());
},
/**
* @private
* @function Highcharts.Point#getLabelConfig
*
* @return {Highcharts.PointLabelObject}
*/
// Add x2 and yCategory to the available properties for tooltip formats
getLabelConfig: function () {
var point = this,
cfg = Point.prototype.getLabelConfig.call(point),
yCats = point.series.yAxis.categories;
cfg.x2 = point.x2;
cfg.yCategory = point.yCategory = yCats && yCats[point.y];
return cfg;
},
tooltipDateKeys: ['x', 'x2'],
/**
* @private
* @function Highcharts.Point#isValid
*
* @return {boolean}
*/
isValid: function () {
return typeof this.x === 'number' &&
typeof this.x2 === 'number';
}
});
// Max x2 should be considered in xAxis extremes
addEvent(Axis, 'afterGetSeriesExtremes', function () {
var axis = this,
axisSeries = axis.series,
dataMax,
modMax;
if (axis.isXAxis) {
dataMax = pick(axis.dataMax, -Number.MAX_VALUE);
each(axisSeries, function (series) {
if (series.x2Data) {
each(series.x2Data, function (val) {
if (val > dataMax) {
dataMax = val;
modMax = true;
}
});
}
});
if (modMax) {
axis.dataMax = dataMax;
}
}
});
/**
* An `xrange` series. If the [type](#series.xrange.type) option is not
* specified, it is inherited from [chart.type](#chart.type).
*
* @extends series,plotOptions.xrange
* @excluding boostThreshold,crisp,cropThreshold,depth,edgeColor,edgeWidth,
* findNearestPointBy,getExtremesFromAll,
* negativeColor,pointInterval,pointIntervalUnit,pointPlacement,
* pointRange,pointStart,softThreshold,stacking,threshold
* @product highcharts highstock gantt
* @apioption series.xrange
*/
/**
* An array of data points for the series. For the `xrange` series type,
* points can be given in the following ways:
*
* 1. An array of objects with named values. The objects are point
* configuration objects as seen below.
*
* ```js
* data: [{
* x: Date.UTC(2017, 0, 1),
* x2: Date.UTC(2017, 0, 3),
* name: "Test",
* y: 0,
* color: "#00FF00"
* }, {
* x: Date.UTC(2017, 0, 4),
* x2: Date.UTC(2017, 0, 5),
* name: "Deploy",
* y: 1,
* color: "#FF0000"
* }]
* ```
*
* @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
*
* @type {Array<number|Array<number>|*>}
* @extends series.line.data
* @product highcharts highstock gantt
* @apioption series.xrange.data
*/
/**
* The starting X value of the range point.
*
* @sample {highcharts} highcharts/demo/x-range
* X-range
*
* @type {number}
* @product highcharts highstock gantt
* @apioption series.xrange.data.x
*/
/**
* The ending X value of the range point.
*
* @sample {highcharts} highcharts/demo/x-range
* X-range
*
* @type {number}
* @product highcharts highstock gantt
* @apioption series.xrange.data.x2
*/
/**
* The Y value of the range point.
*
* @sample {highcharts} highcharts/demo/x-range
* X-range
*
* @type {number}
* @product highcharts highstock gantt
* @apioption series.xrange.data.y
*/
/**
* A partial fill for each point, typically used to visualize how much of
* a task is performed. The partial fill object can be set either on series
* or point level.
*
* @sample {highcharts} highcharts/demo/x-range
* X-range with partial fill
*
* @product highcharts highstock gantt
* @apioption series.xrange.data.partialFill
*/
/**
* The amount of the X-range point to be filled. Values can be 0-1 and are
* converted to percentages in the default data label formatter.
*
* @type {number}
* @product highcharts highstock gantt
* @apioption series.xrange.data.partialFill.amount
*/
/**
* The fill color to be used for partial fills. Defaults to a darker shade
* of the point color.
*
* @type {Highcharts.ColorString}
* @product highcharts highstock gantt
* @apioption series.xrange.data.partialFill.fill
*/
}(Highcharts));
return (function () {
}());
}));