forked from danvk/dygraphs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dygraph-gviz.js
76 lines (65 loc) · 2.1 KB
/
dygraph-gviz.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* @license
* Copyright 2011 Dan Vanderkam (danvdk@gmail.com)
* MIT-licensed (http://opensource.org/licenses/MIT)
*/
/**
* @fileoverview A wrapper around the Dygraph class which implements the
* interface for a GViz (aka Google Visualization API) visualization.
* It is designed to be a drop-in replacement for Google's AnnotatedTimeline,
* so the documentation at
* http://code.google.com/apis/chart/interactive/docs/gallery/annotatedtimeline.html
* translates over directly.
*
* For a full demo, see:
* - http://dygraphs.com/tests/gviz.html
* - http://dygraphs.com/tests/annotation-gviz.html
*/
/*jshint globalstrict: true */
/*global Dygraph:false */
"use strict";
/**
* A wrapper around Dygraph that implements the gviz API.
* @param {Object} container The DOM object the visualization should live in.
*/
Dygraph.GVizChart = function(container) {
this.container = container;
};
Dygraph.GVizChart.prototype.draw = function(data, options) {
// Clear out any existing dygraph.
// TODO(danvk): would it make more sense to simply redraw using the current
// date_graph object?
this.container.innerHTML = '';
if (typeof(this.date_graph) != 'undefined') {
this.date_graph.destroy();
}
this.date_graph = new Dygraph(this.container, data, options);
};
/**
* Google charts compatible setSelection
* Only row selection is supported, all points in the row will be highlighted
* @param {Array} array of the selected cells
* @public
*/
Dygraph.GVizChart.prototype.setSelection = function(selection_array) {
var row = false;
if (selection_array.length) {
row = selection_array[0].row;
}
this.date_graph.setSelection(row);
};
/**
* Google charts compatible getSelection implementation
* @return {Array} array of the selected cells
* @public
*/
Dygraph.GVizChart.prototype.getSelection = function() {
var selection = [];
var row = this.date_graph.getSelection();
if (row < 0) return selection;
var datasets = this.date_graph.layout_.datasets;
for (var setIdx = 0; setIdx < datasets.length; ++setIdx) {
selection.push({row: row, column: setIdx + 1});
}
return selection;
};