Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / android-libraries / achartengine / src / org / achartengine / chart / BubbleChart.java
diff --git a/android-libraries/achartengine/src/org/achartengine/chart/BubbleChart.java b/android-libraries/achartengine/src/org/achartengine/chart/BubbleChart.java
new file mode 100644 (file)
index 0000000..f312571
--- /dev/null
@@ -0,0 +1,146 @@
+/**\r
+ * Copyright (C) 2009 - 2012 SC 4ViewSoft SRL\r
+ *  \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *  \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *  \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.achartengine.chart;\r
+\r
+import org.achartengine.model.XYMultipleSeriesDataset;\r
+import org.achartengine.model.XYValueSeries;\r
+import org.achartengine.renderer.SimpleSeriesRenderer;\r
+import org.achartengine.renderer.XYMultipleSeriesRenderer;\r
+import org.achartengine.renderer.XYSeriesRenderer;\r
+\r
+import android.graphics.Canvas;\r
+import android.graphics.Paint;\r
+import android.graphics.Paint.Style;\r
+import android.graphics.RectF;\r
+\r
+/**\r
+ * The bubble chart rendering class.\r
+ */\r
+public class BubbleChart extends XYChart {\r
+  /** The constant to identify this chart type. */\r
+  public static final String TYPE = "Bubble";\r
+  /** The legend shape width. */\r
+  private static final int SHAPE_WIDTH = 10;\r
+  /** The minimum bubble size. */\r
+  private static final int MIN_BUBBLE_SIZE = 2;\r
+  /** The maximum bubble size. */\r
+  private static final int MAX_BUBBLE_SIZE = 20;\r
+\r
+  BubbleChart() {\r
+  }\r
+\r
+  /**\r
+   * Builds a new bubble chart instance.\r
+   * \r
+   * @param dataset the multiple series dataset\r
+   * @param renderer the multiple series renderer\r
+   */\r
+  public BubbleChart(XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer) {\r
+    super(dataset, renderer);\r
+  }\r
+\r
+  /**\r
+   * The graphical representation of a series.\r
+   * \r
+   * @param canvas the canvas to paint to\r
+   * @param paint the paint to be used for drawing\r
+   * @param points the array of points to be used for drawing the series\r
+   * @param seriesRenderer the series renderer\r
+   * @param yAxisValue the minimum value of the y axis\r
+   * @param seriesIndex the index of the series currently being drawn\r
+   * @param startIndex the start index of the rendering points\r
+   */\r
+  public void drawSeries(Canvas canvas, Paint paint, float[] points,\r
+      SimpleSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, int startIndex) {\r
+    XYSeriesRenderer renderer = (XYSeriesRenderer) seriesRenderer;\r
+    paint.setColor(renderer.getColor());\r
+    paint.setStyle(Style.FILL);\r
+    int length = points.length;\r
+    XYValueSeries series = (XYValueSeries) mDataset.getSeriesAt(seriesIndex);\r
+    double max = series.getMaxValue();\r
+    double coef = MAX_BUBBLE_SIZE / max;\r
+    for (int i = 0; i < length; i += 2) {\r
+      double size = series.getValue(startIndex + i / 2) * coef + MIN_BUBBLE_SIZE;\r
+      drawCircle(canvas, paint, points[i], points[i + 1], (float) size);\r
+    }\r
+  }\r
+\r
+  @Override\r
+  protected ClickableArea[] clickableAreasForPoints(float[] points, double[] values,\r
+      float yAxisValue, int seriesIndex, int startIndex) {\r
+    int length = points.length;\r
+    XYValueSeries series = (XYValueSeries) mDataset.getSeriesAt(seriesIndex);\r
+    double max = series.getMaxValue();\r
+    double coef = MAX_BUBBLE_SIZE / max;\r
+    ClickableArea[] ret = new ClickableArea[length / 2];\r
+    for (int i = 0; i < length; i += 2) {\r
+      double size = series.getValue(startIndex + i / 2) * coef + MIN_BUBBLE_SIZE;\r
+      ret[i / 2] = new ClickableArea(new RectF(points[i] - (float) size, points[i + 1]\r
+          - (float) size, points[i] + (float) size, points[i + 1] + (float) size), values[i],\r
+          values[i + 1]);\r
+    }\r
+    return ret;\r
+  }\r
+\r
+  /**\r
+   * Returns the legend shape width.\r
+   * \r
+   * @param seriesIndex the series index\r
+   * @return the legend shape width\r
+   */\r
+  public int getLegendShapeWidth(int seriesIndex) {\r
+    return SHAPE_WIDTH;\r
+  }\r
+\r
+  /**\r
+   * The graphical representation of the legend shape.\r
+   * \r
+   * @param canvas the canvas to paint to\r
+   * @param renderer the series renderer\r
+   * @param x the x value of the point the shape should be drawn at\r
+   * @param y the y value of the point the shape should be drawn at\r
+   * @param seriesIndex the series index\r
+   * @param paint the paint to be used for drawing\r
+   */\r
+  public void drawLegendShape(Canvas canvas, SimpleSeriesRenderer renderer, float x, float y,\r
+      int seriesIndex, Paint paint) {\r
+    paint.setStyle(Style.FILL);\r
+    drawCircle(canvas, paint, x + SHAPE_WIDTH, y, 3);\r
+  }\r
+\r
+  /**\r
+   * The graphical representation of a circle point shape.\r
+   * \r
+   * @param canvas the canvas to paint to\r
+   * @param paint the paint to be used for drawing\r
+   * @param x the x value of the point the shape should be drawn at\r
+   * @param y the y value of the point the shape should be drawn at\r
+   * @param radius the bubble radius\r
+   */\r
+  private void drawCircle(Canvas canvas, Paint paint, float x, float y, float radius) {\r
+    canvas.drawCircle(x, y, radius, paint);\r
+  }\r
+\r
+  /**\r
+   * Returns the chart type identifier.\r
+   * \r
+   * @return the chart type\r
+   */\r
+  public String getChartType() {\r
+    return TYPE;\r
+  }\r
+\r
+}
\ No newline at end of file