corrade-nucleus-nucleons – Blame information for rev 11

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /**
11 office 2 * @license Highcharts JS v5.0.12 (2017-05-24)
1 office 3 *
4 * (c) 2009-2017 Torstein Honsi
5 *
6 * License: www.highcharts.com/license
7 */
8 'use strict';
9 (function(factory) {
10 if (typeof module === 'object' && module.exports) {
11 module.exports = factory;
12 } else {
13 factory(Highcharts);
14 }
15 }(function(Highcharts) {
16 (function(H) {
17 /**
18 * (c) 2009-2017 Torstein Honsi
19 *
20 * License: www.highcharts.com/license
21 */
22  
23 var defined = H.defined,
24 isNumber = H.isNumber,
25 inArray = H.inArray,
26 isArray = H.isArray,
27 merge = H.merge,
28 Chart = H.Chart,
29 extend = H.extend,
30 each = H.each;
31  
32 var ALIGN_FACTOR,
33 ALLOWED_SHAPES;
34  
35 ALLOWED_SHAPES = ['path', 'rect', 'circle'];
36  
37 ALIGN_FACTOR = {
38 top: 0,
39 left: 0,
40 center: 0.5,
41 middle: 0.5,
42 bottom: 1,
43 right: 1
44 };
45  
46 function defaultOptions(shapeType) {
47 var shapeOptions,
48 options;
49  
50 options = {
51 xAxis: 0,
52 yAxis: 0,
53 title: {
54 style: {},
55 text: '',
56 x: 0,
57 y: 0
58 },
59 shape: {
60 params: {
61 stroke: '#000000',
62 fill: 'transparent',
63 strokeWidth: 2
64 }
65 }
66 };
67  
68 shapeOptions = {
69 circle: {
70 params: {
71 x: 0,
72 y: 0
73 }
74 }
75 };
76  
77 if (shapeOptions[shapeType]) {
78 options.shape = merge(options.shape, shapeOptions[shapeType]);
79 }
80  
81 return options;
82 }
83  
84 function translatePath(d, xAxis, yAxis, xOffset, yOffset) {
85 var len = d.length,
86 i = 0;
87  
88 while (i < len) {
89 if (isNumber(d[i]) && isNumber(d[i + 1])) {
90 d[i] = xAxis.toPixels(d[i]) - xOffset;
91 d[i + 1] = yAxis.toPixels(d[i + 1]) - yOffset;
92 i += 2;
93 } else {
94 i += 1;
95 }
96 }
97  
98 return d;
99 }
100  
101  
102 // Define annotation prototype
103 var Annotation = function() {
104 this.init.apply(this, arguments);
105 };
106 Annotation.prototype = {
107 /*
108 * Initialize the annotation
109 */
110 init: function(chart, options) {
111 var shapeType = options.shape && options.shape.type;
112  
113 this.chart = chart;
114 this.options = merge({}, defaultOptions(shapeType), options);
115 },
116  
117 /*
118 * Render the annotation
119 */
120 render: function(redraw) {
121 var annotation = this,
122 chart = this.chart,
123 renderer = annotation.chart.renderer,
124 group = annotation.group,
125 title = annotation.title,
126 shape = annotation.shape,
127 options = annotation.options,
128 titleOptions = options.title,
129 shapeOptions = options.shape;
130  
131 if (!group) {
132 group = annotation.group = renderer.g();
133 }
134  
135  
136 if (!shape && shapeOptions && inArray(shapeOptions.type, ALLOWED_SHAPES) !== -1) {
137 shape = annotation.shape = renderer[options.shape.type](shapeOptions.params);
138 shape.add(group);
139 }
140  
141 if (!title && titleOptions) {
142 title = annotation.title = renderer.label(titleOptions);
143 title.add(group);
144 }
145  
146 group.add(chart.annotations.group);
147  
148 // link annotations to point or series
149 annotation.linkObjects();
150  
151 if (redraw !== false) {
152 annotation.redraw();
153 }
154 },
155  
156 /*
157 * Redraw the annotation title or shape after options update
158 */
159 redraw: function() {
160 var options = this.options,
161 chart = this.chart,
162 group = this.group,
163 title = this.title,
164 shape = this.shape,
165 linkedTo = this.linkedObject,
166 xAxis = chart.xAxis[options.xAxis],
167 yAxis = chart.yAxis[options.yAxis],
168 width = options.width,
169 height = options.height,
170 anchorY = ALIGN_FACTOR[options.anchorY],
171 anchorX = ALIGN_FACTOR[options.anchorX],
172 shapeParams,
173 linkType,
174 series,
175 bbox,
176 x,
177 y;
178  
179 if (linkedTo) {
180 linkType = (linkedTo instanceof H.Point) ? 'point' :
181 (linkedTo instanceof H.Series) ? 'series' : null;
182  
183 if (linkType === 'point') {
184 options.xValue = linkedTo.x;
185 options.yValue = linkedTo.y;
186 series = linkedTo.series;
187 } else if (linkType === 'series') {
188 series = linkedTo;
189 }
190  
191 if (group.visibility !== series.group.visibility) {
192 group.attr({
193 visibility: series.group.visibility
194 });
195 }
196 }
197  
198  
199 // Based on given options find annotation pixel position
200 x = (defined(options.xValue) ? xAxis.toPixels(options.xValue + xAxis.minPointOffset) - xAxis.minPixelPadding : options.x);
201 y = defined(options.yValue) ? yAxis.toPixels(options.yValue) : options.y;
202  
203 if (!isNumber(x) || !isNumber(y)) {
204 return;
205 }
206  
207  
208 if (title) {
209 title.attr(options.title);
210 title.css(options.title.style);
211 }
212  
213 if (shape) {
214 shapeParams = extend({}, options.shape.params);
215  
216 if (options.units === 'values') {
11 office 217 H.objectEach(shapeParams, function(val, param) {
1 office 218 if (inArray(param, ['width', 'x']) > -1) {
219 shapeParams[param] = xAxis.translate(shapeParams[param]);
220 } else if (inArray(param, ['height', 'y']) > -1) {
221 shapeParams[param] = yAxis.translate(shapeParams[param]);
222 }
11 office 223 });
1 office 224  
225 if (shapeParams.width) {
226 shapeParams.width -= xAxis.toPixels(0) - xAxis.left;
227 }
228  
229 if (shapeParams.x) {
230 shapeParams.x += xAxis.minPixelPadding;
231 }
232  
233 if (options.shape.type === 'path') {
234 translatePath(shapeParams.d, xAxis, yAxis, x, y);
235 }
236 }
237  
238 // move the center of the circle to shape x/y
239 if (options.shape.type === 'circle') {
240 shapeParams.x += shapeParams.r;
241 shapeParams.y += shapeParams.r;
242 }
243  
244 shape.attr(shapeParams);
245 }
246  
247 group.bBox = null;
248  
249 // If annotation width or height is not defined in options use bounding box size
250 if (!isNumber(width)) {
251 bbox = group.getBBox();
252 width = bbox.width;
253 }
254  
255 if (!isNumber(height)) {
256 // get bbox only if it wasn't set before
257 if (!bbox) {
258 bbox = group.getBBox();
259 }
260  
261 height = bbox.height;
262 }
263  
264 // Calculate anchor point
265 if (!isNumber(anchorX)) {
266 anchorX = ALIGN_FACTOR.center;
267 }
268  
269 if (!isNumber(anchorY)) {
270 anchorY = ALIGN_FACTOR.center;
271 }
272  
273 // Translate group according to its dimension and anchor point
274 x = x - width * anchorX;
275 y = y - height * anchorY;
276  
277 if (defined(group.translateX) && defined(group.translateY)) {
278 group.animate({
279 translateX: x,
280 translateY: y
281 });
282 } else {
283 group.translate(x, y);
284 }
285 },
286  
287 /*
288 * Destroy the annotation
289 */
290 destroy: function() {
291 var annotation = this,
292 chart = this.chart,
293 allItems = chart.annotations.allItems,
294 index = allItems.indexOf(annotation);
295  
296 if (index > -1) {
297 allItems.splice(index, 1);
298 }
299  
300 each(['title', 'shape', 'group'], function(element) {
301 if (annotation[element]) {
302 annotation[element].destroy();
303 annotation[element] = null;
304 }
305 });
306  
307 annotation.group = annotation.title = annotation.shape = annotation.chart = annotation.options = null;
308 },
309  
310 /*
311 * Update the annotation with a given options
312 */
313 update: function(options, redraw) {
314 extend(this.options, options);
315  
316 // update link to point or series
317 this.linkObjects();
318  
319 this.render(redraw);
320 },
321  
322 linkObjects: function() {
323 var annotation = this,
324 chart = annotation.chart,
325 linkedTo = annotation.linkedObject,
326 linkedId = linkedTo && (linkedTo.id || linkedTo.options.id),
327 options = annotation.options,
328 id = options.linkedTo;
329  
330 if (!defined(id)) {
331 annotation.linkedObject = null;
332 } else if (!defined(linkedTo) || id !== linkedId) {
333 annotation.linkedObject = chart.get(id);
334 }
335 }
336 };
337  
338  
339 // Add annotations methods to chart prototype
340 extend(Chart.prototype, {
341 annotations: {
342 /*
343 * Unified method for adding annotations to the chart
344 */
345 add: function(options, redraw) {
346 var annotations = this.allItems,
347 chart = this.chart,
348 item,
349 len;
350  
351 if (!isArray(options)) {
352 options = [options];
353 }
354  
355 len = options.length;
356  
357 while (len--) {
358 item = new Annotation(chart, options[len]);
359 annotations.push(item);
360 item.render(redraw);
361 }
362 },
363  
364 /**
365 * Redraw all annotations, method used in chart events
366 */
367 redraw: function() {
368 each(this.allItems, function(annotation) {
369 annotation.redraw();
370 });
371 }
372 }
373 });
374  
375  
376 // Initialize on chart load
377 Chart.prototype.callbacks.push(function(chart) {
378 var options = chart.options.annotations,
379 group;
380  
381 group = chart.renderer.g('annotations');
382 group.attr({
383 zIndex: 7
384 });
385 group.add();
386  
387 // initialize empty array for annotations
388 chart.annotations.allItems = [];
389  
390 // link chart object to annotations
391 chart.annotations.chart = chart;
392  
393 // link annotations group element to the chart
394 chart.annotations.group = group;
395  
396 if (isArray(options) && options.length > 0) {
397 chart.annotations.add(chart.options.annotations);
398 }
399  
400 // update annotations after chart redraw
401 H.addEvent(chart, 'redraw', function() {
402 chart.annotations.redraw();
403 });
404 });
405  
406 }(Highcharts));
407 }));