Merge branch 'master' of https://github.com/kberg/dygraphs
[dygraphs.git] / gadget.xml
CommitLineData
36615faf
DV
1<?xml version="1.0" encoding="UTF-8"?>
2<Module>
3
4 <ModulePrefs
5 title="dygraphs Gadget"
6 description="Interactive, zoomable chart"
7 author="Dan Vanderkam"
8 author_email="danvdk@gmail.com"
1723e3d6 9 thumbnail="http://danvk.org/dygraphs/thumbnail.png"
36615faf
DV
10 >
11 <!-- TODO(danvk): change these -->
12 <!--
13 screenshot="http://www.google.com/ig/modules/simple-table.png"
36615faf
DV
14 -->
15 <Require feature="idi" />
16 <Require feature="locked-domain" />
17 </ModulePrefs>
18
19 <UserPref name="_table_query_url" display_name="Data source url" required="true"/>
20 <UserPref name="_table_query_refresh_interval" display_name="Data refresh interval (minutes)" default_value="300" datatype="enum" required="false">
21 <EnumValue value="0" display_value="Do not refresh"/>
22 <EnumValue value="60" display_value="1"/>
23 <EnumValue value="300" display_value="5"/>
24 <EnumValue value="1800" display_value="30"/>
25 </UserPref>
1723e3d6
DV
26 <UserPref name="_dg_rollPeriod" display_name="Roll Period" required="false" default_value="1" />
27 <UserPref name="_dg_showRoller" display_name="Show Roller" required="false" default_value="false" datatype="bool" />
28 <UserPref name="_dg_minY" display_name="Min Y Value" required="false" default_value="" />
29 <UserPref name="_dg_maxY" display_name="Max Y Value" required="false" default_value="" />
30 <UserPref name="_dg_kmb" display_name="KMB labels" required="false" default_value="false" datatype="bool" />
3e3f84e4 31 <UserPref name="_dg_errorbars" display_name="Error Bars" required="false" default_value="false" datatype="bool" />
f81dd1ea 32 <UserPref name="_dg_fillGraph" display_name="Fill Chart" required="false" default_value="false" datatype="bool" />
36615faf
DV
33 <!--
34 This is a sample gadget, that uses the Google Visualization API to read data
35 from a data source, and displays it as an html table.
36 -->
37
38 <Content type="html"><![CDATA[
39
40 <!-- Load the Google common loader, that is later used to load the Visualization API. -->
41 <script src="http://www.google.com/jsapi" type="text/javascript"></script>
42 <script src="http://danvk.org/dygraphs/dygraph-combined.js" type="text/javascript"></script>
43
44 <div id="chartdiv" style="overflow: auto;"><img src="http://www.google.com/ig/images/spinner.gif" /></div>
45
46 <script>
47 var gadgetHelper = null;
f81dd1ea 48 var table = null;
36615faf
DV
49
50 _IG_RegisterOnloadHandler(loadVisualizationAPI);
51
52 /**
53 * Load the Google Visualization API
54 */
55 function loadVisualizationAPI() {
56 google.load("visualization", "1");
57 google.setOnLoadCallback(sendQuery);
58 }
59
60 /**
61 * Create a query from the user prefs, and then send it to the data source.
62 * This method is called once the visualization API is fully loaded.
63 * Note that in the last line, a callback function is specified to be
64 * called once the response is received from the data source.
65 */
66 function sendQuery() {
67 var prefs = new _IG_Prefs(); // User preferences
68 var chartDiv = _gel('chartdiv');
69 chartDiv.style.width = document.body.clientWidth + 'px';
70 chartDiv.style.height = document.body.clientHeight + 'px';
71 chart = new DateGraph.GVizChart(chartDiv);
72
73 gadgetHelper = new google.visualization.GadgetHelper();
74 var query = gadgetHelper.createQueryFromPrefs(prefs);
75 query.send(handleQueryResponse);
76 }
77
78 /**
79 * Query response handler function.
80 * Called by the Google Visualization API once the response is received.
81 * Takes the query response and formats it as a table.
82 */
83 function handleQueryResponse(response) {
84 // Use the visualization GadgetHelper class to validate the data, and
85 // for error handling.
86 if (!gadgetHelper.validateResponse(response)) {
87 // Default error handling was done, just leave.
88 return;
89 };
90 var data = response.getDataTable();
91
92 // Take the data table from the response, and format it.
93 // var options = {showRowNumber: true};
94 var prefs = new _IG_Prefs(); // User preferences
1723e3d6
DV
95 var showRoller = prefs.getBool("_dg_showRoller");
96 var rollPeriod = prefs.getInt("_dg_rollPeriod");
97 var labelsKMB = prefs.getBool("_dg_kmb");
3e3f84e4 98 var errorBars = prefs.getBool("_dg_errorbars");
f81dd1ea 99 var fillGraph = prefs.getBool("_dg_fillGraph");
1723e3d6
DV
100 var opts = {
101 showRoller: showRoller,
102 rollPeriod: rollPeriod,
3e3f84e4 103 labelsKMB: labelsKMB,
f81dd1ea
DV
104 errorBars: errorBars,
105 fillGraph: fillGraph
1723e3d6
DV
106 };
107
108 var minY = prefs.getString("_dg_minY");
109 var maxY = prefs.getString("_dg_maxY");
110 if (minY && maxY) {
111 opts.valueRange = [parseInt(minY), parseInt(maxY)];
112 }
113
114 chart.draw(data, opts);
36615faf
DV
115 };
116
117 </script>
118
119 ]]>
120 </Content>
121</Module>