-
Notifications
You must be signed in to change notification settings - Fork 45
/
highcharts-more.src.js
5195 lines (4565 loc) · 192 KB
/
highcharts-more.src.js
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
/**
* @license Highcharts JS v6.0.3 (2017-11-14)
*
* (c) 2009-2016 Torstein Honsi
*
* License: www.highcharts.com/license
*/
'use strict';
(function(factory) {
if (typeof module === 'object' && module.exports) {
module.exports = factory;
} else {
factory(Highcharts);
}
}(function(Highcharts) {
(function(H) {
/**
* (c) 2010-2017 Torstein Honsi
*
* License: www.highcharts.com/license
*/
var deg2rad = H.deg2rad,
isNumber = H.isNumber,
pick = H.pick,
relativeLength = H.relativeLength;
H.CenteredSeriesMixin = {
/**
* Get the center of the pie based on the size and center options relative to the
* plot area. Borrowed by the polar and gauge series types.
*/
getCenter: function() {
var options = this.options,
chart = this.chart,
slicingRoom = 2 * (options.slicedOffset || 0),
handleSlicingRoom,
plotWidth = chart.plotWidth - 2 * slicingRoom,
plotHeight = chart.plotHeight - 2 * slicingRoom,
centerOption = options.center,
positions = [pick(centerOption[0], '50%'), pick(centerOption[1], '50%'), options.size || '100%', options.innerSize || 0],
smallestSize = Math.min(plotWidth, plotHeight),
i,
value;
for (i = 0; i < 4; ++i) {
value = positions[i];
handleSlicingRoom = i < 2 || (i === 2 && /%$/.test(value));
// i == 0: centerX, relative to width
// i == 1: centerY, relative to height
// i == 2: size, relative to smallestSize
// i == 3: innerSize, relative to size
positions[i] = relativeLength(value, [plotWidth, plotHeight, smallestSize, positions[2]][i]) +
(handleSlicingRoom ? slicingRoom : 0);
}
// innerSize cannot be larger than size (#3632)
if (positions[3] > positions[2]) {
positions[3] = positions[2];
}
return positions;
},
/**
* getStartAndEndRadians - Calculates start and end angles in radians.
* Used in series types such as pie and sunburst.
*
* @param {Number} start Start angle in degrees.
* @param {Number} end Start angle in degrees.
* @return {object} Returns an object containing start and end angles as
* radians.
*/
getStartAndEndRadians: function getStartAndEndRadians(start, end) {
var startAngle = isNumber(start) ? start : 0, // must be a number
endAngle = (
(
isNumber(end) && // must be a number
end > startAngle && // must be larger than the start angle
// difference must be less than 360 degrees
(end - startAngle) < 360
) ?
end :
startAngle + 360
),
correction = -90;
return {
start: deg2rad * (startAngle + correction),
end: deg2rad * (endAngle + correction)
};
}
};
}(Highcharts));
(function(H) {
/**
* (c) 2010-2017 Torstein Honsi
*
* License: www.highcharts.com/license
*/
var CenteredSeriesMixin = H.CenteredSeriesMixin,
each = H.each,
extend = H.extend,
merge = H.merge,
splat = H.splat;
/**
* The Pane object allows options that are common to a set of X and Y axes.
*
* In the future, this can be extended to basic Highcharts and Highstock.
*
*/
function Pane(options, chart) {
this.init(options, chart);
}
// Extend the Pane prototype
extend(Pane.prototype, {
coll: 'pane', // Member of chart.pane
/**
* Initiate the Pane object
*/
init: function(options, chart) {
this.chart = chart;
this.background = [];
chart.pane.push(this);
this.setOptions(options);
},
setOptions: function(options) {
// Set options. Angular charts have a default background (#3318)
this.options = options = merge(
this.defaultOptions,
this.chart.angular ? {
background: {}
} : undefined,
options
);
},
/**
* Render the pane with its backgrounds.
*/
render: function() {
var options = this.options,
backgroundOption = this.options.background,
renderer = this.chart.renderer,
len,
i;
if (!this.group) {
this.group = renderer.g('pane-group')
.attr({
zIndex: options.zIndex || 0
})
.add();
}
this.updateCenter();
// Render the backgrounds
if (backgroundOption) {
backgroundOption = splat(backgroundOption);
len = Math.max(
backgroundOption.length,
this.background.length || 0
);
for (i = 0; i < len; i++) {
if (backgroundOption[i] && this.axis) { // #6641 - if axis exists, chart is circular and apply background
this.renderBackground(
merge(
this.defaultBackgroundOptions,
backgroundOption[i]
),
i
);
} else if (this.background[i]) {
this.background[i] = this.background[i].destroy();
this.background.splice(i, 1);
}
}
}
},
/**
* Render an individual pane background.
* @param {Object} backgroundOptions Background options
* @param {number} i The index of the background in this.backgrounds
*/
renderBackground: function(backgroundOptions, i) {
var method = 'animate';
if (!this.background[i]) {
this.background[i] = this.chart.renderer.path()
.add(this.group);
method = 'attr';
}
this.background[i][method]({
'd': this.axis.getPlotBandPath(
backgroundOptions.from,
backgroundOptions.to,
backgroundOptions
)
}).attr({
'fill': backgroundOptions.backgroundColor,
'stroke': backgroundOptions.borderColor,
'stroke-width': backgroundOptions.borderWidth,
'class': 'highcharts-pane ' + (backgroundOptions.className || '')
});
},
/**
* The pane serves as a container for axes and backgrounds for circular
* gauges and polar charts.
* @since 2.3.0
* @optionparent pane
*/
defaultOptions: {
/**
* The center of a polar chart or angular gauge, given as an array
* of [x, y] positions. Positions can be given as integers that transform
* to pixels, or as percentages of the plot area size.
*
* @type {Array<String|Number>}
* @sample {highcharts} highcharts/demo/gauge-vu-meter/
* Two gauges with different center
* @default ["50%", "50%"]
* @since 2.3.0
* @product highcharts
*/
center: ['50%', '50%'],
/**
* The size of the pane, either as a number defining pixels, or a
* percentage defining a percentage of the plot are.
*
* @type {Number|String}
* @sample {highcharts} highcharts/demo/gauge-vu-meter/ Smaller size
* @default 85%
* @product highcharts
*/
size: '85%',
/**
* The start angle of the polar X axis or gauge axis, given in degrees
* where 0 is north. Defaults to 0.
*
* @type {Number}
* @sample {highcharts} highcharts/demo/gauge-vu-meter/
* VU-meter with custom start and end angle
* @since 2.3.0
* @product highcharts
*/
startAngle: 0
/**
* The end angle of the polar X axis or gauge value axis, given in degrees
* where 0 is north. Defaults to [startAngle](#pane.startAngle) + 360.
*
* @type {Number}
* @sample {highcharts} highcharts/demo/gauge-vu-meter/
* VU-meter with custom start and end angle
* @since 2.3.0
* @product highcharts
* @apioption pane.endAngle
*/
},
/**
* An array of background items for the pane.
* @type Array.<Object>
* @sample {highcharts} highcharts/demo/gauge-speedometer/
* Speedometer gauge with multiple backgrounds
* @optionparent pane.background
*/
defaultBackgroundOptions: {
/**
* The class name for this background.
*
* @type {String}
* @sample {highcharts} highcharts/css/pane/ Panes styled by CSS
* @sample {highstock} highcharts/css/pane/ Panes styled by CSS
* @sample {highmaps} highcharts/css/pane/ Panes styled by CSS
* @default highcharts-pane
* @since 5.0.0
* @apioption pane.background.className
*/
/**
* Tha shape of the pane background. When `solid`, the background
* is circular. When `arc`, the background extends only from the min
* to the max of the value axis.
*
* @validvalue ["solid", "arc"]
* @type {String}
* @default solid
* @since 2.3.0
* @product highcharts
*/
shape: 'circle',
/**
* The pixel border width of the pane background.
*
* @type {Number}
* @default 1
* @since 2.3.0
* @product highcharts
*/
borderWidth: 1,
/**
* The pane background border color.
*
* @type {Color}
* @default #cccccc
* @since 2.3.0
* @product highcharts
*/
borderColor: '#cccccc',
/**
* The background color or gradient for the pane.
*
* @type {Color}
* @since 2.3.0
* @product highcharts
*/
backgroundColor: {
/**
* Definition of the gradient, similar to SVG: object literal holds
* start position (x1, y1) and the end position (x2, y2) relative
* to the shape, where 0 means top/left and 1 is bottom/right.
* All positions are floats between 0 and 1.
*
* @type {Object}
*/
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
/**
* The stops is an array of tuples, where the first
* item is a float between 0 and 1 assigning the relative position in
* the gradient, and the second item is the color.
*
* @default [[0, #ffffff], [1, #e6e6e6]]
* @type {Array<Array>}
*/
stops: [
[0, '#ffffff'],
[1, '#e6e6e6']
]
},
/** @ignore */
from: -Number.MAX_VALUE, // corrected to axis min
/**
* The inner radius of the pane background. Can be either numeric
* (pixels) or a percentage string.
*
* @type {Number|String}
* @default 0
* @since 2.3.0
* @product highcharts
*/
innerRadius: 0,
/** @ignore */
to: Number.MAX_VALUE, // corrected to axis max
/**
* The outer radius of the circular pane background. Can be either
* numeric (pixels) or a percentage string.
*
* @type {Number|String}
* @default 105%
* @since 2.3.0
* @product highcharts
*/
outerRadius: '105%'
},
/**
* Gets the center for the pane and its axis.
*/
updateCenter: function(axis) {
this.center = (axis || this.axis || {}).center =
CenteredSeriesMixin.getCenter.call(this);
},
/**
* Destroy the pane item
* /
destroy: function () {
H.erase(this.chart.pane, this);
each(this.background, function (background) {
background.destroy();
});
this.background.length = 0;
this.group = this.group.destroy();
},
*/
/**
* Update the pane item with new options
* @param {Object} options New pane options
*/
update: function(options, redraw) {
merge(true, this.options, options);
this.setOptions(this.options);
this.render();
each(this.chart.axes, function(axis) {
if (axis.pane === this) {
axis.pane = null;
axis.update({}, redraw);
}
}, this);
}
});
H.Pane = Pane;
}(Highcharts));
(function(H) {
/**
* (c) 2010-2017 Torstein Honsi
*
* License: www.highcharts.com/license
*/
var Axis = H.Axis,
each = H.each,
extend = H.extend,
map = H.map,
merge = H.merge,
noop = H.noop,
pick = H.pick,
pInt = H.pInt,
Tick = H.Tick,
wrap = H.wrap,
hiddenAxisMixin, // @todo Extract this to a new file
radialAxisMixin, // @todo Extract this to a new file
axisProto = Axis.prototype,
tickProto = Tick.prototype;
/**
* Augmented methods for the x axis in order to hide it completely, used for the X axis in gauges
*/
hiddenAxisMixin = {
getOffset: noop,
redraw: function() {
this.isDirty = false; // prevent setting Y axis dirty
},
render: function() {
this.isDirty = false; // prevent setting Y axis dirty
},
setScale: noop,
setCategories: noop,
setTitle: noop
};
/**
* Augmented methods for the value axis
*/
radialAxisMixin = {
/**
* The default options extend defaultYAxisOptions
*/
defaultRadialGaugeOptions: {
labels: {
align: 'center',
x: 0,
y: null // auto
},
minorGridLineWidth: 0,
minorTickInterval: 'auto',
minorTickLength: 10,
minorTickPosition: 'inside',
minorTickWidth: 1,
tickLength: 10,
tickPosition: 'inside',
tickWidth: 2,
title: {
rotation: 0
},
zIndex: 2 // behind dials, points in the series group
},
// Circular axis around the perimeter of a polar chart
defaultRadialXOptions: {
gridLineWidth: 1, // spokes
labels: {
align: null, // auto
distance: 15,
x: 0,
y: null // auto
},
maxPadding: 0,
minPadding: 0,
showLastLabel: false,
tickLength: 0
},
// Radial axis, like a spoke in a polar chart
defaultRadialYOptions: {
gridLineInterpolation: 'circle',
labels: {
align: 'right',
x: -3,
y: -2
},
showLastLabel: false,
title: {
x: 4,
text: null,
rotation: 90
}
},
/**
* Merge and set options
*/
setOptions: function(userOptions) {
var options = this.options = merge(
this.defaultOptions,
this.defaultRadialOptions,
userOptions
);
// Make sure the plotBands array is instanciated for each Axis (#2649)
if (!options.plotBands) {
options.plotBands = [];
}
},
/**
* Wrap the getOffset method to return zero offset for title or labels in a radial
* axis
*/
getOffset: function() {
// Call the Axis prototype method (the method we're in now is on the instance)
axisProto.getOffset.call(this);
// Title or label offsets are not counted
this.chart.axisOffset[this.side] = 0;
},
/**
* Get the path for the axis line. This method is also referenced in the getPlotLinePath
* method.
*/
getLinePath: function(lineWidth, radius) {
var center = this.center,
end,
chart = this.chart,
r = pick(radius, center[2] / 2 - this.offset),
path;
if (this.isCircular || radius !== undefined) {
path = this.chart.renderer.symbols.arc(
this.left + center[0],
this.top + center[1],
r,
r, {
start: this.startAngleRad,
end: this.endAngleRad,
open: true,
innerR: 0
}
);
// Bounds used to position the plotLine label next to the line
// (#7117)
path.xBounds = [this.left + center[0]];
path.yBounds = [this.top + center[1] - r];
} else {
end = this.postTranslate(this.angleRad, r);
path = ['M', center[0] + chart.plotLeft, center[1] + chart.plotTop, 'L', end.x, end.y];
}
return path;
},
/**
* Override setAxisTranslation by setting the translation to the difference
* in rotation. This allows the translate method to return angle for
* any given value.
*/
setAxisTranslation: function() {
// Call uber method
axisProto.setAxisTranslation.call(this);
// Set transA and minPixelPadding
if (this.center) { // it's not defined the first time
if (this.isCircular) {
this.transA = (this.endAngleRad - this.startAngleRad) /
((this.max - this.min) || 1);
} else {
this.transA = (this.center[2] / 2) / ((this.max - this.min) || 1);
}
if (this.isXAxis) {
this.minPixelPadding = this.transA * this.minPointOffset;
} else {
// This is a workaround for regression #2593, but categories still don't position correctly.
this.minPixelPadding = 0;
}
}
},
/**
* In case of auto connect, add one closestPointRange to the max value right before
* tickPositions are computed, so that ticks will extend passed the real max.
*/
beforeSetTickPositions: function() {
// If autoConnect is true, polygonal grid lines are connected, and one closestPointRange
// is added to the X axis to prevent the last point from overlapping the first.
this.autoConnect = this.isCircular && pick(this.userMax, this.options.max) === undefined &&
this.endAngleRad - this.startAngleRad === 2 * Math.PI;
if (this.autoConnect) {
this.max += (this.categories && 1) || this.pointRange || this.closestPointRange || 0; // #1197, #2260
}
},
/**
* Override the setAxisSize method to use the arc's circumference as length. This
* allows tickPixelInterval to apply to pixel lengths along the perimeter
*/
setAxisSize: function() {
axisProto.setAxisSize.call(this);
if (this.isRadial) {
// Set the center array
this.pane.updateCenter(this);
// The sector is used in Axis.translate to compute the translation of reversed axis points (#2570)
if (this.isCircular) {
this.sector = this.endAngleRad - this.startAngleRad;
}
// Axis len is used to lay out the ticks
this.len = this.width = this.height = this.center[2] * pick(this.sector, 1) / 2;
}
},
/**
* Returns the x, y coordinate of a point given by a value and a pixel distance
* from center
*/
getPosition: function(value, length) {
return this.postTranslate(
this.isCircular ? this.translate(value) : this.angleRad, // #2848
pick(this.isCircular ? length : this.translate(value), this.center[2] / 2) - this.offset
);
},
/**
* Translate from intermediate plotX (angle), plotY (axis.len - radius) to final chart coordinates.
*/
postTranslate: function(angle, radius) {
var chart = this.chart,
center = this.center;
angle = this.startAngleRad + angle;
return {
x: chart.plotLeft + center[0] + Math.cos(angle) * radius,
y: chart.plotTop + center[1] + Math.sin(angle) * radius
};
},
/**
* Find the path for plot bands along the radial axis
*/
getPlotBandPath: function(from, to, options) {
var center = this.center,
startAngleRad = this.startAngleRad,
fullRadius = center[2] / 2,
radii = [
pick(options.outerRadius, '100%'),
options.innerRadius,
pick(options.thickness, 10)
],
offset = Math.min(this.offset, 0),
percentRegex = /%$/,
start,
end,
open,
isCircular = this.isCircular, // X axis in a polar chart
ret;
// Polygonal plot bands
if (this.options.gridLineInterpolation === 'polygon') {
ret = this.getPlotLinePath(from).concat(this.getPlotLinePath(to, true));
// Circular grid bands
} else {
// Keep within bounds
from = Math.max(from, this.min);
to = Math.min(to, this.max);
// Plot bands on Y axis (radial axis) - inner and outer radius depend on to and from
if (!isCircular) {
radii[0] = this.translate(from);
radii[1] = this.translate(to);
}
// Convert percentages to pixel values
radii = map(radii, function(radius) {
if (percentRegex.test(radius)) {
radius = (pInt(radius, 10) * fullRadius) / 100;
}
return radius;
});
// Handle full circle
if (options.shape === 'circle' || !isCircular) {
start = -Math.PI / 2;
end = Math.PI * 1.5;
open = true;
} else {
start = startAngleRad + this.translate(from);
end = startAngleRad + this.translate(to);
}
radii[0] -= offset; // #5283
radii[2] -= offset; // #5283
ret = this.chart.renderer.symbols.arc(
this.left + center[0],
this.top + center[1],
radii[0],
radii[0], {
start: Math.min(start, end), // Math is for reversed yAxis (#3606)
end: Math.max(start, end),
innerR: pick(radii[1], radii[0] - radii[2]),
open: open
}
);
}
return ret;
},
/**
* Find the path for plot lines perpendicular to the radial axis.
*/
getPlotLinePath: function(value, reverse) {
var axis = this,
center = axis.center,
chart = axis.chart,
end = axis.getPosition(value),
xAxis,
xy,
tickPositions,
ret;
// Spokes
if (axis.isCircular) {
ret = ['M', center[0] + chart.plotLeft, center[1] + chart.plotTop, 'L', end.x, end.y];
// Concentric circles
} else if (axis.options.gridLineInterpolation === 'circle') {
value = axis.translate(value);
if (value) { // a value of 0 is in the center
ret = axis.getLinePath(0, value);
}
// Concentric polygons
} else {
// Find the X axis in the same pane
each(chart.xAxis, function(a) {
if (a.pane === axis.pane) {
xAxis = a;
}
});
ret = [];
value = axis.translate(value);
tickPositions = xAxis.tickPositions;
if (xAxis.autoConnect) {
tickPositions = tickPositions.concat([tickPositions[0]]);
}
// Reverse the positions for concatenation of polygonal plot bands
if (reverse) {
tickPositions = [].concat(tickPositions).reverse();
}
each(tickPositions, function(pos, i) {
xy = xAxis.getPosition(pos, value);
ret.push(i ? 'L' : 'M', xy.x, xy.y);
});
}
return ret;
},
/**
* Find the position for the axis title, by default inside the gauge
*/
getTitlePosition: function() {
var center = this.center,
chart = this.chart,
titleOptions = this.options.title;
return {
x: chart.plotLeft + center[0] + (titleOptions.x || 0),
y: chart.plotTop + center[1] - ({
high: 0.5,
middle: 0.25,
low: 0
}[titleOptions.align] *
center[2]) + (titleOptions.y || 0)
};
}
};
/**
* Override axisProto.init to mix in special axis instance functions and function overrides
*/
wrap(axisProto, 'init', function(proceed, chart, userOptions) {
var angular = chart.angular,
polar = chart.polar,
isX = userOptions.isX,
isHidden = angular && isX,
isCircular,
options,
chartOptions = chart.options,
paneIndex = userOptions.pane || 0,
pane = this.pane = chart.pane && chart.pane[paneIndex],
paneOptions = pane && pane.options;
// Before prototype.init
if (angular) {
extend(this, isHidden ? hiddenAxisMixin : radialAxisMixin);
isCircular = !isX;
if (isCircular) {
this.defaultRadialOptions = this.defaultRadialGaugeOptions;
}
} else if (polar) {
extend(this, radialAxisMixin);
isCircular = isX;
this.defaultRadialOptions = isX ? this.defaultRadialXOptions : merge(this.defaultYAxisOptions, this.defaultRadialYOptions);
}
// Disable certain features on angular and polar axes
if (angular || polar) {
this.isRadial = true;
chart.inverted = false;
chartOptions.chart.zoomType = null;
} else {
this.isRadial = false;
}
// A pointer back to this axis to borrow geometry
if (pane && isCircular) {
pane.axis = this;
}
// Run prototype.init
proceed.call(this, chart, userOptions);
if (!isHidden && pane && (angular || polar)) {
options = this.options;
// Start and end angle options are
// given in degrees relative to top, while internal computations are
// in radians relative to right (like SVG).
this.angleRad = (options.angle || 0) * Math.PI / 180; // Y axis in polar charts
this.startAngleRad = (paneOptions.startAngle - 90) * Math.PI / 180; // Gauges
this.endAngleRad = (pick(paneOptions.endAngle, paneOptions.startAngle + 360) - 90) * Math.PI / 180; // Gauges
this.offset = options.offset || 0;
this.isCircular = isCircular;
}
});
/**
* Wrap auto label align to avoid setting axis-wide rotation on radial axes (#4920)
* @param {Function} proceed
* @returns {String} Alignment
*/
wrap(axisProto, 'autoLabelAlign', function(proceed) {
if (!this.isRadial) {
return proceed.apply(this, [].slice.call(arguments, 1));
} // else return undefined
});
/**
* Add special cases within the Tick class' methods for radial axes.
*/
wrap(tickProto, 'getPosition', function(proceed, horiz, pos, tickmarkOffset, old) {
var axis = this.axis;
return axis.getPosition ?
axis.getPosition(pos) :
proceed.call(this, horiz, pos, tickmarkOffset, old);
});
/**
* Wrap the getLabelPosition function to find the center position of the label
* based on the distance option
*/
wrap(tickProto, 'getLabelPosition', function(proceed, x, y, label, horiz, labelOptions, tickmarkOffset, index, step) {
var axis = this.axis,
optionsY = labelOptions.y,
ret,
centerSlot = 20, // 20 degrees to each side at the top and bottom
align = labelOptions.align,
angle = ((axis.translate(this.pos) + axis.startAngleRad + Math.PI / 2) / Math.PI * 180) % 360;
if (axis.isRadial) { // Both X and Y axes in a polar chart
ret = axis.getPosition(this.pos, (axis.center[2] / 2) + pick(labelOptions.distance, -25));
// Automatically rotated
if (labelOptions.rotation === 'auto') {
label.attr({
rotation: angle
});
// Vertically centered
} else if (optionsY === null) {
optionsY = axis.chart.renderer.fontMetrics(label.styles.fontSize).b - label.getBBox().height / 2;
}
// Automatic alignment
if (align === null) {
if (axis.isCircular) { // Y axis
if (this.label.getBBox().width > axis.len * axis.tickInterval / (axis.max - axis.min)) { // #3506
centerSlot = 0;
}
if (angle > centerSlot && angle < 180 - centerSlot) {
align = 'left'; // right hemisphere
} else if (angle > 180 + centerSlot && angle < 360 - centerSlot) {
align = 'right'; // left hemisphere
} else {
align = 'center'; // top or bottom
}
} else {
align = 'center';
}
label.attr({
align: align
});
}
ret.x += labelOptions.x;
ret.y += optionsY;
} else {
ret = proceed.call(this, x, y, label, horiz, labelOptions, tickmarkOffset, index, step);
}
return ret;
});
/**
* Wrap the getMarkPath function to return the path of the radial marker
*/
wrap(tickProto, 'getMarkPath', function(proceed, x, y, tickLength, tickWidth, horiz, renderer) {
var axis = this.axis,
endPoint,
ret;