aa563374c1403d6970c15c12794da15365e31cdd
3 * Copyright 2012 Dan Vanderkam (danvdk@gmail.com)
4 * MIT-licensed (http://opensource.org/licenses/MIT)
6 Dygraph
.Plugins
.ChartLabels
= (function() {
8 // TODO(danvk): move chart label options out of dygraphs and into the plugin.
10 var chart_labels
= function() {
11 this.title_div_
= null;
12 this.xlabel_div_
= null;
13 this.ylabel_div_
= null;
14 this.y2label_div_
= null;
17 chart_labels
.prototype.toString
= function() {
18 return "ChartLabels Plugin";
21 chart_labels
.prototype.activate
= function(g
) {
24 // clearChart: this.clearChart,
25 drawChart
: this.drawChart
29 // QUESTION: should there be a plugin-utils.js?
30 var createDivInRect
= function(r
) {
31 var div
= document
.createElement('div');
32 div
.style
.position
= 'absolute';
33 div
.style
.left
= r
.x
+ 'px';
34 div
.style
.top
= r
.y
+ 'px';
35 div
.style
.width
= r
.w
+ 'px';
36 div
.style
.height
= r
.h
+ 'px';
40 // Detach and null out any existing nodes.
41 chart_labels
.prototype.detachLabels_
= function() {
42 var els
= [ this.title_div_
,
46 for (var i
= 0; i
< els
.length
; i
++) {
49 if (el
.parentNode
) el
.parentNode
.removeChild(el
);
52 this.title_div_
= null;
53 this.xlabel_div_
= null;
54 this.ylabel_div_
= null;
55 this.y2label_div_
= null;
58 chart_labels
.prototype.layout
= function(e
) {
62 var div
= e
.chart_div
;
63 if (g
.getOption('title')) {
64 // QUESTION: should this return an absolutely-positioned div instead?
65 var title_rect
= e
.reserveSpaceTop(g
.getOption('titleHeight'));
66 this.title_div_
= createDivInRect(title_rect
);
67 this.title_div_
.innerHTML
= g
.getOption('title');
68 this.title_div_
.style
.textAlign
= 'center';
69 this.title_div_
.style
.fontSize
= (g
.getOption('titleHeight') - 8) + 'px';
70 this.title_div_
.style
.fontWeight
= 'bold';
71 div
.appendChild(this.title_div_
);
75 if (g.getOption('xlabel')) {
76 var x_rect = e.reserveSpaceBottom(g.getOption('xLabelHeight'));
79 if (g.getOption('ylabel')) {
80 var y_rect = e.reserveSpaceLeft(0);
83 if (g.getOption('y2label')) {
84 var y2_rect = e.reserveSpaceRight(0);
89 chart_labels
.prototype.drawChart
= function(e
) {
91 if (this.title_div_
) {
92 this.title_div_
.innerHTML
= g
.getOption('title');
96 chart_labels
.prototype.clearChart
= function() {
99 chart_labels
.prototype.destroy
= function() {