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