1 <?xml version=
"1.0" encoding=
"UTF-8"?>
5 title=
"dygraphs Gadget"
6 description=
"Interactive, zoomable chart"
8 author_email=
"danvdk@gmail.com"
9 thumbnail=
"http://danvk.org/dygraphs/thumbnail.png"
11 <!-- TODO(danvk): change these --
>
13 screenshot=
"http://www.google.com/ig/modules/simple-table.png"
15 <Require feature=
"idi" />
16 <Require feature=
"locked-domain" />
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"/>
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" />
32 This is a sample gadget, that uses the Google Visualization API to read data
33 from a data source, and displays it as an html table.
36 <Content type=
"html"><![CDATA[
38 <!-- Load the Google common loader, that is later used to load the Visualization API. --
>
39 <script src=
"http://www.google.com/jsapi" type=
"text/javascript"></script>
40 <script src=
"http://danvk.org/dygraphs/dygraph-combined.js" type=
"text/javascript"></script>
42 <div id=
"chartdiv" style=
"overflow: auto;"><img src=
"http://www.google.com/ig/images/spinner.gif" /></div>
45 var gadgetHelper = null;
48 _IG_RegisterOnloadHandler(loadVisualizationAPI);
51 * Load the Google Visualization API
53 function loadVisualizationAPI() {
54 google.load(
"visualization",
"1");
55 google.setOnLoadCallback(sendQuery);
59 * Create a query from the user prefs, and then send it to the data source.
60 * This method is called once the visualization API is fully loaded.
61 * Note that in the last line, a callback function is specified to be
62 * called once the response is received from the data source.
64 function sendQuery() {
65 var prefs = new _IG_Prefs(); // User preferences
66 var chartDiv = _gel('chartdiv');
67 chartDiv.style.width = document.body.clientWidth + 'px';
68 chartDiv.style.height = document.body.clientHeight + 'px';
69 chart = new DateGraph.GVizChart(chartDiv);
71 gadgetHelper = new google.visualization.GadgetHelper();
72 var query = gadgetHelper.createQueryFromPrefs(prefs);
73 query.send(handleQueryResponse);
77 * Query response handler function.
78 * Called by the Google Visualization API once the response is received.
79 * Takes the query response and formats it as a table.
81 function handleQueryResponse(response) {
82 // Use the visualization GadgetHelper class to validate the data, and
83 // for error handling.
84 if (!gadgetHelper.validateResponse(response)) {
85 // Default error handling was done, just leave.
88 var data = response.getDataTable();
90 // Take the data table from the response, and format it.
91 // var options = {showRowNumber: true};
92 var prefs = new _IG_Prefs(); // User preferences
93 var showRoller = prefs.getBool(
"_dg_showRoller");
94 var rollPeriod = prefs.getInt(
"_dg_rollPeriod");
95 var labelsKMB = prefs.getBool(
"_dg_kmb");
97 showRoller: showRoller,
98 rollPeriod: rollPeriod,
102 var minY = prefs.getString(
"_dg_minY");
103 var maxY = prefs.getString(
"_dg_maxY");
105 opts.valueRange = [parseInt(minY), parseInt(maxY)];
108 chart.draw(data, opts);