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
) {
27 // QUESTION: should there be a plugin-utils.js?
28 var createDivInRect
= function(r
) {
29 var div
= document
.createElement('div');
30 div
.style
.position
= 'absolute';
31 div
.style
.left
= r
.x
+ 'px';
32 div
.style
.top
= r
.y
+ 'px';
33 div
.style
.width
= r
.w
+ 'px';
34 div
.style
.height
= r
.h
+ 'px';
38 chart_labels
.layout
= function(e
) {
40 var div
= e
.chart_div
;
41 if (g
.getOption('title')) {
42 // QUESTION: should this return an absolutely-positioned div instead?
43 var title_rect
= e
.reserveSpaceTop(g
.getOption('titleHeight'));
44 this.title_div_
= createDivInRect(title_rect
);
45 this.title_div_
.innerHTML
= g
.getOption('title');
46 this.title_div_
.style
.textAlign
= 'center';
47 this.title_div_
.style
.fontSize
= (g
.getOption('titleHeight') - 8) + 'px';
48 this.title_div_
.style
.fontWeight
= 'bold';
49 div
.appendChild(this.title_div_
);
53 if (g.getOption('xlabel')) {
54 var x_rect = e.reserveSpaceBottom(g.getOption('xLabelHeight'));
57 if (g.getOption('ylabel')) {
58 var y_rect = e.reserveSpaceLeft(0);
61 if (g.getOption('y2label')) {
62 var y2_rect = e.reserveSpaceRight(0);
67 chart_labels
.prototype.destroy
= function() {
68 this.title_div_
= null;
69 this.xlabel_div_
= null;
70 this.ylabel_div_
= null;
71 this.y2label_div_
= null;