From 71ac4733fec0ca3adab2ae5440db13e1cd2231f1 Mon Sep 17 00:00:00 2001 From: Adam Vartanian Date: Fri, 9 Apr 2010 14:45:04 -0400 Subject: [PATCH] Add GWT Dygraphs loader class and supporting files. --- Makefile | 8 ++++++- docs/index.html | 21 +++++++++++++++++ generate-jar.sh | 4 ++++ gwt/org/danvk/Dygraphs$Resources.class | Bin 0 -> 526 bytes gwt/org/danvk/Dygraphs.class | Bin 0 -> 1282 bytes gwt/org/danvk/Dygraphs.java | 41 +++++++++++++++++++++++++++++++++ gwt/org/danvk/dygraph-combined.js | 1 + gwt/org/danvk/dygraphs.gwt.xml | 8 +++++++ 8 files changed, 82 insertions(+), 1 deletion(-) create mode 100755 generate-jar.sh create mode 100644 gwt/org/danvk/Dygraphs$Resources.class create mode 100644 gwt/org/danvk/Dygraphs.class create mode 100644 gwt/org/danvk/Dygraphs.java create mode 120000 gwt/org/danvk/dygraph-combined.js create mode 100644 gwt/org/danvk/dygraphs.gwt.xml diff --git a/Makefile b/Makefile index b71596c..2614ea3 100644 --- a/Makefile +++ b/Makefile @@ -8,4 +8,10 @@ all: generate-combined generate-combined: @echo Generating dygraph-combined.js - @generate-combined.sh + @./generate-combined.sh + +gwt: generate-gwt + +generate-gwt: + @echo Generating GWT JAR file + @./generate-jar.sh diff --git a/docs/index.html b/docs/index.html index 71df56b..1a86ecc 100644 --- a/docs/index.html +++ b/docs/index.html @@ -19,6 +19,7 @@
  • Baseball chart
  • Stock chart
  • Options Reference
  • +
  • GWT Compatibility
  • Data Policy
  • @@ -828,6 +829,26 @@ perl -ne 'BEGIN{print "Month,Nominal,Real\n"} chomp; ($m,$cpi,$low,$close,$high)
  • Make sure you don't have any trailing commas in your call to the Dygraph constructor or in the options parameter. Firefox, Chrome and Safari ignore these but they can cause a graph to not display in Internet Explorer.
  • +

    GWT Compatibility

    +

    There is currently no GWT wrapper around Dygraphs, however there is a class that can be used to easily load Dygraphs into the browser. To use it, include the generated dygraph-gwt.jar file in your classpath and add the following line to your GWT module:

    + +
    +<inherits name="org.danvk.dygraphs"/>    
    +
    + +

    Call org.danvk.Dygraphs.install() when your application starts to install the JavaScript code into the browser. You can use JSNI to call Dygraphs from your GWT code, as in the example below. The example uses the Visualization API for GWT and the Dygraphs GViz API.

    + +
    +  public static native JavaScriptObject drawDygraph(Element element, DataTable data, double minY, double maxY) /*-{
    +    var chart = new $wnd.Dygraph.GVizChart(element);
    +    chart.draw(dataTable,
    +      {
    +        valueRange: [minY, maxY]
    +      });
    +    return chart;
    +  }-*/;
    +
    +

    Data Policy

    dygraphs is purely client-side JavaScript. It does not send your data to any servers – the data is processed entirely in the client's browser.

    diff --git a/generate-jar.sh b/generate-jar.sh new file mode 100755 index 0000000..2c1d12d --- /dev/null +++ b/generate-jar.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# Generates a JAR file that can be used from GWT to load Dygraphs + +jar -cf dygraph-gwt.jar -C gwt org diff --git a/gwt/org/danvk/Dygraphs$Resources.class b/gwt/org/danvk/Dygraphs$Resources.class new file mode 100644 index 0000000000000000000000000000000000000000..7f4bddaa097a5a8fb4a50e0d4b2372bdc189cc26 GIT binary patch literal 526 zcmb7BO-lnY5S^**Zd+Te_2Z)6iYREKh$l~45ekA(y?IJ^hcz`#WRqR>uX*qX_@l(J z-D1H*@i0tg^4`38$>-Pm2LPPFRtT*S+99kXRO7cKmCuh3;duYxCbDCZSes}P$%_{$ zIh&;sIT2|^#*2G;^@E~$j<7w*j8|jon_M|H)O2Bt_0lVATnHNo!QF(9(C8aOX-`Y% zh_%iZD)lCUmzjw*b*58Tu#!ui5yGxb6A??3KZ(M?5wAW}hT`ss=hvr3ZoY$ELZ@@JQwnJ=c-=FY7jlF-s5;&wQq$RivsdZzj15l;UDFT5hO|E?GyAe1m17ufDRgrYI3*4{Tk;spF(C;_iBt;g|(pZ4SqVA)Bpeg literal 0 HcmV?d00001 diff --git a/gwt/org/danvk/Dygraphs.class b/gwt/org/danvk/Dygraphs.class new file mode 100644 index 0000000000000000000000000000000000000000..084f8fabedb841264bd2f58274ae5dfab7b2fe7b GIT binary patch literal 1282 zcmah}SyR(c6#i~onl`!Yi^?WDZCQf*QUs+`$B}^l#9!VH2B zj?exm$CI{^LdW`Y&pkKa`OcnSzrX(ga1X^a+A$(y6nDd8EL6u8D40+%i76S=mY-VTkp3E#S+8lhU=NC zp*hDN)%6q8(<%r4)L+v)fi1@mG}{&i1KVSe>N-O_ll{PuD7c1T=-jXzv3XS97v7Gx zZ_`V1*>bF4g(0=9+x4qls)qF13IXkrzr{oCSmWqLpM)h&>EGvgfQKC2=;3&T#}b}! zJjF8!&pGl~=6Hb>39B40@rvUP1{j80qkwgWo@N+BR~Ue5YmTXI?H>v~V3^R| zvTC}nX$#f-6sQKNl!kBub=}pE%5w?ugGp)J?LUzY%9kJoTFL3mF*t$k$boN`YrNCh^VQ;A^PT zwZMtWkEr@H%}n7Sh0fMoKh^ZHkBAEVn1Pwq2MXOYVV-yZ7n+AC;)1qUW zG|>50Ev*7*b#A!UT~9=Hf3v$o8&K;v1=*N#bq$ICs+_f%%VV6jyo2^XhQV<3=_ZFu zK{Adk`Y`~8Tcqs~f{|Q21^a^B1!CujzssE>afvpDOC%Z2AywZ~xpSm<6K7yw$%5fF zor6f$&mr@4FCWD literal 0 HcmV?d00001 diff --git a/gwt/org/danvk/Dygraphs.java b/gwt/org/danvk/Dygraphs.java new file mode 100644 index 0000000..f581577 --- /dev/null +++ b/gwt/org/danvk/Dygraphs.java @@ -0,0 +1,41 @@ +package org.danvk; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.ScriptElement; +import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.resources.client.TextResource; + +/** + * Methods for installing Dygraphs source in a GWT document. + * + * @author flooey@google.com (Adam Vartanian) + */ +public class Dygraphs { + + // Protected because the GWT compiler has to generate a subclass. + protected interface Resources extends ClientBundle { + @Source("org/danvk/dygraph-combined.js") + TextResource dygraphs(); + } + + private static final Resources RESOURCES = GWT.create(Resources.class); + private static boolean installed = false; + + /** + * Install the Dygraphs JavaScript source into the current document. This + * method is idempotent. + */ + public static synchronized void install() { + if (!installed) { + ScriptElement e = Document.get().createScriptElement(); + e.setText(RESOURCES.dygraphs().getText()); + Document.get().getBody().appendChild(e); + installed = true; + } + } + + // Prevent construction + private Dygraphs() { } + +} diff --git a/gwt/org/danvk/dygraph-combined.js b/gwt/org/danvk/dygraph-combined.js new file mode 120000 index 0000000..d64425f --- /dev/null +++ b/gwt/org/danvk/dygraph-combined.js @@ -0,0 +1 @@ +../../../dygraph-combined.js \ No newline at end of file diff --git a/gwt/org/danvk/dygraphs.gwt.xml b/gwt/org/danvk/dygraphs.gwt.xml new file mode 100644 index 0000000..679765e --- /dev/null +++ b/gwt/org/danvk/dygraphs.gwt.xml @@ -0,0 +1,8 @@ + + + + + + + + -- 2.7.4