patch as received by e-mail from Highcarts developer Shawn Quinn as preview for 1.4.x

This commit is contained in:
Axel Uhl
2012-02-28 14:17:56 +01:00
parent ee8a81536d
commit 5b642565d1
6 changed files with 347 additions and 53 deletions
@@ -1,5 +0,0 @@
<module>
<inherits name='com.google.gwt.user.User'/>
<inherits name="com.google.gwt.json.JSON" />
<source path="client"/>
</module>
+31
View File
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>root</artifactId>
<groupId>com.sap.sailing</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.moxieapps.gwt.highcharts</artifactId>
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-source-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>plugin-source</id>
<phase>generate-sources</phase>
<goals>
<goal>plugin-source</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -1125,7 +1125,6 @@ public abstract class BaseChart<T> extends Widget {
*
* @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() {
@@ -1382,6 +1381,48 @@ public abstract class BaseChart<T> extends Widget {
return this.setOption("/plotOptions/spline", splinePlotOptions.getOptions());
}
// Whether or not to retain the data points associated with each series in local GWT arrays (as
// well as within the core Highcharts DOM elements)
private boolean persistent = false;
/**
* By default the data associated with the series of the chart is only maintained within a GWT managed Java
* array until the chart is rendered, at which point the data points of the series are maintained
* exclusively within the DOM via the Highcharts API. This is primarily intended for memory
* savings, to avoid having to keep the all of the data point information in two places. However,
* if you need to support dynamically moving a chart from one panel to another within the application
* you can set the persistent option to 'true', which will then retain the GWT managed Java array
* as well so that when the chart is redrawn in the new panel all of the data will still be available.
*
* @return 'true' if the data associated with the points in the series in the chart will be retained locally
* within a GWT managed Java array (as well as within the DOM via the core Highcharts JS library).
* Defaults to 'false' for memory savings.
* @since 1.2.0
*/
public boolean isPersistent() {
return persistent;
}
/**
* By default the data associated with the series of the chart is only maintained within a GWT managed Java
* array until the chart is rendered, at which point the data points of the series are maintained
* exclusively within the DOM via the Highcharts API. This is primarily intended for memory
* savings, to avoid having to keep the all of the data point information in two places. However,
* if you need to support dynamically moving a chart from one panel to another within the application
* you can set the persistent option to 'true', which will then retain the GWT managed Java array
* as well so that when the chart is redrawn in the new panel all of the data will still be available.
*
* @param persistent 'true' to retain the data associated with the points in the series in the chart locally
* within a GWT managed Java array (as well as within the DOM via the core Highcharts JS library).
* Defaults to 'false' for memory savings.
* @since 1.2.0
* @return A reference to this {@link BaseChart} instance for convenient method chaining.
*/
public T setPersistent(boolean persistent) {
this.persistent = persistent;
return returnThis();
}
// Purposefully not using the generic "List" interface here in order to optimize GWT performance.
private ArrayList<Series> seriesList = new ArrayList<Series>();
@@ -1918,6 +1959,12 @@ public abstract class BaseChart<T> extends Widget {
if (isRendered()) {
nativeDestroy(chart);
chart = null;
// If they're going to move the widget to another parent, make sure that everything
// starts off as if it's unrendered...
for (Series series : seriesList) {
series.setRendered(false);
}
}
}
@@ -1951,6 +1998,12 @@ public abstract class BaseChart<T> extends Widget {
}
}
// In the case that they're going to wait to access the X/Y axis after the chart is rendered,
// we need to call the 'get' methods once (at least for the primary X/Y axis) so that the ids
// are set on the Highcharts options correctly
this.getXAxis();
this.getYAxis();
// #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()]));
@@ -2003,16 +2056,27 @@ public abstract class BaseChart<T> extends Widget {
// 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();
JSONObject options = point.getOptions();
if (options != null) {
return addPointScalarValues(point, options);
} else if(point.hasNativeProperties()) {
options = new JSONObject();
addPointScalarValues(point, options);
return Point.addPointNativeProperties(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());
if (point.getOpen() != null && point.getHigh() != null && point.getLow() != null && point.getClose() != null) {
jsonArray.set(1, new JSONNumber(point.getOpen().doubleValue()));
jsonArray.set(2, new JSONNumber(point.getHigh().doubleValue()));
jsonArray.set(3, new JSONNumber(point.getLow().doubleValue()));
jsonArray.set(4, new JSONNumber(point.getClose().doubleValue()));
} else {
jsonArray.set(1, JSONNull.getInstance());
}
}
return jsonArray;
} else if (point.getY() != null) {
@@ -2032,6 +2096,18 @@ public abstract class BaseChart<T> extends Widget {
} else {
options.put("y", JSONNull.getInstance());
}
if (point.getOpen() != null) {
options.put("open", new JSONNumber(point.getOpen().doubleValue()));
}
if (point.getHigh() != null) {
options.put("high", new JSONNumber(point.getHigh().doubleValue()));
}
if (point.getLow() != null) {
options.put("low", new JSONNumber(point.getLow().doubleValue()));
}
if (point.getClose() != null) {
options.put("close", new JSONNumber(point.getClose().doubleValue()));
}
return options;
}
@@ -2168,56 +2244,59 @@ public abstract class BaseChart<T> extends Widget {
}-*/;
@SuppressWarnings({"UnusedDeclaration"})
private void chartEventCallback(JavaScriptObject nativeEvent, String eventType) {
private boolean chartEventCallback(JavaScriptObject nativeEvent, String eventType) {
if ("click".equals(eventType) && chartClickEventHandler != null) {
chartClickEventHandler.onClick(new ChartClickEvent(nativeEvent));
return chartClickEventHandler.onClick(new ChartClickEvent(nativeEvent));
} else if ("load".equals(eventType) && chartLoadEventHandler != null) {
chartLoadEventHandler.onLoad(new ChartLoadEvent(nativeEvent));
return chartLoadEventHandler.onLoad(new ChartLoadEvent(nativeEvent));
} else if ("redraw".equals(eventType) && chartRedrawEventHandler != null) {
chartRedrawEventHandler.onRedraw(new ChartRedrawEvent(nativeEvent));
return chartRedrawEventHandler.onRedraw(new ChartRedrawEvent(nativeEvent));
} else if ("selection".equals(eventType) && chartSelectionEventHandler != null) {
chartSelectionEventHandler.onSelection(new ChartSelectionEvent(nativeEvent));
return chartSelectionEventHandler.onSelection(new ChartSelectionEvent(nativeEvent));
}
return true;
}
@SuppressWarnings({"UnusedDeclaration"})
private void seriesEventCallback(JavaScriptObject nativeSeries, JavaScriptObject nativeEvent, String eventType) {
private boolean seriesEventCallback(JavaScriptObject nativeSeries, JavaScriptObject nativeEvent, String eventType) {
if ("click".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getSeriesClickEventHandler() != null) {
seriesPlotOptions.getSeriesClickEventHandler().onClick(new SeriesClickEvent(nativeEvent, nativeSeries));
return seriesPlotOptions.getSeriesClickEventHandler().onClick(new SeriesClickEvent(nativeEvent, nativeSeries));
} else if ("checkboxClick".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getSeriesCheckboxClickEventHandler() != null) {
seriesPlotOptions.getSeriesCheckboxClickEventHandler().onClick(new SeriesCheckboxClickEvent(nativeEvent, nativeSeries));
return seriesPlotOptions.getSeriesCheckboxClickEventHandler().onClick(new SeriesCheckboxClickEvent(nativeEvent, nativeSeries));
} else if ("hide".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getSeriesHideEventHandler() != null) {
seriesPlotOptions.getSeriesHideEventHandler().onHide(new SeriesHideEvent(nativeEvent, nativeSeries));
return seriesPlotOptions.getSeriesHideEventHandler().onHide(new SeriesHideEvent(nativeEvent, nativeSeries));
} else if ("legendItemClick".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getSeriesLegendItemClickEventHandler() != null) {
seriesPlotOptions.getSeriesLegendItemClickEventHandler().onClick(new SeriesLegendItemClickEvent(nativeEvent, nativeSeries));
return seriesPlotOptions.getSeriesLegendItemClickEventHandler().onClick(new SeriesLegendItemClickEvent(nativeEvent, nativeSeries));
} else if ("mouseOver".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getSeriesMouseOverEventHandler() != null) {
seriesPlotOptions.getSeriesMouseOverEventHandler().onMouseOver(new SeriesMouseOverEvent(nativeEvent, nativeSeries));
return seriesPlotOptions.getSeriesMouseOverEventHandler().onMouseOver(new SeriesMouseOverEvent(nativeEvent, nativeSeries));
} else if ("mouseOut".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getSeriesMouseOutEventHandler() != null) {
seriesPlotOptions.getSeriesMouseOutEventHandler().onMouseOut(new SeriesMouseOutEvent(nativeEvent, nativeSeries));
return seriesPlotOptions.getSeriesMouseOutEventHandler().onMouseOut(new SeriesMouseOutEvent(nativeEvent, nativeSeries));
} else if ("show".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getSeriesShowEventHandler() != null) {
seriesPlotOptions.getSeriesShowEventHandler().onShow(new SeriesShowEvent(nativeEvent, nativeSeries));
return seriesPlotOptions.getSeriesShowEventHandler().onShow(new SeriesShowEvent(nativeEvent, nativeSeries));
}
return true;
}
@SuppressWarnings({"UnusedDeclaration"})
private void pointEventCallback(JavaScriptObject nativePoint, JavaScriptObject nativeEvent, String eventType) {
private boolean pointEventCallback(JavaScriptObject nativePoint, JavaScriptObject nativeEvent, String eventType) {
if ("click".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getPointClickEventHandler() != null) {
seriesPlotOptions.getPointClickEventHandler().onClick(new PointClickEvent(nativeEvent, nativePoint));
return seriesPlotOptions.getPointClickEventHandler().onClick(new PointClickEvent(nativeEvent, nativePoint));
} else if ("mouseOver".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getPointMouseOverEventHandler() != null) {
seriesPlotOptions.getPointMouseOverEventHandler().onMouseOver(new PointMouseOverEvent(nativeEvent, nativePoint));
return seriesPlotOptions.getPointMouseOverEventHandler().onMouseOver(new PointMouseOverEvent(nativeEvent, nativePoint));
} else if ("mouseOut".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getPointMouseOutEventHandler() != null) {
seriesPlotOptions.getPointMouseOutEventHandler().onMouseOut(new PointMouseOutEvent(nativeEvent, nativePoint));
return seriesPlotOptions.getPointMouseOutEventHandler().onMouseOut(new PointMouseOutEvent(nativeEvent, nativePoint));
} else if ("remove".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getPointRemoveEventHandler() != null) {
seriesPlotOptions.getPointRemoveEventHandler().onRemove(new PointRemoveEvent(nativeEvent, nativePoint));
return seriesPlotOptions.getPointRemoveEventHandler().onRemove(new PointRemoveEvent(nativeEvent, nativePoint));
} else if ("select".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getPointSelectEventHandler() != null) {
seriesPlotOptions.getPointSelectEventHandler().onSelect(new PointSelectEvent(nativeEvent, nativePoint));
return seriesPlotOptions.getPointSelectEventHandler().onSelect(new PointSelectEvent(nativeEvent, nativePoint));
} else if ("unselect".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getPointUnselectEventHandler() != null) {
seriesPlotOptions.getPointUnselectEventHandler().onUnselect(new PointUnselectEvent(nativeEvent, nativePoint));
return seriesPlotOptions.getPointUnselectEventHandler().onUnselect(new PointUnselectEvent(nativeEvent, nativePoint));
} else if ("update".equals(eventType) && seriesPlotOptions != null && seriesPlotOptions.getPointUpdateEventHandler() != null) {
seriesPlotOptions.getPointUpdateEventHandler().onUpdate(new PointUpdateEvent(nativeEvent, nativePoint));
return seriesPlotOptions.getPointUpdateEventHandler().onUpdate(new PointUpdateEvent(nativeEvent, nativePoint));
} else if ("legendItemClick".equals(eventType) && piePlotOptions != null && piePlotOptions.getPointLegendItemClickEventHandler() != null) {
piePlotOptions.getPointLegendItemClickEventHandler().onClick(new PointLegendItemClickEvent(nativeEvent, nativePoint));
return piePlotOptions.getPointLegendItemClickEventHandler().onClick(new PointLegendItemClickEvent(nativeEvent, nativePoint));
}
return true;
}
@SuppressWarnings({"UnusedDeclaration"})
@@ -18,6 +18,8 @@ package org.moxieapps.gwt.highcharts.client;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
import org.moxieapps.gwt.highcharts.client.plotOptions.Marker;
/**
@@ -62,6 +64,10 @@ public class Point extends Configurable<Point> {
private Number y;
private Number x;
private Number open;
private Number high;
private Number low;
private Number close;
/**
* Create a new point, setting only the Y axis value that the point should be
@@ -85,6 +91,24 @@ public class Point extends Configurable<Point> {
this.y = y;
}
/**
* Create a new point for an OHLC chart, setting the x and all four OHLC values.
*
* @param x The X value that the point should be rendered at within the series.
* @param open The "open" Y value that the point should be rendered at within the series.
* @param high The "high" Y value that the point should be rendered at within the series.
* @param low The "low" Y value that the point should be rendered at within the series.
* @param close The "close" Y value that the point should be rendered at within the series.
* @since 1.2.0
*/
public Point(Number x, Number open, Number high, Number low, Number close) {
this.x = x;
this.open = open;
this.high = high;
this.low = low;
this.close = close;
}
/**
* 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.
@@ -116,7 +140,7 @@ public class Point extends Configurable<Point> {
* @return The Y value of the point (should always be non null).
*/
public Number getY() {
if (this.nativePoint != null) {
if (this.nativePoint != null && nativeContainsKey(this.nativePoint, "y")) {
return nativeGetNumber(this.nativePoint, "y");
} else {
return y;
@@ -129,13 +153,69 @@ public class Point extends Configurable<Point> {
* @return The X value of the point, or null if no X value was set.
*/
public Number getX() {
if (this.nativePoint != null) {
if (this.nativePoint != null && nativeContainsKey(this.nativePoint, "x")) {
return nativeGetNumber(this.nativePoint, "x");
} else {
return x;
}
}
/**
* For OHLC charts, return the "open" value of the data point
*
* @return The "open" value of the point, or null if no open value was set.
* @since 1.2.0
*/
public Number getOpen() {
if (this.nativePoint != null && nativeContainsKey(this.nativePoint, "open")) {
return nativeGetNumber(this.nativePoint, "open");
} else {
return open;
}
}
/**
* For OHLC charts, return the "high" value of the data point
*
* @return The "high" value of the point, or null if no high value was set.
* @since 1.2.0
*/
public Number getHigh() {
if (this.nativePoint != null && nativeContainsKey(this.nativePoint, "high")) {
return nativeGetNumber(this.nativePoint, "high");
} else {
return high;
}
}
/**
* For OHLC charts, return the "low" value of the data point
*
* @return The "low" value of the point, or null if no low value was set.
* @since 1.2.0
*/
public Number getLow() {
if (this.nativePoint != null && nativeContainsKey(this.nativePoint, "low")) {
return nativeGetNumber(this.nativePoint, "low");
} else {
return low;
}
}
/**
* For OHLC charts, return the "close" value of the data point
*
* @return The "close" value of the point, or null if no close value was set.
* @since 1.2.0
*/
public Number getClose() {
if (this.nativePoint != null && nativeContainsKey(this.nativePoint, "close")) {
return nativeGetNumber(this.nativePoint, "close");
} else {
return close;
}
}
/**
* Convenience method for setting the 'color' option of the point. Equivalent to:
* <pre><code>
@@ -272,11 +352,11 @@ public class Point extends Configurable<Point> {
* @since 1.1.0
*/
public JSONObject getUserData() {
if(nativePoint != null) {
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;
return this.getOptions() != null ? (JSONObject) this.getOptions().get("userData") : null;
}
}
@@ -591,7 +671,7 @@ public class Point extends Configurable<Point> {
if (this.nativePoint != null) {
if (animation == null || animation.getOptions() == null) {
if (pointOptions.isSingleValue()) {
if(pointOptions.getY() == null) {
if (pointOptions.getY() == null) {
nativeUpdateToNull(this.nativePoint, redraw, animation != null);
} else {
nativeUpdate(this.nativePoint, pointOptions.getY().doubleValue(), redraw, animation != null);
@@ -601,7 +681,7 @@ public class Point extends Configurable<Point> {
}
} else {
if (pointOptions.isSingleValue()) {
if(pointOptions.getY() == null) {
if (pointOptions.getY() == null) {
nativeUpdateToNull(this.nativePoint, redraw, animation.getOptions().getJavaScriptObject());
} else {
nativeUpdate(this.nativePoint, pointOptions.getY().doubleValue(), redraw, animation.getOptions().getJavaScriptObject());
@@ -613,6 +693,10 @@ public class Point extends Configurable<Point> {
} else {
this.x = pointOptions.x;
this.y = pointOptions.y;
this.open = pointOptions.open;
this.high = pointOptions.high;
this.low = pointOptions.low;
this.close = pointOptions.close;
this.name = pointOptions.name;
this.selected = pointOptions.selected;
this.sliced = pointOptions.sliced;
@@ -628,6 +712,26 @@ public class Point extends Configurable<Point> {
return this.getOptions() == null && this.getX() == null;
}
// Purposefully package scope
boolean hasNativeProperties() {
return this.nativePoint != null && (nativeContainsKey(this.nativePoint, "name") || nativeContainsKey(this.nativePoint, "userData"));
}
// Purposefully package scope
static JSONValue addPointNativeProperties(Point point, JSONObject options) {
if (options.get("name") == null && nativeContainsKey(point.nativePoint, "name")) {
options.put("name", new JSONString(point.getName()));
}
if (options.get("userData") == null && nativeContainsKey(point.nativePoint, "userData")) {
options.put("userData", point.getUserData());
}
return options;
}
private static native boolean nativeContainsKey(JavaScriptObject point, String key) /*-{
return point[key] != undefined;
}-*/;
private static native double nativeGetNumber(JavaScriptObject point, String key) /*-{
return point[key];
}-*/;
@@ -367,6 +367,24 @@ public class Series extends Configurable<Series> {
return this.addPoint(new Point(x, y));
}
/**
* Simple way to add a point using the default options, and setting only the X, Open, High,
* Low, and Close values that the point should be rendered at within the series (for OHLC
* charts). See the various overloaded versions of the <code>addPoint()</code> 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 open The "open" Y value that the point should be rendered at within the series.
* @param high The "high" Y value that the point should be rendered at within the series.
* @param low The "low" Y value that the point should be rendered at within the series.
* @param close The "close" Y value that the point should be rendered at within the series.
* @return A reference to this {@link Series} instance for convenient method chaining.
* @since 1.2.0
*/
public Series addPoint(Number x, Number open, Number high, Number low, Number close) {
return this.addPoint(new Point(x, open, high, low, close));
}
/**
* 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.
@@ -409,6 +427,30 @@ public class Series extends Configurable<Series> {
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 (in OHLC format), 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 open The "open" Y value that the point should be rendered at within the series.
* @param high The "high" Y value that the point should be rendered at within the series.
* @param low The "low" Y value that the point should be rendered at within the series.
* @param close The "close" Y value that the point should be rendered 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.
* @since 1.2.0
*/
public Series addPoint(Number x, Number open, Number high, Number low, Number close, boolean redraw, boolean shift, Animation animation) {
return this.addPoint(new Point(x, open, high, low, close), redraw, shift, animation);
}
/**
* Add a point to the series accepting the default options on how the point will be drawn.
*
@@ -456,6 +498,15 @@ public class Series extends Configurable<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 we haven't been rendered, then just store the point in ourselves for now. Or,
// if persistence is enabled than we need to store the point locally as well (so we have it if
// the chart is dynamically moved to another panel).
if (!isRendered() || chart.isPersistent()) {
// If we haven't been rendered, then just store the point in ourselves for now.
points.add(point);
}
if (isRendered()) {
// We'll store the point directly in the DOM if we've already been rendered
final JavaScriptObject nativeSeries = chart.get(this.id);
@@ -475,11 +526,7 @@ public class Series extends Configurable<Series> {
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;
}
@@ -488,6 +535,9 @@ public class Series extends Configurable<Series> {
static JavaScriptObject convertPointToJavaScriptObject(Point point) {
final JSONObject options = point.getOptions() != null ? point.getOptions() : new JSONObject();
Chart.addPointScalarValues(point, options);
if(point.hasNativeProperties()) {
Point.addPointNativeProperties(point, options);
}
return options.getJavaScriptObject();
}
@@ -516,6 +566,15 @@ public class Series extends Configurable<Series> {
*/
public Series setPoints(Number[] yValues, boolean redraw) {
this.points.clear();
// If persistence is enabled than we need to store the point locally as well (so we have it if
// the chart is dynamically moved to another panel).
if (!isRendered() || chart.isPersistent()) {
for (Number yValue : yValues) {
this.addPoint(yValue);
}
}
if (isRendered()) {
final JavaScriptObject nativeSeries = chart.get(this.id);
if (nativeSeries != null) {
@@ -525,11 +584,8 @@ public class Series extends Configurable<Series> {
}
nativeSetData(nativeSeries, jsonArray.getJavaScriptObject(), redraw);
}
} else {
for (Number yValue : yValues) {
this.addPoint(yValue);
}
}
return this;
}
@@ -560,6 +616,20 @@ public class Series extends Configurable<Series> {
*/
public Series setPoints(Number[][] values, boolean redraw) {
this.points.clear();
// If persistence is enabled than we need to store the point locally as well (so we have it if
// the chart is dynamically moved to another panel).
if (!isRendered() || chart.isPersistent()) {
for (Number[] xyValue : values) {
if (xyValue.length == 5) {
// For OHLC charts
this.addPoint(xyValue[0], xyValue[1], xyValue[2], xyValue[3], xyValue[4]);
} else {
this.addPoint(xyValue[0], xyValue[1]);
}
}
}
if (isRendered()) {
final JavaScriptObject nativeSeries = chart.get(this.id);
if (nativeSeries != null) {
@@ -567,7 +637,16 @@ public class Series extends Configurable<Series> {
for (int i = 0, pointsLength = values.length; i < pointsLength; i++) {
Number[] point = values[i];
JSONValue jsonValue;
if (point.length > 1) {
if (point.length == 5) {
// For OHLC charts
JSONArray pointArray = new JSONArray();
pointArray.set(0, new JSONNumber(point[0].doubleValue()));
pointArray.set(1, new JSONNumber(point[1].doubleValue()));
pointArray.set(2, new JSONNumber(point[2].doubleValue()));
pointArray.set(3, new JSONNumber(point[3].doubleValue()));
pointArray.set(4, new JSONNumber(point[4].doubleValue()));
jsonValue = pointArray;
} else if (point.length > 1) {
JSONArray pointArray = new JSONArray();
pointArray.set(0, new JSONNumber(point[0].doubleValue()));
pointArray.set(1, new JSONNumber(point[1].doubleValue()));
@@ -579,11 +658,8 @@ public class Series extends Configurable<Series> {
}
nativeSetData(nativeSeries, jsonArray.getJavaScriptObject(), redraw);
}
} else {
for (Number[] xyValue : values) {
this.addPoint(xyValue[0], xyValue[1]);
}
}
return this;
}
@@ -608,6 +684,13 @@ public class Series extends Configurable<Series> {
*/
public Series setPoints(Point[] points, boolean redraw) {
this.points.clear();
// If persistence is enabled than we need to store the point locally as well (so we have it if
// the chart is dynamically moved to another panel).
if (!isRendered() || chart.isPersistent()) {
Collections.addAll(this.points, points);
}
if (isRendered()) {
final JavaScriptObject nativeSeries = chart.get(this.id);
if (nativeSeries != null) {
@@ -617,9 +700,8 @@ public class Series extends Configurable<Series> {
}
nativeSetData(nativeSeries, jsonArray.getJavaScriptObject(), redraw);
}
} else {
Collections.addAll(this.points, points);
}
return this;
}
@@ -645,7 +727,7 @@ public class Series extends Configurable<Series> {
}
}
}
return convertedPoints.toArray(new Point[points.size()]);
return convertedPoints.toArray(new Point[convertedPoints.size()]);
}
/**
@@ -741,7 +823,9 @@ public class Series extends Configurable<Series> {
// Purposefully setting to package scope
void clearInternalPointsList() {
this.points.clear();
if (!chart.isPersistent()) {
this.points.clear();
}
}
boolean rendered = false;