Pie.js
6.06 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
/**
* (c) 2010-2018 Torstein Honsi
*
* 3D pie series
*
* License: www.highcharts.com/license
*/
'use strict';
import H from '../parts/Globals.js';
import '../parts/Utilities.js';
var deg2rad = H.deg2rad,
each = H.each,
pick = H.pick,
seriesTypes = H.seriesTypes,
svg = H.svg,
wrap = H.wrap;
/**
* The thickness of a 3D pie. Requires `highcharts-3d.js`
*
* @type {Number}
* @default 0
* @since 4.0
* @product highcharts
* @apioption plotOptions.pie.depth
*/
wrap(seriesTypes.pie.prototype, 'translate', function (proceed) {
proceed.apply(this, [].slice.call(arguments, 1));
// Do not do this if the chart is not 3D
if (!this.chart.is3d()) {
return;
}
var series = this,
seriesOptions = series.options,
depth = seriesOptions.depth || 0,
options3d = series.chart.options.chart.options3d,
alpha = options3d.alpha,
beta = options3d.beta,
z = seriesOptions.stacking ?
(seriesOptions.stack || 0) * depth :
series._i * depth;
z += depth / 2;
if (seriesOptions.grouping !== false) {
z = 0;
}
each(series.data, function (point) {
var shapeArgs = point.shapeArgs,
angle;
point.shapeType = 'arc3d';
shapeArgs.z = z;
shapeArgs.depth = depth * 0.75;
shapeArgs.alpha = alpha;
shapeArgs.beta = beta;
shapeArgs.center = series.center;
angle = (shapeArgs.end + shapeArgs.start) / 2;
point.slicedTranslation = {
translateX: Math.round(
Math.cos(angle) *
seriesOptions.slicedOffset *
Math.cos(alpha * deg2rad)
),
translateY: Math.round(
Math.sin(angle) *
seriesOptions.slicedOffset *
Math.cos(alpha * deg2rad)
)
};
});
});
wrap(
seriesTypes.pie.prototype.pointClass.prototype,
'haloPath',
function (proceed) {
var args = arguments;
return this.series.chart.is3d() ? [] : proceed.call(this, args[1]);
}
);
wrap(
seriesTypes.pie.prototype,
'pointAttribs',
function (proceed, point, state) {
var attr = proceed.call(this, point, state),
options = this.options;
if (this.chart.is3d()) {
attr.stroke = options.edgeColor || point.color || this.color;
attr['stroke-width'] = pick(options.edgeWidth, 1);
}
return attr;
}
);
wrap(seriesTypes.pie.prototype, 'drawPoints', function (proceed) {
proceed.apply(this, [].slice.call(arguments, 1));
if (this.chart.is3d()) {
each(this.points, function (point) {
var graphic = point.graphic;
// #4584 Check if has graphic - null points don't have it
if (graphic) {
// Hide null or 0 points (#3006, 3650)
graphic[point.y && point.visible ? 'show' : 'hide']();
}
});
}
});
wrap(seriesTypes.pie.prototype, 'drawDataLabels', function (proceed) {
if (this.chart.is3d()) {
var series = this,
chart = series.chart,
options3d = chart.options.chart.options3d;
each(series.data, function (point) {
var shapeArgs = point.shapeArgs,
r = shapeArgs.r,
// #3240 issue with datalabels for 0 and null values
a1 = (shapeArgs.alpha || options3d.alpha) * deg2rad,
b1 = (shapeArgs.beta || options3d.beta) * deg2rad,
a2 = (shapeArgs.start + shapeArgs.end) / 2,
labelPos = point.labelPos,
labelIndexes = [0, 2, 4], // [x1, y1, x2, y2, x3, y3]
yOffset = (-r * (1 - Math.cos(a1)) * Math.sin(a2)),
xOffset = r * (Math.cos(b1) - 1) * Math.cos(a2);
// Apply perspective on label positions
each(labelIndexes, function (index) {
labelPos[index] += xOffset;
labelPos[index + 1] += yOffset;
});
});
}
proceed.apply(this, [].slice.call(arguments, 1));
});
wrap(seriesTypes.pie.prototype, 'addPoint', function (proceed) {
proceed.apply(this, [].slice.call(arguments, 1));
if (this.chart.is3d()) {
// destroy (and rebuild) everything!!!
this.update(this.userOptions, true); // #3845 pass the old options
}
});
wrap(seriesTypes.pie.prototype, 'animate', function (proceed) {
if (!this.chart.is3d()) {
proceed.apply(this, [].slice.call(arguments, 1));
} else {
var args = arguments,
init = args[1],
animation = this.options.animation,
attribs,
center = this.center,
group = this.group,
markerGroup = this.markerGroup;
if (svg) { // VML is too slow anyway
if (animation === true) {
animation = {};
}
// Initialize the animation
if (init) {
// Scale down the group and place it in the center
group.oldtranslateX = group.translateX;
group.oldtranslateY = group.translateY;
attribs = {
translateX: center[0],
translateY: center[1],
scaleX: 0.001, // #1499
scaleY: 0.001
};
group.attr(attribs);
if (markerGroup) {
markerGroup.attrSetters = group.attrSetters;
markerGroup.attr(attribs);
}
// Run the animation
} else {
attribs = {
translateX: group.oldtranslateX,
translateY: group.oldtranslateY,
scaleX: 1,
scaleY: 1
};
group.animate(attribs, animation);
if (markerGroup) {
markerGroup.animate(attribs, animation);
}
// Delete this function to allow it only once
this.animate = null;
}
}
}
});