| 1 | /** |
| 2 | * @license |
| 3 | * Copyright 2012 Dan Vanderkam (danvdk@gmail.com) |
| 4 | * MIT-licensed (http://opensource.org/licenses/MIT) |
| 5 | */ |
| 6 | Dygraph.Plugins.ChartLabels = (function() { |
| 7 | |
| 8 | // TODO(danvk): move chart label options out of dygraphs and into the plugin. |
| 9 | |
| 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; |
| 15 | }; |
| 16 | |
| 17 | chart_labels.prototype.toString = function() { |
| 18 | return "ChartLabels Plugin"; |
| 19 | }; |
| 20 | |
| 21 | chart_labels.prototype.activate = function(g) { |
| 22 | return { |
| 23 | layout: this.layout |
| 24 | }; |
| 25 | }; |
| 26 | |
| 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'; |
| 35 | return div; |
| 36 | }; |
| 37 | |
| 38 | chart_labels.prototype.layout = function(e) { |
| 39 | var g = e.dygraph; |
| 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_); |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | if (g.getOption('xlabel')) { |
| 54 | var x_rect = e.reserveSpaceBottom(g.getOption('xLabelHeight')); |
| 55 | } |
| 56 | |
| 57 | if (g.getOption('ylabel')) { |
| 58 | var y_rect = e.reserveSpaceLeft(0); |
| 59 | } |
| 60 | |
| 61 | if (g.getOption('y2label')) { |
| 62 | var y2_rect = e.reserveSpaceRight(0); |
| 63 | } |
| 64 | */ |
| 65 | }; |
| 66 | |
| 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; |
| 72 | }; |
| 73 | |
| 74 | |
| 75 | return chart_labels; |
| 76 | })(); |