sunburst.src.js
30.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
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
/**
* (c) 2016 Highsoft AS
* Authors: Jon Arild Nygard
*
* License: www.highcharts.com/license
*
* This module implements sunburst charts in Highcharts.
*/
'use strict';
import H from '../parts/Globals.js';
import '../mixins/centered-series.js';
import drawPoint from '../mixins/draw-point.js';
import mixinTreeSeries from '../mixins/tree-series.js';
import '../parts/Series.js';
import './treemap.src.js';
var CenteredSeriesMixin = H.CenteredSeriesMixin,
Series = H.Series,
each = H.each,
extend = H.extend,
getCenter = CenteredSeriesMixin.getCenter,
getColor = mixinTreeSeries.getColor,
getLevelOptions = mixinTreeSeries.getLevelOptions,
getStartAndEndRadians = CenteredSeriesMixin.getStartAndEndRadians,
grep = H.grep,
inArray = H.inArray,
isBoolean = function (x) {
return typeof x === 'boolean';
},
isNumber = H.isNumber,
isObject = H.isObject,
isString = H.isString,
keys = H.keys,
merge = H.merge,
noop = H.noop,
rad2deg = 180 / Math.PI,
seriesType = H.seriesType,
seriesTypes = H.seriesTypes,
setTreeValues = mixinTreeSeries.setTreeValues,
reduce = H.reduce,
updateRootId = mixinTreeSeries.updateRootId;
// TODO introduce step, which should default to 1.
var range = function range(from, to) {
var result = [],
i;
if (isNumber(from) && isNumber(to) && from <= to) {
for (i = from; i <= to; i++) {
result.push(i);
}
}
return result;
};
/**
* @param {Object} levelOptions Map of level to its options.
* @param {Object} params Object containing parameters.
* @param {Number} params.innerRadius
* @param {Number} params.outerRadius
* @
*/
var calculateLevelSizes = function calculateLevelSizes(levelOptions, params) {
var result,
p = isObject(params) ? params : {},
totalWeight = 0,
diffRadius,
levels,
levelsNotIncluded,
remainingSize,
from,
to;
if (isObject(levelOptions)) {
result = merge({}, levelOptions); // Copy levelOptions
from = isNumber(p.from) ? p.from : 0;
to = isNumber(p.to) ? p.to : 0;
levels = range(from, to);
levelsNotIncluded = grep(keys(result), function (k) {
return inArray(+k, levels) === -1;
});
diffRadius = remainingSize = isNumber(p.diffRadius) ? p.diffRadius : 0;
/**
* Convert percentage to pixels.
* Calculate the remaining size to divide between "weight" levels.
* Calculate total weight to use in convertion from weight to pixels.
*/
each(levels, function (level) {
var options = result[level],
unit = options.levelSize.unit,
value = options.levelSize.value;
if (unit === 'weight') {
totalWeight += value;
} else if (unit === 'percentage') {
options.levelSize = {
unit: 'pixels',
value: (value / 100) * diffRadius
};
remainingSize -= options.levelSize.value;
} else if (unit === 'pixels') {
remainingSize -= value;
}
});
// Convert weight to pixels.
each(levels, function (level) {
var options = result[level],
weight;
if (options.levelSize.unit === 'weight') {
weight = options.levelSize.value;
result[level].levelSize = {
unit: 'pixels',
value: (weight / totalWeight) * remainingSize
};
}
});
// Set all levels not included in interval [from,to] to have 0 pixels.
each(levelsNotIncluded, function (level) {
result[level].levelSize = {
value: 0,
unit: 'pixels'
};
});
}
return result;
};
/**
* getEndPoint - Find a set of coordinates given a start coordinates, an angle,
* and a distance.
*
* @param {number} x Start coordinate x
* @param {number} y Start coordinate y
* @param {number} angle Angle in radians
* @param {number} distance Distance from start to end coordinates
* @return {object} Returns the end coordinates, x and y.
*/
var getEndPoint = function getEndPoint(x, y, angle, distance) {
return {
x: x + (Math.cos(angle) * distance),
y: y + (Math.sin(angle) * distance)
};
};
var layoutAlgorithm = function layoutAlgorithm(parent, children, options) {
var startAngle = parent.start,
range = parent.end - startAngle,
total = parent.val,
x = parent.x,
y = parent.y,
radius = (
(
options &&
isObject(options.levelSize) &&
isNumber(options.levelSize.value)
) ?
options.levelSize.value :
0
),
innerRadius = parent.r,
outerRadius = innerRadius + radius,
slicedOffset = options && isNumber(options.slicedOffset) ?
options.slicedOffset :
0;
return reduce(children || [], function (arr, child) {
var percentage = (1 / total) * child.val,
radians = percentage * range,
radiansCenter = startAngle + (radians / 2),
offsetPosition = getEndPoint(x, y, radiansCenter, slicedOffset),
values = {
x: child.sliced ? offsetPosition.x : x,
y: child.sliced ? offsetPosition.y : y,
innerR: innerRadius,
r: outerRadius,
radius: radius,
start: startAngle,
end: startAngle + radians
};
arr.push(values);
startAngle = values.end;
return arr;
}, []);
};
var getDlOptions = function getDlOptions(params) {
// Set options to new object to avoid problems with scope
var point = params.point,
shape = isObject(params.shapeArgs) ? params.shapeArgs : {},
optionsPoint = (
isObject(params.optionsPoint) ?
params.optionsPoint.dataLabels :
{}
),
optionsLevel = (
isObject(params.level) ?
params.level.dataLabels :
{}
),
options = merge({
style: {}
}, optionsLevel, optionsPoint),
rotationRad,
rotation,
rotationMode = options.rotationMode;
if (!isNumber(options.rotation)) {
if (rotationMode === 'auto') {
if (
point.innerArcLength < 1 &&
point.outerArcLength > shape.radius
) {
rotationRad = 0;
} else if (
point.innerArcLength > 1 &&
point.outerArcLength > 1.5 * shape.radius
) {
rotationMode = 'parallel';
} else {
rotationMode = 'perpendicular';
}
}
if (rotationMode !== 'auto') {
rotationRad = (shape.end - (shape.end - shape.start) / 2);
}
if (rotationMode === 'parallel') {
options.style.width = Math.min(
shape.radius * 2.5,
(point.outerArcLength + point.innerArcLength) / 2
);
} else {
options.style.width = shape.radius;
}
if (
rotationMode === 'perpendicular' &&
point.series.chart.renderer.fontMetrics(options.style.fontSize).h >
point.outerArcLength
) {
options.style.width = 1;
}
// Apply padding (#8515)
options.style.width = Math.max(
options.style.width - 2 * (options.padding || 0),
1
);
rotation = (rotationRad * rad2deg) % 180;
if (rotationMode === 'parallel') {
rotation -= 90;
}
// Prevent text from rotating upside down
if (rotation > 90) {
rotation -= 180;
} else if (rotation < -90) {
rotation += 180;
}
options.rotation = rotation;
}
// NOTE: alignDataLabel positions the data label differntly when rotation is
// 0. Avoiding this by setting rotation to a small number.
if (options.rotation === 0) {
options.rotation = 0.001;
}
return options;
};
var getAnimation = function getAnimation(shape, params) {
var point = params.point,
radians = params.radians,
innerR = params.innerR,
idRoot = params.idRoot,
idPreviousRoot = params.idPreviousRoot,
shapeExisting = params.shapeExisting,
shapeRoot = params.shapeRoot,
shapePreviousRoot = params.shapePreviousRoot,
visible = params.visible,
from = {},
to = {
end: shape.end,
start: shape.start,
innerR: shape.innerR,
r: shape.r,
x: shape.x,
y: shape.y
};
if (visible) {
// Animate points in
if (!point.graphic && shapePreviousRoot) {
if (idRoot === point.id) {
from = {
start: radians.start,
end: radians.end
};
} else {
from = (shapePreviousRoot.end <= shape.start) ? {
start: radians.end,
end: radians.end
} : {
start: radians.start,
end: radians.start
};
}
// Animate from center and outwards.
from.innerR = from.r = innerR;
}
} else {
// Animate points out
if (point.graphic) {
if (idPreviousRoot === point.id) {
to = {
innerR: innerR,
r: innerR
};
} else if (shapeRoot) {
to = (shapeRoot.end <= shapeExisting.start) ?
{
innerR: innerR,
r: innerR,
start: radians.end,
end: radians.end
} : {
innerR: innerR,
r: innerR,
start: radians.start,
end: radians.start
};
}
}
}
return {
from: from,
to: to
};
};
var getDrillId = function getDrillId(point, idRoot, mapIdToNode) {
var drillId,
node = point.node,
nodeRoot;
if (!node.isLeaf) {
// When it is the root node, the drillId should be set to parent.
if (idRoot === point.id) {
nodeRoot = mapIdToNode[idRoot];
drillId = nodeRoot.parent;
} else {
drillId = point.id;
}
}
return drillId;
};
var cbSetTreeValuesBefore = function before(node, options) {
var mapIdToNode = options.mapIdToNode,
nodeParent = mapIdToNode[node.parent],
series = options.series,
chart = series.chart,
points = series.points,
point = points[node.i],
colorInfo = getColor(node, {
colors: chart && chart.options && chart.options.colors,
colorIndex: series.colorIndex,
index: options.index,
mapOptionsToLevel: options.mapOptionsToLevel,
parentColor: nodeParent && nodeParent.color,
parentColorIndex: nodeParent && nodeParent.colorIndex,
series: options.series,
siblings: options.siblings
});
node.color = colorInfo.color;
node.colorIndex = colorInfo.colorIndex;
if (point) {
point.color = node.color;
point.colorIndex = node.colorIndex;
// Set slicing on node, but avoid slicing the top node.
node.sliced = (node.id !== options.idRoot) ? point.sliced : false;
}
return node;
};
/**
* A Sunburst displays hierarchical data, where a level in the hierarchy is
* represented by a circle. The center represents the root node of the tree.
* The visualization bears a resemblance to both treemap and pie charts.
*
* @extends plotOptions.pie
* @sample highcharts/demo/sunburst Sunburst chart
* @excluding allAreas, clip, colorAxis, compare, compareBase,
* dataGrouping, depth, endAngle, gapSize, gapUnit,
* ignoreHiddenPoint, innerSize, joinBy, legendType, linecap,
* minSize, navigatorOptions, pointRange
* @product highcharts
* @optionparent plotOptions.sunburst
*/
var sunburstOptions = {
/**
* Set options on specific levels. Takes precedence over series options,
* but not point options.
*
* @type {Array<Object>}
* @sample highcharts/demo/sunburst Sunburst chart
* @apioption plotOptions.sunburst.levels
*/
/**
* Can set a `borderColor` on all points which lies on the same level.
*
* @type {Color}
* @apioption plotOptions.sunburst.levels.borderColor
*/
/**
* Can set a `borderWidth` on all points which lies on the same level.
*
* @type {Number}
* @apioption plotOptions.sunburst.levels.borderWidth
*/
/**
* Can set a `borderDashStyle` on all points which lies on the same level.
*
* @type {String}
* @apioption plotOptions.sunburst.levels.borderDashStyle
*/
/**
* Can set a `color` on all points which lies on the same level.
*
* @type {Color}
* @apioption plotOptions.sunburst.levels.color
*/
/**
* Can set a `colorVariation` on all points which lies on the same level.
*
* @type {Object}
* @apioption plotOptions.sunburst.levels.colorVariation
*/
/**
* The key of a color variation. Currently supports `brightness` only.
*
* @type {String}
* @apioption plotOptions.sunburst.levels.colorVariation.key
*/
/**
* The ending value of a color variation. The last sibling will receive this
* value.
*
* @type {Number}
* @apioption plotOptions.sunburst.levels.colorVariation.to
*/
/**
* Can set a `dataLabels` on all points which lies on the same level.
*
* @type {Object}
* @apioption plotOptions.sunburst.levels.dataLabels
*/
/**
* Can set a `levelSize` on all points which lies on the same level.
*
* @type {Object}
* @apioption plotOptions.sunburst.levels.levelSize
*/
/**
* Can set a `rotation` on all points which lies on the same level.
*
* @type {Number}
* @apioption plotOptions.sunburst.levels.rotation
*/
/**
* Can set a `rotationMode` on all points which lies on the same level.
*
* @type {String}
* @apioption plotOptions.sunburst.levels.rotationMode
*/
/**
* When enabled the user can click on a point which is a parent and
* zoom in on its children.
*
* @sample highcharts/demo/sunburst
* Allow drill to node
* @type {Boolean}
* @default false
* @apioption plotOptions.sunburst.allowDrillToNode
*/
/**
* The center of the sunburst chart relative to the plot area. Can be
* percentages or pixel values.
*
* @type {Array<String|Number>}
* @sample {highcharts} highcharts/plotoptions/pie-center/
* Centered at 100, 100
* @product highcharts
*/
center: ['50%', '50%'],
colorByPoint: false,
/**
* @extends plotOptions.series.dataLabels
* @excluding align,allowOverlap,distance,staggerLines,step
*/
dataLabels: {
allowOverlap: true,
defer: true,
style: {
textOverflow: 'ellipsis'
},
/**
* Decides how the data label will be rotated relative to the perimeter
* of the sunburst. Valid values are `auto`, `parallel` and
* `perpendicular`. When `auto`, the best fit will be computed for the
* point.
*
* The `series.rotation` option takes precedence over `rotationMode`.
*
* @since 6.0.0
* @validvalue ["auto", "perpendicular", "parallel"]
*/
rotationMode: 'auto'
},
/**
* Which point to use as a root in the visualization.
*
* @type {String|undefined}
* @default undefined
*/
rootId: undefined,
/**
* Used together with the levels and `allowDrillToNode` options. When
* set to false the first level visible when drilling is considered
* to be level one. Otherwise the level will be the same as the tree
* structure.
*/
levelIsConstant: true,
/**
* Determines the width of the ring per level.
* @since 6.0.5
* @sample {highcharts} highcharts/plotoptions/sunburst-levelsize/
* Sunburst with various sizes per level
*/
levelSize: {
/**
* The value used for calculating the width of the ring. Its' affect is
* determined by `levelSize.unit`.
* @sample {highcharts} highcharts/plotoptions/sunburst-levelsize/
* Sunburst with various sizes per level
*/
value: 1,
/**
* How to interpret `levelSize.value`.
* `percentage` gives a width relative to result of outer radius minus
* inner radius.
* `pixels` gives the ring a fixed width in pixels.
* `weight` takes the remaining width after percentage and pixels, and
* distributes it accross all "weighted" levels. The value relative to
* the sum of all weights determines the width.
* @validvalue ["percentage", "pixels", "weight"]
* @sample {highcharts} highcharts/plotoptions/sunburst-levelsize/
* Sunburst with various sizes per level
*/
unit: 'weight'
},
/**
* If a point is sliced, moved out from the center, how many pixels
* should it be moved?.
*
* @since 6.0.4
* @sample highcharts/plotoptions/sunburst-sliced Sliced sunburst
*/
slicedOffset: 10
};
/**
* Properties of the Sunburst series.
*/
var sunburstSeries = {
drawDataLabels: noop, // drawDataLabels is called in drawPoints
drawPoints: function drawPoints() {
var series = this,
mapOptionsToLevel = series.mapOptionsToLevel,
shapeRoot = series.shapeRoot,
group = series.group,
hasRendered = series.hasRendered,
idRoot = series.rootNode,
idPreviousRoot = series.idPreviousRoot,
nodeMap = series.nodeMap,
nodePreviousRoot = nodeMap[idPreviousRoot],
shapePreviousRoot = nodePreviousRoot && nodePreviousRoot.shapeArgs,
points = series.points,
radians = series.startAndEndRadians,
chart = series.chart,
optionsChart = chart && chart.options && chart.options.chart || {},
animation = (
isBoolean(optionsChart.animation) ?
optionsChart.animation :
true
),
positions = series.center,
center = {
x: positions[0],
y: positions[1]
},
innerR = positions[3] / 2,
renderer = series.chart.renderer,
animateLabels,
animateLabelsCalled = false,
addedHack = false,
hackDataLabelAnimation = !!(
animation &&
hasRendered &&
idRoot !== idPreviousRoot &&
series.dataLabelsGroup
);
if (hackDataLabelAnimation) {
series.dataLabelsGroup.attr({ opacity: 0 });
animateLabels = function () {
var s = series;
animateLabelsCalled = true;
if (s.dataLabelsGroup) {
s.dataLabelsGroup.animate({
opacity: 1,
visibility: 'visible'
});
}
};
}
each(points, function (point) {
var node = point.node,
level = mapOptionsToLevel[node.level],
shapeExisting = point.shapeExisting || {},
shape = node.shapeArgs || {},
animationInfo,
onComplete,
visible = !!(node.visible && node.shapeArgs);
if (hasRendered && animation) {
animationInfo = getAnimation(shape, {
center: center,
point: point,
radians: radians,
innerR: innerR,
idRoot: idRoot,
idPreviousRoot: idPreviousRoot,
shapeExisting: shapeExisting,
shapeRoot: shapeRoot,
shapePreviousRoot: shapePreviousRoot,
visible: visible
});
} else {
// When animation is disabled, attr is called from animation.
animationInfo = {
to: shape,
from: {}
};
}
extend(point, {
shapeExisting: shape, // Store for use in animation
tooltipPos: [shape.plotX, shape.plotY],
drillId: getDrillId(point, idRoot, nodeMap),
name: '' + (point.name || point.id || point.index),
plotX: shape.plotX, // used for data label position
plotY: shape.plotY, // used for data label position
value: node.val,
isNull: !visible // used for dataLabels & point.draw
});
point.dlOptions = getDlOptions({
point: point,
level: level,
optionsPoint: point.options,
shapeArgs: shape
});
if (!addedHack && visible) {
addedHack = true;
onComplete = animateLabels;
}
point.draw({
animate: animationInfo.to,
attr: extend(
animationInfo.from,
series.pointAttribs && series.pointAttribs(
point,
point.selected && 'select'
)
),
onComplete: onComplete,
group: group,
renderer: renderer,
shapeType: 'arc',
shapeArgs: shape
});
});
// Draw data labels after points
// TODO draw labels one by one to avoid addtional looping
if (hackDataLabelAnimation && addedHack) {
series.hasRendered = false;
series.options.dataLabels.defer = true;
Series.prototype.drawDataLabels.call(series);
series.hasRendered = true;
// If animateLabels is called before labels were hidden, then call
// it again.
if (animateLabelsCalled) {
animateLabels();
}
} else {
Series.prototype.drawDataLabels.call(series);
}
},
/*
* The layout algorithm for the levels
*/
layoutAlgorithm: layoutAlgorithm,
/*
* Set the shape arguments on the nodes. Recursive from root down.
*/
setShapeArgs: function (parent, parentValues, mapOptionsToLevel) {
var childrenValues = [],
level = parent.level + 1,
options = mapOptionsToLevel[level],
// Collect all children which should be included
children = grep(parent.children, function (n) {
return n.visible;
}),
twoPi = 6.28; // Two times Pi.
childrenValues = this.layoutAlgorithm(parentValues, children, options);
each(children, function (child, index) {
var values = childrenValues[index],
angle = values.start + ((values.end - values.start) / 2),
radius = values.innerR + ((values.r - values.innerR) / 2),
radians = (values.end - values.start),
isCircle = (values.innerR === 0 && radians > twoPi),
center = (
isCircle ?
{ x: values.x, y: values.y } :
getEndPoint(values.x, values.y, angle, radius)
),
val = (
child.val ?
(
child.childrenTotal > child.val ?
child.childrenTotal :
child.val
) :
child.childrenTotal
);
// The inner arc length is a convenience for data label filters.
if (this.points[child.i]) {
this.points[child.i].innerArcLength = radians * values.innerR;
this.points[child.i].outerArcLength = radians * values.r;
}
child.shapeArgs = merge(values, {
plotX: center.x,
plotY: center.y + 4 * Math.abs(Math.cos(angle))
});
child.values = merge(values, {
val: val
});
// If node has children, then call method recursively
if (child.children.length) {
this.setShapeArgs(child, child.values, mapOptionsToLevel);
}
}, this);
},
translate: function translate() {
var series = this,
options = series.options,
positions = series.center = getCenter.call(series),
radians = series.startAndEndRadians = getStartAndEndRadians(
options.startAngle,
options.endAngle
),
innerRadius = positions[3] / 2,
outerRadius = positions[2] / 2,
diffRadius = outerRadius - innerRadius,
// NOTE: updateRootId modifies series.
rootId = updateRootId(series),
mapIdToNode = series.nodeMap,
mapOptionsToLevel,
idTop,
nodeRoot = mapIdToNode && mapIdToNode[rootId],
nodeTop,
tree,
values;
series.shapeRoot = nodeRoot && nodeRoot.shapeArgs;
// Call prototype function
Series.prototype.translate.call(series);
// @todo Only if series.isDirtyData is true
tree = series.tree = series.getTree();
mapIdToNode = series.nodeMap;
nodeRoot = mapIdToNode[rootId];
idTop = isString(nodeRoot.parent) ? nodeRoot.parent : '';
nodeTop = mapIdToNode[idTop];
mapOptionsToLevel = getLevelOptions({
from: nodeRoot.level > 0 ? nodeRoot.level : 1,
levels: series.options.levels,
to: tree.height,
defaults: {
colorByPoint: options.colorByPoint,
dataLabels: options.dataLabels,
levelIsConstant: options.levelIsConstant,
levelSize: options.levelSize,
slicedOffset: options.slicedOffset
}
});
// NOTE consider doing calculateLevelSizes in a callback to
// getLevelOptions
mapOptionsToLevel = calculateLevelSizes(mapOptionsToLevel, {
diffRadius: diffRadius,
from: nodeRoot.level > 0 ? nodeRoot.level : 1,
to: tree.height
});
// TODO Try to combine setTreeValues & setColorRecursive to avoid
// unnecessary looping.
setTreeValues(tree, {
before: cbSetTreeValuesBefore,
idRoot: rootId,
levelIsConstant: options.levelIsConstant,
mapOptionsToLevel: mapOptionsToLevel,
mapIdToNode: mapIdToNode,
points: series.points,
series: series
});
values = mapIdToNode[''].shapeArgs = {
end: radians.end,
r: innerRadius,
start: radians.start,
val: nodeRoot.val,
x: positions[0],
y: positions[1]
};
this.setShapeArgs(nodeTop, values, mapOptionsToLevel);
// Set mapOptionsToLevel on series for use in drawPoints.
series.mapOptionsToLevel = mapOptionsToLevel;
},
/**
* Animate the slices in. Similar to the animation of polar charts.
*/
animate: function (init) {
var chart = this.chart,
center = [
chart.plotWidth / 2,
chart.plotHeight / 2
],
plotLeft = chart.plotLeft,
plotTop = chart.plotTop,
attribs,
group = this.group;
// Initialize the animation
if (init) {
// Scale down the group and place it in the center
attribs = {
translateX: center[0] + plotLeft,
translateY: center[1] + plotTop,
scaleX: 0.001, // #1499
scaleY: 0.001,
rotation: 10,
opacity: 0.01
};
group.attr(attribs);
// Run the animation
} else {
attribs = {
translateX: plotLeft,
translateY: plotTop,
scaleX: 1,
scaleY: 1,
rotation: 0,
opacity: 1
};
group.animate(attribs, this.options.animation);
// Delete this function to allow it only once
this.animate = null;
}
},
utils: {
calculateLevelSizes: calculateLevelSizes,
range: range
}
};
/**
* Properties of the Sunburst series.
*/
var sunburstPoint = {
draw: drawPoint,
shouldDraw: function shouldDraw() {
var point = this;
return !point.isNull;
}
};
/**
* A `sunburst` series. If the [type](#series.sunburst.type) option is
* not specified, it is inherited from [chart.type](#chart.type).
*
* @type {Object}
* @extends series,plotOptions.sunburst
* @excluding dataParser,dataURL,stack
* @product highcharts
* @apioption series.sunburst
*/
/**
* @type {Array<Object|Number>}
* @extends series.treemap.data
* @excluding x,y
* @product highcharts
* @apioption series.sunburst.data
*/
/**
* The value of the point, resulting in a relative area of the point
* in the sunburst.
*
* @type {Number}
* @default undefined
* @since 6.0.0
* @product highcharts
* @apioption series.sunburst.data.value
*/
/**
* Use this option to build a tree structure. The value should be the id of the
* point which is the parent. If no points has a matching id, or this option is
* undefined, then the parent will be set to the root.
*
* @type {String|undefined}
* @default undefined
* @since 6.0.0
* @product highcharts
* @apioption series.treemap.data.parent
*/
/**
* Whether to display a slice offset from the center. When a sunburst point is
* sliced, its children are also offset.
*
* @type {Boolean}
* @default false
* @since 6.0.4
* @sample highcharts/plotoptions/sunburst-sliced Sliced sunburst
* @product highcharts
* @apioption series.sunburst.data.sliced
*/
seriesType(
'sunburst',
'treemap',
sunburstOptions,
sunburstSeries,
sunburstPoint
);