3 * Copyright 2011 Dan Vanderkam (danvdk@gmail.com)
4 * MIT-licensed (http://opensource.org/licenses/MIT)
8 * @fileoverview A wrapper around the Dygraph class which implements the
9 * interface for a GViz (aka Google Visualization API) visualization.
10 * It is designed to be a drop-in replacement for Google's AnnotatedTimeline,
11 * so the documentation at
12 * http://code.google.com/apis/chart/interactive/docs/gallery/annotatedtimeline.html
13 * translates over directly.
15 * For a full demo, see:
16 * - http://dygraphs.com/tests/gviz.html
17 * - http://dygraphs.com/tests/annotation-gviz.html
23 * A wrapper around Dygraph that implements the gviz API.
24 * @param {Object} container The DOM object the visualization should live in.
26 Dygraph
.GVizChart
= function(container
) {
27 this.container
= container
;
30 Dygraph
.GVizChart
.prototype.draw
= function(data
, options
) {
31 // Clear out any existing dygraph.
32 // TODO(danvk): would it make more sense to simply redraw using the current
34 this.container
.innerHTML
= '';
35 if (typeof(this.date_graph
) != 'undefined') {
36 this.date_graph
.destroy();
39 this.date_graph
= new Dygraph(this.container
, data
, options
);
43 * Google charts compatible setSelection
44 * Only row selection is supported, all points in the row will be highlighted
45 * @param {Array} array of the selected cells
48 Dygraph
.GVizChart
.prototype.setSelection
= function(selection_array
) {
50 if (selection_array
.length
) {
51 row
= selection_array
[0].row
;
53 this.date_graph
.setSelection(row
);
57 * Google charts compatible getSelection implementation
58 * @return {Array} array of the selected cells
61 Dygraph
.GVizChart
.prototype.getSelection
= function() {
64 var row
= this.date_graph
.getSelection();
66 if (row
< 0) return selection
;
69 for (var i
in this.date_graph
.layout_
.datasets
) {
70 selection
.push({row
: row
, column
: col
});