diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6109861 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/target +/.settings +/.classpath +/.project +/nb-configuration.xml \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 9c01c03..1f848cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,6 @@ jdk: - openjdk6 - openjdk7 - oraclejdk7 + - oraclejdk8 +after_success: + - mvn test jacoco:report coveralls:jacoco diff --git a/README.md b/README.md index 1612f7e..885437c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/geckoboard-java-api/highchart-java-api.svg?branch=master)](https://travis-ci.org/geckoboard-java-api/highchart-java-api) +[![Coverage Status](https://coveralls.io/repos/geckoboard-java-api/highchart-java-api/badge.png)](https://coveralls.io/r/geckoboard-java-api/highchart-java-api) Highchart java api ============= diff --git a/pom.xml b/pom.xml index c0d71d0..c554a47 100644 --- a/pom.xml +++ b/pom.xml @@ -1,19 +1,18 @@ - + 4.0.0 - - parent - nl.pvanassen - 0.1 - + uk.com.gamma highchart-java-api - 0.2-SNAPSHOT + 1 + Highchart java API A Java API to generate highchart json on the server side. http://www.pvanassen.nl + - Paul van Assen - http://www.pvanassen.nl + Gamma Associates Ltd + http://www.gamma.uk.com @@ -22,64 +21,40 @@ repo - - - pvanassen - Paul van Assen - source@pvanassen.nl - - + - 3.0.4 + 4.0.0 - - scm:git:git@github.com:pvanassen/highchart-java-api.git - scm:git:git@github.com:pvanassen/highchart-java-api.git - HEAD - https://github.com/pvanassen/highchart-java-api - - - GitHub Issues - https://github.com/pvanassen/highchart-java-api/issues - - - Jenkins - http://build.pvanassen.nl - + UTF-8 + 2.4 - - - com.google.code.gson - gson - 2.2.4 - - - junit - junit - 4.11 - test - - + - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - - + org.apache.maven.plugins maven-compiler-plugin + 3.1 - 1.6 - 1.6 + 1.8 + 1.8 + + + junit + junit + 4.11 + test + + + com.google.code.gson + gson + ${gson.version} + + diff --git a/src/main/java/nl/pvanassen/highchart/api/Axis.java b/src/main/java/nl/pvanassen/highchart/api/Axis.java index dafda8d..3bca828 100644 --- a/src/main/java/nl/pvanassen/highchart/api/Axis.java +++ b/src/main/java/nl/pvanassen/highchart/api/Axis.java @@ -1,108 +1,166 @@ package nl.pvanassen.highchart.api; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlTransient; - import nl.pvanassen.highchart.api.axis.AxisLabels; import nl.pvanassen.highchart.api.axis.AxisPlotLines; import nl.pvanassen.highchart.api.base.BaseObject; import nl.pvanassen.highchart.api.format.DateTimeLabelFormats; +import nl.pvanassen.highchart.api.shared.DashStyleType; +import nl.pvanassen.highchart.api.shared.EnumString; +import nl.pvanassen.highchart.api.shared.HexColor; +import nl.pvanassen.highchart.api.shared.Styleable; import nl.pvanassen.highchart.api.utils.ArrayString; import nl.pvanassen.highchart.api.utils.JsonArray; +import nl.pvanassen.highchart.api.utils.Utils; -@XmlAccessorType( XmlAccessType.NONE ) -public class Axis extends BaseObject { - - @XmlElement - private Integer maxZoom; - - @XmlElement - private Boolean startOnTick; +import java.awt.Color; - @XmlElement - private Double tickInterval; +public class Axis + extends BaseObject + implements Styleable { - @XmlElement - private Boolean showFirstLabel; - - @XmlElement - private Double min; - - @XmlElement - private Double max; + public enum Type { + LINEAR, + LOGARITHMIC, + DATETIME, + CATEGORY + } + + private ArrayString categories; + + private DateTimeLabelFormats dateTimeLabelFormats; + + private String gridLineColor; + + private String gridLineDashStyle; + + private Integer gridLineWidth; + + private AxisLabels labels; + + private String lineColor; + + private Integer lineWidth; + + private Double max; + + private Double min; + + private String minorGridLineColor; + + private String minorGridLineDashStyle; + + private Integer minorGridLineWidth; + + private Boolean opposite; + + private JsonArray plotLines; + + private Boolean reversed; + + private Boolean showEmpty; + + private Boolean showFirstLabel; - @XmlElement - private String type; + private Boolean showLastLabel; - @XmlElement( type = AxisLabels.class ) - private AxisLabels labels; + private Boolean startOnTick; - private DateTimeLabelFormats dateTimeLabelFormats; + private Double tickInterval; - @XmlTransient - private ArrayString categories; + private Double minTickInterval; - private JsonArray plotLines; + private Title title; + + private String type; - private Title title; + private String id; - public Axis() { - labels = null; - dateTimeLabelFormats = null; - categories = null; - title = null; + public Axis() { } + + @Override + public Axis style( + final Axis src) { + if(src == null) { + return this; + } + Utils.stylePrimitiveArray(this.categories, src.categories); + Utils.style(this.dateTimeLabelFormats, src.dateTimeLabelFormats); + this.gridLineColor = src.gridLineColor; + this.gridLineDashStyle = src.gridLineDashStyle; + this.gridLineWidth = src.gridLineWidth; + Utils.style(this.labels, src.labels); + this.lineColor = src.lineColor; + this.lineWidth = src.lineWidth; + this.max = src.max; + this.min = src.min; + this.minorGridLineColor = src.minorGridLineColor; + this.minorGridLineDashStyle = src.minorGridLineDashStyle; + this.minorGridLineWidth = src.minorGridLineWidth; + this.opposite = src.opposite; + this.plotLines = src.plotLines; + this.reversed = src.reversed; + this.showEmpty = src.showEmpty; + this.showFirstLabel = src.showFirstLabel; + this.showLastLabel = src.showLastLabel; + this.startOnTick = src.startOnTick; + this.tickInterval = src.tickInterval; + this.minTickInterval = src.minTickInterval; + Utils.style(this.title, src.title); + this.type = src.type; + this.id = src.id; + return this; } - @XmlTransient public ArrayString getCategories() { - if ( categories == null ) { + if (categories == null) { categories = new ArrayString(); } return categories; } public int getCategoriesLength() { - return ( categories != null ) ? categories.size() : 0; + return categories != null ? categories.size() : 0; } public DateTimeLabelFormats getDateTimeLabelFormats() { - if ( dateTimeLabelFormats == null ) { + if (dateTimeLabelFormats == null) { dateTimeLabelFormats = new DateTimeLabelFormats(); } return dateTimeLabelFormats; } public AxisLabels getLabels() { - if ( labels == null ) { + if (labels == null) { labels = new AxisLabels(); } return labels; } - public double getMax() { + public Double getMax() { return max; } - public int getMaxZoom() { - return maxZoom; - } - - public double getMin() { + public Double getMin() { return min; } public JsonArray getPlotLines() { + if(this.plotLines == null) { + this.plotLines = new JsonArray(); + } return plotLines; } - public double getTickInterval() { + public Double getTickInterval() { return tickInterval; } + public Double getMinTickInterval() { + return minTickInterval; + } + public Title getTitle() { - if ( title == null ) { + if (title == null) { title = new Title(); } return title; @@ -112,51 +170,264 @@ public String getType() { return type; } - public boolean isShowFirstLabel() { - return showFirstLabel; + public String getId() { + return id; } - public boolean isStartOnTick() { - return startOnTick; + public Axis setMax(Double max) { + this.max = max; + return this; } - public Axis setMax( double max ) { - this.max = max; + public Axis setMin(Double min) { + this.min = min; return this; } - public Axis setMaxZoom( int maxZoom ) { - this.maxZoom = maxZoom; + public Axis setTickInterval(Double tickInterval) { + this.tickInterval = tickInterval; return this; } - public Axis setMin( double min ) { - this.min = min; + public Axis setMinTickInterval(double minTickInterval) { + this.minTickInterval = minTickInterval; return this; } - public Axis setPlotLines( JsonArray plotLines ) { - this.plotLines = plotLines; + public Axis setType(Type type) { + this.type = EnumString.toString(type).toLowerCase(); return this; } - public Axis setShowFirstLabel( boolean showFirstLabel ) { - this.showFirstLabel = showFirstLabel; + public Axis setId(String id) { + this.id = id; return this; } + + /** + * @return the gridLineColor + */ + public String getGridLineColor() { + return gridLineColor; + } - public Axis setStartOnTick( boolean startOnTick ) { - this.startOnTick = startOnTick; + /** + * @param gridLineColor the gridLineColor to set + * @return + */ + public Axis setGridLineColor(Color gridLineColor) { + this.gridLineColor = HexColor.toString(gridLineColor); return this; } - public Axis setTickInterval( double tickInterval ) { - this.tickInterval = tickInterval; + /** + * @return the gridLineDashStyle + */ + public String getGridLineDashStyle() { + return gridLineDashStyle; + } + + /** + * @param gridLineDashStyle the gridLineDashStyle to set + * @return + */ + public Axis setGridLineDashStyle(DashStyleType gridLineDashStyle) { + this.gridLineDashStyle = EnumString.toString(gridLineDashStyle); + return this; + } + + /** + * @return the gridLineWidth + */ + public Integer getGridLineWidth() { + return gridLineWidth; + } + + /** + * @param gridLineWidth the gridLineWidth to set + * @return + */ + public Axis setGridLineWidth(Integer gridLineWidth) { + this.gridLineWidth = gridLineWidth; + return this; + } + + /** + * @return the lineColor + */ + public String getLineColor() { + return lineColor; + } + + /** + * @param lineColor the lineColor to set + * @return + */ + public Axis setLineColor(Color lineColor) { + this.lineColor = HexColor.toString(lineColor); + return this; + } + + /** + * @return the lineWidth + */ + public Integer getLineWidth() { + return lineWidth; + } + + /** + * @param lineWidth the lineWidth to set + * @return + */ + public Axis setLineWidth(Integer lineWidth) { + this.lineWidth = lineWidth; + return this; + } + + /** + * @return the minorGridLineColor + */ + public String getMinorGridLineColor() { + return minorGridLineColor; + } + + /** + * @param minorGridLineColor the minorGridLineColor to set + * @return + */ + public Axis setMinorGridLineColor(Color minorGridLineColor) { + this.minorGridLineColor = HexColor.toString(minorGridLineColor); + return this; + } + + /** + * @return the minorGridLineDashStyle + */ + public String getMinorGridLineDashStyle() { + return minorGridLineDashStyle; + } + + /** + * @param minorGridLineDashStyle the minorGridLineDashStyle to set + * @return + */ + public Axis setMinorGridLineDashStyle( + final DashStyleType minorGridLineDashStyle) { + this.minorGridLineDashStyle = + EnumString.toString( + minorGridLineDashStyle); return this; } - public Axis setType( String type ) { - this.type = type; + /** + * @return the minorGridLineWidth + */ + public Integer getMinorGridLineWidth() { + return minorGridLineWidth; + } + + /** + * @param minorGridLineWidth the minorGridLineWidth to set + * @return + */ + public Axis setMinorGridLineWidth(Integer minorGridLineWidth) { + this.minorGridLineWidth = minorGridLineWidth; + return this; + } + + /** + * @return the opposite + */ + public Boolean getOpposite() { + return opposite; + } + + /** + * @param opposite the opposite to set + * @return + */ + public Axis setOpposite(Boolean opposite) { + this.opposite = opposite; + return this; + } + + /** + * @return the reversed + */ + public Boolean getReversed() { + return reversed; + } + + /** + * @param reversed the reversed to set + * @return + */ + public Axis setReversed(Boolean reversed) { + this.reversed = reversed; + return this; + } + + /** + * @return the showEmpty + */ + public Boolean getShowEmpty() { + return showEmpty; + } + + /** + * @param showEmpty the showEmpty to set + * @return + */ + public Axis setShowEmpty(Boolean showEmpty) { + this.showEmpty = showEmpty; + return this; + } + + /** + * @return the showFirstLabel + */ + public Boolean getShowFirstLabel() { + return showFirstLabel; + } + + /** + * @param showFirstLabel the showFirstLabel to set + * @return + */ + public Axis setShowFirstLabel(Boolean showFirstLabel) { + this.showFirstLabel = showFirstLabel; + return this; + } + + /** + * @return the showLastLabel + */ + public Boolean getShowLastLabel() { + return showLastLabel; + } + + /** + * @param showLastLabel the showLastLabel to set + * @return + */ + public Axis setShowLastLabel(Boolean showLastLabel) { + this.showLastLabel = showLastLabel; + return this; + } + + /** + * @return the startOnTick + */ + public Boolean getStartOnTick() { + return startOnTick; + } + + /** + * @param startOnTick the startOnTick to set + * @return + */ + public Axis setStartOnTick(Boolean startOnTick) { + this.startOnTick = startOnTick; return this; } diff --git a/src/main/java/nl/pvanassen/highchart/api/Chart.java b/src/main/java/nl/pvanassen/highchart/api/Chart.java index f676573..5083240 100644 --- a/src/main/java/nl/pvanassen/highchart/api/Chart.java +++ b/src/main/java/nl/pvanassen/highchart/api/Chart.java @@ -4,9 +4,10 @@ import nl.pvanassen.highchart.api.shared.SeriesType; public class Chart extends BaseObject { - private String zoomType; - private String backgroundColor; + private String zoomType; + + private String backgroundColor; private Integer marginRight; @@ -16,11 +17,13 @@ public class Chart extends BaseObject { private Integer height; - private String defaultSeriesType; + private String defaultSeriesType; - private int marginLeft; + private Integer marginLeft; - private int marginTop; + private Integer marginTop; + + private String type; public String getBackgroundColor() { return backgroundColor; @@ -29,6 +32,10 @@ public String getBackgroundColor() { public String getDefaultSeriesType() { return defaultSeriesType; } + + public String getType() { + return type; + } public int getHeight() { return height; @@ -58,47 +65,52 @@ public String getZoomType() { return zoomType; } - public Chart setBackgroundColor( String backgroundColor ) { + public Chart setBackgroundColor(String backgroundColor) { this.backgroundColor = backgroundColor; return this; } - public Chart setDefaultSeriesType( SeriesType type ) { + public Chart setDefaultSeriesType(SeriesType type) { defaultSeriesType = type.name().toLowerCase(); return this; } + + public Chart setType(SeriesType type) { + this.type = type.name().toLowerCase(); + return this; + } - public Chart setHeight( int height ) { + public Chart setHeight(int height) { this.height = height; return this; } - public Chart setMarginBottom( int marginBottom ) { + public Chart setMarginBottom(int marginBottom) { this.marginBottom = marginBottom; return this; } - public Chart setMarginLeft( int marginLeft ) { + public Chart setMarginLeft(int marginLeft) { this.marginLeft = marginLeft; return this; } - public Chart setMarginRight( int marginRight ) { + public Chart setMarginRight(int marginRight) { this.marginRight = marginRight; return this; } - public Chart setMarginTop( int marginTop ) { + public Chart setMarginTop(int marginTop) { this.marginTop = marginTop; return this; } - public Chart setWidth( int width ) { + public Chart setWidth(int width) { this.width = width; return this; } - public Chart setZoomType( String zoomType ) { + public Chart setZoomType(String zoomType) { this.zoomType = zoomType; return this; } diff --git a/src/main/java/nl/pvanassen/highchart/api/ChartOptions.java b/src/main/java/nl/pvanassen/highchart/api/ChartOptions.java index 597f534..792331d 100644 --- a/src/main/java/nl/pvanassen/highchart/api/ChartOptions.java +++ b/src/main/java/nl/pvanassen/highchart/api/ChartOptions.java @@ -1,129 +1,145 @@ package nl.pvanassen.highchart.api; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElements; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; import nl.pvanassen.highchart.api.base.BaseObject; import nl.pvanassen.highchart.api.utils.JsonArray; -@XmlRootElement( name = "chartOptions" ) -@XmlAccessorType( XmlAccessType.NONE ) public class ChartOptions extends BaseObject { - @XmlTransient - private Chart chart; + private Chart chart; + + private JsonArray colors; - @XmlElement - private Credits credits; + private Credits credits; - @XmlElement - private Labels labels; + private Labels labels; - @XmlElement - private Legend legend; + private Legend legend; - @XmlElement - private PlotOptions plotOptions; + private PlotOptions plotOptions; - // @XmlTransient - @XmlElements( @XmlElement( name = "series", type = Series.class ) ) private JsonArray series; - @XmlElement - private Title title; + private Title title; - @XmlElement - private Title subtitle; + private Title subtitle; - @XmlElement - private Tooltip tooltip; + private Tooltip tooltip; - @XmlElement - private Axis xAxis; + private JsonArray xAxis; - @XmlElement - private Axis yAxis; + private JsonArray yAxis; + + private DrillDown drilldown; public Chart getChart() { - if ( chart == null ) { + if (chart == null) { chart = new Chart(); } return chart; } + + public JsonArray getColors() { + if(this.colors == null) { + this.colors = new JsonArray(); + } + return this.colors; + } public Credits getCredits() { - if ( credits == null ) { + if (credits == null) { credits = new Credits(); } return credits; } public Labels getLabels() { - if ( labels == null ) { + if (labels == null) { labels = new Labels(); } return labels; } public Legend getLegend() { - if ( legend == null ) { + if (legend == null) { legend = new Legend(); } return legend; } public PlotOptions getPlotOptions() { - if ( plotOptions == null ) { + if (plotOptions == null) { plotOptions = new PlotOptions(); } return plotOptions; } - @XmlTransient public JsonArray getSeries() { - if ( series == null ) { + if (series == null) { series = new JsonArray(); } return series; } public Title getSubtitle() { - if ( subtitle == null ) { + if (subtitle == null) { subtitle = new Title(); } return subtitle; } public Title getTitle() { - if ( title == null ) { + if (title == null) { title = new Title(); } return title; } public Tooltip getTooltip() { - if ( tooltip == null ) { + if (tooltip == null) { tooltip = new Tooltip(); } return tooltip; } + + public Axis getXAxis(int index) { + if(index < this.getXAxis().size()) { + return this.getXAxis().get(index); + } else { + this.getXAxis().add(new Axis()); + return this.getXAxis(index); + } + } - public Axis getXAxis() { - if ( xAxis == null ) { - xAxis = new Axis(); + public JsonArray getXAxis() { + if (xAxis == null) { + xAxis = new JsonArray(); } return xAxis; } + + public Axis getYAxis(int index) { + if(index < this.getYAxis().size()) { + return this.getYAxis().get(index); + } else { + this.getYAxis().add(new Axis()); + return this.getYAxis(index); + } + } - public Axis getYAxis() { - if ( yAxis == null ) { - yAxis = new Axis(); + public JsonArray getYAxis() { + if (yAxis == null) { + yAxis = new JsonArray(); } return yAxis; } + public DrillDown getDrilldown() { + if (drilldown == null) { + drilldown = new DrillDown(); + } + return drilldown; + } + + } diff --git a/src/main/java/nl/pvanassen/highchart/api/Credits.java b/src/main/java/nl/pvanassen/highchart/api/Credits.java index 4039936..33029ce 100644 --- a/src/main/java/nl/pvanassen/highchart/api/Credits.java +++ b/src/main/java/nl/pvanassen/highchart/api/Credits.java @@ -10,7 +10,7 @@ public boolean istEnabled() { return enabled; } - public Credits setEnabled( boolean enabled ) { + public Credits setEnabled(boolean enabled) { this.enabled = enabled; return this; } diff --git a/src/main/java/nl/pvanassen/highchart/api/DrillDown.java b/src/main/java/nl/pvanassen/highchart/api/DrillDown.java new file mode 100644 index 0000000..c92b008 --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/DrillDown.java @@ -0,0 +1,29 @@ + + +package nl.pvanassen.highchart.api; + +import nl.pvanassen.highchart.api.base.BaseObject; +import nl.pvanassen.highchart.api.drilldown.DrillUpButton; +import nl.pvanassen.highchart.api.utils.JsonArray; + +public class DrillDown extends BaseObject { + + private JsonArray series; + + private DrillUpButton drillUpButton; + + public JsonArray getSeries() { + if (series == null) { + series = new JsonArray(); + } + return series; + } + + public DrillUpButton getDrillUpButton() { + if (drillUpButton == null) { + drillUpButton = new DrillUpButton(); + } + return drillUpButton; + } + +} diff --git a/src/main/java/nl/pvanassen/highchart/api/HighchartsFactory.java b/src/main/java/nl/pvanassen/highchart/api/HighchartsFactory.java index a8def01..f7a120a 100644 --- a/src/main/java/nl/pvanassen/highchart/api/HighchartsFactory.java +++ b/src/main/java/nl/pvanassen/highchart/api/HighchartsFactory.java @@ -1,6 +1,5 @@ package nl.pvanassen.highchart.api; - public class HighchartsFactory { public HighchartsFactory() { diff --git a/src/main/java/nl/pvanassen/highchart/api/Labels.java b/src/main/java/nl/pvanassen/highchart/api/Labels.java index e450346..0af272c 100644 --- a/src/main/java/nl/pvanassen/highchart/api/Labels.java +++ b/src/main/java/nl/pvanassen/highchart/api/Labels.java @@ -1,31 +1,32 @@ package nl.pvanassen.highchart.api; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlTransient; -import javax.xml.bind.annotation.XmlType; - import nl.pvanassen.highchart.api.base.BaseObject; import nl.pvanassen.highchart.api.label.LabelsItems; +import nl.pvanassen.highchart.api.shared.Style; import nl.pvanassen.highchart.api.utils.JsonArray; -@XmlAccessorType( XmlAccessType.NONE ) -@XmlType( namespace = "chart-options" ) public class Labels extends BaseObject { - @XmlTransient private JsonArray items; + + private Style style; public Labels() { } - @XmlTransient public JsonArray getItems() { - if ( items == null ) { + if (items == null) { items = new JsonArray(); } return items; } + + public Style getStyle() { + if(this.style == null) { + this.style = new Style(); + } + return this.style; + } } diff --git a/src/main/java/nl/pvanassen/highchart/api/Legend.java b/src/main/java/nl/pvanassen/highchart/api/Legend.java index 8b29a50..e92e26e 100644 --- a/src/main/java/nl/pvanassen/highchart/api/Legend.java +++ b/src/main/java/nl/pvanassen/highchart/api/Legend.java @@ -1,35 +1,61 @@ package nl.pvanassen.highchart.api; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; - +import java.awt.Color; import nl.pvanassen.highchart.api.base.BaseObject; +import nl.pvanassen.highchart.api.shared.Style; +import nl.pvanassen.highchart.api.shared.AlignType; +import nl.pvanassen.highchart.api.shared.EnumString; +import nl.pvanassen.highchart.api.shared.HexColor; +import nl.pvanassen.highchart.api.shared.VerticalAlignType; -@XmlAccessorType( XmlAccessType.NONE ) public class Legend extends BaseObject { + + public enum LegendLayoutType { + horizontal, + vertical + } - private Boolean reversed; + private String align; + private String backgroundColor; + + private String borderColor; + + private Integer borderRadius; + + private Integer borderWidth; + private Boolean enabled; + + private Boolean floating; + + private Integer itemDistance; + + private Style itemStyle; + + private String labelFormat; + + private String layout; + + private Integer maxHeight; + + private Boolean reversed; + + private Boolean useHTML; - private String align; - - private String layout; - - private String verticalAlign; - - @XmlElement + private String verticalAlign; + + private Integer width; + private Integer x; - @XmlElement private Integer y; public String getAlign() { return align; } - public boolean getEnabled() { + public Boolean getEnabled() { return enabled; } @@ -41,54 +67,229 @@ public String getVerticalAlign() { return verticalAlign; } - public int getX() { + public Integer getX() { return x; } - public int getY() { + public Integer getY() { return y; } - public boolean isReversed() { + public Boolean getReversed() { return reversed; } - @XmlElement - public Legend setAlign( String align ) { - this.align = align; + public Legend setAlign(AlignType align) { + this.align = EnumString.toString(align); return this; } - public Legend setEnabled( boolean enabled ) { + public Legend setEnabled(Boolean enabled) { this.enabled = enabled; return this; } - @XmlElement - public Legend setLayout( String layout ) { - this.layout = layout; + public Legend setLayout(LegendLayoutType layout) { + this.layout = EnumString.toString(layout); return this; } - public Legend setReversed( boolean reversed ) { + public Legend setReversed(Boolean reversed) { this.reversed = reversed; return this; } - @XmlElement - public Legend setVerticalAlign( String verticalAlign ) { - this.verticalAlign = verticalAlign; + public Legend setVerticalAlign(VerticalAlignType verticalAlign) { + this.verticalAlign = EnumString.toString(verticalAlign); return this; } - public Legend setX( int x ) { + public Legend setX(int x) { this.x = x; return this; } - public Legend setY( int y ) { + public Legend setY(int y) { this.y = y; return this; } + /** + * @return the backgroundColor + */ + public String getBackgroundColor() { + return backgroundColor; + } + + /** + * @param backgroundColor the backgroundColor to set + * @return + */ + public Legend setBackgroundColor(String backgroundColor) { + this.backgroundColor = backgroundColor; + return this; + } + + /** + * @param backgroundColor the b + * @return ackgroundColor to set + */ + public Legend setBackgroundColor(Color backgroundColor) { + this.backgroundColor = HexColor.toString(backgroundColor); + return this; + } + + /** + * @return the borderColor + */ + public String getBorderColor() { + return borderColor; + } + + /** + * @param borderColor the borderColor to set + * @return + */ + public Legend setBorderColor(Color borderColor) { + this.borderColor = HexColor.toString(borderColor); + return this; + } + + /** + * @return the borderRadius + */ + public Integer getBorderRadius() { + return borderRadius; + } + + /** + * @param borderRadius the borderRadius to set + * @return + */ + public Legend setBorderRadius(Integer borderRadius) { + this.borderRadius = borderRadius; + return this; + } + + /** + * @return the borderWidth + */ + public Integer getBorderWidth() { + return borderWidth; + } + + /** + * @param borderWidth the borderWidth to set + * @return + */ + public Legend setBorderWidth(Integer borderWidth) { + this.borderWidth = borderWidth; + return this; + } + + /** + * @return the floating + */ + public Boolean getFloating() { + return floating; + } + + /** + * @param floating the floating to set + * @return + */ + public Legend setFloating(Boolean floating) { + this.floating = floating; + return this; + } + + /** + * @return the itemDistance + */ + public Integer getItemDistance() { + return itemDistance; + } + + /** + * @param itemDistance the itemDistance to set + * @return + */ + public Legend setItemDistance(Integer itemDistance) { + this.itemDistance = itemDistance; + return this; + } + + /** + * @return the itemStyle + */ + public Style getItemStyle() { + if(this.itemStyle == null) { + this.itemStyle = new Style(); + } + return itemStyle; + } + + /** + * @return the labelFormat + */ + public String getLabelFormat() { + return labelFormat; + } + + /** + * @param labelFormat the labelFormat to set + * @return + */ + public Legend setLabelFormat(String labelFormat) { + this.labelFormat = labelFormat; + return this; + } + + /** + * @return the maxHeight + */ + public Integer getMaxHeight() { + return maxHeight; + } + + /** + * @param maxHeight the maxHeight to set + * @return + */ + public Legend setMaxHeight(Integer maxHeight) { + this.maxHeight = maxHeight; + return this; + } + + /** + * @return the useHTML + */ + public Boolean getUseHTML() { + return useHTML; + } + + /** + * @param useHTML the useHTML to set + * @return + */ + public Legend setUseHTML(Boolean useHTML) { + this.useHTML = useHTML; + return this; + } + + /** + * @return the width + */ + public Integer getWidth() { + return width; + } + + /** + * @param width the width to set + * @return + */ + public Legend setWidth(Integer width) { + this.width = width; + return this; + } } diff --git a/src/main/java/nl/pvanassen/highchart/api/NullableDouble.java b/src/main/java/nl/pvanassen/highchart/api/NullableDouble.java new file mode 100644 index 0000000..579bad1 --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/NullableDouble.java @@ -0,0 +1,49 @@ +/* + * Copyright 2015 Gamma Associates Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.pvanassen.highchart.api; + +/** + * + * @author shaun.lefeuvre + */ +public class NullableDouble { + + private final Double value; + + public static final NullableDouble NULL_INSTANCE = + new NullableDouble(); + + public static NullableDouble of( + final Double input) { + if(input == null) { + return NULL_INSTANCE; + } + return new NullableDouble(input); + } + + private NullableDouble() { + this.value = null; + } + + private NullableDouble( + final Double value) { + this.value = value; + } + + public Double getValue() { + return this.value; + } +} diff --git a/src/main/java/nl/pvanassen/highchart/api/PlotOptions.java b/src/main/java/nl/pvanassen/highchart/api/PlotOptions.java index 276fe2d..9549f13 100644 --- a/src/main/java/nl/pvanassen/highchart/api/PlotOptions.java +++ b/src/main/java/nl/pvanassen/highchart/api/PlotOptions.java @@ -1,61 +1,239 @@ package nl.pvanassen.highchart.api; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; - import nl.pvanassen.highchart.api.base.BaseObject; import nl.pvanassen.highchart.api.plotoption.PlotOptionsSeries; -@XmlAccessorType( XmlAccessType.NONE ) public class PlotOptions extends BaseObject { - @XmlElement - private final PlotOptionsSeries area, areaspline, line, pie, series, - spline; + private PlotOptionsSeries area; + + private PlotOptionsSeries arearange; + + private PlotOptionsSeries areaspline; + + private PlotOptionsSeries areasplinerange; + + private PlotOptionsSeries bar; + + private PlotOptionsSeries boxplot; + + private PlotOptionsSeries bubble; + + private PlotOptionsSeries column; + + private PlotOptionsSeries columnrange; + + private PlotOptionsSeries errorbar; + + private PlotOptionsSeries funnel; + + private PlotOptionsSeries gauge; + + private PlotOptionsSeries heatmap; + + private PlotOptionsSeries line; + + private PlotOptionsSeries pie; + + private PlotOptionsSeries pyramid; + + private PlotOptionsSeries scatter; - private PlotOptionsSeries column, bar; + private PlotOptionsSeries series; + + private PlotOptionsSeries solidgauge; + + private PlotOptionsSeries spline; + + private PlotOptionsSeries waterfall; public PlotOptions() { - area = new PlotOptionsSeries(); - areaspline = new PlotOptionsSeries(); - bar = new PlotOptionsSeries(); - column = new PlotOptionsSeries(); - line = new PlotOptionsSeries(); - pie = new PlotOptionsSeries(); - series = new PlotOptionsSeries(); - spline = new PlotOptionsSeries(); + super(); } public PlotOptionsSeries getArea() { + if (area == null) { + area = new PlotOptionsSeries(); + } return area; } - public PlotOptionsSeries getAreaspline() { + public PlotOptionsSeries getAreaSpline() { + if (areaspline == null) { + areaspline = new PlotOptionsSeries(); + } return areaspline; } public PlotOptionsSeries getBar() { + if (bar == null) { + bar = new PlotOptionsSeries(); + } return bar; } public PlotOptionsSeries getColumn() { + if (column == null) { + column = new PlotOptionsSeries(); + } return column; } public PlotOptionsSeries getLine() { + if (line == null) { + line = new PlotOptionsSeries(); + } return line; } public PlotOptionsSeries getPie() { + if (pie == null) { + pie = new PlotOptionsSeries(); + } return pie; } public PlotOptionsSeries getSeries() { + if (series == null) { + series = new PlotOptionsSeries(); + } return series; } public PlotOptionsSeries getSpline() { + if (spline == null) { + spline = new PlotOptionsSeries(); + } return spline; } + + /** + * @return the arearange + */ + public PlotOptionsSeries getAreaRange() { + if (arearange == null) { + arearange = new PlotOptionsSeries(); + } + return arearange; + } + + /** + * @return the areasplinerange + */ + public PlotOptionsSeries getAreaSplineRange() { + if (areasplinerange == null) { + areasplinerange = new PlotOptionsSeries(); + } + return areasplinerange; + } + + /** + * @return the boxplot + */ + public PlotOptionsSeries getBoxPlot() { + if (boxplot == null) { + boxplot = new PlotOptionsSeries(); + } + return boxplot; + } + + /** + * @return the bubble + */ + public PlotOptionsSeries getBubble() { + if (bubble == null) { + bubble = new PlotOptionsSeries(); + } + return bubble; + } + + /** + * @return the columnrange + */ + public PlotOptionsSeries getColumnRange() { + if (columnrange == null) { + columnrange = new PlotOptionsSeries(); + } + return columnrange; + } + + /** + * @return the errorbar + */ + public PlotOptionsSeries getErrorBar() { + if (errorbar == null) { + errorbar = new PlotOptionsSeries(); + } + return errorbar; + } + + /** + * @return the funnel + */ + public PlotOptionsSeries getFunnel() { + if (funnel == null) { + funnel = new PlotOptionsSeries(); + } + return funnel; + } + + /** + * @return the gauge + */ + public PlotOptionsSeries getGauge() { + if (gauge == null) { + gauge = new PlotOptionsSeries(); + } + return gauge; + } + + /** + * @return the heatmap + */ + public PlotOptionsSeries getHeatmap() { + if (heatmap == null) { + heatmap = new PlotOptionsSeries(); + } + return heatmap; + } + + /** + * @return the pyramid + */ + public PlotOptionsSeries getPyramid() { + if (pyramid == null) { + pyramid = new PlotOptionsSeries(); + } + return pyramid; + } + + /** + * @return the scatter + */ + public PlotOptionsSeries getScatter() { + if (scatter == null) { + scatter = new PlotOptionsSeries(); + } + return scatter; + } + + /** + * @return the solidgauge + */ + public PlotOptionsSeries getSolidGauge() { + if (solidgauge == null) { + solidgauge = new PlotOptionsSeries(); + } + return solidgauge; + } + + /** + * @return the waterfall + */ + public PlotOptionsSeries getWaterfall() { + if (waterfall == null) { + waterfall = new PlotOptionsSeries(); + } + return waterfall; + } } diff --git a/src/main/java/nl/pvanassen/highchart/api/Point.java b/src/main/java/nl/pvanassen/highchart/api/Point.java index 17d8d71..d71009d 100644 --- a/src/main/java/nl/pvanassen/highchart/api/Point.java +++ b/src/main/java/nl/pvanassen/highchart/api/Point.java @@ -1,28 +1,59 @@ package nl.pvanassen.highchart.api; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; - +import java.awt.Color; import nl.pvanassen.highchart.api.base.BaseObject; +import nl.pvanassen.highchart.api.plotoption.PlotOptionsDataLabels; +import nl.pvanassen.highchart.api.plotoption.PlotOptionsMarker; +import nl.pvanassen.highchart.api.shared.HexColor; +import nl.pvanassen.highchart.api.shared.Styleable; +import nl.pvanassen.highchart.api.utils.Utils; -@XmlAccessorType( XmlAccessType.NONE ) -public class Point extends BaseObject { - - @XmlElement - private Double x; - - @XmlElement - private Double y; - - private Boolean selected, sliced; - - private String color; - - private String name; +public class Point + extends BaseObject + implements Styleable { + + private String color; + + private PlotOptionsDataLabels dataLabels; + + private String drilldown; + + private String id; + + private Boolean isIntermediateSum; + + private Boolean isSum; + + private PlotOptionsMarker marker; + + private String name; + + private Boolean sliced; + + private NullableDouble x; - public Point() { + private NullableDouble y; + + private NullableDouble z; + + @Override + public Point style( + final Point src) { + if(src == null) { + return this; + } + this.color = src.color; + Utils.style(this.dataLabels, src.dataLabels); + this.drilldown = src.drilldown; + this.id = src.id; + this.isIntermediateSum = src.isIntermediateSum; + this.isSum = src.isSum; + Utils.style(this.marker, src.marker); + this.name = src.name; + this.sliced = src.sliced; + return this; } + public String getColor() { return color; @@ -32,50 +63,194 @@ public String getName() { return name; } - public boolean getSelected() { - return selected; + public Double getX() { + return x.getValue(); } - public double getX() { - return x; + public Double getY() { + return y.getValue(); } - public double getY() { - return y; + /** + * @return the z + */ + public Double getZ() { + return z.getValue(); + } + + public Point setZ(double z) { + this.z = NullableDouble.of(z); + return this; } - public boolean isSliced() { - return sliced; + /** + * @param z the z to set + */ + public Point setZ(Double z) { + this.z = NullableDouble.of(z); + return this; } - public Point setColor( String color ) { + public Point setColor(String color) { this.color = color; return this; } + + public Point setColor(Color color) { + this.color = HexColor.toString(color); + return this; + } - public Point setName( String name ) { + public Point setName(String name) { this.name = name; return this; } + + public Point setX(double x) { + this.x = NullableDouble.of(x); + return this; + } + + public Point setX(Double x) { + this.x = NullableDouble.of(x); + return this; + } + + public Point setY(double y) { + this.y = NullableDouble.of(y); + return this; + } - public Point setSelected( boolean selected ) { - this.selected = selected; + public Point setY(Double y) { + this.y = NullableDouble.of(y); return this; } - public Point setSliced( boolean sliced ) { - this.sliced = sliced; + /** + * Individual data label for each point. The options are the same as + * the ones for plotOptions.series.dataLabels + * @return the dataLabels + */ + public PlotOptionsDataLabels getDataLabels() { + if(this.dataLabels == null) { + this.dataLabels = new PlotOptionsDataLabels(); + } + return dataLabels; + } + + /** + * The id of a series in the drilldown.series array to use for a + * drilldown for this point. + * @return the drilldown + */ + public String getDrilldown() { + return drilldown; + } + + /** + * The id of a series in the drilldown.series array to use for a + * drilldown for this point. + * @param drilldown the drilldown to set + * @return + */ + public Point setDrilldown(String drilldown) { + this.drilldown = drilldown; return this; } - public Point setX( double x ) { - this.x = x; + /** + * An id for the point. This can be used after render time to get a + * pointer to the point object through chart.get(). + * @return the id + */ + public String getId() { + return id; + } + + /** + * An id for the point. This can be used after render time to get a + * pointer to the point object through chart.get(). + * @param id the id to set + * @return + */ + public Point setId(String id) { + this.id = id; return this; } - public Point setY( double y ) { - this.y = y; + /** + * Waterfall series only. When this property is true, the points acts + * as a summary column for the values added or subtracted since the + * last intermediate sum, or since the start of the series. + * The y value is ignored. Defaults to false. + * @return the isIntermediateSum + */ + public Boolean getIsIntermediateSum() { + return isIntermediateSum; + } + + /** + * Waterfall series only. When this property is true, the points acts + * as a summary column for the values added or subtracted since the + * last intermediate sum, or since the start of the series. + * The y value is ignored. Defaults to false. + * @param isIntermediateSum the isIntermediateSum to set + * @return + */ + public Point setIsIntermediateSum(Boolean isIntermediateSum) { + this.isIntermediateSum = isIntermediateSum; return this; } -} \ No newline at end of file + /** + * Waterfall series only. When this property is true, the point display + * the total sum across the entire series. + * The y value is ignored. Defaults to false. + * @return the isSum + */ + public Boolean getIsSum() { + return isSum; + } + + /** + * Waterfall series only. When this property is true, the point display + * the total sum across the entire series. + * The y value is ignored. Defaults to false. + * @param isSum the isSum to set + * @return + */ + public Point setIsSum(Boolean isSum) { + this.isSum = isSum; + return this; + } + + /** + * @return the marker + */ + public PlotOptionsMarker getMarker() { + if(this.marker == null) { + this.marker = new PlotOptionsMarker(); + } + return marker; + } + + /** + * Pie series only. Whether to display a slice offset from the center. + * Defaults to false. + * @return the sliced + */ + public Boolean getSliced() { + return sliced; + } + + /** + * Pie series only. Whether to display a slice offset from the center. + * Defaults to false. + * @param sliced the sliced to set + * @return + */ + public Point setSliced(Boolean sliced) { + this.sliced = sliced; + return this; + } +} diff --git a/src/main/java/nl/pvanassen/highchart/api/Series.java b/src/main/java/nl/pvanassen/highchart/api/Series.java index 1f9b065..4d3cdc5 100644 --- a/src/main/java/nl/pvanassen/highchart/api/Series.java +++ b/src/main/java/nl/pvanassen/highchart/api/Series.java @@ -1,117 +1,198 @@ package nl.pvanassen.highchart.api; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlElements; -import javax.xml.bind.annotation.XmlTransient; -import javax.xml.bind.annotation.XmlType; - -import nl.pvanassen.highchart.api.base.BaseObject; -import nl.pvanassen.highchart.api.plotoption.PlotMarkerStates; -import nl.pvanassen.highchart.api.serie.SeriesCenter; +import nl.pvanassen.highchart.api.plotoption.PlotOptionsSeries; +import nl.pvanassen.highchart.api.shared.SeriesType; import nl.pvanassen.highchart.api.utils.JsonArray; - -@XmlAccessorType( XmlAccessType.NONE ) -@XmlType( namespace = "chartoptions" ) -public class Series extends BaseObject { - - @XmlElement( type = PlotMarkerStates.class ) - private PlotMarkerStates states; - - @XmlElements( @XmlElement( name = "data", type = Point.class ) ) - private Object data; - - @XmlElement - private String color; - - @XmlElement - private String name; - - @XmlElement - private String type; - - @XmlElement - private String size; - - private SeriesCenter center; - - public String getCenterX() { - return ( center != null ) ? center.getX() : null; +import nl.pvanassen.highchart.api.utils.Utils; + +public class Series extends PlotOptionsSeries { + + private JsonArray data; + + private String id; + + private String name; + + private String stack; + + private String type; + + private Integer xAxis; + + private Integer yAxis; + + private Integer zIndex; + + public Series style(final Series src) { + super.style(src); + + if(src == null) { + return this; + } + + this.id = src.id; + this.name = src.name; + this.stack = src.stack; + this.type = src.type; + this.xAxis = src.xAxis; + this.yAxis = src.yAxis; + Utils.styleArray(this.data, src.data); + this.zIndex = src.zIndex; + return this; } - public String getCenterY() { - return ( center != null ) ? center.getY() : null; + public JsonArray getData() { + if (data == null) { + data = new JsonArray(); + } + return data; } - public String getColor() { - return color; + /** + * An id for the series. This can be used after render time to get a + * pointer to the series object through chart.get(). + * @return the id + */ + public String getId() { + return id; } - @SuppressWarnings( "unchecked" ) - public JsonArray getData() { - if ( data == null ) { - data = new JsonArray(); - } - return ( JsonArray ) data; + /** + * An id for the series. This can be used after render time to get a + * pointer to the series object through chart.get(). + * @param id the id to set + * @return + */ + public Series setId(String id) { + this.id = id; + return this; } + /** + * The name of the series as shown in the legend, tooltip etc. + * @return the name + */ public String getName() { return name; } - public String getSize() { - return size; + /** + * The name of the series as shown in the legend, tooltip etc. + * @param name the name to set + * @return + */ + public Series setName(String name) { + this.name = name; + return this; } - public PlotMarkerStates getStates() { - if ( states == null ) { - states = new PlotMarkerStates(); - } - return states; + /** + * This option allows grouping series in a stacked chart. The stack option + * can be a string or a number or anything else, as long as the grouped + * series' stack options match each other. + * @return the stack + */ + public String getStack() { + return stack; } + /** + * This option allows grouping series in a stacked chart. The stack option + * can be a string or a number or anything else, as long as the grouped + * series' stack options match each other. + * @param stack the stack to set + * @return + */ + public Series setStack(String stack) { + this.stack = stack; + return this; + } + + /** + * The type of series + * @return the type + */ public String getType() { return type; } - public Series setCenter( String x, String y ) { - if ( center == null ) { - center = new SeriesCenter(); + /** + * The type of series + * @param type the type to set + * @return + */ + public Series setType(SeriesType type) { + if(type != null) { + this.type = type.name().toLowerCase(); + } else { + this.type = null; } - center.setX( x ); - center.setY( y ); return this; } - public Series setColor( String color ) { - this.color = color; - return this; + /** + * When using dual or multiple x axes, this number defines which xAxis the + * particular series is connected to. It refers to either the axis id or + * the index of the axis in the xAxis array, with 0 being the first. + * Defaults to 0. + * @return the xAxis + */ + public Integer getXAxis() { + return xAxis; } - @XmlTransient - public Series setData( JsonArray data ) { - this.data = data; + /** + * When using dual or multiple x axes, this number defines which xAxis the + * particular series is connected to. It refers to either the axis id or + * the index of the axis in the xAxis array, with 0 being the first. + * Defaults to 0. + * @param xAxis the xAxis to set + * @return + */ + public Series setXAxis(Integer xAxis) { + this.xAxis = xAxis; return this; } - public Series setName( String name ) { - this.name = name; - return this; + /** + * When using dual or multiple y axes, this number defines which yAxis the + * particular series is connected to. It refers to either the axis id or + * the index of the axis in the yAxis array, with 0 being the first. + * Defaults to 0. + * @return the yAxis + */ + public Integer getYAxis() { + return yAxis; } - public Series setSize( String size ) { - this.size = size; + /** + * When using dual or multiple y axes, this number defines which yAxis the + * particular series is connected to. It refers to either the axis id or + * the index of the axis in the yAxis array, with 0 being the first. + * Defaults to 0. + * @param yAxis the yAxis to set + * @return + */ + public Series setYAxis(Integer yAxis) { + this.yAxis = yAxis; return this; } - public Series setStates( PlotMarkerStates states ) { - this.states = states; - return this; + /** + * Define the visual z index of the series. + * @return the zIndex + */ + public Integer getZIndex() { + return zIndex; } - public Series setType( String type ) { - this.type = type; + /** + * Define the visual z index of the series. + * @param zIndex the zIndex to set + * @return + */ + public Series setZIndex(Integer zIndex) { + this.zIndex = zIndex; return this; } } diff --git a/src/main/java/nl/pvanassen/highchart/api/Title.java b/src/main/java/nl/pvanassen/highchart/api/Title.java index 1706839..67228bc 100644 --- a/src/main/java/nl/pvanassen/highchart/api/Title.java +++ b/src/main/java/nl/pvanassen/highchart/api/Title.java @@ -1,34 +1,59 @@ package nl.pvanassen.highchart.api; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; - import nl.pvanassen.highchart.api.base.BaseObject; -import nl.pvanassen.highchart.api.base.Style; - -@XmlAccessorType( XmlAccessType.NONE ) -public class Title extends BaseObject { +import nl.pvanassen.highchart.api.shared.Style; +import nl.pvanassen.highchart.api.shared.AlignType; +import nl.pvanassen.highchart.api.shared.EnumString; +import nl.pvanassen.highchart.api.shared.Styleable; +import nl.pvanassen.highchart.api.shared.VerticalAlignType; +import nl.pvanassen.highchart.api.utils.Utils; - @XmlElement - private String text; +public class Title + extends BaseObject + implements Styleable { + + private String align; + + private Boolean floating; + + private Integer margin; + + private Style style; - private Style style; + private String text; - @XmlElement - private Integer margin; + private Boolean useHTML; + + private String verticalAlign; + + private Integer x; + + private Integer y; public Title() { - style = null; - text = ""; + this.text = ""; } - - public int getMargin() { - return margin; + + @Override + public Title style( + final Title src) { + if(src == null) { + return this; + } + this.align = src.align; + this.floating = src.floating; + this.margin = src.margin; + Utils.style(this.style, src.style); + this.text = src.text; + this.useHTML = src.useHTML; + this.verticalAlign = src.verticalAlign; + this.x = src.x; + this.y = src.y; + return this; } public Style getStyle() { - if ( style == null ) { + if (style == null) { style = new Style(); } return style; @@ -38,14 +63,120 @@ public String getText() { return text; } - public Title setMargin( int margin ) { + public Title setText(String text) { + this.text = text; + return this; + } + + /** + * @return the align + */ + public String getAlign() { + return align; + } + + /** + * @param align the align to set + * @return + */ + public Title setAlign(AlignType align) { + this.align = EnumString.toString(align); + return this; + } + + /** + * @return the floating + */ + public Boolean getFloating() { + return floating; + } + + /** + * @param floating the floating to set + * @return + */ + public Title setFloating(Boolean floating) { + this.floating = floating; + return this; + } + + /** + * @return the margin + */ + public Integer getMargin() { + return margin; + } + + /** + * @param margin the margin to set + * @return + */ + public Title setMargin(Integer margin) { this.margin = margin; return this; } - public Title setText( String text ) { - this.text = text; + /** + * @return the useHTML + */ + public Boolean getUseHTML() { + return useHTML; + } + + /** + * @param useHTML the useHTML to set + * @return + */ + public Title setUseHTML(Boolean useHTML) { + this.useHTML = useHTML; return this; } + /** + * @return the verticalAlign + */ + public String getVerticalAlign() { + return verticalAlign; + } + + /** + * @param verticalAlign the verticalAlign to set + * @return + */ + public Title setVerticalAlign(VerticalAlignType verticalAlign) { + this.verticalAlign = EnumString.toString(verticalAlign); + return this; + } + + /** + * @return the x + */ + public Integer getX() { + return x; + } + + /** + * @param x the x to set + * @return + */ + public Title setX(Integer x) { + this.x = x; + return this; + } + + /** + * @return the y + */ + public Integer getY() { + return y; + } + + /** + * @param y the y to set + * @return + */ + public Title setY(Integer y) { + this.y = y; + return this; + } } diff --git a/src/main/java/nl/pvanassen/highchart/api/Tooltip.java b/src/main/java/nl/pvanassen/highchart/api/Tooltip.java index 89fc3c2..6a4048d 100644 --- a/src/main/java/nl/pvanassen/highchart/api/Tooltip.java +++ b/src/main/java/nl/pvanassen/highchart/api/Tooltip.java @@ -1,36 +1,372 @@ package nl.pvanassen.highchart.api; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; - +import java.awt.Color; import nl.pvanassen.highchart.api.base.BaseObject; +import nl.pvanassen.highchart.api.shared.Style; +import nl.pvanassen.highchart.api.shared.HexColor; -@XmlAccessorType( XmlAccessType.NONE ) public class Tooltip extends BaseObject { + + private Boolean animation; + + private String backgroundColor; + + private String borderColor; + + private Integer borderRadius; + + private Integer borderWidth; - @XmlElement private Boolean crosshairs; + + private Boolean enabled; + + private String footerFormat; + + private String headerFormat; + + private String pointFormat; + + private Boolean shadow; + + private String shape; - @XmlElement private Boolean shared; + + private Integer snap; + + private Style style; + + private Boolean useHTML; + + private Integer valueDecimals; + + private String valuePrefix; + + private String valueSuffix; + + private String xDateFormat; + + /** + * @return the animation + */ + public Boolean getAnimation() { + return animation; + } + + /** + * @param animation the animation to set + * @return + */ + public Tooltip setAnimation(Boolean animation) { + this.animation = animation; + return this; + } + + /** + * @return the backgroundColor + */ + public String getBackgroundColor() { + return backgroundColor; + } + + /** + * @param backgroundColor the backgroundColor to set + * @return + */ + public Tooltip setBackgroundColor(String backgroundColor) { + this.backgroundColor = backgroundColor; + return this; + } + + /** + * @param backgroundColor the backgroundColor to set + * @return + */ + public Tooltip setBackgroundColor(Color backgroundColor) { + this.backgroundColor = HexColor.toString(backgroundColor); + return this; + } + + /** + * @return the borderColor + */ + public String getBorderColor() { + return borderColor; + } + + /** + * @param borderColor the borderColor to set + * @return + */ + public Tooltip setBorderColor(Color borderColor) { + this.borderColor = HexColor.toString(borderColor); + return this; + } + + /** + * @return the borderRadius + */ + public Integer getBorderRadius() { + return borderRadius; + } + + /** + * @param borderRadius the borderRadius to set + * @return + */ + public Tooltip setBorderRadius(Integer borderRadius) { + this.borderRadius = borderRadius; + return this; + } - public boolean isCrosshairs() { + /** + * @return the borderWidth + */ + public Integer getBorderWidth() { + return borderWidth; + } + + /** + * @param borderWidth the borderWidth to set + * @return + */ + public Tooltip setBorderWidth(Integer borderWidth) { + this.borderWidth = borderWidth; + return this; + } + + /** + * @return the crosshairs + */ + public Boolean getCrosshairs() { return crosshairs; } - public boolean isShared() { - return shared; + /** + * @param crosshairs the crosshairs to set + * @return + */ + public Tooltip setCrosshairs(Boolean crosshairs) { + this.crosshairs = crosshairs; + return this; + } + + /** + * @return the enabled + */ + public Boolean getEnabled() { + return enabled; } - public Tooltip setCrosshairs( boolean b ) { - crosshairs = b; + /** + * @param enabled the enabled to set + * @return + */ + public Tooltip setEnabled(Boolean enabled) { + this.enabled = enabled; return this; } - public Tooltip setShared( boolean shared ) { + /** + * @return the footerFormat + */ + public String getFooterFormat() { + return footerFormat; + } + + /** + * @param footerFormat the footerFormat to set + * @return + */ + public Tooltip setFooterFormat(String footerFormat) { + this.footerFormat = footerFormat; + return this; + } + + /** + * @return the headerFormat + */ + public String getHeaderFormat() { + return headerFormat; + } + + /** + * @param headerFormat the headerFormat to set + * @return + */ + public Tooltip setHeaderFormat(String headerFormat) { + this.headerFormat = headerFormat; + return this; + } + + /** + * @return the pointFormat + */ + public String getPointFormat() { + return pointFormat; + } + + /** + * @param pointFormat the pointFormat to set + * @return + */ + public Tooltip setPointFormat(String pointFormat) { + this.pointFormat = pointFormat; + return this; + } + + /** + * @return the shadow + */ + public Boolean getShadow() { + return shadow; + } + + /** + * @param shadow the shadow to set + * @return + */ + public Tooltip setShadow(Boolean shadow) { + this.shadow = shadow; + return this; + } + + /** + * @return the shape + */ + public String getShape() { + return shape; + } + + /** + * @param shape the shape to set + * @return + */ + public Tooltip setShape(String shape) { + this.shape = shape; + return this; + } + + /** + * @return the shared + */ + public Boolean getShared() { + return shared; + } + + /** + * @param shared the shared to set + * @return + */ + public Tooltip setShared(Boolean shared) { this.shared = shared; return this; } + /** + * @return the snap + */ + public Integer getSnap() { + return snap; + } + + /** + * @param snap the snap to set + * @return + */ + public Tooltip setSnap(Integer snap) { + this.snap = snap; + return this; + } + + /** + * @return the style + */ + public Style getStyle() { + if(this.style == null) { + this.style = new Style(); + } + return style; + } + + /** + * @return the useHTML + */ + public Boolean getUseHTML() { + return useHTML; + } + + /** + * @param useHTML the useHTML to set + * @return + */ + public Tooltip setUseHTML(Boolean useHTML) { + this.useHTML = useHTML; + return this; + } + + /** + * @return the valueDecimals + */ + public Integer getValueDecimals() { + return valueDecimals; + } + + /** + * @param valueDecimals the valueDecimals to set + * @return + */ + public Tooltip setValueDecimals(Integer valueDecimals) { + this.valueDecimals = valueDecimals; + return this; + } + + /** + * @return the valuePrefix + */ + public String getValuePrefix() { + return valuePrefix; + } + + /** + * @param valuePrefix the valuePrefix to set + * @return + */ + public Tooltip setValuePrefix(String valuePrefix) { + this.valuePrefix = valuePrefix; + return this; + } + + /** + * @return the valueSuffix + */ + public String getValueSuffix() { + return valueSuffix; + } + + /** + * @param valueSuffix the valueSuffix to set + * @return + */ + public Tooltip setValueSuffix(String valueSuffix) { + this.valueSuffix = valueSuffix; + return this; + } + + /** + * @return the xDateFormat + */ + public String getXDateFormat() { + return xDateFormat; + } + + /** + * @param xDateFormat the xDateFormat to set + * @return + */ + public Tooltip setXDateFormat(String xDateFormat) { + this.xDateFormat = xDateFormat; + return this; + } } diff --git a/src/main/java/nl/pvanassen/highchart/api/axis/AxisLabels.java b/src/main/java/nl/pvanassen/highchart/api/axis/AxisLabels.java index 7fb7009..f2c28b0 100644 --- a/src/main/java/nl/pvanassen/highchart/api/axis/AxisLabels.java +++ b/src/main/java/nl/pvanassen/highchart/api/axis/AxisLabels.java @@ -1,21 +1,64 @@ package nl.pvanassen.highchart.api.axis; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlType; - import nl.pvanassen.highchart.api.base.BaseObject; +import nl.pvanassen.highchart.api.shared.Style; +import nl.pvanassen.highchart.api.shared.AlignType; +import nl.pvanassen.highchart.api.shared.EnumString; +import nl.pvanassen.highchart.api.shared.Styleable; +import nl.pvanassen.highchart.api.utils.Utils; + -@XmlAccessorType( XmlAccessType.NONE ) -@XmlType( namespace = "axis" ) -public class AxisLabels extends BaseObject { +public class AxisLabels + extends BaseObject + implements Styleable<AxisLabels> { + + private String align; + + private Boolean enabled; + + private String format; + + private Integer maxStaggerLines; + + private String overflow; - @XmlElement private Double rotation; - @XmlElement - private String align; + private Integer staggerLines; + + private Integer step; + + private Style style; + + private Boolean useHTML; + + private Integer x; + + private Integer y; + + private Integer zIndex; + + @Override + public AxisLabels style( + final AxisLabels src) { + if(src == null) { + return this; + } + this.align = src.align; + this.enabled = src.enabled; + this.format = src.format; + this.maxStaggerLines = src.maxStaggerLines; + this.overflow = src.overflow; + this.rotation = src.rotation; + this.staggerLines = src.staggerLines; + this.step = src.step; + Utils.style(this.style, src.style); + this.useHTML = src.useHTML; + this.x = src.x; + this.y = src.y; + this.zIndex = src.zIndex; + return this; + } public String getAlign() { return align; @@ -25,14 +68,183 @@ public Double getRotation() { return rotation; } - public AxisLabels setAlign( String align ) { - this.align = align; + public AxisLabels setAlign(AlignType align) { + this.align = EnumString.toString(align); return this; } - public AxisLabels setRotation( double rotation ) { + public AxisLabels setRotation(Double rotation) { this.rotation = rotation; return this; } + /** + * @return the enabled + */ + public Boolean getEnabled() { + return enabled; + } + + /** + * @param enabled the enabled to set + * @return + */ + public AxisLabels setEnabled(Boolean enabled) { + this.enabled = enabled; + return this; + } + + /** + * @return the format + */ + public String getFormat() { + return format; + } + + /** + * @param format the format to set + * @return + */ + public AxisLabels setFormat(String format) { + this.format = format; + return this; + } + + /** + * @return the maxStaggerLines + */ + public Integer getMaxStaggerLines() { + return maxStaggerLines; + } + + /** + * @param maxStaggerLines the maxStaggerLines to set + * @return + */ + public AxisLabels setMaxStaggerLines(Integer maxStaggerLines) { + this.maxStaggerLines = maxStaggerLines; + return this; + } + + /** + * @return the overflow + */ + public Object getOverflow() { + return overflow; + } + + /** + * @return + */ + public AxisLabels setOverflow(String overflow) { + this.overflow = overflow; + return this; + } + + /** + * @return the staggerLines + */ + public Integer getStaggerLines() { + return staggerLines; + } + + /** + * @param staggerLines the staggerLines to set + * @return + */ + public AxisLabels setStaggerLines(Integer staggerLines) { + this.staggerLines = staggerLines; + return this; + } + + /** + * @return the step + */ + public Integer getStep() { + return step; + } + + /** + * @param step the step to set + * @return + */ + public AxisLabels setStep(Integer step) { + this.step = step; + return this; + } + + /** + * @return the style + */ + public Style getStyle() { + if(this.style == null) { + this.style = new Style(); + } + return style; + } + + /** + * @return the useHTML + */ + public Boolean getUseHTML() { + return useHTML; + } + + /** + * @param useHTML the useHTML to set + * @return + */ + public AxisLabels setUseHTML(Boolean useHTML) { + this.useHTML = useHTML; + return this; + } + + /** + * @return the x + */ + public Integer getX() { + return x; + } + + /** + * @param x the x to set + * @return + */ + public AxisLabels setX(Integer x) { + this.x = x; + return this; + } + + /** + * @return the y + */ + public Integer getY() { + return y; + } + + /** + * @param y the y to set + * @return + */ + public AxisLabels setY(Integer y) { + this.y = y; + return this; + } + + /** + * @return the zIndex + */ + public Integer getZIndex() { + return zIndex; + } + + /** + * @param zIndex the zIndex to set + * @return + */ + public AxisLabels setZIndex(Integer zIndex) { + this.zIndex = zIndex; + return this; + } + } \ No newline at end of file diff --git a/src/main/java/nl/pvanassen/highchart/api/axis/AxisPlotLineLabel.java b/src/main/java/nl/pvanassen/highchart/api/axis/AxisPlotLineLabel.java index b5f16a4..6299e58 100644 --- a/src/main/java/nl/pvanassen/highchart/api/axis/AxisPlotLineLabel.java +++ b/src/main/java/nl/pvanassen/highchart/api/axis/AxisPlotLineLabel.java @@ -1,7 +1,7 @@ package nl.pvanassen.highchart.api.axis; import nl.pvanassen.highchart.api.base.BaseObject; -import nl.pvanassen.highchart.api.base.Style; +import nl.pvanassen.highchart.api.shared.Style; public class AxisPlotLineLabel extends BaseObject { @@ -19,7 +19,7 @@ public class AxisPlotLineLabel extends BaseObject { private double y; - private Style style; + private Style style; public AxisPlotLineLabel() { style = new Style(); @@ -57,42 +57,42 @@ public double getY() { return y; } - public AxisPlotLineLabel setAlign( String align ) { + public AxisPlotLineLabel setAlign(String align) { this.align = align; return this; } - public AxisPlotLineLabel setRotation( double rotation ) { + public AxisPlotLineLabel setRotation(double rotation) { this.rotation = rotation; return this; } - public AxisPlotLineLabel setStyle( Style style ) { + public AxisPlotLineLabel setStyle(Style style) { this.style = style; return this; } - public AxisPlotLineLabel setText( String text ) { + public AxisPlotLineLabel setText(String text) { this.text = text; return this; } - public AxisPlotLineLabel setTextAlign( String textAlign ) { + public AxisPlotLineLabel setTextAlign(String textAlign) { this.textAlign = textAlign; return this; } - public AxisPlotLineLabel setVerticalAlign( String verticalAlign ) { + public AxisPlotLineLabel setVerticalAlign(String verticalAlign) { this.verticalAlign = verticalAlign; return this; } - public AxisPlotLineLabel setX( double x ) { + public AxisPlotLineLabel setX(double x) { this.x = x; return this; } - public AxisPlotLineLabel setY( double y ) { + public AxisPlotLineLabel setY(double y) { this.y = y; return this; } diff --git a/src/main/java/nl/pvanassen/highchart/api/axis/AxisPlotLines.java b/src/main/java/nl/pvanassen/highchart/api/axis/AxisPlotLines.java index b6bc507..1e4abb1 100644 --- a/src/main/java/nl/pvanassen/highchart/api/axis/AxisPlotLines.java +++ b/src/main/java/nl/pvanassen/highchart/api/axis/AxisPlotLines.java @@ -4,17 +4,17 @@ public class AxisPlotLines extends BaseObject { - private int zindex; + private int zindex; - private int width; + private int width; - private double value; + private double value; - private String id; + private String id; - private String color; + private String color; - private String dashStyle; + private String dashStyle; private AxisPlotLineLabel label; @@ -50,37 +50,37 @@ public int getZIndex() { return zindex; } - public AxisPlotLines setColor( String color ) { + public AxisPlotLines setColor(String color) { this.color = color; return this; } - public AxisPlotLines setDashStyle( String dashStyle ) { + public AxisPlotLines setDashStyle(String dashStyle) { this.dashStyle = dashStyle; return this; } - public AxisPlotLines setId( String id ) { + public AxisPlotLines setId(String id) { this.id = id; return this; } - public AxisPlotLines setLabel( AxisPlotLineLabel label ) { + public AxisPlotLines setLabel(AxisPlotLineLabel label) { this.label = label; return this; } - public AxisPlotLines setValue( double value ) { + public AxisPlotLines setValue(double value) { this.value = value; return this; } - public AxisPlotLines setWidth( int width ) { + public AxisPlotLines setWidth(int width) { this.width = width; return this; } - public AxisPlotLines setZIndex( int zindex ) { + public AxisPlotLines setZIndex(int zindex) { this.zindex = zindex; return this; } diff --git a/src/main/java/nl/pvanassen/highchart/api/base/BaseObject.java b/src/main/java/nl/pvanassen/highchart/api/base/BaseObject.java index 9f0599c..ed4bb9f 100644 --- a/src/main/java/nl/pvanassen/highchart/api/base/BaseObject.java +++ b/src/main/java/nl/pvanassen/highchart/api/base/BaseObject.java @@ -5,15 +5,16 @@ import nl.pvanassen.highchart.api.shared.Jsonify; -@XmlAccessorType( XmlAccessType.NONE ) +@XmlAccessorType(XmlAccessType.NONE) public class BaseObject implements Jsonify { + public BaseObject() { super(); } @Override public String toJson() { - return GsonHelper.toJson( this ); + return GsonHelper.toJson(this); } } \ No newline at end of file diff --git a/src/main/java/nl/pvanassen/highchart/api/base/GsonHelper.java b/src/main/java/nl/pvanassen/highchart/api/base/GsonHelper.java index c0598c4..5cd94a9 100644 --- a/src/main/java/nl/pvanassen/highchart/api/base/GsonHelper.java +++ b/src/main/java/nl/pvanassen/highchart/api/base/GsonHelper.java @@ -1,5 +1,6 @@ package nl.pvanassen.highchart.api.base; +import nl.pvanassen.highchart.api.shared.Style; import nl.pvanassen.highchart.api.format.DateTimeLabelFormats; import nl.pvanassen.highchart.api.serializer.DateTimeLabelFormatsSerializer; import nl.pvanassen.highchart.api.serializer.StyleSerializer; @@ -7,37 +8,48 @@ import com.google.gson.ExclusionStrategy; import com.google.gson.FieldAttributes; import com.google.gson.GsonBuilder; +import nl.pvanassen.highchart.api.NullableDouble; +import nl.pvanassen.highchart.api.serializer.NullableDoubleSerializer; public final class GsonHelper { - private static final String DATE_FORMAT = "yyyyMMdd"; + private static final String DATE_FORMAT = "yyyyMMdd"; - private static final String USER_OBJECT = "userObject"; + private static final String USER_OBJECT = "userObject"; - private static final GsonHelper INSTANCE = new GsonHelper(); + private static final GsonHelper INSTANCE = new GsonHelper(); - static String toJson( Object object ) { - return INSTANCE.gsonBuilder.create().toJson( object ); + public static String toJson(Object object) { + return GsonHelper.INSTANCE.gsonBuilder.create().toJson(object); } private final GsonBuilder gsonBuilder; private GsonHelper() { - gsonBuilder = new GsonBuilder().registerTypeAdapter( DateTimeLabelFormats.class, new DateTimeLabelFormatsSerializer() ) // - .registerTypeAdapter( Style.class, new StyleSerializer() )// - .setDateFormat( DATE_FORMAT )// - .setExclusionStrategies( new ExclusionStrategy() { + gsonBuilder = new GsonBuilder() + .registerTypeAdapter( + DateTimeLabelFormats.class, + new DateTimeLabelFormatsSerializer()) // + .registerTypeAdapter( + Style.class, + new StyleSerializer())// + .registerTypeAdapter( + NullableDouble.class, + new NullableDoubleSerializer()) + .serializeSpecialFloatingPointValues() + .setDateFormat(GsonHelper.DATE_FORMAT)// + .setExclusionStrategies(new ExclusionStrategy() { @Override - public boolean shouldSkipClass( Class<?> arg0 ) { + public boolean shouldSkipClass(Class<?> arg0) { return false; } @Override - public boolean shouldSkipField( FieldAttributes attributes ) { - return attributes.getName().equals( USER_OBJECT ); + public boolean shouldSkipField(FieldAttributes attributes) { + return attributes.getName().equals(GsonHelper.USER_OBJECT); } - } ); + }); } } diff --git a/src/main/java/nl/pvanassen/highchart/api/base/Style.java b/src/main/java/nl/pvanassen/highchart/api/base/Style.java deleted file mode 100644 index b6919a1..0000000 --- a/src/main/java/nl/pvanassen/highchart/api/base/Style.java +++ /dev/null @@ -1,30 +0,0 @@ -package nl.pvanassen.highchart.api.base; - -import java.util.HashMap; -import java.util.Map; - -public class Style extends BaseObject { - - private Map<String, String> properties; - - public Style() { - properties = null; - } - - public Map<String, String> getProperties() { - return properties; - } - - public String getProperty( String property ) { - return ( properties != null ) ? properties.get( property ) : null; - } - - public Style setProperty( String property, String value ) { - if ( properties == null ) { - properties = new HashMap<String, String>(); - } - properties.put( property, value ); - return this; - } - -} diff --git a/src/main/java/nl/pvanassen/highchart/api/drilldown/DrillUpButton.java b/src/main/java/nl/pvanassen/highchart/api/drilldown/DrillUpButton.java new file mode 100644 index 0000000..a34d5af --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/drilldown/DrillUpButton.java @@ -0,0 +1,42 @@ +package nl.pvanassen.highchart.api.drilldown; + +import nl.pvanassen.highchart.api.base.BaseObject; + +public class DrillUpButton extends BaseObject { + + private String relativeTo; + + private Position position; + + /** + * Returns the relativeTo option. + * + * @return the relativeTo + */ + public String getRelativeTo() { + return relativeTo; + } + + /** + * Sets the relative to option. + * + * @param relativeTo the relativeTo to set + */ + public DrillUpButton setRelativeTo(String relativeTo) { + this.relativeTo = relativeTo; + return this; + } + + /** + * Returns the position. + * + * @return the position. + */ + public Position getPosition() { + if (position == null) { + position = new Position(); + } + return position; + } + +} \ No newline at end of file diff --git a/src/main/java/nl/pvanassen/highchart/api/drilldown/Position.java b/src/main/java/nl/pvanassen/highchart/api/drilldown/Position.java new file mode 100644 index 0000000..8b58e7c --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/drilldown/Position.java @@ -0,0 +1,48 @@ +package nl.pvanassen.highchart.api.drilldown; + +import nl.pvanassen.highchart.api.base.BaseObject; + +public class Position extends BaseObject { + + private Integer x; + + private Integer y; + + /** + * Returns the x position value. + * + * @return the x + */ + public Integer getX() { + return x; + } + + /** + * Sets the x position value. + * + * @param x the x to set + */ + public Position setX(Integer x) { + this.x = x; + return this; + } + + /** + * Returns the y position value. + * + * @return the y + */ + public Integer getY() { + return y; + } + + /** + * Sets the y position value. + * + * @param y the y to set + */ + public Position setY(Integer y) { + this.y = y; + return this; + } +} \ No newline at end of file diff --git a/src/main/java/nl/pvanassen/highchart/api/export/Renderer.java b/src/main/java/nl/pvanassen/highchart/api/export/Renderer.java index 6a3de29..2b43023 100644 --- a/src/main/java/nl/pvanassen/highchart/api/export/Renderer.java +++ b/src/main/java/nl/pvanassen/highchart/api/export/Renderer.java @@ -6,7 +6,7 @@ public interface Renderer<T> { public static abstract class PojoRenderer<T> implements Renderer<T> { - private T options, globalOptions; + private T options, globalOptions; private OutputStream output; @@ -23,19 +23,19 @@ protected OutputStream getOutputStream() { } @Override - public Renderer<T> setChartOptions( T options ) { + public Renderer<T> setChartOptions(T options) { this.options = options; return this; } @Override - public Renderer<T> setGlobalOptions( T options ) { + public Renderer<T> setGlobalOptions(T options) { this.globalOptions = options; return this; } @Override - public Renderer<T> setOutputStream( OutputStream output ) { + public Renderer<T> setOutputStream(OutputStream output) { this.output = output; return this; } @@ -44,10 +44,10 @@ public Renderer<T> setOutputStream( OutputStream output ) { void render(); - Renderer<T> setChartOptions( T options ); + Renderer<T> setChartOptions(T options); - Renderer<T> setGlobalOptions( T options ); + Renderer<T> setGlobalOptions(T options); - Renderer<T> setOutputStream( OutputStream outputStream ); + Renderer<T> setOutputStream(OutputStream outputStream); } \ No newline at end of file diff --git a/src/main/java/nl/pvanassen/highchart/api/format/DateTimeLabelFormats.java b/src/main/java/nl/pvanassen/highchart/api/format/DateTimeLabelFormats.java index 5a7cc55..b2f599e 100644 --- a/src/main/java/nl/pvanassen/highchart/api/format/DateTimeLabelFormats.java +++ b/src/main/java/nl/pvanassen/highchart/api/format/DateTimeLabelFormats.java @@ -4,8 +4,13 @@ import java.util.Map; import nl.pvanassen.highchart.api.base.BaseObject; +import nl.pvanassen.highchart.api.shared.Styleable; +import nl.pvanassen.highchart.api.utils.Utils; + +public class DateTimeLabelFormats + extends BaseObject + implements Styleable<DateTimeLabelFormats> { -public class DateTimeLabelFormats extends BaseObject { public enum TimeUnit { SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR; } @@ -15,20 +20,30 @@ public enum TimeUnit { public DateTimeLabelFormats() { formats = null; } + + @Override + public DateTimeLabelFormats style( + final DateTimeLabelFormats src) { + if(src == null) { + return this; + } + Utils.stylePrimitiveMap(this.formats, src.formats); + return this; + } - public String getFormat( TimeUnit unit ) { - return ( formats != null ) ? formats.get( unit ) : null; + public String getFormat(TimeUnit unit) { + return formats != null ? formats.get(unit) : null; } public Map<TimeUnit, String> getFormats() { return formats; } - public DateTimeLabelFormats set( TimeUnit unit, String format ) { - if ( formats == null ) { + public DateTimeLabelFormats set(TimeUnit unit, String format) { + if (formats == null) { formats = new HashMap<TimeUnit, String>(); } - formats.put( unit, format ); + formats.put(unit, format); return this; } diff --git a/src/main/java/nl/pvanassen/highchart/api/label/LabelsItems.java b/src/main/java/nl/pvanassen/highchart/api/label/LabelsItems.java index b20fa94..879d5a8 100644 --- a/src/main/java/nl/pvanassen/highchart/api/label/LabelsItems.java +++ b/src/main/java/nl/pvanassen/highchart/api/label/LabelsItems.java @@ -1,26 +1,16 @@ package nl.pvanassen.highchart.api.label; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlType; +import nl.pvanassen.highchart.api.shared.Style; -import nl.pvanassen.highchart.api.base.Style; - -@XmlAccessorType( XmlAccessType.NONE ) -@XmlType( namespace = "labels" ) public class LabelsItems { private String html; - private Style style; - - public LabelsItems() { - style = new Style(); - } + private Style style; - public LabelsItems center( int centerPosition, double top ) { - getStyle().setProperty( "left", ( centerPosition - ( ( getHtml().length() * 6 ) / 2 ) ) + "px" ); - getStyle().setProperty( "top", top + "px" ); + public LabelsItems center(int centerPosition, double top) { + getStyle().setProperty("left", centerPosition - getHtml().length() * 6 / 2 + "px"); + getStyle().setProperty("top", top + "px"); return this; } @@ -29,10 +19,13 @@ public String getHtml() { } public Style getStyle() { + if(this.style == null) { + this.style = new Style(); + } return style; } - public LabelsItems setHtml( String html ) { + public LabelsItems setHtml(String html) { this.html = html; return this; } diff --git a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotMarkerHover.java b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotMarkerHover.java index f0e3b01..1b0aba1 100644 --- a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotMarkerHover.java +++ b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotMarkerHover.java @@ -10,7 +10,7 @@ public boolean isEnabled() { return enabled; } - public PlotMarkerHover setEnabled( boolean enabled ) { + public PlotMarkerHover setEnabled(boolean enabled) { this.enabled = enabled; return this; } diff --git a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotMarkerSelect.java b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotMarkerSelect.java index 81be405..4c7a6ab 100644 --- a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotMarkerSelect.java +++ b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotMarkerSelect.java @@ -6,7 +6,7 @@ public class PlotMarkerSelect extends BaseObject { private String fillColor, lineColor; - private int lineWidth; + private int lineWidth; public String getFillColor() { return fillColor; @@ -20,17 +20,17 @@ public int getLineWidth() { return lineWidth; } - public PlotMarkerSelect setFillColor( String fillColor ) { + public PlotMarkerSelect setFillColor(String fillColor) { this.fillColor = fillColor; return this; } - public PlotMarkerSelect setLineColor( String lineColor ) { + public PlotMarkerSelect setLineColor(String lineColor) { this.lineColor = lineColor; return this; } - public PlotMarkerSelect setLineWidth( int lineWidth ) { + public PlotMarkerSelect setLineWidth(int lineWidth) { this.lineWidth = lineWidth; return this; } diff --git a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotMarkerStates.java b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotMarkerStates.java index de9680d..ef6f8b5 100644 --- a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotMarkerStates.java +++ b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotMarkerStates.java @@ -4,9 +4,9 @@ public class PlotMarkerStates extends BaseObject { - private PlotMarkerSelect select; + private final PlotMarkerSelect select; - private PlotMarkerHover hover; + private final PlotMarkerHover hover; public PlotMarkerStates() { select = new PlotMarkerSelect(); diff --git a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsDataLabels.java b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsDataLabels.java index 0ac7d20..92dba9a 100644 --- a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsDataLabels.java +++ b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsDataLabels.java @@ -1,91 +1,433 @@ package nl.pvanassen.highchart.api.plotoption; +import java.awt.Color; import nl.pvanassen.highchart.api.base.BaseObject; +import nl.pvanassen.highchart.api.shared.Style; +import nl.pvanassen.highchart.api.shared.AlignType; +import nl.pvanassen.highchart.api.shared.EnumString; +import nl.pvanassen.highchart.api.shared.HexColor; +import nl.pvanassen.highchart.api.shared.Styleable; +import nl.pvanassen.highchart.api.shared.VerticalAlignType; +import nl.pvanassen.highchart.api.utils.Utils; -public class PlotOptionsDataLabels extends BaseObject { +public class PlotOptionsDataLabels + extends BaseObject + implements Styleable<PlotOptionsDataLabels> { - private String color; + private String align; + + private String backgroundColor; + + private String borderColor; + + private Integer borderRadius; + + private Integer borderWidth; + + private String color; + + private Boolean crop; + + private Boolean defer; - private boolean enabled; + private Boolean enabled; + + private String format; + + private Boolean inside; + + private String overflow; + + private Integer padding; + + private Double rotation; + + private Boolean shadow; + + private Style style; + + private Boolean useHTML; + + private String verticalAlign; + + private Integer x; + + private Integer y; + + private Integer zIndex; + + + public PlotOptionsDataLabels style( + final PlotOptionsDataLabels src) { + if(src == null) { + return this; + } + this.align = src.align; + this.backgroundColor = src.backgroundColor; + this.borderColor = src.borderColor; + this.borderRadius = src.borderRadius; + this.borderWidth = src.borderWidth; + this.color = src.color; + this.crop = src.crop; + this.defer = src.defer; + this.enabled = src.enabled; + this.format = src.format; + this.inside = src.inside; + this.overflow = src.overflow; + this.padding = src.padding; + this.rotation = src.rotation; + this.shadow = src.shadow; + Utils.style(this.style, src.style); + this.useHTML = src.useHTML; + return this; + } + + /** + * @return the align + */ + public String getAlign() { + return align; + } - private Object formatter; + /** + * @param align the align to set + * @return + */ + public PlotOptionsDataLabels setAlign(AlignType align) { + this.align = EnumString.toString(align); + return this; + } + + /** + * @return the backgroundColor + */ + public String getBackgroundColor() { + return backgroundColor; + } - private Integer x, y, distance; + /** + * @param backgroundColor the backgroundColor to set + * @return + */ + public PlotOptionsDataLabels setBackgroundColor(Color backgroundColor) { + this.backgroundColor = HexColor.toString(backgroundColor); + return this; + } + + /** + * @param backgroundColor the backgroundColor to set + * @return + */ + public PlotOptionsDataLabels setBackgroundColor(String backgroundColor) { + this.backgroundColor = backgroundColor; + return this; + } - private String align = "center"; + /** + * @return the borderColor + */ + public String getBorderColor() { + return borderColor; + } - private double rotation; + /** + * @param borderColor the borderColor to set + * @return + */ + public PlotOptionsDataLabels setBorderColor(Color borderColor) { + this.borderColor = HexColor.toString(borderColor); + return this; + } - public String getAlign() { - return align; + /** + * @return the borderRadius + */ + public Integer getBorderRadius() { + return borderRadius; } + /** + * @param borderRadius the borderRadius to set + * @return + */ + public PlotOptionsDataLabels setBorderRadius(Integer borderRadius) { + this.borderRadius = borderRadius; + return this; + } + + /** + * @return the borderWidth + */ + public Integer getBorderWidth() { + return borderWidth; + } + + /** + * @param borderWidth the borderWidth to set + * @return + */ + public PlotOptionsDataLabels setBorderWidth(Integer borderWidth) { + this.borderWidth = borderWidth; + return this; + } + + /** + * @return the color + */ public String getColor() { return color; } + + /** + * @param color the color to set + * @return + */ + public PlotOptionsDataLabels setColor(String color) { + this.color = color; + return this; + } - public int getDistance() { - return distance; + /** + * @param color the color to set + * @return + */ + public PlotOptionsDataLabels setColor(Color color) { + this.color = HexColor.toString(color); + return this; } - public Object getFormatter() { - return formatter; + /** + * @return the crop + */ + public Boolean getCrop() { + return crop; } - public double getRotation() { - return rotation; + /** + * @param crop the crop to set + * @return + */ + public PlotOptionsDataLabels setCrop(Boolean crop) { + this.crop = crop; + return this; } - public int getX() { - return x; + /** + * @return the defer + */ + public Boolean getDefer() { + return defer; } - public int getY() { - return y; + /** + * @param defer the defer to set + * @return + */ + public PlotOptionsDataLabels setDefer(Boolean defer) { + this.defer = defer; + return this; } - public boolean isEnabled() { + /** + * @return the enabled + */ + public Boolean getEnabled() { return enabled; } - public PlotOptionsDataLabels setAlign( String align ) { - this.align = align; + /** + * @param enabled the enabled to set + * @return + */ + public PlotOptionsDataLabels setEnabled(Boolean enabled) { + this.enabled = enabled; return this; } - public PlotOptionsDataLabels setColor( String color ) { - this.color = color; + /** + * @return the format + */ + public String getFormat() { + return format; + } + + /** + * @param format the format to set + * @return + */ + public PlotOptionsDataLabels setFormat(String format) { + this.format = format; return this; } - public PlotOptionsDataLabels setDistance( int distance ) { - this.distance = distance; + /** + * @return the inside + */ + public Boolean getInside() { + return inside; + } + + /** + * @param inside the inside to set + * @return + */ + public PlotOptionsDataLabels setInside(Boolean inside) { + this.inside = inside; return this; } - public PlotOptionsDataLabels setEnabled( boolean enabled ) { - this.enabled = enabled; + /** + * @return the overflow + */ + public String getOverflow() { + return overflow; + } + + /** + * @param overflow the overflow to set + * @return + */ + public PlotOptionsDataLabels setOverflow(String overflow) { + this.overflow = overflow; return this; } - public PlotOptionsDataLabels setFormatter( Object formatter ) { - this.formatter = formatter; + /** + * @return the padding + */ + public Integer getPadding() { + return padding; + } + + /** + * @param padding the padding to set + * @return + */ + public PlotOptionsDataLabels setPadding(Integer padding) { + this.padding = padding; return this; } - public PlotOptionsDataLabels setRotation( double rotation ) { + /** + * @return the rotation + */ + public Double getRotation() { + return rotation; + } + + /** + * @param rotation the rotation to set + * @return + */ + public PlotOptionsDataLabels setRotation(Double rotation) { this.rotation = rotation; return this; } - public PlotOptionsDataLabels setX( int x ) { + /** + * @return the shadow + */ + public Boolean getShadow() { + return shadow; + } + + /** + * @param shadow the shadow to set + * @return + */ + public PlotOptionsDataLabels setShadow(Boolean shadow) { + this.shadow = shadow; + return this; + } + + /** + * @return the style + */ + public Style getStyle() { + if(this.style == null) { + this.style = new Style(); + } + return style; + } + + /** + * @return the useHTML + */ + public Boolean getUseHTML() { + return useHTML; + } + + /** + * @param useHTML the useHTML to set + * @return + */ + public PlotOptionsDataLabels setUseHTML(Boolean useHTML) { + this.useHTML = useHTML; + return this; + } + + /** + * @return the verticalAlign + */ + public String getVerticalAlign() { + return verticalAlign; + } + + /** + * @param verticalAlign the verticalAlign to set + * @return + */ + public PlotOptionsDataLabels setVerticalAlign( + final VerticalAlignType verticalAlign) { + this.verticalAlign = EnumString.toString(verticalAlign); + return this; + } + + /** + * @return the x + */ + public Integer getX() { + return x; + } + + /** + * @param x the x to set + * @return + */ + public PlotOptionsDataLabels setX(Integer x) { this.x = x; return this; } - public PlotOptionsDataLabels setY( int y ) { + /** + * @return the y + */ + public Integer getY() { + return y; + } + + /** + * @param y the y to set + * @return + */ + public PlotOptionsDataLabels setY(Integer y) { this.y = y; return this; } + /** + * @return the zIndex + */ + public Integer getZIndex() { + return zIndex; + } + + /** + * @param zIndex the zIndex to set + * @return + */ + public PlotOptionsDataLabels setZIndex(Integer zIndex) { + this.zIndex = zIndex; + return this; + } } \ No newline at end of file diff --git a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsMarker.java b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsMarker.java index 50bac8f..7d586b7 100644 --- a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsMarker.java +++ b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsMarker.java @@ -1,39 +1,162 @@ package nl.pvanassen.highchart.api.plotoption; import nl.pvanassen.highchart.api.base.BaseObject; +import nl.pvanassen.highchart.api.shared.Styleable; -public class PlotOptionsMarker extends BaseObject { - - private String symbol; - - private boolean enabled; +public class PlotOptionsMarker + extends BaseObject + implements Styleable<PlotOptionsMarker> { + private Boolean enabled; + + private String fillColor; + + private String lineColor; + + private Integer lineWidth; + + private Float radius; + private PlotMarkerStates states; - public PlotOptionsMarker() { + private String symbol; + + @Override + public PlotOptionsMarker style( + final PlotOptionsMarker src) { + if(src == null) { + return this; + } + this.enabled = src.enabled; + this.fillColor = src.fillColor; + this.lineColor = src.lineColor; + this.lineWidth = src.lineWidth; + this.radius = src.radius; + this.symbol = src.symbol; + return this; } public PlotMarkerStates getStates() { - if ( states == null ) { + if (states == null) { states = new PlotMarkerStates(); } return states; } - public String getSymbol() { - return symbol; - } - - public boolean isEnabled() { + /** + * Enable or disable the point marker. Defaults to true. + * @return the enabled + */ + public Boolean getEnabled() { return enabled; } - public PlotOptionsMarker setEnabled( boolean enabled ) { + /** + * Enable or disable the point marker. Defaults to true. + * @param enabled the enabled to set + * @return + */ + public PlotOptionsMarker setEnabled(Boolean enabled) { this.enabled = enabled; return this; } - public PlotOptionsMarker setSymbol( String symbol ) { + /** + * The fill color of the point marker. When null, the series' + * or point's color is used. + * @return the fillColor + */ + public String getFillColor() { + return fillColor; + } + + /** + * The fill color of the point marker. When null, the series' + * or point's color is used. + * @param fillColor the fillColor to set + * @return + */ + public PlotOptionsMarker setFillColor(String fillColor) { + this.fillColor = fillColor; + return this; + } + + /** + * The color of the point marker's outline. When null, the series' + * or point's color is used. Defaults to #FFFFFF. + * @return the lineColor + */ + public String getLineColor() { + return lineColor; + } + + /** + * The color of the point marker's outline. When null, the series' + * or point's color is used. Defaults to #FFFFFF. + * @param lineColor the lineColor to set + * @return + */ + public PlotOptionsMarker setLineColor(String lineColor) { + this.lineColor = lineColor; + return this; + } + + /** + * The width of the point marker's outline. Defaults to 0. + * @return the lineWidth + */ + public Integer getLineWidth() { + return lineWidth; + } + + /** + * The width of the point marker's outline. Defaults to 0. + * @param lineWidth the lineWidth to set + * @return + */ + public PlotOptionsMarker setLineWidth(Integer lineWidth) { + this.lineWidth = lineWidth; + return this; + } + + /** + * The radius of the point marker. Defaults to 4. + * @return the radius + */ + public Float getRadius() { + return radius; + } + + /** + * The radius of the point marker. Defaults to 4. + * @param radius the radius to set + * @return + */ + public PlotOptionsMarker setRadius(Float radius) { + this.radius = radius; + return this; + } + + /** + * A predefined shape or symbol for the marker. When null, the symbol is + * pulled from options.symbols. Other possible values are "circle", + * "square", "diamond", "triangle" and "triangle-down".Additionally, + * the URL to a graphic can be given on this form: "url(graphic.png)". + * @return the symbol + */ + public String getSymbol() { + return symbol; + } + + /** + * A predefined shape or symbol for the marker. When null, the symbol is + * pulled from options.symbols. Other possible values are "circle", + * "square", "diamond", "triangle" and "triangle-down".Additionally, + * the URL to a graphic can be given on this form: "url(graphic.png)". + * @param symbol the symbol to set + * @return + */ + public PlotOptionsMarker setSymbol(String symbol) { this.symbol = symbol; return this; } diff --git a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsSeries.java b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsSeries.java index 8b3ec2a..e7564d4 100644 --- a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsSeries.java +++ b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsSeries.java @@ -1,60 +1,170 @@ package nl.pvanassen.highchart.api.plotoption; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlType; - +import java.awt.Color; import nl.pvanassen.highchart.api.base.BaseObject; +import nl.pvanassen.highchart.api.shared.DashStyleType; +import nl.pvanassen.highchart.api.shared.EnumString; +import nl.pvanassen.highchart.api.shared.HexColor; +import nl.pvanassen.highchart.api.shared.StackingType; +import nl.pvanassen.highchart.api.shared.Styleable; +import nl.pvanassen.highchart.api.utils.JsonArray; +import nl.pvanassen.highchart.api.utils.Utils; -@XmlType( namespace = "plotoptions" ) -@XmlAccessorType( XmlAccessType.NONE ) -public class PlotOptionsSeries extends BaseObject { - - @XmlElement( type = PlotOptionsStates.class ) - private PlotOptionsStates states; - +public class PlotOptionsSeries + extends BaseObject + implements Styleable<PlotOptionsSeries> { + + private Boolean allowPointSelect; + + private String animation; + + private String borderColor; + + private Integer borderRadius; + + private Integer borderWidth; + + private String color; + + private Boolean colorByPoint; + + private JsonArray<String> colors; + + private Boolean connectEnds; + + private Boolean connectNulls; + + private Integer cropThreshold; + + private String cursor; + + private String dashStyle; + private PlotOptionsDataLabels dataLabels; + + private Integer depth; + + private String edgeColor; + + private Integer edgeWidth; + + private Boolean enableMouseTracking; + + private String fillColor; + + private Float fillOpacity; + + private Float groupPadding; + + private Integer groupZPadding; + + private Boolean grouping; + + private String innerSize; + + private String lineColor; + + private Integer lineWidth; + + private String linkedTo; + + private PlotOptionsMarker marker; + + private Integer minPointLength; + + private Integer minSize; + + private String negativeColor; + + private String negativeFillColor; + + private Float pointPadding; + + private Boolean shadow; + + private Integer slicedOffset; + + private String stacking; + + private Integer startAngle; + + private PlotOptionsStates states; + + private String step; + + private Double threshold; + + private Boolean trackByArea; - private String stacking; - - private PlotOptionsMarker marker; - - @XmlElement - private Boolean allowPointSelect; - - @XmlElement - private Boolean shadow; - - @XmlElement - private Integer lineWidth; + private Boolean visible; - @XmlElement - private Double fillOpacity; - - private int borderWidth; - - public int getBorderWidth() { - return borderWidth; + private Integer turboThreshold; + + @Override + public PlotOptionsSeries style( + final PlotOptionsSeries src) { + if(src == null) { + return this; + } + + this.allowPointSelect = src.allowPointSelect; + this.animation = src.animation; + this.borderColor = src.borderColor; + this.borderRadius = src.borderRadius; + this.borderWidth = src.borderWidth; + this.color = src.color; + this.colorByPoint = src.colorByPoint; + Utils.stylePrimitiveArray(this.colors, src.colors); + this.connectEnds = src.connectEnds; + this.connectNulls = src.connectNulls; + this.cropThreshold = src.cropThreshold; + this.cursor = src.cursor; + this.dashStyle = src.dashStyle; + Utils.style(this.dataLabels, src.dataLabels); + this.depth = src.depth; + this.edgeColor = src.edgeColor; + this.edgeWidth = src.edgeWidth; + this.enableMouseTracking = src.enableMouseTracking; + this.fillColor = src.fillColor; + this.fillOpacity = src.fillOpacity; + this.groupPadding = src.groupPadding; + this.groupZPadding = src.groupZPadding; + this.grouping = src.grouping; + this.innerSize = src.innerSize; + this.lineColor = src.lineColor; + this.lineWidth = src.lineWidth; + this.linkedTo = src.linkedTo; + Utils.style(this.marker, src.marker); + this.minPointLength = src.minPointLength; + this.minSize = src.minSize; + this.negativeColor = src.negativeColor; + this.negativeFillColor = src.negativeFillColor; + this.pointPadding = src.pointPadding; + this.shadow = src.shadow; + this.slicedOffset = src.slicedOffset; + this.stacking = src.stacking; + this.startAngle = src.startAngle; + this.step = src.step; + this.threshold = src.threshold; + this.trackByArea = src.trackByArea; + this.visible = src.visible; + this.turboThreshold = src.turboThreshold; + return this; } public PlotOptionsDataLabels getDataLabels() { - if ( dataLabels == null ) { + if (dataLabels == null) { dataLabels = new PlotOptionsDataLabels(); } return dataLabels; } - public double getFillOpacity() { - return fillOpacity; - } - - public int getLineWidth() { + public Integer getLineWidth() { return lineWidth; } public PlotOptionsMarker getMarker() { - if ( marker == null ) { + if (marker == null) { marker = new PlotOptionsMarker(); } return marker; @@ -65,53 +175,668 @@ public String getStacking() { } public PlotOptionsStates getStates() { - if ( states == null ) { + if (states == null) { states = new PlotOptionsStates(); } return states; } - public boolean isAllowPointSelect() { - return allowPointSelect; + public PlotOptionsSeries setStacking(StackingType stacking) { + this.stacking = EnumString.toString(stacking); + return this; } - public boolean isShadow() { - return shadow; + /** + * @return the allowPointSelect + */ + public Boolean getAllowPointSelect() { + return allowPointSelect; } - public PlotOptionsSeries setAllowPointSelect( boolean allowPointSelect ) { + /** + * @param allowPointSelect the allowPointSelect to set + * @return + */ + public PlotOptionsSeries setAllowPointSelect(Boolean allowPointSelect) { this.allowPointSelect = allowPointSelect; return this; } - public PlotOptionsSeries setBorderWidth( int borderWidth ) { + /** + * @return the animation + */ + public String getAnimation() { + return animation; + } + + /** + * @param animation the animation to set + * @return + */ + public PlotOptionsSeries setAnimation(Boolean animation) { + if(animation != null) { + this.animation = Boolean.toString(animation); + } else { + this.animation = null; + } + return this; + } + + /** + * @return the color + */ + public String getColor() { + return color; + } + + /** + * @param color the color to set + * @return + */ + public PlotOptionsSeries setColor(String color) { + this.color = color; + return this; + } + + /** + * @param color the color to set + * @return + */ + public PlotOptionsSeries setColor(Color color) { + this.color = HexColor.toString(color); + return this; + } + + /** + * @return the connectEnds + */ + public Boolean getConnectEnds() { + return connectEnds; + } + + /** + * @param connectEnds the connectEnds to set + * @return + */ + public PlotOptionsSeries setConnectEnds(Boolean connectEnds) { + this.connectEnds = connectEnds; + return this; + } + + /** + * @return the connectNulls + */ + public Boolean getConnectNulls() { + return connectNulls; + } + + /** + * @param connectNulls the connectNulls to set + * @return + */ + public PlotOptionsSeries setConnectNulls(Boolean connectNulls) { + this.connectNulls = connectNulls; + return this; + } + + /** + * @return the cropThreshold + */ + public Integer getCropThreshold() { + return cropThreshold; + } + + /** + * @param cropThreshold the cropThreshold to set + * @return + */ + public PlotOptionsSeries setCropThreshold(Integer cropThreshold) { + this.cropThreshold = cropThreshold; + return this; + } + + /** + * @return the dashStyle + */ + public String getDashStyle() { + return dashStyle; + } + + /** + * @param dashStyle the dashStyle to set + * @return + */ + public PlotOptionsSeries setDashStyle(DashStyleType dashStyle) { + this.dashStyle = EnumString.toString(dashStyle); + return this; + } + + /** + * @param lineWidth the lineWidth to set + * @return + */ + public PlotOptionsSeries setLineWidth(Integer lineWidth) { + this.lineWidth = lineWidth; + return this; + } + + /** + * @return the linkedTo + */ + public String getLinkedTo() { + return linkedTo; + } + + /** + * @param linkedTo the linkedTo to set + * @return + */ + public PlotOptionsSeries setLinkedTo(String linkedTo) { + this.linkedTo = linkedTo; + return this; + } + + /** + * @return the negativeColor + */ + public String getNegativeColor() { + return negativeColor; + } + + /** + * @param negativeColor the negativeColor to set + * @return + */ + public PlotOptionsSeries setNegativeColor(String negativeColor) { + this.negativeColor = negativeColor; + return this; + } + + /** + * @param negativeColor the negativeColor to set + * @return + */ + public PlotOptionsSeries setNegativeColor(Color negativeColor) { + this.negativeColor = HexColor.toString(negativeColor); + return this; + } + + /** + * @return the visible + */ + public Boolean getVisible() { + return visible; + } + + /** + * @param visible the visible to set + * @return + */ + public PlotOptionsSeries setVisible(Boolean visible) { + this.visible = visible; + return this; + } + + /** + * @return the borderColor + */ + public String getBorderColor() { + return borderColor; + } + + /** + * @param borderColor the borderColor to set + * @return + */ + public PlotOptionsSeries setBorderColor(Color borderColor) { + this.borderColor = HexColor.toString(borderColor); + return this; + } + + /** + * @return the borderRadius + */ + public Integer getBorderRadius() { + return borderRadius; + } + + /** + * @param borderRadius the borderRadius to set + * @return + */ + public PlotOptionsSeries setBorderRadius(Integer borderRadius) { + this.borderRadius = borderRadius; + return this; + } + + /** + * @return the borderWidth + */ + public Integer getBorderWidth() { + return borderWidth; + } + + /** + * @param borderWidth the borderWidth to set + * @return + */ + public PlotOptionsSeries setBorderWidth(Integer borderWidth) { this.borderWidth = borderWidth; return this; } - public PlotOptionsSeries setFillOpacity( double fillOpacity ) { + /** + * @return the colorByPoint + */ + public Boolean getColorByPoint() { + return colorByPoint; + } + + /** + * @param colorByPoint the colorByPoint to set + * @return + */ + public PlotOptionsSeries setColorByPoint(Boolean colorByPoint) { + this.colorByPoint = colorByPoint; + return this; + } + + /** + * @return the colors + */ + public JsonArray<String> getColors() { + if(this.colors == null) { + this.colors = new JsonArray<String>(); + } + return colors; + } + + /** + * @return the cursor + */ + public String getCursor() { + return cursor; + } + + /** + * @param cursor the cursor to set + * @return + */ + public PlotOptionsSeries setCursor(String cursor) { + this.cursor = cursor; + return this; + } + + /** + * @return the depth + */ + public Integer getDepth() { + return depth; + } + + /** + * @param depth the depth to set + * @return + */ + public PlotOptionsSeries setDepth(Integer depth) { + this.depth = depth; + return this; + } + + /** + * @return the edgeColor + */ + public String getEdgeColor() { + return edgeColor; + } + + /** + * @param edgeColor the edgeColor to set + * @return + */ + public PlotOptionsSeries setEdgeColor(Color edgeColor) { + this.edgeColor = HexColor.toString(edgeColor); + return this; + } + + /** + * @return the edgeWidth + */ + public Integer getEdgeWidth() { + return edgeWidth; + } + + /** + * @param edgeWidth the edgeWidth to set + * @return + */ + public PlotOptionsSeries setEdgeWidth(Integer edgeWidth) { + this.edgeWidth = edgeWidth; + return this; + } + + /** + * @return the enableMouseTracking + */ + public Boolean getEnableMouseTracking() { + return enableMouseTracking; + } + + /** + * @param enableMouseTracking the enableMouseTracking to set + * @return + */ + public PlotOptionsSeries setEnableMouseTracking( + final Boolean enableMouseTracking) { + this.enableMouseTracking = enableMouseTracking; + return this; + } + + /** + * @return the fillColor + */ + public String getFillColor() { + return fillColor; + } + + /** + * @param fillColor the fillColor to set + * @return + */ + public PlotOptionsSeries setFillColor(String fillColor) { + this.fillColor = fillColor; + return this; + } + + /** + * @param fillColor the fillColor to set + * @return + */ + public PlotOptionsSeries setFillColor(Color fillColor) { + this.fillColor = HexColor.toString(fillColor); + return this; + } + + /** + * @return the fillOpacity + */ + public Float getFillOpacity() { + return fillOpacity; + } + + /** + * @param fillOpacity the fillOpacity to set + * @return + */ + public PlotOptionsSeries setFillOpacity(Float fillOpacity) { this.fillOpacity = fillOpacity; return this; } - public PlotOptionsSeries setLineWidth( int lineWidth ) { - this.lineWidth = lineWidth; + /** + * @return the groupPadding + */ + public Float getGroupPadding() { + return groupPadding; + } + + /** + * @param groupPadding the groupPadding to set + * @return + */ + public PlotOptionsSeries setGroupPadding(Float groupPadding) { + this.groupPadding = groupPadding; + return this; + } + + /** + * @return the groupZPadding + */ + public Integer getGroupZPadding() { + return groupZPadding; + } + + /** + * @param groupZPadding the groupZPadding to set + * @return + */ + public PlotOptionsSeries setGroupZPadding(Integer groupZPadding) { + this.groupZPadding = groupZPadding; + return this; + } + + /** + * @return the grouping + */ + public Boolean getGrouping() { + return grouping; + } + + /** + * @param grouping the grouping to set + * @return + */ + public PlotOptionsSeries setGrouping(Boolean grouping) { + this.grouping = grouping; + return this; + } + + /** + * @return the innserSize + */ + public String getInnerSize() { + return innerSize; + } + + /** + * @param innserSize the innserSize to set + * @return + */ + public PlotOptionsSeries setInnerSize(String innerSize) { + this.innerSize = innerSize; + return this; + } + + /** + * @return the lineColor + */ + public String getLineColor() { + return lineColor; + } + + /** + * @param lineColor the lineColor to set + * @return + */ + public PlotOptionsSeries setLineColor(Color lineColor) { + this.lineColor = HexColor.toString(lineColor); return this; } - public PlotOptionsSeries setShadow( boolean shadow ) { + /** + * @return the minPointLength + */ + public Integer getMinPointLength() { + return minPointLength; + } + + /** + * @param minPointLength the minPointLength to set + * @return + */ + public PlotOptionsSeries setMinPointLength(Integer minPointLength) { + this.minPointLength = minPointLength; + return this; + } + + /** + * @return the minSize + */ + public Integer getMinSize() { + return minSize; + } + + /** + * @param minSize the minSize to set + * @return + */ + public PlotOptionsSeries setMinSize(Integer minSize) { + this.minSize = minSize; + return this; + } + + /** + * @return the negativeFillColor + */ + public String getNegativeFillColor() { + return negativeFillColor; + } + + /** + * @param negativeFillColor the negativeFillColor to set + * @return + */ + public PlotOptionsSeries setNegativeFillColor(String negativeFillColor) { + this.negativeFillColor = negativeFillColor; + return this; + } + + /** + * @param negativeFillColor the negativeFillColor to set + * @return + */ + public PlotOptionsSeries setNegativeFillColor(Color negativeFillColor) { + this.negativeFillColor = HexColor.toString(negativeFillColor); + return this; + } + + /** + * @return the pointPadding + */ + public Float getPointPadding() { + return pointPadding; + } + + /** + * @param pointPadding the pointPadding to set + * @return + */ + public PlotOptionsSeries setPointPadding(Float pointPadding) { + this.pointPadding = pointPadding; + return this; + } + + /** + * @return the shadow + */ + public Boolean getShadow() { + return shadow; + } + + /** + * @param shadow the shadow to set + * @return + */ + public PlotOptionsSeries setShadow(Boolean shadow) { this.shadow = shadow; return this; } - @XmlElement - public PlotOptionsSeries setStacking( String stacking ) { - this.stacking = stacking; + /** + * @return the slicedOffset + */ + public Integer getSlicedOffset() { + return slicedOffset; + } + + /** + * @param slicedOffset the slicedOffset to set + * @return + */ + public PlotOptionsSeries setSlicedOffset(Integer slicedOffset) { + this.slicedOffset = slicedOffset; + return this; + } + + /** + * @return the startAngle + */ + public Integer getStartAngle() { + return startAngle; + } + + /** + * @param startAngle the startAngle to set + * @return + */ + public PlotOptionsSeries setStartAngle(Integer startAngle) { + this.startAngle = startAngle; + return this; + } + + /** + * @return the step + */ + public String getStep() { + return step; + } + + /** + * @param step the step to set + * @return + */ + public PlotOptionsSeries setStep(String step) { + this.step = step; return this; } - public PlotOptionsSeries setStates( PlotOptionsStates states ) { - this.states = states; + /** + * @return the threshold + */ + public Double getThreshold() { + return threshold; + } + + /**. + * @param threshold the threshold to set + * @return + */ + public PlotOptionsSeries setThreshold(Double threshold) { + this.threshold = threshold; + return this; + } + + /** + * @return the trackByArea + */ + public Boolean getTrackByArea() { + return trackByArea; + } + + /** + * Whether the whole area or just the line should respond to mouseover + * tooltips and other mouse or touch events. Defaults to false. + * @param trackByArea the trackByArea to set + * @return + */ + public PlotOptionsSeries setTrackByArea(Boolean trackByArea) { + this.trackByArea = trackByArea; + return this; + } + + /** + * @return the turboThreshold + */ + public Integer getTurboThreshold() { + return turboThreshold; + } + + /**. + * @param turboThreshold the turboThreshold to set + * @return + */ + public PlotOptionsSeries setTurboThreshold(Integer turboThreshold) { + this.turboThreshold = turboThreshold; return this; } } \ No newline at end of file diff --git a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsStates.java b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsStates.java index 9d7fe15..8e9e9cb 100644 --- a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsStates.java +++ b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotOptionsStates.java @@ -1,18 +1,25 @@ package nl.pvanassen.highchart.api.plotoption; -import javax.xml.bind.annotation.XmlElement; import nl.pvanassen.highchart.api.base.BaseObject; public class PlotOptionsStates extends BaseObject { - @XmlElement( type = PlotStatesSelect.class ) private PlotStatesSelect select; + + private PlotStatesSelect hover; public PlotStatesSelect getSelect() { - if ( select == null ) { + if (select == null) { select = new PlotStatesSelect(); } return select; } + + public PlotStatesSelect getHover() { + if (hover == null) { + hover = new PlotStatesSelect(); + } + return hover; + } } \ No newline at end of file diff --git a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotStatesSelect.java b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotStatesSelect.java index cc24e61..a3c18db 100644 --- a/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotStatesSelect.java +++ b/src/main/java/nl/pvanassen/highchart/api/plotoption/PlotStatesSelect.java @@ -6,11 +6,14 @@ import nl.pvanassen.highchart.api.base.BaseObject; -@XmlAccessorType( XmlAccessType.NONE ) +@XmlAccessorType(XmlAccessType.NONE) public class PlotStatesSelect extends BaseObject { - private String color; - private String borderColor; + private String color; + + private String borderColor; + + private Integer lineWidth; @XmlElement private Integer borderWidth; @@ -26,20 +29,29 @@ public int getBorderWidth() { public String getColor() { return color; } + + public Integer getLineWidth() { + return lineWidth; + } - public PlotStatesSelect setBorderColor( String borderColor ) { + public PlotStatesSelect setBorderColor(String borderColor) { this.borderColor = borderColor; return this; } - public PlotStatesSelect setBorderWidth( int borderWidth ) { + public PlotStatesSelect setBorderWidth(int borderWidth) { this.borderWidth = borderWidth; return this; } - public PlotStatesSelect setColor( String color ) { + public PlotStatesSelect setColor(String color) { this.color = color; return this; } + + public PlotStatesSelect setLineWidth(Integer lineWidth) { + this.lineWidth = lineWidth; + return this; + } } \ No newline at end of file diff --git a/src/main/java/nl/pvanassen/highchart/api/serializer/CenterSerializer.java b/src/main/java/nl/pvanassen/highchart/api/serializer/CenterSerializer.java deleted file mode 100644 index f471f15..0000000 --- a/src/main/java/nl/pvanassen/highchart/api/serializer/CenterSerializer.java +++ /dev/null @@ -1,26 +0,0 @@ -package nl.pvanassen.highchart.api.serializer; - -import java.lang.reflect.Type; - -import nl.pvanassen.highchart.api.serie.SeriesCenter; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -public class CenterSerializer implements JsonSerializer<SeriesCenter> { - - @Override - public JsonElement serialize( SeriesCenter center, Type arg1, JsonSerializationContext arg2 ) { - if ( ( center.getX() == null ) || ( center.getY() == null ) ) { - return new JsonPrimitive( "" ); - } - JsonArray r = new JsonArray(); - r.add( new JsonPrimitive( center.getX() ) ); - r.add( new JsonPrimitive( center.getY() ) ); - return r; - } - -} diff --git a/src/main/java/nl/pvanassen/highchart/api/serializer/DateTimeLabelFormatsSerializer.java b/src/main/java/nl/pvanassen/highchart/api/serializer/DateTimeLabelFormatsSerializer.java index da1aabe..9c48c50 100644 --- a/src/main/java/nl/pvanassen/highchart/api/serializer/DateTimeLabelFormatsSerializer.java +++ b/src/main/java/nl/pvanassen/highchart/api/serializer/DateTimeLabelFormatsSerializer.java @@ -10,11 +10,11 @@ public class DateTimeLabelFormatsSerializer extends Serializer<DateTimeLabelFormats> { @Override - public Map<String, String> getProperties( DateTimeLabelFormats instance ) { + public Map<String, String> getProperties(DateTimeLabelFormats instance) { Map<TimeUnit, String> map = instance.getFormats(); Map<String, String> r = new HashMap<String, String>(); - for ( Entry<TimeUnit, String> e : map.entrySet() ) { - r.put( e.getKey().name().toLowerCase(), e.getValue() ); + for (Entry<TimeUnit, String> e : map.entrySet()) { + r.put(e.getKey().name().toLowerCase(), e.getValue()); } return r; } diff --git a/src/main/java/nl/pvanassen/highchart/api/serializer/NullableDoubleSerializer.java b/src/main/java/nl/pvanassen/highchart/api/serializer/NullableDoubleSerializer.java new file mode 100644 index 0000000..b6a270b --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/serializer/NullableDoubleSerializer.java @@ -0,0 +1,56 @@ +/* + * Copyright 2015 Gamma Associates Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.pvanassen.highchart.api.serializer; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonNull; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; +import nl.pvanassen.highchart.api.NullableDouble; + +/** + * + * @author shaun.lefeuvre + */ +public class NullableDoubleSerializer + implements JsonSerializer<NullableDouble>, + JsonDeserializer<NullableDouble> { + + public JsonElement serialize( + final NullableDouble src, + final Type typeOfSrc, + final JsonSerializationContext context) { + if(src.getValue() == null) { + return new JsonPrimitive("NullableDouble.NULL"); + } + return new JsonPrimitive(src.getValue()); + } + + public NullableDouble deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) throws JsonParseException { + if(json.getAsString().equals("NullableDouble.NULL")) { + return NullableDouble.NULL_INSTANCE; + } + return NullableDouble.of(json.getAsDouble()); + } +} diff --git a/src/main/java/nl/pvanassen/highchart/api/serializer/Serializer.java b/src/main/java/nl/pvanassen/highchart/api/serializer/Serializer.java index bab44a3..85d3518 100644 --- a/src/main/java/nl/pvanassen/highchart/api/serializer/Serializer.java +++ b/src/main/java/nl/pvanassen/highchart/api/serializer/Serializer.java @@ -4,11 +4,7 @@ import java.util.Map; import java.util.Map.Entry; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; +import com.google.gson.*; public abstract class Serializer<K> implements JsonSerializer<K> { @@ -16,18 +12,18 @@ public Serializer() { super(); } - public abstract Map<String, String> getProperties( K instance ); + public abstract Map<String, String> getProperties(K instance); @Override - public JsonElement serialize( K instance, Type arg1, JsonSerializationContext arg2 ) { - Map<String, String> map = getProperties( instance ); - if ( map == null ) { - return new JsonPrimitive( "" ); + public JsonElement serialize(K instance, Type arg1, JsonSerializationContext arg2) { + Map<String, String> map = getProperties(instance); + if (map == null) { + return new JsonPrimitive(""); } JsonObject r = new JsonObject(); - for ( Entry<String, String> e : map.entrySet() ) { - r.addProperty( e.getKey(), e.getValue() ); + for (Entry<String, String> e : map.entrySet()) { + r.addProperty(e.getKey(), e.getValue()); } return r; diff --git a/src/main/java/nl/pvanassen/highchart/api/serializer/StyleSerializer.java b/src/main/java/nl/pvanassen/highchart/api/serializer/StyleSerializer.java index 1cf60f7..8087976 100644 --- a/src/main/java/nl/pvanassen/highchart/api/serializer/StyleSerializer.java +++ b/src/main/java/nl/pvanassen/highchart/api/serializer/StyleSerializer.java @@ -2,12 +2,12 @@ import java.util.Map; -import nl.pvanassen.highchart.api.base.Style; +import nl.pvanassen.highchart.api.shared.Style; public class StyleSerializer extends Serializer<Style> { @Override - public Map<String, String> getProperties( Style instance ) { + public Map<String, String> getProperties(Style instance) { return instance.getProperties(); } diff --git a/src/main/java/nl/pvanassen/highchart/api/serie/SeriesCenter.java b/src/main/java/nl/pvanassen/highchart/api/serie/SeriesCenter.java deleted file mode 100644 index 08a948a..0000000 --- a/src/main/java/nl/pvanassen/highchart/api/serie/SeriesCenter.java +++ /dev/null @@ -1,24 +0,0 @@ -package nl.pvanassen.highchart.api.serie; - -import nl.pvanassen.highchart.api.utils.ArrayString; - -public class SeriesCenter extends ArrayString { - - private static final long serialVersionUID = 1L; - - public String getX() { - return get( 0 ); - } - - public String getY() { - return get( 1 ); - } - - public void setX( String x ) { - add( 0, x ); - } - - public void setY( String y ) { - add( 1, y ); - } -} \ No newline at end of file diff --git a/src/main/java/nl/pvanassen/highchart/api/shared/AlignType.java b/src/main/java/nl/pvanassen/highchart/api/shared/AlignType.java new file mode 100644 index 0000000..d641e07 --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/shared/AlignType.java @@ -0,0 +1,26 @@ +/* + * Copyright 2014 Gamma Associates Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.pvanassen.highchart.api.shared; + +/** + * + * @author shaun.lefeuvre + */ +public enum AlignType { + left, + center, + right +} diff --git a/src/main/java/nl/pvanassen/highchart/api/shared/Button.java b/src/main/java/nl/pvanassen/highchart/api/shared/Button.java new file mode 100644 index 0000000..395ef67 --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/shared/Button.java @@ -0,0 +1,68 @@ +/* + * Copyright 2015 Gamma Associates Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.pvanassen.highchart.api.shared; + +import nl.pvanassen.highchart.api.base.BaseObject; + +/** + * + * @author shaun.lefeuvre + */ +public class Button extends BaseObject { + public enum RelativeToType { + plotBox, spacingBox + } + + private Position position; + + private String relativeTo; + + private Theme theme; + + /** + * @return the position + */ + public Position getPosition() { + if(this.position == null) { + this.position = new Position(); + } + return position; + } + + /** + * @return the relativeTo + */ + public String getRelativeTo() { + return relativeTo; + } + + /** + * @param relativeTo the relativeTo to set + */ + public void setRelativeTo(RelativeToType relativeTo) { + this.relativeTo = EnumString.toString(relativeTo); + } + + /** + * @return the theme + */ + public Theme getTheme() { + if(this.theme == null) { + this.theme = new Theme(); + } + return theme; + } +} diff --git a/src/main/java/nl/pvanassen/highchart/api/shared/DashStyleType.java b/src/main/java/nl/pvanassen/highchart/api/shared/DashStyleType.java new file mode 100644 index 0000000..6d1f7b9 --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/shared/DashStyleType.java @@ -0,0 +1,34 @@ +/* + * Copyright 2014 Gamma Associates Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.pvanassen.highchart.api.shared; + +/** + * + * @author shaun.lefeuvre + */ +public enum DashStyleType { + Solid, + ShortDash, + ShortDot, + ShortDashDot, + ShortDashDotDot, + Dot, + Dash, + LongDash, + DashDot, + LongDashDot, + LongDashDotDot +} diff --git a/src/main/java/nl/pvanassen/highchart/api/shared/EnumString.java b/src/main/java/nl/pvanassen/highchart/api/shared/EnumString.java new file mode 100644 index 0000000..2642093 --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/shared/EnumString.java @@ -0,0 +1,32 @@ +/* + * Copyright 2014 Gamma Associates Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.pvanassen.highchart.api.shared; + +/** + * + * @author shaun.lefeuvre + */ +public class EnumString { + private EnumString() {} + + public static String toString( + final Enum<?> src) { + if(src != null) { + return src.name(); + } + return null; + } +} diff --git a/src/main/java/nl/pvanassen/highchart/api/shared/HexColor.java b/src/main/java/nl/pvanassen/highchart/api/shared/HexColor.java new file mode 100644 index 0000000..ca939df --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/shared/HexColor.java @@ -0,0 +1,39 @@ +/* + * Copyright 2014 Gamma Associates Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.pvanassen.highchart.api.shared; + +import java.awt.Color; + +/** + * + * @author shaun.lefeuvre + */ +public class HexColor { + + private HexColor() {} + + public static String toString( + final Color src) { + if(src != null) { + return String.format( + "#%02x%02x%02x", + src.getRed(), + src.getGreen(), + src.getBlue()); + } + return null; + } +} diff --git a/src/main/java/nl/pvanassen/highchart/api/shared/Position.java b/src/main/java/nl/pvanassen/highchart/api/shared/Position.java new file mode 100644 index 0000000..9953684 --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/shared/Position.java @@ -0,0 +1,97 @@ +/* + * Copyright 2015 Gamma Associates Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.pvanassen.highchart.api.shared; + +import nl.pvanassen.highchart.api.base.BaseObject; + +/** + * + * @author shaun.lefeuvre + */ +public class Position extends BaseObject { + + private Integer x; + + private Integer y; + + private String align; + + private String verticalAlign; + + /** + * @return the x + */ + public Integer getX() { + return x; + } + + /** + * @param x the x to set + */ + public Position setX(Integer x) { + this.x = x; + return this; + } + + /** + * @return the y + */ + public Integer getY() { + return y; + } + + /** + * @param y the y to set + */ + public Position setY(Integer y) { + this.y = y; + return this; + } + + /** + * @return the align + */ + public String getAlign() { + return align; + } + + /** + * @param align the align to set + * @return + */ + public Position setAlign(AlignType align) { + this.align = EnumString.toString(align); + return this; + } + + /** + * @return the verticalAlign + */ + public String getVerticalAlign() { + return verticalAlign; + } + + /** + * @param verticalAlign the verticalAlign to set + * @return + */ + public Position setVerticalAlign(VerticalAlignType verticalAlign) { + this.verticalAlign = EnumString.toString(verticalAlign); + return this; + } + + +} diff --git a/src/main/java/nl/pvanassen/highchart/api/shared/SeriesType.java b/src/main/java/nl/pvanassen/highchart/api/shared/SeriesType.java index 85bcf25..4328a47 100644 --- a/src/main/java/nl/pvanassen/highchart/api/shared/SeriesType.java +++ b/src/main/java/nl/pvanassen/highchart/api/shared/SeriesType.java @@ -1,61 +1,13 @@ package nl.pvanassen.highchart.api.shared; public enum SeriesType { - TABLE { - @Override - public <I, O> O accept( SeriesTypeVisitor<I, O> visitor, I in ) { - return visitor.visitTable( this, in ); - } - }, - COLUMN { - @Override - public <I, O> O accept( SeriesTypeVisitor<I, O> visitor, I in ) { - return visitor.visitColumn( this, in ); - } - }, - AREA { - @Override - public <I, O> O accept( SeriesTypeVisitor<I, O> visitor, I in ) { - return visitor.visitArea( this, in ); - } - }, - AREASPLINE { - @Override - public <I, O> O accept( SeriesTypeVisitor<I, O> visitor, I in ) { - return visitor.visitAreaspline( this, in ); - } - }, - BAR { - @Override - public <I, O> O accept( SeriesTypeVisitor<I, O> visitor, I in ) { - return visitor.visitBar( this, in ); - } - }, - LINE { - @Override - public <I, O> O accept( SeriesTypeVisitor<I, O> visitor, I in ) { - return visitor.visitLine( this, in ); - } - }, - PIE { - @Override - public <I, O> O accept( SeriesTypeVisitor<I, O> visitor, I in ) { - return visitor.visitPie( this, in ); - } - }, - SCATTER { - @Override - public <I, O> O accept( SeriesTypeVisitor<I, O> visitor, I in ) { - return visitor.visitScatter( this, in ); - } - }, - SPLINE { - @Override - public <I, O> O accept( SeriesTypeVisitor<I, O> visitor, I in ) { - return visitor.visitSpline( this, in ); - } - }; - - public abstract <I, O> O accept( SeriesTypeVisitor<I, O> visitor, I in ); - + TABLE, + COLUMN, + AREA, + AREASPLINE, + BAR, + LINE, + PIE, + SCATTER, + SPLINE; } \ No newline at end of file diff --git a/src/main/java/nl/pvanassen/highchart/api/shared/SeriesTypeVisitor.java b/src/main/java/nl/pvanassen/highchart/api/shared/SeriesTypeVisitor.java deleted file mode 100644 index af8881c..0000000 --- a/src/main/java/nl/pvanassen/highchart/api/shared/SeriesTypeVisitor.java +++ /dev/null @@ -1,23 +0,0 @@ -package nl.pvanassen.highchart.api.shared; - -public interface SeriesTypeVisitor<I, O> { - - O visitArea( SeriesType type, I in ); - - O visitAreaspline( SeriesType type, I in ); - - O visitBar( SeriesType type, I in ); - - O visitColumn( SeriesType type, I in ); - - O visitLine( SeriesType type, I in ); - - O visitPie( SeriesType type, I in ); - - O visitScatter( SeriesType type, I in ); - - O visitSpline( SeriesType type, I in ); - - O visitTable( SeriesType type, I in ); - -} diff --git a/src/main/java/nl/pvanassen/highchart/api/shared/StackingType.java b/src/main/java/nl/pvanassen/highchart/api/shared/StackingType.java new file mode 100644 index 0000000..ca7cb8e --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/shared/StackingType.java @@ -0,0 +1,25 @@ +/* + * Copyright 2014 Gamma Associates Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.pvanassen.highchart.api.shared; + +/** + * + * @author shaun.lefeuvre + */ +public enum StackingType { + normal, + percent +} diff --git a/src/main/java/nl/pvanassen/highchart/api/shared/Style.java b/src/main/java/nl/pvanassen/highchart/api/shared/Style.java new file mode 100644 index 0000000..19a172d --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/shared/Style.java @@ -0,0 +1,43 @@ +package nl.pvanassen.highchart.api.shared; + +import java.util.HashMap; +import java.util.Map; +import nl.pvanassen.highchart.api.base.BaseObject; +import nl.pvanassen.highchart.api.utils.Utils; + +public class Style + extends BaseObject + implements Styleable<Style> { + + private Map<String, String> properties; + + public Style() { + properties = null; + } + + public Map<String, String> getProperties() { + return properties; + } + + public String getProperty(String property) { + return properties != null ? properties.get(property) : null; + } + + public Style setProperty(String property, String value) { + if (properties == null) { + properties = new HashMap<String, String>(); + } + properties.put(property, value); + return this; + } + + @Override + public Style style( + final Style src) { + if(src == null) { + return this; + } + Utils.stylePrimitiveMap(this.properties, src.properties); + return this; + } +} diff --git a/src/main/java/nl/pvanassen/highchart/api/shared/Styleable.java b/src/main/java/nl/pvanassen/highchart/api/shared/Styleable.java new file mode 100644 index 0000000..0caf787 --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/shared/Styleable.java @@ -0,0 +1,24 @@ +/* + * Copyright 2015 Gamma Associates Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.pvanassen.highchart.api.shared; + +/** + * + * @author shaun.lefeuvre + */ +public interface Styleable<T> { + public T style(T src); +} diff --git a/src/main/java/nl/pvanassen/highchart/api/shared/Theme.java b/src/main/java/nl/pvanassen/highchart/api/shared/Theme.java new file mode 100644 index 0000000..adc0ade --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/shared/Theme.java @@ -0,0 +1,34 @@ +/* + * Copyright 2015 Gamma Associates Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.pvanassen.highchart.api.shared; + +import nl.pvanassen.highchart.api.plotoption.PlotOptionsStates; + +/** + * + * @author shaun.lefeuvre + */ +public class Theme extends Style { + + private PlotOptionsStates states; + + public PlotOptionsStates getStates() { + if(this.states == null) { + this.states = new PlotOptionsStates(); + } + return this.states; + } +} diff --git a/src/main/java/nl/pvanassen/highchart/api/shared/VerticalAlignType.java b/src/main/java/nl/pvanassen/highchart/api/shared/VerticalAlignType.java new file mode 100644 index 0000000..ac08f7b --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/shared/VerticalAlignType.java @@ -0,0 +1,26 @@ +/* + * Copyright 2014 Gamma Associates Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.pvanassen.highchart.api.shared; + +/** + * + * @author shaun.lefeuvre + */ +public enum VerticalAlignType { + top, + middle, + bottom +} diff --git a/src/main/java/nl/pvanassen/highchart/api/utils/ArrayString.java b/src/main/java/nl/pvanassen/highchart/api/utils/ArrayString.java index b23f9a9..59fe437 100644 --- a/src/main/java/nl/pvanassen/highchart/api/utils/ArrayString.java +++ b/src/main/java/nl/pvanassen/highchart/api/utils/ArrayString.java @@ -1,52 +1,52 @@ package nl.pvanassen.highchart.api.utils; -@SuppressWarnings( "serial" ) +@SuppressWarnings("serial") public class ArrayString extends JsonArray<String> { public String join() { - return join( "," ); + return join(","); } - public String join( String separator ) { + public String join(String separator) { StringBuffer sb = new StringBuffer(); int size = length(); - if ( size < 1 ) { + if (size < 1) { return sb.toString(); } - sb.append( getItem( 0 ) ); - for ( int i = 1; i < size; i++ ) { - sb.append( separator ); - sb.append( getItem( i ) ); + sb.append(getItem(0)); + for (int i = 1; i < size; i++) { + sb.append(separator); + sb.append(getItem(i)); } return sb.toString(); } - public ArrayString pushString( String value ) { - pushItem( value ); + public ArrayString pushString(String value) { + pushItem(value); return this; } - public void setLength( int newLength ) { + public void setLength(int newLength) { } - public ArrayString setString( int index, String value ) { - setItem( index, value ); + public ArrayString setString(int index, String value) { + setItem(index, value); return this; } public String shiftItem() { - if ( length() < 1 ) { + if (length() < 1) { return null; } - return remove( 0 ); + return remove(0); } - public void unshiftItem( String value ) { - add( 0, value ); + public void unshiftItem(String value) { + add(0, value); } } diff --git a/src/main/java/nl/pvanassen/highchart/api/utils/JsonArray.java b/src/main/java/nl/pvanassen/highchart/api/utils/JsonArray.java index 8210388..4547d02 100644 --- a/src/main/java/nl/pvanassen/highchart/api/utils/JsonArray.java +++ b/src/main/java/nl/pvanassen/highchart/api/utils/JsonArray.java @@ -1,19 +1,18 @@ package nl.pvanassen.highchart.api.utils; import java.util.ArrayList; +import nl.pvanassen.highchart.api.base.GsonHelper; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; +import nl.pvanassen.highchart.api.shared.Jsonify; -@XmlRootElement -@XmlAccessorType( XmlAccessType.NONE ) -public class JsonArray<E> extends ArrayList<E> { +public class JsonArray<E> + extends ArrayList<E> + implements Jsonify { private static final long serialVersionUID = 1L; - public E getItem( int index ) { - return get( index ); + public E getItem(int index) { + return get(index); } public Integer getLength() { @@ -24,32 +23,37 @@ public int length() { return size(); } - public JsonArray<E> pushElement( E value ) { - pushItem( value ); + public JsonArray<E> pushElement(E value) { + pushItem(value); return this; } - public void pushItem( E value ) { - add( value ); + public void pushItem(E value) { + add(value); } - public JsonArray<E> setElement( int index, E value ) { - setItem( index, value ); + public JsonArray<E> setElement(int index, E value) { + setItem(index, value); return this; } - public void setItem( int index, E value ) { - if ( size() > index ) { - set( index, value ); + public void setItem(int index, E value) { + if (size() > index) { + set(index, value); } - else if ( size() == index ) { - add( index, value ); + else if (size() == index) { + add(index, value); } else { - while ( size() < index ) { - add( null ); + while (size() < index) { + add(null); } - add( index, value ); + add(index, value); } } + + @Override + public String toJson() { + return GsonHelper.toJson(this); + } } diff --git a/src/main/java/nl/pvanassen/highchart/api/utils/Utils.java b/src/main/java/nl/pvanassen/highchart/api/utils/Utils.java new file mode 100644 index 0000000..f3c8833 --- /dev/null +++ b/src/main/java/nl/pvanassen/highchart/api/utils/Utils.java @@ -0,0 +1,66 @@ +/* + * Copyright 2015 Gamma Associates Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.pvanassen.highchart.api.utils; + +import java.util.Map; +import nl.pvanassen.highchart.api.shared.Styleable; + +/** + * + * @author shaun.lefeuvre + */ +public class Utils { + public static boolean isAnyNull(final Object...objects) { + for(final Object t:objects) { + if(t == null) { + return true; + } + } + return false; + } + + public static <T extends Styleable> void style(final T target, final T src) { + if(!isAnyNull(target, src)) { + target.style(src); + } + } + + public static <T extends Styleable> void styleArray(final JsonArray<T> target, final JsonArray<T> src) { + if(!isAnyNull(target, src)) { + for(int i = 0; i < Math.min(target.size(), src.size()); i++) { + style(target.get(i), src.get(i)); + } + } + } + + public static <T> void stylePrimitiveArray( + final JsonArray<T> target, + final JsonArray<T> src) { + if(!isAnyNull(target, src)) { + for(int i = 0; i < Math.min(target.size(), src.size()); i++) { + target.set(i, src.get(i)); + } + } + } + + public static <K,V> void stylePrimitiveMap( + final Map<K, V> target, + final Map<K, V> src) { + if(!isAnyNull(target, src)) { + target.putAll(src); + } + } +} diff --git a/src/test/java/nl/pvanassen/highchart/TestColumnBasic.java b/src/test/java/nl/pvanassen/highchart/TestColumnBasic.java index 9606f74..45ba907 100644 --- a/src/test/java/nl/pvanassen/highchart/TestColumnBasic.java +++ b/src/test/java/nl/pvanassen/highchart/TestColumnBasic.java @@ -1,61 +1,94 @@ package nl.pvanassen.highchart; import nl.pvanassen.highchart.api.ChartOptions; +import nl.pvanassen.highchart.api.Legend.LegendLayoutType; import nl.pvanassen.highchart.api.Point; import nl.pvanassen.highchart.api.Series; +import nl.pvanassen.highchart.api.shared.AlignType; import nl.pvanassen.highchart.api.shared.SeriesType; +import nl.pvanassen.highchart.api.shared.VerticalAlignType; import nl.pvanassen.highchart.api.utils.JsonArray; import org.junit.Assert; import org.junit.Test; public class TestColumnBasic { - private static final String columnBasicJson = "{\"chart\":{\"width\":800,\"height\":400,\"defaultSeriesType\":\"column\",\"marginLeft\":70,\"marginTop\":80},\"legend\":{\"align\":\"left\",\"layout\":\"vertical\",\"verticalAlign\":\"top\",\"x\":100,\"y\":70},\"plotOptions\":{\"area\":{\"borderWidth\":0},\"areaspline\":{\"borderWidth\":0},\"line\":{\"borderWidth\":0},\"pie\":{\"borderWidth\":0},\"series\":{\"borderWidth\":0},\"spline\":{\"borderWidth\":0},\"column\":{\"borderWidth\":0},\"bar\":{\"borderWidth\":0}},\"series\":[{\"data\":[{\"y\":49.9},{\"y\":71.5},{\"y\":106.4},{\"y\":129.2},{\"y\":144.0},{\"y\":176.0},{\"y\":135.6},{\"y\":148.5},{\"y\":216.4},{\"y\":194.1},{\"y\":95.6},{\"y\":54.4}],\"name\":\"Tokyo\"},{\"data\":[{\"y\":83.6},{\"y\":78.8},{\"y\":98.5},{\"y\":93.4},{\"y\":106.0},{\"y\":84.5},{\"y\":105.0},{\"y\":104.3},{\"y\":91.2},{\"y\":83.5},{\"y\":106.6},{\"y\":92.3}],\"name\":\"New York\"},{\"data\":[{\"y\":48.9},{\"y\":38.8},{\"y\":39.3},{\"y\":41.4},{\"y\":47.0},{\"y\":48.3},{\"y\":59.0},{\"y\":59.6},{\"y\":52.4},{\"y\":65.2},{\"y\":59.3},{\"y\":51.2}],\"name\":\"London\"},{\"data\":[{\"y\":42.4},{\"y\":33.2},{\"y\":34.5},{\"y\":39.7},{\"y\":52.6},{\"y\":75.5},{\"y\":57.4},{\"y\":60.4},{\"y\":47.6},{\"y\":39.1},{\"y\":46.8},{\"y\":51.1}],\"name\":\"Berlin\"}],\"title\":{\"text\":\"Monthly Average Rainfall\"},\"subtitle\":{\"text\":\"Source: WorldClimate.com\"},\"xAxis\":{\"categories\":[\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\",\"Jul\",\"Aug\",\"Sep\",\"Oct\",\"Nov\",\"Dec\"]},\"yAxis\":{\"min\":0.0,\"title\":{\"text\":\"Rainfall (mm)\"}}}"; + + private static final String columnBasicJson = "{\"chart\":" + + "{\"width\":800,\"height\":400,\"defaultSeriesType\":\"column\",\"marginLeft\":70,\"marginTop\":80}," + + "\"legend\":{\"align\":\"left\",\"layout\":\"vertical\",\"verticalAlign\":\"top\",\"x\":100,\"y\":70}," + + "\"plotOptions\":{\"column\":{\"borderWidth\":0}}," + + "\"series\":[{\"data\":[{\"y\":49.9},{\"y\":71.5},{\"y\":106.4},{\"y\":129.2},{\"y\":144.0},{\"y\":176.0},{\"y\":135.6},{\"y\":148.5},{\"y\":216.4},{\"y\":194.1},{\"y\":95.6},{\"y\":54.4}],\"name\":\"Tokyo\"}," + + "{\"data\":[{\"y\":83.6},{\"y\":78.8},{\"y\":98.5},{\"y\":93.4},{\"y\":106.0},{\"y\":84.5},{\"y\":105.0},{\"y\":104.3},{\"y\":91.2},{\"y\":83.5},{\"y\":106.6},{\"y\":92.3}],\"name\":\"New York\"}," + + "{\"data\":[{\"y\":48.9},{\"y\":38.8},{\"y\":39.3},{\"y\":41.4},{\"y\":47.0},{\"y\":48.3},{\"y\":59.0},{\"y\":59.6},{\"y\":52.4},{\"y\":65.2},{\"y\":59.3},{\"y\":51.2}],\"name\":\"London\"}," + + "{\"data\":[{\"y\":42.4},{\"y\":33.2},{\"y\":34.5},{\"y\":39.7},{\"y\":52.6},{\"y\":75.5},{\"y\":57.4},{\"y\":60.4},{\"y\":47.6},{\"y\":39.1},{\"y\":46.8},{\"y\":51.1}],\"name\":\"Berlin\"}]," + + "\"title\":{\"text\":\"Monthly Average Rainfall\"},\"subtitle\":{\"text\":\"Source: WorldClimate.com\"},\"xAxis\":[{\"categories\":[\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\",\"Jul\",\"Aug\",\"Sep\",\"Oct\",\"Nov\",\"Dec\"]}],\"yAxis\":[" + + "{\"min\":0.0,\"title\":{\"text\":\"Rainfall (mm)\"}}]}"; @Test public void createColumnBasic() { // http://highcharts.com/demo/column-basic ChartOptions chartOptions = new ChartOptions(); - chartOptions.getChart().setDefaultSeriesType( SeriesType.COLUMN ).setWidth( 800 ).setHeight( 400 ).setMarginLeft( 70 ).setMarginTop( 80 ); + chartOptions.getChart().setDefaultSeriesType(SeriesType.COLUMN).setWidth(800).setHeight(400).setMarginLeft(70) + .setMarginTop(80); // titles - chartOptions.getTitle().setText( "Monthly Average Rainfall" ); - chartOptions.getSubtitle().setText( "Source: WorldClimate.com" ); + chartOptions.getTitle().setText("Monthly Average Rainfall"); + chartOptions.getSubtitle().setText("Source: WorldClimate.com"); // xAxis - chartOptions.getXAxis().getCategories().pushString( "Jan" ).pushString( "Feb" ).pushString( "Mar" ).pushString( "Apr" ).pushString( "May" ).pushString( "Jun" ).pushString( "Jul" ).pushString( "Aug" ).pushString( "Sep" ).pushString( "Oct" ).pushString( "Nov" ).pushString( "Dec" ); + chartOptions.getXAxis(0).getCategories().pushString("Jan").pushString("Feb").pushString("Mar").pushString("Apr") + .pushString("May").pushString("Jun").pushString("Jul").pushString("Aug").pushString("Sep") + .pushString("Oct").pushString("Nov").pushString("Dec"); // yAxis - chartOptions.getYAxis().setMin( 0 ).getTitle().setText( "Rainfall (mm)" ); + chartOptions.getYAxis(0).setMin(0.0).getTitle().setText("Rainfall (mm)"); // Legend - chartOptions.getLegend().setLayout( "vertical" ).setAlign( "left" ).setVerticalAlign( "top" ).setX( 100 ).setY( 70 ); + chartOptions.getLegend().setLayout(LegendLayoutType.vertical).setAlign(AlignType.left).setVerticalAlign(VerticalAlignType.top).setX(100).setY(70); // PlotOptions - chartOptions.getPlotOptions().getColumn().setBorderWidth( 0 ); + chartOptions.getPlotOptions().getColumn().setBorderWidth(0); // Several series - addSeries( chartOptions, "Tokyo", new double[] { 49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4 } ); + addSeries(chartOptions, "Tokyo", new double[] { 49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, + 194.1, 95.6, 54.4 }); + + addSeries(chartOptions, "New York", new double[] { 83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, + 83.5, 106.6, 92.3 }); + + addSeries(chartOptions, "London", new double[] { 48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, + 59.3, 51.2 }); + + addSeries(chartOptions, "Berlin", new double[] { 42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, + 46.8, 51.1 }); - addSeries( chartOptions, "New York", new double[] { 83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3 } ); + String json = chartOptions.toJson(); + + System.out.println(chartOptions.toJson()); - addSeries( chartOptions, "London", new double[] { 48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2 } ); + Assert.assertEquals("Expected column basic json", TestColumnBasic.columnBasicJson, json); + } - addSeries( chartOptions, "Berlin", new double[] { 42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1 } ); + @Test + public void testWrongMargins() { + ChartOptions chartOptions = new ChartOptions(); + chartOptions.getChart().setDefaultSeriesType(SeriesType.COLUMN); // do not set any margins! String json = chartOptions.toJson(); - Assert.assertEquals( "Expected column basic json", columnBasicJson, json ); + Assert.assertEquals("There should be no margins in the json", "{\"chart\":{\"defaultSeriesType\":\"column\"}}", + json); } - private void addSeries( ChartOptions chartOptions, String seriesName, double[] datas ) { + private void addSeries(ChartOptions chartOptions, String seriesName, double[] datas) { - Series newSeries = new Series().setName( seriesName ); + Series newSeries = new Series().setName(seriesName); final JsonArray<Point> seriesDatas = newSeries.getData(); - for ( double d : datas ) { - seriesDatas.pushElement( new Point().setY( d ) ); + for (double d : datas) { + seriesDatas.pushElement(new Point().setY(d)); } - chartOptions.getSeries().pushElement( newSeries ); + chartOptions.getSeries().pushElement(newSeries); } } diff --git a/src/test/java/nl/pvanassen/highchart/TestPieChart.java b/src/test/java/nl/pvanassen/highchart/TestPieChart.java deleted file mode 100644 index 29a7307..0000000 --- a/src/test/java/nl/pvanassen/highchart/TestPieChart.java +++ /dev/null @@ -1,34 +0,0 @@ -package nl.pvanassen.highchart; - -import nl.pvanassen.highchart.api.ChartOptions; -import nl.pvanassen.highchart.api.Point; -import nl.pvanassen.highchart.api.Series; - -import org.junit.Assert; -import org.junit.Test; - -public class TestPieChart { - private static final String pieJson = "{\"chart\":{\"width\":800,\"height\":600,\"marginLeft\":70,\"marginTop\":80},\"plotOptions\":{\"area\":{\"borderWidth\":0},\"areaspline\":{\"borderWidth\":0},\"line\":{\"borderWidth\":0},\"pie\":{\"dataLabels\":{\"color\":\"#000000\",\"enabled\":true,\"formatter\":\"function() {return \\u0027\\u003cb\\u003e\\u0027+ this.point.name +\\u0027\\u003c/b\\u003e: \\u0027+ this.y +\\u0027 %\\u0027;}\",\"align\":\"center\",\"rotation\":0.0},\"allowPointSelect\":true,\"borderWidth\":0},\"series\":{\"borderWidth\":0},\"spline\":{\"borderWidth\":0},\"column\":{\"borderWidth\":0},\"bar\":{\"borderWidth\":0}},\"series\":[{\"data\":[{\"y\":45.0,\"name\":\"Firefox\"},{\"y\":26.8,\"name\":\"IE\"},{\"y\":12.8,\"selected\":true,\"sliced\":true,\"name\":\"Chrome\"},{\"y\":8.5,\"name\":\"Safari\"},{\"y\":6.2,\"name\":\"Opera\"},{\"y\":0.7,\"name\":\"Others\"}],\"name\":\"Browser share\",\"type\":\"pie\"}],\"title\":{\"text\":\"Browser market shares at a specific website, 2010\"}}"; - - @Test - public void createPieChart() { - // http://highcharts.com/demo/pie-basic - ChartOptions chartOptions = new ChartOptions(); - chartOptions.getChart().setWidth( 800 ).setHeight( 600 ).setMarginLeft( 70 ).setMarginTop( 80 ); - // title - chartOptions.getTitle().setText( "Browser market shares at a specific website, 2010" ); - - // plotOptions - chartOptions.getPlotOptions().getPie().setAllowPointSelect( true ).getDataLabels().setEnabled( true ).setColor( "#000000" ).setFormatter( "function() {return '<b>'+ this.point.name +'</b>: '+ this.y +' %';}" ); - - Series newSeries = new Series().setName( "Browser share" ).setType( "pie" ); - chartOptions.getSeries().pushElement( newSeries ); - newSeries.getData().pushElement( new Point().setName( "Firefox" ).setY( 45 ) ).pushElement( new Point().setName( "IE" ).setY( 26.8 ) ).pushElement( new Point().setName( "Chrome" ).setY( 12.8 ).setSliced( true ).setSelected( true ) ).pushElement( new Point().setName( "Safari" ).setY( 8.5 ) ).pushElement( new Point().setName( "Opera" ).setY( 6.2 ) ).pushElement( new Point().setName( "Others" ).setY( 0.7 ) ); - - String json = chartOptions.toJson(); - - Assert.assertEquals( "Expected pie json", pieJson, json ); - - } - -} diff --git a/src/test/java/nl/pvanassen/highchart/TestSplineIrregularTime.java b/src/test/java/nl/pvanassen/highchart/TestSplineIrregularTime.java index 661ccd3..144e9e0 100644 --- a/src/test/java/nl/pvanassen/highchart/TestSplineIrregularTime.java +++ b/src/test/java/nl/pvanassen/highchart/TestSplineIrregularTime.java @@ -1,6 +1,8 @@ package nl.pvanassen.highchart; import java.util.Calendar; +import java.util.TimeZone; +import nl.pvanassen.highchart.api.Axis; import nl.pvanassen.highchart.api.ChartOptions; import nl.pvanassen.highchart.api.Point; @@ -8,55 +10,122 @@ import nl.pvanassen.highchart.api.format.DateTimeLabelFormats.TimeUnit; import nl.pvanassen.highchart.api.shared.SeriesType; -import org.junit.Test; import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; public class TestSplineIrregularTime { - private static final String splineJson = "{\"chart\":{\"width\":800,\"height\":600,\"defaultSeriesType\":\"spline\",\"marginLeft\":70,\"marginTop\":80},\"plotOptions\":{\"area\":{\"borderWidth\":0},\"areaspline\":{\"borderWidth\":0},\"line\":{\"borderWidth\":0},\"pie\":{\"dataLabels\":{\"color\":\"#000000\",\"enabled\":true,\"formatter\":\"function() {return \\u0027\\u003cb\\u003e\\u0027+ this.point.name +\\u0027\\u003c/b\\u003e: \\u0027+ this.y +\\u0027 %\\u0027;}\",\"align\":\"center\",\"rotation\":0.0},\"allowPointSelect\":true,\"borderWidth\":0},\"series\":{\"borderWidth\":0},\"spline\":{\"borderWidth\":0},\"column\":{\"borderWidth\":0},\"bar\":{\"borderWidth\":0}},\"series\":[{\"data\":[{\"x\":2.58732E10,\"y\":0.0},{\"x\":2.70828E10,\"y\":0.6},{\"x\":2.7774E10,\"y\":0.7},{\"x\":2.89836E10,\"y\":0.8},{\"x\":2.95884E10,\"y\":0.6},{\"x\":3.01932E10,\"y\":0.6},{\"x\":3.123E10,\"y\":0.67},{\"x\":3.15756E10,\"y\":0.81},{\"x\":3.21804E10,\"y\":0.78},{\"x\":3.2526E10,\"y\":0.98},{\"x\":3.3822E10,\"y\":1.84},{\"x\":3.50316E10,\"y\":1.8},{\"x\":3.57228E10,\"y\":1.8},{\"x\":3.62412E10,\"y\":1.92},{\"x\":3.69324E10,\"y\":2.49},{\"x\":3.75372E10,\"y\":2.79},{\"x\":3.78828E10,\"y\":2.73},{\"x\":3.87468E10,\"y\":2.61},{\"x\":3.9438E10,\"y\":2.76},{\"x\":3.97836E10,\"y\":2.82},{\"x\":4.03884E10,\"y\":2.8},{\"x\":4.21164E10,\"y\":2.1},{\"x\":4.41036E10,\"y\":1.1},{\"x\":4.53132E10,\"y\":0.25},{\"x\":4.55724E10,\"y\":0.0}],\"name\":\"Winter 2007-2008\"},{\"data\":[{\"x\":2.50956E10,\"y\":0.0},{\"x\":2.57868E10,\"y\":0.2},{\"x\":2.88972E10,\"y\":0.47},{\"x\":2.97612E10,\"y\":0.55},{\"x\":3.09708E10,\"y\":1.38},{\"x\":3.21804E10,\"y\":1.38},{\"x\":3.27852E10,\"y\":1.38},{\"x\":3.4254E10,\"y\":1.38},{\"x\":3.48588E10,\"y\":1.48},{\"x\":3.5982E10,\"y\":1.5},{\"x\":3.76236E10,\"y\":1.89},{\"x\":3.87468E10,\"y\":2.0},{\"x\":3.96108E10,\"y\":1.94},{\"x\":4.00428E10,\"y\":1.91},{\"x\":4.03884E10,\"y\":1.75},{\"x\":4.09068E10,\"y\":1.6},{\"x\":4.40172E10,\"y\":0.6},{\"x\":4.45356E10,\"y\":0.35},{\"x\":4.51404E10,\"y\":0.0}],\"name\":\"Winter 2008-2009\"},{\"data\":[{\"x\":2.4318E10,\"y\":0.0},{\"x\":2.475E10,\"y\":0.15},{\"x\":2.8638E10,\"y\":0.35},{\"x\":2.98476E10,\"y\":0.46},{\"x\":3.15756E10,\"y\":0.59},{\"x\":3.35628E10,\"y\":0.58},{\"x\":3.4254E10,\"y\":0.62},{\"x\":3.47724E10,\"y\":0.65},{\"x\":3.61548E10,\"y\":0.77},{\"x\":3.7278E10,\"y\":0.77},{\"x\":3.77964E10,\"y\":0.79},{\"x\":3.86604E10,\"y\":0.86},{\"x\":3.96108E10,\"y\":0.8},{\"x\":4.08204E10,\"y\":0.94},{\"x\":4.13388E10,\"y\":0.9},{\"x\":4.32396E10,\"y\":0.39},{\"x\":4.36716E10,\"y\":0.0}],\"name\":\"Winter 2009-2010\"}],\"title\":{\"text\":\"Snow depth in the Vikjafjellet mountain, Norway\"},\"subtitle\":{\"text\":\"An example of irregular time data in Highcharts JS\"},\"xAxis\":{\"type\":\"datetime\",\"dateTimeLabelFormats\":{\"month\":\"%e. %b\",\"year\":\"%b\"}},\"yAxis\":{\"min\":0.0,\"title\":{\"text\":\"Snow depth (m)\"}}}"; + + private static final String splineJson = "{\"chart\":{\"width\":800,\"height\":600,\"defaultSeriesType\":\"spline\",\"marginLeft\":70,\"marginTop\":80},\"plotOptions\":{\"pie\":{\"dataLabels\":{\"color\":\"#000000\",\"enabled\":true,\"formatter\":" + + "\"function() {return \\u0027\\u003cb\\u003e\\u0027+ this.point.name +\\u0027\\u003c/b\\u003e: \\u0027+ this.y +\\u0027 %\\u0027;}\"" + + ",\"align\":\"center\",\"rotation\":0.0},\"allowPointSelect\":true}},\"series\":[{\"data\":[{\"x\":2.583E10,\"y\":0.0},{\"x\":2.70396E10,\"y\":0.6},{\"x\":2.77308E10,\"y\":0.7},{\"x\":2.89404E10,\"y\":0.8},{\"x\":2.95452E10,\"y\":0.6},{\"x\":3.015E10,\"y\":0.6},{\"x\":3.11868E10,\"y\":0.67},{\"x\":3.15324E10,\"y\":0.81},{\"x\":3.21372E10,\"y\":0.78},{\"x\":3.24828E10,\"y\":0.98},{\"x\":3.37788E10,\"y\":1.84},{\"x\":3.49884E10,\"y\":1.8},{\"x\":3.56796E10,\"y\":1.8},{\"x\":3.6198E10,\"y\":1.92},{\"x\":3.68892E10,\"y\":2.49},{\"x\":3.7494E10,\"y\":2.79},{\"x\":3.78396E10,\"y\":2.73},{\"x\":3.87036E10,\"y\":2.61},{\"x\":3.93948E10,\"y\":2.76},{\"x\":3.97404E10,\"y\":2.82},{\"x\":4.03452E10,\"y\":2.8},{\"x\":4.20732E10,\"y\":2.1},{\"x\":4.40604E10,\"y\":1.1},{\"x\":4.527E10,\"y\":0.25},{\"x\":4.55292E10,\"y\":0.0}],\"name\":\"Winter 2007-2008\"},{\"data\":[{\"x\":2.50524E10,\"y\":0.0},{\"x\":2.57436E10,\"y\":0.2},{\"x\":2.8854E10,\"y\":0.47},{\"x\":2.9718E10,\"y\":0.55},{\"x\":3.09276E10,\"y\":1.38},{\"x\":3.21372E10,\"y\":1.38},{\"x\":3.2742E10,\"y\":1.38},{\"x\":3.42108E10,\"y\":1.38},{\"x\":3.48156E10,\"y\":1.48},{\"x\":3.59388E10,\"y\":1.5},{\"x\":3.75804E10,\"y\":1.89},{\"x\":3.87036E10,\"y\":2.0},{\"x\":3.95676E10,\"y\":1.94},{\"x\":3.99996E10,\"y\":1.91},{\"x\":4.03452E10,\"y\":1.75},{\"x\":4.08636E10,\"y\":1.6},{\"x\":4.3974E10,\"y\":0.6},{\"x\":4.44924E10,\"y\":0.35},{\"x\":4.50972E10,\"y\":0.0}],\"name\":\"Winter 2008-2009\"},{\"data\":[{\"x\":2.42748E10,\"y\":0.0},{\"x\":2.47068E10,\"y\":0.15},{\"x\":2.85948E10,\"y\":0.35},{\"x\":2.98044E10,\"y\":0.46},{\"x\":3.15324E10,\"y\":0.59},{\"x\":3.35196E10,\"y\":0.58},{\"x\":3.42108E10,\"y\":0.62},{\"x\":3.47292E10,\"y\":0.65},{\"x\":3.61116E10,\"y\":0.77},{\"x\":3.72348E10,\"y\":0.77},{\"x\":3.77532E10,\"y\":0.79},{\"x\":3.86172E10,\"y\":0.86},{\"x\":3.95676E10,\"y\":0.8},{\"x\":4.07772E10,\"y\":0.94},{\"x\":4.12956E10,\"y\":0.9},{\"x\":4.31964E10,\"y\":0.39},{\"x\":4.36284E10,\"y\":0.0}],\"name\":\"Winter 2009-2010\"}],\"title\":{\"text\":\"Snow depth in the Vikjafjellet mountain, Norway\"},\"subtitle\":{\"text\":\"An example of irregular time data in Highcharts JS\"},\"xAxis\":{\"type\":\"datetime\",\"dateTimeLabelFormats\":{\"month\":\"%e. %b\",\"year\":\"%b\"}},\"yAxis\":{\"min\":0.0,\"title\":{\"text\":\"Snow depth (m)\"}}}"; @Test + @Ignore("Because of rounding errors generated json can be different than expected json") public void testSplineIrregularTime() { + TimeZone.setDefault(TimeZone.getTimeZone("GMT+1")); // http://highcharts.com/demo/spline-irregular-time ChartOptions chartOptions = new ChartOptions(); - chartOptions.getChart().setWidth( 800 ).setHeight( 600 ).setDefaultSeriesType( SeriesType.SPLINE ).setMarginLeft( 70 ).setMarginTop( 80 ); + chartOptions.getChart().setWidth(800).setHeight(600).setDefaultSeriesType(SeriesType.SPLINE).setMarginLeft(70) + .setMarginTop(80); // titles - chartOptions.getTitle().setText( "Snow depth in the Vikjafjellet mountain, Norway" ); - chartOptions.getSubtitle().setText( "An example of irregular time data in Highcharts JS" ); + chartOptions.getTitle().setText("Snow depth in the Vikjafjellet mountain, Norway"); + chartOptions.getSubtitle().setText("An example of irregular time data in Highcharts JS"); // axis - chartOptions.getXAxis().setType( "datetime" ).getDateTimeLabelFormats().set( TimeUnit.MONTH, "%e. %b" ).set( TimeUnit.YEAR, "%b" ); - chartOptions.getYAxis().setMin( 0 ).getTitle().setText( "Snow depth (m)" ); + chartOptions.getXAxis(0).setType(Axis.Type.DATETIME).getDateTimeLabelFormats().set(TimeUnit.MONTH, "%e. %b") + .set(TimeUnit.YEAR, "%b"); + chartOptions.getYAxis(0).setMin(0.0).getTitle().setText("Snow depth (m)"); // plotOptions - chartOptions.getPlotOptions().getPie().setAllowPointSelect( true ).getDataLabels().setEnabled( true ).setColor( "#000000" ).setFormatter( "function() {return '<b>'+ this.point.name +'</b>: '+ this.y +' %';}" ); + chartOptions.getPlotOptions().getPie().setAllowPointSelect(true).getDataLabels().setEnabled(true) + .setColor("#000000"); - Series newSeries = new Series().setName( "Winter 2007-2008" ); - chartOptions.getSeries().pushElement( newSeries ); - newSeries.getData().pushElement( new Point().setX( getDateUTC( 1970, 9, 27 ) ).setY( 0 ) ).pushElement( new Point().setX( getDateUTC( 1970, 10, 10 ) ).setY( 0.6 ) ).pushElement( new Point().setX( getDateUTC( 1970, 10, 18 ) ).setY( 0.7 ) ).pushElement( new Point().setX( getDateUTC( 1970, 11, 2 ) ).setY( 0.8 ) ).pushElement( new Point().setX( getDateUTC( 1970, 11, 9 ) ).setY( 0.6 ) ).pushElement( new Point().setX( getDateUTC( 1970, 11, 16 ) ).setY( 0.6 ) ).pushElement( new Point().setX( getDateUTC( 1970, 11, 28 ) ).setY( 0.67 ) ).pushElement( new Point().setX( getDateUTC( 1971, 0, 1 ) ).setY( 0.81 ) ).pushElement( new Point().setX( getDateUTC( 1971, 0, 8 ) ).setY( 0.78 ) ).pushElement( new Point().setX( getDateUTC( 1971, 0, 12 ) ).setY( 0.98 ) ).pushElement( new Point().setX( getDateUTC( 1971, 0, 27 ) ).setY( 1.84 ) ).pushElement( new Point().setX( getDateUTC( 1971, 1, 10 ) ).setY( 1.8 ) ).pushElement( new Point().setX( getDateUTC( 1971, 1, 18 ) ).setY( 1.8 ) ).pushElement( new Point().setX( getDateUTC( 1971, 1, 24 ) ).setY( 1.92 ) ).pushElement( new Point().setX( getDateUTC( 1971, 2, 4 ) ).setY( 2.49 ) ).pushElement( new Point().setX( getDateUTC( 1971, 2, 11 ) ).setY( 2.79 ) ).pushElement( new Point().setX( getDateUTC( 1971, 2, 15 ) ).setY( 2.73 ) ).pushElement( new Point().setX( getDateUTC( 1971, 2, 25 ) ).setY( 2.61 ) ).pushElement( new Point().setX( getDateUTC( 1971, 3, 2 ) ).setY( 2.76 ) ).pushElement( new Point().setX( getDateUTC( 1971, 3, 6 ) ).setY( 2.82 ) ).pushElement( new Point().setX( getDateUTC( 1971, 3, 13 ) ).setY( 2.8 ) ).pushElement( new Point().setX( getDateUTC( 1971, 4, 3 ) ).setY( 2.1 ) ).pushElement( new Point().setX( getDateUTC( 1971, 4, 26 ) ).setY( 1.1 ) ).pushElement( new Point().setX( getDateUTC( 1971, 5, 9 ) ).setY( 0.25 ) ).pushElement( new Point().setX( getDateUTC( 1971, 5, 12 ) ).setY( 0 ) ); + Series newSeries = new Series().setName("Winter 2007-2008"); + chartOptions.getSeries().pushElement(newSeries); + newSeries.getData().pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 9, 27)).setY(0)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 10, 10)).setY(0.6)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 10, 18)).setY(0.7)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 11, 2)).setY(0.8)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 11, 9)).setY(0.6)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 11, 16)).setY(0.6)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 11, 28)).setY(0.67)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 0, 1)).setY(0.81)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 0, 8)).setY(0.78)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 0, 12)).setY(0.98)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 0, 27)).setY(1.84)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 1, 10)).setY(1.8)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 1, 18)).setY(1.8)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 1, 24)).setY(1.92)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 2, 4)).setY(2.49)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 2, 11)).setY(2.79)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 2, 15)).setY(2.73)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 2, 25)).setY(2.61)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 3, 2)).setY(2.76)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 3, 6)).setY(2.82)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 3, 13)).setY(2.8)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 4, 3)).setY(2.1)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 4, 26)).setY(1.1)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 5, 9)).setY(0.25)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 5, 12)).setY(0)); - newSeries = new Series().setName( "Winter 2008-2009" ); - chartOptions.getSeries().pushElement( newSeries ); - newSeries.getData().pushElement( new Point().setX( getDateUTC( 1970, 9, 18 ) ).setY( 0 ) ).pushElement( new Point().setX( getDateUTC( 1970, 9, 26 ) ).setY( 0.2 ) ).pushElement( new Point().setX( getDateUTC( 1970, 11, 1 ) ).setY( 0.47 ) ).pushElement( new Point().setX( getDateUTC( 1970, 11, 11 ) ).setY( 0.55 ) ).pushElement( new Point().setX( getDateUTC( 1970, 11, 25 ) ).setY( 1.38 ) ).pushElement( new Point().setX( getDateUTC( 1971, 0, 8 ) ).setY( 1.38 ) ).pushElement( new Point().setX( getDateUTC( 1971, 0, 15 ) ).setY( 1.38 ) ).pushElement( new Point().setX( getDateUTC( 1971, 1, 1 ) ).setY( 1.38 ) ).pushElement( new Point().setX( getDateUTC( 1971, 1, 8 ) ).setY( 1.48 ) ).pushElement( new Point().setX( getDateUTC( 1971, 1, 21 ) ).setY( 1.5 ) ).pushElement( new Point().setX( getDateUTC( 1971, 2, 12 ) ).setY( 1.89 ) ).pushElement( new Point().setX( getDateUTC( 1971, 2, 25 ) ).setY( 2.0 ) ).pushElement( new Point().setX( getDateUTC( 1971, 3, 4 ) ).setY( 1.94 ) ).pushElement( new Point().setX( getDateUTC( 1971, 3, 9 ) ).setY( 1.91 ) ).pushElement( new Point().setX( getDateUTC( 1971, 3, 13 ) ).setY( 1.75 ) ).pushElement( new Point().setX( getDateUTC( 1971, 3, 19 ) ).setY( 1.6 ) ).pushElement( new Point().setX( getDateUTC( 1971, 4, 25 ) ).setY( 0.6 ) ).pushElement( new Point().setX( getDateUTC( 1971, 4, 31 ) ).setY( 0.35 ) ).pushElement( new Point().setX( getDateUTC( 1971, 5, 7 ) ).setY( 0 ) ); + newSeries = new Series().setName("Winter 2008-2009"); + chartOptions.getSeries().pushElement(newSeries); + newSeries.getData().pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 9, 18)).setY(0)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 9, 26)).setY(0.2)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 11, 1)).setY(0.47)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 11, 11)).setY(0.55)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 11, 25)).setY(1.38)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 0, 8)).setY(1.38)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 0, 15)).setY(1.38)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 1, 1)).setY(1.38)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 1, 8)).setY(1.48)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 1, 21)).setY(1.5)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 2, 12)).setY(1.89)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 2, 25)).setY(2.0)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 3, 4)).setY(1.94)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 3, 9)).setY(1.91)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 3, 13)).setY(1.75)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 3, 19)).setY(1.6)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 4, 25)).setY(0.6)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 4, 31)).setY(0.35)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 5, 7)).setY(0)); - newSeries = new Series().setName( "Winter 2009-2010" ); - chartOptions.getSeries().pushElement( newSeries ); - newSeries.getData().pushElement( new Point().setX( getDateUTC( 1970, 9, 9 ) ).setY( 0 ) ).pushElement( new Point().setX( getDateUTC( 1970, 9, 14 ) ).setY( 0.15 ) ).pushElement( new Point().setX( getDateUTC( 1970, 10, 28 ) ).setY( 0.35 ) ).pushElement( new Point().setX( getDateUTC( 1970, 11, 12 ) ).setY( 0.46 ) ).pushElement( new Point().setX( getDateUTC( 1971, 0, 1 ) ).setY( 0.59 ) ).pushElement( new Point().setX( getDateUTC( 1971, 0, 24 ) ).setY( 0.58 ) ).pushElement( new Point().setX( getDateUTC( 1971, 1, 1 ) ).setY( 0.62 ) ).pushElement( new Point().setX( getDateUTC( 1971, 1, 7 ) ).setY( 0.65 ) ).pushElement( new Point().setX( getDateUTC( 1971, 1, 23 ) ).setY( 0.77 ) ).pushElement( new Point().setX( getDateUTC( 1971, 2, 8 ) ).setY( 0.77 ) ).pushElement( new Point().setX( getDateUTC( 1971, 2, 14 ) ).setY( 0.79 ) ).pushElement( new Point().setX( getDateUTC( 1971, 2, 24 ) ).setY( 0.86 ) ).pushElement( new Point().setX( getDateUTC( 1971, 3, 4 ) ).setY( 0.8 ) ).pushElement( new Point().setX( getDateUTC( 1971, 3, 18 ) ).setY( 0.94 ) ).pushElement( new Point().setX( getDateUTC( 1971, 3, 24 ) ).setY( 0.9 ) ).pushElement( new Point().setX( getDateUTC( 1971, 4, 16 ) ).setY( 0.39 ) ).pushElement( new Point().setX( getDateUTC( 1971, 4, 21 ) ).setY( 0 ) ); + newSeries = new Series().setName("Winter 2009-2010"); + chartOptions.getSeries().pushElement(newSeries); + newSeries.getData().pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 9, 9)).setY(0)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 9, 14)).setY(0.15)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 10, 28)).setY(0.35)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1970, 11, 12)).setY(0.46)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 0, 1)).setY(0.59)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 0, 24)).setY(0.58)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 1, 1)).setY(0.62)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 1, 7)).setY(0.65)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 1, 23)).setY(0.77)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 2, 8)).setY(0.77)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 2, 14)).setY(0.79)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 2, 24)).setY(0.86)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 3, 4)).setY(0.8)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 3, 18)).setY(0.94)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 3, 24)).setY(0.9)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 4, 16)).setY(0.39)) + .pushElement(new Point().setX(TestSplineIrregularTime.getDateUTC(1971, 4, 21)).setY(0)); String json = chartOptions.toJson(); - Assert.assertEquals( "Expected spline json", splineJson, json ); + Assert.assertEquals("Expected spline json", TestSplineIrregularTime.splineJson, json); } - private static long getDateUTC( int year, int month, int day ) { + private static long getDateUTC(int year, int month, int day) { Calendar cal = Calendar.getInstance(); - cal.set( Calendar.YEAR, year ); - cal.set( Calendar.MONTH, month ); - cal.set( Calendar.DAY_OF_MONTH, day ); - cal.set( Calendar.HOUR, 0 ); - cal.set( Calendar.MINUTE, 0 ); - cal.set( Calendar.SECOND, 0 ); - cal.set( Calendar.MILLISECOND, 0 ); + cal.set(Calendar.YEAR, year); + cal.set(Calendar.MONTH, month); + cal.set(Calendar.DAY_OF_MONTH, day); + cal.set(Calendar.HOUR, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); return cal.getTimeInMillis(); } }