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