Skip to content

Commit a472286

Browse files
committed
Upgraded dygraphs.js library to latest version
dygraphs.js version: dd74404fac69f23183ff8e540a018ca35bab4f7a including bugfix for #724 Added support for custom legend formatters and demo for it
1 parent 6b71638 commit a472286

File tree

14 files changed

+7029
-9265
lines changed

14 files changed

+7029
-9265
lines changed

Diff for: dygraphs-gwt-sample/src/main/java/sample/client/SampleShell.java

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import sample.client.examples.HighlightRegionExample;
4444
import sample.client.examples.HighlightWeekendsExample;
4545
import sample.client.examples.IndependantSeriesExample;
46+
import sample.client.examples.LegendFormatterExample;
4647
import sample.client.examples.LinearRegressionExample;
4748
import sample.client.examples.LinkInteractionExample;
4849
import sample.client.examples.PerSeriesPropertiesExample;
@@ -213,6 +214,8 @@ private void initList() {
213214
exampleInfos.add(new ExampleInfo("Linear Regressions",new LinearRegressionExample(),"linear-regression"));
214215
exampleInfos.add(new ExampleInfo("Edge Padding",new EdgePaddingExample(),"edge-padding"));
215216
exampleInfos.add(new ExampleInfo("Google Visualization Example",new GvizExample(),"gviz"));
217+
218+
exampleInfos.add(new ExampleInfo("Legend Formatter",new LegendFormatterExample(),"legend-formatter"));
216219
}
217220

218221
@UiHandler("tabExample")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package sample.client.examples;
2+
3+
import com.github.timeu.dygraphsgwt.client.Dygraphs;
4+
import com.github.timeu.dygraphsgwt.client.DygraphsOptions;
5+
import com.github.timeu.dygraphsgwt.client.callbacks.LegendFormatterCallback;
6+
import com.github.timeu.dygraphsgwt.client.callbacks.LegendFormatterData;
7+
import com.github.timeu.dygraphsgwt.client.callbacks.LegendFormatterSeries;
8+
import com.github.timeu.dygraphsgwt.client.options.HighlightSeriesOptions;
9+
import com.google.gwt.dom.client.DivElement;
10+
import com.google.gwt.dom.client.Document;
11+
import com.google.gwt.dom.client.Style;
12+
import com.google.gwt.user.client.DOM;
13+
import com.google.gwt.user.client.ui.Button;
14+
import com.google.gwt.user.client.ui.Composite;
15+
import com.google.gwt.user.client.ui.FlowPanel;
16+
import com.google.gwt.user.client.ui.HTML;
17+
import com.google.gwt.user.client.ui.HTMLPanel;
18+
import com.google.gwt.user.client.ui.HorizontalPanel;
19+
import com.google.gwt.user.client.ui.VerticalPanel;
20+
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
24+
/**
25+
* Created by uemit.seren on 2/3/16.
26+
*/
27+
public class LegendFormatterExample extends Composite {
28+
29+
private VerticalPanel panel = new VerticalPanel();
30+
private Dygraphs dygraphs;
31+
DivElement legendElement;
32+
33+
public LegendFormatterExample() {
34+
35+
initWidget(panel);
36+
legendElement = Document.get().createDivElement();
37+
panel.add(new HTML("This page demonstrates use of <a href=\"../options.html#legendFormatter\"><code>legendFormatter</code></a>, " +
38+
"which can be used to create more complex legends than <code>valueFormatter</code>"));
39+
panel.getElement().appendChild(legendElement);
40+
initDygraphs();
41+
}
42+
43+
public void initDygraphs() {
44+
DygraphsOptions options = new DygraphsOptions();
45+
options.legend="always";
46+
options.xlabel="Date";
47+
options.ylabel="Count";
48+
options.labelsDiv = legendElement;
49+
options.legendFormatter = new LegendFormatterCallback() {
50+
@Override
51+
public String getFormat(LegendFormatterData data) {
52+
if (data.getX() == null) {
53+
// This happens when there's no selection and {legend: 'always'} is set.
54+
String retval = "<br>";
55+
for (LegendFormatterSeries series: data.getSeries()) {
56+
retval+=series.getDashHTML()+" "+ series.getLabelHTML()+"<br>";
57+
}
58+
return retval;
59+
}
60+
String html = data.getDygraph().getLabels()[0] + ": " + data.getXHTML();
61+
for (LegendFormatterSeries series:data.getSeries()) {
62+
if (series.isVisible()) {
63+
String labeledData = series.getLabelHTML()+": "+ series.getYHTML();
64+
if (series.isHighlighted()) {
65+
labeledData = "<b>" + labeledData+"</b>";
66+
}
67+
html+="<br>" + series.getDashHTML()+" " + labeledData;
68+
}
69+
}
70+
return html;
71+
}
72+
};
73+
74+
HighlightSeriesOptions highlightSeriesOptions = new HighlightSeriesOptions();
75+
highlightSeriesOptions.strokeWidth = 2;
76+
options.highlightSeriesOpts = highlightSeriesOptions;
77+
78+
dygraphs = new Dygraphs(()-> {
79+
String r = "date,parabola,line,another line,sine wave\n";
80+
for (int i = 1; i <= 31; i++) {
81+
r += "200610" + (i < 10 ? "0"+i : String.valueOf(i));
82+
r += "," + 10*(i*(31-i));
83+
r += "," + 10*(8*i);
84+
r += "," + 10*(250 - 8*i);
85+
r += "," + 10*(125 + 125 * Math.sin(0.3*i));
86+
r += "\n";
87+
}
88+
return r;
89+
},options);
90+
panel.add(dygraphs);
91+
}
92+
93+
}

Diff for: dygraphs-gwt/src/main/java/com/github/timeu/dygraphsgwt/client/DygraphsClientBundle.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ public interface DygraphsClientBundle extends ClientBundle {
1111

1212
DygraphsClientBundle INSTANCE = GWT.create(DygraphsClientBundle.class);
1313

14-
@Source("resources/dygraph-combined.js")
14+
@Source("resources/dygraph.min.js")
1515
TextResource dygraphjs();
1616

17-
@Source("resources/dygraph-combined-dev.js")
17+
@Source("resources/dygraph.js")
1818
TextResource dygraphjs_dev();
1919

2020
@Source("resources/extras/shapes.js")

Diff for: dygraphs-gwt/src/main/java/com/github/timeu/dygraphsgwt/client/DygraphsJs.java

+2
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,6 @@ public interface DygraphsJs {
6666
Area getArea();
6767

6868
void drawGraph_();
69+
70+
String[] getLabels();
6971
}

Diff for: dygraphs-gwt/src/main/java/com/github/timeu/dygraphsgwt/client/DygraphsOptions.java

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.github.timeu.dygraphsgwt.client.callbacks.DrawCallback;
1111
import com.github.timeu.dygraphsgwt.client.callbacks.DrawPointCallback;
1212
import com.github.timeu.dygraphsgwt.client.callbacks.HighlightCallback;
13+
import com.github.timeu.dygraphsgwt.client.callbacks.LegendFormatterCallback;
1314
import com.github.timeu.dygraphsgwt.client.callbacks.PointClickCallback;
1415
import com.github.timeu.dygraphsgwt.client.callbacks.UnHighlightCallback;
1516
import com.github.timeu.dygraphsgwt.client.callbacks.UnderlayCallback;
@@ -418,6 +419,15 @@ public final void setArrayFile(JsArray<JsArrayMixed> data) {
418419
public boolean animatedZooms;
419420

420421

422+
/**
423+
* Set this to supply a custom formatter for the legend.
424+
* See <a href=\"https://github.com/danvk/dygraphs/pull/683\">this comment</a> and
425+
* the <a href=\"tests/legend-formatter.html\">legendFormatter demo</a> for usage.
426+
*
427+
* (Default: null)
428+
*/
429+
public LegendFormatterCallback legendFormatter;
430+
421431
/**
422432
* Usually, when Dygraphs encounters a missing value in a data series, it interprets this as a gap and draws it as such.
423433
* If, instead, the missing values represents an x-value for which only a different series has data, then you'll want to connect the dots by setting this to true.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.github.timeu.dygraphsgwt.client.callbacks;
2+
3+
import jsinterop.annotations.JsFunction;
4+
5+
/**
6+
* Created by uemit.seren on 2/2/16.
7+
*/
8+
@FunctionalInterface
9+
@JsFunction
10+
public interface LegendFormatterCallback {
11+
/**
12+
* Handler that is called for suppylying a custom legend.
13+
*
14+
* @param data Object of {@link LegendFormatterData}
15+
*/
16+
String getFormat(LegendFormatterData data);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.github.timeu.dygraphsgwt.client.callbacks;
2+
3+
import com.github.timeu.dygraphsgwt.client.Dygraphs;
4+
import com.github.timeu.dygraphsgwt.client.DygraphsJs;
5+
import jsinterop.annotations.JsPackage;
6+
import jsinterop.annotations.JsProperty;
7+
import jsinterop.annotations.JsType;
8+
9+
/**
10+
* Created by uemit.seren on 2/2/16.
11+
*/
12+
@JsType(isNative = true,namespace = JsPackage.GLOBAL,name="Object")
13+
public interface LegendFormatterData {
14+
15+
@JsProperty
16+
DygraphsJs getDygraph();
17+
18+
@JsProperty
19+
Integer getX();
20+
21+
@JsProperty(name="xHTML")
22+
String getXHTML();
23+
24+
@JsProperty
25+
LegendFormatterSeries[] getSeries();
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.github.timeu.dygraphsgwt.client.callbacks;
2+
3+
import jsinterop.annotations.JsPackage;
4+
import jsinterop.annotations.JsProperty;
5+
import jsinterop.annotations.JsType;
6+
7+
/**
8+
* Created by uemit.seren on 2/2/16.
9+
*/
10+
@JsType(isNative = true,namespace = JsPackage.GLOBAL,name="Object")
11+
public interface LegendFormatterSeries {
12+
13+
@JsProperty
14+
String getDashHTML();
15+
16+
@JsProperty
17+
String getLabel();
18+
19+
@JsProperty
20+
String getLabelHTML();
21+
22+
@JsProperty(name="isVisible")
23+
boolean isVisible();
24+
25+
@JsProperty
26+
String getColor();
27+
28+
@JsProperty
29+
Integer getY();
30+
31+
@JsProperty(name="yHTML")
32+
String getYHTML();
33+
34+
@JsProperty(name="isHighlighted")
35+
boolean isHighlighted();
36+
}

Diff for: dygraphs-gwt/src/main/resources/com/github/timeu/dygraphsgwt/client/resources/dygraph-combined.js

-7
This file was deleted.

0 commit comments

Comments
 (0)