Replace specific item types with generic DataItem
Using a generic DataItem allows to re-use the same data for different
chart types.
For charts that require two-dimensional data points (like LineChart),
add DataItem2D that adds an x value and use the super type's value as y.
LineChart can also use DataItem, in this case the x value will be the
index.
Change-Id: If0a275424be518778273311d4a1e091569da9141
diff --git a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/BarChart.java b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/BarChart.java
index 85a6bde..a78cb56 100644
--- a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/BarChart.java
+++ b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/BarChart.java
@@ -10,6 +10,8 @@
******************************************************************************/
package org.eclipse.rap.addons.chart.basic;
+import static org.eclipse.rap.addons.chart.internal.ColorUtil.toHtmlString;
+
import org.eclipse.rap.addons.chart.NvChart;
import org.eclipse.rap.json.JsonArray;
import org.eclipse.rap.json.JsonObject;
@@ -67,12 +69,23 @@
*
* @param items the data items to display
*/
- public void setItems( BarItem... items ) {
+ public void setItems( DataItem... items ) {
JsonArray values = new JsonArray();
- for( BarItem item : items ) {
- values.add( item.toJson() );
+ for( DataItem item : items ) {
+ values.add( toJson( item ) );
}
setItems( new JsonArray().add( new JsonObject().add( "values", values ) ) );
}
+ private static JsonObject toJson( DataItem item ) {
+ JsonObject json = new JsonObject().add( "value", item.value );
+ if( item.text != null ) {
+ json.add( "label", item.text );
+ }
+ if( item.color != null ) {
+ json.add( "color", toHtmlString( item.color ) );
+ }
+ return json;
+ }
+
}
diff --git a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/BarItem.java b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/BarItem.java
deleted file mode 100644
index b709f7e..0000000
--- a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/BarItem.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 EclipseSource and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Ralf Sternberg - initial API and implementation
- ******************************************************************************/
-package org.eclipse.rap.addons.chart.basic;
-
-import static org.eclipse.rap.addons.chart.internal.ColorUtil.toHtmlString;
-
-import org.eclipse.rap.json.JsonObject;
-import org.eclipse.swt.graphics.RGB;
-
-
-/**
- * Represents a bar in a bar chart.
- *
- * @see BarChart
- */
-public class BarItem {
-
- protected final double value;
- protected final String text;
- protected final RGB color;
-
- /**
- * Create a new bar item with the given value and text.
- *
- * @param value the value of the item, affects the size of the bar
- * @param text the label text for the item, or <code>null</code> to omit the label
- */
- public BarItem( double value, String text ) {
- this( value, text, null );
- }
-
- /**
- * Create a new bar item with the given value, text, and color.
- *
- * @param value the value of the item, affects the size of the bar
- * @param text the label text for the item, or <code>null</code> to omit the label
- * @param color the color of this item, or <code>null</code> to use the default color
- */
- public BarItem( double value, String text, RGB color ) {
- this.value = value;
- this.text = text;
- this.color = color;
- }
-
- protected JsonObject toJson() {
- JsonObject json = new JsonObject().add( "value", value );
- if( text != null ) {
- json.add( "label", text );
- }
- if( color != null ) {
- json.add( "color", toHtmlString( color ) );
- }
- return json;
- }
-
-}
diff --git a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/DataGroup.java b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/DataGroup.java
new file mode 100644
index 0000000..60119bc
--- /dev/null
+++ b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/DataGroup.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2016 EclipseSource and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ralf Sternberg - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.rap.addons.chart.basic;
+
+import org.eclipse.swt.graphics.RGB;
+
+
+/**
+ * Represents a series of data items in a chart.
+ */
+public class DataGroup {
+
+ protected final DataItem[] items;
+ protected final String text;
+ protected final RGB color;
+
+ /**
+ * Create a new group of data items with the given text.
+ *
+ * @param items the items of the group
+ * @param text the label text for the group, or <code>null</code> to omit the label
+ */
+ public DataGroup( DataItem[] items, String text ) {
+ this( items, text, null );
+ }
+
+ /**
+ * Create a new group of data items with the given text and color.
+ *
+ * @param items the items of the group
+ * @param text the label text for the group, or <code>null</code> to omit the label
+ * @param color the color of this group, or <code>null</code> to use the default color
+ */
+ public DataGroup( DataItem[] items, String text, RGB color ) {
+ this.items = items;
+ this.text = text;
+ this.color = color;
+ }
+
+}
diff --git a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/DataItem.java b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/DataItem.java
new file mode 100644
index 0000000..e9dbac8
--- /dev/null
+++ b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/DataItem.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2016 EclipseSource and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ralf Sternberg - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.rap.addons.chart.basic;
+
+import org.eclipse.swt.graphics.RGB;
+
+
+/**
+ * Represents a data item in a chart.
+ */
+public class DataItem {
+
+ protected final double value;
+ protected final String text;
+ protected final RGB color;
+
+ /**
+ * Create a new data item with the given value.
+ *
+ * @param value the value of the item
+ */
+ public DataItem( double value ) {
+ this( value, null );
+ }
+
+ /**
+ * Create a new data item with the given value and text.
+ *
+ * @param value the value of the item
+ * @param text the label text for the item, or <code>null</code> to omit the label
+ */
+ public DataItem( double value, String text ) {
+ this( value, text, null );
+ }
+
+ /**
+ * Create a new data item with the given value, text, and color.
+ *
+ * @param value the value of the item
+ * @param text the label text for the item, or <code>null</code> to omit the label
+ * @param color the color of this item, or <code>null</code> to use the default color
+ */
+ public DataItem( double value, String text, RGB color ) {
+ this.value = value;
+ this.text = text;
+ this.color = color;
+ }
+
+ /**
+ * Returns the value of this data item.
+ *
+ * @return the item value
+ */
+ public double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns the text for this data item.
+ *
+ * @return the item text, can be <code>null</code>
+ */
+ public String getText() {
+ return text;
+ }
+
+ /**
+ * Returns the color for this data item.
+ *
+ * @return the item color, can be <code>null</code>
+ */
+ public RGB getColor() {
+ return color;
+ }
+
+}
diff --git a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/DataItem2D.java b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/DataItem2D.java
new file mode 100644
index 0000000..acbbc7f
--- /dev/null
+++ b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/DataItem2D.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2016 EclipseSource and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ralf Sternberg - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.rap.addons.chart.basic;
+
+import org.eclipse.swt.graphics.RGB;
+
+
+/**
+ * Represents a two-dimensional data item in a chart.
+ */
+public class DataItem2D extends DataItem {
+
+ protected final double x;
+
+ /**
+ * Create a new data item with the given values.
+ *
+ * @param x the x value of the item
+ * @param y the y value of the item
+ */
+ public DataItem2D( double x, double y ) {
+ this( x, y, null );
+ }
+
+ /**
+ * Create a new data item with the given values and text.
+ *
+ * @param x the x value of the item
+ * @param y the y value of the item
+ * @param text the label text for the item, or <code>null</code> to omit the label
+ */
+ public DataItem2D( double x, double y, String text ) {
+ this( x, y, text, null );
+ }
+
+ /**
+ * Create a new data item with the given values, text, and color.
+ *
+ * @param x the x value of the item
+ * @param y the y value of the item
+ * @param text the label text for the item, or <code>null</code> to omit the label
+ * @param color the color of this item, or <code>null</code> to use the default color
+ */
+ public DataItem2D( double x, double y, String text, RGB color ) {
+ super( y, text, color );
+ this.x = x;
+ }
+
+ /**
+ * Returns the x value of this data item.
+ *
+ * @return the item's x value
+ */
+ public double getX() {
+ return x;
+ }
+
+ /**
+ * Returns the y value of this data item.
+ *
+ * @return the item's y value
+ */
+ public double getY() {
+ return value;
+ }
+
+}
diff --git a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/DataPoint.java b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/DataPoint.java
deleted file mode 100644
index 9b16af4..0000000
--- a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/DataPoint.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 EclipseSource and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Ralf Sternberg - initial API and implementation
- ******************************************************************************/
-package org.eclipse.rap.addons.chart.basic;
-
-import org.eclipse.rap.json.JsonObject;
-
-
-/**
- * Represents a data point in a Cartesian plane.
- */
-public class DataPoint {
-
- /**
- * the x coordinate of the point
- */
- public final double x;
-
- /**
- * the y coordinate of the point
- */
- public final double y;
-
- /**
- * Creates a new data point with the given coordinates.
- *
- * @param x the x coordinate of this point
- * @param y the y coordinate of this point
- */
- public DataPoint( double x, double y ) {
- this.x = x;
- this.y = y;
- }
-
- protected JsonObject toJson() {
- return new JsonObject().add( "x", x ).add( "y", y );
- }
-
-}
diff --git a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/LineChart.java b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/LineChart.java
index 5b4067d..9bc183b 100644
--- a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/LineChart.java
+++ b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/LineChart.java
@@ -10,8 +10,11 @@
******************************************************************************/
package org.eclipse.rap.addons.chart.basic;
+import static org.eclipse.rap.addons.chart.internal.ColorUtil.toHtmlString;
+
import org.eclipse.rap.addons.chart.NvChart;
import org.eclipse.rap.json.JsonArray;
+import org.eclipse.rap.json.JsonObject;
import org.eclipse.swt.widgets.Composite;
@@ -142,12 +145,33 @@
*
* @param items the data items to display
*/
- public void setItems( LineItem... items ) {
+ public void setItems( DataGroup... items ) {
JsonArray values = new JsonArray();
- for( LineItem item : items ) {
- values.add( item.toJson() );
+ for( DataGroup item : items ) {
+ values.add( toJson( item ) );
}
setItems( values );
}
+ private static JsonObject toJson( DataGroup group ) {
+ JsonArray values = new JsonArray();
+ for( int i = 0; i < group.items.length; i++ ) {
+ DataItem item = group.items[ i ];
+ if( item instanceof DataItem2D ) {
+ DataItem2D item2d = ( DataItem2D )item;
+ values.add( new JsonObject().add( "x", item2d.getX() ).add( "y", item2d.getY() ) );
+ } else {
+ values.add( new JsonObject().add( "x", i ).add( "y", item.getValue() ) );
+ }
+ }
+ JsonObject json = new JsonObject().add( "values", values );
+ if( group.text != null ) {
+ json.add( "key", group.text );
+ }
+ if( group.color != null ) {
+ json.add( "color", toHtmlString( group.color ) );
+ }
+ return json;
+ }
+
}
diff --git a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/LineItem.java b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/LineItem.java
deleted file mode 100644
index 50a02a9..0000000
--- a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/LineItem.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 EclipseSource and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Ralf Sternberg - initial API and implementation
- ******************************************************************************/
-package org.eclipse.rap.addons.chart.basic;
-
-import static org.eclipse.rap.addons.chart.internal.ColorUtil.toHtmlString;
-
-import org.eclipse.rap.json.JsonArray;
-import org.eclipse.rap.json.JsonObject;
-import org.eclipse.swt.graphics.RGB;
-
-
-/**
- * Represents a line in a line chart.
- *
- * @see LineChart
- */
-public class LineItem {
-
- protected final DataPoint[] points;
- protected final String text;
- protected final RGB color;
-
- /**
- * Creates a line with the given data points and text. Later changes to the data points won't be
- * reflected in the chart.
- *
- * @param points the data point that form the line
- * @param text the label text for the line, or <code>null</code> to omit the label
- */
- public LineItem( DataPoint[] points, String text ) {
- this( points, text, null );
- }
-
- /**
- * Creates a line with the given data points, text, and color. Later changes to the data points
- * won't be reflected in the chart.
- *
- * @param points the data point that form the line
- * @param text the label text for the line, or <code>null</code> to omit the label
- * @param color the color of this line, or <code>null</code> to use the default color
- */
- public LineItem( DataPoint[] points, String text, RGB color ) {
- this.points = points;
- this.text = text;
- this.color = color;
- }
-
- protected JsonObject toJson() {
- JsonArray values = new JsonArray();
- for( DataPoint point : points ) {
- values.add( point.toJson() );
- }
- JsonObject json = new JsonObject().add( "values", values );
- if( text != null ) {
- json.add( "key", text );
- }
- if( color != null ) {
- json.add( "color", toHtmlString( color ) );
- }
- return json;
- }
-
-}
diff --git a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/PieChart.java b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/PieChart.java
index 36ccac3..cd116fa 100644
--- a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/PieChart.java
+++ b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/PieChart.java
@@ -10,8 +10,11 @@
******************************************************************************/
package org.eclipse.rap.addons.chart.basic;
+import static org.eclipse.rap.addons.chart.internal.ColorUtil.toHtmlString;
+
import org.eclipse.rap.addons.chart.NvChart;
import org.eclipse.rap.json.JsonArray;
+import org.eclipse.rap.json.JsonObject;
import org.eclipse.swt.widgets.Composite;
@@ -89,12 +92,23 @@
*
* @param items the data items to display
*/
- public void setItems( PieItem... items ) {
+ public void setItems( DataItem... items ) {
JsonArray values = new JsonArray();
- for( PieItem item : items ) {
- values.add( item.toJson() );
+ for( DataItem item : items ) {
+ values.add( toJson( item ) );
}
setItems( values );
}
+ private static JsonObject toJson( DataItem item ) {
+ JsonObject json = new JsonObject().add( "value", item.value );
+ if( item.text != null ) {
+ json.add( "label", item.text );
+ }
+ if( item.color != null ) {
+ json.add( "color", toHtmlString( item.color ) );
+ }
+ return json;
+ }
+
}
diff --git a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/PieItem.java b/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/PieItem.java
deleted file mode 100644
index 295f746..0000000
--- a/bundles/org.eclipse.rap.addons.chart/src/org/eclipse/rap/addons/chart/basic/PieItem.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 EclipseSource and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Ralf Sternberg - initial API and implementation
- ******************************************************************************/
-package org.eclipse.rap.addons.chart.basic;
-
-import static org.eclipse.rap.addons.chart.internal.ColorUtil.toHtmlString;
-
-import org.eclipse.rap.json.JsonObject;
-import org.eclipse.swt.graphics.RGB;
-
-
-/**
- * Represents a segment of a pie/donut chart.
- *
- * @see PieChart
- */
-public class PieItem {
-
- protected final double value;
- protected final String text;
- protected final RGB color;
-
- /**
- * Create a new pie item with the given value and text.
- *
- * @param value the value of the item, affects the size of the section, should not be negative
- * @param text the label text for the item, or <code>null</code> to omit the label
- */
- public PieItem( double value, String text ) {
- this( value, text, null );
- }
-
- /**
- * Create a new pie item with the given value, text, and color.
- *
- * @param value the value of the item, affects the size of the section, should not be negative
- * @param text the label text for the item, or <code>null</code> to omit the label
- * @param color the color of this section, or <code>null</code> to use the default color
- */
- public PieItem( double value, String text, RGB color ) {
- this.value = value;
- this.text = text;
- this.color = color;
- }
-
- protected JsonObject toJson() {
- JsonObject json = new JsonObject().add( "value", value );
- if( text != null ) {
- json.add( "label", text );
- }
- if( color != null ) {
- json.add( "color", toHtmlString( color ) );
- }
- return json;
- }
-
-}
diff --git a/examples/org.eclipse.rap.addons.chart.demo/src/org/eclipse/rap/addons/chart/demo/BarChartSnippet.java b/examples/org.eclipse.rap.addons.chart.demo/src/org/eclipse/rap/addons/chart/demo/BarChartSnippet.java
index ea065d8..39e0d30 100644
--- a/examples/org.eclipse.rap.addons.chart.demo/src/org/eclipse/rap/addons/chart/demo/BarChartSnippet.java
+++ b/examples/org.eclipse.rap.addons.chart.demo/src/org/eclipse/rap/addons/chart/demo/BarChartSnippet.java
@@ -13,7 +13,7 @@
import static org.eclipse.rap.addons.chart.demo.Colors.CAT10_COLORS;
import org.eclipse.rap.addons.chart.basic.BarChart;
-import org.eclipse.rap.addons.chart.basic.BarItem;
+import org.eclipse.rap.addons.chart.basic.DataItem;
import org.eclipse.rap.rwt.application.AbstractEntryPoint;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
@@ -62,13 +62,13 @@
barChart.setItems( createItems() );
}
- private static BarItem[] createItems() {
- return new BarItem[] {
- new BarItem( Math.random() * 100, "Item 1", CAT10_COLORS[ 0 ] ),
- new BarItem( Math.random() * 100, "Item 2", CAT10_COLORS[ 1 ] ),
- new BarItem( Math.random() * 100, "Item 3", CAT10_COLORS[ 2 ] ),
- new BarItem( Math.random() * 100, "Item 4", CAT10_COLORS[ 3 ] ),
- new BarItem( Math.random() * 100, "Item 5", CAT10_COLORS[ 4 ] )
+ private static DataItem[] createItems() {
+ return new DataItem[] {
+ new DataItem( Math.random() * 100, "Item 1", CAT10_COLORS[ 0 ] ),
+ new DataItem( Math.random() * 100, "Item 2", CAT10_COLORS[ 1 ] ),
+ new DataItem( Math.random() * 100, "Item 3", CAT10_COLORS[ 2 ] ),
+ new DataItem( Math.random() * 100, "Item 4", CAT10_COLORS[ 3 ] ),
+ new DataItem( Math.random() * 100, "Item 5", CAT10_COLORS[ 4 ] )
};
}
diff --git a/examples/org.eclipse.rap.addons.chart.demo/src/org/eclipse/rap/addons/chart/demo/LineChartSnippet.java b/examples/org.eclipse.rap.addons.chart.demo/src/org/eclipse/rap/addons/chart/demo/LineChartSnippet.java
index 895d96c..9627e0b 100644
--- a/examples/org.eclipse.rap.addons.chart.demo/src/org/eclipse/rap/addons/chart/demo/LineChartSnippet.java
+++ b/examples/org.eclipse.rap.addons.chart.demo/src/org/eclipse/rap/addons/chart/demo/LineChartSnippet.java
@@ -12,9 +12,9 @@
import static org.eclipse.rap.addons.chart.demo.Colors.CAT10_COLORS;
-import org.eclipse.rap.addons.chart.basic.DataPoint;
import org.eclipse.rap.addons.chart.basic.LineChart;
-import org.eclipse.rap.addons.chart.basic.LineItem;
+import org.eclipse.rap.addons.chart.basic.DataGroup;
+import org.eclipse.rap.addons.chart.basic.DataItem;
import org.eclipse.rap.rwt.application.AbstractEntryPoint;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
@@ -66,17 +66,17 @@
lineChart.setItems( createItems() );
}
- private static LineItem[] createItems() {
- return new LineItem[] {
- new LineItem( createRandomPoints(), "Series 1", CAT10_COLORS[ 0 ] ),
- new LineItem( createRandomPoints(), "Series 2", CAT10_COLORS[ 1 ] )
+ private static DataGroup[] createItems() {
+ return new DataGroup[] {
+ new DataGroup( createRandomPoints(), "Series 1", CAT10_COLORS[ 0 ] ),
+ new DataGroup( createRandomPoints(), "Series 2", CAT10_COLORS[ 1 ] )
};
}
- private static DataPoint[] createRandomPoints() {
- DataPoint[] values = new DataPoint[100];
+ private static DataItem[] createRandomPoints() {
+ DataItem[] values = new DataItem[100];
for( int i = 0; i < values.length; i++ ) {
- values[i] = new DataPoint( i, Math.random() * 100 );
+ values[i] = new DataItem( Math.random() * 100 );
}
return values;
}
diff --git a/examples/org.eclipse.rap.addons.chart.demo/src/org/eclipse/rap/addons/chart/demo/PieChartSnippet.java b/examples/org.eclipse.rap.addons.chart.demo/src/org/eclipse/rap/addons/chart/demo/PieChartSnippet.java
index 9c29dac..5ffcf27 100644
--- a/examples/org.eclipse.rap.addons.chart.demo/src/org/eclipse/rap/addons/chart/demo/PieChartSnippet.java
+++ b/examples/org.eclipse.rap.addons.chart.demo/src/org/eclipse/rap/addons/chart/demo/PieChartSnippet.java
@@ -11,7 +11,7 @@
package org.eclipse.rap.addons.chart.demo;
-import org.eclipse.rap.addons.chart.basic.PieItem;
+import org.eclipse.rap.addons.chart.basic.DataItem;
import static org.eclipse.rap.addons.chart.demo.Colors.CAT10_COLORS;
@@ -65,13 +65,13 @@
pieChart.setItems( createItems() );
}
- private static PieItem[] createItems() {
- return new PieItem[] {
- new PieItem( Math.random() * 100, "Item 1", CAT10_COLORS[ 0 ] ),
- new PieItem( Math.random() * 100, "Item 2", CAT10_COLORS[ 1 ] ),
- new PieItem( Math.random() * 100, "Item 3", CAT10_COLORS[ 2 ] ),
- new PieItem( Math.random() * 100, "Item 4", CAT10_COLORS[ 3 ] ),
- new PieItem( Math.random() * 100, "Item 5", CAT10_COLORS[ 4 ] )
+ private static DataItem[] createItems() {
+ return new DataItem[] {
+ new DataItem( Math.random() * 100, "Item 1", CAT10_COLORS[ 0 ] ),
+ new DataItem( Math.random() * 100, "Item 2", CAT10_COLORS[ 1 ] ),
+ new DataItem( Math.random() * 100, "Item 3", CAT10_COLORS[ 2 ] ),
+ new DataItem( Math.random() * 100, "Item 4", CAT10_COLORS[ 3 ] ),
+ new DataItem( Math.random() * 100, "Item 5", CAT10_COLORS[ 4 ] )
};
}
diff --git a/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/BarChart_Test.java b/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/BarChart_Test.java
index 63d8672..434982c 100644
--- a/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/BarChart_Test.java
+++ b/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/BarChart_Test.java
@@ -90,7 +90,7 @@
public void testSetItems() {
reset( remoteObject );
- chart.setItems( new BarItem( 23, "foo" ), new BarItem( 42, "bar" ) );
+ chart.setItems( new DataItem( 23, "foo" ), new DataItem( 42, "bar" ) );
String expected = "[ { \"values\": [ { \"value\": 23, \"label\": \"foo\" },"
+ "{ \"value\": 42, \"label\": \"bar\" } ] } ]";
diff --git a/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/BarItem_Test.java b/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/BarItem_Test.java
deleted file mode 100644
index 555c70b..0000000
--- a/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/BarItem_Test.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 EclipseSource and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Ralf Sternberg - initial API and implementation
- ******************************************************************************/
-package org.eclipse.rap.addons.chart.basic;
-
-import static org.junit.Assert.assertEquals;
-
-import org.eclipse.rap.json.JsonObject;
-import org.eclipse.rap.json.JsonValue;
-import org.eclipse.swt.graphics.RGB;
-import org.junit.Test;
-
-
-public class BarItem_Test {
-
- @Test
- public void testToJson() {
- BarItem item = new BarItem( 23, "foo", new RGB( 0, 8, 128 ) );
-
- JsonObject json = item.toJson();
-
- JsonValue expected = parse( "{'value': 23, 'label': 'foo', 'color': '#000880'}" );
- assertEquals( expected, json );
- }
-
- @Test
- public void testToJson_skipsMissingColor() {
- BarItem item = new BarItem( 23, "foo" );
-
- JsonObject json = item.toJson();
-
- JsonValue expected = parse( "{'value': 23, 'label': 'foo'}" );
- assertEquals( expected, json );
- }
-
- @Test
- public void testToJson_skipsMissingText() {
- BarItem item = new BarItem( 23, null, new RGB( 0, 8, 128 ) );
-
- JsonObject json = item.toJson();
-
- JsonValue expected = parse( "{'value': 23, 'color': '#000880'}" );
- assertEquals( expected, json );
- }
-
- private static JsonValue parse( String json ) {
- return JsonValue.readFrom( json.replace( '\'', '"' ) );
- }
-
-}
diff --git a/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/DataPoint_Test.java b/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/DataPoint_Test.java
deleted file mode 100644
index 018e03f..0000000
--- a/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/DataPoint_Test.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 EclipseSource and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Ralf Sternberg - initial API and implementation
- ******************************************************************************/
-package org.eclipse.rap.addons.chart.basic;
-
-import static org.junit.Assert.assertEquals;
-
-import org.eclipse.rap.json.JsonObject;
-import org.junit.Test;
-
-
-public class DataPoint_Test {
-
- @Test
- public void testToJson() {
- DataPoint dataPoint = new DataPoint( 1.41, 3.14 );
-
- JsonObject json = dataPoint.toJson();
-
- assertEquals( new JsonObject().add( "x", 1.41 ).add( "y", 3.14 ), json );
- }
-
-}
diff --git a/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/LineChart_Test.java b/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/LineChart_Test.java
index dc8dfb9..22b74d0 100644
--- a/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/LineChart_Test.java
+++ b/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/LineChart_Test.java
@@ -150,10 +150,10 @@
public void testSetItems() {
reset( remoteObject );
- chart.setItems( new LineItem( new DataPoint[] { new DataPoint( 1, 2 ),
- new DataPoint( 3, 4 ) }, "foo" ),
- new LineItem( new DataPoint[] { new DataPoint( 2, 4 ),
- new DataPoint( 6, 8 ) }, "bar" ) );
+ chart.setItems( new DataGroup( new DataItem2D[] { new DataItem2D( 1, 2 ),
+ new DataItem2D( 3, 4 ) }, "foo" ),
+ new DataGroup( new DataItem2D[] { new DataItem2D( 2, 4 ),
+ new DataItem2D( 6, 8 ) }, "bar" ) );
String expected = "[{ \"values\": [{ \"x\": 1, \"y\": 2 },"
+ "{ \"x\": 3, \"y\": 4 }], \"key\": \"foo\" },"
diff --git a/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/LineItem_Test.java b/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/LineItem_Test.java
deleted file mode 100644
index 0f61ae5..0000000
--- a/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/LineItem_Test.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 EclipseSource and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Ralf Sternberg - initial API and implementation
- ******************************************************************************/
-package org.eclipse.rap.addons.chart.basic;
-
-import static org.junit.Assert.assertEquals;
-
-import org.eclipse.rap.json.JsonObject;
-import org.eclipse.rap.json.JsonValue;
-import org.eclipse.swt.graphics.RGB;
-import org.junit.Test;
-
-
-public class LineItem_Test {
-
- @Test
- public void testToJson() {
- DataPoint[] points = new DataPoint[] { new DataPoint( 1, 2 ), new DataPoint( 3, 4 ) };
- LineItem item = new LineItem( points, "foo", new RGB( 0, 8, 128 ) );
-
- JsonObject json = item.toJson();
-
- JsonValue expected = parse( "{'values': [{'x': 1, 'y': 2}, {'x': 3, 'y': 4}],"
- + "'key': 'foo',"
- + "'color': '#000880'}" );
- assertEquals( expected, json );
- }
-
- @Test
- public void testToJson_skipsMissingColor() {
- DataPoint[] points = new DataPoint[] { new DataPoint( 1, 2 ), new DataPoint( 3, 4 ) };
- LineItem item = new LineItem( points, "foo" );
-
- JsonObject json = item.toJson();
-
- JsonValue expected = parse( "{'values': [{'x': 1, 'y': 2}, {'x': 3, 'y': 4}],"
- + "'key': 'foo'}" );
- assertEquals( expected, json );
- }
-
- @Test
- public void testToJson_skipsMissingText() {
- DataPoint[] points = new DataPoint[] { new DataPoint( 1, 2 ), new DataPoint( 3, 4 ) };
- LineItem item = new LineItem( points, null, new RGB( 0, 8, 128 ) );
-
- JsonObject json = item.toJson();
-
- JsonValue expected = parse( "{'values': [{'x': 1, 'y': 2}, {'x': 3, 'y': 4}],"
- + "'color': '#000880'}" );
- assertEquals( expected, json );
- }
-
- private static JsonValue parse( String json ) {
- return JsonValue.readFrom( json.replace( '\'', '"' ) );
- }
-
-}
diff --git a/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/PieChart_Test.java b/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/PieChart_Test.java
index a00bc66..9e30137 100644
--- a/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/PieChart_Test.java
+++ b/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/PieChart_Test.java
@@ -111,7 +111,7 @@
public void testSetItems() {
reset( remoteObject );
- chart.setItems( new PieItem( 23, "foo" ), new PieItem( 42, "bar" ) );
+ chart.setItems( new DataItem( 23, "foo" ), new DataItem( 42, "bar" ) );
String expected = "[{ \"value\": 23, \"label\": \"foo\" },"
+ "{ \"value\": 42, \"label\": \"bar\" }]";
diff --git a/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/PieItem_Test.java b/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/PieItem_Test.java
deleted file mode 100644
index b06234c..0000000
--- a/tests/org.eclipse.rap.addons.chart.test/src/org/eclipse/rap/addons/chart/basic/PieItem_Test.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 EclipseSource and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Ralf Sternberg - initial API and implementation
- ******************************************************************************/
-package org.eclipse.rap.addons.chart.basic;
-
-import static org.junit.Assert.assertEquals;
-
-import org.eclipse.rap.json.JsonObject;
-import org.eclipse.rap.json.JsonValue;
-import org.eclipse.swt.graphics.RGB;
-import org.junit.Test;
-
-
-public class PieItem_Test {
-
- @Test
- public void testToJson() {
- PieItem item = new PieItem( 23, "foo", new RGB( 0, 8, 128 ) );
-
- JsonObject json = item.toJson();
-
- JsonValue expected = parse( "{'value': 23, 'label': 'foo', 'color': '#000880'}" );
- assertEquals( expected, json );
- }
-
- @Test
- public void testToJson_skipsMissingColor() {
- PieItem item = new PieItem( 23, "foo" );
-
- JsonObject json = item.toJson();
-
- JsonValue expected = parse( "{'value': 23, 'label': 'foo'}" );
- assertEquals( expected, json );
- }
-
- @Test
- public void testToJson_skipsMissingText() {
- PieItem item = new PieItem( 23, null, new RGB( 0, 8, 128 ) );
-
- JsonObject json = item.toJson();
-
- JsonValue expected = parse( "{'value': 23, 'color': '#000880'}" );
- assertEquals( expected, json );
- }
-
- private static JsonValue parse( String json ) {
- return JsonValue.readFrom( json.replace( '\'', '"' ) );
- }
-
-}