Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
9 lars 1
/**
2
 * @license Highcharts JS v4.1.8 (2015-08-20)
3
 *
4
 * (c) 2014 Highsoft AS
5
 * Authors: Jon Arild Nygard / Oystein Moseng
6
 *
7
 * License: www.highcharts.com/license
8
 */
9
 
10
/*global HighchartsAdapter */
11
(function (H) {
12
	var seriesTypes = H.seriesTypes,
13
		merge = H.merge,
14
		extend = H.extend,
15
		extendClass = H.extendClass,
16
		defaultOptions = H.getOptions(),
17
		plotOptions = defaultOptions.plotOptions,
18
		noop = function () { return; },
19
		each = H.each,
20
		grep = HighchartsAdapter.grep,
21
		pick = H.pick,
22
		Series = H.Series,
23
		Color = H.Color;
24
 
25
	// Define default options
26
	plotOptions.treemap = merge(plotOptions.scatter, {
27
		showInLegend: false,
28
		marker: false,
29
		borderColor: '#E0E0E0',
30
		borderWidth: 1,
31
		dataLabels: {
32
			enabled: true,
33
			defer: false,
34
			verticalAlign: 'middle',
35
			formatter: function () { // #2945
36
				return this.point.name || this.point.id;
37
			},
38
			inside: true
39
		},
40
		tooltip: {
41
			headerFormat: '',
42
			pointFormat: '<b>{point.name}</b>: {point.node.val}</b><br/>'
43
		},
44
		layoutAlgorithm: 'sliceAndDice',
45
		layoutStartingDirection: 'vertical',
46
		alternateStartingDirection: false,
47
		levelIsConstant: true,
48
		states: {
49
			hover: {
50
				borderColor: '#A0A0A0',
51
				brightness: seriesTypes.heatmap ? 0 : 0.1,
52
				shadow: false
53
			}
54
		},
55
		drillUpButton: {
56
			position: {
57
				align: 'left',
58
				x: 10,
59
				y: -50
60
			}
61
		}
62
	});
63
 
64
	// Stolen from heatmap
65
	var colorSeriesMixin = {
66
		// mapping between SVG attributes and the corresponding options
67
		pointAttrToOptions: {
68
			stroke: 'borderColor',
69
			'stroke-width': 'borderWidth',
70
			fill: 'color',
71
			dashstyle: 'borderDashStyle'
72
		},
73
		pointArrayMap: ['value'],
74
		axisTypes: seriesTypes.heatmap ? ['xAxis', 'yAxis', 'colorAxis'] : ['xAxis', 'yAxis'],
75
		optionalAxis: 'colorAxis',
76
		getSymbol: noop,
77
		parallelArrays: ['x', 'y', 'value', 'colorValue'],
78
		colorKey: 'colorValue', // Point color option key
79
		translateColors: seriesTypes.heatmap && seriesTypes.heatmap.prototype.translateColors
80
	};
81
 
82
	// The Treemap series type
83
	seriesTypes.treemap = extendClass(seriesTypes.scatter, merge(colorSeriesMixin, {
84
		type: 'treemap',
85
		trackerGroups: ['group', 'dataLabelsGroup'],
86
		pointClass: extendClass(H.Point, {
87
			setState: function (state, move) {
88
				H.Point.prototype.setState.call(this, state, move);
89
				if (state === 'hover') {
90
					if (this.dataLabel) {
91
						this.dataLabel.attr({ zIndex: 1002 });
92
					}
93
				} else {
94
					if (this.dataLabel) {
95
						this.dataLabel.attr({ zIndex: (this.pointAttr[''].zIndex + 1) });
96
					}
97
				}
98
			},
99
			setVisible: seriesTypes.pie.prototype.pointClass.prototype.setVisible
100
		}),
101
		// @todo Move to translate
102
		handleLayout: function () {
103
			var tree = this.tree,
104
				seriesArea;
105
			if (this.points.length) {
106
				// Assign variables
107
				this.rootNode = pick(this.rootNode, "");
108
				tree = this.tree = this.getTree();
109
				this.levelMap = this.getLevels();
110
				seriesArea = this.getSeriesArea(tree.val);
111
				this.calculateChildrenAreas(tree, seriesArea);
112
				this.setPointValues();
113
			}
114
		},
115
		/**
116
		* Creates a tree structured object from the series points
117
		*/
118
		getTree: function () {
119
			var tree,
120
				series = this,
121
				parentList = [],
122
				allIds = [],
123
				key,
124
				insertItem = function (key) {
125
					each(parentList[key], function (item) {
126
						parentList[""].push(item);
127
					});
128
				};
129
			// Actions
130
			this.nodeMap = [];
131
 
132
			// Map children to index
133
			// @todo Use data instead of points
134
			each(this.points, function (point, index) {
135
				var parent = "";
136
				allIds.push(point.id);
137
				if (point.parent !== undefined) {
138
					parent = point.parent;
139
				}
140
				if (parentList[parent] === undefined) {
141
					parentList[parent] = [];
142
				}
143
				parentList[parent].push(index);
144
			});
145
			/*
146
			*  Quality check:
147
			*  - If parent does not exist, then set parent to tree root
148
			*  - Add node id to parents children list
149
			*/
150
			for (key in parentList) {
151
				if ((parentList.hasOwnProperty(key)) && (key !== "") && (HighchartsAdapter.inArray(key, allIds) === -1)) {
152
					insertItem(key);
153
					delete parentList[key];
154
				}
155
			}
156
			tree = series.buildNode("", -1, 0, parentList, null);
157
			this.eachParents(this.nodeMap[this.rootNode], function (node) {
158
				node.visible = true;
159
			});
160
			this.eachChildren(this.nodeMap[this.rootNode], function (node) {
161
				node.visible = true;
162
			});
163
			this.setTreeValues(tree);
164
			return tree;
165
		},
166
		buildNode: function (id, i, level, list, parent) {
167
			var series = this,
168
				children = [],
169
				point = series.points[i],
170
				node,
171
				child;
172
 
173
			// Actions
174
			each((list[id] || []), function (i) {
175
				child = series.buildNode(series.points[i].id, i, (level + 1), list, id);
176
				children.push(child);
177
			});
178
			node = {
179
				id: id,
180
				i: i,
181
				children: children,
182
				level: level,
183
				parent: parent,
184
				visible: false // @todo move this to better location
185
			};
186
			series.nodeMap[node.id] = node;
187
			if (point) {
188
				point.node = node;
189
			}
190
			return node;
191
		},
192
		setTreeValues: function (tree) {
193
			var series = this,
194
				childrenTotal = 0,
195
				sorted = [],
196
				val,
197
				point = series.points[tree.i];
198
 
199
			// First give the children some values
200
			each(tree.children, function (child) {
201
				child = series.setTreeValues(child);
202
				series.insertElementSorted(sorted, child, function (el, el2) {
203
					return el.val > el2.val;
204
				});
205
 
206
				if (!child.ignore) {
207
					childrenTotal += child.val;
208
				} else {
209
					// @todo Add predicate to avoid looping already ignored children
210
					series.eachChildren(child, function (node) {
211
						extend(node, {
212
							ignore: true,
213
							isLeaf: false,
214
							visible: false
215
						});
216
					});
217
				}
218
			});
219
 
220
			// Set the values
221
			val = pick(point && point.value, childrenTotal);
222
			extend(tree, {
223
				children: sorted,
224
				childrenTotal: childrenTotal,
225
				// Ignore this node if point is not visible
226
				ignore: !(pick(point && point.visible, true) && (val > 0)),
227
				isLeaf: tree.visible && !childrenTotal,
228
				name: pick(point && point.name, ""),
229
				val: val
230
			});
231
			return tree;
232
		},
233
		eachChildren: function (node, callback) {
234
			var series = this,
235
				children = node.children;
236
			callback(node);
237
			if (children.length) {
238
				each(children, function (child) {
239
					series.eachChildren(child, callback);
240
				});
241
			}
242
		},
243
		eachParents: function (node, callback) {
244
			var parent = this.nodeMap[node.parent];
245
			callback(node);
246
			if (parent) {
247
				this.eachParents(parent, callback);
248
			}
249
		},
250
		/**
251
		 * Recursive function which calculates the area for all children of a node.
252
		 * @param {Object} node The node which is parent to the children.
253
		 * @param {Object} area The rectangular area of the parent.
254
		 */
255
		calculateChildrenAreas: function (parent, area) {
256
			var series = this,
257
				options = series.options,
258
				levelNumber = (options.levelIsConstant ? parent.level : (parent.level - this.nodeMap[this.rootNode].level)),
259
				level = this.levelMap[levelNumber + 1],
260
				algorithm = pick((series[level && level.layoutAlgorithm] && level.layoutAlgorithm), options.layoutAlgorithm),
261
				alternate = options.alternateStartingDirection,
262
				childrenValues = [],
263
				children,
264
				point;
265
 
266
			// Collect all children which should be included
267
			children = grep(parent.children, function (n) {
268
				return !n.ignore;
269
			});
270
 
271
			if (level && level.layoutStartingDirection) {
272
				area.direction = level.layoutStartingDirection === 'vertical' ? 0 : 1;
273
			}
274
			childrenValues = series[algorithm](area, children);
275
			each(children, function (child, index) {
276
				point = series.points[child.i];
277
				point.level = levelNumber + 1;
278
				child.values = merge(childrenValues[index], {
279
					val: child.childrenTotal,
280
					direction: (alternate ? 1 - area.direction : area.direction)
281
				});
282
				// If node has children, then call method recursively
283
				if (child.children.length) {
284
					series.calculateChildrenAreas(child, child.values);
285
				}
286
			});
287
		},
288
		setPointValues: function () {
289
			var series = this,
290
				xAxis = series.xAxis,
291
				yAxis = series.yAxis;
292
			series.nodeMap[""].values = {
293
				x: 0,
294
				y: 0,
295
				width: 100,
296
				height: 100
297
			};
298
			each(series.points, function (point) {
299
				var node = point.node,
300
					values = node.values,
301
					x1,
302
					x2,
303
					y1,
304
					y2;
305
				// Points which is ignored, have no values.
306
				if (values) {
307
					values.x = values.x / series.axisRatio;
308
					values.width = values.width / series.axisRatio;
309
					x1 = Math.round(xAxis.translate(values.x, 0, 0, 0, 1));
310
					x2 = Math.round(xAxis.translate(values.x + values.width, 0, 0, 0, 1));
311
					y1 = Math.round(yAxis.translate(values.y, 0, 0, 0, 1));
312
					y2 = Math.round(yAxis.translate(values.y + values.height, 0, 0, 0, 1));
313
					// Set point values
314
					point.shapeType = 'rect';
315
					point.shapeArgs = {
316
						x: Math.min(x1, x2),
317
						y: Math.min(y1, y2),
318
						width: Math.abs(x2 - x1),
319
						height: Math.abs(y2 - y1)
320
					};
321
					point.plotX = point.shapeArgs.x + (point.shapeArgs.width / 2);
322
					point.plotY = point.shapeArgs.y + (point.shapeArgs.height / 2);
323
				} else {
324
					// Reset visibility
325
					delete point.plotX;
326
					delete point.plotY;
327
				}
328
			});
329
		},
330
		getSeriesArea: function (val) {
331
			var x = 0,
332
				y = 0,
333
				h = 100,
334
				r = this.axisRatio = (this.xAxis.len / this.yAxis.len),
335
				w = 100 * r,
336
				d = this.options.layoutStartingDirection === 'vertical' ? 0 : 1,
337
				seriesArea = {
338
					x: x,
339
					y: y,
340
					width: w,
341
					height: h,
342
					direction: d,
343
					val: val
344
				};
345
				this.nodeMap[""].values = seriesArea;
346
			return seriesArea;
347
		},
348
		getLevels: function () {
349
			var map = [],
350
				levels = this.options.levels;
351
			if (levels) {
352
				each(levels, function (level) {
353
					if (level.level !== undefined) {
354
						map[level.level] = level;
355
					}
356
				});
357
			}
358
			return map;
359
		},
360
		setColorRecursive: function (node, color) {
361
			var series = this,
362
				point,
363
				level;
364
			if (node) {
365
				point = series.points[node.i];
366
				level = series.levelMap[node.level];
367
				// Select either point color, level color or inherited color.
368
				color = pick(point && point.options.color, level && level.color, color);
369
				if (point) {
370
					point.color = color;
371
				}
372
				// Do it all again with the children
373
				if (node.children.length) {
374
					each(node.children, function (child) {
375
						series.setColorRecursive(child, color);
376
					});
377
				}
378
			}
379
		},
380
		alg_func_group: function (h, w, d, p) {
381
			this.height = h;
382
			this.width = w;
383
			this.plot = p;
384
			this.direction = d;
385
			this.startDirection = d;
386
			this.total = 0;
387
			this.nW = 0;
388
			this.lW = 0;
389
			this.nH = 0;
390
			this.lH = 0;
391
			this.elArr = [];
392
			this.lP = {
393
				total: 0,
394
				lH: 0,
395
				nH: 0,
396
				lW: 0,
397
				nW: 0,
398
				nR: 0,
399
				lR: 0,
400
				aspectRatio: function (w, h) {
401
					return Math.max((w / h), (h / w));
402
				}
403
			};
404
			this.addElement = function (el) {
405
				this.lP.total = this.elArr[this.elArr.length - 1];
406
				this.total = this.total + el;
407
				if (this.direction === 0) {
408
					// Calculate last point old aspect ratio
409
					this.lW = this.nW;
410
					this.lP.lH = this.lP.total / this.lW;
411
					this.lP.lR = this.lP.aspectRatio(this.lW, this.lP.lH);
412
					// Calculate last point new aspect ratio
413
					this.nW = this.total / this.height;
414
					this.lP.nH = this.lP.total / this.nW;
415
					this.lP.nR = this.lP.aspectRatio(this.nW, this.lP.nH);
416
				} else {
417
					// Calculate last point old aspect ratio
418
					this.lH = this.nH;
419
					this.lP.lW = this.lP.total / this.lH;
420
					this.lP.lR = this.lP.aspectRatio(this.lP.lW, this.lH);
421
					// Calculate last point new aspect ratio
422
					this.nH = this.total / this.width;
423
					this.lP.nW = this.lP.total / this.nH;
424
					this.lP.nR = this.lP.aspectRatio(this.lP.nW, this.nH);
425
				}
426
				this.elArr.push(el);
427
			};
428
			this.reset = function () {
429
				this.nW = 0;
430
				this.lW = 0;
431
				this.elArr = [];
432
				this.total = 0;
433
			};
434
		},
435
		alg_func_calcPoints: function (directionChange, last, group, childrenArea) {
436
			var pX,
437
				pY,
438
				pW,
439
				pH,
440
				gW = group.lW,
441
				gH = group.lH,
442
				plot = group.plot,
443
				keep,
444
				i = 0,
445
				end = group.elArr.length - 1;
446
			if (last) {
447
				gW = group.nW;
448
				gH = group.nH;
449
			} else {
450
				keep = group.elArr[group.elArr.length - 1];
451
			}
452
			each(group.elArr, function (p) {
453
				if (last || (i < end)) {
454
					if (group.direction === 0) {
455
						pX = plot.x;
456
						pY = plot.y;
457
						pW = gW;
458
						pH = p / pW;
459
					} else {
460
						pX = plot.x;
461
						pY = plot.y;
462
						pH = gH;
463
						pW = p / pH;
464
					}
465
					childrenArea.push({
466
						x: pX,
467
						y: pY,
468
						width: pW,
469
						height: pH
470
					});
471
					if (group.direction === 0) {
472
						plot.y = plot.y + pH;
473
					} else {
474
						plot.x = plot.x + pW;
475
					}
476
				}
477
				i = i + 1;
478
			});
479
			// Reset variables
480
			group.reset();
481
			if (group.direction === 0) {
482
				group.width = group.width - gW;
483
			} else {
484
				group.height = group.height - gH;
485
			}
486
			plot.y = plot.parent.y + (plot.parent.height - group.height);
487
			plot.x = plot.parent.x + (plot.parent.width - group.width);
488
			if (directionChange) {
489
				group.direction = 1 - group.direction;
490
			}
491
			// If not last, then add uncalculated element
492
			if (!last) {
493
				group.addElement(keep);
494
			}
495
		},
496
		alg_func_lowAspectRatio: function (directionChange, parent, children) {
497
			var childrenArea = [],
498
				series = this,
499
				pTot,
500
				plot = {
501
					x: parent.x,
502
					y: parent.y,
503
					parent: parent
504
				},
505
				direction = parent.direction,
506
				i = 0,
507
				end = children.length - 1,
508
				group = new this.alg_func_group(parent.height, parent.width, direction, plot);
509
			// Loop through and calculate all areas
510
			each(children, function (child) {
511
				pTot = (parent.width * parent.height) * (child.val / parent.val);
512
				group.addElement(pTot);
513
				if (group.lP.nR > group.lP.lR) {
514
					series.alg_func_calcPoints(directionChange, false, group, childrenArea, plot);
515
				}
516
				// If last child, then calculate all remaining areas
517
				if (i === end) {
518
					series.alg_func_calcPoints(directionChange, true, group, childrenArea, plot);
519
				}
520
				i = i + 1;
521
			});
522
			return childrenArea;
523
		},
524
		alg_func_fill: function (directionChange, parent, children) {
525
			var childrenArea = [],
526
				pTot,
527
				direction = parent.direction,
528
				x = parent.x,
529
				y = parent.y,
530
				width = parent.width,
531
				height = parent.height,
532
				pX,
533
				pY,
534
				pW,
535
				pH;
536
			each(children, function (child) {
537
				pTot = (parent.width * parent.height) * (child.val / parent.val);
538
				pX = x;
539
				pY = y;
540
				if (direction === 0) {
541
					pH = height;
542
					pW = pTot / pH;
543
					width = width - pW;
544
					x = x + pW;
545
				} else {
546
					pW = width;
547
					pH = pTot / pW;
548
					height = height - pH;
549
					y = y + pH;
550
				}
551
				childrenArea.push({
552
					x: pX,
553
					y: pY,
554
					width: pW,
555
					height: pH
556
				});
557
				if (directionChange) {
558
					direction = 1 - direction;
559
				}
560
			});
561
			return childrenArea;
562
		},
563
		strip: function (parent, children) {
564
			return this.alg_func_lowAspectRatio(false, parent, children);
565
		},
566
		squarified: function (parent, children) {
567
			return this.alg_func_lowAspectRatio(true, parent, children);
568
		},
569
		sliceAndDice: function (parent, children) {
570
			return this.alg_func_fill(true, parent, children);
571
		},
572
		stripes: function (parent, children) {
573
			return this.alg_func_fill(false, parent, children);
574
		},
575
		translate: function () {
576
			// Call prototype function
577
			Series.prototype.translate.call(this);
578
			this.handleLayout();
579
 
580
			// If a colorAxis is defined
581
			if (this.colorAxis) {
582
				this.translateColors();
583
			} else if (!this.options.colorByPoint) {
584
				this.setColorRecursive(this.tree, undefined);
585
			}
586
		},
587
		/**
588
		 * Extend drawDataLabels with logic to handle custom options related to the treemap series:
589
		 * - Points which is not a leaf node, has dataLabels disabled by default.
590
		 * - Options set on series.levels is merged in.
591
		 * - Width of the dataLabel is set to match the width of the point shape.
592
		 */
593
		drawDataLabels: function () {
594
			var series = this,
595
				dataLabelsGroup = series.dataLabelsGroup,
596
				points = series.points,
597
				options,
598
				level;
599
			each(points, function (point) {
600
				level = series.levelMap[point.level];
601
				// Set options to new object to avoid problems with scope
602
				options = {style: {}};
603
 
604
				// If not a leaf, then label should be disabled as default
605
				if (!point.node.isLeaf) {
606
					options.enabled = false;
607
				}
608
 
609
				// If options for level exists, include them as well
610
				if (level && level.dataLabels) {
611
					options = merge(options, level.dataLabels);
612
					series._hasPointLabels = true;
613
				}
614
 
615
				// Set dataLabel width to the width of the point shape.
616
				if (point.shapeArgs) {
617
					options.style.width = point.shapeArgs.width;
618
				}
619
 
620
				// Merge custom options with point options
621
				point.dlOptions = merge(options, point.options.dataLabels);
622
			});
623
 
624
			this.dataLabelsGroup = this.group; // Draw dataLabels in same group as points, because of z-index on hover
625
			Series.prototype.drawDataLabels.call(this);
626
			this.dataLabelsGroup = dataLabelsGroup;
627
		},
628
		alignDataLabel: seriesTypes.column.prototype.alignDataLabel,
629
		/**
630
		* Extending ColumnSeries drawPoints
631
		*/
632
		drawPoints: function () {
633
			var series = this,
634
				points = series.points,
635
				seriesOptions = series.options,
636
				attr,
637
				hover,
638
				level;
639
			each(points, function (point) {
640
				level = series.levelMap[point.level];
641
				attr = {
642
					stroke: seriesOptions.borderColor,
643
					'stroke-width': seriesOptions.borderWidth,
644
					dashstyle: seriesOptions.borderDashStyle,
645
					r: 0, // borderRadius gives wrong size relations and should always be disabled
646
					fill: pick(point.color, series.color)
647
				};
648
				// Overwrite standard series options with level options
649
				if (level) {
650
					attr.stroke = level.borderColor || attr.stroke;
651
					attr['stroke-width'] = level.borderWidth || attr['stroke-width'];
652
					attr.dashstyle = level.borderDashStyle || attr.dashstyle;
653
				}
654
				// Merge with point attributes
655
				attr.stroke = point.borderColor || attr.stroke;
656
				attr['stroke-width'] = point.borderWidth || attr['stroke-width'];
657
				attr.dashstyle = point.borderDashStyle || attr.dashstyle;
658
				attr.zIndex = (1000 - (point.level * 2));
659
 
660
				// Make a copy to prevent overwriting individual props
661
				point.pointAttr = merge(point.pointAttr);
662
				hover = point.pointAttr.hover;
663
				hover.zIndex = 1001;
664
				hover.fill = Color(attr.fill).brighten(seriesOptions.states.hover.brightness).get();
665
				// If not a leaf, then remove fill
666
				if (!point.node.isLeaf) {
667
					if (pick(seriesOptions.interactByLeaf, !seriesOptions.allowDrillToNode)) {
668
						attr.fill = 'none';
669
						delete hover.fill;
670
					} else {
671
						// TODO: let users set the opacity
672
						attr.fill = Color(attr.fill).setOpacity(0.15).get();
673
						hover.fill = Color(hover.fill).setOpacity(0.75).get();
674
					}
675
				}
676
				if (point.node.level <= series.nodeMap[series.rootNode].level) {
677
					attr.fill = 'none';
678
					attr.zIndex = 0;
679
					delete hover.fill;
680
				}
681
				point.pointAttr[''] = H.extend(point.pointAttr[''], attr);
682
				// @todo Move this to drawDataLabels
683
				if (point.dataLabel) {
684
					point.dataLabel.attr({ zIndex: (point.pointAttr[''].zIndex + 1) });
685
				}
686
			});
687
			// Call standard drawPoints
688
			seriesTypes.column.prototype.drawPoints.call(this);
689
 
690
			each(points, function (point) {
691
				if (point.graphic) {
692
					point.graphic.attr(point.pointAttr['']);
693
				}
694
			});
695
 
696
			// Set click events on points
697
			if (seriesOptions.allowDrillToNode) {
698
				series.drillTo();
699
			}
700
		},
701
		/**
702
		 * Inserts an element into an array, sorted by a condition.
703
		 * Modifies the referenced array
704
		 * @param {*[]} arr The array which the element is inserted into.
705
		 * @param {*} el The element to insert.
706
		 * @param {function} cond The condition to sort on. First parameter is el, second parameter is array element
707
		 */
708
		insertElementSorted: function (arr, el, cond) {
709
			var i = 0,
710
				inserted = false;
711
			if (arr.length !== 0) {
712
				each(arr, function (arrayElement) {
713
					if (cond(el, arrayElement) && !inserted) {
714
						arr.splice(i, 0, el);
715
						inserted = true;
716
					}
717
					i = i + 1;
718
				});
719
			}
720
			if (!inserted) {
721
				arr.push(el);
722
			}
723
		},
724
		/**
725
		* Add drilling on the suitable points
726
		*/
727
		drillTo: function () {
728
			var series = this,
729
				points = series.points;
730
			each(points, function (point) {
731
				var drillId,
732
					drillName;
733
				H.removeEvent(point, 'click.drillTo');
734
				if (point.graphic) {
735
					point.graphic.css({ cursor: 'default' });
736
				}
737
 
738
				// Get the drill to id
739
				if (series.options.interactByLeaf) {
740
					drillId = series.drillToByLeaf(point);
741
				} else {
742
					drillId = series.drillToByGroup(point);
743
				}
744
 
745
				// If a drill id is returned, add click event and cursor.
746
				if (drillId) {
747
					drillName = series.nodeMap[series.rootNode].name || series.rootNode;
748
					if (point.graphic) {
749
						point.graphic.css({ cursor: 'pointer' });
750
					}
751
					H.addEvent(point, 'click.drillTo', function () {
752
						point.setState(''); // Remove hover
753
						series.drillToNode(drillId);
754
						series.showDrillUpButton(drillName);
755
					});
756
				}
757
			});
758
		},
759
		/**
760
		* Finds the drill id for a parent node.
761
		* Returns false if point should not have a click event
762
		* @param {Object} point
763
		* @return {string || boolean} Drill to id or false when point should not have a click event
764
		*/
765
		drillToByGroup: function (point) {
766
			var series = this,
767
				drillId = false;
768
			if ((point.node.level - series.nodeMap[series.rootNode].level) === 1 && !point.node.isLeaf) {
769
				drillId = point.id;
770
			}
771
			return drillId;
772
		},
773
		/**
774
		* Finds the drill id for a leaf node.
775
		* Returns false if point should not have a click event
776
		* @param {Object} point
777
		* @return {string || boolean} Drill to id or false when point should not have a click event
778
		*/
779
		drillToByLeaf: function (point) {
780
			var series = this,
781
				drillId = false,
782
				nodeParent;
783
			if ((point.node.parent !== series.rootNode) && (point.node.isLeaf)) {
784
				nodeParent = point.node;
785
				while (!drillId) {
786
					nodeParent = series.nodeMap[nodeParent.parent];
787
					if (nodeParent.parent === series.rootNode) {
788
						drillId = nodeParent.id;
789
					}
790
				}
791
			}
792
			return drillId;
793
		},
794
		drillUp: function () {
795
			var drillPoint = null,
796
				node,
797
				parent;
798
			if (this.rootNode) {
799
				node = this.nodeMap[this.rootNode];
800
				if (node.parent !== null) {
801
					drillPoint = this.nodeMap[node.parent];
802
				} else {
803
					drillPoint = this.nodeMap[""];
804
				}
805
			}
806
 
807
			if (drillPoint !== null) {
808
				this.drillToNode(drillPoint.id);
809
				if (drillPoint.id === "") {
810
					this.drillUpButton = this.drillUpButton.destroy();
811
				} else {
812
					parent = this.nodeMap[drillPoint.parent];
813
					this.showDrillUpButton((parent.name || parent.id));
814
				}
815
			}
816
		},
817
		drillToNode: function (id) {
818
			var node = this.nodeMap[id],
819
				val = node.values;
820
			this.rootNode = id;
821
			this.xAxis.setExtremes(val.x, val.x + val.width, false);
822
			this.yAxis.setExtremes(val.y, val.y + val.height, false);
823
			this.isDirty = true; // Force redraw
824
			this.chart.redraw();
825
		},
826
		showDrillUpButton: function (name) {
827
			var series = this,
828
				backText = (name || '< Back'),
829
				buttonOptions = series.options.drillUpButton,
830
				attr,
831
				states;
832
 
833
			if (buttonOptions.text) {
834
				backText = buttonOptions.text;
835
			}
836
			if (!this.drillUpButton) {
837
				attr = buttonOptions.theme;
838
				states = attr && attr.states;
839
 
840
				this.drillUpButton = this.chart.renderer.button(
841
					backText,
842
					null,
843
					null,
844
					function () {
845
						series.drillUp();
846
					},
847
					attr,
848
					states && states.hover,
849
					states && states.select
850
				)
851
				.attr({
852
					align: buttonOptions.position.align,
853
					zIndex: 9
854
				})
855
				.add()
856
				.align(buttonOptions.position, false, buttonOptions.relativeTo || 'plotBox');
857
			} else {
858
				this.drillUpButton.attr({
859
					text: backText
860
				})
861
				.align();
862
			}
863
		},
864
		buildKDTree: noop,
865
		drawLegendSymbol: H.LegendSymbolMixin.drawRectangle,
866
		getExtremes: function () {
867
			// Get the extremes from the value data
868
			Series.prototype.getExtremes.call(this, this.colorValueData);
869
			this.valueMin = this.dataMin;
870
			this.valueMax = this.dataMax;
871
 
872
			// Get the extremes from the y data
873
			Series.prototype.getExtremes.call(this);
874
		},
875
		getExtremesFromAll: true,
876
		bindAxes: function () {
877
			var treeAxis = {
878
				endOnTick: false,
879
				gridLineWidth: 0,
880
				lineWidth: 0,
881
				min: 0,
882
				dataMin: 0,
883
				minPadding: 0,
884
				max: 100,
885
				dataMax: 100,
886
				maxPadding: 0,
887
				startOnTick: false,
888
				title: null,
889
				tickPositions: []
890
			};
891
			Series.prototype.bindAxes.call(this);
892
			H.extend(this.yAxis.options, treeAxis);
893
			H.extend(this.xAxis.options, treeAxis);
894
		}
895
	}));
896
}(Highcharts));