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.CategorySeries;
\r
19 import org.achartengine.renderer.DefaultRenderer;
\r
20 import org.achartengine.renderer.SimpleSeriesRenderer;
\r
22 import android.graphics.Canvas;
\r
23 import android.graphics.Paint;
\r
24 import android.graphics.Paint.Align;
\r
27 * An abstract class to be extended by round like chart rendering classes.
\r
29 public abstract class RoundChart extends AbstractChart {
\r
30 /** The legend shape width. */
\r
31 protected static final int SHAPE_WIDTH = 10;
\r
32 /** The series dataset. */
\r
33 protected CategorySeries mDataset;
\r
34 /** The series renderer. */
\r
35 protected DefaultRenderer mRenderer;
\r
36 /** A no value constant. */
\r
37 protected static final int NO_VALUE = Integer.MAX_VALUE;
\r
38 /** The chart center X axis. */
\r
39 protected int mCenterX = NO_VALUE;
\r
40 /** The chart center y axis. */
\r
41 protected int mCenterY = NO_VALUE;
\r
46 * @param dataset the series dataset
\r
47 * @param renderer the series renderer
\r
49 public RoundChart(CategorySeries dataset, DefaultRenderer renderer) {
\r
51 mRenderer = renderer;
\r
55 * The graphical representation of the round chart title.
\r
57 * @param canvas the canvas to paint to
\r
58 * @param x the top left x value of the view to draw to
\r
59 * @param y the top left y value of the view to draw to
\r
60 * @param width the width of the view to draw to
\r
61 * @param paint the paint
\r
63 public void drawTitle(Canvas canvas, int x, int y, int width, Paint paint) {
\r
64 if (mRenderer.isShowLabels()) {
\r
65 paint.setColor(mRenderer.getLabelsColor());
\r
66 paint.setTextAlign(Align.CENTER);
\r
67 paint.setTextSize(mRenderer.getChartTitleTextSize());
\r
68 drawString(canvas, mRenderer.getChartTitle(), x + width / 2,
\r
69 y + mRenderer.getChartTitleTextSize(), paint);
\r
74 * Returns the legend shape width.
\r
76 * @param seriesIndex the series index
\r
77 * @return the legend shape width
\r
79 public int getLegendShapeWidth(int seriesIndex) {
\r
84 * The graphical representation of the legend shape.
\r
86 * @param canvas the canvas to paint to
\r
87 * @param renderer the series renderer
\r
88 * @param x the x value of the point the shape should be drawn at
\r
89 * @param y the y value of the point the shape should be drawn at
\r
90 * @param seriesIndex the series index
\r
91 * @param paint the paint to be used for drawing
\r
93 public void drawLegendShape(Canvas canvas, SimpleSeriesRenderer renderer, float x, float y,
\r
94 int seriesIndex, Paint paint) {
\r
95 canvas.drawRect(x, y - SHAPE_WIDTH / 2, x + SHAPE_WIDTH, y + SHAPE_WIDTH / 2, paint);
\r
99 * Returns the renderer.
\r
101 * @return the renderer
\r
103 public DefaultRenderer getRenderer() {
\r
108 * Returns the center on X axis.
\r
110 * @return the center on X axis
\r
112 public int getCenterX() {
\r
117 * Returns the center on Y axis.
\r
119 * @return the center on Y axis
\r
121 public int getCenterY() {
\r
126 * Sets a new center on X axis.
\r
128 * @param centerX center on X axis
\r
130 public void setCenterX(int centerX) {
\r
131 mCenterX = centerX;
\r
135 * Sets a new center on Y axis.
\r
137 * @param centerY center on Y axis
\r
139 public void setCenterY(int centerY) {
\r
140 mCenterY = centerY;
\r