From c15e57fc40cb1a41d75a236badf61c3623d7c245 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Tue, 28 Feb 2012 12:46:09 +0100 Subject: [PATCH] unpacked Highcharts sources for 1.1.3 version; preparing for applying patches --- java/org.moxieapps.gwt.highcharts/.classpath | 8 + java/org.moxieapps.gwt.highcharts/.project | 28 + .../.settings/org.eclipse.jdt.core.prefs | 82 + .../.settings/org.eclipse.pde.core.prefs | 4 + .../META-INF/MANIFEST.MF | 23 + .../gwt/highcharts/Highcharts.gwt.xml | 5 + .../build.properties | 4 + .../gwt/highcharts/Highcharts.gwt.xml | 5 + .../gwt/highcharts/client/Animation.java | 116 + .../moxieapps/gwt/highcharts/client/Axis.java | 1095 ++++++++ .../gwt/highcharts/client/AxisTitle.java | 155 ++ .../gwt/highcharts/client/BaseChart.java | 2356 +++++++++++++++++ .../gwt/highcharts/client/Chart.java | 134 + .../gwt/highcharts/client/ChartSubtitle.java | 151 ++ .../gwt/highcharts/client/ChartTitle.java | 234 ++ .../gwt/highcharts/client/Color.java | 314 +++ .../gwt/highcharts/client/Configurable.java | 148 ++ .../gwt/highcharts/client/Credits.java | 230 ++ .../client/DateTimeLabelFormats.java | 165 ++ .../gwt/highcharts/client/Exporting.java | 132 + .../gwt/highcharts/client/Extremes.java | 93 + .../gwt/highcharts/client/LabelItem.java | 86 + .../moxieapps/gwt/highcharts/client/Lang.java | 13 + .../gwt/highcharts/client/Legend.java | 478 ++++ .../gwt/highcharts/client/Loading.java | 116 + .../gwt/highcharts/client/Navigation.java | 86 + .../gwt/highcharts/client/PlotBand.java | 170 ++ .../gwt/highcharts/client/PlotLine.java | 260 ++ .../gwt/highcharts/client/Point.java | 699 +++++ .../gwt/highcharts/client/RangeSelector.java | 36 + .../gwt/highcharts/client/Series.java | 798 ++++++ .../gwt/highcharts/client/StockChart.java | 101 + .../gwt/highcharts/client/Style.java | 214 ++ .../gwt/highcharts/client/ToolTip.java | 296 +++ .../gwt/highcharts/client/ToolTipData.java | 361 +++ .../highcharts/client/ToolTipFormatter.java | 103 + .../gwt/highcharts/client/XAxis.java | 178 ++ .../gwt/highcharts/client/YAxis.java | 116 + .../client/events/ChartClickEvent.java | 140 + .../client/events/ChartClickEventHandler.java | 47 + .../client/events/ChartLoadEvent.java | 44 + .../client/events/ChartLoadEventHandler.java | 43 + .../client/events/ChartRedrawEvent.java | 44 + .../events/ChartRedrawEventHandler.java | 44 + .../client/events/ChartSelectionEvent.java | 230 ++ .../events/ChartSelectionEventHandler.java | 47 + .../highcharts/client/events/MouseEvent.java | 150 ++ .../client/events/PointClickEvent.java | 44 + .../client/events/PointClickEventHandler.java | 56 + .../highcharts/client/events/PointEvent.java | 144 + .../events/PointLegendItemClickEvent.java | 44 + .../PointLegendItemClickEventHandler.java | 51 + .../client/events/PointMouseOutEvent.java | 45 + .../events/PointMouseOutEventHandler.java | 51 + .../client/events/PointMouseOverEvent.java | 44 + .../events/PointMouseOverEventHandler.java | 50 + .../client/events/PointRemoveEvent.java | 44 + .../events/PointRemoveEventHandler.java | 52 + .../client/events/PointSelectEvent.java | 45 + .../events/PointSelectEventHandler.java | 51 + .../client/events/PointUnselectEvent.java | 44 + .../events/PointUnselectEventHandler.java | 51 + .../client/events/PointUpdateEvent.java | 46 + .../events/PointUpdateEventHandler.java | 52 + .../events/SeriesCheckboxClickEvent.java | 54 + .../SeriesCheckboxClickEventHandler.java | 51 + .../client/events/SeriesClickEvent.java | 128 + .../events/SeriesClickEventHandler.java | 49 + .../highcharts/client/events/SeriesEvent.java | 64 + .../client/events/SeriesHideEvent.java | 44 + .../client/events/SeriesHideEventHandler.java | 46 + .../events/SeriesLegendItemClickEvent.java | 53 + .../SeriesLegendItemClickEventHandler.java | 51 + .../client/events/SeriesMouseOutEvent.java | 44 + .../events/SeriesMouseOutEventHandler.java | 49 + .../client/events/SeriesMouseOverEvent.java | 44 + .../events/SeriesMouseOverEventHandler.java | 47 + .../client/events/SeriesShowEvent.java | 44 + .../client/events/SeriesShowEventHandler.java | 46 + .../client/labels/AxisLabelsData.java | 76 + .../client/labels/AxisLabelsFormatter.java | 61 + .../client/labels/BaseDataLabels.java | 58 + .../highcharts/client/labels/DataLabels.java | 52 + .../client/labels/DataLabelsData.java | 174 ++ .../client/labels/DataLabelsFormatter.java | 79 + .../gwt/highcharts/client/labels/Labels.java | 176 ++ .../client/labels/PieDataLabels.java | 100 + .../client/labels/PlotBandLabel.java | 263 ++ .../client/labels/PlotLineLabel.java | 265 ++ .../highcharts/client/labels/StackLabels.java | 129 + .../client/labels/StackLabelsData.java | 64 + .../client/labels/StackLabelsFormatter.java | 61 + .../highcharts/client/labels/XAxisLabels.java | 93 + .../highcharts/client/labels/YAxisLabels.java | 78 + .../client/plotOptions/AreaPlotOptions.java | 154 ++ .../plotOptions/AreaSplinePlotOptions.java | 154 ++ .../client/plotOptions/BarPlotOptions.java | 194 ++ .../client/plotOptions/ColumnPlotOptions.java | 186 ++ .../client/plotOptions/LinePlotOptions.java | 40 + .../highcharts/client/plotOptions/Marker.java | 257 ++ .../client/plotOptions/PiePlotOptions.java | 212 ++ .../client/plotOptions/PlotOptions.java | 517 ++++ .../plotOptions/ScatterPlotOptions.java | 41 + .../client/plotOptions/SeriesPlotOptions.java | 420 +++ .../client/plotOptions/SplinePlotOptions.java | 41 + 105 files changed, 16055 insertions(+) create mode 100755 java/org.moxieapps.gwt.highcharts/.classpath create mode 100755 java/org.moxieapps.gwt.highcharts/.project create mode 100755 java/org.moxieapps.gwt.highcharts/.settings/org.eclipse.jdt.core.prefs create mode 100755 java/org.moxieapps.gwt.highcharts/.settings/org.eclipse.pde.core.prefs create mode 100755 java/org.moxieapps.gwt.highcharts/META-INF/MANIFEST.MF create mode 100755 java/org.moxieapps.gwt.highcharts/bin/org/moxieapps/gwt/highcharts/Highcharts.gwt.xml create mode 100755 java/org.moxieapps.gwt.highcharts/build.properties create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/Highcharts.gwt.xml create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Animation.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Axis.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/AxisTitle.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/BaseChart.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Chart.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/ChartSubtitle.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/ChartTitle.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Color.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Configurable.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Credits.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/DateTimeLabelFormats.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Exporting.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Extremes.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/LabelItem.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Lang.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Legend.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Loading.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Navigation.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/PlotBand.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/PlotLine.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Point.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/RangeSelector.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Series.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/StockChart.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Style.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/ToolTip.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/ToolTipData.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/ToolTipFormatter.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/XAxis.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/YAxis.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/ChartClickEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/ChartClickEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/ChartLoadEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/ChartLoadEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/ChartRedrawEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/ChartRedrawEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/ChartSelectionEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/ChartSelectionEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/MouseEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointClickEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointClickEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointLegendItemClickEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointLegendItemClickEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointMouseOutEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointMouseOutEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointMouseOverEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointMouseOverEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointRemoveEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointRemoveEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointSelectEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointSelectEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointUnselectEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointUnselectEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointUpdateEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/PointUpdateEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesCheckboxClickEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesCheckboxClickEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesClickEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesClickEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesHideEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesHideEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesLegendItemClickEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesLegendItemClickEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesMouseOutEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesMouseOutEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesMouseOverEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesMouseOverEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesShowEvent.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/events/SeriesShowEventHandler.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/AxisLabelsData.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/AxisLabelsFormatter.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/BaseDataLabels.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/DataLabels.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/DataLabelsData.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/DataLabelsFormatter.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/Labels.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/PieDataLabels.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/PlotBandLabel.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/PlotLineLabel.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/StackLabels.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/StackLabelsData.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/StackLabelsFormatter.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/XAxisLabels.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/labels/YAxisLabels.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/plotOptions/AreaPlotOptions.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/plotOptions/AreaSplinePlotOptions.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/plotOptions/BarPlotOptions.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/plotOptions/ColumnPlotOptions.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/plotOptions/LinePlotOptions.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/plotOptions/Marker.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/plotOptions/PiePlotOptions.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/plotOptions/PlotOptions.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/plotOptions/ScatterPlotOptions.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/plotOptions/SeriesPlotOptions.java create mode 100755 java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/plotOptions/SplinePlotOptions.java diff --git a/java/org.moxieapps.gwt.highcharts/.classpath b/java/org.moxieapps.gwt.highcharts/.classpath new file mode 100755 index 00000000000..08dfae58fc2 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/java/org.moxieapps.gwt.highcharts/.project b/java/org.moxieapps.gwt.highcharts/.project new file mode 100755 index 00000000000..e0e9ab9a092 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/.project @@ -0,0 +1,28 @@ + + + org.moxieapps.gwt.highcharts + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/java/org.moxieapps.gwt.highcharts/.settings/org.eclipse.jdt.core.prefs b/java/org.moxieapps.gwt.highcharts/.settings/org.eclipse.jdt.core.prefs new file mode 100755 index 00000000000..9736706dda3 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,82 @@ +#Tue Feb 28 12:43:14 CET 2012 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning +org.eclipse.jdt.core.compiler.problem.deadCode=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=error +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedImport=ignore +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/java/org.moxieapps.gwt.highcharts/.settings/org.eclipse.pde.core.prefs b/java/org.moxieapps.gwt.highcharts/.settings/org.eclipse.pde.core.prefs new file mode 100755 index 00000000000..f3bb3537f33 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,4 @@ +#Tue Feb 28 12:33:59 CET 2012 +eclipse.preferences.version=1 +pluginProject.extensions=false +resolve.requirebundle=false diff --git a/java/org.moxieapps.gwt.highcharts/META-INF/MANIFEST.MF b/java/org.moxieapps.gwt.highcharts/META-INF/MANIFEST.MF new file mode 100755 index 00000000000..9a461463a56 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Moxie Apps GWT Highcharts +Bundle-SymbolicName: org.moxieapps.gwt.highcharts +Bundle-Version: 1.1.4.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Export-Package: org.moxieapps.gwt.highcharts.client.plotOptions;uses:="o + rg.moxieapps.gwt.highcharts.client,com.google.gwt.json.client,org.moxie + apps.gwt.highcharts.client.events,org.moxieapps.gwt.highcharts.client.l + abels";version="1.1.3",org.moxieapps.gwt.highcharts;version="1.1.3",org + .moxieapps.gwt.highcharts.client;uses:="com.google.gwt.core.client,com. + google.gwt.dom.client,com.google.gwt.json.client,org.moxieapps.gwt.high + charts.client.plotOptions,com.google.gwt.user.client,org.moxieapps.gwt. + highcharts.client.events,org.moxieapps.gwt.highcharts.client.labels,com + .google.gwt.user.client.ui";version="1.1.3",org.moxieapps.gwt.highchart + s.client.events;uses:="com.google.gwt.core.client,com.google.gwt.dom.cl + ient,org.moxieapps.gwt.highcharts.client";version="1.1.3",org.moxieapps + .gwt.highcharts.client.labels;uses:="com.google.gwt.core.client,org.mox + ieapps.gwt.highcharts.client,com.google.gwt.json.client";version="1.1.3 + " +Import-Package: com.google.gwt.core.client,com.google.gwt.dom.client,com + .google.gwt.json.client,com.google.gwt.user.client,com.google.gwt.user. + client.ui diff --git a/java/org.moxieapps.gwt.highcharts/bin/org/moxieapps/gwt/highcharts/Highcharts.gwt.xml b/java/org.moxieapps.gwt.highcharts/bin/org/moxieapps/gwt/highcharts/Highcharts.gwt.xml new file mode 100755 index 00000000000..b1e06ff8357 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/bin/org/moxieapps/gwt/highcharts/Highcharts.gwt.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/java/org.moxieapps.gwt.highcharts/build.properties b/java/org.moxieapps.gwt.highcharts/build.properties new file mode 100755 index 00000000000..41eb6ade2b4 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/Highcharts.gwt.xml b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/Highcharts.gwt.xml new file mode 100755 index 00000000000..b1e06ff8357 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/Highcharts.gwt.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Animation.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Animation.java new file mode 100755 index 00000000000..d40242c49a6 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Animation.java @@ -0,0 +1,116 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +/** + * A configurable class that can be used to represent custom animation options, which + * can then be set as the default animation approach for the entire chart via the + * {@link Chart#setAnimation(Animation)} method, or just set for certain operations (such as + * when adding a new point to a series in {@link Series#addPoint(Number, boolean, boolean, Animation)}. + * Example usage: + *
+ *   chart.setAnimation(
+ *     new Animation()
+ *       .setDuration(100)
+ *       .setEasing(Animation.Easing.LINEAR)
+ *   );
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class Animation extends Configurable { + + /** + * An enumeration of supported animation easing types, which can be passed to methods such as + * {@link Animation#setEasing(Animation.Easing)}. Note that more easing functions are + * supported via jQuery plugins, in + * which case you'll want to use the general {@link Animation#setEasing(String)} method + * instead to set the easing to a specific string (instead of being restricted to the easing + * types included in this enumeration.) + */ + public enum Easing { + + /** + * Displays a constant pace transition. + */ + LINEAR("linear"), + + /** + * Displays the default jQuery easing transition. + */ + SWING("swing"); + + private Easing(String optionValue) { + this.optionValue = optionValue; + } + + private final String optionValue; + + public String toString() { + return optionValue; + } + + } + + /** + * Convenience method for setting the 'duration' option of the animation. Equivalent to: + *

+     *     animation.setOption("duration", 500);
+     * 
+ * + * @param duration The duration of the animation in milliseconds. + * @return A reference to this {@link Animation} instance for convenient method chaining. + */ + public Animation setDuration(Number duration) { + return this.setOption("duration", duration); + } + + /** + * Convenience method for setting the 'easing' option of the animation. Equivalent to: + *

+     *     animation.setOption("easing", "linear");
+     * 
+ * Note that more easing functions are available using + * jQuery plugins, in which case + * you'll want to use the {@link #setEasing(String)} method instead. + * + * @param easing The type of easing transition that you would like animations to use (the default is {@link Animation.Easing#SWING}); + * @return A reference to this {@link Animation} instance for convenient method chaining. + */ + public Animation setEasing(Easing easing) { + return this.setOption("easing", easing.toString()); + } + + /** + * Convenience method for setting the 'easing' option of the animation. Equivalent to: + *

+     *     animation.setOption("easing", "linear");
+     * 
+ * Note that this method is primarily intended to be used when you're using a + * jQuery plugin to support additional + * easing types. If you're just using standard jQuery easing types you'll want to use the + * {@link #setEasing(Animation.Easing)} method instead. + * + * @param easing The type of easing transition that you would like animations to use (the default is "swing"); + * @return A reference to this {@link Animation} instance for convenient method chaining. + */ + public Animation setEasing(String easing) { + return this.setOption("easing", easing); + } + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Axis.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Axis.java new file mode 100755 index 00000000000..a0e2cbccc8a --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Axis.java @@ -0,0 +1,1095 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +import com.google.gwt.core.client.JavaScriptObject; +import com.google.gwt.dom.client.Document; +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.json.client.JSONValue; + +/** + * The base class for both the X and Y axis types, which allows for general options to be set via + * the inherited {@link Configurable#setOption(String, Object)} method. But also exposes type + * specific methods that the caller is encouraged to use instead, such as + * {@link #setAllowDecimals(boolean)}, {@link #setAlternateGridColor(String)}, etc. + *

+ * Note that you won't normally work with this class directly, but instead one of it's sub-types + * such as {@link XAxis} or {@link YAxis}. + * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public abstract class Axis extends Configurable { + + /** + * An enumeration of supported axis types, which can be passed to methods such as + * {@link Axis#setType(Axis.Type)}. + */ + public enum Type { + + /** + * Default axis type showing the values in a linear structure. + */ + LINEAR("linear"), + + /** + * In a datetime axis, the numbers are given in milliseconds, and tick + * marks are placed on appropriate values like full hours or days. + */ + DATE_TIME("datetime"); + + private Type(String optionValue) { + this.optionValue = optionValue; + } + + private final String optionValue; + + public String toString() { + return optionValue; + } + + } + + /** + * An enumeration of supported tick positions, which can be passed to methods such as + * {@link Axis#setMinorTickPosition(Axis.TickPosition)} and {@link Axis#setTickPosition(Axis.TickPosition)} + */ + public enum TickPosition { + + /** + * Display the ticks inside of the axis line + */ + INSIDE("inside"), + + /** + * Display the ticks outside of the axis line + */ + OUTSIDE("outside"); + + private TickPosition(String optionValue) { + this.optionvalue = optionValue; + } + + private final String optionvalue; + + public String toString() { + return optionvalue; + } + + } + + /** + * An enumeration of supported week days, which can be passed to methods such as + * {@link Axis#setStartOfWeek(Axis.WeekDay)}. + */ + public enum WeekDay { + + SUNDAY(0), + MONDAY(1), + TUESDAY(2), + WEDNESDAY(3), + THURSDAY(4), + FRIDAY(5), + SATURDAY(6); + + private WeekDay(Number optionValue) { + this.optionvalue = optionValue; + } + + private final Number optionvalue; + + public Number toNumber() { + return optionvalue; + } + + } + + // Maintain an internal reference to the chart instance that this axis is a part of + private BaseChart chart; + + // The unique id for this axis, that we can use to access the native axis instance later if changes + // come into the axis after it is rendered + private String id; + + /** + * Use the {@link Chart#getXAxis()} or {@link Chart#getYAxis()} methods to get access + * to the axis instances on the chart. + * + * @param chart The chart instance that this axis is being created within. + */ + Axis(BaseChart chart) { + this.chart = chart; + id = Document.get().createUniqueId(); + setOption("id", id); + } + + /** + * Create a new plot line that can be configured, and then added to this axis instance via the + * {@link #setPlotLines(PlotLine...)} method. + * + * @return The plot line that was created (which will need to be added to the axis after it is configured + * via {@link #setPlotLines(PlotLine...)}. + */ + public PlotLine createPlotLine() { + return new PlotLine(this); + } + + /** + * Create a new plot band that can be configured, and then added to this axis instance via the + * {@link #setPlotBands(PlotBand...)} method. + * + * @return The plot babd that was created (which will need to be added to the axis after it is configured + * via {@link #setPlotBands(PlotBand...)}. + */ + public PlotBand createPlotBand() { + return new PlotBand(this); + } + + /** + * Convenience method for setting the 'allowDecimals' option for the axis. Equivalent to: + *


+     *     axis.setOption("allowDecimals", false);
+     * 
+ * Whether to allow decimals in this axis' ticks. When counting integers, like persons or + * hits on a web page, decimals must be avoided in the axis tick labels. Defaults to true. + * + * @param allowDecimals Whether to allow decimals in this axis' ticks. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setAllowDecimals(boolean allowDecimals) { + return this.setOption("allowDecimals", allowDecimals); + } + + /** + * Convenience method for setting the 'alternateGridColor' option for the axis. Equivalent to: + *

+     *     axis.setOption("alternateGridColor", "#CC0000");
+     * 
+ * When using an alternate grid color, a band is painted across the plot area between every + * other grid line. Defaults to null. + * + * @param alternateGridColor The color to use as the alternate grid color. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setAlternateGridColor(String alternateGridColor) { + return this.setOption("alternateGridColor", alternateGridColor); + } + + /** + * Convenience method for setting the 'dateTimeLabelFormats' options of the axis. Equivalent to code like: + *

+     *     axis.setOption("/dateTimeLabelFormats/second", "%H:%M:%S");
+     *     axis.setOption("/dateTimeLabelFormats/minute", "%H:%M");
+     * 
+ * For a datetime axis, the scale will automatically adjust to the appropriate unit. This configuration + * option sets the default string format representations used for each unit. For an overview of the + * replacement codes available see the javadoc on the {@link DateTimeLabelFormats} class. Defaults to: + * + * Example usage: + *
+     *   axis.setDateTimeLabelFormats(
+     *     new DateTimeLabelFormats()
+     *       .setHour("%I %p")
+     *       .setMinute("%I:%M %p")
+     *   );
+     * 
+ * + * @param dateTimeLabelFormats The formats to use for time series information on this axis. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setDateTimeLabelFormats(DateTimeLabelFormats dateTimeLabelFormats) { + return this.setOption("dateTimeLabelFormats", dateTimeLabelFormats != null ? dateTimeLabelFormats.getOptions() : null); + } + + /** + * Convenience method for setting the 'endOnTick' option for the axis. Equivalent to: + *

+     *     axis.setOption("endOnTick", true);
+     * 
+ * Whether to force the axis to end on a tick. Use this option with the maxPadding option to + * control the axis end. Defaults to false. + * + * @param endOnTick Whether to force the axis to end on a tick. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setEndOnTick(boolean endOnTick) { + return this.setOption("endOnTick", endOnTick); + } + + // TODO: Add support for events + + /** + * Set the minimum and maximum of the axes after render time using the default animation options. + * If the startOnTick and endOnTick options are true, the minimum and maximum values are rounded + * off to the nearest tick. To prevent this, these options can be set to false before calling this method. + *

+ * Also note that this method will use the default chart animation options when changing the extremes. + * To control the animation more specifically use the {@link #setExtremes(Number, Number, boolean, boolean)} + * or {@link #setExtremes(Number, Number, boolean, Animation)} method instead. + * + * @param min The new minimum value. + * @param max The new maximum value. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setExtremes(Number min, Number max) { + return this.setExtremes(min, max, true, true); + } + + /** + * Set the minimum and maximum of the axes after render time, controlling the redraw and animation + * status. If the startOnTick and endOnTick options are true, the minimum and maximum values are + * rounded off to the nearest tick. To prevent this, these options can be set to false before calling this method. + *

+ * The gain more control over the animation used when the extremes are changed, use the + * {@link #setExtremes(Number, Number, boolean, Animation)} method instead. + * + * @param min The new minimum value. + * @param max The new maximum value. + * @param redraw 'true' to force the chart to redraw immediately, or 'false' to wait until the + * {@link Chart#redraw()} method is invoked. + * @param animation When 'true', the chart updating will be animated with default animation options. + * Note, use the {@link #setExtremes(Number, Number, boolean, Animation)} method + * for more control over the animation options. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setExtremes(Number min, Number max, boolean redraw, boolean animation) { + return setExtremes(min, max, redraw, animation ? new Animation() : null); + } + + /** + * Set the minimum and maximum of the axes after render time, controlling the redraw and animation + * options. If the startOnTick and endOnTick options are true, the minimum and maximum values are + * rounded off to the nearest tick. To prevent this, these options can be set to false before calling this method. + *

+ * This method is intended to be used for callers that need tight control over the animation that + * will run when the chart extremes are applied. If you don't need tight control over the animation + * you can use the {@link #setExtremes(Number, Number)} or {@link #setExtremes(Number, Number, boolean, boolean)} + * method instead. + * + * @param min The new minimum value. + * @param max The new maximum value. + * @param redraw 'true' to force the chart to redraw immediately, or 'false' to wait until the + * {@link Chart#redraw()} method is invoked. + * @param animation Custom animation to use when the chart extremes are being updated. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setExtremes(Number min, Number max, boolean redraw, Animation animation) { + if (chart.isRendered()) { + // We'll update the axis live in the DOM if we've already been rendered + final JavaScriptObject nativeAxis = getNativeAxis(); + if (nativeAxis != null) { + if (animation == null || animation.getOptions() == null) { + final boolean animationFlag = animation != null; + nativeSetExtremes(nativeAxis, min, max, redraw, animationFlag); + } else { + final JavaScriptObject animationOptions = animation.getOptions().getJavaScriptObject(); + nativeSetExtremes(nativeAxis, min, max, redraw, animationOptions); + } + } + } else { + // If we're called before the chart has been rendered, then just track the min/max as a configuration option + this.setMin(min).setMax(max); + } + return getThis(); + } + + /** + * Return a non-null object that represents the current extremes for the axis. Note that if this method + * is invoked before the chart has been rendered, only the configured min/max values will be known. + * + * @return The current extremes for the axis. + */ + public Extremes getExtremes() { + + Extremes extremes = null; + + if (chart.isRendered()) { + // If we've already been rendered, we can ask the running chart for it's actual extremes + final JavaScriptObject nativeAxis = getNativeAxis(); + if (nativeAxis != null) { + final JavaScriptObject nativeExtremes = nativeGetExtremes(nativeAxis); + if (nativeExtremes != null) { + JSONObject jsonExtremes = new JSONObject(nativeExtremes); + extremes = new Extremes( + getNumberFromJSONObject(jsonExtremes, "dataMin"), + getNumberFromJSONObject(jsonExtremes, "dataMax"), + getNumberFromJSONObject(jsonExtremes, "min"), + getNumberFromJSONObject(jsonExtremes, "max") + ); + } + } + } + + // If we haven't been rendered (or for some reason we can't get to the native object), then + // all we know if whatever configuration options were set manually + if (extremes == null) { + extremes = new Extremes(null, null, this.min, this.max); + } + return extremes; + } + + protected JavaScriptObject getNativeAxis() { + return chart.get(this.id); + } + + // Save some typing in the getExtremes() method + private Number getNumberFromJSONObject(JSONObject jsonObject, String key) { + JSONValue jsonValue = jsonObject.get(key); + if (jsonValue.isNumber() != null) { + return jsonValue.isNumber().doubleValue(); + } + return null; + } + + /** + * Convenience method for setting the 'gridLineColor' option for the axis. Equivalent to: + *


+     *     axis.setOption("gridLineColor", "#CCCCCC");
+     * 
+ * Color of the grid lines extending the ticks across the plot area. Defaults to "#C0C0C0". + * + * @param gridLineColor Color of the grid lines extending the ticks across the plot area. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setGridLineColor(String gridLineColor) { + return this.setOption("gridLineColor", gridLineColor); + } + + /** + * Convenience method for setting the 'gridLineDashStyle' axis option. Equivalent to: + *

+     *     plotOptions.setOption("gridLineDashStyle", PlotOptions.DashStyle.LONG_DASH);
+     * 
+ * The dash or dot style of the grid lines. Defaults to DashStyle.DOT. See this + * demonstration for a visible reference + * of the available dash styles. + * + * @param gridLineDashStyle Sets the dash or dot style of the grid lines, or null to return to the default. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setGridLineDashStyle(PlotLine.DashStyle gridLineDashStyle) { + return this.setOption("gridLineDashStyle", gridLineDashStyle != null ? gridLineDashStyle.toString() : null); + } + + /** + * Convenience method for setting the 'gridLineWidth' option for the axis. Equivalent to: + *

+     *     axis.setOption("gridLineWidth", 2);
+     * 
+ * The width of the grid lines extending the ticks across the plot area. Defaults to 0. + * + * @param gridLineWidth The new width of the grid lines extending the ticks across the plot area. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setGridLineWidth(Number gridLineWidth) { + return this.setOption("gridLineWidth", gridLineWidth); + } + + /** + * Convenience method for setting the 'lineColor' option for the axis. Equivalent to: + *

+     *     axis.setOption("lineColor", "#00CC00");
+     * 
+ * The color of the line marking the axis itself. Defaults to "#C0D0E0". + * + * @param lineColor The new color of the line marking the axis itself. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setLineColor(String lineColor) { + return this.setOption("lineColor", lineColor); + } + + /** + * Convenience method for setting the 'lineWidth' option for the axis. Equivalent to: + *

+     *     axis.setOption("lineWidth", 2);
+     * 
+ * The width of the line marking the axis itself. Defaults to 1. + * + * @param lineWidth The new width of the line marking the axis itself. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setLineWidth(Number lineWidth) { + return this.setOption("lineWidth", lineWidth); + } + + /** + * Convenience method for setting the 'linkedTo' option for the axis. Equivalent to: + *

+     *     axis.setOption("linkedTo", 2);
+     * 
+ * Index of another axis that this axis is linked to. When an axis is linked to a master + * axis, it will take the same extremes as the master, but as assigned by + * {@link #setMin(Number)} or {@link #setMax(Number)} or + * by {@link #setExtremes(Number, Number)}. It can be used to show additional info, or + * to ease reading the chart by duplicating the scales. Defaults to null. + * + * @param linkedTo The index of another axis that this axis is linked to. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setLinkedTo(Number linkedTo) { + return this.setOption("linkedTo", linkedTo); + } + + private Number max; + + /** + * Convenience method for setting the 'max' option for the axis. Equivalent to: + *

+     *     axis.setOption("max", 100);
+     * 
+ * The maximum value of the axis. If null, the max value is automatically calculated. If + * the {@link #setEndOnTick(boolean)} option is true, the max value might be rounded up. + * The actual maximum value is also influenced by {@link Chart#setAlignTicks(boolean)} + * setting. Defaults to null. + *

+ * Note that this method will only affect the maximum value of the chart before it is rendered. + * To change the min/max value of the chart after render time use the {@link #setExtremes(Number, Number)} + * method instead. + * + * @param max The maximum value of the axis, or null to automatically calculate the maximum. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setMax(Number max) { + this.max = max; + return this.setOption("max", max); + } + + /** + * Convenience method for setting the 'maxPadding' option for the axis. Equivalent to: + *


+     *     axis.setOption("maxPadding", 0.05);
+     * 
+ * Padding of the max value relative to the length of the axis. A padding of 0.05 will make a + * 100px axis 5px longer. This is useful when you don't want the highest data value to appear + * on the edge of the plot area. When the axis' max option is set or a max extreme is set + * using {@link #setExtremes(Number, Number)}, the maxPadding will be ignored. Defaults to 0.01. + * + * @param maxPadding The new padding of the max value relative to the length of the axis. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setMaxPadding(Number maxPadding) { + return this.setOption("maxPadding", maxPadding); + } + + /** + * Convenience method for setting the 'maxZoom' option for the axis. Equivalent to: + *

+     *     axis.setOption("maxZoom", 5);
+     * 
+ * The maximum amount of zoom on this axis. The entire axis will not be allowed to span over + * a smaller interval than this. For example, for a datetime axis the main unit is milliseconds. + * If maxZoom is set to 3600000, you can't zoom in more than to one hour. + * + * @param maxZoom The new maximum amount of zoom on this axis. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setMaxZoom(Number maxZoom) { + return this.setOption("maxZoom", maxZoom); + } + + private Number min; + + /** + * Convenience method for setting the 'max' option for the axis. Equivalent to: + *

+     *     axis.setOption("min", 10);
+     * 
+ * The minimum value of the axis. If null, the min value is automatically calculated. If + * the {@link #setStartOnTick(boolean)} option is true, the min value might be rounded down. + * Defaults to null. + *

+ * Note that this method will only affect the minimum value of the chart before it is rendered. + * To change the min/max value of the chart after render time use the {@link #setExtremes(Number, Number)} + * method instead. + * + * @param min The maximum value of the axis, or null to automatically calculate the maximum. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setMin(Number min) { + this.min = min; + return this.setOption("min", min); + } + + /** + * Convenience method for setting the 'minorGridLineColor' option for the axis. Equivalent to: + *


+     *     axis.setOption("minorGridLineColor", "#00CC00");
+     * 
+ * Color of the minor, secondary grid lines. Defaults to #E0E0E0. + * + * @param minorGridLineColor The new color of the minor, secondary grid lines. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setMinorGridLineColor(String minorGridLineColor) { + return this.setOption("minorGridLineColor", minorGridLineColor); + } + + /** + * Convenience method for setting the 'minorGridLineDashStyle' axis option. Equivalent to: + *

+     *     plotOptions.setOption("minorGridLineDashStyle", PlotOptions.DashStyle.LONG_DASH);
+     * 
+ * The dash or dot style of the grid lines. Defaults to DashStyle.SOLID. See this + * demonstration for a visible reference + * of the available dash styles. + * + * @param minorGridLineDashStyle Sets the dash or dot style of the minor grid lines, or null to return to the default. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setMinorGridLineDashStyle(PlotLine.DashStyle minorGridLineDashStyle) { + return this.setOption("minorGridLineDashStyle", minorGridLineDashStyle != null ? minorGridLineDashStyle.toString() : null); + } + + /** + * Convenience method for setting the 'minorGridLineWidth' option for the axis. Equivalent to: + *

+     *     axis.setOption("minorGridLineWidth", 2);
+     * 
+ * The width of the minor, secondary grid lines. Defaults to 1. + * + * @param minorGridLineWidth The new width of the minor, secondary grid lines. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setMinorGridLineWidth(Number minorGridLineWidth) { + return this.setOption("minorGridLineWidth", minorGridLineWidth); + } + + /** + * Convenience method for setting the 'minorTickColor' option for the axis. Equivalent to: + *

+     *     axis.setOption("minorTickColor", "#00CC00");
+     * 
+ * Color for the minor tick marks. Defaults to #A0A0A0. + * + * @param minorTickColor The new color for the minor tick marks. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setMinorTickColor(String minorTickColor) { + return this.setOption("minorTickColor", minorTickColor); + } + + /** + * Convenience method for setting the 'minorTickInterval' option for the axis. Equivalent to: + *

+     *     axis.setOption("minorTickInterval", 2);
+     * 
+ * Tick interval in scale units for the minor ticks. If null, minor ticks are not shown. Defaults to null. + * Note that if you instead call the {@link #setMinorTickIntervalAuto()} method + * the minor tick interval is calculated as a fifth of the tickInterval. + * + * @param minorTickInterval The new tick interval in scale units for the minor ticks. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setMinorTickInterval(Number minorTickInterval) { + return this.setOption("minorTickInterval", minorTickInterval); + } + + /** + * Convenience method for setting the 'minorTickInterval' option for the axis to auto. Equivalent to: + *

+     *     axis.setOption("minorTickInterval", "auto");
+     * 
+ * Note, if you instead want to set the tick interval to a specific numeric value (or disable the + * ticks completely), you'll want to use the {@link #setMinorTickInterval(Number)} method. + * + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setMinorTickIntervalAuto() { + return this.setOption("minorTickInterval", "auto"); + } + + /** + * Convenience method for setting the 'minorTickLength' option for the axis. Equivalent to: + *

+     *     axis.setOption("minorTickLength", 4);
+     * 
+ * The pixel length of the minor tick marks. Defaults to 2. + * + * @param minorTickLength The new pixel length of the minor tick marks. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setMinorTickLength(Number minorTickLength) { + return this.setOption("minorTickLength", minorTickLength); + } + + /** + * Convenience method for setting the 'minorTickPosition' option for the axis. Equivalent to: + *

+     *     axis.setOption("minorTickPosition", TickPosition.INSIDE);
+     * 
+ * The position of the minor tick marks relative to the axis line. Defaults to {@link Axis.TickPosition#OUTSIDE}. + * + * @param minorTickPosition The new position of the minor tick marks relative to the axis line, + * or null to return to the default. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setMinorTickPosition(TickPosition minorTickPosition) { + return this.setOption("minorTickPosition", minorTickPosition != null ? minorTickPosition.toString() : null); + } + + /** + * Convenience method for setting the 'minorTickWidth' option for the axis. Equivalent to: + *

+     *     axis.setOption("minorTickWidth", 4);
+     * 
+ * The pixel width of the minor tick mark. Defaults to 0. + * + * @param minorTickWidth The new pixel width of the minor tick mark. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setMinorTickWidth(Number minorTickWidth) { + return this.setOption("minorTickWidth", minorTickWidth); + } + + /** + * Convenience method for setting the 'minPadding' option for the axis. Equivalent to: + *

+     *     axis.setOption("minPadding", 0.05);
+     * 
+ * Padding of the min value relative to the length of the axis. A padding of 0.05 will make a + * 100px axis 5px longer. This is useful when you don't want the highest data value to appear + * on the edge of the plot area. When the axis' min option is set or a max extreme is set + * using {@link #setExtremes(Number, Number)}, the minPadding will be ignored. Defaults to 0.01. + * + * @param minPadding The new padding of the min value relative to the length of the axis. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setMinPadding(Number minPadding) { + return this.setOption("minPadding", minPadding); + } + + /** + * Convenience method for setting the 'offset' option for the axis. Equivalent to: + *

+     *     axis.setOption("offset", 60);
+     * 
+ * The distance in pixels from the plot area to the axis line. A positive offset moves + * the axis with it's line, labels and ticks away from the plot area. This is typically + * used when two or more axes are displayed on the same side of the plot. Defaults to 0. + * + * @param offset The new distance in pixels from the plot area to the axis line. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setOffset(Number offset) { + return this.setOption("offset", offset); + } + + /** + * Convenience method for setting the 'opposite' option for the axis. Equivalent to: + *

+     *     axis.setOption("opposite", true);
+     * 
+ * Whether to display the axis on the opposite side of the normal. The normal is on the + * left side for vertical axes and bottom for horizontal, so the opposite sides will be + * right and top respectively. This is typically used with dual or multiple axes. Defaults to false. + * + * @param opposite 'true' to display the axis on the opposite side of the normal, 'false' + * to show the axis on the normal side. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setOpposite(boolean opposite) { + return this.setOption("opposite", opposite); + } + + /** + * Sets the 'plotLines' array for the axis. A plot line is a line stretching across the plot area, + * marking a specific value on one of the axes. Example usage: + *
+     *   XAxis xAxis = chart.getXAxis()
+     *   xAxis.getXAxis()
+     *     .setPlotLines(
+     *       xAxis.createPlotLine()
+     *          .setColor("#CC0000")
+     *          .setValue(40),
+     *       xAxis.createPlotLine()
+     *          .setColor("#009900")
+     *          .setValue(60)
+     *     )
+     *   );
+     * 
+ * + * @param plotLines One or more PlotLine instances that represent the options of each line to render + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setPlotLines(PlotLine... plotLines) { + return this.setOption("plotLines", plotLines); + } + + /** + * Sets the 'plotBands' array for the axis. A plot band is a colored band stretching across the plot + * area marking an interval on the axis. Example usage: + *
+     *   XAxis xAxis = chart.getXAxis()
+     *     .setPlotBands(
+     *       xAxis.createPlotBand()
+     *          .setColor("#CC0000")
+     *          .setFrom(40)
+     *          .setTo(80),
+     *       xAxis.createPlotBand()
+     *          .setColor("#009900")
+     *          .setFrom(90)
+     *          .setTo(120),
+     *     )
+     *   );
+     * 
+ * + * @param plotBands One or more PlotBand instances that represent the options of each band to render + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setPlotBands(PlotBand... plotBands) { + return this.setOption("plotBands", plotBands); + } + + /** + * Convenience method for setting the 'reversed' option for the axis. Equivalent to: + *

+     *     axis.setOption("reversed", true);
+     * 
+ * Whether to reverse the axis so that the highest number is closest to origin. If the chart + * is inverted, the x axis is reversed by default. Defaults to false. + * + * @param reversed 'true' to reverse the axis so that the highest number is closest to origin, 'false' + * to show the axis in its default orientation. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setReversed(boolean reversed) { + return this.setOption("reversed", reversed); + } + + /** + * Convenience method for setting the 'showFirstLabel' option for the axis. Equivalent to: + *

+     *     axis.setOption("showFirstLabel", false);
+     * 
+ * Whether to show the first tick label. Defaults to true. + * + * @param showFirstLabel 'true' to show the first tick label (the default), 'false' to hide it. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setShowFirstLabel(boolean showFirstLabel) { + return this.setOption("showFirstLabel", showFirstLabel); + } + + /** + * Convenience method for setting the 'showLastLabel' option for the axis. Equivalent to: + *

+     *     axis.setOption("showLastLabel", true);
+     * 
+ * Whether to show the last tick label. Defaults to false. + * + * @param showLastLabel 'true' to show the first tick label, 'false' to hide it (the default). + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setShowLastLabel(boolean showLastLabel) { + return this.setOption("showLastLabel", showLastLabel); + } + + /** + * Convenience method for setting the 'startOfWeek' option for the axis. Equivalent to: + *

+     *     axis.setOption("startOfWeek", WeekDay.SUNDAY);
+     * 
+ * For datetime axes, this decides where to put the tick between weeks. Defaults to 1 {@link Axis.WeekDay#MONDAY}. + * + * @param startOfWeek The day of the week where tick marks should be placed between weeks. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setStartOfWeek(WeekDay startOfWeek) { + return this.setOption("startOfWeek", startOfWeek != null ? startOfWeek.toNumber() : null); + } + + /** + * Convenience method for setting the 'startOnTick' option for the axis. Equivalent to: + *

+     *     axis.setOption("startOnTick", true);
+     * 
+ * Whether to force the axis to start on a tick. Use this option with the + * {@link #setMaxPadding(Number)} option to control the axis start. Defaults to false. + * + * @param startOnTick 'true' to force the axis to start on a tick, 'false' for the default behavior. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setStartOnTick(boolean startOnTick) { + return this.setOption("startOnTick", startOnTick); + } + + /** + * Convenience method for setting the 'tickColor' option for the axis. Equivalent to: + *

+     *     axis.setOption("tickColor", "#00CC00");
+     * 
+ * Color for the main tick marks. Defaults to #C0D0E0. + * + * @param tickColor The new color for the main tick marks. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setTickColor(String tickColor) { + return this.setOption("tickColor", tickColor); + } + + /** + * Convenience method for setting the 'tickInterval' option for the axis. Equivalent to: + *

+     *     axis.setOption("tickInterval", 5);
+     * 
+ * The interval of the tick marks in axis units. When null, the tick interval is computed to + * approximately follow the tickPixelInterval on linear and datetime axes. On categorized axes, a + * null tickInterval will default to 1, one category. Note that datetime axes are based on milliseconds, + * so for example an interval of one day is expressed as 24 * 3600 * 1000. Defaults to null. + * + * @param tickInterval The interval of the tick marks in axis units, or null to follow the default interval logic. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setTickInterval(Number tickInterval) { + return this.setOption("tickInterval", tickInterval); + } + + /** + * Convenience method for setting the 'tickLength' option for the axis. Equivalent to: + *

+     *     axis.setOption("tickLength", 20);
+     * 
+ * The pixel length of the main tick marks. Defaults to 5. + * + * @param tickLength The new pixel length of the main tick marks. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setTickLength(Number tickLength) { + return this.setOption("tickLength", tickLength); + } + + /** + * Convenience method for setting the 'tickPixelInterval' option for the axis. Equivalent to: + *

+     *     axis.setOption("tickPixelInterval", 50);
+     * 
+ * If tickInterval is null (the default) this option sets the approximate pixel interval of the tick marks. + * Not applicable to categorized axis. Defaults to 72 for the Y axis and 100 for the X axis. + * + * @param tickPixelInterval The new approximate pixel interval of the tick marks. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setTickPixelInterval(Number tickPixelInterval) { + return this.setOption("tickPixelInterval", tickPixelInterval); + } + + /** + * Convenience method for setting the 'tickPosition' option for the axis. Equivalent to: + *

+     *     axis.setOption("tickPosition", TickPosition.INSIDE);
+     * 
+ * The position of the major tick marks relative to the axis line. Defaults to {@link Axis.TickPosition#OUTSIDE}. + * + * @param tickPosition The new position of the major tick marks relative to the axis line. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setTickPosition(TickPosition tickPosition) { + return this.setOption("tickPosition", tickPosition != null ? tickPosition.toString() : null); + } + + /** + * Convenience method for setting the 'tickWidth' option for the axis. Equivalent to: + *

+     *     axis.setOption("tickWidth", 10);
+     * 
+ * The pixel width of the major tick marks. Defaults to 1. + * + * @param tickWidth The new pixel width of the major tick marks. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setTickWidth(Number tickWidth) { + return this.setOption("tickWidth", tickWidth); + } + + /** + * Convenience method for setting the 'title/text' axis option. Equivalent to: + *

+     *     axis.setOption("/title/text", "A Fine Axis Indeed");
+     * 
+ * The actual text of the axis title. It can contain basic HTML text markup like + * <b>, <i> and spans with style. Defaults to null for the x-axis + * and "Y-values" for the y-axis. + *

+ * Note that for more control over the title, utilize the {@link #setAxisTitle(AxisTitle)} + * method instead. + *

+ * Also note that to hide an axis title completely, simply set the text to null. + * + * @param title Sets the title of axis, or null to hide the title. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setAxisTitleText(String title) { + return this.setOption("/title/text", title); + } + + /** + * Convenience method for setting the 'title/text' axis option. Equivalent to: + *


+     *     axis.setOption("/title/text", "A Fine Axis Indeed");
+     *     axis.setOption("/title/align", AxisTitle.Align.HIGH);
+     * 
+ *

+ * Note that if you call this method it will overwrite any existing + * settings that have already been applied to the title (e.g. if you + * had previously called the {@link #setAxisTitleText(String)} method that change + * will get overwritten by this call.) + *

+ * Note that if you only want to change the text of the axis, you can simply + * use the {@link #setAxisTitleText(String)} method instead. + * + * @param title Sets the axis title options, or null to hide the title. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setAxisTitle(AxisTitle title) { + return this.setOption("/title", title != null ? title.getOptions() : null); + } + + /** + * Convenience method for setting the 'type' axis option. Equivalent to: + *


+     *     axis.setOption("type", Axis.Type.DATE_TIME);
+     * 
+ * The type of axis. Can be one of "linear" or "datetime". In a datetime axis, the numbers are + * given in milliseconds, and tick marks are placed on appropriate values like full hours or days. + * Defaults to {@link Axis.Type#LINEAR}. + * + * @param type Sets the type of axis. + * @return A reference to this {@link Axis} instance for convenient method chaining. + */ + public T setType(Type type) { + return this.setOption("type", type != null ? type.toString() : null); + } + + /** + * Allows plot lines to be added to an axis after the chart is rendered. If you want to add + * plot lines to chart before it is rendered, please utilize the {@link #setPlotLines(PlotLine...)} + * method instead. + * + * @param plotLines One or more PlotLine instances that represent the options of each line to render + * @return A reference to this {@link Axis} instance for convenient method chaining. + * @since 1.1.3 + */ + public T addPlotLines(PlotLine... plotLines) { + if (getNativeAxis() != null) { + for (PlotLine plotLine : plotLines) { + nativeAddPlotLine(getNativeAxis(), plotLine.getOptions().getJavaScriptObject()); + } + } else { + setPlotLines(plotLines); + } + return getThis(); + } + + /** + * Allows plot bands to be added to an axis after the chart is rendered. If you want to add + * plot bands to chart before it is rendered, please utilize the {@link #setPlotBands(PlotBand...)} + * method instead. + * + * @param plotBands One or more PlotBand instances that represent the options of each band to render + * @return A reference to this {@link Axis} instance for convenient method chaining. + * @since 1.1.3 + */ + public T addPlotBands(PlotBand... plotBands) { + if (getNativeAxis() != null) { + for (PlotBand plotBand : plotBands) { + nativeAddPlotBand(getNativeAxis(), plotBand.getOptions().getJavaScriptObject()); + } + } else { + setPlotBands(plotBands); + } + return getThis(); + } + + /** + * Remove the given plot line from the chart after it has been rendered, automatically + * redrawing the chart after the plot line has been removed. + * + * @param plotLine The PlotLine instance to remove from the chart. + * @return A reference to this {@link Axis} instance for convenient method chaining. + * @since 1.1.3 + */ + public T removePlotLine(PlotLine plotLine) { + if (getNativeAxis() != null) { + nativeRemovePlotLine(getNativeAxis(), plotLine.getId()); + } else { + // TODO: Add support for removing a plot line for the set before the chart is rendered + } + return getThis(); + } + + /** + * Remove the given plot band from the chart after it has been rendered, automatically + * redrawing the chart after the plot band has been removed. + * + * @param plotBand The PlotBand instance to remove from the chart. + * @return A reference to this {@link Axis} instance for convenient method chaining. + * @since 1.1.3 + */ + public T removePlotBand(PlotBand plotBand) { + if (getNativeAxis() != null) { + nativeRemovePlotBand(getNativeAxis(), plotBand.getId()); + } else { + // TODO: Add support for removing a plot band for the set before the chart is rendered + } + return getThis(); + } + + + // Handle the unchecked cast limitation with generics in one place + private T getThis() { + @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"}) + final T instance = (T) this; + return instance; + } + + private static native void nativeSetExtremes(JavaScriptObject axis, Number min, Number max, boolean redraw, boolean animation) /*-{ + axis.setExtremes(min, max, redraw, animation); + }-*/; + + private static native void nativeSetExtremes(JavaScriptObject axis, Number min, Number max, boolean redraw, JavaScriptObject animationOptions) /*-{ + axis.setExtremes(min, max, redraw, animationOptions); + }-*/; + + private static native JavaScriptObject nativeGetExtremes(JavaScriptObject axis) /*-{ + return axis.getExtremes(); + }-*/; + + private native void nativeAddPlotLine(JavaScriptObject axis, JavaScriptObject plotLineOptions)/*-{ + axis.addPlotLine(plotLineOptions); + }-*/; + + private native void nativeAddPlotBand(JavaScriptObject axis, JavaScriptObject plotBandOptions)/*-{ + axis.addPlotBand(plotBandOptions); + }-*/; + + private native void nativeRemovePlotLine(JavaScriptObject axis, String id)/*-{ + axis.removePlotLine(id); + }-*/; + + private native void nativeRemovePlotBand(JavaScriptObject axis, String id)/*-{ + axis.removePlotBand(id); + }-*/; +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/AxisTitle.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/AxisTitle.java new file mode 100755 index 00000000000..5174a67791f --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/AxisTitle.java @@ -0,0 +1,155 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +/** + * A configurable class that can be used to represent custom title options for an + * axis, which can then be set on a specific axis (via the {@link Axis#setAxisTitle(AxisTitle)} method.) + * Example usage: + *
+ *   chart.getXAxis().setAxisTitle(
+ *     new AxisTitle()
+ *       .setText("Sales by Month")
+ *       .setAlign(AxisTitle.Align.MIDDLE)
+ *   );
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class AxisTitle extends Configurable { + + /** + * An enumeration of supported axis title alignment types, which can be passed to methods + * like {@link AxisTitle#setAlign(AxisTitle.Align)} method. + */ + public enum Align { + + /** + * Align the title to the bottom (for a y-axis) or to the left (for an x-axis) + */ + LOW("low"), + + /** + * Align the title to the middle (for a y-axis) or to the center (for an x-axis) + */ + MIDDLE("middle"), + + /** + * Align the title to the top (for a y-axis) or to the right (for an x-axis) + */ + HIGH("high"); + + private Align(String optionValue) { + this.optionValue = optionValue; + } + + private final String optionValue; + + public String toString() { + return optionValue; + } + + } + + /** + * Convenience method for setting the 'align' option of the title. Equivalent to: + *

+     *     axisTitle.setOption("align", AxisTitle.Align.LOW);
+     * 
+ * Alignment of the title relative to the axis values. Possible values are "low", "middle" or "high". + * Defaults to {@link AxisTitle.Align#MIDDLE}. + * + * @param align The alignment of the title relative to the axis values. + * @return A reference to this {@link AxisTitle} instance for convenient method chaining. + */ + public AxisTitle setAlign(Align align) { + return this.setOption("align", align != null ? align.toString() : null); + } + + /** + * Convenience method for setting the 'margin' option of the title. Equivalent to: + *

+     *     axisTitle.setOption("margin", 60);
+     * 
+ * The pixel distance between the axis labels or line and the title. Defaults + * to 0 for horizontal axis, 10 for vertical axis. + * + * @param margin The pixel distance between the axis labels or line and the title. + * @return A reference to this {@link AxisTitle} instance for convenient method chaining. + */ + public AxisTitle setMargin(Number margin) { + return this.setOption("margin", margin); + } + + /** + * Convenience method for setting the 'margin' option of the title. Equivalent to: + *

+     *     axisTitle.setOption("margin", 60);
+     * 
+ * The rotation of the text in degrees. 0 is horizontal, 270 is vertical reading + * from bottom to top. Defaults to 0. + * + * @param rotation The rotation of the text in degrees. + * @return A reference to this {@link AxisTitle} instance for convenient method chaining. + */ + public AxisTitle setRotation(Number rotation) { + return this.setOption("rotation", rotation); + } + + /** + * Convenience method for setting the 'style' options of the axis title. Equivalent to: + *

+     *     axisTitle.setOption("/style/fontWeight", "bold");
+     *     axisTitle.setOption("/style/fontFamily", "serif");
+     *     etc.
+     * 
+ * CSS styles for the title. When titles are rotated they are rendered using vector graphic techniques + * and not all styles are applicable. Most noteworthy, a bug in IE8 renders all rotated strings bold + * and italic. Defaults to: + *
    + *
  • color: '#6D869F'
  • + *
  • fontWeight: 'bold'
  • + *
+ * + * @param style CSS styles for the axis title. + * @return A reference to this {@link AxisTitle} instance for convenient method chaining. + */ + public AxisTitle setStyle(Style style) { + return this.setOption("style", style != null ? style.getOptions() : null); + } + + /** + * Convenience method for setting the 'text' option of the title. Equivalent to: + *

+     *     axisTitle.setOption("text", "Sales by Month");
+     * 
+ * The actual text of the axis title. It can contain basic HTML text markup + * like <b>, <i> and spans with style. Defaults to null. + *

+ * Note to disable an axis title from being displayed completely, simply set the text + * to "null". (This can also be accomplished more simply by just setting the title + * text to null directly on the axis via the {@link Axis#setAxisTitleText(String)} method.) + * + * @param text The actual text of the axis title. + * @return A reference to this {@link AxisTitle} instance for convenient method chaining. + */ + public AxisTitle setText(String text) { + return this.setOption("text", text); + } + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/BaseChart.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/BaseChart.java new file mode 100755 index 00000000000..576ddd7ad34 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/BaseChart.java @@ -0,0 +1,2356 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +import com.google.gwt.core.client.JavaScriptObject; +import com.google.gwt.core.client.JsArray; +import com.google.gwt.core.client.JsArrayString; +import com.google.gwt.dom.client.DivElement; +import com.google.gwt.dom.client.Document; +import com.google.gwt.json.client.*; +import com.google.gwt.user.client.ui.Widget; +import org.moxieapps.gwt.highcharts.client.events.*; +import org.moxieapps.gwt.highcharts.client.labels.AxisLabelsData; +import org.moxieapps.gwt.highcharts.client.labels.DataLabelsData; +import org.moxieapps.gwt.highcharts.client.labels.StackLabelsData; +import org.moxieapps.gwt.highcharts.client.plotOptions.*; + +import java.util.ArrayList; +import java.util.Iterator; + +/** + * The common base class for both {@link Chart} types as well as {@link StockChart} types. + * You should not use this class directly, but instead create an instance of one of those + * sub types. + * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @see Chart + * @see StockChart + * @since 1.0.0 + */ +public abstract class BaseChart extends Widget { + + /** + * This class can not be created directly, but instead create an instance of one of the + * sub types such as {@link Chart} or {@link StockChart}. + */ + protected BaseChart() { + final DivElement divElement = Document.get().createDivElement(); + divElement.getStyle().setOverflow(com.google.gwt.dom.client.Style.Overflow.HIDDEN); + divElement.setId(Document.get().createUniqueId()); + this.setElement(divElement); + } + + /** + * Convenience method for setting the 'alignTicks' option of the chart. Equivalent to: + *


+     *     chart.setOption("/chart/alignTicks", false);
+     * 
+ * When using multiple axis, the ticks of two or more opposite axes will automatically be aligned + * by adding ticks to the axis or axes with the least ticks. This can be prevented by setting + * alignTicks to false. If the grid lines look messy, it's a good idea to hide them for the + * secondary axis by setting gridLineWidth to 0. Defaults to true. + * + * @param alignTicks The value to set as the 'alignTicks' option on the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setAlignTicks(boolean alignTicks) { + return this.setOption("/chart/alignTicks", alignTicks); + } + + /** + * Convenience method for setting the 'animation' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/animation", true);
+     * 
+ * Sets the overall animation for all chart updating. Animation can be disabled throughout + * the chart by setting it to false here. It can be overridden for each individual API + * method as a function parameter. The only animation not affected by this option is the + * initial series animation, see {@link org.moxieapps.gwt.highcharts.client.plotOptions.PlotOptions#setAnimation(boolean)} method for + * control over series animations that are added after the chart has been rendered. + *

+ * Note that more control over the animations is available by calling the + * {@link #setAnimation(Animation)} method instead. + *

+ * + * @param animation The value to set as the 'animation' option on the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setAnimation(boolean animation) { + return this.setOption("/chart/animation", animation); + } + + /** + * Convenience method for setting the 'animation' options of the chart. Equivalent to code like: + *


+     *     chart.setOption("/chart/animation/duration", 500);
+     *     chart.setOption("/chart/animation/easing", "linear");
+     * 
+ * Sets the overall animation for all chart updating. Animation can be disabled throughout + * the chart by setting it to false here. It can be overridden for each individual API + * method as a function parameter. The only animation not affected by this option is the + * initial series animation, see {@link org.moxieapps.gwt.highcharts.client.plotOptions.PlotOptions#setAnimation(Animation)} method for + * control over series animations that are added after the chart has been rendered. + *

+ * Note that this is intended for users that want to have finite control over the way animations + * behave. To simply enable/disable animations, you can use the {@link #setAnimation(boolean)} + * method instead. + *

+ * + * @param animation The custom animation to set as the default animation type for the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setAnimation(Animation animation) { + return this.setOption("/chart/animation", animation.getOptions()); + } + + /** + * Convenience method for setting the 'backgroundColor' option of the chart to an RGB hex value. Equivalent to: + *


+     *     chart.setOption("/chart/backgroundColor", "#CCCCCC");
+     * 
+ * The RGB background color for the outer chart area. Defaults to "#FFFFFF". + *

+ * Note that this method is intended for setting the color to a simple RBG hex value. If you instead + * want to set a color to include an alpha channel or a gradient, use the {@link #setBackgroundColor(Color)} + * version instead. + * + * @param backgroundColor The value to set as the 'backgroundColor' option on the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setBackgroundColor(String backgroundColor) { + return this.setOption("/chart/backgroundColor", backgroundColor); + } + + /** + * Convenience method for setting the 'backgroundColor' option of the chart, allowing for + * colors with opacity or gradients. Equivalent to: + *


+     *     chart.setOption("/chart/backgroundColor", new Color()
+     *        .setLinearGradient(0.0, 0.0, 1.0, 1.0)
+     *        .addStop(new Color(255, 255, 255))
+     *        .addStop(new Color(200, 200, 255))
+     *     );
+     * 
+ * The background color or gradient for the outer chart area. Defaults to "#FFFFFF". + *

+ * Note that this method is intended for setting the color to a gradient or color that includes + * an alpha channel. If you instead just want to set the color to a normal RGB hex value + * you can use the {@link #setBackgroundColor(String)} version instead. + * + * @param backgroundColor The color gradient or color with an alpha channel to set as the 'backgroundColor' option on the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setBackgroundColor(Color backgroundColor) { + return this.setOption("/chart/backgroundColor", backgroundColor != null ? backgroundColor.getOptionValue() : null); + } + + /** + * Convenience method for setting the 'borderColor' option of the chart to an RGB hex value. Equivalent to: + *


+     *     chart.setOption("/chart/borderColor", "#CCCCCC");
+     * 
+ * The RGB color of the outer chart border. The border is painted using vector graphic techniques to allow + * rounded corners. Defaults to "#4572A7". + *

+ * Note that this method is intended for setting the color to a simple RBG hex value. If you instead + * want to set a color to include an alpha channel or a gradient, use the {@link #setBorderColor(Color)} + * version instead. + * + * @param borderColor The value to set as the 'borderColor' option on the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setBorderColor(String borderColor) { + return this.setOption("/chart/borderColor", borderColor); + } + + /** + * Convenience method for setting the 'borderColor' option of the chart, allowing for + * colors with opacity or gradients. Equivalent to: + *


+     *     chart.setOption("/chart/borderColor", new Color()
+     *        .setLinearGradient(0.0, 0.0, 1.0, 1.0)
+     *        .addStop(new Color(255, 255, 255))
+     *        .addStop(new Color(200, 200, 255))
+     *     );
+     * 
+ * The color of the outer chart border. The border is painted using vector graphic techniques to allow + * rounded corners. Defaults to "#4572A7". + *

+ * Note that this method is intended for setting the color to a gradient or color that includes + * an alpha channel. If you instead just want to set the color to a normal RGB hex value + * you can use the {@link #setBorderColor(String)} version instead. + * + * @param borderColor The color gradient or color with an alpha channel to set as the 'borderColor' option on the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setBorderColor(Color borderColor) { + return this.setOption("/chart/borderColor", borderColor != null ? borderColor.getOptionValue() : null); + } + + /** + * Convenience method for setting the 'borderRadius' option of the chart. Equivalent to: + *


+     *     chart.setOption("/chart/borderRadius", 10);
+     * 
+ * The corner radius of the outer chart border. Defaults to 5. + * + * @param borderRadius The corner radius of the outer chart border. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setBorderRadius(Number borderRadius) { + return this.setOption("/chart/borderRadius", borderRadius); + } + + /** + * Convenience method for setting the 'borderWidth' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/borderWidth", 10);
+     * 
+ * The pixel width of the outer chart border. The border is painted using vector graphic + * techniques to allow rounded corners. Defaults to 0. + * + * @param borderWidth The corner radius of the outer chart border. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setBorderWidth(Number borderWidth) { + return this.setOption("/chart/borderWidth", borderWidth); + } + + /** + * Convenience method for setting the 'subtitle/text' chart option. Equivalent to: + *

+     *     chart.setOption("/subtitle/text", "Source: Wikipedia.com");
+     * 
+ * The actual text of the chart subtitle. It can contain basic HTML text markup like + * <b>, <i> and spans with style. Defaults to null. + *

+ * For more control over the title, utilize the {@link #setChartSubtitle(ChartSubtitle)} + * method instead. + *

+ * To hide the chart subtitle completely, simply set the text to null. + *

+ * Note that this method is intended for handling configuring the chart's sub title area before + * the chart has been rendered, and has no affect if you invoke the method after the chart has been + * drawn to the DOM. If you do want to change the sub title (or title) of the chart dynamically + * after it has already been rendered, you can use the {@link #setTitle(ChartTitle, ChartSubtitle)} + * method instead. + * + * @param subtitle Sets the subtitle of chart, or null to hide the subtitle. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setChartSubtitleText(String subtitle) { + return this.setOption("/subtitle/text", subtitle); + } + + /** + * Convenience method for setting the 'subtitle' chart options. Equivalent to: + *


+     *     chart.setOption("/subtitle/text", "Source: Wikipedia.com");
+     *     chart.setOption("/subtitle/align", ChartTitle.Align.Left);
+     *     etc...
+     * 
+ *

+ * When you call this method it will overwrite any existing + * settings that have already been applied to the subtitle (e.g. if you + * had previously called the {@link #setChartSubtitleText(String)} method that change + * will get overwritten by this call.) + *

+ * If you just want to change the text of the subtitle, you can simply + * use the {@link #setChartSubtitleText(String)} method instead. + *

+ * Note that this method is intended for handling configuring the chart's sub title area before + * the chart has been rendered, and has no affect if you invoke the method after the chart has been + * drawn to the DOM. If you do want to change the sub title (or title) of the chart dynamically + * after it has already been rendered, you can use the {@link #setTitle(ChartTitle, ChartSubtitle)} + * method instead. + * + * @param subtitle Sets the chart subtitle options, or null to hide the subtitle. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setChartSubtitle(ChartSubtitle subtitle) { + return this.setOption("/subtitle", subtitle != null ? subtitle.getOptions() : null); + } + + /** + * Convenience method for setting the 'title/text' chart option. Equivalent to: + *


+     *     chart.setOption("/title/text", "Sales by Year");
+     * 
+ * The actual text of the chart title. It can contain basic HTML text markup like + * <b>, <i> and spans with style. Defaults to "Chart title". + *

+ * For more control over the title, utilize the {@link #setChartTitle(ChartTitle)} + * method instead. + *

+ * To hide the chart title completely, simply set the text to null. + *

+ * Note that this method is intended for handling configuring the chart's title area before + * the chart has been rendered, and has no affect if you invoke the method after the chart has been + * drawn to the DOM. If you do want to change the title (or sub title) of the chart dynamically + * after it has already been rendered, you can use the {@link #setTitle(ChartTitle, ChartSubtitle)} + * method instead. + * + * @param title Sets the title of chart, or null to hide the title. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setChartTitleText(String title) { + return this.setOption("/title/text", title); + } + + /** + * Convenience method for setting the 'title' chart options. Equivalent to: + *


+     *     chart.setOption("/title/text", "Sales by Year");
+     *     chart.setOption("/title/align", ChartTitle.Align.Left);
+     *     etc...
+     * 
+ *

+ * If you call this method it will overwrite any existing settings that have already + * been applied to the title (e.g. if you had previously called the + * {@link #setChartTitleText(String)} method that change will get overwritten by this call.) + *

+ * If you just want to change the text of the title, you can simply + * use the {@link #setChartTitleText(String)} method instead. + *

+ * Note that this method is intended for handling configuring the chart's title area before + * the chart has been rendered, and has no affect if you invoke the method after the chart has been + * drawn to the DOM. If you do want to change the title (or sub title) of the chart dynamically + * after it has already been rendered, you can use the {@link #setTitle(ChartTitle, ChartSubtitle)} + * method instead. + * + * @param title Sets the chart title options, or null to hide the title. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setChartTitle(ChartTitle title) { + return this.setOption("/title", title != null ? title.getOptions() : null); + } + + /** + * Convenience method for setting the 'className' option of the chart. Equivalent to: + *


+     *     chart.setOption("/chart/className", "RedChart");
+     * 
+ * A CSS class name to apply to the charts container div, allowing unique CSS styling + * for each chart. Defaults to "". + * + * @param className A CSS class name to apply to the charts container div. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setClassName(String className) { + return this.setOption("/chart/className", className); + } + + /** + * Sets the default colors for the chart's series. When all colors are used, new colors are pulled from the start again. + * Note that the colors for each series can be overridden via the {@link org.moxieapps.gwt.highcharts.client.plotOptions.PlotOptions#setColor(String)} mechanism. + *

+ * Default colors are: "#4572A7", "#AA4643", "#89A54E", "#80699B", "#3D96AE", "#DB843D", "#92A8CD", "#A47D7C", "#B5CA92" + * + * @param colors An array of colors to use as the defaults for each series. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setColors(String... colors) { + return this.setOption("/colors", colors); + } + + /** + * Convenience method for setting the 'credits' options of the chart. Equivalent to: + *


+     *     chart.setOption("/credits/text", "Presented by Snoopy");
+     *     chart.setOption("/credits/href", "http://www.peanuts.com/");
+     *     etc..
+     * 
+ * Highchart by default puts a credits label in the lower right corner of the chart. This + * can be changed using these options. + * + * @param credits The options to apply to the credits area of the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setCredits(Credits credits) { + return this.setOption("/credits", credits != null ? credits.getOptions() : null); + } + + /** + * Convenience method for setting the 'exporting' options of the chart. Equivalent to: + *

+     *     chart.setOption("/exporting/enabled", true);
+     *     chart.setOption("/exporting/width", 600);
+     *     etc..
+     * 
+ * Note that the "exporting" module must be included in the page in order for the exporting + * options to apply. E.g.: + *

+ * <script type="text/javascript" src="js/modules/exporting.js"></script> + * + * @param exporting The options to apply to the exporting area of the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + * @see #setNavigation(Navigation) + * @since 1.1.0 + */ + public T setExporting(Exporting exporting) { + return this.setOption("/exporting", exporting != null ? exporting.getOptions() : null); + } + + /** + * Convenience method for setting the 'height' option of the chart. Equivalent to: + *


+     *     chart.setOption("/chart/height", 300);
+     * 
+ * An explicit height for the chart. By default the height is calculated from the offset + * height of the containing element. Defaults to null. + * + * @param height An explicit height for the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setHeight(Number height) { + return this.setOption("/chart/height", height); + } + + /** + * Convenience method for setting the 'ignoreHiddenSeries' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/ignoreHiddenSeries", false);
+     * 
+ * If true, the axes will scale to the remaining visible series once one series is hidden. + * If false, hiding and showing a series will not affect the axes or the other series. + * For stacks, once one series within the stack is hidden, the rest of the stack will close + * in around it even if the axis is not affected. Defaults to true. + * + * @param ignoreHiddenSeries If true, the axes will scale to the remaining visible series + * once one series is hidden. If false, hiding and showing a series + * will not affect the axes or the other series. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setIgnoreHiddenSeries(boolean ignoreHiddenSeries) { + return this.setOption("/chart/ignoreHiddenSeries", ignoreHiddenSeries); + } + + /** + * Convenience method for setting the 'inverted' option of the chart. Equivalent to: + *

+     *     chart.setOption("/inverted", true);
+     * 
+ * Whether to invert the axes so that the x axis is horizontal and y axis is vertical. When true, the + * x axis is reversed by default. If a bar plot is present in the chart, it will be inverted automatically. Defaults to false. + * + * @param inverted Whether to invert the axes so that the x axis is horizontal and y axis is vertical. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setInverted(boolean inverted) { + return this.setOption("/chart/inverted", inverted); + } + + /** + * Sets HTML labels that can be positioned anywhere in the chart area. Each label can contain + * HTML as well as CSS style properties that can be used to position the label anywhere in the + * chart area. See the {@link #setLabelsStyle(Style)} method to control the default style for + * each label. + *

+ * + * @param labelItems An array of LabelItem instances that contain the HTML of the label as well + * as a "style" object that can be used to position each label. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setLabelItems(LabelItem... labelItems) { + return this.setOption("/labels/items", labelItems); + } + + /** + * Sets the default CSS style options that will be shared by all label items that are added to the + * chart via the {@link #setLabelItems(LabelItem...)} method. The default label style + * is simply: + *

    + *
  • color: "#3E576F"
  • + *
+ * + * @param style Shared CSS styles for all label items. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setLabelsStyle(Style style) { + return this.setOption("/labels/style", style != null ? style.getOptions() : null); + } + + /** + * Convenience method for setting the 'legend' options of the chart. Equivalent to: + *

+     *     chart.setOption("/legend/borderColor", "#CCCCCC");
+     *     chart.setOption("/legend/layout", Legend.Layout.HORIZONTAL);
+     *     etc..
+     * 
+ * The legend is a box containing a symbol and name for each series item or point item in the chart. + * + * @param legend The options to apply to the legend of the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setLegend(Legend legend) { + return this.setOption("/legend", legend != null ? legend.getOptions() : null); + } + + /** + * Convenience method for setting the 'loading' options of the chart. Equivalent to: + *

+     *     chart.setOption("/loading/showDuration", 150);
+     *     chart.setOption("/loading/hideDuration", 60);
+     *     etc..
+     * 
+ * The loading options control the appearance of the loading screen that covers the plot area + * on chart operations. This screen only appears after an explicit call to + * {@link Chart#showLoading(String)}. It is a utility for developers to communicate to the end + * user that something is going on, for example while retrieving new data via a GWT remoting + * request. The "Loading..." text itself is not part of this configuration object, but part of + * the {@link Lang} object. + * + * @param loading The options to apply to the loading area of the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setLoading(Loading loading) { + return this.setOption("/loading", loading != null ? loading.getOptions() : null); + } + + /** + * Convenience method for setting the 'margin' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/margin", 0, 10, 0, 15);
+     * 
+ * The margin between the outer edge of the chart and the plot area. Use the options + * {@link #setMarginTop(Number)}, {@link #setMarginRight(Number)}, {@link #setMarginBottom(Number)}, and + * {@link #setMarginLeft(Number)} for shorthand setting of one option. + *

+ * Since version 2.1, the margin is 0 by default. The actual space is dynamically calculated from + * the offset of axis labels, axis title, title, subtitle and legend in addition to the + * {@link #setSpacingTop(Number)}, {@link #setSpacingRight(Number)}, {@link #setSpacingBottom(Number)}, + * and {@link #setSpacingLeft(Number)} options. + * + * @param marginTop The margin between the top outer edge of the chart and the plot area. + * @param marginRight The margin between the right outer edge of the chart and the plot area. + * @param marginBottom The margin between the bottom outer edge of the chart and the plot area. + * @param marginLeft The margin between the left outer edge of the chart and the plot area. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setMargin(Number marginTop, Number marginRight, Number marginBottom, Number marginLeft) { + JSONArray margins = new JSONArray(); + margins.set(0, new JSONNumber(marginTop.doubleValue())); + margins.set(1, new JSONNumber(marginRight.doubleValue())); + margins.set(2, new JSONNumber(marginBottom.doubleValue())); + margins.set(3, new JSONNumber(marginLeft.doubleValue())); + return this.setOption("/chart/margin", margins); + } + + /** + * Convenience method for setting the 'marginTop' option of the chart. Equivalent to: + *


+     *     chart.setOption("/chart/marginTop", 100);
+     * 
+ * The margin between the top outer edge of the chart and the plot area. Use this to set a fixed + * pixel value for the margin as opposed to the default dynamic margin. + * See also {@link #setSpacingTop(Number)}. Defaults to null. + * + * @param marginTop The margin between the top outer edge of the chart and the plot area. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setMarginTop(Number marginTop) { + return this.setOption("/chart/marginTop", marginTop); + } + + /** + * Convenience method for setting the 'marginRight' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/marginRight", 100);
+     * 
+ * The margin between the right outer edge of the chart and the plot area. Use this to set + * a fixed pixel value for the margin as opposed to the default dynamic margin. + * See also {@link #setSpacingRight(Number)}. Defaults to null. + * + * @param marginRight The margin between the right outer edge of the chart and the plot area. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setMarginRight(Number marginRight) { + return this.setOption("/chart/marginRight", marginRight); + } + + /** + * Convenience method for setting the 'marginBottom' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/marginBottom", 100);
+     * 
+ * The margin between the bottom outer edge of the chart and the plot area. Use this to set + * a fixed pixel value for the margin as opposed to the default dynamic margin. + * See also {@link #setSpacingBottom(Number)}. Defaults to null. + * + * @param marginBottom The margin between the bottom outer edge of the chart and the plot area. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setMarginBottom(Number marginBottom) { + return this.setOption("/chart/marginBottom", marginBottom); + } + + /** + * Convenience method for setting the 'marginBottom' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/marginLeft", 100);
+     * 
+ * The margin between the left outer edge of the chart and the plot area. Use this to set a + * fixed pixel value for the margin as opposed to the default dynamic margin. + * See also {@link #setSpacingLeft(Number)}. Defaults to null. + * + * @param marginLeft The margin between the left outer edge of the chart and the plot area. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setMarginLeft(Number marginLeft) { + return this.setOption("/chart/marginLeft", marginLeft); + } + + /** + * Convenience method for setting the 'navigation' options of the chart, which represents + * a collection of options for buttons and menus appearing in the exporting module. + *

+ * Note that the "exporting" module must be included in the page in order for the + * exporting navigation options to apply. E.g.: + *

+ * <script type="text/javascript" src="js/modules/navigation.js"></script> + * + * @param navigation The options to apply to the exporting navigation area of the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + * @see #setExporting(Exporting) + * @since 1.1.0 + */ + public T setNavigation(Navigation navigation) { + return this.setOption("/navigation", navigation != null ? navigation.getOptions() : null); + } + + /** + * Convenience method for setting the 'plotBackgroundColor' option of the chart to an RGB hex value. Equivalent to: + *


+     *     chart.setOption("/chart/plotBackgroundColor", "#CCCCCC");
+     * 
+ * The RGB background color for the plot area. Defaults to null. + *

+ * Note that this method is intended for setting the color to a simple RBG hex value. If you instead + * want to set a color to include an alpha channel or a gradient, use the {@link #setPlotBackgroundColor(Color)} + * version instead. + * + * @param plotBackgroundColor The value to set as the 'plotBackgroundColor' option on the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setPlotBackgroundColor(String plotBackgroundColor) { + return this.setOption("/chart/plotBackgroundColor", plotBackgroundColor); + } + + /** + * Convenience method for setting the 'plotBackgroundColor' option of the chart, allowing for + * colors with opacity or gradients. Equivalent to: + *


+     *     chart.setOption("/chart/plotBackgroundColor", new Color()
+     *        .setLinearGradient(0.0, 0.0, 1.0, 1.0)
+     *        .addStop(new Color(255, 255, 255))
+     *        .addStop(new Color(200, 200, 255))
+     *     );
+     * 
+ * The background color or gradient for the plot area. Defaults to null. + *

+ * Note that this method is intended for setting the color to a gradient or color that includes + * an alpha channel. If you instead just want to set the color to a normal RGB hex value + * you can use the {@link #setPlotBackgroundColor(String)} version instead. + * + * @param plotBackgroundColor The color gradient or color with an alpha channel to set as the 'plotBackgroundColor' option on the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setPlotBackgroundColor(Color plotBackgroundColor) { + return this.setOption("/chart/plotBackgroundColor", plotBackgroundColor != null ? plotBackgroundColor.getOptionValue() : null); + } + + /** + * Convenience method for setting the 'plotBorderColor' option of the chart to an RGB hex value. Equivalent to: + *


+     *     chart.setOption("/chart/plotBorderColor", "#CCCCCC");
+     * 
+ * The RGB color of the inner chart or plot area border. Defaults to "#C0C0C0". + *

+ * Note that this method is intended for setting the color to a simple RBG hex value. If you instead + * want to set a color to include an alpha channel or a gradient, use the {@link #setPlotBorderColor(Color)} + * version instead. + * + * @param plotBorderColor The value to set as the 'plotBorderColor' option on the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setPlotBorderColor(String plotBorderColor) { + return this.setOption("/chart/plotBorderColor", plotBorderColor); + } + + /** + * Convenience method for setting the 'plotBorderColor' option of the chart, allowing for + * colors with opacity or gradients. Equivalent to: + *


+     *     chart.setOption("/chart/plotBorderColor", new Color()
+     *        .setLinearGradient(0.0, 0.0, 1.0, 1.0)
+     *        .addStop(new Color(255, 255, 255))
+     *        .addStop(new Color(200, 200, 255))
+     *     );
+     * 
+ * The color (or gradient) of the inner chart or plot area border. Defaults to "#C0C0C0". + *

+ * Note that this method is intended for setting the color to a gradient or color that includes + * an alpha channel. If you instead just want to set the color to a normal RGB hex value + * you can use the {@link #setPlotBorderColor(String)} version instead. + * + * @param plotBorderColor The color gradient or color with an alpha channel to set as the 'plotBorderColor' option on the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setPlotBorderColor(Color plotBorderColor) { + return this.setOption("/chart/plotBorderColor", plotBorderColor != null ? plotBorderColor.getOptionValue() : null); + } + + /** + * Convenience method for setting the 'plotBorderWidth' option of the chart. Equivalent to: + *


+     *     chart.setOption("/chart/plotBorderWidth", 10);
+     * 
+ * The pixel width of the plot area border. Defaults to 0. + * + * @param plotBorderWidth The pixel width of the plot area border. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setPlotBorderWidth(Number plotBorderWidth) { + return this.setOption("/chart/plotBorderWidth", plotBorderWidth); + } + + /** + * Convenience method for setting the 'plotShadow' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/plotShadow", false);
+     * 
+ * Whether to apply a drop shadow to the plot area. Requires that plotBackgroundColor be set. Defaults to false. + * + * @param plotShadow Whether to apply a drop shadow to the plot area. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setPlotShadow(boolean plotShadow) { + return this.setOption("/chart/plotShadow", plotShadow); + } + + /** + * Convenience method for setting the 'reflow' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/reflow", false);
+     * 
+ * Whether to reflow the chart to fit the width of the container div on resizing + * the window. Defaults to true. + * + * @param reflow If true, reflow the chart to fit the width of the container div on resizing + * the window. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setReflow(boolean reflow) { + return this.setOption("/chart/reflow", reflow); + } + + /** + * Convenience method for setting the 'shadow' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/shadow", true);
+     * 
+ * Whether to apply a drop shadow to the outer chart area. Requires that backgroundColor be set. Defaults to false. + * + * @param shadow If true, apply a drop shadow to the outer chart area. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setShadow(boolean shadow) { + return this.setOption("/chart/shadow", shadow); + } + + /** + * Convenience method for setting the 'showAxes' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/showAxes", true);
+     * 
+ * Whether to show the axes initially. This only applies to empty charts where series are added + * dynamically, as axes are automatically added to cartesian series. Defaults to false. + * + * @param showAxes If true, show the axes initially (only applies to empty charts when the series + * are added dynamically). + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setShowAxes(boolean showAxes) { + return this.setOption("/chart/showAxes", showAxes); + } + + /** + * Convenience method for setting the 'spacingTop' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/spacingTop", 100);
+     * 
+ * The space between the top edge of the chart and the content (plot area, axis title and labels, + * title, subtitle or legend in top position). Defaults to 10. + * + * @param spacingTop The space between the top edge of the chart and the content. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setSpacingTop(Number spacingTop) { + return this.setOption("/chart/spacingTop", spacingTop); + } + + /** + * Convenience method for setting the 'spacingRight' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/spacingRight", 100);
+     * 
+ * The space between the right edge of the chart and the content (plot area, axis title and labels, + * title, subtitle or legend in top position). Defaults to 10. + * + * @param spacingRight The space between the right edge of the chart and the content. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setSpacingRight(Number spacingRight) { + return this.setOption("/chart/spacingRight", spacingRight); + } + + /** + * Convenience method for setting the 'spacingBottom' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/spacingBottom", 100);
+     * 
+ * The space between the bottom edge of the chart and the content (plot area, axis title and labels, + * title, subtitle or legend in top position). Defaults to 15. + * + * @param spacingBottom The space between the bottom edge of the chart and the content. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setSpacingBottom(Number spacingBottom) { + return this.setOption("/chart/spacingBottom", spacingBottom); + } + + /** + * Convenience method for setting the 'spacingLeft' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/spacingLeft", 100);
+     * 
+ * The space between the left edge of the chart and the content (plot area, axis title and labels, + * title, subtitle or legend in top position). Defaults to 10. + * + * @param spacingLeft The space between the left edge of the chart and the content. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setSpacingLeft(Number spacingLeft) { + return this.setOption("/chart/spacingLeft", spacingLeft); + } + + /** + * Convenience method for setting the 'style' options of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/style/fontWeight", "bold");
+     *     chart.setOption("/chart/style/fontFamily", "serif");
+     *     etc.
+     * 
+ * Additional CSS styles to apply inline to the container div. Note that since the default + * font styles are applied in the renderer, it is ignorant of the individual chart options + * and must be set globally. Defaults to: + *
    + *
  • fontFamily: '"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif'
  • + *
  • fontSize: '12px'
  • + *
+ * + * @param style An object containing the style properties to set on the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setStyle(Style style) { + return this.setOption("/chart/style", style != null ? style.getOptions() : null); + } + + /** + * Sets the default symbols for the series point markers. When all symbols are used, new symbols + * are pulled from the start again. Note that the symbols for each series can be overridden via the + * {@link org.moxieapps.gwt.highcharts.client.plotOptions.Marker#setSymbol(org.moxieapps.gwt.highcharts.client.plotOptions.Marker.Symbol)} method + * (which can be set on the series via its plot options, see + * {@link Series#setPlotOptions(org.moxieapps.gwt.highcharts.client.plotOptions.PlotOptions)}). + *

+ * Default symbols are: Circle, Diamond, Square, Triangle, and Triangle-Down + * + * @param symbols An array of symbols to use as the default symbols for the series point markers. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setSymbols(Marker.Symbol... symbols) { + JSONArray symbolsArray = null; + if (symbols != null) { + symbolsArray = new JSONArray(); + for (int i = 0; i < symbols.length; i++) { + Marker.Symbol symbol = symbols[i]; + symbolsArray.set(i, new JSONString(symbol.toString())); + } + } + return this.setOption("/symbols", symbolsArray); + } + + /** + * Set a new title or subtitle for the chart. This method can be called after the chart is + * rendered in order to change the title of the chart dynamically. + *

+ * Note: this method is primarily intended to allow the chart's title or sub-title area to + * be modified dynamically, after the chart has already been rendered to the DOM. If you + * instead simply want to set the title or sub-title of the chart via normal configuration + * (before the chart has been rendered), then you can utilize the {@link #setChartTitleText(String)}, + * {@link #setChartTitle(ChartTitle)}, {@link #setChartSubtitleText(String)} and + * {@link #setChartSubtitle(ChartSubtitle)} methods. + * + * @param chartTitle The new options for the main title area of the chart (including the text). + * @param chartSubtitle The new options for the main subtitle area of the chart (including the text). + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + * @since 1.1.0 + */ + public T setTitle(ChartTitle chartTitle, ChartSubtitle chartSubtitle) { + if (isRendered()) { + nativeSetTitle(chart, + chartTitle != null ? chartTitle.getOptions().getJavaScriptObject() : null, + chartSubtitle != null ? chartSubtitle.getOptions().getJavaScriptObject() : null + ); + } else { + this.setChartTitle(chartTitle); + this.setChartSubtitle(chartSubtitle); + } + return returnThis(); + } + + // We need to maintain a local reference to tooltip to deal with the formatter function + private ToolTip toolTip; + + /** + * Convenience method for setting the 'tooltip' option of the chart. Equivalent to: + *


+     *     chart.setOption("/tooltip/borderColor", "#CCCCCC");
+     *     chart.setOption("/tooltip/shadow", true);
+     *     etc..
+     * 
+ * The tooltip appears when the user hovers over a series or point. + * + * @param toolTip The options to apply to the tooltip of the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setToolTip(ToolTip toolTip) { + this.toolTip = toolTip; + return this.setOption("/tooltip", toolTip != null ? toolTip.getOptions() : null); + } + + /** + * Sets the defaults series type for the chart (which controls the way the series will be rendered), using + * an enumeration type in order to ensure a correct value is passed. This is equivalent to + * setting the option manually with code like: + *

+     *     chart.setOption("/chart/type", "line");
+     * 
+ * Note that if you don't set this explicitly the default series type is {@link Series.Type#LINE}. + * + * @param type One of the supported series types. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setType(Series.Type type) { + return this.setOption("/chart/type", type.toString()); + } + + /** + * Convenience method for setting the 'width' option of the chart. Equivalent to: + *

+     *     chart.setOption("/chart/width", 800);
+     * 
+ * An explicit width for the chart. By default the width is calculated from the offset + * width of the containing element. Defaults to null. + * + * @param width An explicit width for the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setWidth(Number width) { + return this.setOption("/chart/width", width); + } + + /** + * Update the size of the chart to match the size of the container that this widget was inserted + * inside of. + * + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setSizeToMatchContainer() { + return this.setSize(this.getOffsetWidth(), this.getOffsetHeight()); + } + + /** + * A helper method which can be used to conveniently set the width of the DOM element that contains + * the chart to "100%". Note that for more precise control over the size of the chart see the + * {@link #setSize(int, int)} and {@link #setSizeToMatchContainer()} methods. + * + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setWidth100() { + this.getElement().getStyle().setWidth(100, com.google.gwt.dom.client.Style.Unit.PCT); + return returnThis(); + } + + /** + * A helper method which can be used to conveniently set the height of the DOM element that contains + * the chart to "100%". Note that for more precise control over the size of the chart see the + * {@link #setSize(int, int)} and {@link #setSizeToMatchContainer()} methods. + * + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setHeight100() { + this.getElement().getStyle().setHeight(100, com.google.gwt.dom.client.Style.Unit.PCT); + return returnThis(); + } + + /** + * Updates the size of the chart to match the given width and height, using the default animation options. + * Note that if you simply want to set the size of the chart to match the container in which it was inserted, + * you can simply call the {@link #setSizeToMatchContainer()} method instead. + * + * @param width The new pixel width of the chart. + * @param height The new pixel height of the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setSize(int width, int height) { + return this.setSize(width, height, true); + } + + /** + * Updates the size of the chart to match the given width and height, explicitly setting whether or + * not the resize should be animated. + * + * @param width The new pixel width of the chart. + * @param height The new pixel height of the chart. + * @param animated When true, the resize will be animated with default animation options. The animation + * can also be configured by call the {@link #setSize(int, int, Animation)} method instead. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setSize(int width, int height, boolean animated) { + return this.setSize(width, height, animated ? new Animation() : null); + } + + /** + * Updates the size of the chart to match the given width and height, allowing for custom control + * over how the animation will be resized. + * + * @param width The new pixel width of the chart. + * @param height The new pixel height of the chart. + * @param animation The custom animation to use as the resize animation for the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setSize(int width, int height, Animation animation) { + + // Avoid monkeying with anything if we got bad values + if (width <= 0 || height <= 0) { + return returnThis(); + } + + if (isRendered()) { + // If we're already on the screen, then do the resize natively + if (animation == null || animation.getOptions() == null) { + nativeSetSize(chart, width, height, animation != null); + } else { + nativeSetSize(chart, width, height, animation.getOptions().getJavaScriptObject()); + } + } else { + // In we're invoked before the chart is rendered, keep the width and height around in our configuration + setOption("/chart/width", width); + setOption("/chart/height", height); + } + + return returnThis(); + + } + + // Delegate responsibility for managing configuration options to an anonymous helper class + private Configurable configurable = new Configurable() { + }; + + /** + * General purpose method to set an arbitrary option on the chart at any level, + * using "/" characters to designate which level of option you'd like to set. + * E.g., the following code: + *

+     * Chart chart = new Chart();
+     * chart.setOption("/chart/type", "spline");
+     * chart.setOption("/chart/marginRight", 10);
+     * chart.setOption("/title/text", "Nice Chart");
+     * 
+ * Would result in initializing HighCharts like the following: + *

+     * new HighCharts.Chart({
+     *     chart: {
+     *         type: "spline",
+     *         marginRight: 10
+     *     },
+     *     title: {
+     *         text: "Nice Chart"
+     *     }
+     * });
+     * 
+ * Note that the beginning "/" is optional, so chart.setOption("/thing", "piglet") is + * equivalent to chart.setOption("thing", "piglet"). + *

+ * For details on available options see the Highcharts reference. + *

+ * Note that, when possible, you'll ideally want to use one of the available type specific setter + * methods instead of this general method. E.g. instead of doing this: + *


+     * chart.setOption("/chart/type", "spline");
+     * 
+ * Do this instead: + *

+     * chart.setType(Series.Type.SPLINE);
+     * 
+ * + * @param path The path to the option to set (e.g. "/title/text"); + * @param value The value to set for the option (can be a String, Number, Boolean, or JSONObject) + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setOption(String path, Object value) { + configurable.setOption(path, value); + return returnThis(); + } + + /** + * Retrieve all of the options that have been configured for this chart instance + * as a JSONObject. + * + * @return A JSONObject representing all of the configuration options + * that have been set on the instance (will be null if no options have been set) + * + * @since 1.1.3 + */ + public JSONObject getOptions() { + return configurable.getOptions(); + } + + // Helper method to avoid having to do the cast and warning handling in multiple places + private T returnThis() { + @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"}) + T instance = (T) this; + return instance; + } + + // We need to maintain a local reference to the plot options in order to handle the potential callback formatter functions + private AreaPlotOptions areaPlotOptions; + private AreaSplinePlotOptions areaSplinePlotOptions; + private BarPlotOptions barPlotOptions; + private ColumnPlotOptions columnPlotOptions; + private LinePlotOptions linePlotOptions; + private PiePlotOptions piePlotOptions; + private SeriesPlotOptions seriesPlotOptions; + private ScatterPlotOptions scatterPlotOptions; + private SplinePlotOptions splinePlotOptions; + + /** + * Updates the options that all area type series within the chart will use by default. The settings can then + * be overridden for each individual series via the {@link Series#setPlotOptions(PlotOptions)} method. + *

+ * Note that changing the plot options on a chart that has already been rendered will only affect + * series that are subsequently added to the chart (and will not impact any of the series that are already + * rendered in the chart.) + * + * @param areaPlotOptions The options to set on the chart as the default settings for all area type series + * that are part of this chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setAreaPlotOptions(AreaPlotOptions areaPlotOptions) { + this.areaPlotOptions = areaPlotOptions; + return areaPlotOptions != null && areaPlotOptions.getOptions() != null ? + this.setOption("/plotOptions/area", areaPlotOptions.getOptions()) : + returnThis(); + } + + + /** + * Updates the options that all area spline type series within the chart will use by default. The settings can then + * be overridden for each individual series via the {@link Series#setPlotOptions(PlotOptions)} method. + *

+ * Note that changing the plot options on a chart that has already been rendered will only affect + * series that are subsequently added to the chart (and will not impact any of the series that are already + * rendered in the chart.) + * + * @param areaSplinePlotOptions The options to set on the chart as the default settings for all area spline type series + * that are part of this chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setAreaSplinePlotOptions(AreaSplinePlotOptions areaSplinePlotOptions) { + this.areaSplinePlotOptions = areaSplinePlotOptions; + return areaSplinePlotOptions != null && areaSplinePlotOptions.getOptions() != null ? + this.setOption("/plotOptions/areaspline", areaSplinePlotOptions.getOptions()) : + returnThis(); + } + + /** + * Updates the options that all bar type series within the chart will use by default. The settings can then + * be overridden for each individual series via the {@link Series#setPlotOptions(PlotOptions)} method. + *

+ * Note that changing the plot options on a chart that has already been rendered will only affect + * series that are subsequently added to the chart (and will not impact any of the series that are already + * rendered in the chart.) + * + * @param barPlotOptions The options to set on the chart as the default settings for all bar type series + * that are part of this chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setBarPlotOptions(BarPlotOptions barPlotOptions) { + this.barPlotOptions = barPlotOptions; + return barPlotOptions != null && barPlotOptions.getOptions() != null ? + this.setOption("/plotOptions/bar", barPlotOptions.getOptions()) : + returnThis(); + } + + /** + * Updates the options that all column type series within the chart will use by default. The settings can then + * be overridden for each individual series via the {@link Series#setPlotOptions(PlotOptions)} method. + *

+ * Note that changing the plot options on a chart that has already been rendered will only affect + * series that are subsequently added to the chart (and will not impact any of the series that are already + * rendered in the chart.) + * + * @param columnPlotOptions The options to set on the chart as the default settings for all column type series + * that are part of this chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setColumnPlotOptions(ColumnPlotOptions columnPlotOptions) { + this.columnPlotOptions = columnPlotOptions; + return columnPlotOptions != null && columnPlotOptions.getOptions() != null ? + this.setOption("/plotOptions/column", columnPlotOptions.getOptions()) : + returnThis(); + } + + /** + * Updates the options that all line type series within the chart will use by default. The settings can then + * be overridden for each individual series via the {@link Series#setPlotOptions(PlotOptions)} method. + *

+ * Note that changing the plot options on a chart that has already been rendered will only affect + * series that are subsequently added to the chart (and will not impact any of the series that are already + * rendered in the chart.) + * + * @param linePlotOptions The options to set on the chart as the default settings for all line type series + * that are part of this chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setLinePlotOptions(LinePlotOptions linePlotOptions) { + this.linePlotOptions = linePlotOptions; + return linePlotOptions != null && linePlotOptions.getOptions() != null ? + this.setOption("/plotOptions/line", linePlotOptions.getOptions()) : + returnThis(); + } + + /** + * Updates the options that all pie type series within the chart will use by default. The settings can then + * be overridden for each individual series via the {@link Series#setPlotOptions(PlotOptions)} method. + *

+ * Note that changing the plot options on a chart that has already been rendered will only affect + * series that are subsequently added to the chart (and will not impact any of the series that are already + * rendered in the chart.) + * + * @param piePlotOptions The options to set on the chart as the default settings for all pie type series + * that are part of this chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setPiePlotOptions(PiePlotOptions piePlotOptions) { + this.piePlotOptions = piePlotOptions; + return piePlotOptions != null && piePlotOptions.getOptions() != null ? + this.setOption("/plotOptions/pie", piePlotOptions.getOptions()) : + returnThis(); + } + + /** + * Updates the general options that all series within the chart will use by default. The settings can then + * be overridden for each individual series via the {@link Series#setPlotOptions(PlotOptions)} method. + *

+ * Note that the general {@link SeriesPlotOptions} type only represents core options that area available for all series types. + * To control options that are more specific to each series type, use one of the more specific methods instead (e.g. + * {@link #setLinePlotOptions(org.moxieapps.gwt.highcharts.client.plotOptions.LinePlotOptions)}, + * {@link #setAreaPlotOptions(org.moxieapps.gwt.highcharts.client.plotOptions.AreaPlotOptions)}, etc.) + *

+ * Also note that changing the general plot options on a chart that has already been rendered will only affect + * series that are subsequently added to the chart, and therefore will not impact any of the series that are already + * rendered in the chart. + * + * @param seriesPlotOptions The options to set on the chart as the default settings for all series that are part of this chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setSeriesPlotOptions(SeriesPlotOptions seriesPlotOptions) { + this.seriesPlotOptions = seriesPlotOptions; + return seriesPlotOptions != null && seriesPlotOptions.getOptions() != null ? + this.setOption("/plotOptions/series", seriesPlotOptions.getOptions()) : + returnThis(); + } + + /** + * Updates the options that all scatter type series within the chart will use by default. The settings can then + * be overridden for each individual series via the {@link Series#setPlotOptions(PlotOptions)} method. + *

+ * Note that changing the plot options on a chart that has already been rendered will only affect + * series that are subsequently added to the chart (and will not impact any of the series that are already + * rendered in the chart.) + * + * @param scatterPlotOptions The options to set on the chart as the default settings for all scatter type series + * that are part of this chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setScatterPlotOptions(ScatterPlotOptions scatterPlotOptions) { + this.scatterPlotOptions = scatterPlotOptions; + return scatterPlotOptions != null && scatterPlotOptions.getOptions() != null ? + this.setOption("/plotOptions/scatter", scatterPlotOptions.getOptions()) : + returnThis(); + } + + private ChartClickEventHandler chartClickEventHandler; + + /** + * Set a callback handler that will be invoked whenever the user clicks on the plot background. + * Information where the user clicked can then be found through the {@link org.moxieapps.gwt.highcharts.client.events.ChartClickEvent} instance + * that is passed to the handler's {@link org.moxieapps.gwt.highcharts.client.events.ChartClickEventHandler#onClick(org.moxieapps.gwt.highcharts.client.events.ChartClickEvent)} method. + * + * @param chartClickEventHandler The handler that should be invoked whenever a click event occurs. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + * @since 1.1.0 + */ + public T setClickEventHandler(ChartClickEventHandler chartClickEventHandler) { + this.chartClickEventHandler = chartClickEventHandler; + return returnThis(); + } + + private ChartLoadEventHandler chartLoadEventHandler; + + /** + * Set a callback handler that will be invoked whenever the chart's loading event is fired. + * + * @param chartLoadEventHandler The handler that should be invoked whenever a load event occurs. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + * @since 1.1.0 + */ + public T setLoadEventHandler(ChartLoadEventHandler chartLoadEventHandler) { + this.chartLoadEventHandler = chartLoadEventHandler; + return returnThis(); + } + + private ChartRedrawEventHandler chartRedrawEventHandler; + + /** + * Set a callback handler that will be invoked whenever the chart's redraw event is fired. + * + * @param chartRedrawEventHandler The handler that should be invoked whenever a redraw event occurs. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + * @since 1.1.0 + */ + public T setRedrawEventHandler(ChartRedrawEventHandler chartRedrawEventHandler) { + this.chartRedrawEventHandler = chartRedrawEventHandler; + return returnThis(); + } + + private ChartSelectionEventHandler chartSelectionEventHandler; + + /** + * Set a callback handler that will be invoked whenever the chart's selection event is fired. + * + * @param chartSelectionEventHandler The handler that should be invoked whenever a selection event occurs. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + * @since 1.1.0 + */ + public T setSelectionEventHandler(ChartSelectionEventHandler chartSelectionEventHandler) { + this.chartSelectionEventHandler = chartSelectionEventHandler; + return returnThis(); + } + + /** + * Updates the options that all spline type series within the chart will use by default. The settings can then + * be overridden for each individual series via the {@link Series#setPlotOptions(PlotOptions)} method. + *

+ * Note that changing the plot options on a chart that has already been rendered will only affect + * series that are subsequently added to the chart (and will not impact any of the series that are already + * rendered in the chart.) + * + * @param splinePlotOptions The options to set on the chart as the default settings for all spline type series + * that are part of this chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T setSplinePlotOptions(SplinePlotOptions splinePlotOptions) { + this.splinePlotOptions = splinePlotOptions; + return this.setOption("/plotOptions/spline", splinePlotOptions.getOptions()); + } + + // Purposefully not using the generic "List" interface here in order to optimize GWT performance. + private ArrayList seriesList = new ArrayList(); + + /** + * Create a new data series that can be configured, and then added to this chart instance via the + * {@link #addSeries(Series)} method. + * + * @return The series that was created (which will need to be added to the chart after it is configured + * via {@link #addSeries(Series)}. + */ + public Series createSeries() { + return new Series(this); + } + + /** + * Add the given data series to the chart, using the default options. Note, see the + * {@link #addSeries(Series, boolean, boolean)} and {@link #addSeries(Series, boolean, Animation)} for more + * control over how the series will be drawn and animated when added to a chart that has already been rendered. + * + * @param series The data series to add to the chart, including its general configuration and plot options. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T addSeries(Series series) { + return this.addSeries(series, true, true); + } + + /** + * Add a data series to this chart, controlling the redraw and animation options. + * + * @param series The data series to add to the chart, including its general configuration and plot options. + * @param redraw 'true' to force the chart to redraw immediately, or 'false' to wait until the + * {@link #redraw()} method is invoked. + * @param animation When 'true', the series updating will be animated with default animation options. + * Note, use the {@link #addSeries(Series, boolean, Animation)} method for more control over the animation options. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T addSeries(Series series, boolean redraw, boolean animation) { + return addSeries(series, redraw, animation ? new Animation() : null); + } + + /** + * Add a data series to this chart, controlling the redraw and animation options. + * + * @param series The data series to add to the chart, including its general configuration and plot options. + * @param redraw 'true' to force the chart to redraw immediately, or 'false' to wait until the + * {@link #redraw()} method is invoked. + * @param animation Custom animation to use when the series is being updated. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T addSeries(Series series, boolean redraw, Animation animation) { + + // Whether or not we've been rendered yet or not, maintain a reference to all of the series that we're managing + seriesList.add(series); + + if (isRendered()) { + final JavaScriptObject seriesOptions = convertSeriesToJSON(series).getJavaScriptObject(); + if (animation == null || animation.getOptions() == null) { + final boolean animationFlag = animation != null; + nativeAddSeries(chart, seriesOptions, redraw, animationFlag); + } else { + final JavaScriptObject animationOptions = animation.getOptions().getJavaScriptObject(); + nativeAddSeries(chart, seriesOptions, redraw, animationOptions); + } + series.setRendered(true); + + // Once we're rendered, we're maintaining the point state in the DOM, so we can dump our internal list to save memory + series.clearInternalPointsList(); + } + + return returnThis(); + } + + /** + * Retrieve the series instance within the chart for the given id, or null if no series exists in the chart + * with the given id. Note that series ids are set automatically by the framework, so all series instances + * are guaranteed to have an id associated with them. + *

+ * Some event methods (such as {@link org.moxieapps.gwt.highcharts.client.events.SeriesClickEvent#getSeriesId()}) + * return the unique id of a series, which can then be used in conjunction with this method to access + * the series instance associated with the event. + * + * @param seriesId The unique id of the series to try and find. + * @return The series associated with the given id, or null if no series exist with the given id + * @since 1.1.0 + */ + public Series getSeries(String seriesId) { + for (Series series : seriesList) { + if (series.getId().equals(seriesId)) { + return series; + } + } + return null; + } + + /** + * Return an array of all the {@link Series} instances that have been added to this chart (either before or + * after the chart was rendered), or an empty array if none have been added yet. Note that we're returning + * an array instead of a java.util.List as the generic interface types require a bit of a performance hit + * in GWT to use. + * + * @return An array of the Series instances currently within the chart, or an empty array if none have yet + * been added. + */ + public Series[] getSeries() { + return seriesList.toArray(new Series[seriesList.size()]); + } + + /** + * Remove the given series from the chart, automatically redrawing the chart after the series + * has been removed. See the {@link #removeSeries(Series, boolean)} method if you're performing + * multiple options on the chart at once and need tighter control over when the chart is redrawn. + * + * @param series The series instance to remove from the chart. + * @return 'true' if the series was a part of this chart and successfully removed, or 'false' if the + * given series was not a part of this chart and therefore couldn't be removed. + */ + public boolean removeSeries(Series series) { + return removeSeries(series, true); + } + + /** + * Remove the given series from the chart, explicitly controlling whether or not the chart will + * be redrawn after the series is removed. + * + * @param series The series instance to remove from the chart. + * @param redraw Whether to redraw the chart after the series is removed. When you're performing multiple + * options on the chart, it is highly recommended that the redraw option be set to false, and instead + * explicitly call the {@link Chart#redraw()} method after you're done updating the chart. + * @return 'true' if the series was a part of this chart and successfully removed, or 'false' if the + * given series was not a part of this chart and therefore couldn't be removed. + */ + public boolean removeSeries(Series series, boolean redraw) { + if (!seriesList.remove(series)) { + return false; + } + if (isRendered()) { + final JavaScriptObject nativeSeries = nativeGet(chart, series.getId()); + if (nativeSeries != null) { + nativeRemoveSeries(chart, nativeSeries, redraw); + } + } + return true; + } + + /** + * A convenience method to run through and remove all of the series that are currently part of the chart + * instance, only performing a redraw after they're all done. See the {@link Series#remove()} or + * {@link #removeSeries(Series)} method if you instead want to remove a single series from the chart. + * Also see the {@link #removeAllSeries(boolean)} method if you need more control over when the chart + * is redrawn. + * + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T removeAllSeries() { + removeAllSeries(true); + return returnThis(); + } + + /** + * A convenience method to run through and remove all of the series that are currently part of the chart + * instance, with explicit control over the animation options. See the {@link Series#remove()} or + * {@link #removeSeries(Series)} method if you instead want to remove a single series from the chart. + * + * @param redraw Whether to redraw the chart after the series is removed. When you're performing multiple + * options on the chart, it is highly recommended that the redraw option be set to false, and instead + * explicitly call the {@link Chart#redraw()} method after you're done updating the chart. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T removeAllSeries(boolean redraw) { + // Clone the collection so that we can remove from the main list while iterating over the clone + ArrayList clonedList = new ArrayList(seriesList); + for (Iterator iterator = clonedList.iterator(); iterator.hasNext(); ) { + Series series = iterator.next(); + // Only redraw after the vary last series is removed (unless not requested to at all) + if (iterator.hasNext()) { + removeSeries(series, false); + } else { + removeSeries(series, redraw); + } + } + return returnThis(); + } + + /** + * Returns an array of all currently selected series in the chart. Series can be selected either programmatically by the + * {@link Series#select(boolean)} method or by checking the checkbox next to the legend item if the + * {@link SeriesPlotOptions#setShowCheckbox(boolean)} option is true. + * + * @return An array of the selected Series items, or an empty array if either no series are selected or the + * chart has not yet been rendered. + * @since 1.1.0 + */ + public Series[] getSelectedSeries() { + ArrayList selectedSeries = new ArrayList(); + if (isRendered()) { + JsArrayString selectedSeriesIds = nativeGetSelectedSeriesIds(chart); + for (int i = 0; i < selectedSeriesIds.length(); i++) { + String selectedSeriesId = selectedSeriesIds.get(i); + for (Series series : seriesList) { + if (series.getId().equals(selectedSeriesId)) { + selectedSeries.add(series); + } + } + } + } + return selectedSeries.toArray(new Series[selectedSeries.size()]); + } + + /** + * Returns an array of all currently selected points in the chart. Points can be selected either + * programmatically via the {@link Point#select(boolean, boolean)} method or by clicking on them. + * + * @return An array of the selected Point items, or an empty array if either no points are selected or the + * chart has not yet been rendered. + * @since 1.1.0 + */ + public Point[] getSelectedPoints() { + ArrayList selectedPoints = new ArrayList(); + if (isRendered()) { + JsArray nativeSelectedPoints = nativeGetSelectedPoints(chart); + for (int i = 0; i < nativeSelectedPoints.length(); i++) { + selectedPoints.add(new Point(nativeSelectedPoints.get(i))); + } + } + return selectedPoints.toArray(new Point[selectedPoints.size()]); + } + + /** + * Exporting module required. Get an SVG string representing the chart.

+ * This method has no effect if the chart has not yet been rendered. + * + * @return An SVG representation of the chart, or null if the chart has not yet been rendered + */ + public String getSVG() { + if (isRendered()) { + return nativeGetSVG(chart); + } else { + return null; + } + } + + /** + * Hide the loading screen. Options for the loading screen are defined via {@link Chart#setLoading(Loading)}. + * Should be used in conjunction with the {@link #showLoading(String)} method.

+ * This method has no effect if the chart has not yet been rendered. + * + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T hideLoading() { + if (isRendered()) { + nativeHideLoading(chart); + } + return returnThis(); + } + + /** + * Dim the chart's plot area and show a loading label text. Options for the loading screen are defined via + * {@link Chart#setLoading(Loading)}. A custom text can be given as a parameter, otherwise the default + * message specified via the {@link Lang} options will be used. + * Should be used in conjunction with the {@link #hideLoading()} method.

+ * This method has no effect if the chart has not yet been rendered. + * + * @param message A custom message to appear as the loading text. + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T showLoading(String message) { + if (isRendered()) { + nativeShowLoading(chart, message); + } + return returnThis(); + } + + /** + * Exporting module required. Clears away other elements in the page and prints the chart as it is + * displayed. By default, when the exporting module is enabled, a button at the upper left calls this method.

+ * This method has no effect if the chart has not yet been rendered. + * + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T print() { + if (isRendered()) { + nativePrint(chart); + } + return returnThis(); + } + + // Purposefully using a specific type instead of the generic List interface for enhanced GWT performance + private ArrayList xAxes = new ArrayList(); + private ArrayList yAxes = new ArrayList(); + + /** + * Retrieve a reference to the XAxis for this chart (guaranteed non-null), so that it can then be + * configured or operated on. Note that you should use this method when you only have one x-axis + * to operate on. If you have multiple x-axis, then utilize the {@link #getXAxis(int)} method instead. + * + * @return A reference to the XAxis for this chart (never null); + */ + public XAxis getXAxis() { + return getXAxis(0); + } + + /** + * Retrieve a reference to a specific XAxis for this chart (guaranteed non-null), so that it can then be + * configured or operated on. Note that you should use this method when you only have multiple x-axis + * to operate on. If you have only a single y-axis, then utilize the {@link #getXAxis()} method instead. + * + * @param axisIndex The numeric index (zero based) of the XAxis to return. + * @return A reference to the XAxis at the given index for this chart (never null). + */ + public XAxis getXAxis(int axisIndex) { + if (axisIndex < xAxes.size()) { + return xAxes.get(axisIndex); + } + for (int i = xAxes.size(); i <= axisIndex; i++) { + xAxes.add(new XAxis(this)); + } + return xAxes.get(axisIndex); + } + + /** + * Retrieve a reference to the YAxis for this chart (guaranteed non-null), so that it can then be + * configured or operated on. Note that you should use this method when you only have one y-axis + * to operate on. If you have multiple y-axis, then utilize the {@link #getYAxis(int)} method instead. + * + * @return A reference to the YAxis for this chart (never null); + */ + public YAxis getYAxis() { + return getYAxis(0); + } + + /** + * Retrieve a reference to a specific YAxis for this chart (guaranteed non-null), so that it can then be + * configured or operated on. Note that you should use this method when you only have multiple y-axis + * to operate on. If you have only a single y-axis, then utilize the {@link #getYAxis()} method instead. + * + * @param axisIndex The numeric index (zero based) of the YAxis to return. + * @return A reference to the YAxis at the given index for this chart (never null). + */ + public YAxis getYAxis(int axisIndex) { + if (axisIndex < yAxes.size()) { + return yAxes.get(axisIndex); + } + for (int i = yAxes.size(); i <= axisIndex; i++) { + yAxes.add(new YAxis(this)); + } + return yAxes.get(axisIndex); + } + + /** + * Redraw the chart after changes have been done to the data or axis extremes. All methods for + * updating axes, series or points have a parameter for redrawing the chart. This is true by default. + * But in many cases you want to do more than one operation on the chart before redrawing, for + * example add a number of points. In those cases it is a waste of resources to redraw the chart + * for each new point added. So you add the points and call redraw() after. + *

+ * The redraw() method only redraws those parts of the chart that are actually changed. + * If the data of a series is changed and it doesn't affect the axes, only the series itself is redrawn. + * If the new data requires the axis extremes to be altered, the axis and all other series depending + * on it are redrawn. + * + * @return A reference to this {@link BaseChart} instance for convenient method chaining. + */ + public T redraw() { + if (isRendered()) { + nativeRedraw(chart); + } + return returnThis(); + } + + /** + * Returns true if the chart has already been rendered to the DOM, or false otherwise. + * + * @return 'true' if the chart has been rendered to the DOM + */ + public boolean isRendered() { + return chart != null; + } + + private JavaScriptObject chart; + + @Override + protected void onLoad() { + + // Build some arrays that we can pass into the JS function so that it knows how many custom callback functions it needs to wire + // up on the client side for formatter functions. + JSONArray xAxisLabelFormatters = new JSONArray(); + for (int i = 0, xAxesSize = xAxes.size(); i < xAxesSize; i++) { + XAxis xAxis = xAxes.get(i); + xAxisLabelFormatters.set(i, JSONBoolean.getInstance(xAxis.getLabels() != null && xAxis.getLabels().getFormatter() != null)); + } + JSONArray yAxisLabelFormatters = new JSONArray(); + JSONArray yAxisStackLabelFormatters = new JSONArray(); + for (int i = 0, yAxesSize = yAxes.size(); i < yAxesSize; i++) { + YAxis yAxis = yAxes.get(i); + yAxisLabelFormatters.set(i, JSONBoolean.getInstance(yAxis.getLabels() != null && yAxis.getLabels().getFormatter() != null)); + yAxisStackLabelFormatters.set(i, JSONBoolean.getInstance(yAxis.getStackLabels() != null && yAxis.getStackLabels().getFormatter() != null)); + } + + // Build a similar object for dealing with all of the data label formatters that may be set on the plot options + JSONObject plotOptionsLabelFormatters = new JSONObject(); + plotOptionsLabelFormatters.put("area", hasDataLabelsFormatter(areaPlotOptions)); + plotOptionsLabelFormatters.put("areaspline", hasDataLabelsFormatter(areaSplinePlotOptions)); + plotOptionsLabelFormatters.put("bar", hasDataLabelsFormatter(barPlotOptions)); + plotOptionsLabelFormatters.put("column", hasDataLabelsFormatter(columnPlotOptions)); + plotOptionsLabelFormatters.put("line", hasDataLabelsFormatter(linePlotOptions)); + plotOptionsLabelFormatters.put("pie", hasDataLabelsFormatter(piePlotOptions)); + plotOptionsLabelFormatters.put("series", hasDataLabelsFormatter(seriesPlotOptions)); + plotOptionsLabelFormatters.put("scatter", hasDataLabelsFormatter(scatterPlotOptions)); + plotOptionsLabelFormatters.put("spline", hasDataLabelsFormatter(splinePlotOptions)); + + // And one more for dealing with any data label formatters that have been applied directly to a series + JSONArray seriesLabelFormatters = new JSONArray(); + for (int i = 0, seriesListSize = seriesList.size(); i < seriesListSize; i++) { + Series series = seriesList.get(i); + seriesLabelFormatters.set(i, hasDataLabelsFormatter(series)); + } + + // Another one for events fired on the chart + JSONObject chartEventHandlers = new JSONObject(); + chartEventHandlers.put("click", JSONBoolean.getInstance(chartClickEventHandler != null)); + chartEventHandlers.put("load", JSONBoolean.getInstance(chartLoadEventHandler != null)); + chartEventHandlers.put("redraw", JSONBoolean.getInstance(chartRedrawEventHandler != null)); + chartEventHandlers.put("selection", JSONBoolean.getInstance(chartSelectionEventHandler != null)); + + // And two more for events that have been applied to the series (or the points within the series) + JSONObject seriesEventHandlers = new JSONObject(); + JSONObject pointEventHandlers = new JSONObject(); + + if (seriesPlotOptions != null) { + + // Series event + seriesEventHandlers.put("click", + JSONBoolean.getInstance(seriesPlotOptions.getSeriesClickEventHandler() != null) + ); + seriesEventHandlers.put("checkboxClick", + JSONBoolean.getInstance(seriesPlotOptions.getSeriesCheckboxClickEventHandler() != null) + ); + seriesEventHandlers.put("hide", + JSONBoolean.getInstance(seriesPlotOptions.getSeriesHideEventHandler() != null) + ); + seriesEventHandlers.put("legendItemClick", + JSONBoolean.getInstance(seriesPlotOptions.getSeriesLegendItemClickEventHandler() != null) + ); + seriesEventHandlers.put("mouseOver", + JSONBoolean.getInstance(seriesPlotOptions.getSeriesMouseOverEventHandler() != null) + ); + seriesEventHandlers.put("mouseOut", + JSONBoolean.getInstance(seriesPlotOptions.getSeriesMouseOutEventHandler() != null) + ); + seriesEventHandlers.put("show", + JSONBoolean.getInstance(seriesPlotOptions.getSeriesShowEventHandler() != null) + ); + + // Point events + pointEventHandlers.put("click", + JSONBoolean.getInstance(seriesPlotOptions.getPointClickEventHandler() != null) + ); + pointEventHandlers.put("mouseOver", + JSONBoolean.getInstance(seriesPlotOptions.getPointMouseOverEventHandler() != null) + ); + pointEventHandlers.put("mouseOut", + JSONBoolean.getInstance(seriesPlotOptions.getPointMouseOutEventHandler() != null) + ); + pointEventHandlers.put("remove", + JSONBoolean.getInstance(seriesPlotOptions.getPointRemoveEventHandler() != null) + ); + pointEventHandlers.put("select", + JSONBoolean.getInstance(seriesPlotOptions.getPointSelectEventHandler() != null) + ); + pointEventHandlers.put("unselect", + JSONBoolean.getInstance(seriesPlotOptions.getPointUnselectEventHandler() != null) + ); + pointEventHandlers.put("update", + JSONBoolean.getInstance(seriesPlotOptions.getPointUpdateEventHandler() != null) + ); + } + + // Pie charts support one additional point event + if (piePlotOptions != null) { + pointEventHandlers.put("legendItemClick", + JSONBoolean.getInstance(piePlotOptions.getPointLegendItemClickEventHandler() != null) + ); + } + + chart = nativeRenderChart( + getChartTypeName(), + createNativeOptions(), + toolTip != null && toolTip.getToolTipFormatter() != null, + chartEventHandlers.getJavaScriptObject(), + seriesEventHandlers.getJavaScriptObject(), + pointEventHandlers.getJavaScriptObject(), + xAxisLabelFormatters.getJavaScriptObject(), + yAxisLabelFormatters.getJavaScriptObject(), + yAxisStackLabelFormatters.getJavaScriptObject(), + plotOptionsLabelFormatters.getJavaScriptObject(), + seriesLabelFormatters.getJavaScriptObject() + ); + + // Now that we're rendered we're going to switch to maintaining everything within the DOM, so we can dump + // any series data that we were managing internally + for (Series series : seriesList) { + series.clearInternalPointsList(); + series.setRendered(true); + } + + } + + /** + * To be overridden in a sub class to return the JS type name of the chart instance that + * should be created when the chart is rendered. E.g. "Chart", "StockChart", etc. + * + * @return The name of the JS class type that should be created when this chart is rendered. + */ + protected abstract String getChartTypeName(); + + private JSONBoolean hasDataLabelsFormatter(PlotOptions plotOptions) { + return JSONBoolean.getInstance(plotOptions != null && + plotOptions.getDataLabels() != null && + plotOptions.getDataLabels().getFormatter() != null + ); + } + + private JSONBoolean hasDataLabelsFormatter(Series series) { + return JSONBoolean.getInstance(series != null && + series.getPlotOptions() != null && + series.getPlotOptions().getDataLabels() != null && + series.getPlotOptions().getDataLabels().getFormatter() != null + ); + } + + + @Override + protected void onUnload() { + if (isRendered()) { + nativeDestroy(chart); + chart = null; + } + } + + private JavaScriptObject createNativeOptions() { + JSONObject options = configurable.getOptions(); + if (options == null) { + options = new JSONObject(); + } + + // #1: We need to merge the options they provided with the additional detail we know internally, + // and first we need to set which DOM element the chart should be rendered within + JSONValue chartValue = options.get("chart"); + if (chartValue == null || chartValue.isObject() == null) { + chartValue = new JSONObject(); + options.put("chart", chartValue); + } + final JSONObject chartObject = (JSONObject) options.get("chart"); + chartObject.put("renderTo", new JSONString(this.getElement().getId())); + + // #2: We need to setup whatever data series needs to be rendered initially in the chart + if (seriesList.size() > 0) { + final JSONValue seriesValue = options.get("series"); + if (seriesValue == null || seriesValue.isArray() == null) { + options.put("series", new JSONArray()); + } + final JSONArray seriesArray = (JSONArray) options.get("series"); + for (int i = 0, seriesListSize = seriesList.size(); i < seriesListSize; i++) { + Series series = seriesList.get(i); + JSONObject seriesOptions = convertSeriesToJSON(series); + seriesArray.set(i, seriesOptions); + } + } + + // #3: We need to add references to our axis so that we can later lookup the + // axis by id (as well as pass along any configuration options that were applied to the axis) + final JSONValue xAxisJSONValue = convertToJSONValue(xAxes.toArray(new Configurable[xAxes.size()])); + if (xAxisJSONValue != null && xAxisJSONValue.isNull() == null) { + options.put("xAxis", xAxisJSONValue); + } + final JSONValue yAxisJSONValue = convertToJSONValue(yAxes.toArray(new Configurable[yAxes.size()])); + if (yAxisJSONValue != null && yAxisJSONValue.isNull() == null) { + options.put("yAxis", yAxisJSONValue); + } + + // For debugging the raw options that we're passing to the chart on startup, uncomment the following line + // com.google.gwt.user.client.Window.alert(options.toString()); + + return options.getJavaScriptObject(); + } + + private JSONObject convertSeriesToJSON(Series series) { + JSONObject seriesOptions = series.getOptions(); + if (seriesOptions == null) { + seriesOptions = new JSONObject(); + } + JSONValue dataValue = seriesOptions.get("data"); + if (dataValue == null || dataValue.isArray() == null) { + seriesOptions.put("data", new JSONArray()); + } + copyPointsToJSONArray(series.getPoints(), (JSONArray) seriesOptions.get("data")); + return seriesOptions; + } + + private static JSONValue convertToJSONValue(Configurable... configurables) { + if (configurables.length > 1) { + JSONArray jsonArray = new JSONArray(); + for (int i = 0; i < configurables.length; i++) { + jsonArray.set(i, configurables[i].getOptions()); + } + return jsonArray; + } else if (configurables.length == 1) { + return configurables[0].getOptions(); + } + return JSONNull.getInstance(); + } + + private static void copyPointsToJSONArray(Point[] points, JSONArray jsonArray) { + for (int i = 0, pointsLength = points.length; i < pointsLength; i++) { + final Point point = points[i]; + jsonArray.set(i, convertPointToJSON(point)); + } + } + + // Purposefully package scope so we can get to this method from the Series and Point classes as well + static JSONValue convertPointToJSON(Point point) { + final JSONObject options = point.getOptions(); + if (options != null) { + return addPointScalarValues(point, options); + } else if (point.getX() != null) { + JSONArray jsonArray = new JSONArray(); + jsonArray.set(0, new JSONNumber(point.getX().doubleValue())); + if (point.getY() != null) { + jsonArray.set(1, new JSONNumber(point.getY().doubleValue())); + } else { + jsonArray.set(1, JSONNull.getInstance()); + } + return jsonArray; + } else if (point.getY() != null) { + return new JSONNumber(point.getY().doubleValue()); + } else { + return JSONNull.getInstance(); + } + } + + // Purposefully package scope + static JSONValue addPointScalarValues(Point point, JSONObject options) { + if (point.getX() != null) { + options.put("x", new JSONNumber(point.getX().doubleValue())); + } + if (point.getY() != null) { + options.put("y", new JSONNumber(point.getY().doubleValue())); + } else { + options.put("y", JSONNull.getInstance()); + } + return options; + } + + // Purposefully constrained to package scope + JavaScriptObject get(String id) { + if (isRendered()) { + return nativeGet(chart, id); + } else { + return null; + } + } + + private native JavaScriptObject nativeRenderChart(String chartTypeName, + JavaScriptObject options, + boolean toolTipFormatterFlag, + JavaScriptObject chartEventHandlerFlags, + JavaScriptObject seriesEventHandlerFlags, + JavaScriptObject pointEventHandlerFlags, + JavaScriptObject xAxisLabelFormatterFlags, + JavaScriptObject yAxisLabelFormatterFlags, + JavaScriptObject yAxisStackLabelFormatterFlags, + JavaScriptObject plotOptionsLabelsFormatterFlags, + JavaScriptObject seriesLabelsFormatterFlags) /*-{ + + var self = this; + + // Add in GWT interceptor callback functions for the various core chart event handlers + for (var type1 in chartEventHandlerFlags) { + if (type1.indexOf("gwt") < 0 && chartEventHandlerFlags[type1]) { + options.chart.events = options.chart.events || {}; + options.chart.events[type1] = function(e) { + return self.@org.moxieapps.gwt.highcharts.client.BaseChart::chartEventCallback(Lcom/google/gwt/core/client/JavaScriptObject;Ljava/lang/String;)(e, arguments.callee.type); + }; + options.chart.events[type1].type = type1; + } + } + + // Add in GWT interceptor callback functions for the various series event handlers + for (var type2 in seriesEventHandlerFlags) { + if (type2.indexOf("gwt") < 0 && seriesEventHandlerFlags[type2]) { + options.plotOptions = options.plotOptions || {}; + options.plotOptions.series = options.plotOptions.series || {}; + options.plotOptions.series.events = options.plotOptions.series.events || {}; + options.plotOptions.series.events[type2] = function(e) { + return self.@org.moxieapps.gwt.highcharts.client.BaseChart::seriesEventCallback(Lcom/google/gwt/core/client/JavaScriptObject;Lcom/google/gwt/core/client/JavaScriptObject;Ljava/lang/String;)(this, e, arguments.callee.type); + }; + options.plotOptions.series.events[type2].type = type2; + } + } + + // Add in GWT interceptor callback functions for the various series point event handlers + for (var type3 in pointEventHandlerFlags) { + if (type3.indexOf("gwt") < 0 && pointEventHandlerFlags[type3]) { + options.plotOptions = options.plotOptions || {}; + options.plotOptions.series = options.plotOptions.series || {}; + options.plotOptions.series.point = options.plotOptions.series.point || {}; + options.plotOptions.series.point.events = options.plotOptions.series.point.events || {}; + options.plotOptions.series.point.events[type3] = function(e) { + return self.@org.moxieapps.gwt.highcharts.client.BaseChart::pointEventCallback(Lcom/google/gwt/core/client/JavaScriptObject;Lcom/google/gwt/core/client/JavaScriptObject;Ljava/lang/String;)(this, e, arguments.callee.type); + }; + options.plotOptions.series.point.events[type3].type = type3; + } + } + + // Add in GWT interceptor callback functions for the various formatters so that we can move from + // the native JS world back to the Java world... + if (toolTipFormatterFlag) { + options.tooltip = options.tooltip || {}; + options.tooltip.formatter = function() { + var result = self.@org.moxieapps.gwt.highcharts.client.BaseChart::toolTipFormatterCallback(Lcom/google/gwt/core/client/JavaScriptObject;)(this); + if (result == null) { + return false; + } + return result; + }; + } + + // X axis label formatters + for (i = 0; i < xAxisLabelFormatterFlags.length; i++) { + if (!xAxisLabelFormatterFlags[i]) continue; + var xAxis = xAxisLabelFormatterFlags.length == 1 ? options.xAxis : options.xAxis[i]; + xAxis.labels = xAxis.labels || {}; + xAxis.labels.formatter = function() { + return self.@org.moxieapps.gwt.highcharts.client.BaseChart::xAxisLabelFormatterCallback(Lcom/google/gwt/core/client/JavaScriptObject;I)(this, arguments.callee.index); + }; + xAxis.labels.formatter.index = i; + } + + // Y axis label formatters + for (i = 0; i < yAxisLabelFormatterFlags.length && i < yAxisStackLabelFormatterFlags.length; i++) { + var yAxis = yAxisLabelFormatterFlags.length == 1 ? options.yAxis : options.yAxis[i]; + if (yAxisLabelFormatterFlags[i]) { + yAxis.labels = yAxis.labels || {}; + yAxis.labels.formatter = function() { + return self.@org.moxieapps.gwt.highcharts.client.BaseChart::yAxisLabelFormatterCallback(Lcom/google/gwt/core/client/JavaScriptObject;I)(this, arguments.callee.index); + }; + yAxis.labels.formatter.index = i; + } + if (yAxisStackLabelFormatterFlags[i]) { + yAxis.stackLabels = yAxis.stackLabels || {}; + yAxis.stackLabels.formatter = function() { + return self.@org.moxieapps.gwt.highcharts.client.BaseChart::yAxisStackLabelFormatterCallback(Lcom/google/gwt/core/client/JavaScriptObject;I)(this, arguments.callee.index); + }; + yAxis.stackLabels.formatter.index = i; + } + } + + // Plot options data label formatters + for (var type4 in plotOptionsLabelsFormatterFlags) { + if (type4.indexOf("gwt") < 0 && plotOptionsLabelsFormatterFlags[type4]) { + options.plotOptions = options.plotOptions || {}; + options.plotOptions[type4] = options.plotOptions[type4] || {}; + options.plotOptions[type4].dataLabels = options.plotOptions[type4].dataLabels || {}; + options.plotOptions[type4].dataLabels.formatter = function() { + return self.@org.moxieapps.gwt.highcharts.client.BaseChart::plotOptionsLabelsFormatterCallback(Lcom/google/gwt/core/client/JavaScriptObject;Ljava/lang/String;)(this, arguments.callee.type); + }; + options.plotOptions[type4].dataLabels.formatter.type = type4; + } + } + + // Series override label formatters + for (i = 0; i < seriesLabelsFormatterFlags.length; i++) { + if (!seriesLabelsFormatterFlags[i]) continue; + var series = options.series[i]; + series.dataLabels = series.dataLabels || {}; + series.dataLabels.formatter = function() { + return self.@org.moxieapps.gwt.highcharts.client.BaseChart::seriesLabelsFormatterCallback(Lcom/google/gwt/core/client/JavaScriptObject;I)(this, arguments.callee.index); + }; + series.dataLabels.formatter.index = i; + } + + // Draw the chart! + return new $wnd.Highcharts[chartTypeName](options); + }-*/; + + @SuppressWarnings({"UnusedDeclaration"}) + private void chartEventCallback(JavaScriptObject nativeEvent, String eventType) { + if ("click".equals(eventType) && chartClickEventHandler != null) { + chartClickEventHandler.onClick(new ChartClickEvent(nativeEvent)); + } else if ("load".equals(eventType) && chartLoadEventHandler != null) { + chartLoadEventHandler.onLoad(new ChartLoadEvent(nativeEvent)); + } else if ("redraw".equals(eventType) && chartRedrawEventHandler != null) { + chartRedrawEventHandler.onRedraw(new ChartRedrawEvent(nativeEvent)); + } else if ("selection".equals(eventType) && chartSelectionEventHandler != null) { + chartSelectionEventHandler.onSelection(new ChartSelectionEvent(nativeEvent)); + } + } + + @SuppressWarnings({"UnusedDeclaration"}) + private void seriesEventCallback(JavaScriptObject nativeSeries, JavaScriptObject nativeEvent, String eventType) { + if ("click".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getSeriesClickEventHandler() != null) { + seriesPlotOptions.getSeriesClickEventHandler().onClick(new SeriesClickEvent(nativeEvent, nativeSeries)); + } else if ("checkboxClick".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getSeriesCheckboxClickEventHandler() != null) { + seriesPlotOptions.getSeriesCheckboxClickEventHandler().onClick(new SeriesCheckboxClickEvent(nativeEvent, nativeSeries)); + } else if ("hide".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getSeriesHideEventHandler() != null) { + seriesPlotOptions.getSeriesHideEventHandler().onHide(new SeriesHideEvent(nativeEvent, nativeSeries)); + } else if ("legendItemClick".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getSeriesLegendItemClickEventHandler() != null) { + seriesPlotOptions.getSeriesLegendItemClickEventHandler().onClick(new SeriesLegendItemClickEvent(nativeEvent, nativeSeries)); + } else if ("mouseOver".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getSeriesMouseOverEventHandler() != null) { + seriesPlotOptions.getSeriesMouseOverEventHandler().onMouseOver(new SeriesMouseOverEvent(nativeEvent, nativeSeries)); + } else if ("mouseOut".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getSeriesMouseOutEventHandler() != null) { + seriesPlotOptions.getSeriesMouseOutEventHandler().onMouseOut(new SeriesMouseOutEvent(nativeEvent, nativeSeries)); + } else if ("show".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getSeriesShowEventHandler() != null) { + seriesPlotOptions.getSeriesShowEventHandler().onShow(new SeriesShowEvent(nativeEvent, nativeSeries)); + } + } + + @SuppressWarnings({"UnusedDeclaration"}) + private void pointEventCallback(JavaScriptObject nativePoint, JavaScriptObject nativeEvent, String eventType) { + if ("click".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getPointClickEventHandler() != null) { + seriesPlotOptions.getPointClickEventHandler().onClick(new PointClickEvent(nativeEvent, nativePoint)); + } else if ("mouseOver".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getPointMouseOverEventHandler() != null) { + seriesPlotOptions.getPointMouseOverEventHandler().onMouseOver(new PointMouseOverEvent(nativeEvent, nativePoint)); + } else if ("mouseOut".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getPointMouseOutEventHandler() != null) { + seriesPlotOptions.getPointMouseOutEventHandler().onMouseOut(new PointMouseOutEvent(nativeEvent, nativePoint)); + } else if ("remove".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getPointRemoveEventHandler() != null) { + seriesPlotOptions.getPointRemoveEventHandler().onRemove(new PointRemoveEvent(nativeEvent, nativePoint)); + } else if ("select".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getPointSelectEventHandler() != null) { + seriesPlotOptions.getPointSelectEventHandler().onSelect(new PointSelectEvent(nativeEvent, nativePoint)); + } else if ("unselect".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getPointUnselectEventHandler() != null) { + seriesPlotOptions.getPointUnselectEventHandler().onUnselect(new PointUnselectEvent(nativeEvent, nativePoint)); + } else if ("update".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getPointUpdateEventHandler() != null) { + seriesPlotOptions.getPointUpdateEventHandler().onUpdate(new PointUpdateEvent(nativeEvent, nativePoint)); + } else if ("legendItemClick".equals(eventType) && piePlotOptions != null && piePlotOptions.getPointLegendItemClickEventHandler() != null) { + piePlotOptions.getPointLegendItemClickEventHandler().onClick(new PointLegendItemClickEvent(nativeEvent, nativePoint)); + } + } + + @SuppressWarnings({"UnusedDeclaration"}) + private String toolTipFormatterCallback(JavaScriptObject nativeData) { + if (toolTip == null || toolTip.getToolTipFormatter() == null) { + return null; + } + return toolTip.getToolTipFormatter().format(new ToolTipData(nativeData)); + } + + @SuppressWarnings({"UnusedDeclaration"}) + private String xAxisLabelFormatterCallback(JavaScriptObject nativeData, int axisIndex) { + if (xAxes == null || xAxes.size() <= axisIndex || + xAxes.get(axisIndex).getLabels() == null || + xAxes.get(axisIndex).getLabels().getFormatter() == null) { + return null; + } + return xAxes.get(axisIndex).getLabels().getFormatter().format(new AxisLabelsData(nativeData)); + } + + @SuppressWarnings({"UnusedDeclaration"}) + private String yAxisLabelFormatterCallback(JavaScriptObject nativeData, int axisIndex) { + if (yAxes == null || yAxes.size() <= axisIndex || + yAxes.get(axisIndex).getLabels() == null || + yAxes.get(axisIndex).getLabels().getFormatter() == null) { + return null; + } + return yAxes.get(axisIndex).getLabels().getFormatter().format(new AxisLabelsData(nativeData)); + } + + @SuppressWarnings({"UnusedDeclaration"}) + private String yAxisStackLabelFormatterCallback(JavaScriptObject nativeData, int axisIndex) { + if (yAxes == null || yAxes.size() <= axisIndex || + yAxes.get(axisIndex).getStackLabels() == null || + yAxes.get(axisIndex).getStackLabels().getFormatter() == null) { + return null; + } + return yAxes.get(axisIndex).getStackLabels().getFormatter().format(new StackLabelsData(nativeData)); + } + + @SuppressWarnings({"UnusedDeclaration"}) + private String plotOptionsLabelsFormatterCallback(JavaScriptObject nativeData, String type) { + PlotOptions plotOptions = null; + if ("area".equals(type)) plotOptions = areaPlotOptions; + if ("areaspline".equals(type)) plotOptions = areaSplinePlotOptions; + if ("bar".equals(type)) plotOptions = barPlotOptions; + if ("column".equals(type)) plotOptions = columnPlotOptions; + if ("line".equals(type)) plotOptions = linePlotOptions; + if ("pie".equals(type)) plotOptions = piePlotOptions; + if ("scatter".equals(type)) plotOptions = scatterPlotOptions; + if ("series".equals(type)) plotOptions = seriesPlotOptions; + if ("spline".equals(type)) plotOptions = splinePlotOptions; + + if (plotOptions == null || plotOptions.getDataLabels() == null || plotOptions.getDataLabels().getFormatter() == null) { + return null; + } + return plotOptions.getDataLabels().getFormatter().format(new DataLabelsData(nativeData)); + } + + @SuppressWarnings({"UnusedDeclaration"}) + private String seriesLabelsFormatterCallback(JavaScriptObject nativeData, int seriesIndex) { + if (seriesList == null || seriesList.size() <= seriesIndex || + seriesList.get(seriesIndex).getPlotOptions() == null || + seriesList.get(seriesIndex).getPlotOptions().getDataLabels() == null || + seriesList.get(seriesIndex).getPlotOptions().getDataLabels().getFormatter() == null) { + return null; + } + return seriesList.get(seriesIndex).getPlotOptions().getDataLabels().getFormatter().format(new DataLabelsData(nativeData)); + } + + private static native void nativeRedraw(JavaScriptObject chart) /*-{ + chart.redraw(); + }-*/; + + private static native void nativeDestroy(JavaScriptObject chart) /*-{ + chart.destroy(); + }-*/; + + private static native void nativeSetSize(JavaScriptObject chart, int width, int height, boolean animated) /*-{ + chart.setSize(width, height, animated); + }-*/; + + private static native void nativeSetSize(JavaScriptObject chart, int width, int height, JavaScriptObject animation) /*-{ + chart.setSize(width, height, animation); + }-*/; + + private static native JavaScriptObject nativeGet(JavaScriptObject chart, String id) /*-{ + return chart.get(id); + }-*/; + + private static native void nativeAddSeries(JavaScriptObject chart, JavaScriptObject seriesOptions, boolean redraw, boolean animationFlag) /*-{ + chart.addSeries(seriesOptions, redraw, animationFlag); + }-*/; + + private static native void nativeAddSeries(JavaScriptObject chart, JavaScriptObject seriesOptions, boolean redraw, JavaScriptObject animationOptions) /*-{ + chart.addSeries(seriesOptions, redraw, animationOptions); + }-*/; + + private static native void nativeRemoveSeries(JavaScriptObject chart, JavaScriptObject nativeSeries, boolean redraw) /*-{ + nativeSeries.remove(redraw); + }-*/; + + private static native void nativeHideLoading(JavaScriptObject chart) /*-{ + chart.hideLoading(); + }-*/; + + private static native void nativeShowLoading(JavaScriptObject chart, String message) /*-{ + chart.showLoading(message); + }-*/; + + private static native void nativePrint(JavaScriptObject chart) /*-{ + chart.print(); + }-*/; + + private static native JsArrayString nativeGetSelectedSeriesIds(JavaScriptObject chart) /*-{ + var seriesIds = []; + var selectedSeries = chart.getSelectedSeries(); + for (var i = 0; i < selectedSeries.length; i++) { + seriesIds.push(selectedSeries[i].options["id"]); + } + return seriesIds; + }-*/; + + private static native JsArray nativeGetSelectedPoints(JavaScriptObject chart) /*-{ + return chart.getSelectedPoints(); + }-*/; + + private static native String nativeGetSVG(JavaScriptObject chart) /*-{ + return chart.getSVG(); + }-*/; + + private static native void nativeSetTitle(JavaScriptObject chart, JavaScriptObject title, JavaScriptObject subTitle) /*-{ + chart.setTitle(title, subTitle); + }-*/; + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Chart.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Chart.java new file mode 100755 index 00000000000..cb04064be5f --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Chart.java @@ -0,0 +1,134 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +/** + * The main GWT widget that can be constructed and then configured in order to add a Highcharts + * chart into a GWT layout container. Note that only standard chart types can be created with + * this widget. See the {@link StockChart} for other available chart types. + * Basic usage is as follows: + *


+ * Chart chart = new Chart()
+ *    .setType(Series.Type.SPLINE)
+ *    .setChartTitleText("Nice Chart")
+ *    .setMarginRight(10);
+ * Series series = chart.createSeries()
+ *   .addPoint(40)
+ *   .addPoint(35)
+ *   .addPoint(60);
+ * chart.addSeries(series);
+ * RootPanel.get().add(chart);
+ * 
+ * For details on available options see the Highcharts reference. + *

+ * Note that in order for this widget to function you must have included the Highcharts javascript + * library and any of its dependencies in the page that the widget will run inside of. E.g.: + *


+ * <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
+ * <script type="text/javascript" src="js/highcharts.js"></script>
+ * 

+ * <!-- Optionally, add a highcharts theme file -->
+ * <script type="text/javascript" src="js/themes/gray.js"></script>
+ * 

+ * <!-- Optionally, include the highcharts exporting module -->
+ * <script type="text/javascript" src="js/modules/exporting.js"></script>
+ * 
+ * Note that Highcharts supports other JS frameworks besides jQuery for its internal DOM manipulation + * functionality. So, if jQuery isn't your cup of tea check the + * installation docs + * on the Highcharts site for more details. + * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class Chart extends BaseChart { + + /** + * An enumeration of supported chart zoom types, which can be passed to the + * {@link Chart#setZoomType(ZoomType)} method. The zoom type controls in what + * dimensions the user can zoom by dragging the mouse + */ + public enum ZoomType { + + /** + * Allow zoom horizontally on the X axis only. + */ + X("x"), + + /** + * Allow zoom vertically on the Y axis only. + */ + Y("y"), + + /** + * Allow zooming both horizontally and vertically (both axes). + */ + X_AND_Y("xy"); + + private ZoomType(String optionValue) { + this.optionValue = optionValue; + } + + private final String optionValue; + + public String toString() { + return optionValue; + } + + } + + /** + * Create a new Highcharts chart instance as a GWT Widget that can then be added to + * a GWT layout like any other widget. Note that the various methods that support + * setting properties of the chart (e.g. {@link #setType(org.moxieapps.gwt.highcharts.client.Series.Type)}, + * {@link #setBackgroundColor(String)}, {@link #setOption(String, Object)}, etc.) + * then support method chaining, allowing for syntax like the following: + *

+     * Chart chart = new Chart()
+     *    .setType(Series.Type.SPLINE)
+     *    .setChartTitleText("Nice Chart")
+     *    .setMarginRight(10);
+     * RootPanel.get().add(chart);
+     * 
+ */ + public Chart() { + super(); + } + + /** + * Sets which dimensions the user can zoom by dragging the mouse. + * Can be one of {@link Chart.ZoomType#X}, {@link Chart.ZoomType#Y} or + * {@link Chart.ZoomType#X_AND_Y}. Defaults to null. + * This is equivalent to setting the option manually with code like: + *

+     *     chart.setOption("/chart/zoomType", Chart.ZoomType.X);
+     * 
+ * + * @param zoomType One of the allowed zoom types. + * @return A reference to this {@link Chart} instance for convenient method chaining. + */ + public Chart setZoomType(Chart.ZoomType zoomType) { + return this.setOption("/chart/zoomType", zoomType != null ? zoomType.toString() : null); + } + + + @Override + protected String getChartTypeName() { + return "Chart"; + } + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/ChartSubtitle.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/ChartSubtitle.java new file mode 100755 index 00000000000..f373fc57c72 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/ChartSubtitle.java @@ -0,0 +1,151 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +/** + * A configurable class that can be used to represent custom sub title options for the + * chart, which can then be set on the chart (via the {@link Chart#setChartSubtitle(ChartSubtitle)} method.) + * Example usage: + *
+ *   chart.setChartSubTitle(
+ *     new ChartSubtitle()
+ *       .setText("Source: Wikipedia")
+ *       .setAlign(ChartTitle.Align.MIDDLE)
+ *   );
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class ChartSubtitle extends Configurable { + + /** + * Convenience method for setting the 'align' option of the subtitle. Equivalent to: + *

+     *     chartSubtitle.setOption("align", chartSubtitle.Align.LEFT);
+     * 
+ * The horizontal alignment of the subtitle. Can be one of "left", "center" and "right". + * Defaults to {@link ChartTitle.Align#CENTER}. + * + * @param align The horizontal alignment of the subtitle. + * @return A reference to this {@link ChartSubtitle} instance for convenient method chaining. + */ + public ChartSubtitle setAlign(ChartTitle.Align align) { + return this.setOption("align", align != null ? align.toString() : null); + } + + /** + * Convenience method for setting the 'floating' option of the subtitle. Equivalent to: + *

+     *     chartSubtitle.setOption("floating", true);
+     * 
+ * When the subtitle is floating, the plot area will not move to make space for it. Defaults to false. + * + * @param floating 'true' to float the subtitle above the plot area, or 'false' (the default) to make space for it. + * @return A reference to this {@link ChartSubtitle} instance for convenient method chaining. + */ + public ChartSubtitle setFloating(boolean floating) { + return this.setOption("floating", floating); + } + + /** + * Convenience method for setting the 'style' options of the subtitle. Equivalent to: + *

+     *     chartSubtitle.setOption("/style/fontWeight", "bold");
+     *     chartSubtitle.setOption("/style/fontFamily", "serif");
+     *     etc.
+     * 
+ * CSS styles for the subtitle. Exact positioning of the title can be achieved by changing the + * margin property, or by adding position: "absolute" and left and top properties. Defaults to: + *
    + *
  • color: '#3E576F'
  • + *
+ * + * @param style CSS styles for the subtitle. + * @return A reference to this {@link ChartSubtitle} instance for convenient method chaining. + */ + public ChartSubtitle setStyle(Style style) { + return this.setOption("style", style != null ? style.getOptions() : null); + } + + /** + * Convenience method for setting the 'text' option of the subtitle. Equivalent to: + *

+     *     chartSubtitle.setOption("text", "Sales by Month");
+     * 
+ * The actual text of the axis subtitle. It can contain basic HTML text markup + * like <b>, <i> and spans with style. Defaults to null. + *

+ * Note to disable an axis subtitle from being displayed completely, simply set the text + * to "null". (This can also be accomplished more simply by just setting the subtitle + * text to null directly on the axis via the {@link Axis#setAxisTitleText(String)} method.) + * + * @param text The actual text of the axis subtitle. + * @return A reference to this {@link ChartSubtitle} instance for convenient method chaining. + */ + public ChartSubtitle setText(String text) { + return this.setOption("text", text); + } + + /** + * Convenience method for setting the 'verticalAlign' option of the subtitle. Equivalent to: + *


+     *     chartSubtitle.setOption("verticalAlign", chartSubtitle.VerticalAlign.BOTTOM);
+     * 
+ * The vertical alignment of the subtitle. Can be one of "top", "middle" and "bottom". Defaults to "top". + * Defaults to {@link ChartTitle.VerticalAlign#TOP}. + * + * @param verticalAlign The vertical alignment of the subtitle. + * @return A reference to this {@link ChartSubtitle} instance for convenient method chaining. + */ + public ChartSubtitle setVerticalAlign(ChartTitle.VerticalAlign verticalAlign) { + return this.setOption("verticalAlign", verticalAlign != null ? verticalAlign.toString() : null); + } + + /** + * Convenience method for setting the 'x' position option of the subtitle. Equivalent to: + *

+     *     chartSubtitle.setOption("x", 70);
+     * 
+ * The x position of the subtitle relative to the alignment within the spacing set on the chart + * controlled via {@link Chart#setSpacingLeft(Number)} and {@link Chart#setSpacingRight(Number)}. + * Defaults to 0. + * + * @param x The x position of the subtitle, relative to the chart's spacing. + * @return A reference to this {@link ChartSubtitle} instance for convenient method chaining. + */ + public ChartSubtitle setX(Number x) { + return this.setOption("x", x); + } + + /** + * Convenience method for setting the 'y' position option of the subtitle. Equivalent to: + *

+     *     chartSubtitle.setOption("y", -20);
+     * 
+ * The y position of the subtitle relative to the alignment within the spacing set on the chart + * controlled via {@link Chart#setSpacingTop(Number)} and {@link Chart#setSpacingBottom(Number)}. + * Defaults to 25. + * + * @param y The y position of the subtitle, relative to the chart's spacing. + * @return A reference to this {@link ChartSubtitle} instance for convenient method chaining. + */ + public ChartSubtitle setY(Number y) { + return this.setOption("y", y); + } + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/ChartTitle.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/ChartTitle.java new file mode 100755 index 00000000000..297dea15c5a --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/ChartTitle.java @@ -0,0 +1,234 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +/** + * A configurable class that can be used to represent custom title options for the + * chart, which can then be set the chart (via the {@link Chart#setChartTitle(ChartTitle)} method.) + * Example usage: + *
+ *   chart.setChartTitle(
+ *     new ChartTitle()
+ *       .setText("Sales by Month")
+ *       .setAlign(ChartTitle.Align.MIDDLE)
+ *   );
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class ChartTitle extends Configurable { + + /** + * An enumeration of supported chart title horizontal alignment types, which can be passed to methods + * like {@link ChartTitle#setAlign(ChartTitle.Align)}. + */ + public enum Align { + + /** + * Left align the chart's title + */ + LEFT("left"), + + /** + * Center the chart's title + */ + CENTER("center"), + + /** + * Right align the chart's title + */ + RIGHT("right"); + + private Align(String optionValue) { + this.optionValue = optionValue; + } + + private final String optionValue; + + public String toString() { + return optionValue; + } + + } + + /** + * An enumeration of supported chart title vertical alignment types, which can be passed to methods + * like {@link ChartTitle#setVerticalAlign(ChartTitle.VerticalAlign)}. + */ + public enum VerticalAlign { + + /** + * Show the title at the top of the chart + */ + TOP("top"), + + /** + * Show the title in the middle of the chart + */ + MIDDLE("middle"), + + /** + * Show the title at the bottom of the chart + */ + BOTTOM("bottom"); + + private VerticalAlign(String optionValue) { + this.optionValue = optionValue; + } + + private final String optionValue; + + public String toString() { + return optionValue; + } + + } + + /** + * Convenience method for setting the 'align' option of the title. Equivalent to: + *

+     *     chartTitle.setOption("align", ChartTitle.Align.LEFT);
+     * 
+ * The horizontal alignment of the title. Can be one of "left", "center" and "right". + * Defaults to {@link ChartTitle.Align#CENTER}. + * + * @param align The horizontal alignment of the title. + * @return A reference to this {@link ChartTitle} instance for convenient method chaining. + */ + public ChartTitle setAlign(Align align) { + return this.setOption("align", align != null ? align.toString() : null); + } + + /** + * Convenience method for setting the 'floating' option of the title. Equivalent to: + *

+     *     chartTitle.setOption("floating", true);
+     * 
+ * When the title is floating, the plot area will not move to make space for it. Defaults to false. + * + * @param floating 'true' to float the title above the plot area, or 'false' (the default) to make space for it. + * @return A reference to this {@link ChartTitle} instance for convenient method chaining. + */ + public ChartTitle setFloating(boolean floating) { + return this.setOption("floating", floating); + } + + /** + * Convenience method for setting the 'margin' option of the title. Equivalent to: + *

+     *     chartTitle.setOption("margin", 60);
+     * 
+ * The margin between the title and the plot area, or if a subtitle is present, + * the margin between the subtitle and the plot area. Defaults to 15. + * + * @param margin The margin between the title and the plot area, or if a subtitle is present, + * the margin between the subtitle and the plot area. + * @return A reference to this {@link ChartTitle} instance for convenient method chaining. + */ + public ChartTitle setMargin(Number margin) { + return this.setOption("margin", margin); + } + + /** + * Convenience method for setting the 'style' options of the title. Equivalent to: + *

+     *     chartTitle.setOption("/style/fontWeight", "bold");
+     *     chartTitle.setOption("/style/fontFamily", "serif");
+     *     etc.
+     * 
+ * CSS styles for the title. Use this for font styling, but use {@link #setAlign(org.moxieapps.gwt.highcharts.client.ChartTitle.Align)}, + * {@link #setX(Number)}, and {@link #setY(Number)} for text alignment. Defaults to: + *
    + *
  • color: '#3E576F'
  • + *
  • fontSize: '16px'
  • + *
+ * + * @param style CSS styles for the title. + * @return A reference to this {@link ChartTitle} instance for convenient method chaining. + */ + public ChartTitle setStyle(Style style) { + return this.setOption("style", style != null ? style.getOptions() : null); + } + + /** + * Convenience method for setting the 'text' option of the title. Equivalent to: + *

+     *     chartTitle.setOption("text", "Sales by Month");
+     * 
+ * The actual text of the axis title. It can contain basic HTML text markup + * like <b>, <i> and spans with style. Defaults to null. + *

+ * Note to disable an axis title from being displayed completely, simply set the text + * to "null". (This can also be accomplished more simply by just setting the title + * text to null directly on the axis via the {@link Axis#setAxisTitleText(String)} method.) + * + * @param text The actual text of the axis title. + * @return A reference to this {@link ChartTitle} instance for convenient method chaining. + */ + public ChartTitle setText(String text) { + return this.setOption("text", text); + } + + /** + * Convenience method for setting the 'verticalAlign' option of the title. Equivalent to: + *


+     *     chartTitle.setOption("verticalAlign", ChartTitle.VerticalAlign.BOTTOM);
+     * 
+ * The vertical alignment of the title. Can be one of "top", "middle" and "bottom". Defaults to "top". + * Defaults to {@link ChartTitle.VerticalAlign#TOP}. + * + * @param verticalAlign The vertical alignment of the title. + * @return A reference to this {@link ChartTitle} instance for convenient method chaining. + */ + public ChartTitle setVerticalAlign(VerticalAlign verticalAlign) { + return this.setOption("verticalAlign", verticalAlign != null ? verticalAlign.toString() : null); + } + + /** + * Convenience method for setting the 'x' position option of the title. Equivalent to: + *

+     *     chartTitle.setOption("x", 70);
+     * 
+ * The x position of the title relative to the alignment within the spacing set on the chart + * controlled via {@link Chart#setSpacingLeft(Number)} and {@link Chart#setSpacingRight(Number)}. + * Defaults to 0. + * + * @param x The x position of the title, relative to the chart's spacing. + * @return A reference to this {@link ChartTitle} instance for convenient method chaining. + */ + public ChartTitle setX(Number x) { + return this.setOption("x", x); + } + + /** + * Convenience method for setting the 'y' position option of the title. Equivalent to: + *

+     *     chartTitle.setOption("y", -20);
+     * 
+ * The y position of the title relative to the alignment within the spacing set on the chart + * controlled via {@link Chart#setSpacingTop(Number)} and {@link Chart#setSpacingBottom(Number)}. + * Defaults to 25. + * + * @param y The y position of the title, relative to the chart's spacing. + * @return A reference to this {@link ChartTitle} instance for convenient method chaining. + */ + public ChartTitle setY(Number y) { + return this.setOption("y", y); + } + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Color.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Color.java new file mode 100755 index 00000000000..eaf3f512b4b --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Color.java @@ -0,0 +1,314 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONNumber; +import com.google.gwt.json.client.JSONString; +import com.google.gwt.json.client.JSONValue; + +/** + * Represents a color as either a solid RGB color, an RBG color with an alpha channel, + * or a gradient of colors. Many of the configurable chart objects support setting various + * color options (backgrounds, borders, etc). They all support a simply mechanism for + * setting the color to a standard RGB hex value (such as {@link Chart#setBackgroundColor(String)}. + * However, if they also support alpha channels or gradients an overloaded method will be + * provided that takes a Color instance instead (e.g. {@link Chart#setBackgroundColor(Color)}. + *

+ * Example which sets the background color to a 10% opacity red color: + *


+ * chart.setBackgroundColor(new Color(255, 0, 0, .1));
+ * 
+ *

+ * Example which sets the background color to a linear gradient from white to + * a 50% opaque blue: + *


+ * chart.setBackgroundColor(new Color()
+ *   .setLinearGradient(0.0, 0.0, 1.0, 1.0)
+ *   .addColorStop(0, "#FFFFFF")
+ *   .addColorStop(0, 200, 200, 255, 0.5)
+ * );
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class Color extends Configurable { + + /** + * An empty constructor that can be used when creating a color as a gradient. See the + * {@link #setLinearGradient(double, double, double, double)} and {@link #addColorStop(double, String)} + * methods (and their overloaded variants.) + */ + public Color() { + } + + /** + * Create a color instance specifying the color in standard RGB hex notation (include the "#") + * + * @param rgbHexColor The RGB hex of the color (include the "#"). + */ + public Color(String rgbHexColor) { + value = new JSONString(rgbHexColor); + } + + /** + * Create a color instance specifying the three components of the RGB color separately (will + * result in a color that looks like "rgb(200, 255, 10)". + * + * @param r The red component of the color in the RGB color space (0 to 255) + * @param g The green component of the color in the RGB color space (0 to 255) + * @param b The blue component of the color in the RGB color space (0 to 255) + */ + public Color(int r, int g, int b) { + value = new JSONString(createRGB(r, g, b)); + + } + + /** + * Create a color instance specifying the three components of the RGB color separately as we + * as the alpha channel (will result in a color that looks like "rgb(200, 255, 10, 0.5)". + * + * @param r The red component of the color in the RGB color space (0 to 255) + * @param g The green component of the color in the RGB color space (0 to 255) + * @param b The blue component of the color in the RGB color space (0 to 255) + * @param a The alpha channel of the color (0.0 to 1.0) + */ + public Color(int r, int g, int b, double a) { + value = new JSONString(createRGBA(r, g, b, a)); + } + + private JSONValue value; + + /** + * Sets up this color as a linear gradient from one location in space to another. + * Coordinates can either be provided as whole numbers, in which case they are + * treated as pixels. Or, they can be provided as number with a "%" character on the + * end, in which case they are treated in percentages. E.g. + *

+ *


+     *   color.setLinearGradient("0", "0", "500", "500");
+     * 
+ * Or: + *

+     *   color.setLinearGradient("20%", "20%", "80%", "80%");
+     * 
+ * Note that you can also use the {@link #setLinearGradient(int, int, int, int)} + * version if you know you're only going to be operating in pixels, or the + * {@link #setLinearGradient(double, double, double, double)} if you're only operating + * in percentages. + * + * @param x0 The x-coordinate of the start point of the gradient. + * @param y0 The y-coordinate of the start point of the gradient. + * @param x1 The x-coordinate of the end point of the gradient. + * @param y1 The y-coordinate of the end point of the gradient. + * @return A reference to this {@link Color} instance for convenient method chaining. + */ + public Color setLinearGradient(String x0, String y0, String x1, String y1) { + value = null; + JSONArray coordinates = new JSONArray(); + coordinates.set(0, new JSONString(x0)); + coordinates.set(1, new JSONString(y0)); + coordinates.set(2, new JSONString(x1)); + coordinates.set(3, new JSONString(y1)); + return this.setOption("linearGradient", coordinates); + } + + /** + * Sets up this color as a linear gradient from one location in space to another, specifying + * the coordinates in pixels. + *

+ * Note that you can also use the {@link #setLinearGradient(double, double, double, double)} + * version if you know you instead want to operate in percentages, or the + * {@link #setLinearGradient(String, String, String, String)} version if you need to + * operate in both percentages and pixels concurrently. + * + * @param x0 The x-coordinate of the start point of the gradient (in pixels). + * @param y0 The y-coordinate of the start point of the gradient (in pixels). + * @param x1 The x-coordinate of the end point of the gradient (in pixels). + * @param y1 The y-coordinate of the end point of the gradient (in pixels). + * @return A reference to this {@link Color} instance for convenient method chaining. + */ + public Color setLinearGradient(int x0, int y0, int x1, int y1) { + value = null; + JSONArray coordinates = new JSONArray(); + coordinates.set(0, new JSONNumber(x0)); + coordinates.set(1, new JSONNumber(y0)); + coordinates.set(2, new JSONNumber(x1)); + coordinates.set(3, new JSONNumber(y1)); + return this.setOption("linearGradient", coordinates); + } + + /** + * Sets up this color as a linear gradient from one location in space to another, specifying + * the coordinates in percentages of the space the gradient will fill. Note that the percentage + * is specified by providing a floating point number in the range of 0.0 to 1.0, where 0.0 is + * equivalent to "0%" and 1.0 is equivalent to "100%". + *

+ * Note that you can also use the {@link #setLinearGradient(int, int, int, int)} + * version if you know you instead want to operate in pixels, or the + * {@link #setLinearGradient(String, String, String, String)} version if you need to + * operate in both percentages and pixels concurrently. + * + * @param x0 The x-percentage of the start point of the gradient (0.0 to 1.0) + * @param y0 The y-percentage of the start point of the gradient (0.0 to 1.0) + * @param x1 The x-percentage of the end point of the gradient (0.0 to 1.0) + * @param y1 The y-percentage of the end point of the gradient (0.0 to 1.0) + * @return A reference to this {@link Color} instance for convenient method chaining. + */ + public Color setLinearGradient(double x0, double y0, double x1, double y1) { + value = null; + JSONArray coordinates = new JSONArray(); + coordinates.set(0, new JSONString(((Double) (x0 * 100)).intValue() + "%")); + coordinates.set(1, new JSONString(((Double) (y0 * 100)).intValue() + "%")); + coordinates.set(2, new JSONString(((Double) (x1 * 100)).intValue() + "%")); + coordinates.set(3, new JSONString(((Double) (y1 * 100)).intValue() + "%")); + return this.setOption("linearGradient", coordinates); + } + + private JSONArray colorStops = new JSONArray(); + + /** + * Adds the specified color at some position within the gradient (to be used in + * conjunction with the {@link #setLinearGradient(double, double, double, double)} method + * or another one of its overloaded variants.) + *

+ * Example which sets the background color to a linear gradient from white to blue: + *


+     * chart.setBackgroundColor(new Color()
+     *   .setLinearGradient(0.0, 0.0, 1.0, 1.0)
+     *   .addColorStop(0.0, "#FFFFFF")
+     *   .addColorStop(0.0, "#0000FF")
+     * );
+     * 
+ * Note that this method is intended to be used when you simply want to set the gradient + * stop color to a standard RGB hex value. If you need more control use the + * {@link #addColorStop(double, int, int, int)} or {@link #addColorStop(double, int, int, int, double)} + * method instead. + * + * @param offset A floating point value between 0.0 and 1.0 that represents the position + * between the start and end points in a gradient. + * @param rgbHexColor The RGB hex color that the gradient should display at the given offset (include the "#"). + * @return A reference to this {@link Color} instance for convenient method chaining. + */ + public Color addColorStop(double offset, String rgbHexColor) { + return this.internalAddColorStop(offset, rgbHexColor); + } + + /** + * Adds the specified color at some position within the gradient (to be used in + * conjunction with the {@link #setLinearGradient(double, double, double, double)} method + * or another one of its overloaded variants.) + *

+ * Example which sets the background color to a linear gradient from white to blue: + *


+     * chart.setBackgroundColor(new Color()
+     *   .setLinearGradient(0.0, 0.0, 1.0, 1.0)
+     *   .addColorStop(0.0, 255, 255, 255)
+     *   .addColorStop(0.0, 0, 0, 255)
+     * );
+     * 
+ * Note that this method is intended to be used when you simply want to set the gradient + * stop color to a standard RGB hex value. If you need more control use the + * {@link #addColorStop(double, int, int, int, double)} method instead. + * + * @param offset A floating point value between 0.0 and 1.0 that represents the position + * between the start and end points in a gradient. + * @param r The red component of the color in the RGB color space (0 to 255) + * @param g The green component of the color in the RGB color space (0 to 255) + * @param b The blue component of the color in the RGB color space (0 to 255) + * @return A reference to this {@link Color} instance for convenient method chaining. + */ + public Color addColorStop(double offset, int r, int g, int b) { + return this.internalAddColorStop(offset, createRGB(r, g, b)); + } + + /** + * Adds the specified color at some position within the gradient allowing for the color + * to be specified with an alpha channel (to be used in conjunction with the + * {@link #setLinearGradient(double, double, double, double)} method or another one of its overloaded variants.) + *

+ * Example which sets the background color to a linear gradient from solid white to + * a 50% opaque blue: + *


+     * chart.setBackgroundColor(new Color()
+     *   .setLinearGradient(0.0, 0.0, 1.0, 1.0)
+     *   .addColorStop(0.0, 255, 255, 255)
+     *   .addColorStop(0.0, 0, 0, 255, 0.5)
+     * );
+     * 
+ * + * @param offset A floating point value between 0.0 and 1.0 that represents the position + * between the start and end points in a gradient. + * @param r The red component of the color in the RGB color space (0 to 255) + * @param g The green component of the color in the RGB color space (0 to 255) + * @param b The blue component of the color in the RGB color space (0 to 255) + * @param a The alpha channel of the color (0.0 to 1.0) + * @return A reference to this {@link Color} instance for convenient method chaining. + */ + public Color addColorStop(double offset, int r, int g, int b, double a) { + return this.internalAddColorStop(offset, createRGBA(r, g, b, a)); + } + + /** + * This method will return the value of the object as a single value if it is + * represented as just a solid color or as a JSONObject if it represents a gradient. + * Note that this method is primarily intended for internal use. + * + * @return The value of this object as a single value (if appropriate), or a JSONObject + * if this color represents a gradient. + */ + public JSONValue getOptionValue() { + return value != null ? value : this.getOptions(); + } + + // Internal helper methods + private Color internalAddColorStop(double offset, String color) { + value = null; + JSONArray colorStop = new JSONArray(); + colorStop.set(0, new JSONNumber(offset)); + colorStop.set(1, new JSONString(color)); + colorStops.set(colorStops.size(), colorStop); + return this.setOption("stops", colorStops); + } + + private String createRGB(int r, int g, int b) { + return new StringBuilder() + .append("rgb(") + .append(r) + .append(",") + .append(g) + .append(",") + .append(b) + .append(")").toString(); + } + + private String createRGBA(int r, int g, int b, double a) { + return new StringBuilder() + .append("rgba(") + .append(r) + .append(",") + .append(g) + .append(",") + .append(b) + .append(",") + .append(a) + .append(")").toString(); + } + + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Configurable.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Configurable.java new file mode 100755 index 00000000000..2e2a51c0e4e --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Configurable.java @@ -0,0 +1,148 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +import com.google.gwt.core.client.JavaScriptObject; +import com.google.gwt.json.client.*; + +/** + * A common base class that any of the objects which support configuration options will + * extend to allow the caller to set the options on them. Provides a convenient + * {@link #setOption(String, Object)} method that will allow for a configuration option + * to be set at any level. + * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public abstract class Configurable { + + private JSONObject options; + + /** + * Set an option on the object at any level, using "/" characters to designate which + * level of option you'd like to set. E.g., the following code: + *

+     * Chart chart = new Chart();
+     * chart.setOption("/chart/type", "spline");
+     * chart.setOption("/chart/marginRight", 10);
+     * chart.setOption("/title/text", "Nice Chart");
+     * 
+ * Would result in initializing HighCharts like the following: + *

+     * new HighCharts.Chart({
+     *     chart: {
+     *         type: "spline",
+     *         marginRight: 10
+     *     },
+     *     title: {
+     *         text: "Nice Chart"
+     *     }
+     * });
+     * 
+ * Note that the beginning "/" is optional, so chart.setOption("/thing", "piglet") is + * equivalent to chart.setOption("thing", "piglet"). + *

+ * For details on available options see the Highcharts reference. + *

+ * Note that, when possible, you'll ideally want to use one of the available type specific setter + * methods instead of this general method. E.g. instead of doing this: + *


+     * series.setOption("type", "spline");
+     * 
+ * Do this instead: + *

+     * series.setType(Series.Type.SPLINE);
+     * 
+ * + * @param path The path to the option to set (e.g. "/title/text"); + * @param value The value to set for the option (can be a String, Number, Boolean, or JSONObject) + * @return A reference to this {@link Configurable} instance for convenient method chaining. + */ + public T setOption(String path, Object value) { + if (options == null) { + options = new JSONObject(); + } + setOption(options, path, value); + @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"}) + final T instance = (T) this; + return instance; + } + + /** + * Retrieve all of the options that have been configured for this instance + * as a JSONObject. + * + * @return A JSONObject representing all of the configuration options + * that have been set on the instance (will be null if no options have been set) + */ + public JSONObject getOptions() { + return options; + } + + // Internal... + private void setOption(JSONObject rootObject, String path, Object value) { + if (path == null) { + return; + } + if (path.startsWith("/")) { + path = path.substring(1); + } + if (path.length() <= 0) { + return; + } + String nodeName = path; + if (nodeName.contains("/")) { + nodeName = nodeName.substring(0, nodeName.indexOf("/")); + JSONValue objectAsValue = rootObject.get(nodeName); + if (objectAsValue == null || objectAsValue.isObject() == null) { + rootObject.put(nodeName, new JSONObject()); + } + JSONObject object = (JSONObject) rootObject.get(nodeName); + setOption(object, path.substring(path.indexOf("/") + 1), value); + } else { + rootObject.put(nodeName, convertToJSONValue(value)); + } + } + + private JSONValue convertToJSONValue(Object value) { + if (value == null) { + return JSONNull.getInstance(); + } else if(value instanceof JSONValue) { + return (JSONValue)value; + } if (value instanceof Boolean) { + return JSONBoolean.getInstance((Boolean) value); + } else if (value instanceof Number) { + return new JSONNumber(((Number) value).doubleValue()); + } else if (value instanceof String) { + return new JSONString((String) value); + } else if (value instanceof JavaScriptObject) { + return new JSONObject((JavaScriptObject)value); + } else if (value instanceof Configurable) { + return ((Configurable)value).getOptions(); + } else if (value.getClass().isArray()) { + JSONArray jsonArray = new JSONArray(); + Object[] valueArray = (Object[]) value; + for (int i = 0, valueArrayLength = valueArray.length; i < valueArrayLength; i++) { + Object arrayValue = valueArray[i]; + jsonArray.set(i, convertToJSONValue(arrayValue)); + } + return jsonArray; + } + return null; + } + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Credits.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Credits.java new file mode 100755 index 00000000000..f292d2923dc --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Credits.java @@ -0,0 +1,230 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +/** + * A configurable class that can be used to represent custom credits options for the + * chart, which can then be set on the chart (via the {@link Chart#setCredits(Credits)} method.) + * Highchart by default puts a credits label in the lower right corner of the chart. + * This can be changed using these options. Example usage: + *
+ *   chart.setCredits(
+ *     new Credits()
+ *       .setText("Presented by Snoopy")
+ *       .setHref("http://www.peanuts.com/")
+ *   );
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class Credits extends Configurable { + + /** + * An enumeration of supported credits horizontal alignment types, which can be passed to methods + * like {@link Credits#setAlign(Credits.Align)} method. + */ + public enum Align { + + /** + * Left align the credits + */ + LEFT("left"), + + /** + * Center the credits + */ + CENTER("center"), + + /** + * Right align the credits + */ + RIGHT("right"); + + private Align(String optionValue) { + this.optionValue = optionValue; + } + + private final String optionValue; + + public String toString() { + return optionValue; + } + + } + + /** + * An enumeration of supported credits vertical alignment types, which can be passed to methods + * like {@link Credits#setVerticalAlign(Credits.VerticalAlign)} method. + */ + public enum VerticalAlign { + + /** + * Show the credits at the top of the chart + */ + TOP("top"), + + /** + * Show the credits in the middle of the chart + */ + MIDDLE("middle"), + + /** + * Show the credits at the bottom of the chart + */ + BOTTOM("bottom"); + + private VerticalAlign(String optionValue) { + this.optionValue = optionValue; + } + + private final String optionValue; + + public String toString() { + return optionValue; + } + + } + + /** + * Convenience method for setting the 'align' option of the credits. Equivalent to: + *

+     *     credits.setOption("/position/align", Credit.Align.LEFT);
+     * 
+ * The horizontal alignment of the credits text within the chart area. Can be one of "left", "center" and "right". + * Defaults to {@link Credits.Align#RIGHT}. + * + * @param align The horizontal alignment of the credits text within the chart area. + * @return A reference to this {@link Credits} instance for convenient method chaining. + */ + public Credits setAlign(Align align) { + return this.setOption("/position/align", align != null ? align.toString() : null); + } + + /** + * Convenience method for setting the 'enabled' option for the credits. Equivalent to: + *

+     *     credits.setOption("enabled", true);
+     * 
+ * Whether to show the credits text. Defaults to true. + * + * @param enabled Whether or not to enable or disable the credits text. + * @return A reference to this {@link Credits} instance for convenient method chaining. + */ + public Credits setEnabled(boolean enabled) { + return this.setOption("enabled", enabled); + } + + /** + * Convenience method for setting the 'href' option of the credits. Equivalent to: + *

+     *     credits.setOption("href", "http://www.peanuts.com/");
+     * 
+ * The URL for the credits label. Defaults to "http://www.highcharts.com". + * + * @param href The URL for the credits label. + * @return A reference to this {@link Credits} instance for convenient method chaining. + */ + public Credits setHref(String href) { + return this.setOption("href", href); + } + + /** + * Convenience method for setting the 'style' options of the credits. Equivalent to: + *

+     *     credits.setOption("/style/fontWeight", "bold");
+     *     credits.setOption("/style/fontFamily", "serif");
+     *     etc.
+     * 
+ * CSS styles for the credits label. . Defaults to: + *
    + *
  • cursor: 'pointer'
  • + *
  • color: '#909090'
  • + *
  • fontSize: '10px'
  • + *
+ * + * @param style An object containing the style properties to set on the credits. + * @return A reference to this {@link Credits} instance for convenient method chaining. + */ + public Credits setStyle(Style style) { + return this.setOption("style", style != null ? style.getOptions() : null); + } + + /** + * Convenience method for setting the 'text' option of the credits. Equivalent to: + *

+     *     credits.setOption("text", "Thanks to Snoopy");
+     * 
+ * The text for the credits label. Defaults to "Highcharts.com". + * + * @param text The text for the credits label. + * @return A reference to this {@link Credits} instance for convenient method chaining. + */ + public Credits setText(String text) { + return this.setOption("text", text); + } + + /** + * Convenience method for setting the 'verticalAlign' option of the credits. Equivalent to: + *

+     *     legend.setOption("/position/verticalAlign", Credits.VerticalAlign.BOTTOM);
+     * 
+ * The vertical alignment of the legend box. Can be one of "top", "middle" or "bottom". + * Vertical position can be further determined by the y option. + * Defaults to {@link Legend.VerticalAlign#BOTTOM}. + * + * @param verticalAlign The vertical alignment of the credits. + * @return A reference to this {@link Credits} instance for convenient method chaining. + */ + public Credits setVerticalAlign(VerticalAlign verticalAlign) { + return this.setOption("/position/verticalAlign", verticalAlign != null ? verticalAlign.toString() : null); + } + + /** + * Convenience method for setting the 'x' position option of the credits. Equivalent to: + *

+     *     legend.setOption("/position/x", 70);
+     * 
+ * The x offset of the credits relative to it's horizontal alignment align within + * {@link Chart#setSpacingLeft(Number)} and {@link Chart#setSpacingRight(Number)}. Negative x + * moves it to the left, positive x moves it to the right. The default value of -10 together + * with {@link Align#RIGHT} puts it near the right side of the plot area. Defaults to -10. + * + * @param x The x offset of the credits, relative to the chart's spacing. + * @return A reference to this {@link Credits} instance for convenient method chaining. + */ + public Credits setX(Number x) { + return this.setOption("/position/x", x); + } + + /** + * Convenience method for setting the 'y' position option of the credits. Equivalent to: + *

+     *     legend.setOption("/position/y", -20);
+     * 
+ * The vertical offset of the legend relative to it's vertical alignment (@link VerticalAlign} + * within {@link Chart#setSpacingTop(Number)} and {@link Chart#setSpacingBottom(Number)}. + * Negative y moves it up, positive y moves it down. Defaults to -5. + * + * @param y The y position of the credits, relative to the chart's spacing. + * @return A reference to this {@link Credits} instance for convenient method chaining. + */ + public Credits setY(Number y) { + return this.setOption("/position/y", y); + } + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/DateTimeLabelFormats.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/DateTimeLabelFormats.java new file mode 100755 index 00000000000..cdce9258741 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/DateTimeLabelFormats.java @@ -0,0 +1,165 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +/** + * Represents the configuration options available for controlling the way date and time information + * will be displayed. For a datetime axis, the scale will automatically adjust to the appropriate unit. This configuration + * class controls the default string format representations used for each unit. Defaults to: + *
    + *
  • second: '%H:%M:%S'
  • + *
  • minute: '%H:%M'
  • + *
  • hour: '%H:%M'
  • + *
  • day: '%e. %b'
  • + *
  • week: '%e. %b'
  • + *
  • month: '%b \'%y'
  • + *
  • year: '%Y
  • + *
+ * Available replacement codes for the day of date are: + *
    + *
  • 'a': Short weekday, like 'Mon'
  • + *
  • 'A': Long weekday, like 'Monday'
  • + *
  • 'd': Two digit day of the month, 01 to 31
  • + *
  • 'e': Day of the month, 1 through 31
  • + *
+ * Available replacement codes for the month of the date are: + *
    + *
  • 'b': Short month, like 'Jan'
  • + *
  • 'B': Long month, like 'January'
  • + *
  • 'm': Two digit month number, 01 through 12
  • + *
+ * Available replacement codes for the year of the date are: + *
    + *
  • 'y': Two digits year, like 09 for 2009
  • + *
  • 'Y': Four digits year, like 2009
  • + *
+ * Available replacement codes for the time portions are: + *
    + *
  • 'H': Two digits hours in 24h format, 00 through 23
  • + *
  • 'I': Two digits hours in 12h format, 00 through 11
  • + *
  • 'l': Hours in 12h format, 1 through 12
  • + *
  • 'M': Two digits minutes, 00 through 59
  • + *
  • 'p': Upper case AM or PM
  • + *
  • 'P': Lower case AM or PM
  • + *
  • 'S': Two digits seconds, 00 through 59
  • + *
+ * Example usage: + *
+ *   axis.setDateTimeLabelFormats(
+ *     new DateTimeLabelFormats()
+ *       .setHour("%I %p")
+ *       .setMinute("%I:%M %p")
+ *   );
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class DateTimeLabelFormats extends Configurable { + + /** + * Convenience method for setting the 'second' format. Equivalent to: + *

+     *     dateTimeLabelFormats.setOption("second", "%H:%M:%S");
+     * 
+ * + * @param second The format to use when displaying labels in units of seconds. + * @return A reference to this {@link DateTimeLabelFormats} instance for convenient method chaining. + */ + public DateTimeLabelFormats setSecond(String second) { + return this.setOption("second", second); + } + + /** + * Convenience method for setting the 'minute' format. Equivalent to: + *

+     *     dateTimeLabelFormats.setOption("minute", "%H:%M");
+     * 
+ * + * @param minute The format to use when displaying labels in units of minutes. + * @return A reference to this {@link DateTimeLabelFormats} instance for convenient method chaining. + */ + public DateTimeLabelFormats setMinute(String minute) { + return this.setOption("minute", minute); + } + + /** + * Convenience method for setting the 'hour' format. Equivalent to: + *

+     *     dateTimeLabelFormats.setOption("hour", "%H:%M");
+     * 
+ * + * @param hour The format to use when displaying labels in units of hours. + * @return A reference to this {@link DateTimeLabelFormats} instance for convenient method chaining. + */ + public DateTimeLabelFormats setHour(String hour) { + return this.setOption("hour", hour); + } + + /** + * Convenience method for setting the 'day' format. Equivalent to: + *

+     *     dateTimeLabelFormats.setOption("day", "%e. %b");
+     * 
+ * + * @param day The format to use when displaying labels in units of days. + * @return A reference to this {@link DateTimeLabelFormats} instance for convenient method chaining. + */ + public DateTimeLabelFormats setDay(String day) { + return this.setOption("day", day); + } + + /** + * Convenience method for setting the 'week' format. Equivalent to: + *

+     *     dateTimeLabelFormats.setOption("week", "%e. %b");
+     * 
+ * + * @param week The format to use when displaying labels in units of weeks. + * @return A reference to this {@link DateTimeLabelFormats} instance for convenient method chaining. + */ + public DateTimeLabelFormats setWeek(String week) { + return this.setOption("week", week); + } + + /** + * Convenience method for setting the 'month' format. Equivalent to: + *

+     *     dateTimeLabelFormats.setOption("month", "%b \'%y");
+     * 
+ * + * @param month The format to use when displaying labels in units of month. + * @return A reference to this {@link DateTimeLabelFormats} instance for convenient method chaining. + */ + public DateTimeLabelFormats setMonth(String month) { + return this.setOption("month", month); + } + + /** + * Convenience method for setting the 'year' format. Equivalent to: + *

+     *     dateTimeLabelFormats.setOption("year", "%Y");
+     * 
+ * + * @param year The format to use when displaying labels in units of year. + * @return A reference to this {@link DateTimeLabelFormats} instance for convenient method chaining. + */ + public DateTimeLabelFormats setYear(String year) { + return this.setOption("year", year); + } + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Exporting.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Exporting.java new file mode 100755 index 00000000000..22888ef1f19 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Exporting.java @@ -0,0 +1,132 @@ +package org.moxieapps.gwt.highcharts.client; + +/** + * A configurable class that will allow you to control the options for exporting module. An instance of + * this class can be constructed and then set on the chart via the + * {@link BaseChart#setExporting(Exporting)} method. + *

+ * Note that the "exporting" module must be included in the page in order for the exporting + * navigation options to apply. E.g.: + *

+ * <script type="text/javascript" src="js/modules/exporting.js"></script> + * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.1.0 + */ +public class Exporting extends Configurable { + + /** + * An enumeration of supported exporting file types, which can be passed to the + * {@link Exporting#setType(Exporting.Type)} method. + */ + public enum Type { + + /** + * Portable Network Graphics file type + */ + PNG("image/png"), + + /** + * Joint Photographic Experts Group file type + */ + JPEG("image/jpeg"), + + /** + * Portable Document Format file type + */ + PDF("application/pdf"), + + /** + * Scalable Vector Graphics file type + */ + SVG("image/svg+xml"); + + private Type(String optionValue) { + this.optionValue = optionValue; + } + + private final String optionValue; + + public String toString() { + return optionValue; + } + + } + + // TODO: Add buttons configuration methods + + /** + * Convenience method for setting the 'enabled' option for the exporting module. Equivalent to: + *


+     *     exporting.setOption("enabled", true);
+     * 
+ * Whether to enable the exporting module. Defaults to true, but note that the exporting module + * Javascript file must be included in the source of the page in order for the exporting + * functionality to appear. + * + * @param enabled Whether or not to enable or disable the exporting module for the chart. + * @return A reference to this {@link Exporting} instance for convenient method chaining. + */ + public Exporting setEnabled(boolean enabled) { + return this.setOption("enabled", enabled); + } + + /** + * Convenience method for setting the 'filename' option for the exporting module. Equivalent to: + *

+     *     exporting.setOption("filename", true);
+     * 
+ * The filename, without extension, to use for the exported chart. Defaults to "chart". + * + * @param fileName The filename, without extension, to use for the exported chart. + * @return A reference to this {@link Exporting} instance for convenient method chaining. + */ + public Exporting setFilename(String fileName) { + return this.setOption("fileName", fileName); + } + + /** + * Convenience method for setting the 'type' option for the exporting module. Equivalent to: + *

+     *     exporting.setOption("type", "image/jpeg");
+     * 
+ * Default MIME type for exporting if chart.exportChart() is called without specifying a type option. + * Possible values are image/png, image/jpeg, application/pdf and image/svg+xml. Defaults to "image/png". + * + * @param type The default file format that exported charts should be created as. + * @return A reference to this {@link Exporting} instance for convenient method chaining. + */ + public Exporting setType(Type type) { + return this.setOption("type", type != null ? type.toString() : null); + } + + /** + * Convenience method for setting the 'url' option for the exporting module. Equivalent to: + *

+     *     exporting.setOption("url", "http://export.highcharts.com");
+     * 
+ * The URL for the server module converting the SVG string to an image format. By default this + * points to Highslide Software's free web service. Defaults to http://export.highcharts.com. + * + * @param url The URL for the server module converting the SVG string to an image format. + * @return A reference to this {@link Exporting} instance for convenient method chaining. + */ + public Exporting setUrl(String url) { + return this.setOption("url", url); + } + + /** + * Convenience method for setting the 'width' option for the exporting module. Equivalent to: + *

+     *     exporting.setOption("width", 600);
+     * 
+ * The pixel width of charts exported to PNG or JPG. Defaults to 800. + * + * @param width The pixel width of charts exported to PNG or JPG. + * @return A reference to this {@link Exporting} instance for convenient method chaining. + */ + public Exporting setWidth(Number width) { + return this.setOption("width", width); + } + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Extremes.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Extremes.java new file mode 100755 index 00000000000..9efc14f13a5 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Extremes.java @@ -0,0 +1,93 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +/** + * A simple value object that is used to report the current extremes of an axis whenever + * the {@link Axis#getExtremes()} method is invoked (normally after the chart has been rendered). + * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class Extremes { + + private Number dataMax; + private Number dataMin; + private Number max; + private Number min; + + /** + * Use the {@link Axis#getExtremes()} method to gain + * access to 'Extremes' instance associated with the chart axis. + * + * @param dataMin The minimum value of the axis' associated series. + * @param dataMax The maximum value of the axis' associated series. + * @param min The minimum axis value, either automatic or set manually. + * @param max The maximum axis value, either automatic or set manually. + */ + Extremes(Number dataMin, Number dataMax, Number min, Number max) { + this.dataMin = dataMin; + this.dataMax = dataMax; + this.min = min; + this.max = max; + } + + /** + * Return the minimum value of the axis' associated series, or null if the extremes + * are requested before the chart has been rendered. + * + * @return The maximum value of the axis' associated series. + */ + public Number getDataMin() { + return dataMin; + } + + /** + * Return the maximum value of the axis' associated series, or null if the extremes + * are requested before the chart has been rendered. + * + * @return The maximum value of the axis' associated series. + */ + public Number getDataMax() { + return dataMax; + } + + /** + * Return the minimum axis value, either automatic or set manually. If the max option + * is not set and minPadding is 0, this value will be the same as {@link #getDataMin()}. Will + * return null if the extremes are requested before the chart has been rendered and + * no manual minimum has been set via {@link Axis#setMin(Number)}. + * + * @return The minimum axis value, either automatic or set manually. + */ + public Number getMin() { + return min; + } + + /** + * Return the maximum axis value, either automatic or set manually. If the max option + * is not set and maxPadding is 0, this value will be the same as {@link #getDataMax()}. Will + * return null if the extremes are requested before the chart has been rendered and + * no manual maximum has been set via {@link Axis#setMax(Number)}. + * + * @return The maximum axis value, either automatic or set manually. + */ + public Number getMax() { + return max; + } + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/LabelItem.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/LabelItem.java new file mode 100755 index 00000000000..ea36de02d7f --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/LabelItem.java @@ -0,0 +1,86 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +/** + * A simple configurable object that can be used to position arbitrary HTML labels + * anywhere in the chart area. After creating a LabelItem it can then be added to the + * chart via the {@link Chart#setLabelItems(LabelItem...)} method. Example usage: + *
+ * chart.setLabelItems(
+ *    new LabelItem()
+ *      .setHtml("United States")
+ *      .setStyle(new Style()
+ *         .setColor("#FF0000")
+ *         .setTop("10px")
+ *         .setLeft("10px")
+ *      ),
+ *    new LabelItem()
+ *      .setHtml("Europe")
+ *      .setStyle(new Style()
+ *         .setColor("#0000FF")
+ *         .setTop("10px")
+ *         .setLeft("210px")
+ *      ),
+ * );
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class LabelItem extends Configurable { + + /** + * Convenience method for setting the 'html' option of the label item. Equivalent to: + *

+     *     labelItem.setOption("html", "Australia");
+     * 
+ * Inner HTML or text for the label. Defaults to "". + * + * @param html Inner HTML or text for the label. + * @return A reference to this {@link LabelItem} instance for convenient method chaining. + */ + public LabelItem setHtml(String html) { + return this.setOption("html", html); + } + + /** + * Convenience method for setting the 'style' options of the label item. Equivalent to: + *

+     *     labelItem.setOption("/style/left", "100px");
+     *     labelItem.setOption("/style/top", "10px");
+     *     etc.
+     * 
+ * CSS styles for each label. To position the label, use left and top like this: + *

+     *    new LabelItem()
+     *      .setHtml("Antarctica")
+     *      .setStyle(new Style()
+     *         .setColor("#0000FF")
+     *         .setTop("10px")
+     *         .setLeft("100px")
+     *      )
+     * 

+ *

+ * + * @param style CSS styles for each label + * @return A reference to this {@link LabelItem} instance for convenient method chaining. + */ + public LabelItem setStyle(Style style) { + return this.setOption("style", style != null ? style.getOptions() : null); + } +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Lang.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Lang.java new file mode 100755 index 00000000000..3bdb13d82a6 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Lang.java @@ -0,0 +1,13 @@ +package org.moxieapps.gwt.highcharts.client; + +/** + * TODO + * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class Lang { + + // TODO + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Legend.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Legend.java new file mode 100755 index 00000000000..14181eb8742 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Legend.java @@ -0,0 +1,478 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +/** + * A configurable class that can be used to represent custom legend options for the + * chart, which can then be set on the chart (via the {@link Chart#setLegend(Legend)} method.) + * The legend is a box containing a symbol and name for each series item or point item in the chart. + * Example usage: + *
+ *   chart.setLegend(
+ *     new Legend()
+ *       .setBorderColor("#CC0000")
+ *       .setLayout(Legend.Layout.HORIZONTAL)
+ *   );
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class Legend extends Configurable { + + /** + * An enumeration of supported legend horizontal alignment types, which can be passed to methods + * like {@link Legend#setAlign(Legend.Align)} method. + */ + public enum Align { + + /** + * Left align the legend + */ + LEFT("left"), + + /** + * Center the legend + */ + CENTER("center"), + + /** + * Right align the legend + */ + RIGHT("right"); + + private Align(String optionValue) { + this.optionValue = optionValue; + } + + private final String optionValue; + + public String toString() { + return optionValue; + } + + } + + /** + * An enumeration of supported legend vertical alignment types, which can be passed to methods + * like {@link Legend#setVerticalAlign(Legend.VerticalAlign)} method. + */ + public enum VerticalAlign { + + /** + * Show the legend at the top of the chart + */ + TOP("top"), + + /** + * Show the legend in the middle of the chart + */ + MIDDLE("middle"), + + /** + * Show the legend at the bottom of the chart + */ + BOTTOM("bottom"); + + private VerticalAlign(String optionValue) { + this.optionValue = optionValue; + } + + private final String optionValue; + + public String toString() { + return optionValue; + } + + } + + /** + * An enumeration of supported legend layout types, which can be passed to methods + * like {@link Legend#setLayout(Layout)} method. + */ + public enum Layout { + + /** + * Lay the legend items out in a horizontal row + */ + HORIZONTAL("horizontal"), + + /** + * Lay the legend items out in a vertical stack + */ + VERTICAL("vertical"); + + private Layout(String optionValue) { + this.optionValue = optionValue; + } + + private final String optionValue; + + public String toString() { + return optionValue; + } + + } + + /** + * Convenience method for setting the 'align' option of the legend. Equivalent to: + *

+     *     legend.setOption("align", Legend.Align.LEFT);
+     * 
+ * The horizontal alignment of the legend box within the chart area. Can be one of "left", "center" and "right". + * Defaults to {@link Legend.Align#CENTER}. + * + * @param align The horizontal alignment of the legend box within the chart area. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setAlign(Align align) { + return this.setOption("align", align != null ? align.toString() : null); + } + + /** + * Convenience method for setting the 'backgroundColor' option of the legend. Equivalent to: + *

+     *     legend.setOption("backgroundColor", "#CCCCCC");
+     * 
+ * The background color of the legend, filling the rounded corner border. Defaults to null. + * + * @param backgroundColor The value to set as the 'backgroundColor' option on the legend. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setBackgroundColor(String backgroundColor) { + return this.setOption("backgroundColor", backgroundColor); + } + + /** + * Convenience method for setting the 'borderColor' option of the legend. Equivalent to: + *

+     *     legend.setOption("borderColor", "#CCCCCC");
+     * 
+ * The color of the drawn border around the legend. Defaults to #909090. + * + * @param borderColor The color of the drawn border around the legend. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setBorderColor(String borderColor) { + return this.setOption("borderColor", borderColor); + } + + /** + * Convenience method for setting the 'borderRadius' option of the legend. Equivalent to: + *

+     *     legend.setOption("borderRadius", 8);
+     * 
+ * The border corner radius of the legend. Defaults to 5. + * + * @param borderRadius The border corner radius of the legend. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setBorderRadius(Number borderRadius) { + return this.setOption("borderRadius", borderRadius); + } + + /** + * Convenience method for setting the 'borderWidth' option of the legend. Equivalent to: + *

+     *     legend.setOption("borderWidth", 3);
+     * 
+ * The width of the drawn border around the legend. Defaults to 1. + * + * @param borderWidth The width of the drawn border around the legend. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setBorderWidth(Number borderWidth) { + return this.setOption("borderWidth", borderWidth); + } + + /** + * Convenience method for setting the 'floating' option of the legend. Equivalent to: + *

+     *     legend.setOption("floating", true);
+     * 
+ * When the legend is floating, the plot area ignores it and is allowed to be placed below it. Defaults to false. + * + * @param floating 'true' to float the legend above the plot area, or 'false' (the default) to make space for it. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setFloating(boolean floating) { + return this.setOption("floating", floating); + } + + /** + * Convenience method for setting the 'enabled' option for the legend. Equivalent to: + *

+     *     legend.setOption("enabled", true);
+     * 
+ * Enable or disable the legend. Defaults to true. + * + * @param enabled Whether or not to enable or disable the legend. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setEnabled(boolean enabled) { + return this.setOption("enabled", enabled); + } + + /** + * Convenience method for setting the 'itemHiddenStyle' options of the legend. Equivalent to: + *

+     *     legend.setOption("/itemHiddenStyle/fontWeight", "bold");
+     *     legend.setOption("/itemHiddenStyle/fontFamily", "serif");
+     *     etc.
+     * 
+ * CSS styles for each legend item when the corresponding series or point is hidden. Properties are inherited + * from {@link #setStyle(Style)} unless overridden here. Defaults to: + *
    + *
  • color: '#CCC'
  • + *
+ * + * @param itemHiddenStyle CSS styles for each legend item when the corresponding series or point is hidden. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setItemHiddenStyle(Style itemHiddenStyle) { + return this.setOption("itemHiddenStyle", itemHiddenStyle != null ? itemHiddenStyle.getOptions() : null); + } + + /** + * Convenience method for setting the 'itemHoverStyle' options of the legend. Equivalent to: + *

+     *     legend.setOption("/itemHoverStyle/fontWeight", "bold");
+     *     legend.setOption("/itemHoverStyle/fontFamily", "serif");
+     *     etc.
+     * 
+ * CSS styles for each legend item in hover mode. Properties are inherited from {@link #setStyle(Style)} + * unless overridden here. Defaults to: + *
    + *
  • color: '#000'
  • + *
+ * + * @param itemHoverStyle CSS styles for each legend item in hover mode. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setItemHoverStyle(Style itemHoverStyle) { + return this.setOption("itemHoverStyle", itemHoverStyle != null ? itemHoverStyle.getOptions() : null); + } + + /** + * Convenience method for setting the 'itemStyle' options of the legend. Equivalent to: + *

+     *     legend.setOption("/itemStyle/fontWeight", "bold");
+     *     legend.setOption("/itemStyle/fontFamily", "serif");
+     *     etc.
+     * 
+ * CSS styles for each legend item. Defaults to: + *
    + *
  • cursor: 'pointer'
  • + *
  • color: '#3E576F'
  • + *
+ * + * @param itemStyle CSS styles for each legend item. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setItemStyle(Style itemStyle) { + return this.setOption("itemStyle", itemStyle != null ? itemStyle.getOptions() : null); + } + + /** + * Convenience method for setting the 'itemWidth' option of the legend. Equivalent to: + *

+     *     legend.setOption("itemWidth", 150);
+     * 
+ * The width for each legend item. This is useful in a horizontal layout with many items + * when you want the items to align vertically. Defaults to null. + * + * @param itemWidth The width for each legend item, or null to automatically calculate. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setItemWidth(Number itemWidth) { + return this.setOption("itemWidth", itemWidth); + } + + /** + * Convenience method for setting the 'layout' option of the legend. Equivalent to: + *

+     *     legend.setOption("layout", Layout.VERTICAL);
+     * 
+ * The layout of the legend items. Can be one of "horizontal" or "vertical". + * Defaults to {@link Layout#HORIZONTAL}. + * + * @param layout The layout of the legend items. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setLayout(Layout layout) { + return this.setOption("layout", layout != null ? layout.toString() : null); + } + + // TODO: Add label formatter + + /** + * Convenience method for setting the 'margin' option of the legend. Equivalent to: + *

+     *     legend.setOption("margin", 60);
+     * 
+ * If the plot area sized is calculated automatically and the legend is not floating, the + * legend margin is the space between the legend and the axis labels or plot area. Defaults to 15. + * + * @param margin The space between the legend and the axis labels or plot area. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setMargin(Number margin) { + return this.setOption("margin", margin); + } + + /** + * Convenience method for setting the 'reversed' option of the legend. Equivalent to: + *

+     *     legend.setOption("reversed", true);
+     * 
+ * Whether to reverse the order of the legend items compared to the order of the series + * or points as defined in the configuration object. Defaults to false. + * + * @param reversed 'true' to reverse the order of the legend items. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setReversed(boolean reversed) { + return this.setOption("reversed", reversed); + } + + /** + * Convenience method for setting the 'shadow' option of the legend. Equivalent to: + *

+     *     legend.setOption("shadow", true);
+     * 
+ * Whether to apply a drop shadow to the legend. A {@link #setBackgroundColor(String)} + * also needs to be applied for this to take effect. Defaults to false. + * + * @param shadow 'true' to apply a drop shadow to the legend. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setShadow(boolean shadow) { + return this.setOption("shadow", shadow); + } + + /** + * Convenience method for setting the 'style' options of the legend. Equivalent to: + *

+     *     legend.setOption("/style/fontWeight", "bold");
+     *     legend.setOption("/style/fontFamily", "serif");
+     *     etc.
+     * 
+ * CSS styles for the legend area. In the 1.x versions the position of the legend area was + * determined by CSS. In 2.x, the position is determined by properties like + * {@link #setAlign(org.moxieapps.gwt.highcharts.client.Legend.Align)}, + * {@link #setVerticalAlign(org.moxieapps.gwt.highcharts.client.Legend.VerticalAlign)}, + * {@link #setX(Number)} and {@link #setY(Number)}, but the styles are still parsed for backwards compatibility. + * + * @param style CSS styles for the legend area. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setStyle(Style style) { + return this.setOption("style", style != null ? style.getOptions() : null); + } + + /** + * Convenience method for setting the 'symbolPadding' option of the legend. Equivalent to: + *

+     *     legend.setOption("symbolPadding", 4);
+     * 
+ * The pixel padding between the legend item symbol and the legend item text. Defaults to 5. + * + * @param symbolPadding The pixel padding between the legend item symbol and the legend item text. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setSymbolPadding(Number symbolPadding) { + return this.setOption("symbolPadding", symbolPadding); + } + + /** + * Convenience method for setting the 'symbolWidth' option of the legend. Equivalent to: + *

+     *     legend.setOption("symbolWidth", 40);
+     * 
+ * The pixel width of the legend item symbol. Defaults to 30. + * + * @param symbolWidth The pixel width of the legend item symbol. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setSymbolWidth(Number symbolWidth) { + return this.setOption("symbolWidth", symbolWidth); + } + + /** + * Convenience method for setting the 'verticalAlign' option of the legend. Equivalent to: + *

+     *     legend.setOption("verticalAlign", Legend.VerticalAlign.BOTTOM);
+     * 
+ * The vertical alignment of the legend box. Can be one of "top", "middle" or "bottom". + * Vertical position can be further determined by the y option. + * Defaults to {@link Legend.VerticalAlign#BOTTOM}. + * + * @param verticalAlign The vertical alignment of the legend. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setVerticalAlign(VerticalAlign verticalAlign) { + return this.setOption("verticalAlign", verticalAlign != null ? verticalAlign.toString() : null); + } + + /** + * Convenience method for setting the 'width' option of the legend. Equivalent to: + *

+     *     legend.setOption("width", 150);
+     * 
+ * The width of the legend box, not including and padding set on the style. Defaults to null. + * + * @param width The width of the legend box (not including padding). + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setWidth(Number width) { + return this.setOption("width", width); + } + + /** + * Convenience method for setting the 'x' position option of the legend. Equivalent to: + *

+     *     legend.setOption("x", 70);
+     * 
+ * The x offset of the legend relative to it's horizontal alignment align within + * {@link Chart#setSpacingLeft(Number)} and {@link Chart#setSpacingRight(Number)}. Negative x + * moves it to the left, positive x moves it to the right. The default value of 15 together + * with {@link Align#CENTER} puts it in the center of the plot area. Defaults to 15. + * + * @param x The x offset of the legend, relative to the chart's spacing. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setX(Number x) { + return this.setOption("x", x); + } + + /** + * Convenience method for setting the 'y' position option of the legend. Equivalent to: + *

+     *     legend.setOption("y", -20);
+     * 
+ * The vertical offset of the legend relative to it's vertical alignment (@link VerticalAlign} + * within {@link Chart#setSpacingTop(Number)} and {@link Chart#setSpacingBottom(Number)}. + * Negative y moves it up, positive y moves it down. Defaults to 0. + * + * @param y The y position of the legend, relative to the chart's spacing. + * @return A reference to this {@link Legend} instance for convenient method chaining. + */ + public Legend setY(Number y) { + return this.setOption("y", y); + } + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Loading.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Loading.java new file mode 100755 index 00000000000..28362620933 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Loading.java @@ -0,0 +1,116 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +/** + * A configurable class that can be used to represent custom loading options for the + * chart, which can then be set on the chart (via the {@link Chart#setLoading(Loading)} method.) + * The loading options control the appearance of the loading screen that covers the plot area + * on chart operations. This screen only appears after an explicit call to + * {@link Chart#showLoading(String)}. It is a utility for developers to communicate to + * the end user that something is going on, for example while retrieving new data via GWT remoting + * requests. The "Loading..." text itself is not part of this configuration object, but part of + * the {@link Lang} object. + * Example usage: + *
+ *   chart.setLoading(
+ *     new Loading()
+ *       .setShowDuration(500)
+ *       .setStyle(
+ *           new Style()
+ *              .setColor("red")
+ *              .setFontSize("16px")
+ *       )
+ *   );
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class Loading extends Configurable { + + /** + * Convenience method for setting the 'hideDuration' option of the loading options. Equivalent to: + *

+     *     loading.setOption("hideDuration", 150);
+     * 
+ * The duration in milliseconds of the fade out effect. Defaults to 100. + * + * @param hideDuration The duration in milliseconds of the fade out effect. + * @return A reference to this {@link Loading} instance for convenient method chaining. + */ + public Loading setHideDuration(Number hideDuration) { + return this.setOption("hideDuration", hideDuration); + } + + /** + * Convenience method for setting the 'labelStyle' options of the loading options. Equivalent to: + *

+     *     loading.setOption("labelStyle/fontSize", "16px");
+     *     loading.setOption("labelStyle/color", "red");
+     * 
+ * CSS styles for the loading label span. Defaults to: + *
    + *
  • fontWeight: bold
  • + *
  • position: relative
  • + *
  • top: 1em
  • + *
+ * + * @param labelStyle The CSS styles for the loading label span. + * @return A reference to this {@link Loading} instance for convenient method chaining. + */ + public Loading setLabelStyle(Style labelStyle) { + return this.setOption("labelStyle", labelStyle != null ? labelStyle.getOptions() : null); + } + + /** + * + * Convenience method for setting the 'showDuration' option of the loading options. Equivalent to: + *

+     *     loading.setOption("showDuration", 150);
+     * 
+ * The duration in milliseconds of the fade in effect. Defaults to 100. + * + * @param showDuration The duration in milliseconds of the fade in effect. + * @return A reference to this {@link Loading} instance for convenient method chaining. + */ + public Loading setShowDuration(Number showDuration) { + return this.setOption("showDuration", showDuration); + } + + /** + * Convenience method for setting the 'labelStyle' options of the loading options. Equivalent to: + *

+     *     loading.setOption("style/backgroundColor", "red");
+     *     loading.setOption("style/opacity", "0.8
+     * 
+ * CSS styles for the loading screen that covers the plot area. Defaults to: + *
    + *
  • position: absolute
  • + *
  • backgroundColor: 'white'
  • + *
  • opacity: 0.5
  • + *
  • textAlign: center
  • + *
+ * + * @param style The CSS styles for the loading screen that covers the plot area. + * @return A reference to this {@link Loading} instance for convenient method chaining. + */ + public Loading setStyle(Style style) { + return this.setOption("style", style != null ? style.getOptions() : null); + } + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Navigation.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Navigation.java new file mode 100755 index 00000000000..bebc6a99b09 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Navigation.java @@ -0,0 +1,86 @@ +package org.moxieapps.gwt.highcharts.client; + +/** + * A configurable class that will allow you to control the options for buttons and menus + * appearing in the exporting module. An instance of this class can be constructed and then + * set on the chart via the {@link BaseChart#setNavigation(Navigation)} method. + *

+ * Note that the "exporting" module must be included in the page in order for the exporting + * navigation options to apply. E.g.: + *

+ * <script type="text/javascript" src="js/modules/exporting.js"></script> + * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.1.0 + */ +public class Navigation extends Configurable { + + /** + * Convenience method for setting the 'menuStyle' options of the navigation area. Equivalent to: + *


+     *     navigation.setOption("/menuStyle/left", "100px");
+     *     navigation.setOption("/menuStyle/top", "10px");
+     *     etc.
+     * 
+ * CSS styles for the popup menu appearing by default when the export icon is clicked. This menu is rendered in HTML. + * Default options for the "menuStyle" are as follows: + *
    + *
  • border: '1px solid #A0A0A0'
  • + *
  • background: '#FFFFFF
  • + *
+ * + * @param menuStyle CSS styles for the popup menus of the exporting module + * @return A reference to this {@link Navigation} instance for convenient method chaining. + */ + public Navigation setMenuStyle(Style menuStyle) { + return this.setOption("menuStyle", menuStyle != null ? menuStyle.getOptions() : null); + } + + /** + * Convenience method for setting the 'menuItemStyle' options of the navigation area. Equivalent to: + *

+     *     navigation.setOption("/menuItemStyle/left", "100px");
+     *     navigation.setOption("/menuItemStyle/top", "10px");
+     *     etc.
+     * 
+ * CSS styles for the individual items within the popup menu appearing by default when the export icon + * is clicked. The menu items are rendered in HTML. Default options for the "menuItemStyle" are as follows: + *
    + *
  • padding: '0 5px'
  • + *
  • background: NONE
  • + *
  • color: '#303030'
  • + *
+ * + * @param menuItemStyle CSS styles for the individual items in the popup menus of the exporting module. + * @return A reference to this {@link Navigation} instance for convenient method chaining. + */ + public Navigation setMenuItemStyle(Style menuItemStyle) { + return this.setOption("menuItemStyle", menuItemStyle != null ? menuItemStyle.getOptions() : null); + } + + /** + * Convenience method for setting the 'menuItemHoverStyle' options of the navigation area. Equivalent to: + *

+     *     navigation.setOption("/menuItemHoverStyle/left", "100px");
+     *     navigation.setOption("/menuItemHoverStyle/top", "10px");
+     *     etc.
+     * 
+ * CSS styles for the hover state of the individual items within the popup menu appearing by default + * when the export icon is clicked. The menu items are rendered in HTML. Default options for + * the "menuItemHoverStyle" are as follows: + *
    + *
  • background: '#4572A5'
  • + *
  • color: '#FFFFFF'
  • + *
+ * + * @param menuItemHoverStyle CSS styles for the hover style of the individual items in the popup menus + * of the exporting module. + * @return A reference to this {@link Navigation} instance for convenient method chaining. + */ + public Navigation setMenuItemHoverStyle(Style menuItemHoverStyle) { + return this.setOption("menuItemHoverStyle", menuItemHoverStyle != null ? menuItemHoverStyle.getOptions() : null); + } + + // TODO: Add buttonOptions configuration methods + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/PlotBand.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/PlotBand.java new file mode 100755 index 00000000000..e78d3f6012e --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/PlotBand.java @@ -0,0 +1,170 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +import com.google.gwt.dom.client.Document; +import org.moxieapps.gwt.highcharts.client.labels.PlotBandLabel; + +/** + * A configurable class that can be used to represent plot bands across an area of the chart, which can + * then be set on an axis (via the {@link Axis#setPlotBands(PlotBand...)} method.) + * Note that a plot band is a colored band stretching across the plot area marking an interval on the axis. + * Example usage: + *
+ *   XAxis xAxis = chart.getXAxis();
+ *   xAxis.setPlotBands(
+ *     xAxis.createPlotBand()
+ *        .setColor("#CC0000")
+ *        .setFrom(40)
+ *        .setTo(80),
+ *     xAxis.createPlotBand()
+ *        .setColor("#00CC00")
+ *        .setFrom(80)
+ *        .setTo(120),
+ *   );
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class PlotBand extends Configurable { + + private Axis axis; + private String id; + + /** + * Use the {@link Axis#createPlotBand()} method to create new plot bands + * + * @param axis The axis instance that this plot band is being created within. + */ + PlotBand(Axis axis) { + this.axis = axis; + id = Document.get().createUniqueId(); + setOption("id", id); + } + + /** + * Convenience method for setting the 'color' option of the plot band to an RGB hex value. Equivalent to: + *

+     *     plotBand.setOption("color", "#CCCCCC");
+     * 
+ * The RGB color for the plot band. Defaults to null. + *

+ * Note that this method is intended for setting the color to a simple RBG hex value. If you instead + * want to set a color to include an alpha channel or a gradient, use the {@link #setColor(Color)} + * version instead. + * + * @param color The value to set as the 'color' option on the plot band. + * @return A reference to this {@link PlotBand} instance for convenient method chaining. + */ + public PlotBand setColor(String color) { + return this.setOption("color", color); + } + + /** + * Convenience method for setting the 'color' option of the plot band, allowing for + * colors with opacity or gradients. Equivalent to: + *


+     *     plotBand.setOption("color", new Color()
+     *        .setLinearGradient(0.0, 0.0, 1.0, 1.0)
+     *        .addStop(new Color(255, 255, 255))
+     *        .addStop(new Color(200, 200, 255))
+     *     );
+     * 
+ * The color or gradient for the plot band. Defaults to null. + *

+ * Note that this method is intended for setting the color to a gradient or color that includes + * an alpha channel. If you instead just want to set the color to a normal RGB hex value + * you can use the {@link #setColor(String)} version instead. + * + * @param color The color gradient or color with an alpha channel to set as the 'color' option on the plot band. + * @return A reference to this {@link PlotBand} instance for convenient method chaining. + */ + public PlotBand setColor(Color color) { + return this.setOption("color", color != null ? color.getOptionValue() : null); + } + + // TODO: Add events + + /** + * Convenience method for setting the 'from' option of the plot band. Equivalent to: + *


+     *     plotBand.setOption("from", 40);
+     * 
+ * The start position of the plot band in axis units. Defaults to null. + * + * @param from The start position of the plot band in axis units. + * @return A reference to this {@link PlotBand} instance for convenient method chaining. + */ + public PlotBand setFrom(Number from) { + return this.setOption("from", from); + } + + /** + * Convenience method for setting the 'label' options of the plot band. Equivalent to: + *

+     *     plotBand.setOption("/label/align", PlotBandLabel.Align.LEFT);
+     *     plotBand.setOption("/label/x", 20);
+     *     etc....
+     * 
+ * + * @param plotBandLabel The options for the label on the plot band. + * @return A reference to this {@link PlotBand} instance for convenient method chaining. + */ + public PlotBand setLabel(PlotBandLabel plotBandLabel) { + return this.setOption("label", plotBandLabel != null ? plotBandLabel.getOptions() : null); + } + + /** + * Convenience method for setting the 'to' option of the plot band. Equivalent to: + *

+     *     plotBand.setOption("to", 40);
+     * 
+ * The end position of the plot band in axis units. Defaults to null. + * + * @param to The end position of the plot band in axis units. + * @return A reference to this {@link PlotBand} instance for convenient method chaining. + */ + public PlotBand setTo(Number to) { + return this.setOption("to", to); + } + + /** + * Convenience method for setting the 'zIndex' option of the plot band. Equivalent to: + *

+     *     plotBand.setOption("zIndex", 100);
+     * 
+ * The z index of the plot band within the chart. Defaults to null. + * + * @param zIndex The z index of the plot band within the chart. + * @return A reference to this {@link PlotBand} instance for convenient method chaining. + */ + public PlotBand setZIndex(Number zIndex) { + return this.setOption("zIndex", zIndex); + } + + /** + * Internal method used to retrieve the unique id generated for this plot band. + * + * @return The unique id of this plot band + * @since 1.1.3 + */ + String getId() { + return id; + } + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/PlotLine.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/PlotLine.java new file mode 100755 index 00000000000..725410bf36a --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/PlotLine.java @@ -0,0 +1,260 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +import com.google.gwt.dom.client.Document; +import org.moxieapps.gwt.highcharts.client.labels.PlotLineLabel; + +/** + * A configurable class that can be used to represent plot lines on an axis of the chart, which can + * then be set on an axis (via the {@link Axis#setPlotLines(PlotLine...)} method.) + * Note that a plot line is a line stretching across the plot area, marking a specific value on one of the axes. + * Example usage: + *
+ *   XAxis xAxis = chart.getXAxis();
+ *   xAxis.setPlotLines(
+ *     xAxis.createPlotLine()
+ *        .setColor("#CC0000")
+ *        .setValue(40),
+ *     xAxis.createPlotLine()
+ *        .setColor("#009900")
+ *        .setValue(60)
+ *   );
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class PlotLine extends Configurable { + + /** + * An enumeration of supported dash style types, which can be passed to the + * {@link #setDashStyle(DashStyle)} method. See this + * demonstration for a visible reference + * of the available dash styles. + */ + public enum DashStyle { + + /** + * Solid line, no dashes + */ + SOLID("Solid"), + + /** + * Short dashes, "- - - -" + */ + SHORT_DASH("ShortDash"), + + /** + * Short (tightly spaced) dots, ". . . ." + */ + SHORT_DOT("ShortDot"), + + /** + * Short (tightly spaced) dash and dots, "- . - . - ." + */ + SHORT_DASH_DOT("ShortDashDot"), + + /** + * Short (tightly spaced) dash and two dots, "- . . - . . - . ." + */ + SHORT_DASH_DOT_DOT("ShortDashDotDot"), + + /** + * Large (widely spaced) dots, ". . . . ." + */ + DOT("Dot"), + + /** + * Medium size dashes, "-- -- -- --" + */ + DASH("Dash"), + + /** + * Long dashes, "--- --- --- ---" + */ + LONG_DASH("LongDash"), + + /** + * Medium size dashes and a dot, "-- . -- . -- . --" + */ + DASH_DOT("DashDot"), + + /** + * Long dashes and a dot, "--- . --- . --- . ---" + */ + LONG_DASH_DOT("LongDashDot"), + + /** + * Long dashes and two dots, "--- .. --- .. --- .. ---" + */ + LONG_DASH_DOT_DOT("LongDashDotDot"); + + private DashStyle(String optionValue) { + this.optionValue = optionValue; + } + + private final String optionValue; + + public String toString() { + return optionValue; + } + + } + + private Axis axis; + private String id; + + /** + * Use the {@link Axis#createPlotLine()} method to create new plot lines + * + * @param axis The axis instance that this plotline is being created within. + */ + PlotLine(Axis axis) { + this.axis = axis; + id = Document.get().createUniqueId(); + setOption("id", id); + } + + /** + * Convenience method for setting the 'color' option of the plot line to an RGB hex value. Equivalent to: + *

+     *     plotLine.setOption("color", "#CCCCCC");
+     * 
+ * The RGB color for the plot line. Defaults to null. + *

+ * Note that this method is intended for setting the color to a simple RBG hex value. If you instead + * want to set a color to include an alpha channel or a gradient, use the {@link #setColor(Color)} + * version instead. + * + * @param color The value to set as the 'color' option on the plot line. + * @return A reference to this {@link PlotLine} instance for convenient method chaining. + */ + public PlotLine setColor(String color) { + return this.setOption("color", color); + } + + /** + * Convenience method for setting the 'color' option of the plot line, allowing for + * colors with opacity or gradients. Equivalent to: + *


+     *     plotLine.setOption("color", new Color()
+     *        .setLinearGradient(0.0, 0.0, 1.0, 1.0)
+     *        .addStop(new Color(255, 255, 255))
+     *        .addStop(new Color(200, 200, 255))
+     *     );
+     * 
+ * The color or gradient for the plot line. Defaults to null. + *

+ * Note that this method is intended for setting the color to a gradient or color that includes + * an alpha channel. If you instead just want to set the color to a normal RGB hex value + * you can use the {@link #setColor(String)} version instead. + * + * @param color The color gradient or color with an alpha channel to set as the 'color' option on the plot line. + * @return A reference to this {@link PlotLine} instance for convenient method chaining. + */ + public PlotLine setColor(Color color) { + return this.setOption("color", color != null ? color.getOptionValue() : null); + } + + /** + * Convenience method for setting the 'dashStyle' plot line optoin. Equivalent to: + *


+     *     plotLine.setOption("dashStyle", DashStyle.DOT);
+     * 
+ * The dashing or dot style for the plot line. Defaults to {@link DashStyle#SOLID}. See this + * demonstration for a visible reference + * of the available dash styles. + * + * @param dashStyle The dash style to use for this plot line, or null to use the default. + * @return A reference to this {@link PlotLine} instance for convenient method chaining. + */ + public PlotLine setDashStyle(PlotLine.DashStyle dashStyle) { + return this.setOption("dashStyle", dashStyle != null ? dashStyle.toString() : null); + } + + // TODO: Add events + + /** + * Convenience method for setting the 'label' options of the plot line. Equivalent to: + *

+     *     plotLine.setOption("/label/align", PlotLineLabel.Align.LEFT);
+     *     plotLine.setOption("/label/x", 20);
+     *     etc....
+     * 
+ * + * @param plotLineLabel The options for the label on the plot line. + * @return A reference to this {@link PlotLine} instance for convenient method chaining. + */ + public PlotLine setLabel(PlotLineLabel plotLineLabel) { + return this.setOption("label", plotLineLabel != null ? plotLineLabel.getOptions() : null); + } + + /** + * Convenience method for setting the 'value' option of the plot line. Equivalent to: + *

+     *     plotLine.setOption("value", 40);
+     * 
+ * The position of the line in axis units. Defaults to null. + * + * @param value The position of the line in axis units. + * @return A reference to this {@link PlotLine} instance for convenient method chaining. + */ + public PlotLine setValue(Number value) { + return this.setOption("value", value); + } + + /** + * Convenience method for setting the 'width' option of the plot line. Equivalent to: + *

+     *     plotLine.setOption("width", 2);
+     * 
+ * The width or thickness of the plot line. Defaults to null. + * + * @param width The width or thickness of the plot line. + * @return A reference to this {@link PlotLine} instance for convenient method chaining. + */ + public PlotLine setWidth(Number width) { + return this.setOption("width", width); + } + + /** + * Convenience method for setting the 'zIndex' option of the plot line. Equivalent to: + *

+     *     plotLine.setOption("zIndex", 100);
+     * 
+ * The z index of the plot line within the chart. Defaults to null. + * + * @param zIndex The z index of the plot line within the chart. + * @return A reference to this {@link PlotLine} instance for convenient method chaining. + */ + public PlotLine setZIndex(Number zIndex) { + return this.setOption("zIndex", zIndex); + } + + /** + * Internal method used to retrieve the unique id generated for this plot line. + * + * @return The unique id of this plot line + * @since 1.1.3 + */ + String getId() { + return id; + } + + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Point.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Point.java new file mode 100755 index 00000000000..73baff6b0c8 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Point.java @@ -0,0 +1,699 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +import com.google.gwt.core.client.JavaScriptObject; +import com.google.gwt.json.client.JSONObject; +import org.moxieapps.gwt.highcharts.client.plotOptions.Marker; + +/** + * Represents a single data point that can be added to a {@link Series}. As an extension + * of {@link Configurable} each point instance can also optionally have configuration options set on it. + * Standard example: + *
+ *  chart.addSeries(chart.createSeries()
+ *     .setName("Browser share")
+ *     .setPoints(new Point[] {
+ *        new Point(15, 45.0),
+ *        new Point(25, 26.8),
+ *        new Point(35, 12.8),
+ *        new Point(46, 8.5),
+ *        new Point(55, 6.2),
+ *        new Point(65, 0.7)
+ *     })
+ * );
+ * 
+ *

+ * Advanced pie chart example (where the points represent categories and values for each category): + *
+ *  chart.addSeries(chart.createSeries()
+ *     .setName("Browser share")
+ *     .setPoints(new Point[]{
+ *        new Point("Firefox", 45.0),
+ *        new Point("IE", 26.8),
+ *        new Point("Chrome", 12.8)
+ *            .setSliced(true)
+ *            .setSelected(true),
+ *        new Point("Safari", 8.5),
+ *        new Point("Opera", 6.2),
+ *        new Point("Others", 0.7)
+ *     })
+ * );
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class Point extends Configurable { + + private Number y; + private Number x; + + /** + * Create a new point, setting only the Y axis value that the point should be + * rendered at within the series. + * + * @param y The Y value that the point should be rendered at within the series. + */ + public Point(Number y) { + this.y = y; + } + + /** + * Create a new point, setting both the value that the point should be rendered + * at on the X and Y axis within the series. + * + * @param x The X value that the point should be rendered at within the series. + * @param y The Y value that the point should be rendered at within the series. + */ + public Point(Number x, Number y) { + this.x = x; + this.y = y; + } + + /** + * Create a new point, setting the Y axis value that the point should be + * rendered at within the series as well as the "name" property of the point. + * + * @param name The value to set as the "property" of the point. + * @param y The Y value that the point should be rendered at within the series. + */ + public Point(String name, Number y) { + setName(name); + this.y = y; + } + + @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) + private JavaScriptObject nativePoint; + + /** + * This constructor is intended for internal use, and provides the ability to construct a GWT Point + * instance from the native JS Point instance managed within Highcharts. + * + * @param nativePoint The native javascript object containing the details of the point + */ + public Point(JavaScriptObject nativePoint) { + this.nativePoint = nativePoint; + } + + /** + * Retrieve the Y value of where point should be rendered at within the series. + * + * @return The Y value of the point (should always be non null). + */ + public Number getY() { + if (this.nativePoint != null) { + return nativeGetNumber(this.nativePoint, "y"); + } else { + return y; + } + } + + /** + * Retrieve the X value of where point should be rendered at within the series. + * + * @return The X value of the point, or null if no X value was set. + */ + public Number getX() { + if (this.nativePoint != null) { + return nativeGetNumber(this.nativePoint, "x"); + } else { + return x; + } + } + + /** + * Convenience method for setting the 'color' option of the point. Equivalent to: + *

+     *     point.setOption("color", "#CC0000");
+     * 
+ * Individual color for the point. Defaults to null. + * + * @param color The value to set as the point's color. + * @return A reference to this {@link Point} instance for convenient method chaining. + */ + public Point setColor(String color) { + return this.setOption("color", color); + } + + /** + * Override the individual point marker for the point. Defaults to null. E.g. + *

+     *    new Point(10, 30)
+     *      .setMarker(
+     *         new Marker()
+     *            .setEnabled(true)
+     *            .setFillColor("#CC0000")
+     *            .setRadius(4)
+     *      );
+     * 

+ *

+ * Note that this method is intended to be used to override the marker options of one + * particular point. If you instead want to control the marker options for the entire + * series, use the {@link org.moxieapps.gwt.highcharts.client.plotOptions.PlotOptions#setMarker(Marker)} + * method instead. + * + * @param marker The override marker options for this particular point, or null to + * simply use the whatever default marker options have been applied to whole series + * via {@link org.moxieapps.gwt.highcharts.client.plotOptions.PlotOptions#setMarker(Marker)} + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point setMarker(Marker marker) { + return this.setOption("marker", marker != null ? marker.getOptions() : null); + } + + private String name; + + /** + * Convenience method for setting the 'name' option of the point. Equivalent to: + *

+     *     point.setOption("name", "Green Bears");
+     * 
+ * The name of the point as shown in the legend, tooltip, dataLabel etc. Defaults to "". + * + * @param name The value to set as the point's name. + * @return A reference to this {@link Point} instance for convenient method chaining. + */ + public Point setName(String name) { + this.name = name; + return this.setOption("name", name); + } + + /** + * Return the name property that was set on this point, or null if no name was set. + * + * @return The 'name' property that was set on this point (likely via {@link #setName(String)}, + * or null if no name was set. + */ + public String getName() { + if (this.nativePoint != null) { + return nativeGetString(this.nativePoint, "name"); + } else { + return this.name; + } + } + + private boolean selected = false; + + /** + * Convenience method for setting the 'selected' option of the point. Equivalent to: + *

+     *     point.setOption("selected", true);
+     * 
+ * Whether the point is selected or not. + * + * @param selected Whether the point is selected or not. + * @return A reference to this {@link Point} instance for convenient method chaining. + */ + public Point setSelected(boolean selected) { + this.selected = selected; + return this.setOption("selected", selected); + } + + private boolean sliced = false; + + /** + * Convenience method for setting the 'sliced' option of the point. Equivalent to: + *

+     *     point.setOption("sliced", false);
+     * 
+ * Pie series only. Whether to display a slice offset from the center. Defaults to false. + * + * @param sliced The value to set as the point's 'sliced' option. + * @return A reference to this {@link Point} instance for convenient method chaining. + */ + public Point setSliced(boolean sliced) { + this.sliced = sliced; + return this.setOption("sliced", sliced); + } + + /** + * Store some arbitrary data on the point. As the user interacts with the chart various events + * are fired (such as {@link org.moxieapps.gwt.highcharts.client.events.PointClickEvent}), which + * include a reference to the Point instance that the event was fired on. The Point instances + * that are returned from the live rendered chart are actually different instances then the versions + * that were originally added to the chart via one of the Series addPoint() or setPoints() methods, + * as Highcharts has its own internal representation of all of the point objects. Therefore, + * if you need to track some additional information with each point (beyond its axis values) + * that you can later access when an event on the point is fired, this method provides a convenient + * way for you to store some arbitrary data on the point which will then later be available + * via the {@link #getUserData()} method. + * + * @param userData Some arbitrary data that to store with the point that will be available + * later whenever the point instance is retrieved after the chart is rendered. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point setUserData(JSONObject userData) { + return this.setOption("userData", userData); + } + + /** + * Retrieve any arbitrary data that was stored along with the point + * (via the {@link #setUserData(JSONObject)} method) when it was originally added to a series + * + * @return The arbitrary data that was stored with the point when it was first added to the series, + * or null if no such data was set. + * @since 1.1.0 + */ + public JSONObject getUserData() { + if(nativePoint != null) { + JavaScriptObject nativeUserData = nativeGetUserData(nativePoint); + return nativeUserData != null ? new JSONObject(nativeUserData) : null; + } else { + return this.getOptions() != null ? (JSONObject)this.getOptions().get("userData") : null; + } + } + + /** + * Remove the point from the series, automatically redrawing the chart using the default + * animation options.

+ * Note that this method is only relevant on Point instance that are obtained from the chart + * after it has been rendered, such as via an event or dynamically retrieving the points of + * a series. + * + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point remove() { + return this.remove(true, true); + } + + /** + * Remove the point from the series, explicitly controlling whether the chart is redrawn + * and/or animated or not.

+ * Note that this method is only relevant on Point instance that are obtained from the chart + * after it has been rendered, such as via an event or dynamically retrieving the points of + * a series. + * + * @param redraw Whether to redraw the chart after the point is removed. When removing more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called after the removing of points is finished. + * @param animation Defaults to true. When true, the graph will be animated with default animation options. + * Note, see the {@link #remove(boolean, Animation)} method + * for more control over how the animation will run. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point remove(boolean redraw, boolean animation) { + return this.remove(redraw, animation ? new Animation() : null); + } + + /** + * Remove the point from the series, explicitly controlling whether the chart is redrawn + * and the details of the animation options.

+ * Note that this method is only relevant on Point instance that are obtained from the chart + * after it has been rendered, such as via an event or dynamically retrieving the points of + * a series. + * + * @param redraw Whether to redraw the chart after the point is removed. When removing more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called after the removing of points is finished. + * @param animation The custom animation to use when removing the point from the series. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point remove(boolean redraw, Animation animation) { + if (this.nativePoint != null) { + if (animation == null || animation.getOptions() == null) { + nativeRemove(this.nativePoint, redraw, animation != null); + } else { + nativeRemove(this.nativePoint, redraw, animation.getOptions().getJavaScriptObject()); + } + } + // Nothing to do if this point isn't connected to a Highcharts JS point instance + return this; + } + + /** + * Select or unselect the point. See the {@link #selectToggle(boolean)} method for other options. + * + * @param select When true, the point is selected. If you'd instead like to simply toggle the selection + * state see the {@link #selectToggle(boolean)} method instead. + * @param accumulate When true, the selection is added to other selected points. When false, other + * selected points are deselected. Internally in Highcharts, selected points + * are accumulated on Control, Shift or Cmd clicking the point. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point select(boolean select, boolean accumulate) { + if (this.nativePoint != null) { + nativeSelect(this.nativePoint, select, accumulate); + } else { + setSelected(select); + } + return this; + } + + /** + * Toggle the selection state of the point. See the {@link #select(boolean, boolean)} method for other options. + * + * @param accumulate When true, the selection is added to other selected points. When false, other + * selected points are deselected. Internally in Highcharts, selected points + * are accumulated on Control, Shift or Cmd clicking the point. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point selectToggle(boolean accumulate) { + if (this.nativePoint != null) { + nativeSelectToggle(this.nativePoint, accumulate); + } else { + setSelected(!selected); + } + return this; + } + + /** + * Slice out or set back in a pie chart slice, automatically redrawing the chart with the default + * animation options. This is the default way of Highcharts to visualize that a pie point is + * selected. See the {@link #sliceToggle()} method as well. + * + * @param sliced When true, the point is sliced out. When false, the point is set in. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point slice(boolean sliced) { + return this.slice(sliced, true, true); + } + + /** + * Slice out or set back in a pie chart slice, controlling whether or not the chart will be + * automatically redraw or not. This is the default way of Highcharts to visualize that a pie point is + * selected. See the {@link #sliceToggle(boolean, boolean)} method as well. + * + * @param sliced When true, the point is sliced out. When false, the point is set in. + * @param redraw Whether to redraw the chart after the point is sliced. When slicing more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called after the slicing of points is finished. + * @param animation Defaults to true. When true, the graph will be animated with default animation options. + * Note, also see the {@link #slice(boolean, boolean, Animation)} method + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point slice(boolean sliced, boolean redraw, boolean animation) { + return this.slice(sliced, redraw, animation ? new Animation() : null); + } + + /** + * Slice out or set back in a pie chart slice, controlling whether or not the chart will be + * automatically redraw or not. This is the default way of Highcharts to visualize that a pie point is + * selected. See the {@link #sliceToggle(boolean, Animation)} method as well. + * + * @param sliced When true, the point is sliced out. When false, the point is set in. + * @param redraw Whether to redraw the chart after the point is sliced. When slicing more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called after the slicing of points is finished. + * @param animation The custom animation to use when slicing the point ing the series. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point slice(boolean sliced, boolean redraw, Animation animation) { + if (this.nativePoint != null) { + if (animation == null || animation.getOptions() == null) { + nativeSlice(this.nativePoint, sliced, redraw, animation != null); + } else { + nativeSlice(this.nativePoint, sliced, redraw, animation.getOptions().getJavaScriptObject()); + } + } else { + setSliced(sliced); + } + return this; + } + + /** + * Toggle slicing out or set back in a pie chart slice, automatically redrawing the chart with the default + * animation options. This is the default way of Highcharts to visualize that a pie point is + * selected. See the {@link #slice(boolean)} method as well. + * + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point sliceToggle() { + return this.sliceToggle(true, true); + } + + /** + * Toggle slicing out or set back in a pie chart slice, controlling whether or not the chart will be + * automatically redraw or not. This is the default way of Highcharts to visualize that a pie point is + * selected. See the {@link #slice(boolean, boolean, boolean)} method as well. + * + * @param redraw Whether to redraw the chart after the point is sliced. When slicing more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called after the slicing of points is finished. + * @param animation Defaults to true. When true, the graph will be animated with default animation options. + * Note, also see the {@link #slice(boolean, boolean, Animation)} method + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point sliceToggle(boolean redraw, boolean animation) { + return this.sliceToggle(redraw, animation ? new Animation() : null); + } + + /** + * Toggle slicing out or set back in a pie chart slice, controlling whether or not the chart will be + * automatically redraw or not. This is the default way of Highcharts to visualize that a pie point is + * selected. See the {@link #slice(boolean, boolean, Animation)} method as well. + * + * @param redraw Whether to redraw the chart after the point is sliced. When slicing more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called after the slicing of points is finished. + * @param animation The custom animation to use when slicing the point ing the series. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point sliceToggle(boolean redraw, Animation animation) { + if (this.nativePoint != null) { + if (animation == null || animation.getOptions() == null) { + nativeSlice(this.nativePoint, redraw, animation != null); + } else { + nativeSlice(this.nativePoint, redraw, animation.getOptions().getJavaScriptObject()); + } + } else { + setSliced(!sliced); + } + return this; + } + + /** + * Update the point with the new values, automatically redrawing + * the chart with the default animation options. + * + * @param y The new y value for the point. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point update(Number y) { + return this.update(new Point(y)); + } + + /** + * Update the point with the new values, automatically redrawing + * the chart with the default animation options. + * + * @param x The new x value for the point. + * @param y The new value for the point. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point update(Number x, Number y) { + return this.update(new Point(x, y)); + } + + /** + * Update the point with the new values, specifying whether or not the chart should be automatically + * redrawn with the new values. + * + * @param y The new y value for the point. + * @param redraw Whether to redraw the chart after the point is updated. When updating more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called after the updating of points is finished. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point update(Number y, boolean redraw) { + return this.update(new Point(y), redraw, true); + } + + /** + * Update the point with the new values, specifying whether or not the chart should be automatically + * redrawn with the new values. + * + * @param x The new x value for the point. + * @param y The new value for the point. + * @param redraw Whether to redraw the chart after the point is updated. When updating more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called after the updating of points is finished. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point update(Number x, Number y, boolean redraw) { + return this.update(new Point(x, y), redraw, true); + } + + /** + * Update the point with the new values and options from the given point, automatically redrawing + * the chart with the default animation options. + * + * @param pointOptions The point instance from which the new values and options will be retrieved. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point update(Point pointOptions) { + return this.update(pointOptions, true, true); + } + + /** + * Update the point with the new values and options from the given point, specifying if the chart + * should be automatically redrawn and animated or not. + * + * @param pointOptions The point instance from which the new values and options will be retrieved. + * @param redraw Whether to redraw the chart after the point is updated. When updating more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called after the updating of points is finished. + * @param animation Defaults to true. When true, the graph will be animated with default animation options. + * Note, see the {@link #update(Point, boolean, Animation)} method + * for more control over how the animation will run. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point update(Point pointOptions, boolean redraw, boolean animation) { + return this.update(pointOptions, redraw, animation ? new Animation() : null); + } + + /** + * Update the point with the new values and options from the given point, specifying if the chart + * should be automatically redrawn and animated or not. + * + * @param pointOptions The point instance from which the new values and options will be retrieved. + * @param redraw Whether to redraw the chart after the point is updating. When updating more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called after the updating of points is finished. + * @param animation The custom animation to use when updating the point in the series. + * @return A reference to this {@link Point} instance for convenient method chaining. + * @since 1.1.0 + */ + public Point update(Point pointOptions, boolean redraw, Animation animation) { + if (this.nativePoint != null) { + if (animation == null || animation.getOptions() == null) { + if (pointOptions.isSingleValue()) { + if(pointOptions.getY() == null) { + nativeUpdateToNull(this.nativePoint, redraw, animation != null); + } else { + nativeUpdate(this.nativePoint, pointOptions.getY().doubleValue(), redraw, animation != null); + } + } else { + nativeUpdate(this.nativePoint, Series.convertPointToJavaScriptObject(pointOptions), redraw, animation != null); + } + } else { + if (pointOptions.isSingleValue()) { + if(pointOptions.getY() == null) { + nativeUpdateToNull(this.nativePoint, redraw, animation.getOptions().getJavaScriptObject()); + } else { + nativeUpdate(this.nativePoint, pointOptions.getY().doubleValue(), redraw, animation.getOptions().getJavaScriptObject()); + } + } else { + nativeUpdate(this.nativePoint, Series.convertPointToJavaScriptObject(pointOptions), redraw, animation.getOptions().getJavaScriptObject()); + } + } + } else { + this.x = pointOptions.x; + this.y = pointOptions.y; + this.name = pointOptions.name; + this.selected = pointOptions.selected; + this.sliced = pointOptions.sliced; + for (String key : pointOptions.getOptions().keySet()) { + this.setOption(key, pointOptions.getOptions().get(key)); + } + } + return this; + } + + // Purposefully package scope + boolean isSingleValue() { + return this.getOptions() == null && this.getX() == null; + } + + private static native double nativeGetNumber(JavaScriptObject point, String key) /*-{ + return point[key]; + }-*/; + + private static native String nativeGetString(JavaScriptObject point, String key) /*-{ + return point[key]; + }-*/; + + private static native void nativeRemove(JavaScriptObject point, boolean redraw, boolean animation) /*-{ + point.remove(redraw, animation); + }-*/; + + private static native void nativeRemove(JavaScriptObject point, boolean redraw, JavaScriptObject animation) /*-{ + point.remove(redraw, animation); + }-*/; + + private static native void nativeSelect(JavaScriptObject point, boolean select, boolean accumulate) /*-{ + point.select(select, accumulate); + }-*/; + + private static native void nativeSelectToggle(JavaScriptObject point, boolean accumulate) /*-{ + point.select(null, accumulate); + }-*/; + + private static native void nativeSlice(JavaScriptObject point, boolean sliced, boolean redraw, JavaScriptObject animation) /*-{ + point.slice(sliced, redraw, animation); + }-*/; + + private static native void nativeSlice(JavaScriptObject point, boolean sliced, boolean redraw, boolean animation) /*-{ + point.slice(sliced, redraw, animation); + }-*/; + + private static native void nativeSlice(JavaScriptObject point, boolean redraw, JavaScriptObject animation) /*-{ + point.slice(null, redraw, animation); + }-*/; + + private static native void nativeSlice(JavaScriptObject point, boolean redraw, boolean animation) /*-{ + point.slice(null, redraw, animation); + }-*/; + + private static native void nativeUpdate(JavaScriptObject point, JavaScriptObject options, boolean redraw, JavaScriptObject animation) /*-{ + point.update(options, redraw, animation); + }-*/; + + private static native void nativeUpdate(JavaScriptObject point, double y, boolean redraw, JavaScriptObject animation) /*-{ + point.update(y, redraw, animation); + }-*/; + + private static native void nativeUpdate(JavaScriptObject point, JavaScriptObject options, boolean redraw, boolean animation) /*-{ + point.update(options, redraw, animation); + }-*/; + + private static native void nativeUpdate(JavaScriptObject point, double y, boolean redraw, boolean animation) /*-{ + point.update(y, redraw, animation); + }-*/; + + private static native void nativeUpdateToNull(JavaScriptObject point, boolean redraw, JavaScriptObject animation) /*-{ + point.update(null, redraw, animation); + }-*/; + + private static native void nativeUpdateToNull(JavaScriptObject point, boolean redraw, boolean animation) /*-{ + point.update(null, redraw, animation); + }-*/; + + private static native JavaScriptObject nativeGetUserData(JavaScriptObject point) /*-{ + return point.userData; + }-*/; + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/RangeSelector.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/RangeSelector.java new file mode 100755 index 00000000000..9056e87e592 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/RangeSelector.java @@ -0,0 +1,36 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +/** + * TODO: This is a place holder class which will be formalized once the Highstock + * library is released. + * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class RangeSelector extends Configurable { + + public RangeSelector setSelected(Number selected) { + return this.setOption("selected", selected); + } + + public RangeSelector setInputEnabled(boolean inputEnabled) { + return this.setOption("inputEnabled", inputEnabled); + } + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Series.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Series.java new file mode 100755 index 00000000000..9f47be701eb --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Series.java @@ -0,0 +1,798 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +import com.google.gwt.core.client.JavaScriptObject; +import com.google.gwt.core.client.JsArray; +import com.google.gwt.dom.client.Document; +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONNumber; +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.json.client.JSONValue; +import org.moxieapps.gwt.highcharts.client.plotOptions.PlotOptions; + +import java.util.ArrayList; +import java.util.Collections; + +/** + * Manages a data series (and its options) that can then be added to a {@link Chart}. As an extension + * of {@link Configurable} each series instance can also optionally have configuration options set on it. + * In order to create a new series, utilize the {@link Chart#createSeries()} method, configure it, add data + * to it, and then add it to the chart via the {@link Chart#addSeries(Series)} method. Note that a series + * can be modified after the chart has been rendered as well, which allows for support of dynamic charts or series + * that change in some way based on user behavior. Simple example of setting up a series on a chart: + *

+ * Series series = chart.createSeries()
+ *   .setName("Random Stuff")
+ *   .addPoint(40)
+ *   .addPoint(35)
+ *   .addPoint(60);
+ * chart.addSeries(series);
+ * 
+ * Example of updating all of the points in a series at once: + *
+ * chart.addSeries(chart.createSeries()
+ *   .setName("Random Stuff")
+ *   .setPoints(new Number[] { 40, 35, 60 })
+ * );
+ * 
+ * Example of changing the options for one point in the series: + *
+ * chart.addSeries(chart.createSeries()
+ *   .setName("Random Stuff")
+ *   .addPoint(40)
+ *   .addPoint(new Point(35).setColor("#BF0B23"))
+ *   .addPoint(60)
+ * );
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class Series extends Configurable { + + /** + * An enumeration of supported series types, which can be passed to methods such as + * {@link Series#setType(Series.Type)} or {@link Chart#setType(Series.Type)}. + */ + public enum Type { + + /** + * Show the series as an area filled in beneath a non-curved line + */ + AREA("area"), + + /** + * Show the series as an area filled in beneath a curved line + */ + + AREA_SPLINE("areaspline"), + + /** + * Show the series as horizontal bars + */ + BAR("bar"), + + /** + * Show the series as vertical bars + */ + COLUMN("column"), + + /** + * Show the series as a sequence of connected straight lines + */ + LINE("line"), + + /** + * Show the series as a pie chart + */ + PIE("pie"), + + /** + * Show the series as a scatter plot + */ + SCATTER("scatter"), + + /** + * Show the series as a sequence of lines that are rendered as a spline to appear as a smooth curve + */ + SPLINE("spline"), + + /** + * Show the series as a sequence of bars that show the open, high, low, and close values. + * Only available when you're using the {@link StockChart} widget type. + * + * @since 1.1.0 + */ + OHLC("ohlc"), + + /** + * Show the series as a sequence of candlesticks, where each candlestick represents four values. + * Only available when you're using the {@link StockChart} widget type. + * + * @since 1.1.0 + */ + CANDLESTICK("candlestick"); + + private Type(String optionName) { + this.optionName = optionName; + } + + private final String optionName; + + public String toString() { + return optionName; + } + + } + + // Purposefully set to package scope + BaseChart chart; + + // The unique id for this series, that we can use to access the native series instance later if changes + // come into the series after it is rendered + private String id; + + /** + * Use the {@link Chart#createSeries()} method to create new series instances. + * + * @param chart The chart instance that this series is being created within. + */ + protected Series(BaseChart chart) { + this.chart = chart; + id = Document.get().createUniqueId(); + setOption("id", id); + } + + /** + * Convenience method for setting the 'name' option of the series. Equivalent to: + *

+     *     series.setOption("name", "My Chart");
+     * 
+ * The name of the series as shown in the legend, tooltip etc. Defaults to "". + * + * @param name The string to set as the series name. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series setName(String name) { + return this.setOption("name", name); + } + + /** + * Convenience method for setting the 'stack' option of the series to a string. Equivalent to: + *

+     *     series.setOption("stack", "Stack 1");
+     * 
+ * The 'stack' option allows grouping series in a stacked chart. Defaults to null. Note + * that you can also set this option to a number instead via the {@link #setStack(Number)} method. + * + * @param stack The string to set as the 'stack' option on the series. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series setStack(String stack) { + return this.setOption("stack", stack); + } + + /** + * Convenience method for setting the 'stack' option of the series to a number. Equivalent to: + *

+     *     series.setOption("stack", 1);
+     * 
+ * The 'stack' option allows grouping series in a stacked chart. Defaults to null. Note + * that you can also set this option to a string instead via the {@link #setStack(String)} method. + * + * @param stack The number to set as the 'stack' option on the series. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series setStack(Number stack) { + return this.setOption("stack", stack); + } + + /** + * Sets the type of this series (which controls the way the series will be rendered), using + * an enumeration type in order to ensure a correct value is passed. This is equivalent to + * setting the option manually with code like: + *

+     *     series.setOption("type", "line");
+     * 
+ * Note that if you don't set this explicitly the default series type is {@link Series.Type#LINE}. + * + * @param type One of the supported series types. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series setType(Type type) { + return this.setOption("type", type.toString()); + } + + /** + * Convenience method for setting the 'xAxis' property of the series to a number. Equivalent to: + *

+     *     series.setOption("xAxis", 1);
+     * 
+ * When using dual or multiple x axes, this number defines which xAxis the particular series is + * connected to. It refers to the index of the axis in the xAxis array, with 0 being the first. + * Defaults to 0. + * + * @param xAxis The number to set as the 'xAxis' option on the series. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series setXAxis(Number xAxis) { + return this.setOption("xAxis", xAxis); + } + + /** + * Convenience method for setting the 'yAxis' property of the series to a number. Equivalent to: + *

+     *     series.setOption("yAxis", 1);
+     * 
+ * When using dual or multiple y axes, this number defines which yAxis the particular series is + * connected to. It refers to the index of the axis in the yAxis array, with 0 being the first. + * Defaults to 0. + * + * @param yAxis The number to set as the 'yAxis' option on the series. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series setYAxis(Number yAxis) { + return this.setOption("yAxis", yAxis); + } + + // Need to maintain a refernce to the plot options set on us in order to deal with potential custom data label formatters + private PlotOptions plotOptions; + + /** + * Updates the plot options for this series to reflect the given options. The default + * options for all series in the chart (of each type) can be set on the {@link Chart} instance, + * and therefore you only need to use this method if you want to override the plot options for + * this series only. + *

+ * Note that the general {@link PlotOptions} type only represents the abstract base class of all the + * different series types. To call this method you need to instantiate one of the concrete + * sub-classes instead (e.g. {@link org.moxieapps.gwt.highcharts.client.plotOptions.AreaPlotOptions}, + * {@link org.moxieapps.gwt.highcharts.client.plotOptions.BarPlotOptions}, etc.). + *

+ * Also note that changing the plot options for a series after it has been rendered to the screen + * does not change the way the live series will appear. If you need to change the plot options + * after the series is rendered, you'd instead need to first {@link #remove()} the series from + * the chart and then re-add it to the chart via the {@link Chart#addSeries(Series)} method. + * + * @param plotOptions The plot options to use for this series (or one of its sub-types) + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series setPlotOptions(PlotOptions plotOptions) { + + this.plotOptions = plotOptions; + + if (plotOptions == null) { + return this; + } + + // Applying plot options directly to a series is a little different as the optoins + // get applied directly to the root configuration object, instead of off within their + // own sub object like almost everything else works. So, we need to merge the given + // options with our root options + JSONObject plotOptionsJSON = plotOptions.getOptions(); + + if (plotOptionsJSON != null) { + for (String key : plotOptionsJSON.keySet()) { + this.setOption(key, plotOptionsJSON.get(key)); + } + } + + return this; + } + + // Purposefully package scope + PlotOptions getPlotOptions() { + return this.plotOptions; + } + + /** + * Simplest way to add a point using the default options, and setting only the Y value + * that the point should be rendered at within the series. See the various overloaded + * versions of the addPoint() method for more control over the way the + * point is rendered. + * + * @param y The value on the Y axis that the point should be drawn at within the series. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series addPoint(Number y) { + return this.addPoint(new Point(y)); + } + + /** + * Add a point to the series with a specific value on the Y axis, controlling the + * options on how the change will be drawn to the series. + * + * @param y The value on the Y axis that the point should be drawn at within the series. + * @param redraw Whether to redraw the chart after the point is added. When adding more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called + * after the adding of points is finished. + * @param shift Defaults to false. When shift is true, one point is shifted off the start of the + * series as one is appended to the end. Use this option for live charts monitoring + * a value over time. + * @param animation Defaults to true. When true, the graph will be animated with default animation options. + * Note, see the {@link #addPoint(Number, boolean, boolean, Animation)} method + * for more control over how the animation will run. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series addPoint(Number y, boolean redraw, boolean shift, boolean animation) { + return this.addPoint(new Point(y), redraw, shift, animation); + } + + /** + * Add a point to the series with a specific value on the Y axis, controlling the + * options on how the change will be drawn to the series. + * + * @param y The value on the Y axis that the point should be drawn at within the series. + * @param redraw Whether to redraw the chart after the point is added. When adding more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called + * after the adding of points is finished. + * @param shift Defaults to false. When shift is true, one point is shifted off the start of the + * series as one is appended to the end. Use this option for live charts monitoring + * a value over time. + * @param animation The custom animation to use when adding the point to the series. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series addPoint(Number y, boolean redraw, boolean shift, Animation animation) { + return this.addPoint(new Point(y), redraw, shift, animation); + } + + /** + * Simple way to add a point using the default options, and setting only the X and Y value + * that the point should be rendered at within the series. See the various overloaded + * versions of the addPoint() method for more control over the way the + * point is rendered. + * + * @param x The value on the X axis that the point should be drawn at within the series. + * @param y The value on the Y axis that the point should be drawn at within the series. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series addPoint(Number x, Number y) { + return this.addPoint(new Point(x, y)); + } + + /** + * Add a point to the series with a specific value on the X and Y axis, controlling the + * options on how the change will be drawn to the series. + * + * @param x The value on the X axis that the point should be drawn at within the series. + * @param y The value on the Y axis that the point should be drawn at within the series. + * @param redraw Whether to redraw the chart after the point is added. When adding more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called + * after the adding of points is finished. + * @param shift Defaults to false. When shift is true, one point is shifted off the start of the + * series as one is appended to the end. Use this option for live charts monitoring + * a value over time. + * @param animation Defaults to true. When true, the graph will be animated with default animation options. + * Note, see the {@link #addPoint(Number, Number, boolean, boolean, Animation)} method + * for more control over how the animation will run. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series addPoint(Number x, Number y, boolean redraw, boolean shift, boolean animation) { + return this.addPoint(new Point(x, y), redraw, shift, animation); + } + + /** + * Add a point to the series with a specific value on the X and Y axis, controlling the + * options on how the change will be drawn to the series. + * + * @param x The value on the X axis that the point should be drawn at within the series. + * @param y The value on the Y axis that the point should be drawn at within the series. + * @param redraw Whether to redraw the chart after the point is added. When adding more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called + * after the adding of points is finished. + * @param shift Defaults to false. When shift is true, one point is shifted off the start of the + * series as one is appended to the end. Use this option for live charts monitoring + * a value over time. + * @param animation The custom animation to use when adding the point to the series. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series addPoint(Number x, Number y, boolean redraw, boolean shift, Animation animation) { + return this.addPoint(new Point(x, y), redraw, shift, animation); + } + + /** + * Add a point to the series accepting the default options on how the point will be drawn. + * + * @param point The point to add to the series (which, in turn, can have its own configuration options). + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series addPoint(Point point) { + return this.addPoint(point, true, false, true); + } + + /** + * Add a point to the series with a specific value on the X and Y axis, controlling the + * options on how the change will be drawn to the series. + * + * @param point The point to add to the series (which, in turn, can have its own configuration options). + * @param redraw Whether to redraw the chart after the point is added. When adding more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called + * after the adding of points is finished. + * @param shift Defaults to false. When shift is true, one point is shifted off the start of the + * series as one is appended to the end. Use this option for live charts monitoring + * a value over time. + * @param animation Defaults to true. When true, the graph will be animated with default animation options. + * Note, see the {@link #addPoint(Point, boolean, boolean, Animation)} method + * for more control over how the animation will run. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series addPoint(Point point, boolean redraw, boolean shift, boolean animation) { + return this.addPoint(point, redraw, shift, animation ? new Animation() : null); + } + + /** + * Add a point to the series with a specific value on the X and Y axis, controlling the + * options on how the change will be drawn to the series. + * + * @param point The point to add to the series (which, in turn, can have its own configuration options). + * @param redraw Whether to redraw the chart after the point is added. When adding more than one + * point, it is highly recommended that the redraw option be set to false, and instead + * {@link Chart#redraw()} is explicitly called + * after the adding of points is finished. + * @param shift Defaults to false. When shift is true, one point is shifted off the start of the + * series as one is appended to the end. Use this option for live charts monitoring + * a value over time. + * @param animation The custom animation to use when adding the point to the series. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series addPoint(Point point, boolean redraw, boolean shift, Animation animation) { + if (isRendered()) { + // We'll store the point directly in the DOM if we've already been rendered + final JavaScriptObject nativeSeries = chart.get(this.id); + if (nativeSeries != null) { + if (animation == null || animation.getOptions() == null) { + final boolean animationFlag = animation != null; + if (point.isSingleValue()) { + nativeAddPoint(nativeSeries, point.getY(), redraw, shift, animationFlag); + } else { + nativeAddPoint(nativeSeries, convertPointToJavaScriptObject(point), redraw, shift, animationFlag); + } + } else { + final JavaScriptObject animationOptions = animation.getOptions().getJavaScriptObject(); + if (point.isSingleValue()) { + nativeAddPoint(nativeSeries, point.getY(), redraw, shift, animationOptions); + } else { + nativeAddPoint(nativeSeries, convertPointToJavaScriptObject(point), redraw, shift, animationOptions); + } + } + + } + } else { + // If we haven't been rendered, then store the point in ourselves for now + points.add(point); + } + return this; + } + + // Purposefully friendly scope so that we can get to this method from the Point class as well + static JavaScriptObject convertPointToJavaScriptObject(Point point) { + final JSONObject options = point.getOptions() != null ? point.getOptions() : new JSONObject(); + Chart.addPointScalarValues(point, options); + return options.getJavaScriptObject(); + } + + /** + * Apply a new set of data (Y values only) to the series and automatically redraw it. If you need + * more control than just simply setting the y values of each data point, then use the + * {@link #setPoints(Point[])} method instead. + * + * @param yValues The array of Y values to set on the data series (replacing any data already in place) + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series setPoints(Number[] yValues) { + return this.setPoints(yValues, true); + } + + /** + * Apply a new set of data (Y values only) to the series and optionally redraw it. If you need + * more control than just simply setting the y values of each data point, then use the + * {@link #setPoints(Point[], boolean)} method instead. + * + * @param yValues The array of Y values to set on the data series (replacing any data already in place) + * @param redraw Whether to redraw the chart after the series is altered. If doing more operations + * on the chart, it is a good idea to set redraw to false and then call + * {@link Chart#redraw()} after. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series setPoints(Number[] yValues, boolean redraw) { + this.points.clear(); + if (isRendered()) { + final JavaScriptObject nativeSeries = chart.get(this.id); + if (nativeSeries != null) { + JSONArray jsonArray = new JSONArray(); + for (int i = 0, pointsLength = yValues.length; i < pointsLength; i++) { + jsonArray.set(i, new JSONNumber(yValues[i].doubleValue())); + } + nativeSetData(nativeSeries, jsonArray.getJavaScriptObject(), redraw); + } + } else { + for (Number yValue : yValues) { + this.addPoint(yValue); + } + } + return this; + } + + /** + * Apply a new set of data (X and Y values) to the series and automatically redraw it. If you need + * more control than just simply setting the x and y values of each data point, then use the + * {@link #setPoints(Point[])} method instead. + * + * @param values A two dimensional array of values, where the main array is the list of points and + * each inner array contains two values representing the X and Y values respectively. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series setPoints(Number[][] values) { + return this.setPoints(values, true); + } + + /** + * Apply a new set of data (X and Y values) to the series and optionally redraw it. If you need + * more control than just simply setting the x and y values of each data point, then use the + * {@link #setPoints(Point[])} method instead. + * + * @param values A two dimensional array of values, where the main array is the list of points and + * each inner array contains two values representing the X and Y values respectively. + * @param redraw Whether to redraw the chart after the series is altered. If doing more operations + * on the chart, it is a good idea to set redraw to false and then call + * {@link Chart#redraw()} after. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series setPoints(Number[][] values, boolean redraw) { + this.points.clear(); + if (isRendered()) { + final JavaScriptObject nativeSeries = chart.get(this.id); + if (nativeSeries != null) { + JSONArray jsonArray = new JSONArray(); + for (int i = 0, pointsLength = values.length; i < pointsLength; i++) { + Number[] point = values[i]; + JSONValue jsonValue; + if (point.length > 1) { + JSONArray pointArray = new JSONArray(); + pointArray.set(0, new JSONNumber(point[0].doubleValue())); + pointArray.set(1, new JSONNumber(point[1].doubleValue())); + jsonValue = pointArray; + } else { + jsonValue = new JSONNumber(point[0].doubleValue()); + } + jsonArray.set(i, jsonValue); + } + nativeSetData(nativeSeries, jsonArray.getJavaScriptObject(), redraw); + } + } else { + for (Number[] xyValue : values) { + this.addPoint(xyValue[0], xyValue[1]); + } + } + return this; + } + + /** + * Apply a new set of data to the series and automatically redraw it. + * + * @param points The array of points to set on the data series (replacing any data already in place) + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series setPoints(Point[] points) { + return this.setPoints(points, true); + } + + /** + * Apply a new set of data to the series and optionally redraw it. + * + * @param points The array of points to set on the data series (replacing any data already in place) + * @param redraw Whether to redraw the chart after the series is altered. If doing more operations + * on the chart, it is a good idea to set redraw to false and then call + * {@link Chart#redraw()} after. + * @return A reference to this {@link Series} instance for convenient method chaining. + */ + public Series setPoints(Point[] points, boolean redraw) { + this.points.clear(); + if (isRendered()) { + final JavaScriptObject nativeSeries = chart.get(this.id); + if (nativeSeries != null) { + JSONArray jsonArray = new JSONArray(); + for (int i = 0, pointsLength = points.length; i < pointsLength; i++) { + jsonArray.set(i, Chart.convertPointToJSON(points[i])); + } + nativeSetData(nativeSeries, jsonArray.getJavaScriptObject(), redraw); + } + } else { + Collections.addAll(this.points, points); + } + return this; + } + + /** + * Retrieve the array of points that have been added to this series. If this method is invoked + * before the series is rendered to a chart, then it will simply return the points that have been + * added so far. If it is invoked after the series has been rendered, then it will retrieve + * the JS point instances from the live Highcharts element and convert them to GWT points. + * + * @return The array of points, or an empty array (non null) if no points have been added to the series yet. + */ + public Point[] getPoints() { + ArrayList convertedPoints = points; + if (isRendered()) { + convertedPoints = new ArrayList(); + // After the series has been rendered, convert the live JS data series back into GWT objects + final JavaScriptObject nativeSeries = chart.get(this.id); + if (nativeSeries != null) { + JsArray nativePoints = nativeGetData(nativeSeries); + for (int i = 0; i < nativePoints.length(); i++) { + JavaScriptObject nativePoint = nativePoints.get(i); + convertedPoints.add(new Point(nativePoint)); + } + } + } + return convertedPoints.toArray(new Point[points.size()]); + } + + /** + * Remove this series from the chart it is a part of. + * + * @return 'true' if the series was a part of an active chart and successfully removed, or 'false' if the + * given series had not yet been added to any chart. + */ + public boolean remove() { + return chart.removeSeries(this); + } + + /** + * Shows the series if hidden. Only applies after the chart has been rendered. + * + * @return A reference to this {@link Series} instance for convenient method chaining. + * @since 1.1.0 + */ + public Series show() { + if (isRendered()) { + final JavaScriptObject nativeSeries = chart.get(this.id); + if (nativeSeries != null) { + nativeShow(nativeSeries); + } + } + return this; + } + + /** + * Hides the series if visible. If the {@link BaseChart#setIgnoreHiddenSeries(boolean)} option is true, + * the chart is automatically redrawn without this series. Only applies after the chart has been rendered. + * + * @return A reference to this {@link Series} instance for convenient method chaining. + * @since 1.1.0 + */ + public Series hide() { + if (isRendered()) { + final JavaScriptObject nativeSeries = chart.get(this.id); + if (nativeSeries != null) { + nativeHide(nativeSeries); + } + } + return this; + } + + /** + * Select or unselect the series. This means it's selected property is set, the checkbox in the legend is + * toggled and when selected, the series is returned in the {@link BaseChart#getSelectedSeries()} method. + * + * @param select When true, the series is selected. When false it is unselected. See the {@link #selectToggle()} + * method to instead toggle the selection state. + * @return A reference to this {@link Series} instance for convenient method chaining. + * @since 1.1.0 + */ + public Series select(boolean select) { + if (isRendered()) { + final JavaScriptObject nativeSeries = chart.get(this.id); + if (nativeSeries != null) { + nativeSelect(nativeSeries, select); + } + } + return this; + } + + /** + * Select the series if it is currently unselected, or unselect the series if it is currently selected. + * See the {@link #select(boolean)} method for more explicit control over the selection state of a series. + * + * @return A reference to this {@link Series} instance for convenient method chaining. + * @since 1.1.0 + */ + public Series selectToggle() { + if (isRendered()) { + final JavaScriptObject nativeSeries = chart.get(this.id); + if (nativeSeries != null) { + nativeSelectToggle(nativeSeries); + } + } + return this; + } + + /** + * Internal method used to retrieve the unique id generated for this series. + * + * @return The unique id of this series + */ + String getId() { + return id; + } + + // Purposefully not using the generic "List" interface here in order optimize GWT performance. + private ArrayList points = new ArrayList(); + + // Purposefully setting to package scope + void clearInternalPointsList() { + this.points.clear(); + } + + boolean rendered = false; + + // Purposefully restricting to package scope + void setRendered(boolean flag) { + this.rendered = flag; + } + + private boolean isRendered() { + return this.rendered; + } + + private static native JavaScriptObject nativeAddPoint(JavaScriptObject series, JavaScriptObject options, boolean redraw, boolean shift, JavaScriptObject animation) /*-{ + series.addPoint(options, redraw, shift, animation); + }-*/; + + private static native JavaScriptObject nativeAddPoint(JavaScriptObject series, JavaScriptObject options, boolean redraw, boolean shift, boolean animation) /*-{ + series.addPoint(options, redraw, shift, animation); + }-*/; + + private static native JavaScriptObject nativeAddPoint(JavaScriptObject series, Number value, boolean redraw, boolean shift, JavaScriptObject animation) /*-{ + series.addPoint(value, redraw, shift, animation); + }-*/; + + private static native JavaScriptObject nativeAddPoint(JavaScriptObject series, Number value, boolean redraw, boolean shift, boolean animation) /*-{ + series.addPoint(value, redraw, shift, animation); + }-*/; + + private static native void nativeSetData(JavaScriptObject series, JavaScriptObject data, boolean redraw) /*-{ + series.setData(data, redraw); + }-*/; + + private static native void nativeShow(JavaScriptObject series) /*-{ + series.show(); + }-*/; + + private static native void nativeHide(JavaScriptObject series) /*-{ + series.hide(); + }-*/; + + private static native void nativeSelect(JavaScriptObject series, boolean select) /*-{ + series.select(select); + }-*/; + + private static native void nativeSelectToggle(JavaScriptObject series) /*-{ + series.select(null); + }-*/; + + private static native JsArray nativeGetData(JavaScriptObject series) /*-{ + return series.data; + }-*/; + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/StockChart.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/StockChart.java new file mode 100755 index 00000000000..55b95d964a0 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/StockChart.java @@ -0,0 +1,101 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +/** + * BETA! The main GWT widget that can be constructed and then configured in order to add a Highstock + * chart into a GWT layout container. Note that for more basic chart types just make use of the + * {@link Chart} widget instead. + * Basic usage is as follows: + *


+ * StockChart stockChart = new StockChart()
+ *    .setChartTitleText("NYSE")
+ *    .setMarginRight(10);
+ * Series series = stockChart.createSeries()
+ *   .addPoint(40)
+ *   .addPoint(35)
+ *   .addPoint(60);
+ * stockChart.addSeries(series);
+ * RootPanel.get().add(stockChart);
+ * 
+ * For details on available options see the Highcharts reference. + *

+ * Note that in order for this widget to function you must have included the Highstock javascript + * library and any of its dependencies in the page that the widget will run inside of. E.g.: + *


+ * <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
+ * <script type="text/javascript" src="js/highstock.js"></script>
+ * 

+ * <!-- Optionally, add a highcharts theme file -->
+ * <script type="text/javascript" src="js/themes/gray.js"></script>
+ * 

+ * <!-- Optionally, include the highcharts exporting module -->
+ * <script type="text/javascript" src="js/modules/exporting.js"></script>
+ * 
+ * Note that the "highstock.js" file includes all of the capabilities of the "highcharts.js" file. + * So if you plan on using both {@link StockChart}'s and regular {@link Chart}'s simultaneously, then + * you only need to include the "highstock.js" file in your page. + *

+ * Also note that Highcharts supports other JS frameworks besides jQuery for its internal DOM manipulation + * functionality. So, if jQuery isn't your cup of tea check the + * installation docs + * on the Highcharts site for more details. + * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class StockChart extends BaseChart { + + /** + * Create a new Highstock chart instance as a GWT Widget that can then be added to + * a GWT layout like any other widget. Note that the various methods that support + * setting properties of the chart (e.g. {@link #setType(org.moxieapps.gwt.highcharts.client.Series.Type)}, + * {@link #setBackgroundColor(String)}, {@link #setOption(String, Object)}, etc.) + * then support method chaining, allowing for syntax like the following: + *


+     * StockChart chart = new StockChart()
+     *    .setChartTitleText("Nice Chart")
+     *    .setMarginRight(10);
+     * RootPanel.get().add(chart);
+     * 
+ */ + public StockChart() { + super(); + } + + @Override + protected String getChartTypeName() { + return "StockChart"; + } + + /** + * Convenience method for setting the 'rangeSelector' chart options. Equivalent to: + *

+     *     stockChart.setOption("/rangeSelector/selected", 1);
+     *     stockChart.setOption("/rangeSelector/inputEnabled", false);
+     *     etc...
+     * 
+ * + * @param rangeSelector Sets the chart range selector options. + * @return A reference to this {@link StockChart} instance for convenient method chaining. + */ + public StockChart setRangeSelector(RangeSelector rangeSelector) { + return this.setOption("/rangeSelector", rangeSelector != null ? rangeSelector.getOptions() : null); + } + + +} diff --git a/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Style.java b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Style.java new file mode 100755 index 00000000000..cb9145eb616 --- /dev/null +++ b/java/org.moxieapps.gwt.highcharts/src/org/moxieapps/gwt/highcharts/client/Style.java @@ -0,0 +1,214 @@ +/* + * Copyright 2011 Moxie Group + * + * 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 org.moxieapps.gwt.highcharts.client; + +/** + * A configurable class that can be used to represent custom CSS style options for the + * chart, which can then be set on various other configuration objects (e.g. + * {@link Chart#setStyle(Style)}, {@link ChartTitle#setStyle(Style)}, etc.). + * Example usage: + *
+ *   chart.setStyle(
+ *     new Style()
+ *       .setOption("fontFamily", "serif")
+ *   );
+ * 
+ * Note that some convenience methods are provided on this class for setting commonly used + * CSS options (such as {@link #setColor(String)}, {@link #setFontFamily(String)}, + * {@link #setFontSize(String)}, etc). But, any arbitrary CSS option can be set by + * simply using the {@link #setOption(String, Object)} method. E.g., the following two + * lines are equivalent: + *
+ *   style.setFontFamily("serif");
+ *   style.setOption("fontFamily", "serif");
+ * 
+ * + * @author squinn@moxiegroup.com (Shawn Quinn) + * @since 1.0.0 + */ +public class Style extends Configurable