corrade-nucleus-nucleons – Blame information for rev 20

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