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.renderer;
\r
18 import java.io.Serializable;
\r
19 import java.util.ArrayList;
\r
20 import java.util.List;
\r
22 import android.graphics.Color;
\r
23 import android.graphics.Typeface;
\r
26 * An abstract renderer to be extended by the multiple series classes.
\r
28 public class DefaultRenderer implements Serializable {
\r
29 /** The chart title. */
\r
30 private String mChartTitle = "";
\r
31 /** The chart title text size. */
\r
32 private float mChartTitleTextSize = 15;
\r
33 /** A no color constant. */
\r
34 public static final int NO_COLOR = 0;
\r
35 /** The default background color. */
\r
36 public static final int BACKGROUND_COLOR = Color.BLACK;
\r
37 /** The default color for text. */
\r
38 public static final int TEXT_COLOR = Color.LTGRAY;
\r
39 /** A text font for regular text, like the chart labels. */
\r
40 private static final Typeface REGULAR_TEXT_FONT = Typeface
\r
41 .create(Typeface.SERIF, Typeface.NORMAL);
\r
42 /** The typeface name for the texts. */
\r
43 private String mTextTypefaceName = REGULAR_TEXT_FONT.toString();
\r
44 /** The typeface style for the texts. */
\r
45 private int mTextTypefaceStyle = Typeface.NORMAL;
\r
46 /** The chart background color. */
\r
47 private int mBackgroundColor;
\r
48 /** If the background color is applied. */
\r
49 private boolean mApplyBackgroundColor;
\r
50 /** If the axes are visible. */
\r
51 private boolean mShowAxes = true;
\r
52 /** The axes color. */
\r
53 private int mAxesColor = TEXT_COLOR;
\r
54 /** If the labels are visible. */
\r
55 private boolean mShowLabels = true;
\r
56 /** The labels color. */
\r
57 private int mLabelsColor = TEXT_COLOR;
\r
58 /** The labels text size. */
\r
59 private float mLabelsTextSize = 10;
\r
60 /** If the legend is visible. */
\r
61 private boolean mShowLegend = true;
\r
62 /** The legend text size. */
\r
63 private float mLegendTextSize = 12;
\r
64 /** If the legend should size to fit. */
\r
65 private boolean mFitLegend = false;
\r
66 /** If the X axis grid should be displayed. */
\r
67 private boolean mShowGridX = false;
\r
68 /** If the Y axis grid should be displayed. */
\r
69 private boolean mShowGridY = false;
\r
70 /** If the custom text grid should be displayed. */
\r
71 private boolean mShowCustomTextGrid = false;
\r
72 /** The simple renderers that are included in this multiple series renderer. */
\r
73 private List<SimpleSeriesRenderer> mRenderers = new ArrayList<SimpleSeriesRenderer>();
\r
74 /** The antialiasing flag. */
\r
75 private boolean mAntialiasing = true;
\r
76 /** The legend height. */
\r
77 private int mLegendHeight = 0;
\r
78 /** The margins size. */
\r
79 private int[] mMargins = new int[] { 20, 30, 10, 20 };
\r
80 /** A value to be used for scaling the chart. */
\r
81 private float mScale = 1;
\r
82 /** A flag for enabling the pan. */
\r
83 private boolean mPanEnabled = true;
\r
84 /** A flag for enabling the zoom. */
\r
85 private boolean mZoomEnabled = true;
\r
86 /** A flag for enabling the visibility of the zoom buttons. */
\r
87 private boolean mZoomButtonsVisible = false;
\r
88 /** The zoom rate. */
\r
89 private float mZoomRate = 1.5f;
\r
90 /** A flag for enabling the external zoom. */
\r
91 private boolean mExternalZoomEnabled = false;
\r
92 /** The original chart scale. */
\r
93 private float mOriginalScale = mScale;
\r
94 /** A flag for enabling the click on elements. */
\r
95 private boolean mClickEnabled = false;
\r
96 /** The selectable radius around a clickable point. */
\r
97 private int selectableBuffer = 15;
\r
98 /** If the chart should display the values (available for pie chart). */
\r
99 private boolean mDisplayValues;
\r
102 * A flag to be set if the chart is inside a scroll and doesn't need to shrink
\r
103 * when not enough space.
\r
105 private boolean mInScroll;
\r
106 /** The start angle for circular charts such as pie, doughnut, etc. */
\r
107 private float mStartAngle = 0;
\r
110 * Returns the chart title.
\r
112 * @return the chart title
\r
114 public String getChartTitle() {
\r
115 return mChartTitle;
\r
119 * Sets the chart title.
\r
121 * @param title the chart title
\r
123 public void setChartTitle(String title) {
\r
124 mChartTitle = title;
\r
128 * Returns the chart title text size.
\r
130 * @return the chart title text size
\r
132 public float getChartTitleTextSize() {
\r
133 return mChartTitleTextSize;
\r
137 * Sets the chart title text size.
\r
139 * @param textSize the chart title text size
\r
141 public void setChartTitleTextSize(float textSize) {
\r
142 mChartTitleTextSize = textSize;
\r
146 * Adds a simple renderer to the multiple renderer.
\r
148 * @param renderer the renderer to be added
\r
150 public void addSeriesRenderer(SimpleSeriesRenderer renderer) {
\r
151 mRenderers.add(renderer);
\r
155 * Adds a simple renderer to the multiple renderer.
\r
157 * @param index the index in the renderers list
\r
158 * @param renderer the renderer to be added
\r
160 public void addSeriesRenderer(int index, SimpleSeriesRenderer renderer) {
\r
161 mRenderers.add(index, renderer);
\r
165 * Removes a simple renderer from the multiple renderer.
\r
167 * @param renderer the renderer to be removed
\r
169 public void removeSeriesRenderer(SimpleSeriesRenderer renderer) {
\r
170 mRenderers.remove(renderer);
\r
174 * Removes all renderers from the multiple renderer.
\r
176 public void removeAllRenderers() {
\r
177 mRenderers.clear();
\r
181 * Returns the simple renderer from the multiple renderer list.
\r
183 * @param index the index in the simple renderers list
\r
184 * @return the simple renderer at the specified index
\r
186 public SimpleSeriesRenderer getSeriesRendererAt(int index) {
\r
187 return mRenderers.get(index);
\r
191 * Returns the simple renderers count in the multiple renderer list.
\r
193 * @return the simple renderers count
\r
195 public int getSeriesRendererCount() {
\r
196 return mRenderers.size();
\r
200 * Returns an array of the simple renderers in the multiple renderer list.
\r
202 * @return the simple renderers array
\r
204 public SimpleSeriesRenderer[] getSeriesRenderers() {
\r
205 return mRenderers.toArray(new SimpleSeriesRenderer[0]);
\r
209 * Returns the background color.
\r
211 * @return the background color
\r
213 public int getBackgroundColor() {
\r
214 return mBackgroundColor;
\r
218 * Sets the background color.
\r
220 * @param color the background color
\r
222 public void setBackgroundColor(int color) {
\r
223 mBackgroundColor = color;
\r
227 * Returns if the background color should be applied.
\r
229 * @return the apply flag for the background color.
\r
231 public boolean isApplyBackgroundColor() {
\r
232 return mApplyBackgroundColor;
\r
236 * Sets if the background color should be applied.
\r
238 * @param apply the apply flag for the background color
\r
240 public void setApplyBackgroundColor(boolean apply) {
\r
241 mApplyBackgroundColor = apply;
\r
245 * Returns the axes color.
\r
247 * @return the axes color
\r
249 public int getAxesColor() {
\r
254 * Sets the axes color.
\r
256 * @param color the axes color
\r
258 public void setAxesColor(int color) {
\r
259 mAxesColor = color;
\r
263 * Returns the labels color.
\r
265 * @return the labels color
\r
267 public int getLabelsColor() {
\r
268 return mLabelsColor;
\r
272 * Sets the labels color.
\r
274 * @param color the labels color
\r
276 public void setLabelsColor(int color) {
\r
277 mLabelsColor = color;
\r
281 * Returns the labels text size.
\r
283 * @return the labels text size
\r
285 public float getLabelsTextSize() {
\r
286 return mLabelsTextSize;
\r
290 * Sets the labels text size.
\r
292 * @param textSize the labels text size
\r
294 public void setLabelsTextSize(float textSize) {
\r
295 mLabelsTextSize = textSize;
\r
299 * Returns if the axes should be visible.
\r
301 * @return the visibility flag for the axes
\r
303 public boolean isShowAxes() {
\r
308 * Sets if the axes should be visible.
\r
310 * @param showAxes the visibility flag for the axes
\r
312 public void setShowAxes(boolean showAxes) {
\r
313 mShowAxes = showAxes;
\r
317 * Returns if the labels should be visible.
\r
319 * @return the visibility flag for the labels
\r
321 public boolean isShowLabels() {
\r
322 return mShowLabels;
\r
326 * Sets if the labels should be visible.
\r
328 * @param showLabels the visibility flag for the labels
\r
330 public void setShowLabels(boolean showLabels) {
\r
331 mShowLabels = showLabels;
\r
335 * Returns if the X axis grid should be visible.
\r
337 * @return the visibility flag for the X axis grid
\r
339 public boolean isShowGridX() {
\r
344 * Returns if the Y axis grid should be visible.
\r
346 * @return the visibility flag for the Y axis grid
\r
348 public boolean isShowGridY() {
\r
353 * Sets if the X axis grid should be visible.
\r
355 * @param showGrid the visibility flag for the X axis grid
\r
357 public void setShowGridX(boolean showGrid) {
\r
358 mShowGridX = showGrid;
\r
362 * Sets if the Y axis grid should be visible.
\r
364 * @param showGrid the visibility flag for the Y axis grid
\r
366 public void setShowGridY(boolean showGrid) {
\r
367 mShowGridY = showGrid;
\r
371 * Sets if the grid should be visible.
\r
373 * @param showGrid the visibility flag for the grid
\r
375 public void setShowGrid(boolean showGrid) {
\r
376 setShowGridX(showGrid);
\r
377 setShowGridY(showGrid);
\r
381 * Returns if the grid should be visible for custom X or Y labels.
\r
383 * @return the visibility flag for the custom text grid
\r
385 public boolean isShowCustomTextGrid() {
\r
386 return mShowCustomTextGrid;
\r
390 * Sets if the grid for custom X or Y labels should be visible.
\r
392 * @param showGrid the visibility flag for the custom text grid
\r
394 public void setShowCustomTextGrid(boolean showGrid) {
\r
395 mShowCustomTextGrid = showGrid;
\r
399 * Returns if the legend should be visible.
\r
401 * @return the visibility flag for the legend
\r
403 public boolean isShowLegend() {
\r
404 return mShowLegend;
\r
408 * Sets if the legend should be visible.
\r
410 * @param showLegend the visibility flag for the legend
\r
412 public void setShowLegend(boolean showLegend) {
\r
413 mShowLegend = showLegend;
\r
417 * Returns if the legend should size to fit.
\r
419 * @return the fit behavior
\r
421 public boolean isFitLegend() {
\r
426 * Sets if the legend should size to fit.
\r
428 * @param fit the fit behavior
\r
430 public void setFitLegend(boolean fit) {
\r
435 * Returns the text typeface name.
\r
437 * @return the text typeface name
\r
439 public String getTextTypefaceName() {
\r
440 return mTextTypefaceName;
\r
444 * Returns the text typeface style.
\r
446 * @return the text typeface style
\r
448 public int getTextTypefaceStyle() {
\r
449 return mTextTypefaceStyle;
\r
453 * Returns the legend text size.
\r
455 * @return the legend text size
\r
457 public float getLegendTextSize() {
\r
458 return mLegendTextSize;
\r
462 * Sets the legend text size.
\r
464 * @param textSize the legend text size
\r
466 public void setLegendTextSize(float textSize) {
\r
467 mLegendTextSize = textSize;
\r
471 * Sets the text typeface name and style.
\r
473 * @param typefaceName the text typeface name
\r
474 * @param style the text typeface style
\r
476 public void setTextTypeface(String typefaceName, int style) {
\r
477 mTextTypefaceName = typefaceName;
\r
478 mTextTypefaceStyle = style;
\r
482 * Returns the antialiasing flag value.
\r
484 * @return the antialiasing value
\r
486 public boolean isAntialiasing() {
\r
487 return mAntialiasing;
\r
491 * Sets the antialiasing value.
\r
493 * @param antialiasing the antialiasing
\r
495 public void setAntialiasing(boolean antialiasing) {
\r
496 mAntialiasing = antialiasing;
\r
500 * Returns the value to be used for scaling the chart.
\r
502 * @return the scale value
\r
504 public float getScale() {
\r
509 * Returns the original value to be used for scaling the chart.
\r
511 * @return the original scale value
\r
513 public float getOriginalScale() {
\r
514 return mOriginalScale;
\r
518 * Sets the value to be used for scaling the chart. It works on some charts
\r
519 * like pie, doughnut, dial.
\r
521 * @param scale the scale value
\r
523 public void setScale(float scale) {
\r
528 * Returns the enabled state of the zoom.
\r
530 * @return if zoom is enabled
\r
532 public boolean isZoomEnabled() {
\r
533 return mZoomEnabled;
\r
537 * Sets the enabled state of the zoom.
\r
539 * @param enabled zoom enabled
\r
541 public void setZoomEnabled(boolean enabled) {
\r
542 mZoomEnabled = enabled;
\r
546 * Returns the visible state of the zoom buttons.
\r
548 * @return if zoom buttons are visible
\r
550 public boolean isZoomButtonsVisible() {
\r
551 return mZoomButtonsVisible;
\r
555 * Sets the visible state of the zoom buttons.
\r
557 * @param visible if the zoom buttons are visible
\r
559 public void setZoomButtonsVisible(boolean visible) {
\r
560 mZoomButtonsVisible = visible;
\r
564 * Returns the enabled state of the external (application implemented) zoom.
\r
566 * @return if external zoom is enabled
\r
568 public boolean isExternalZoomEnabled() {
\r
569 return mExternalZoomEnabled;
\r
573 * Sets the enabled state of the external (application implemented) zoom.
\r
575 * @param enabled external zoom enabled
\r
577 public void setExternalZoomEnabled(boolean enabled) {
\r
578 mExternalZoomEnabled = enabled;
\r
582 * Returns the zoom rate.
\r
584 * @return the zoom rate
\r
586 public float getZoomRate() {
\r
591 * Returns the enabled state of the pan.
\r
593 * @return if pan is enabled
\r
595 public boolean isPanEnabled() {
\r
596 return mPanEnabled;
\r
600 * Sets the enabled state of the pan.
\r
602 * @param enabled pan enabled
\r
604 public void setPanEnabled(boolean enabled) {
\r
605 mPanEnabled = enabled;
\r
609 * Sets the zoom rate.
\r
611 * @param rate the zoom rate
\r
613 public void setZoomRate(float rate) {
\r
618 * Returns the enabled state of the click.
\r
620 * @return if click is enabled
\r
622 public boolean isClickEnabled() {
\r
623 return mClickEnabled;
\r
627 * Sets the enabled state of the click.
\r
629 * @param enabled click enabled
\r
631 public void setClickEnabled(boolean enabled) {
\r
632 mClickEnabled = enabled;
\r
636 * Returns the selectable radius value around clickable points.
\r
638 * @return the selectable radius
\r
640 public int getSelectableBuffer() {
\r
641 return selectableBuffer;
\r
645 * Sets the selectable radius value around clickable points.
\r
647 * @param buffer the selectable radius
\r
649 public void setSelectableBuffer(int buffer) {
\r
650 selectableBuffer = buffer;
\r
654 * Returns the legend height.
\r
656 * @return the legend height
\r
658 public int getLegendHeight() {
\r
659 return mLegendHeight;
\r
663 * Sets the legend height, in pixels.
\r
665 * @param height the legend height
\r
667 public void setLegendHeight(int height) {
\r
668 mLegendHeight = height;
\r
672 * Returns the margin sizes. An array containing the margins in this order:
\r
673 * top, left, bottom, right
\r
675 * @return the margin sizes
\r
677 public int[] getMargins() {
\r
682 * Sets the margins, in pixels.
\r
684 * @param margins an array containing the margin size values, in this order:
\r
685 * top, left, bottom, right
\r
687 public void setMargins(int[] margins) {
\r
688 mMargins = margins;
\r
692 * Returns if the chart is inside a scroll view and doesn't need to shrink.
\r
694 * @return if it is inside a scroll view
\r
696 public boolean isInScroll() {
\r
701 * To be set if the chart is inside a scroll view and doesn't need to shrink
\r
702 * when not enough space.
\r
704 * @param inScroll if it is inside a scroll view
\r
706 public void setInScroll(boolean inScroll) {
\r
707 mInScroll = inScroll;
\r
711 * Returns the start angle for circular charts such as pie, doughnut. An angle
\r
712 * of 0 degrees correspond to the geometric angle of 0 degrees (3 o'clock on a
\r
715 * @return the start angle in degrees
\r
717 public float getStartAngle() {
\r
718 return mStartAngle;
\r
722 * Sets the start angle for circular charts such as pie, doughnut, etc. An
\r
723 * angle of 0 degrees correspond to the geometric angle of 0 degrees (3
\r
724 * o'clock on a watch.)
\r
726 * @param startAngle the start angle in degrees
\r
728 public void setStartAngle(float startAngle) {
\r
729 mStartAngle = startAngle;
\r
733 * Returns if the values should be displayed as text.
\r
735 * @return if the values should be displayed as text
\r
737 public boolean isDisplayValues() {
\r
738 return mDisplayValues;
\r
742 * Sets if the values should be displayed as text (supported by pie chart).
\r
744 * @param display if the values should be displayed as text
\r
746 public void setDisplayValues(boolean display) {
\r
747 mDisplayValues = display;
\r