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 | * Solid angular gauge 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(H) { |
||
18 | /** |
||
19 | * Solid angular gauge module |
||
20 | * |
||
21 | * (c) 2010-2017 Torstein Honsi |
||
22 | * |
||
23 | * License: www.highcharts.com/license |
||
24 | */ |
||
25 | |||
26 | |||
27 | var pInt = H.pInt, |
||
28 | pick = H.pick, |
||
29 | each = H.each, |
||
30 | isNumber = H.isNumber, |
||
31 | wrap = H.wrap, |
||
32 | Renderer = H.Renderer, |
||
33 | colorAxisMethods; |
||
34 | |||
35 | /** |
||
36 | * Symbol definition of an arc with round edges. |
||
37 | * |
||
38 | * @param {Number} x - The X coordinate for the top left position. |
||
39 | * @param {Number} y - The Y coordinate for the top left position. |
||
40 | * @param {Number} w - The pixel width. |
||
41 | * @param {Number} h - The pixel height. |
||
42 | * @param {Object} [options] - Additional options, depending on the actual |
||
43 | * symbol drawn. |
||
44 | * @param {boolean} [options.rounded] - Whether to draw rounded edges. |
||
45 | * @return {Array} Path of the created arc. |
||
46 | */ |
||
47 | wrap(Renderer.prototype.symbols, 'arc', function(proceed, x, y, w, h, options) { |
||
48 | var arc = proceed, |
||
49 | path = arc(x, y, w, h, options); |
||
50 | if (options.rounded) { |
||
51 | var r = options.r || w, |
||
52 | smallR = (r - options.innerR) / 2, |
||
53 | x1 = path[1], |
||
54 | y1 = path[2], |
||
55 | x2 = path[12], |
||
56 | y2 = path[13], |
||
57 | roundStart = ['A', smallR, smallR, 0, 1, 1, x1, y1], |
||
58 | roundEnd = ['A', smallR, smallR, 0, 1, 1, x2, y2]; |
||
59 | // Insert rounded edge on end, and remove line. |
||
60 | path.splice.apply(path, [path.length - 1, 0].concat(roundStart)); |
||
61 | // Insert rounded edge on end, and remove line. |
||
62 | path.splice.apply(path, [11, 3].concat(roundEnd)); |
||
63 | } |
||
64 | return path; |
||
65 | }); |
||
66 | |||
67 | // These methods are defined in the ColorAxis object, and copied here. |
||
68 | // If we implement an AMD system we should make ColorAxis a dependency. |
||
69 | colorAxisMethods = { |
||
70 | |||
71 | |||
72 | initDataClasses: function(userOptions) { |
||
73 | var axis = this, |
||
74 | chart = this.chart, |
||
75 | dataClasses, |
||
76 | colorCounter = 0, |
||
77 | options = this.options; |
||
78 | this.dataClasses = dataClasses = []; |
||
79 | |||
80 | each(userOptions.dataClasses, function(dataClass, i) { |
||
81 | var colors; |
||
82 | |||
83 | dataClass = H.merge(dataClass); |
||
84 | dataClasses.push(dataClass); |
||
85 | if (!dataClass.color) { |
||
86 | if (options.dataClassColor === 'category') { |
||
87 | colors = chart.options.colors; |
||
88 | dataClass.color = colors[colorCounter++]; |
||
89 | // loop back to zero |
||
90 | if (colorCounter === colors.length) { |
||
91 | colorCounter = 0; |
||
92 | } |
||
93 | } else { |
||
94 | dataClass.color = axis.tweenColors(H.color(options.minColor), H.color(options.maxColor), i / (userOptions.dataClasses.length - 1)); |
||
95 | } |
||
96 | } |
||
97 | }); |
||
98 | }, |
||
99 | |||
100 | initStops: function(userOptions) { |
||
101 | this.stops = userOptions.stops || [ |
||
102 | [0, this.options.minColor], |
||
103 | [1, this.options.maxColor] |
||
104 | ]; |
||
105 | each(this.stops, function(stop) { |
||
106 | stop.color = H.color(stop[1]); |
||
107 | }); |
||
108 | }, |
||
109 | /** |
||
110 | * Translate from a value to a color |
||
111 | */ |
||
112 | toColor: function(value, point) { |
||
113 | var pos, |
||
114 | stops = this.stops, |
||
115 | from, |
||
116 | to, |
||
117 | color, |
||
118 | dataClasses = this.dataClasses, |
||
119 | dataClass, |
||
120 | i; |
||
121 | |||
122 | if (dataClasses) { |
||
123 | i = dataClasses.length; |
||
124 | while (i--) { |
||
125 | dataClass = dataClasses[i]; |
||
126 | from = dataClass.from; |
||
127 | to = dataClass.to; |
||
128 | if ((from === undefined || value >= from) && (to === undefined || value <= to)) { |
||
129 | color = dataClass.color; |
||
130 | if (point) { |
||
131 | point.dataClass = i; |
||
132 | } |
||
133 | break; |
||
134 | } |
||
135 | } |
||
136 | |||
137 | } else { |
||
138 | |||
139 | if (this.isLog) { |
||
140 | value = this.val2lin(value); |
||
141 | } |
||
142 | pos = 1 - ((this.max - value) / (this.max - this.min)); |
||
143 | i = stops.length; |
||
144 | while (i--) { |
||
145 | if (pos > stops[i][0]) { |
||
146 | break; |
||
147 | } |
||
148 | } |
||
149 | from = stops[i] || stops[i + 1]; |
||
150 | to = stops[i + 1] || from; |
||
151 | |||
152 | // The position within the gradient |
||
153 | pos = 1 - (to[0] - pos) / ((to[0] - from[0]) || 1); |
||
154 | |||
155 | color = this.tweenColors( |
||
156 | from.color, |
||
157 | to.color, |
||
158 | pos |
||
159 | ); |
||
160 | } |
||
161 | return color; |
||
162 | }, |
||
163 | /* |
||
164 | * Return an intermediate color between two colors, according to pos where 0 |
||
165 | * is the from color and 1 is the to color. |
||
166 | */ |
||
167 | tweenColors: function(from, to, pos) { |
||
168 | // Check for has alpha, because rgba colors perform worse due to lack of |
||
169 | // support in WebKit. |
||
170 | var hasAlpha, |
||
171 | ret; |
||
172 | |||
173 | // Unsupported color, return to-color (#3920) |
||
174 | if (!to.rgba.length || !from.rgba.length) { |
||
175 | ret = to.input || 'none'; |
||
176 | |||
177 | // Interpolate |
||
178 | } else { |
||
179 | from = from.rgba; |
||
180 | to = to.rgba; |
||
181 | hasAlpha = (to[3] !== 1 || from[3] !== 1); |
||
182 | ret = (hasAlpha ? 'rgba(' : 'rgb(') + |
||
183 | Math.round(to[0] + (from[0] - to[0]) * (1 - pos)) + ',' + |
||
184 | Math.round(to[1] + (from[1] - to[1]) * (1 - pos)) + ',' + |
||
185 | Math.round(to[2] + (from[2] - to[2]) * (1 - pos)) + |
||
186 | (hasAlpha ? (',' + (to[3] + (from[3] - to[3]) * (1 - pos))) : '') + ')'; |
||
187 | } |
||
188 | return ret; |
||
189 | } |
||
190 | }; |
||
191 | |||
192 | /** |
||
193 | * Handle animation of the color attributes directly |
||
194 | */ |
||
195 | each(['fill', 'stroke'], function(prop) { |
||
196 | H.Fx.prototype[prop + 'Setter'] = function() { |
||
197 | this.elem.attr( |
||
198 | prop, |
||
199 | colorAxisMethods.tweenColors( |
||
200 | H.color(this.start), |
||
201 | H.color(this.end), |
||
202 | this.pos |
||
203 | ), |
||
204 | null, |
||
205 | true |
||
206 | ); |
||
207 | }; |
||
208 | }); |
||
209 | |||
210 | // The solidgauge series type |
||
211 | H.seriesType('solidgauge', 'gauge', { |
||
212 | colorByPoint: true |
||
213 | |||
214 | }, { |
||
215 | |||
216 | /** |
||
217 | * Extend the translate function to extend the Y axis with the necessary |
||
218 | * decoration (#5895). |
||
219 | */ |
||
220 | translate: function() { |
||
221 | var axis = this.yAxis; |
||
222 | H.extend(axis, colorAxisMethods); |
||
223 | |||
224 | // Prepare data classes |
||
225 | if (!axis.dataClasses && axis.options.dataClasses) { |
||
226 | axis.initDataClasses(axis.options); |
||
227 | } |
||
228 | axis.initStops(axis.options); |
||
229 | |||
230 | // Generate points and inherit data label position |
||
231 | H.seriesTypes.gauge.prototype.translate.call(this); |
||
232 | }, |
||
233 | |||
234 | /** |
||
235 | * Draw the points where each point is one needle |
||
236 | */ |
||
237 | drawPoints: function() { |
||
238 | var series = this, |
||
239 | yAxis = series.yAxis, |
||
240 | center = yAxis.center, |
||
241 | options = series.options, |
||
242 | renderer = series.chart.renderer, |
||
243 | overshoot = options.overshoot, |
||
244 | overshootVal = isNumber(overshoot) ? overshoot / 180 * Math.PI : 0, |
||
245 | thresholdAngleRad; |
||
246 | |||
247 | // Handle the threshold option |
||
248 | if (isNumber(options.threshold)) { |
||
249 | thresholdAngleRad = yAxis.startAngleRad + yAxis.translate( |
||
250 | options.threshold, |
||
251 | null, |
||
252 | null, |
||
253 | null, |
||
254 | true |
||
255 | ); |
||
256 | } |
||
257 | this.thresholdAngleRad = pick(thresholdAngleRad, yAxis.startAngleRad); |
||
258 | |||
259 | |||
260 | each(series.points, function(point) { |
||
261 | var graphic = point.graphic, |
||
262 | rotation = yAxis.startAngleRad + yAxis.translate(point.y, null, null, null, true), |
||
263 | radius = (pInt(pick(point.options.radius, options.radius, 100)) * center[2]) / 200, |
||
264 | innerRadius = (pInt(pick(point.options.innerRadius, options.innerRadius, 60)) * center[2]) / 200, |
||
265 | shapeArgs, |
||
266 | d, |
||
267 | toColor = yAxis.toColor(point.y, point), |
||
268 | axisMinAngle = Math.min(yAxis.startAngleRad, yAxis.endAngleRad), |
||
269 | axisMaxAngle = Math.max(yAxis.startAngleRad, yAxis.endAngleRad), |
||
270 | minAngle, |
||
271 | maxAngle; |
||
272 | |||
273 | if (toColor === 'none') { // #3708 |
||
274 | toColor = point.color || series.color || 'none'; |
||
275 | } |
||
276 | if (toColor !== 'none') { |
||
277 | point.color = toColor; |
||
278 | } |
||
279 | |||
280 | // Handle overshoot and clipping to axis max/min |
||
281 | rotation = Math.max(axisMinAngle - overshootVal, Math.min(axisMaxAngle + overshootVal, rotation)); |
||
282 | |||
283 | // Handle the wrap option |
||
284 | if (options.wrap === false) { |
||
285 | rotation = Math.max(axisMinAngle, Math.min(axisMaxAngle, rotation)); |
||
286 | } |
||
287 | |||
288 | minAngle = Math.min(rotation, series.thresholdAngleRad); |
||
289 | maxAngle = Math.max(rotation, series.thresholdAngleRad); |
||
290 | |||
291 | if (maxAngle - minAngle > 2 * Math.PI) { |
||
292 | maxAngle = minAngle + 2 * Math.PI; |
||
293 | } |
||
294 | |||
295 | point.shapeArgs = shapeArgs = { |
||
296 | x: center[0], |
||
297 | y: center[1], |
||
298 | r: radius, |
||
299 | innerR: innerRadius, |
||
300 | start: minAngle, |
||
301 | end: maxAngle, |
||
302 | rounded: options.rounded |
||
303 | }; |
||
304 | point.startR = radius; // For PieSeries.animate |
||
305 | |||
306 | if (graphic) { |
||
307 | d = shapeArgs.d; |
||
308 | graphic.animate(H.extend({ |
||
309 | fill: toColor |
||
310 | }, shapeArgs)); |
||
311 | if (d) { |
||
312 | shapeArgs.d = d; // animate alters it |
||
313 | } |
||
314 | } else { |
||
315 | point.graphic = renderer.arc(shapeArgs) |
||
316 | .addClass('highcharts-point') |
||
317 | .attr({ |
||
318 | fill: toColor, |
||
319 | 'sweep-flag': 0 |
||
320 | }) |
||
321 | .add(series.group); |
||
322 | |||
323 | |||
324 | if (options.linecap !== 'square') { |
||
325 | point.graphic.attr({ |
||
326 | 'stroke-linecap': 'round', |
||
327 | 'stroke-linejoin': 'round' |
||
328 | }); |
||
329 | } |
||
330 | point.graphic.attr({ |
||
331 | stroke: options.borderColor || 'none', |
||
332 | 'stroke-width': options.borderWidth || 0 |
||
333 | }); |
||
334 | |||
335 | } |
||
336 | }); |
||
337 | }, |
||
338 | |||
339 | /** |
||
340 | * Extend the pie slice animation by animating from start angle and up |
||
341 | */ |
||
342 | animate: function(init) { |
||
343 | |||
344 | if (!init) { |
||
345 | this.startAngleRad = this.thresholdAngleRad; |
||
346 | H.seriesTypes.pie.prototype.animate.call(this, init); |
||
347 | } |
||
348 | } |
||
349 | }); |
||
350 | |||
351 | }(Highcharts)); |
||
352 | })); |