corrade-nucleus-nucleons – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
11 | office | 2 | * @license Highcharts JS v5.0.12 (2017-05-24) |
1 | office | 3 | * Highcharts funnel module |
4 | * |
||
5 | * (c) 2010-2017 Torstein Honsi |
||
6 | * |
||
7 | * License: www.highcharts.com/license |
||
8 | */ |
||
9 | 'use strict'; |
||
10 | (function(factory) { |
||
11 | if (typeof module === 'object' && module.exports) { |
||
12 | module.exports = factory; |
||
13 | } else { |
||
14 | factory(Highcharts); |
||
15 | } |
||
16 | }(function(Highcharts) { |
||
17 | (function(Highcharts) { |
||
18 | /** |
||
19 | * Highcharts funnel module |
||
20 | * |
||
21 | * (c) 2010-2017 Torstein Honsi |
||
22 | * |
||
23 | * License: www.highcharts.com/license |
||
24 | */ |
||
25 | /* eslint indent:0 */ |
||
26 | |||
27 | // create shortcuts |
||
28 | var seriesType = Highcharts.seriesType, |
||
29 | seriesTypes = Highcharts.seriesTypes, |
||
30 | noop = Highcharts.noop, |
||
11 | office | 31 | pick = Highcharts.pick, |
1 | office | 32 | each = Highcharts.each; |
33 | |||
34 | |||
35 | seriesType('funnel', 'pie', { |
||
36 | animation: false, |
||
37 | center: ['50%', '50%'], |
||
38 | width: '90%', |
||
39 | neckWidth: '30%', |
||
40 | height: '100%', |
||
41 | neckHeight: '25%', |
||
42 | reversed: false, |
||
43 | size: true, // to avoid adapting to data label size in Pie.drawDataLabels |
||
44 | |||
45 | |||
46 | }, |
||
47 | |||
48 | // Properties |
||
49 | { |
||
50 | animate: noop, |
||
51 | |||
52 | /** |
||
53 | * Overrides the pie translate method |
||
54 | */ |
||
55 | translate: function() { |
||
56 | |||
57 | var |
||
58 | // Get positions - either an integer or a percentage string must be given |
||
59 | getLength = function(length, relativeTo) { |
||
60 | return (/%$/).test(length) ? |
||
61 | relativeTo * parseInt(length, 10) / 100 : |
||
62 | parseInt(length, 10); |
||
63 | }, |
||
64 | |||
65 | sum = 0, |
||
66 | series = this, |
||
67 | chart = series.chart, |
||
68 | options = series.options, |
||
69 | reversed = options.reversed, |
||
70 | ignoreHiddenPoint = options.ignoreHiddenPoint, |
||
71 | plotWidth = chart.plotWidth, |
||
72 | plotHeight = chart.plotHeight, |
||
73 | cumulative = 0, // start at top |
||
74 | center = options.center, |
||
75 | centerX = getLength(center[0], plotWidth), |
||
76 | centerY = getLength(center[1], plotHeight), |
||
77 | width = getLength(options.width, plotWidth), |
||
78 | tempWidth, |
||
79 | getWidthAt, |
||
80 | height = getLength(options.height, plotHeight), |
||
81 | neckWidth = getLength(options.neckWidth, plotWidth), |
||
82 | neckHeight = getLength(options.neckHeight, plotHeight), |
||
83 | neckY = (centerY - height / 2) + height - neckHeight, |
||
84 | data = series.data, |
||
85 | path, |
||
86 | fraction, |
||
87 | half = options.dataLabels.position === 'left' ? 1 : 0, |
||
88 | |||
89 | x1, |
||
90 | y1, |
||
91 | x2, |
||
92 | x3, |
||
93 | y3, |
||
94 | x4, |
||
95 | y5; |
||
96 | |||
97 | // Return the width at a specific y coordinate |
||
98 | series.getWidthAt = getWidthAt = function(y) { |
||
99 | var top = (centerY - height / 2); |
||
100 | |||
101 | return y > neckY || height === neckHeight ? |
||
102 | neckWidth : |
||
103 | neckWidth + (width - neckWidth) * (1 - (y - top) / (height - neckHeight)); |
||
104 | }; |
||
11 | office | 105 | series.getX = function(y, half, point) { |
106 | return centerX + (half ? -1 : 1) * ((getWidthAt(reversed ? 2 * centerY - y : y) / 2) + point.labelDistance); |
||
1 | office | 107 | }; |
108 | |||
109 | // Expose |
||
110 | series.center = [centerX, centerY, height]; |
||
111 | series.centerX = centerX; |
||
112 | |||
113 | /* |
||
114 | * Individual point coordinate naming: |
||
115 | * |
||
116 | * x1,y1 _________________ x2,y1 |
||
117 | * \ / |
||
118 | * \ / |
||
119 | * \ / |
||
120 | * \ / |
||
121 | * \ / |
||
122 | * x3,y3 _________ x4,y3 |
||
123 | * |
||
124 | * Additional for the base of the neck: |
||
125 | * |
||
126 | * | | |
||
127 | * | | |
||
128 | * | | |
||
129 | * x3,y5 _________ x4,y5 |
||
130 | */ |
||
131 | |||
132 | |||
133 | |||
134 | |||
135 | // get the total sum |
||
136 | each(data, function(point) { |
||
137 | if (!ignoreHiddenPoint || point.visible !== false) { |
||
138 | sum += point.y; |
||
139 | } |
||
140 | }); |
||
141 | |||
142 | each(data, function(point) { |
||
143 | // set start and end positions |
||
144 | y5 = null; |
||
145 | fraction = sum ? point.y / sum : 0; |
||
146 | y1 = centerY - height / 2 + cumulative * height; |
||
147 | y3 = y1 + fraction * height; |
||
148 | //tempWidth = neckWidth + (width - neckWidth) * ((height - neckHeight - y1) / (height - neckHeight)); |
||
149 | tempWidth = getWidthAt(y1); |
||
150 | x1 = centerX - tempWidth / 2; |
||
151 | x2 = x1 + tempWidth; |
||
152 | tempWidth = getWidthAt(y3); |
||
153 | x3 = centerX - tempWidth / 2; |
||
154 | x4 = x3 + tempWidth; |
||
155 | |||
156 | // the entire point is within the neck |
||
157 | if (y1 > neckY) { |
||
158 | x1 = x3 = centerX - neckWidth / 2; |
||
159 | x2 = x4 = centerX + neckWidth / 2; |
||
160 | |||
161 | // the base of the neck |
||
162 | } else if (y3 > neckY) { |
||
163 | y5 = y3; |
||
164 | |||
165 | tempWidth = getWidthAt(neckY); |
||
166 | x3 = centerX - tempWidth / 2; |
||
167 | x4 = x3 + tempWidth; |
||
168 | |||
169 | y3 = neckY; |
||
170 | } |
||
171 | |||
172 | if (reversed) { |
||
173 | y1 = 2 * centerY - y1; |
||
174 | y3 = 2 * centerY - y3; |
||
175 | y5 = (y5 ? 2 * centerY - y5 : null); |
||
176 | } |
||
177 | // save the path |
||
178 | path = [ |
||
179 | 'M', |
||
180 | x1, y1, |
||
181 | 'L', |
||
182 | x2, y1, |
||
183 | x4, y3 |
||
184 | ]; |
||
185 | if (y5) { |
||
186 | path.push(x4, y5, x3, y5); |
||
187 | } |
||
188 | path.push(x3, y3, 'Z'); |
||
189 | |||
190 | // prepare for using shared dr |
||
191 | point.shapeType = 'path'; |
||
192 | point.shapeArgs = { |
||
193 | d: path |
||
194 | }; |
||
195 | |||
196 | |||
197 | // for tooltips and data labels |
||
198 | point.percentage = fraction * 100; |
||
199 | point.plotX = centerX; |
||
200 | point.plotY = (y1 + (y5 || y3)) / 2; |
||
201 | |||
202 | // Placement of tooltips and data labels |
||
203 | point.tooltipPos = [ |
||
204 | centerX, |
||
205 | point.plotY |
||
206 | ]; |
||
207 | |||
208 | // Slice is a noop on funnel points |
||
209 | point.slice = noop; |
||
210 | |||
211 | // Mimicking pie data label placement logic |
||
212 | point.half = half; |
||
213 | |||
214 | if (!ignoreHiddenPoint || point.visible !== false) { |
||
215 | cumulative += fraction; |
||
216 | } |
||
217 | }); |
||
218 | }, |
||
219 | |||
220 | /** |
||
221 | * Funnel items don't have angles (#2289) |
||
222 | */ |
||
223 | sortByAngle: function(points) { |
||
224 | points.sort(function(a, b) { |
||
225 | return a.plotY - b.plotY; |
||
226 | }); |
||
227 | }, |
||
228 | |||
229 | /** |
||
230 | * Extend the pie data label method |
||
231 | */ |
||
232 | drawDataLabels: function() { |
||
11 | office | 233 | var series = this, |
234 | data = series.data, |
||
235 | labelDistance = series.options.dataLabels.distance, |
||
1 | office | 236 | leftSide, |
237 | sign, |
||
238 | point, |
||
239 | i = data.length, |
||
240 | x, |
||
241 | y; |
||
242 | |||
243 | // In the original pie label anticollision logic, the slots are distributed |
||
244 | // from one labelDistance above to one labelDistance below the pie. In funnels |
||
245 | // we don't want this. |
||
11 | office | 246 | series.center[2] -= 2 * labelDistance; |
1 | office | 247 | |
248 | // Set the label position array for each point. |
||
249 | while (i--) { |
||
250 | point = data[i]; |
||
251 | leftSide = point.half; |
||
252 | sign = leftSide ? 1 : -1; |
||
253 | y = point.plotY; |
||
11 | office | 254 | point.labelDistance = pick( |
255 | point.options.dataLabels && point.options.dataLabels.distance, |
||
256 | labelDistance |
||
257 | ); |
||
1 | office | 258 | |
11 | office | 259 | series.maxLabelDistance = Math.max(point.labelDistance, series.maxLabelDistance || 0); |
260 | x = series.getX(y, leftSide, point); |
||
261 | |||
1 | office | 262 | // set the anchor point for data labels |
263 | point.labelPos = [ |
||
264 | 0, // first break of connector |
||
265 | y, // a/a |
||
11 | office | 266 | x + (point.labelDistance - 5) * sign, // second break, right outside point shape |
1 | office | 267 | y, // a/a |
11 | office | 268 | x + point.labelDistance * sign, // landing point for connector |
1 | office | 269 | y, // a/a |
270 | leftSide ? 'right' : 'left', // alignment |
||
271 | |||
272 | ]; |
||
273 | } |
||
274 | |||
275 | seriesTypes.pie.prototype.drawDataLabels.call(this); |
||
276 | } |
||
277 | |||
278 | }); |
||
279 | |||
280 | /** |
||
281 | * Pyramid series type. |
||
282 | * A pyramid series is a special type of funnel, without neck and reversed by default. |
||
283 | */ |
||
284 | seriesType('pyramid', 'funnel', { |
||
285 | neckWidth: '0%', |
||
286 | neckHeight: '0%', |
||
287 | reversed: true |
||
288 | }); |
||
289 | |||
290 | }(Highcharts)); |
||
291 | })); |