corrade-nucleus-nucleons – Blame information for rev 31

Subversion Repositories:
Rev:
Rev Author Line No. Line
31 office 1 /**
2 * @license Highcharts JS v5.0.14 (2017-07-28)
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 * Highcharts module to hide overlapping data labels. This module is included in
24 * Highcharts.
25 */
26 var Chart = H.Chart,
27 each = H.each,
28 objectEach = H.objectEach,
29 pick = H.pick,
30 addEvent = H.addEvent;
31  
32 // Collect potensial overlapping data labels. Stack labels probably don't need
33 // to be considered because they are usually accompanied by data labels that lie
34 // inside the columns.
35 Chart.prototype.callbacks.push(function(chart) {
36 function collectAndHide() {
37 var labels = [];
38  
39 each(chart.yAxis || [], function(yAxis) {
40 if (
41 yAxis.options.stackLabels &&
42 !yAxis.options.stackLabels.allowOverlap
43 ) {
44 objectEach(yAxis.stacks, function(stack) {
45 objectEach(stack, function(stackItem) {
46 labels.push(stackItem.label);
47 });
48 });
49 }
50 });
51  
52 each(chart.series || [], function(series) {
53 var dlOptions = series.options.dataLabels,
54 // Range series have two collections
55 collections = series.dataLabelCollections || ['dataLabel'];
56  
57 if (
58 (dlOptions.enabled || series._hasPointLabels) &&
59 !dlOptions.allowOverlap &&
60 series.visible
61 ) { // #3866
62 each(collections, function(coll) {
63 each(series.points, function(point) {
64 if (point[coll]) {
65 point[coll].labelrank = pick(
66 point.labelrank,
67 point.shapeArgs && point.shapeArgs.height
68 ); // #4118
69 labels.push(point[coll]);
70 }
71 });
72 });
73 }
74 });
75 chart.hideOverlappingLabels(labels);
76 }
77  
78 // Do it now ...
79 collectAndHide();
80  
81 // ... and after each chart redraw
82 addEvent(chart, 'redraw', collectAndHide);
83  
84 });
85  
86 /**
87 * Hide overlapping labels. Labels are moved and faded in and out on zoom to
88 * provide a smooth visual imression.
89 */
90 Chart.prototype.hideOverlappingLabels = function(labels) {
91  
92 var len = labels.length,
93 label,
94 i,
95 j,
96 label1,
97 label2,
98 isIntersecting,
99 pos1,
100 pos2,
101 parent1,
102 parent2,
103 padding,
104 bBox,
105 intersectRect = function(x1, y1, w1, h1, x2, y2, w2, h2) {
106 return !(
107 x2 > x1 + w1 ||
108 x2 + w2 < x1 ||
109 y2 > y1 + h1 ||
110 y2 + h2 < y1
111 );
112 };
113  
114 for (i = 0; i < len; i++) {
115 label = labels[i];
116 if (label) {
117  
118 // Mark with initial opacity
119 label.oldOpacity = label.opacity;
120 label.newOpacity = 1;
121  
122 // Get width and height if pure text nodes (stack labels)
123 if (!label.width) {
124 bBox = label.getBBox();
125 label.width = bBox.width;
126 label.height = bBox.height;
127 }
128 }
129 }
130  
131 // Prevent a situation in a gradually rising slope, that each label will
132 // hide the previous one because the previous one always has lower rank.
133 labels.sort(function(a, b) {
134 return (b.labelrank || 0) - (a.labelrank || 0);
135 });
136  
137 // Detect overlapping labels
138 for (i = 0; i < len; i++) {
139 label1 = labels[i];
140  
141 for (j = i + 1; j < len; ++j) {
142 label2 = labels[j];
143 if (
144 label1 && label2 &&
145 label1 !== label2 && // #6465, polar chart with connectEnds
146 label1.placed && label2.placed &&
147 label1.newOpacity !== 0 && label2.newOpacity !== 0
148 ) {
149 pos1 = label1.alignAttr;
150 pos2 = label2.alignAttr;
151 // Different panes have different positions
152 parent1 = label1.parentGroup;
153 parent2 = label2.parentGroup;
154 // Substract the padding if no background or border (#4333)
155 padding = 2 * (label1.box ? 0 : (label1.padding || 0));
156 isIntersecting = intersectRect(
157 pos1.x + parent1.translateX,
158 pos1.y + parent1.translateY,
159 label1.width - padding,
160 label1.height - padding,
161 pos2.x + parent2.translateX,
162 pos2.y + parent2.translateY,
163 label2.width - padding,
164 label2.height - padding
165 );
166  
167 if (isIntersecting) {
168 (label1.labelrank < label2.labelrank ? label1 : label2)
169 .newOpacity = 0;
170 }
171 }
172 }
173 }
174  
175 // Hide or show
176 each(labels, function(label) {
177 var complete,
178 newOpacity;
179  
180 if (label) {
181 newOpacity = label.newOpacity;
182  
183 if (label.oldOpacity !== newOpacity && label.placed) {
184  
185 // Make sure the label is completely hidden to avoid catching
186 // clicks (#4362)
187 if (newOpacity) {
188 label.show(true);
189 } else {
190 complete = function() {
191 label.hide();
192 };
193 }
194  
195 // Animate or set the opacity
196 label.alignAttr.opacity = newOpacity;
197 label[label.isOld ? 'animate' : 'attr'](
198 label.alignAttr,
199 null,
200 complete
201 );
202  
203 }
204 label.isOld = true;
205 }
206 });
207 };
208  
209 }(Highcharts));
210 }));