1 // Copyright 2011 Dan Vanderkam (danvdk@gmail.com)
2 // All Rights Reserved.
5 * @fileoverview A wrapper around the Dygraph class which implements the
6 * interface for a GViz (aka Google Visualization API) visualization.
7 * It is designed to be a drop-in replacement for Google's AnnotatedTimeline,
8 * so the documentation at
9 * http://code.google.com/apis/chart/interactive/docs/gallery/annotatedtimeline.html
10 * translates over directly.
12 * For a full demo, see:
13 * - http://dygraphs.com/tests/gviz.html
14 * - http://dygraphs.com/tests/annotation-gviz.html
18 * A wrapper around Dygraph that implements the gviz API.
19 * @param {Object} container The DOM object the visualization should live in.
21 Dygraph
.GVizChart
= function(container
) {
22 this.container
= container
;
25 Dygraph
.GVizChart
.prototype.draw
= function(data
, options
) {
26 // Clear out any existing dygraph.
27 // TODO(danvk): would it make more sense to simply redraw using the current
29 this.container
.innerHTML
= '';
30 if (typeof(this.date_graph
) != 'undefined') {
31 this.date_graph
.destroy();
34 this.date_graph
= new Dygraph(this.container
, data
, options
);
38 * Google charts compatible setSelection
39 * Only row selection is supported, all points in the row will be highlighted
40 * @param {Array} array of the selected cells
43 Dygraph
.GVizChart
.prototype.setSelection
= function(selection_array
) {
45 if (selection_array
.length
) {
46 row
= selection_array
[0].row
;
48 this.date_graph
.setSelection(row
);
52 * Google charts compatible getSelection implementation
53 * @return {Array} array of the selected cells
56 Dygraph
.GVizChart
.prototype.getSelection
= function() {
59 var row
= this.date_graph
.getSelection();
61 if (row
< 0) return selection
;
64 for (var i
in this.date_graph
.layout_
.datasets
) {
65 selection
.push({row
: row
, column
: col
});