From 9f4148955a7dd46698e66962d16fed46a179df79 Mon Sep 17 00:00:00 2001 From: Manfred Huber Date: Thu, 2 Apr 2015 09:02:48 +0200 Subject: [PATCH] + Different instantiation (!!!) - Take a look at the Code Samples for further info! + Empty Title + Default Background is now transparent + LineChart + BarChart + Margin for Chart + Colors interface + Changing Chart Colors + (JavaDoc) + (Demo UI) --- highchartsapi-demo/highchartsapi-demo.iml | 1 + highchartsapi-demo/pom.xml | 4 +- .../highchartsapi/demo/DemoUI.java | 138 ++++++++++++--- .../highchartsapi/demo/DemoWidgetSet.gwt.xml | 2 + .../webapp/VAADIN/themes/demo/styles.scss | 2 +- .../src/main/webapp/WEB-INF/web.xml | 46 +++++ highchartsapi/pom.xml | 4 +- .../vaadinaddons/highchartsapi/Colors.java | 157 ++++++++++++++++++ .../highchartsapi/HighChartFactory.java | 16 +- .../highchartsapi/HighChartsAPI.java | 44 ----- .../client/HighChartsAPIClientRpc.java | 12 -- .../client/HighChartsAPIConnector.java | 79 --------- .../client/HighChartsAPIServerRpc.java | 12 -- .../client/HighChartsAPIState.java | 8 - .../client/HighChartsAPIWidget.java | 16 -- .../exceptions/HighChartsException.java | 16 ++ .../exceptions/NoChartTypeException.java | 16 ++ .../exceptions/WrongSeriesException.java | 16 ++ .../model/ChartConfiguration.java | 129 ++++++++++++-- .../highchartsapi/model/HighChartsSeries.java | 10 -- .../highchartsapi/model/HighchartsObject.java | 15 ++ .../highchartsapi/model/Margin.java | 55 ++++++ .../highchartsapi/model/PieChartSeries.java | 40 ----- .../highchartsapi/model/Series.java | 41 ----- .../highchartsapi/model/XAxis.java | 2 +- .../highchartsapi/model/YAxis.java | 2 +- .../model/data/PieChartData.java | 39 +++++ .../model/series/BarChartSeries.java | 53 ++++++ .../model/series/HighChartsSeries.java | 14 ++ .../model/series/LineChartSeries.java | 52 ++++++ .../model/series/PieChartSeries.java | 70 ++++++++ highchartsapi/src/main/resources/Changes | 14 ++ 32 files changed, 826 insertions(+), 299 deletions(-) create mode 100644 highchartsapi-demo/src/main/webapp/WEB-INF/web.xml create mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/Colors.java delete mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/HighChartsAPI.java delete mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIClientRpc.java delete mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIConnector.java delete mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIServerRpc.java delete mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIState.java delete mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIWidget.java create mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/exceptions/HighChartsException.java create mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/exceptions/NoChartTypeException.java create mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/exceptions/WrongSeriesException.java delete mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/HighChartsSeries.java create mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/HighchartsObject.java create mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/Margin.java delete mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/PieChartSeries.java delete mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/Series.java create mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/data/PieChartData.java create mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/BarChartSeries.java create mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/HighChartsSeries.java create mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/LineChartSeries.java create mode 100644 highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/PieChartSeries.java create mode 100644 highchartsapi/src/main/resources/Changes diff --git a/highchartsapi-demo/highchartsapi-demo.iml b/highchartsapi-demo/highchartsapi-demo.iml index de1b1cd..e4c1af4 100644 --- a/highchartsapi-demo/highchartsapi-demo.iml +++ b/highchartsapi-demo/highchartsapi-demo.iml @@ -5,6 +5,7 @@ + diff --git a/highchartsapi-demo/pom.xml b/highchartsapi-demo/pom.xml index 6d998cb..8360f93 100644 --- a/highchartsapi-demo/pom.xml +++ b/highchartsapi-demo/pom.xml @@ -1,5 +1,5 @@ - 4.0.0 at.downdrown.vaadinaddons @@ -75,7 +75,7 @@ at.downdrown.vaadinaddons highchartsapi - ${version} + LATEST com.vaadin diff --git a/highchartsapi-demo/src/main/java/at/downdrown/vaadinaddons/highchartsapi/demo/DemoUI.java b/highchartsapi-demo/src/main/java/at/downdrown/vaadinaddons/highchartsapi/demo/DemoUI.java index 5cb1338..1568b6a 100644 --- a/highchartsapi-demo/src/main/java/at/downdrown/vaadinaddons/highchartsapi/demo/DemoUI.java +++ b/highchartsapi-demo/src/main/java/at/downdrown/vaadinaddons/highchartsapi/demo/DemoUI.java @@ -1,9 +1,15 @@ package at.downdrown.vaadinaddons.highchartsapi.demo; -import at.downdrown.vaadinaddons.highchartsapi.HighChartsAPI; - -import javax.servlet.annotation.WebServlet; - +import at.downdrown.vaadinaddons.highchartsapi.Colors; +import at.downdrown.vaadinaddons.highchartsapi.HighChart; +import at.downdrown.vaadinaddons.highchartsapi.HighChartFactory; +import at.downdrown.vaadinaddons.highchartsapi.exceptions.HighChartsException; +import at.downdrown.vaadinaddons.highchartsapi.model.ChartConfiguration; +import at.downdrown.vaadinaddons.highchartsapi.model.ChartType; +import at.downdrown.vaadinaddons.highchartsapi.model.data.PieChartData; +import at.downdrown.vaadinaddons.highchartsapi.model.series.BarChartSeries; +import at.downdrown.vaadinaddons.highchartsapi.model.series.LineChartSeries; +import at.downdrown.vaadinaddons.highchartsapi.model.series.PieChartSeries; import com.vaadin.annotations.Theme; import com.vaadin.annotations.Title; import com.vaadin.annotations.VaadinServletConfiguration; @@ -13,31 +19,125 @@ import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; +import javax.servlet.annotation.WebServlet; +import java.util.ArrayList; +import java.util.List; + @Theme("demo") @Title("HighChartsAPI Add-on Demo") @SuppressWarnings("serial") -public class DemoUI extends UI -{ - - @WebServlet(value = "/*", asyncSupported = true) - @VaadinServletConfiguration(productionMode = false, ui = DemoUI.class, widgetset = "at.downdrown.vaadinaddons.highchartsapi.demo.DemoWidgetSet") - public static class Servlet extends VaadinServlet { - } +public class DemoUI extends UI { @Override protected void init(VaadinRequest request) { - - // Initialize our new UI component - final HighChartsAPI component = new HighChartsAPI(); - - // Show it in the middle of the screen final VerticalLayout layout = new VerticalLayout(); layout.setStyleName("demoContentLayout"); - layout.setSizeFull(); - layout.addComponent(component); - layout.setComponentAlignment(component, Alignment.MIDDLE_CENTER); + + // *** PIE *** + ChartConfiguration pieConfiguration = new ChartConfiguration(); + pieConfiguration.setTitle("TestPie"); + pieConfiguration.setChartType(ChartType.PIE); + pieConfiguration.setBackgroundColor(Colors.WHITE); + + PieChartSeries pieFruits = new PieChartSeries("Fruits"); + PieChartData bananas = new PieChartData("Bananas", 33.2); + PieChartData melons = new PieChartData("Melons", 6.21); + PieChartData apples = new PieChartData("Apples", 3.44); + + pieFruits.getData().add(bananas); + pieFruits.getData().add(melons); + pieFruits.getData().add(apples); + + + pieConfiguration.getSeriesList().add(pieFruits); + try { + HighChart pieChart = HighChartFactory.renderChart(pieConfiguration); + pieChart.setHeight(80, Unit.PERCENTAGE); + pieChart.setWidth(80, Unit.PERCENTAGE); + System.out.println("PieChart Script : " + pieConfiguration.getHighChartValue()); + layout.addComponent(pieChart); + layout.setComponentAlignment(pieChart, Alignment.MIDDLE_CENTER); + } catch (HighChartsException e) { + e.printStackTrace(); + } + + + // *** LINE *** + ChartConfiguration lineConfiguration = new ChartConfiguration(); + lineConfiguration.setTitle("TestLine"); + lineConfiguration.setChartType(ChartType.LINE); + lineConfiguration.setBackgroundColor(Colors.WHITE); + + List bananaValues = new ArrayList(); + bananaValues.add(11.3); + bananaValues.add(25.1); + bananaValues.add(32.7); + + LineChartSeries bananaLine = new LineChartSeries("Bananas", bananaValues); + + List sweetValues = new ArrayList(); + sweetValues.add(33.65); + sweetValues.add(63.24); + sweetValues.add(21.52); + + LineChartSeries choclateLine = new LineChartSeries("Choclate", sweetValues); + + lineConfiguration.getSeriesList().add(bananaLine); + lineConfiguration.getSeriesList().add(choclateLine); + + try { + HighChart lineChart = HighChartFactory.renderChart(lineConfiguration); + lineChart.setHeight(80, Unit.PERCENTAGE); + lineChart.setWidth(80, Unit.PERCENTAGE); + System.out.println("LineChart Script : " + lineConfiguration.getHighChartValue()); + layout.addComponent(lineChart); + layout.setComponentAlignment(lineChart, Alignment.MIDDLE_CENTER); + + } catch (HighChartsException e) { + e.printStackTrace(); + } setContent(layout); + + // *** BAR *** + ChartConfiguration barConfiguration = new ChartConfiguration(); + barConfiguration.setTitle("TestBar"); + barConfiguration.setChartType(ChartType.BAR); + barConfiguration.setBackgroundColor(Colors.WHITE); + + List bananaBarValues = new ArrayList(); + bananaBarValues.add(11.3); + bananaBarValues.add(25.1); + bananaBarValues.add(32.7); + + BarChartSeries bananaBar = new BarChartSeries("Bananas", bananaValues); + + List sweetBarValues = new ArrayList(); + sweetBarValues.add(33.65); + sweetBarValues.add(63.24); + sweetBarValues.add(21.52); + + BarChartSeries choclateBar = new BarChartSeries("Choclate", sweetValues); + + barConfiguration.getSeriesList().add(bananaBar); + barConfiguration.getSeriesList().add(choclateBar); + + try { + HighChart barChart = HighChartFactory.renderChart(barConfiguration); + barChart.setHeight(80, Unit.PERCENTAGE); + barChart.setWidth(80, Unit.PERCENTAGE); + System.out.println("BarChart Script : " + barConfiguration.getHighChartValue()); + layout.addComponent(barChart); + layout.setComponentAlignment(barChart, Alignment.MIDDLE_CENTER); + + } catch (HighChartsException e) { + e.printStackTrace(); + } + setContent(layout); } + @WebServlet(value = {"/demo/*", "/VAADIN/*"}, asyncSupported = true) + @VaadinServletConfiguration(productionMode = false, ui = DemoUI.class, widgetset = "at.downdrown.vaadinaddons.highchartsapi.demo.DemoWidgetSet") + public static class Servlet extends VaadinServlet { + } } diff --git a/highchartsapi-demo/src/main/resources/at/downdrown/vaadinaddons/highchartsapi/demo/DemoWidgetSet.gwt.xml b/highchartsapi-demo/src/main/resources/at/downdrown/vaadinaddons/highchartsapi/demo/DemoWidgetSet.gwt.xml index 64b761f..2e8bc84 100644 --- a/highchartsapi-demo/src/main/resources/at/downdrown/vaadinaddons/highchartsapi/demo/DemoWidgetSet.gwt.xml +++ b/highchartsapi-demo/src/main/resources/at/downdrown/vaadinaddons/highchartsapi/demo/DemoWidgetSet.gwt.xml @@ -29,4 +29,6 @@ --> + + diff --git a/highchartsapi-demo/src/main/webapp/VAADIN/themes/demo/styles.scss b/highchartsapi-demo/src/main/webapp/VAADIN/themes/demo/styles.scss index 88cbc1d..432748a 100644 --- a/highchartsapi-demo/src/main/webapp/VAADIN/themes/demo/styles.scss +++ b/highchartsapi-demo/src/main/webapp/VAADIN/themes/demo/styles.scss @@ -12,7 +12,7 @@ $darkgreen: darken($green, 30%); // You can style your demo app right here .demoContentLayout { - background-color: $gray; + background-color: white; background-image: url(images/radial-gradient.png); background-size: 90%; background-position: center center; diff --git a/highchartsapi-demo/src/main/webapp/WEB-INF/web.xml b/highchartsapi-demo/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..a03778e --- /dev/null +++ b/highchartsapi-demo/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,46 @@ + + + + + + Produktionsmodus + productionMode + false + + + Heartbeat Intervall. + heartbeatInterval + 300 + + + Demo + com.vaadin.server.VaadinServlet + + UIProvider + com.vaadin.server.DefaultUIProvider + + + UI + at.downdrown.vaadinaddons.highchartsapi.demo.DemoUI + + + widgetset + at.downdrown.vaadinaddons.highchartsapi.demo.DemoWidgetSet + + + closeIdleSessions + true + + + + Demo + /* + + + 30 + + \ No newline at end of file diff --git a/highchartsapi/pom.xml b/highchartsapi/pom.xml index 15f5676..b4329d8 100644 --- a/highchartsapi/pom.xml +++ b/highchartsapi/pom.xml @@ -1,11 +1,11 @@ - 4.0.0 at.downdrown.vaadinaddons highchartsapi jar - 1.5 + 1.6 HighChartsAPI Add-on 2015 diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/Colors.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/Colors.java new file mode 100644 index 0000000..8f285ad --- /dev/null +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/Colors.java @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2015 by Manfred Huber. + */ + +package at.downdrown.vaadinaddons.highchartsapi; + +import com.vaadin.shared.ui.colorpicker.Color; + +/** + * Interface with common HTML Colors. + *

+ *

Take a look this for further information.

+ */ +public interface Colors { + + Color ALICEBLUE = new Color(240, 248, 255); + Color ANTIQUEWHITE = new Color(250, 235, 215); + Color AQUA = new Color(0, 255, 255); + Color AQUAMARINE = new Color(127, 255, 212); + Color AZURE = new Color(240, 255, 255); + Color BEIGE = new Color(245, 245, 220); + Color BISUQE = new Color(255, 228, 196); + Color BLACK = new Color(0, 0, 0); + Color BLANCHEDALMOND = new Color(255, 235, 205); + Color BLUE = new Color(0, 0, 255); + Color BLUEVIOLET = new Color(138, 43, 226); + Color BROWN = new Color(165, 42, 42); + Color BURLYWOOD = new Color(222, 184, 135); + Color CADETBLUE = new Color(95, 158, 160); + Color CHARTREUSE = new Color(127, 255, 0); + Color CHOCOLATE = new Color(210, 105, 30); + Color CORAL = new Color(255, 127, 80); + Color CORNFLOWERBLUE = new Color(100, 149, 237); + Color CORNSILK = new Color(255, 248, 220); + Color CRIMSON = new Color(220, 20, 60); + Color CYAN = new Color(0, 255, 255); + Color DARKBLUE = new Color(0, 0, 139); + Color DARKCYAN = new Color(0, 139, 139); + Color DARKGOLDENROD = new Color(184, 134, 11); + Color DARKGREY = new Color(169, 169, 169); + Color DARKGREEN = new Color(0, 100, 0); + Color DARKKHAKI = new Color(189, 183, 107); + Color DARKMAGENTA = new Color(139, 0, 139); + Color DARKOLIVEGREEN = new Color(85, 107, 47); + Color DARKORANGE = new Color(255, 140, 0); + Color DARKORCHID = new Color(153, 50, 204); + Color DARKRED = new Color(139, 0, 0); + Color DARKSALMON = new Color(233, 150, 122); + Color DARKSEAGREEN = new Color(143, 188, 143); + Color DARKSLATEBLUE = new Color(72, 61, 139); + Color DARKSLATEGRAY = new Color(47, 79, 79); + Color DARKTURQUOISE = new Color(0, 206, 209); + Color DARKVIOLET = new Color(148, 0, 211); + Color DEEPPINK = new Color(255, 20, 147); + Color DEEPSKYBLUE = new Color(0, 191, 255); + Color DIMGRAY = new Color(105, 105, 105); + Color DODGERBLUE = new Color(30, 144, 255); + Color FIREBRICK = new Color(178, 34, 34); + Color FLORALWHITE = new Color(255, 250, 240); + Color FORESTGREEN = new Color(34, 139, 34); + Color FUCHSIA = new Color(255, 0, 255); + Color GAINSBORO = new Color(220, 220, 220); + Color GHOSTWHITE = new Color(248, 248, 255); + Color GOLD = new Color(255, 215, 0); + Color GOLDENROD = new Color(218, 165, 32); + Color GRAY = new Color(128, 128, 128); + Color GREEN = new Color(0, 128, 0); + Color GREENYELLOW = new Color(173, 255, 47); + Color HONEYDEW = new Color(240, 255, 240); + Color HOTPINK = new Color(255, 105, 180); + Color INDIANRED = new Color(205, 92, 92); + Color INDIGO = new Color(75, 0, 130); + Color IVORY = new Color(255, 255, 240); + Color KHAKI = new Color(240, 230, 140); + Color LAVENDER = new Color(230, 230, 250); + Color LAVENDERBLUSH = new Color(255, 240, 245); + Color LAWNGREEN = new Color(124, 252, 0); + Color LEMONCHIFFON = new Color(255, 250, 205); + Color LIGHTBLUE = new Color(173, 216, 230); + Color LIGHTCORAL = new Color(240, 128, 128); + Color LIGHTCYAN = new Color(224, 255, 255); + Color LIGHTGOLDENRODYELLOW = new Color(250, 250, 210); + Color LIGHTGRAY = new Color(211, 211, 211); + Color LIGHTGREEN = new Color(144, 238, 144); + Color LIGHTPINK = new Color(255, 182, 193); + Color LIGHTSALMON = new Color(255, 160, 122); + Color LIGHTSEAGREEN = new Color(32, 178, 170); + Color LIGHTSKYBLUE = new Color(135, 206, 250); + Color LIGHTSLATEGRAY = new Color(119, 136, 153); + Color LIGHTSTEELBLUE = new Color(176, 196, 222); + Color LIGHTYELLOW = new Color(255, 255, 224); + Color LIME = new Color(0, 255, 0); + Color LIMEGREEN = new Color(50, 205, 50); + Color LINEN = new Color(250, 240, 230); + Color MAGENTA = new Color(255, 0, 255); + Color MAROON = new Color(128, 0, 0); + Color MEDIUMAQUAMARINE = new Color(102, 205, 170); + Color MEDIUMBLUE = new Color(0, 0, 205); + Color MEDIUMORCHID = new Color(186, 85, 211); + Color MEDIUMPURPLE = new Color(147, 112, 219); + Color MEDIUMSEAGREEN = new Color(60, 179, 113); + Color MEDIUMSLATEBLUE = new Color(123, 104, 238); + Color MEDIUMSPRINGGREEN = new Color(0, 250, 154); + Color MEDIUMTURQUOISE = new Color(72, 209, 204); + Color MEDIUMVIOLETRED = new Color(199, 21, 133); + Color MIDNIGHTBLUE = new Color(25, 25, 112); + Color MINTCREAM = new Color(245, 255, 250); + Color MISTYROSE = new Color(255, 228, 225); + Color MOCCASIN = new Color(255, 228, 181); + Color NAVAJOWHITE = new Color(255, 222, 173); + Color NAVY = new Color(0, 0, 128); + Color OLDLACE = new Color(253, 245, 230); + Color OLIVE = new Color(128, 128, 0); + Color OLIVEDRAB = new Color(107, 142, 35); + Color ORANGE = new Color(255, 165, 0); + Color ORANGERED = new Color(255, 69, 0); + Color ORCHID = new Color(218, 112, 214); + Color PALEGOLDENROD = new Color(238, 232, 170); + Color PALEGREEN = new Color(152, 251, 152); + Color PALETURQUOISE = new Color(175, 238, 238); + Color PALEVIOLETRED = new Color(219, 112, 147); + Color PAPAYAWHIP = new Color(255, 239, 213); + Color PEACHPUFF = new Color(255, 218, 185); + Color PERU = new Color(205, 133, 63); + Color PINK = new Color(255, 192, 203); + Color PLUM = new Color(221, 160, 221); + Color POWDERBLUE = new Color(176, 224, 230); + Color PURPLE = new Color(128, 0, 128); + Color REBECCAPURPLE = new Color(102, 51, 153); + Color RED = new Color(255, 0, 0); + Color ROSYBROWN = new Color(188, 143, 143); + Color ROYALBLUE = new Color(65, 105, 225); + Color SADDLEBROWN = new Color(139, 69, 19); + Color SALMON = new Color(250, 128, 114); + Color SANDYBROWN = new Color(244, 164, 96); + Color SEAGREEN = new Color(46, 139, 87); + Color SEASHELL = new Color(255, 245, 238); + Color SIENNA = new Color(160, 82, 45); + Color SILVER = new Color(192, 192, 192); + Color SKYBLUE = new Color(135, 206, 235); + Color SLATEBLUE = new Color(106, 90, 205); + Color SLATEGRAY = new Color(112, 128, 144); + Color SNOW = new Color(255, 250, 250); + Color SPRINGGREEN = new Color(0, 255, 127); + Color STEELBLUE = new Color(70, 130, 180); + Color TAN = new Color(210, 180, 140); + Color TEAL = new Color(0, 128, 128); + Color THISTLE = new Color(216, 191, 216); + Color TOMATO = new Color(255, 99, 71); + Color TURQUOISE = new Color(64, 224, 208); + Color VIOLET = new Color(238, 130, 238); + Color WHEAT = new Color(245, 222, 179); + Color WHITE = new Color(255, 255, 255); + Color WHITESMOKE = new Color(245, 245, 245); + Color YELLOW = new Color(255, 255, 0); + Color YELLOWGREEN = new Color(154, 205, 50); +} \ No newline at end of file diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/HighChartFactory.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/HighChartFactory.java index e7cfb46..520b272 100644 --- a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/HighChartFactory.java +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/HighChartFactory.java @@ -4,11 +4,25 @@ package at.downdrown.vaadinaddons.highchartsapi; +import at.downdrown.vaadinaddons.highchartsapi.exceptions.HighChartsException; +import at.downdrown.vaadinaddons.highchartsapi.exceptions.NoChartTypeException; +import at.downdrown.vaadinaddons.highchartsapi.exceptions.WrongSeriesException; import at.downdrown.vaadinaddons.highchartsapi.model.ChartConfiguration; public class HighChartFactory { - public static HighChart renderChart(ChartConfiguration configuration) { + /** + * This method renders a chart from a passed {@link ChartConfiguration} object. + * You can catch the super-exception {@link HighChartsException} if you don't + * want to catch each exception seperate. + * + * @param configuration + * @return {@link HighChart} object. + * @throws HighChartsException + * @throws NoChartTypeException + * @throws WrongSeriesException + */ + public static HighChart renderChart(ChartConfiguration configuration) throws HighChartsException { HighChart tempChart = new HighChart(); tempChart.setChartoptions(configuration.getHighChartValue()); return tempChart; diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/HighChartsAPI.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/HighChartsAPI.java deleted file mode 100644 index 2ee1951..0000000 --- a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/HighChartsAPI.java +++ /dev/null @@ -1,44 +0,0 @@ -package at.downdrown.vaadinaddons.highchartsapi; - -import at.downdrown.vaadinaddons.highchartsapi.client.HighChartsAPIClientRpc; -import at.downdrown.vaadinaddons.highchartsapi.client.HighChartsAPIServerRpc; -import at.downdrown.vaadinaddons.highchartsapi.client.HighChartsAPIState; - -import com.vaadin.shared.MouseEventDetails; - -// This is the server-side UI component that provides public API -// for HighChartsAPI -public class HighChartsAPI extends com.vaadin.ui.AbstractComponent { - - private int clickCount = 0; - - // To process events from the client, we implement ServerRpc - private HighChartsAPIServerRpc rpc = new HighChartsAPIServerRpc() { - - // Event received from client - user clicked our widget - public void clicked(MouseEventDetails mouseDetails) { - - // Send nag message every 5:th click with ClientRpc - if (++clickCount % 5 == 0) { - getRpcProxy(HighChartsAPIClientRpc.class) - .alert("Ok, that's enough!"); - } - - // Update shared state. This state update is automatically - // sent to the client. - getState().text = "You have clicked " + clickCount + " times"; - } - }; - - public HighChartsAPI() { - - // To receive events from the client, we register ServerRpc - registerRpc(rpc); - } - - // We must override getState() to cast the state to HighChartsAPIState - @Override - public HighChartsAPIState getState() { - return (HighChartsAPIState) super.getState(); - } -} diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIClientRpc.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIClientRpc.java deleted file mode 100644 index d0c04bb..0000000 --- a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIClientRpc.java +++ /dev/null @@ -1,12 +0,0 @@ -package at.downdrown.vaadinaddons.highchartsapi.client; - -import com.vaadin.shared.communication.ClientRpc; - -// ClientRpc is used to pass events from server to client -// For sending information about the changes to component state, use State instead -public interface HighChartsAPIClientRpc extends ClientRpc { - - // Example API: Fire up alert box in client - public void alert(String message); - -} \ No newline at end of file diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIConnector.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIConnector.java deleted file mode 100644 index c256f3e..0000000 --- a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIConnector.java +++ /dev/null @@ -1,79 +0,0 @@ -package at.downdrown.vaadinaddons.highchartsapi.client; - -import at.downdrown.vaadinaddons.highchartsapi.HighChartsAPI; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.client.MouseEventDetailsBuilder; -import com.vaadin.client.communication.RpcProxy; -import com.vaadin.client.communication.StateChangeEvent; -import com.vaadin.client.ui.AbstractComponentConnector; -import com.vaadin.shared.MouseEventDetails; -import com.vaadin.shared.ui.Connect; - -// Connector binds client-side widget class to server-side component class -// Connector lives in the client and the @Connect annotation specifies the -// corresponding server-side component -@Connect(HighChartsAPI.class) -public class HighChartsAPIConnector extends AbstractComponentConnector { - - // ServerRpc is used to send events to server. Communication implementation - // is automatically created here - HighChartsAPIServerRpc rpc = RpcProxy.create(HighChartsAPIServerRpc.class, this); - - public HighChartsAPIConnector() { - - // To receive RPC events from server, we register ClientRpc implementation - registerRpc(HighChartsAPIClientRpc.class, new HighChartsAPIClientRpc() { - public void alert(String message) { - Window.alert(message); - } - }); - - // We choose listed for mouse clicks for the widget - getWidget().addClickHandler(new ClickHandler() { - public void onClick(ClickEvent event) { - final MouseEventDetails mouseDetails = MouseEventDetailsBuilder - .buildMouseEventDetails(event.getNativeEvent(), - getWidget().getElement()); - - // When the widget is clicked, the event is sent to server with ServerRpc - rpc.clicked(mouseDetails); - } - }); - - } - - // We must implement createWidget() to create correct type of widget - @Override - protected Widget createWidget() { - return GWT.create(HighChartsAPIWidget.class); - } - - - // We must implement getWidget() to cast to correct type - @Override - public HighChartsAPIWidget getWidget() { - return (HighChartsAPIWidget) super.getWidget(); - } - - // We must implement getState() to cast to correct type - @Override - public HighChartsAPIState getState() { - return (HighChartsAPIState) super.getState(); - } - - // Whenever the state changes in the server-side, this method is called - @Override - public void onStateChanged(StateChangeEvent stateChangeEvent) { - super.onStateChanged(stateChangeEvent); - - // State is directly readable in the client after it is set in server - final String text = getState().text; - getWidget().setText(text); - } - -} diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIServerRpc.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIServerRpc.java deleted file mode 100644 index 6eb3f9d..0000000 --- a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIServerRpc.java +++ /dev/null @@ -1,12 +0,0 @@ -package at.downdrown.vaadinaddons.highchartsapi.client; - -import com.vaadin.shared.MouseEventDetails; -import com.vaadin.shared.communication.ServerRpc; - -// ServerRpc is used to pass events from client to server -public interface HighChartsAPIServerRpc extends ServerRpc { - - // Example API: Widget click is clicked - public void clicked(MouseEventDetails mouseDetails); - -} diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIState.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIState.java deleted file mode 100644 index 2f4b7d9..0000000 --- a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIState.java +++ /dev/null @@ -1,8 +0,0 @@ -package at.downdrown.vaadinaddons.highchartsapi.client; - -public class HighChartsAPIState extends com.vaadin.shared.AbstractComponentState { - - // State can have both public variable and bean properties - public String text = "HighChartsAPI"; - -} \ No newline at end of file diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIWidget.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIWidget.java deleted file mode 100644 index 654c5b4..0000000 --- a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/client/HighChartsAPIWidget.java +++ /dev/null @@ -1,16 +0,0 @@ -package at.downdrown.vaadinaddons.highchartsapi.client; - -import com.google.gwt.user.client.ui.Label; - -// Extend any GWT Widget -public class HighChartsAPIWidget extends Label { - - public HighChartsAPIWidget() { - - // CSS class-name should not be v- prefixed - setStyleName("highchartsapi"); - - // State is set to widget in HighChartsAPIConnector - } - -} \ No newline at end of file diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/exceptions/HighChartsException.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/exceptions/HighChartsException.java new file mode 100644 index 0000000..530c42b --- /dev/null +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/exceptions/HighChartsException.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2015 by Manfred Huber. + */ + +package at.downdrown.vaadinaddons.highchartsapi.exceptions; + +public class HighChartsException extends Exception { + + public HighChartsException(String message) { + super(message); + } + + public HighChartsException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/exceptions/NoChartTypeException.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/exceptions/NoChartTypeException.java new file mode 100644 index 0000000..75c5c59 --- /dev/null +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/exceptions/NoChartTypeException.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2015 by Manfred Huber. + */ + +package at.downdrown.vaadinaddons.highchartsapi.exceptions; + +public class NoChartTypeException extends HighChartsException { + + public NoChartTypeException(String message) { + super(message); + } + + public NoChartTypeException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/exceptions/WrongSeriesException.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/exceptions/WrongSeriesException.java new file mode 100644 index 0000000..2401efb --- /dev/null +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/exceptions/WrongSeriesException.java @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2015 by Manfred Huber. + */ + +package at.downdrown.vaadinaddons.highchartsapi.exceptions; + +public class WrongSeriesException extends HighChartsException { + + public WrongSeriesException(String message) { + super(message); + } + + public WrongSeriesException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/ChartConfiguration.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/ChartConfiguration.java index 078373f..cda0aec 100644 --- a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/ChartConfiguration.java +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/ChartConfiguration.java @@ -4,6 +4,9 @@ package at.downdrown.vaadinaddons.highchartsapi.model; +import at.downdrown.vaadinaddons.highchartsapi.exceptions.NoChartTypeException; +import at.downdrown.vaadinaddons.highchartsapi.exceptions.WrongSeriesException; +import at.downdrown.vaadinaddons.highchartsapi.model.series.HighChartsSeries; import com.vaadin.shared.ui.colorpicker.Color; import java.util.ArrayList; @@ -12,19 +15,26 @@ public class ChartConfiguration { private String title = null; - private ChartType chartType = ChartType.PIE; - private Color backgroundColor = new Color(245, 245, 245); + private ChartType chartType = null; + private Color backgroundColor = null; private boolean creditsEnabled = false; private boolean legendEnabled = true; private boolean tooltipEnabled = true; private XAxis xAxis = null; private YAxis yAxis = null; - private List seriesList = new ArrayList(); + private Margin chartMargin = null; + private List seriesList = new ArrayList(); + private List colors = new ArrayList(); public String getTitle() { return title; } + /** + * Set the chart's title. + * + * @param title + */ public void setTitle(String title) { this.title = title; } @@ -33,6 +43,10 @@ public ChartType getChartType() { return chartType; } + /** + * Set chart type. Use the {@link ChartType} enumeration for this purpose. + * @param chartType + */ public void setChartType(ChartType chartType) { this.chartType = chartType; } @@ -41,6 +55,10 @@ public Color getBackgroundColor() { return backgroundColor; } + /** + * Set the chart's background color. Use the {@link at.downdrown.vaadinaddons.highchartsapi.Colors} interface for this purpose. + * @param backgroundColor + */ public void setBackgroundColor(Color backgroundColor) { this.backgroundColor = backgroundColor; } @@ -49,6 +67,10 @@ public boolean isCreditsEnabled() { return creditsEnabled; } + /** + * Set the chart's credits en- or disabled. + * @param creditsEnabled + */ public void setCreditsEnabled(boolean creditsEnabled) { this.creditsEnabled = creditsEnabled; } @@ -57,6 +79,10 @@ public boolean isLegendEnabled() { return legendEnabled; } + /** + * Set the chart's legend en- or disabled. + * @param legendEnabled + */ public void setLegendEnabled(boolean legendEnabled) { this.legendEnabled = legendEnabled; } @@ -65,6 +91,10 @@ public boolean isTooltipEnabled() { return tooltipEnabled; } + /** + * Set the chart's tooltip en- or disabled. + * @param tooltipEnabled + */ public void setTooltipEnabled(boolean tooltipEnabled) { this.tooltipEnabled = tooltipEnabled; } @@ -73,6 +103,10 @@ public XAxis getxAxis() { return xAxis; } + /** + * Set the chart's {@link XAxis} object. + * @param xAxis + */ public void setxAxis(XAxis xAxis) { this.xAxis = xAxis; } @@ -81,24 +115,82 @@ public YAxis getyAxis() { return yAxis; } + /** + * Set the chart's {@link YAxis} object. + * @param yAxis + */ public void setyAxis(YAxis yAxis) { this.yAxis = yAxis; } - public List getSeriesList() { + public Margin getChartMargin() { + return chartMargin; + } + + /** + * Set the chart's margins. Use the {@link Margin} object for this purpose. + * + * @param chartMargin + */ + public void setChartMargin(Margin chartMargin) { + this.chartMargin = chartMargin; + } + + public List getSeriesList() { return seriesList; } - public void setSeriesList(List seriesList) { + /** + * Set the chart's series. + * + * @param seriesList + */ + public void setSeriesList(List seriesList) { this.seriesList = seriesList; } - public String getHighChartValue() { + public List getColors() { + return colors; + } + + /** + * Set the chart's default rendering colors. Use a collection of {@link Color} objects for this purpose. + * Maybe the {@link at.downdrown.vaadinaddons.highchartsapi.Colors} interface is helpful herefore. + * + * @param colors + */ + public void setColors(List colors) { + this.colors = colors; + } + + /** + * Returns the generated HighCharts script. + * + * @return + */ + public String getHighChartValue() throws NoChartTypeException, WrongSeriesException { + + if (getChartType() == null) throw new NoChartTypeException("No ChartType is set to the configuration."); StringBuilder builder = new StringBuilder(); builder.append("{"); - builder.append("chart: { renderTo: 'container', type: '" + getChartType().getHighchartsvalue() + "', backgroundColor: '" + getBackgroundColor().getCSS() + "' }"); - - if (getTitle() != null) builder.append(", title: { text: '" + getTitle() + "' }"); + //Chart properties + builder.append("chart: { renderTo: 'container' "); + builder.append(",type: '" + getChartType().getHighchartsvalue() + "'"); + //Set Background + if (getBackgroundColor() != null) { + builder.append(",backgroundColor: '" + getBackgroundColor().getCSS() + "'"); + } else { + builder.append(",backgroundColor: 'transparent'"); + } + if (getChartMargin() != null) builder.append(getChartMargin().getHighChartValue()); + builder.append("}"); + + //Set Title if any was given + if (getTitle() != null) { + builder.append(", title: { text: '" + getTitle() + "' }"); + } else { + builder.append(", title: { text: null }"); + } if (getxAxis() != null) builder.append(getxAxis().getHighChartValue()); if (getyAxis() != null) builder.append(getyAxis().getHighChartValue()); @@ -109,7 +201,9 @@ public String getHighChartValue() { if (!getSeriesList().isEmpty()) { int seriesNr = 1; builder.append(", series: ["); - for (Series series : getSeriesList()) { + for (HighChartsSeries series : getSeriesList()) { + if (getChartType() != series.getChartType()) + throw new WrongSeriesException("The passed series object has a different chart type than the configuration. Series: " + series.getChartType() + " / Configuration: " + getChartType()); if (seriesNr == 1) { builder.append(series.getHighChartValue()); } else if (seriesNr > 1) { @@ -121,6 +215,21 @@ public String getHighChartValue() { builder.append("]"); } + if (!getColors().isEmpty()) { + int colorsNr = 1; + builder.append(", colors: ["); + for (Color color : getColors()) { + if (colorsNr == 1) { + builder.append("'" + color.getCSS() + "'"); + } else if (colorsNr > 1) { + builder.append(","); + builder.append("'" + color.getCSS() + "'"); + } + colorsNr++; + } + builder.append("]"); + } + builder.append("};"); return builder.toString(); } diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/HighChartsSeries.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/HighChartsSeries.java deleted file mode 100644 index aff1821..0000000 --- a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/HighChartsSeries.java +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) 2015 by Manfred Huber. - */ - -package at.downdrown.vaadinaddons.highchartsapi.model; - -public interface HighChartsSeries { - - public String getHighChartValue(); -} diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/HighchartsObject.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/HighchartsObject.java new file mode 100644 index 0000000..c62c25e --- /dev/null +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/HighchartsObject.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2015 by Manfred Huber. + */ + +package at.downdrown.vaadinaddons.highchartsapi.model; + +/** + * Interface that implements the only-needed Method "getHighChartValue()", + * whicht returns parameters in HighCharts Format. + */ +public interface HighchartsObject { + + String getHighChartValue(); + +} diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/Margin.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/Margin.java new file mode 100644 index 0000000..d799ff9 --- /dev/null +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/Margin.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2015 by Manfred Huber. + */ + +package at.downdrown.vaadinaddons.highchartsapi.model; + +public class Margin implements HighchartsObject { + private int marginLeft; + private int marginTop; + private int marginRight; + private int marginBottom; + + public Margin(int marginLeft, int marginTop, int marginRight, int marginBottom) { + this.marginLeft = marginLeft; + this.marginTop = marginTop; + this.marginRight = marginRight; + this.marginBottom = marginBottom; + } + + public int getMarginLeft() { + return marginLeft; + } + + public void setMarginLeft(int marginLeft) { + this.marginLeft = marginLeft; + } + + public int getMarginTop() { + return marginTop; + } + + public void setMarginTop(int marginTop) { + this.marginTop = marginTop; + } + + public int getMarginRight() { + return marginRight; + } + + public void setMarginRight(int marginRight) { + this.marginRight = marginRight; + } + + public int getMarginBottom() { + return marginBottom; + } + + public void setMarginBottom(int marginBottom) { + this.marginBottom = marginBottom; + } + + public String getHighChartValue() { + return ",margin: [" + marginTop + ", " + marginRight + ", " + marginBottom + ", " + marginLeft + "]"; + } +} diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/PieChartSeries.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/PieChartSeries.java deleted file mode 100644 index c1dfa9b..0000000 --- a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/PieChartSeries.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2015 by Manfred Huber. - */ - -package at.downdrown.vaadinaddons.highchartsapi.model; - -public class PieChartSeries implements HighChartsSeries { - private String type; - private Object value; - - public PieChartSeries(String type, Object value) { - this.type = type; - this.value = value; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Object getValue() { - return value; - } - - public void setValue(Object value) { - this.value = value; - } - - @Override - public String toString() { - return "['"+ type +"', "+ value +"]"; - } - - public String getHighChartValue() { - return "['"+ type +"', "+ value +"]"; - } -} diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/Series.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/Series.java deleted file mode 100644 index 4d33235..0000000 --- a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/Series.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2015 by Manfred Huber. - */ - -package at.downdrown.vaadinaddons.highchartsapi.model; - -import java.util.ArrayList; -import java.util.List; - -public class Series { - private String name; - private List data = new ArrayList(); - - @Deprecated - public Series() { - } - - public Series(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getData() { - return data; - } - - public void setData(List data) { - this.data = data; - } - - public String getHighChartValue() { - return "{ name: '" + getName() + "', data: " + getData() + " }"; - } -} diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/XAxis.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/XAxis.java index 476fa0f..86ce78a 100644 --- a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/XAxis.java +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/XAxis.java @@ -4,7 +4,7 @@ package at.downdrown.vaadinaddons.highchartsapi.model; -public class XAxis { +public class XAxis implements HighchartsObject { private String title; private boolean labelsEnabled = true; diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/YAxis.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/YAxis.java index 0fe9ea5..24104de 100644 --- a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/YAxis.java +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/YAxis.java @@ -4,7 +4,7 @@ package at.downdrown.vaadinaddons.highchartsapi.model; -public class YAxis { +public class YAxis implements HighchartsObject { private String title; private boolean labelsEnabled = true; diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/data/PieChartData.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/data/PieChartData.java new file mode 100644 index 0000000..f8dd104 --- /dev/null +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/data/PieChartData.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015 by Manfred Huber. + */ + +package at.downdrown.vaadinaddons.highchartsapi.model.data; + +import at.downdrown.vaadinaddons.highchartsapi.model.HighchartsObject; + +public class PieChartData implements HighchartsObject { + + private String name; + private Object value; + + public PieChartData(String name, Object value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + @Override + public String getHighChartValue() { + return "['" + this.name + "', " + this.value + "]"; + } +} diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/BarChartSeries.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/BarChartSeries.java new file mode 100644 index 0000000..210bdd0 --- /dev/null +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/BarChartSeries.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015 by Manfred Huber. + */ + +package at.downdrown.vaadinaddons.highchartsapi.model.series; + +import at.downdrown.vaadinaddons.highchartsapi.model.ChartType; + +import java.util.ArrayList; +import java.util.List; + +public class BarChartSeries implements HighChartsSeries { + + private final ChartType chartType = ChartType.BAR; + + private String name; + private List data = new ArrayList(); + + public BarChartSeries(String name) { + this.name = name; + } + + public BarChartSeries(String name, List data) { + this.name = name; + this.data = data; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + @Override + public String getHighChartValue() { + return "{ name: '" + this.name + "', data: " + this.data + " }"; + } + + @Override + public ChartType getChartType() { + return this.chartType; + } +} \ No newline at end of file diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/HighChartsSeries.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/HighChartsSeries.java new file mode 100644 index 0000000..6753be9 --- /dev/null +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/HighChartsSeries.java @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2015 by Manfred Huber. + */ + +package at.downdrown.vaadinaddons.highchartsapi.model.series; + +import at.downdrown.vaadinaddons.highchartsapi.model.ChartType; +import at.downdrown.vaadinaddons.highchartsapi.model.HighchartsObject; + +public interface HighChartsSeries extends HighchartsObject { + + ChartType getChartType(); + +} diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/LineChartSeries.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/LineChartSeries.java new file mode 100644 index 0000000..14e77e8 --- /dev/null +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/LineChartSeries.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2015 by Manfred Huber. + */ + +package at.downdrown.vaadinaddons.highchartsapi.model.series; + +import at.downdrown.vaadinaddons.highchartsapi.model.ChartType; + +import java.util.ArrayList; +import java.util.List; + +public class LineChartSeries implements HighChartsSeries { + + private final ChartType chartType = ChartType.LINE; + private String name; + private List data = new ArrayList(); + + public LineChartSeries(String name) { + this.name = name; + } + + public LineChartSeries(String name, List data) { + this.name = name; + this.data = data; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + @Override + public String getHighChartValue() { + return "{ name: '" + this.name + "', data: " + this.data + " }"; + } + + @Override + public ChartType getChartType() { + return this.chartType; + } +} diff --git a/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/PieChartSeries.java b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/PieChartSeries.java new file mode 100644 index 0000000..7b42e21 --- /dev/null +++ b/highchartsapi/src/main/java/at/downdrown/vaadinaddons/highchartsapi/model/series/PieChartSeries.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2015 by Manfred Huber. + */ + +package at.downdrown.vaadinaddons.highchartsapi.model.series; + +import at.downdrown.vaadinaddons.highchartsapi.model.ChartType; +import at.downdrown.vaadinaddons.highchartsapi.model.data.PieChartData; + +import java.util.ArrayList; +import java.util.List; + +public class PieChartSeries implements HighChartsSeries { + + private final ChartType chartType = ChartType.PIE; + private String name; + private List data = new ArrayList(); + + public PieChartSeries(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getHighChartValue() { + + StringBuilder builder = new StringBuilder(); + builder.append("{ name: '" + this.name + "', data: ["); + + int count = 1; + if (getData() != null) { + + for (PieChartData data : getData()) { + if (count == 1) { + builder.append(data.getHighChartValue()); + } else if (count > 1) { + builder.append(","); + builder.append(data.getHighChartValue()); + } + count++; + } + } + + builder.append("]"); + builder.append("}"); + + return builder.toString(); + } + + @Override + public ChartType getChartType() { + return this.chartType; + } +} + + diff --git a/highchartsapi/src/main/resources/Changes b/highchartsapi/src/main/resources/Changes new file mode 100644 index 0000000..1d8b1de --- /dev/null +++ b/highchartsapi/src/main/resources/Changes @@ -0,0 +1,14 @@ +### Version 1.5 +- Basic Functionality. + +### Version 1.6 ++ Different instantiation (!!!) - Take a look at the Code Samples for further info! ++ Empty Title ++ Default Background is now transparent ++ LineChart ++ BarChart ++ Margin for Chart ++ Colors interface ++ Changing Chart Colors ++ (JavaDoc) ++ (Demo UI) \ No newline at end of file