Pane.js
9.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/**
* (c) 2010-2018 Torstein Honsi
*
* License: www.highcharts.com/license
*/
'use strict';
import H from '../parts/Globals.js';
import '../mixins/centered-series.js';
import '../parts/Utilities.js';
var CenteredSeriesMixin = H.CenteredSeriesMixin,
each = H.each,
extend = H.extend,
merge = H.merge,
splat = H.splat;
/**
* The Pane object allows options that are common to a set of X and Y axes.
*
* In the future, this can be extended to basic Highcharts and Highstock.
*
*/
function Pane(options, chart) {
this.init(options, chart);
}
// Extend the Pane prototype
extend(Pane.prototype, {
coll: 'pane', // Member of chart.pane
/**
* Initiate the Pane object
*/
init: function (options, chart) {
this.chart = chart;
this.background = [];
chart.pane.push(this);
this.setOptions(options);
},
setOptions: function (options) {
// Set options. Angular charts have a default background (#3318)
this.options = options = merge(
this.defaultOptions,
this.chart.angular ? { background: {} } : undefined,
options
);
},
/**
* Render the pane with its backgrounds.
*/
render: function () {
var options = this.options,
backgroundOption = this.options.background,
renderer = this.chart.renderer,
len,
i;
if (!this.group) {
this.group = renderer.g('pane-group')
.attr({ zIndex: options.zIndex || 0 })
.add();
}
this.updateCenter();
// Render the backgrounds
if (backgroundOption) {
backgroundOption = splat(backgroundOption);
len = Math.max(
backgroundOption.length,
this.background.length || 0
);
for (i = 0; i < len; i++) {
// #6641 - if axis exists, chart is circular and apply
// background
if (backgroundOption[i] && this.axis) {
this.renderBackground(
merge(
this.defaultBackgroundOptions,
backgroundOption[i]
),
i
);
} else if (this.background[i]) {
this.background[i] = this.background[i].destroy();
this.background.splice(i, 1);
}
}
}
},
/**
* Render an individual pane background.
* @param {Object} backgroundOptions Background options
* @param {number} i The index of the background in this.backgrounds
*/
renderBackground: function (backgroundOptions, i) {
var method = 'animate';
if (!this.background[i]) {
this.background[i] = this.chart.renderer.path()
.add(this.group);
method = 'attr';
}
this.background[i][method]({
'd': this.axis.getPlotBandPath(
backgroundOptions.from,
backgroundOptions.to,
backgroundOptions
)
}).attr({
'fill': backgroundOptions.backgroundColor,
'stroke': backgroundOptions.borderColor,
'stroke-width': backgroundOptions.borderWidth,
'class': 'highcharts-pane ' + (backgroundOptions.className || '')
});
},
/**
* The pane serves as a container for axes and backgrounds for circular
* gauges and polar charts.
* @since 2.3.0
* @product highcharts
* @optionparent pane
*/
defaultOptions: {
/**
* The end angle of the polar X axis or gauge value axis, given in
* degrees where 0 is north. Defaults to [startAngle](#pane.startAngle)
* + 360.
*
* @type {Number}
* @sample {highcharts} highcharts/demo/gauge-vu-meter/
* VU-meter with custom start and end angle
* @since 2.3.0
* @product highcharts
* @apioption pane.endAngle
*/
/**
* The center of a polar chart or angular gauge, given as an array
* of [x, y] positions. Positions can be given as integers that
* transform to pixels, or as percentages of the plot area size.
*
* @type {Array<String|Number>}
* @sample {highcharts} highcharts/demo/gauge-vu-meter/
* Two gauges with different center
* @default ["50%", "50%"]
* @since 2.3.0
* @product highcharts
*/
center: ['50%', '50%'],
/**
* The size of the pane, either as a number defining pixels, or a
* percentage defining a percentage of the plot are.
*
* @type {Number|String}
* @sample {highcharts} highcharts/demo/gauge-vu-meter/ Smaller size
* @default 85%
* @product highcharts
*/
size: '85%',
/**
* The start angle of the polar X axis or gauge axis, given in degrees
* where 0 is north. Defaults to 0.
*
* @type {Number}
* @sample {highcharts} highcharts/demo/gauge-vu-meter/
* VU-meter with custom start and end angle
* @since 2.3.0
* @product highcharts
*/
startAngle: 0
},
/**
* An array of background items for the pane.
* @type {Array<Object>}
* @sample {highcharts} highcharts/demo/gauge-speedometer/
* Speedometer gauge with multiple backgrounds
* @optionparent pane.background
*/
defaultBackgroundOptions: {
/**
* The class name for this background.
*
* @type {String}
* @sample {highcharts} highcharts/css/pane/ Panes styled by CSS
* @sample {highstock} highcharts/css/pane/ Panes styled by CSS
* @sample {highmaps} highcharts/css/pane/ Panes styled by CSS
* @default highcharts-pane
* @since 5.0.0
* @apioption pane.background.className
*/
/**
* The shape of the pane background. When `solid`, the background
* is circular. When `arc`, the background extends only from the min
* to the max of the value axis.
*
* @validvalue ["solid", "arc"]
* @type {String}
* @default solid
* @since 2.3.0
* @product highcharts
*/
shape: 'circle',
/**
* The pixel border width of the pane background.
*
* @type {Number}
* @default 1
* @since 2.3.0
* @product highcharts
*/
borderWidth: 1,
/**
* The pane background border color.
*
* @type {Color}
* @default #cccccc
* @since 2.3.0
* @product highcharts
*/
borderColor: '#cccccc',
/**
* The background color or gradient for the pane.
*
* @type {Color}
* @since 2.3.0
* @product highcharts
*/
backgroundColor: {
/**
* Definition of the gradient, similar to SVG: object literal holds
* start position (x1, y1) and the end position (x2, y2) relative
* to the shape, where 0 means top/left and 1 is bottom/right.
* All positions are floats between 0 and 1.
*
* @type {Object}
*/
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
/**
* The stops is an array of tuples, where the first item is a float
* between 0 and 1 assigning the relative position in the gradient,
* and the second item is the color.
*
* @default [[0, #ffffff], [1, #e6e6e6]]
* @type {Array<Array>}
*/
stops: [
[0, '#ffffff'],
[1, '#e6e6e6']
]
},
/** @ignore-option */
from: -Number.MAX_VALUE, // corrected to axis min
/**
* The inner radius of the pane background. Can be either numeric
* (pixels) or a percentage string.
*
* @type {Number|String}
* @default 0
* @since 2.3.0
* @product highcharts
*/
innerRadius: 0,
/** @ignore-option */
to: Number.MAX_VALUE, // corrected to axis max
/**
* The outer radius of the circular pane background. Can be either
* numeric (pixels) or a percentage string.
*
* @type {Number|String}
* @default 105%
* @since 2.3.0
* @product highcharts
*/
outerRadius: '105%'
},
/**
* Gets the center for the pane and its axis.
*/
updateCenter: function (axis) {
this.center = (axis || this.axis || {}).center =
CenteredSeriesMixin.getCenter.call(this);
},
/**
* Destroy the pane item
* /
destroy: function () {
H.erase(this.chart.pane, this);
each(this.background, function (background) {
background.destroy();
});
this.background.length = 0;
this.group = this.group.destroy();
},
*/
/**
* Update the pane item with new options
* @param {Object} options New pane options
*/
update: function (options, redraw) {
merge(true, this.options, options);
this.setOptions(this.options);
this.render();
each(this.chart.axes, function (axis) {
if (axis.pane === this) {
axis.pane = null;
axis.update({}, redraw);
}
}, this);
}
});
H.Pane = Pane;