Skip to content

Commit c63cec4

Browse files
committed
Provided CssResource params on ChartTypeLoader.
Fixed all loading / unloading of js / css resources. Extend StockChart to AbstractChart for complete support. Major Clean up and JSInterop corrections.
1 parent 27f67bf commit c63cec4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1320
-1465
lines changed

gwt-material-amcharts.iml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
<facet type="gwt" name="GWT">
55
<configuration>
66
<setting name="compilerParameters" value="-compileReport -XcompilerMetrics" />
7+
<setting name="compilerMaxHeapSize" value="1024" />
8+
<setting name="gwtScriptOutputStyle" value="DETAILED" />
9+
<setting name="gwtSdkUrl" value="file://$MAVEN_REPOSITORY$/com/google/gwt/gwt-dev/2.8.2" />
10+
<setting name="gwtSdkType" value="maven" />
711
<packaging>
812
<module name="gwt.material.design.amcharts.GwtMaterialAmChartsBase" enabled="false" />
913
<module name="gwt.material.design.amcharts.GwtMaterialAmChartsBasic" enabled="false" />

src/main/java/gwt/material/design/amcharts/client/ui/chart/CoordinateChart.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public void setUrlTarget(String urlTarget) {
181181
public void setValueAxes(ValueAxis... valueAxes) {
182182
for (int i = 0; i < valueAxes.length; i++) {
183183
getChart().valueAxes[i] = valueAxes[i].getAmValueAxis();
184+
valueAxes[i].load();
184185
}
185186
}
186187

@@ -197,6 +198,7 @@ public void addGraph(Graph graph) {
197198
*/
198199
public void addValueAxis(ValueAxis valueAxis) {
199200
getChart().addValueAxis(valueAxis.getAmValueAxis());
201+
valueAxis.load();
200202
}
201203

202204
/**
@@ -254,6 +256,7 @@ public void removeGraph(Graph graph) {
254256
*/
255257
public void removeValueAxis(ValueAxis valueAxis) {
256258
getChart().removeValueAxis(valueAxis.getAmValueAxis());
259+
valueAxis.unload();
257260
}
258261

259262
/**

src/main/java/gwt/material/design/amcharts/client/ui/chart/base/constants/ChartType.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
import gwt.material.design.amcharts.client.ui.chart.resources.ChartTypeClientBundle;
2323
import gwt.material.design.amcharts.client.ui.chart.resources.ChartTypeClientDebugBundle;
24+
import gwt.material.design.amcharts.client.ui.maps.resources.MapClientBundle;
25+
import gwt.material.design.amcharts.client.ui.maps.resources.MapClientDebugBundle;
26+
import gwt.material.design.amcharts.client.ui.stock.resources.StockChartClientBundle;
27+
import gwt.material.design.amcharts.client.ui.stock.resources.StockChartClientDebugBundle;
2428
import gwt.material.design.client.base.helper.EnumHelper;
2529
import gwt.material.design.client.constants.CssType;
2630

@@ -63,11 +67,32 @@ public enum ChartType implements CssType {
6367
ChartTypeClientBundle.INSTANCE.ganttJs().getText(),
6468
ChartTypeClientDebugBundle.INSTANCE.ganttDebugJs().getText()),
6569

66-
MAP("map", null, null);
70+
MAP("map",
71+
MapClientBundle.INSTANCE.amMapJs().getText(),
72+
MapClientDebugBundle.INSTANCE.amMapDebugJs().getText(),
73+
MapClientBundle.INSTANCE.ammapCss().getText(),
74+
MapClientDebugBundle.INSTANCE.ammapDebugCss().getText()),
75+
76+
77+
STOCK("stock",
78+
StockChartClientBundle.INSTANCE.stockChartJs().getText(),
79+
StockChartClientDebugBundle.INSTANCE.stockChartDebugJs().getText(),
80+
StockChartClientBundle.INSTANCE.stockChartCss().getText(),
81+
StockChartClientDebugBundle.INSTANCE.stockChartDebugCss().getText());
6782

6883
private String name;
6984
private String jsResource;
7085
private String jsDebugResource;
86+
private String cssResource;
87+
private String cssDebugResource;
88+
89+
ChartType(String name, String jsResource, String jsDebugResource, String cssResource, String cssDebugResource) {
90+
this.name = name;
91+
this.jsResource = jsResource;
92+
this.jsDebugResource = jsDebugResource;
93+
this.cssResource = cssResource;
94+
this.cssDebugResource = cssDebugResource;
95+
}
7196

7297
ChartType(String name, String jsResource, String jsDebugResource) {
7398
this.name = name;
@@ -95,4 +120,12 @@ public String getJsResource() {
95120
public String getJsDebugResource() {
96121
return jsDebugResource;
97122
}
123+
124+
public String getCssResource() {
125+
return cssResource;
126+
}
127+
128+
public String getCssDebugResource() {
129+
return cssDebugResource;
130+
}
98131
}

src/main/java/gwt/material/design/amcharts/client/ui/chart/events/object/AxisItemData.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@
3333
public class AxisItemData {
3434

3535
@JsProperty
36-
public AmAxisBase axisBase;
36+
private AmAxisBase axisBase;
3737

3838
@JsProperty
39-
public Label target;
39+
private Label target;
4040

4141
@JsProperty
42-
public AmRectangularChart chart;
42+
private AmRectangularChart chart;
4343

4444
@JsProperty
45-
public MouseEvent event;
45+
private MouseEvent event;
4646

4747
@JsProperty
4848
private String type;

src/main/java/gwt/material/design/amcharts/client/ui/chart/js/AmChart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public class AmChart {
442442
/**
443443
* Adds a legend to the chart. By default, you don't need to create div for your legend, however if you want it to
444444
* be positioned in some different way, you can create div anywhere you want and pass id or reference to your div
445-
* as a second parameter. (NOTE: This method will not work on StockPanel.)
445+
* as a second parameter. (NOTE: This method will not work on AmStockPanel.)
446446
*
447447
* @param legend {@link AmLegend}
448448
* @param targetElementId id or reference to legend div

src/main/java/gwt/material/design/amcharts/client/ui/chart/js/options/AmCategoryAxis.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
*/
2020
package gwt.material.design.amcharts.client.ui.chart.js.options;
2121

22+
import com.google.gwt.core.client.JsDate;
2223
import gwt.material.design.jquery.client.api.Functions;
2324
import jsinterop.annotations.JsMethod;
2425
import jsinterop.annotations.JsPackage;
2526
import jsinterop.annotations.JsProperty;
2627
import jsinterop.annotations.JsType;
2728

28-
import java.util.Date;
29-
3029
//@formatter:off
3130

3231
/**
@@ -91,14 +90,14 @@ public class AmCategoryAxis extends AmAxisBase {
9190
* Returns Date of the coordinate, in case parseDates is set to true and equalSpacing is set to false.
9291
*/
9392
@JsMethod
94-
public native Date coordinateToDate(int coordinate);
93+
public native JsDate coordinateToDate(int coordinate);
9594

9695
/**
9796
* Returns coordinate of the date, in case parseDates is set to true. if parseDates is false, use
9897
* categoryToCoordinate method.
9998
*/
10099
@JsMethod
101-
public native int dateToCoordinate(Date date);
100+
public native int dateToCoordinate(JsDate date);
102101

103102
/**
104103
* Returns index of the category which is most close to specified coordinate.

src/main/java/gwt/material/design/amcharts/client/ui/chart/options/GaugeArrow.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public AmGaugeAxis getAxis() {
5959
*/
6060
public void setAxis(GaugeAxis axis) {
6161
getAmGaugeArrow().axis = axis.getAmGaugeAxis();
62+
axis.load();
6263
}
6364

6465
public int getBorderAlpha() {

src/main/java/gwt/material/design/amcharts/client/ui/chart/resources/ChartResourceLoader.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,16 @@ public class ChartResourceLoader extends ResourceLoader {
3030
public static void loadChartTypeResource(ChartType type) {
3131
if (GwtMaterialAmChart.isDebug()) {
3232
injectDebugJs(type.getName(), type.getJsResource());
33+
34+
if (type.getCssDebugResource() != null) {
35+
injectCss(type.getCssDebugResource());
36+
}
3337
} else {
3438
injectJs(type.getName(), type.getJsResource());
39+
40+
if (type.getCssResource() != null) {
41+
injectCss(type.getCssResource());
42+
}
3543
}
3644
}
3745

src/main/java/gwt/material/design/amcharts/client/ui/chart/resources/ResourceLoader.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222
import com.google.gwt.core.client.ScriptInjector;
2323
import com.google.gwt.dom.client.StyleInjector;
2424

25+
import java.util.HashMap;
26+
2527
public class ResourceLoader {
2628

29+
30+
static HashMap<String, String> bundles = new HashMap<>();
31+
2732
//TODO Unload all injected js
2833

2934
public static void injectJs(String name, String textResource) {
@@ -35,14 +40,18 @@ public static void injectDebugJs(String name, String textResource) {
3540
}
3641

3742
public static void directInjectJs(String resourceName, String textResource, boolean removeTag, boolean sourceUrl) {
38-
String text = textResource + (sourceUrl ?
39-
"//# sourceURL=" + resourceName + ".js" : "");
40-
41-
// Inject the script resource
42-
ScriptInjector.fromString(text)
43-
.setWindow(ScriptInjector.TOP_WINDOW)
44-
.setRemoveTag(removeTag)
45-
.inject();
43+
bundles.put(resourceName, textResource);
44+
45+
if (bundles.get(resourceName) != null) {
46+
String text = textResource + (sourceUrl ?
47+
"//# sourceURL=" + resourceName + ".js" : "");
48+
49+
// Inject the script resource
50+
ScriptInjector.fromString(text)
51+
.setWindow(ScriptInjector.TOP_WINDOW)
52+
.setRemoveTag(removeTag)
53+
.inject();
54+
}
4655
}
4756

4857
public static void injectCss(String resource) {

src/main/java/gwt/material/design/amcharts/client/ui/maps/Map.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@
1919
*/
2020
package gwt.material.design.amcharts.client.ui.maps;
2121

22-
import gwt.material.design.amcharts.client.ui.GwtMaterialAmChart;
2322
import gwt.material.design.amcharts.client.ui.chart.base.AbstractChart;
2423
import gwt.material.design.amcharts.client.ui.chart.base.constants.ChartType;
2524
import gwt.material.design.amcharts.client.ui.maps.base.constants.Projection;
2625
import gwt.material.design.amcharts.client.ui.maps.js.AmMap;
2726
import gwt.material.design.amcharts.client.ui.maps.js.options.*;
28-
import gwt.material.design.amcharts.client.ui.maps.resources.MapClientBundle;
29-
import gwt.material.design.amcharts.client.ui.maps.resources.MapClientDebugBundle;
30-
import gwt.material.design.client.MaterialDesign;
3127
import gwt.material.design.jquery.client.api.Functions;
3228

3329
/**
@@ -40,16 +36,6 @@
4036
//@formatter:on
4137
public class Map extends AbstractChart {
4238

43-
static {
44-
if (GwtMaterialAmChart.isDebug()) {
45-
MaterialDesign.injectDebugJs(MapClientDebugBundle.INSTANCE.amMapDebugJs());
46-
MaterialDesign.injectCss(MapClientDebugBundle.INSTANCE.ammapDebugCss());
47-
} else {
48-
MaterialDesign.injectJs(MapClientBundle.INSTANCE.amMapJs());
49-
MaterialDesign.injectCss(MapClientBundle.INSTANCE.ammapCss());
50-
}
51-
}
52-
5339
private AmMap amMap;
5440

5541
public Map() {

0 commit comments

Comments
 (0)