2 * Copyright (C) 2009 - 2012 SC 4ViewSoft SRL
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
16 package org.achartengine.chart;
\r
18 import org.achartengine.model.XYMultipleSeriesDataset;
\r
19 import org.achartengine.model.XYSeries;
\r
20 import org.achartengine.renderer.SimpleSeriesRenderer;
\r
21 import org.achartengine.renderer.XYMultipleSeriesRenderer;
\r
23 import android.graphics.Canvas;
\r
24 import android.graphics.Paint;
\r
25 import android.graphics.Paint.Style;
\r
28 * The range bar chart rendering class.
\r
30 public class RangeBarChart extends BarChart {
\r
31 /** The chart type. */
\r
32 public static final String TYPE = "RangeBar";
\r
37 RangeBarChart(Type type) {
\r
42 * Builds a new range bar chart instance.
\r
44 * @param dataset the multiple series dataset
\r
45 * @param renderer the multiple series renderer
\r
46 * @param type the range bar chart type
\r
48 public RangeBarChart(XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer renderer, Type type) {
\r
49 super(dataset, renderer, type);
\r
53 * The graphical representation of a series.
\r
55 * @param canvas the canvas to paint to
\r
56 * @param paint the paint to be used for drawing
\r
57 * @param points the array of points to be used for drawing the series
\r
58 * @param seriesRenderer the series renderer
\r
59 * @param yAxisValue the minimum value of the y axis
\r
60 * @param seriesIndex the index of the series currently being drawn
\r
61 * @param startIndex the start index of the rendering points
\r
63 public void drawSeries(Canvas canvas, Paint paint, float[] points,
\r
64 SimpleSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, int startIndex) {
\r
65 int seriesNr = mDataset.getSeriesCount();
\r
66 int length = points.length;
\r
67 paint.setColor(seriesRenderer.getColor());
\r
68 paint.setStyle(Style.FILL);
\r
69 float halfDiffX = getHalfDiffX(points, length, seriesNr);
\r
71 if (startIndex > 0) {
\r
74 for (int i = start; i < length; i += 4) {
\r
75 if (points.length > i + 3) {
\r
76 float xMin = points[i];
\r
77 float yMin = points[i + 1];
\r
79 float xMax = points[i + 2];
\r
80 float yMax = points[i + 3];
\r
81 drawBar(canvas, xMin, yMin, xMax, yMax, halfDiffX, seriesNr, seriesIndex, paint);
\r
84 paint.setColor(seriesRenderer.getColor());
\r
88 * The graphical representation of the series values as text.
\r
90 * @param canvas the canvas to paint to
\r
91 * @param series the series to be painted
\r
92 * @param renderer the series renderer
\r
93 * @param paint the paint to be used for drawing
\r
94 * @param points the array of points to be used for drawing the series
\r
95 * @param seriesIndex the index of the series currently being drawn
\r
96 * @param startIndex the start index of the rendering points
\r
98 protected void drawChartValuesText(Canvas canvas, XYSeries series, SimpleSeriesRenderer renderer,
\r
99 Paint paint, float[] points, int seriesIndex, int startIndex) {
\r
100 int seriesNr = mDataset.getSeriesCount();
\r
101 float halfDiffX = getHalfDiffX(points, points.length, seriesNr);
\r
103 if (startIndex > 0) {
\r
106 for (int i = start; i < points.length; i += 4) {
\r
107 int index = startIndex + i / 2;
\r
108 float x = points[i];
\r
109 if (mType == Type.DEFAULT) {
\r
110 x += seriesIndex * 2 * halfDiffX - (seriesNr - 1.5f) * halfDiffX;
\r
113 if (!isNullValue(series.getY(index + 1)) && points.length > i + 3) {
\r
114 // draw the maximum value
\r
115 drawText(canvas, getLabel(series.getY(index + 1)), x,
\r
116 points[i + 3] - renderer.getChartValuesSpacing(), paint, 0);
\r
118 if (!isNullValue(series.getY(index)) && points.length > i + 1) {
\r
119 // draw the minimum value
\r
120 drawText(canvas, getLabel(series.getY(index)), x,
\r
121 points[i + 1] + renderer.getChartValuesTextSize() + renderer.getChartValuesSpacing()
\r
128 * Returns the value of a constant used to calculate the half-distance.
\r
130 * @return the constant value
\r
132 protected float getCoeficient() {
\r
137 * Returns the chart type identifier.
\r
139 * @return the chart type
\r
141 public String getChartType() {
\r