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