create changelog entry
[debian/openrocket] / android-libraries / achartengine / src / org / achartengine / renderer / DefaultRenderer.java
1 /**\r
2  * Copyright (C) 2009 - 2012 SC 4ViewSoft SRL\r
3  *  \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
7  *  \r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *  \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
15  */\r
16 package org.achartengine.renderer;\r
17 \r
18 import java.io.Serializable;\r
19 import java.util.ArrayList;\r
20 import java.util.List;\r
21 \r
22 import android.graphics.Color;\r
23 import android.graphics.Typeface;\r
24 \r
25 /**\r
26  * An abstract renderer to be extended by the multiple series classes.\r
27  */\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
100 \r
101   /**\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
104    */\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
108 \r
109   /**\r
110    * Returns the chart title.\r
111    * \r
112    * @return the chart title\r
113    */\r
114   public String getChartTitle() {\r
115     return mChartTitle;\r
116   }\r
117 \r
118   /**\r
119    * Sets the chart title.\r
120    * \r
121    * @param title the chart title\r
122    */\r
123   public void setChartTitle(String title) {\r
124     mChartTitle = title;\r
125   }\r
126 \r
127   /**\r
128    * Returns the chart title text size.\r
129    * \r
130    * @return the chart title text size\r
131    */\r
132   public float getChartTitleTextSize() {\r
133     return mChartTitleTextSize;\r
134   }\r
135 \r
136   /**\r
137    * Sets the chart title text size.\r
138    * \r
139    * @param textSize the chart title text size\r
140    */\r
141   public void setChartTitleTextSize(float textSize) {\r
142     mChartTitleTextSize = textSize;\r
143   }\r
144 \r
145   /**\r
146    * Adds a simple renderer to the multiple renderer.\r
147    * \r
148    * @param renderer the renderer to be added\r
149    */\r
150   public void addSeriesRenderer(SimpleSeriesRenderer renderer) {\r
151     mRenderers.add(renderer);\r
152   }\r
153 \r
154   /**\r
155    * Adds a simple renderer to the multiple renderer.\r
156    * \r
157    * @param index the index in the renderers list\r
158    * @param renderer the renderer to be added\r
159    */\r
160   public void addSeriesRenderer(int index, SimpleSeriesRenderer renderer) {\r
161     mRenderers.add(index, renderer);\r
162   }\r
163 \r
164   /**\r
165    * Removes a simple renderer from the multiple renderer.\r
166    * \r
167    * @param renderer the renderer to be removed\r
168    */\r
169   public void removeSeriesRenderer(SimpleSeriesRenderer renderer) {\r
170     mRenderers.remove(renderer);\r
171   }\r
172 \r
173   /**\r
174    * Removes all renderers from the multiple renderer.\r
175    */\r
176   public void removeAllRenderers() {\r
177     mRenderers.clear();\r
178   }\r
179 \r
180   /**\r
181    * Returns the simple renderer from the multiple renderer list.\r
182    * \r
183    * @param index the index in the simple renderers list\r
184    * @return the simple renderer at the specified index\r
185    */\r
186   public SimpleSeriesRenderer getSeriesRendererAt(int index) {\r
187     return mRenderers.get(index);\r
188   }\r
189 \r
190   /**\r
191    * Returns the simple renderers count in the multiple renderer list.\r
192    * \r
193    * @return the simple renderers count\r
194    */\r
195   public int getSeriesRendererCount() {\r
196     return mRenderers.size();\r
197   }\r
198 \r
199   /**\r
200    * Returns an array of the simple renderers in the multiple renderer list.\r
201    * \r
202    * @return the simple renderers array\r
203    */\r
204   public SimpleSeriesRenderer[] getSeriesRenderers() {\r
205     return mRenderers.toArray(new SimpleSeriesRenderer[0]);\r
206   }\r
207 \r
208   /**\r
209    * Returns the background color.\r
210    * \r
211    * @return the background color\r
212    */\r
213   public int getBackgroundColor() {\r
214     return mBackgroundColor;\r
215   }\r
216 \r
217   /**\r
218    * Sets the background color.\r
219    * \r
220    * @param color the background color\r
221    */\r
222   public void setBackgroundColor(int color) {\r
223     mBackgroundColor = color;\r
224   }\r
225 \r
226   /**\r
227    * Returns if the background color should be applied.\r
228    * \r
229    * @return the apply flag for the background color.\r
230    */\r
231   public boolean isApplyBackgroundColor() {\r
232     return mApplyBackgroundColor;\r
233   }\r
234 \r
235   /**\r
236    * Sets if the background color should be applied.\r
237    * \r
238    * @param apply the apply flag for the background color\r
239    */\r
240   public void setApplyBackgroundColor(boolean apply) {\r
241     mApplyBackgroundColor = apply;\r
242   }\r
243 \r
244   /**\r
245    * Returns the axes color.\r
246    * \r
247    * @return the axes color\r
248    */\r
249   public int getAxesColor() {\r
250     return mAxesColor;\r
251   }\r
252 \r
253   /**\r
254    * Sets the axes color.\r
255    * \r
256    * @param color the axes color\r
257    */\r
258   public void setAxesColor(int color) {\r
259     mAxesColor = color;\r
260   }\r
261 \r
262   /**\r
263    * Returns the labels color.\r
264    * \r
265    * @return the labels color\r
266    */\r
267   public int getLabelsColor() {\r
268     return mLabelsColor;\r
269   }\r
270 \r
271   /**\r
272    * Sets the labels color.\r
273    * \r
274    * @param color the labels color\r
275    */\r
276   public void setLabelsColor(int color) {\r
277     mLabelsColor = color;\r
278   }\r
279 \r
280   /**\r
281    * Returns the labels text size.\r
282    * \r
283    * @return the labels text size\r
284    */\r
285   public float getLabelsTextSize() {\r
286     return mLabelsTextSize;\r
287   }\r
288 \r
289   /**\r
290    * Sets the labels text size.\r
291    * \r
292    * @param textSize the labels text size\r
293    */\r
294   public void setLabelsTextSize(float textSize) {\r
295     mLabelsTextSize = textSize;\r
296   }\r
297 \r
298   /**\r
299    * Returns if the axes should be visible.\r
300    * \r
301    * @return the visibility flag for the axes\r
302    */\r
303   public boolean isShowAxes() {\r
304     return mShowAxes;\r
305   }\r
306 \r
307   /**\r
308    * Sets if the axes should be visible.\r
309    * \r
310    * @param showAxes the visibility flag for the axes\r
311    */\r
312   public void setShowAxes(boolean showAxes) {\r
313     mShowAxes = showAxes;\r
314   }\r
315 \r
316   /**\r
317    * Returns if the labels should be visible.\r
318    * \r
319    * @return the visibility flag for the labels\r
320    */\r
321   public boolean isShowLabels() {\r
322     return mShowLabels;\r
323   }\r
324 \r
325   /**\r
326    * Sets if the labels should be visible.\r
327    * \r
328    * @param showLabels the visibility flag for the labels\r
329    */\r
330   public void setShowLabels(boolean showLabels) {\r
331     mShowLabels = showLabels;\r
332   }\r
333 \r
334   /**\r
335    * Returns if the X axis grid should be visible.\r
336    * \r
337    * @return the visibility flag for the X axis grid\r
338    */\r
339   public boolean isShowGridX() {\r
340     return mShowGridX;\r
341   }\r
342 \r
343   /**\r
344    * Returns if the Y axis grid should be visible.\r
345    * \r
346    * @return the visibility flag for the Y axis grid\r
347    */\r
348   public boolean isShowGridY() {\r
349     return mShowGridY;\r
350   }\r
351 \r
352   /**\r
353    * Sets if the X axis grid should be visible.\r
354    * \r
355    * @param showGrid the visibility flag for the X axis grid\r
356    */\r
357   public void setShowGridX(boolean showGrid) {\r
358     mShowGridX = showGrid;\r
359   }\r
360 \r
361   /**\r
362    * Sets if the Y axis grid should be visible.\r
363    * \r
364    * @param showGrid the visibility flag for the Y axis grid\r
365    */\r
366   public void setShowGridY(boolean showGrid) {\r
367     mShowGridY = showGrid;\r
368   }\r
369 \r
370   /**\r
371    * Sets if the grid should be visible.\r
372    * \r
373    * @param showGrid the visibility flag for the grid\r
374    */\r
375   public void setShowGrid(boolean showGrid) {\r
376     setShowGridX(showGrid);\r
377     setShowGridY(showGrid);\r
378   }\r
379 \r
380   /**\r
381    * Returns if the grid should be visible for custom X or Y labels.\r
382    * \r
383    * @return the visibility flag for the custom text grid\r
384    */\r
385   public boolean isShowCustomTextGrid() {\r
386     return mShowCustomTextGrid;\r
387   }\r
388 \r
389   /**\r
390    * Sets if the grid for custom X or Y labels should be visible.\r
391    * \r
392    * @param showGrid the visibility flag for the custom text grid\r
393    */\r
394   public void setShowCustomTextGrid(boolean showGrid) {\r
395     mShowCustomTextGrid = showGrid;\r
396   }\r
397 \r
398   /**\r
399    * Returns if the legend should be visible.\r
400    * \r
401    * @return the visibility flag for the legend\r
402    */\r
403   public boolean isShowLegend() {\r
404     return mShowLegend;\r
405   }\r
406 \r
407   /**\r
408    * Sets if the legend should be visible.\r
409    * \r
410    * @param showLegend the visibility flag for the legend\r
411    */\r
412   public void setShowLegend(boolean showLegend) {\r
413     mShowLegend = showLegend;\r
414   }\r
415 \r
416   /**\r
417    * Returns if the legend should size to fit.\r
418    * \r
419    * @return the fit behavior\r
420    */\r
421   public boolean isFitLegend() {\r
422     return mFitLegend;\r
423   }\r
424 \r
425   /**\r
426    * Sets if the legend should size to fit.\r
427    * \r
428    * @param fit the fit behavior\r
429    */\r
430   public void setFitLegend(boolean fit) {\r
431     mFitLegend = fit;\r
432   }\r
433 \r
434   /**\r
435    * Returns the text typeface name.\r
436    * \r
437    * @return the text typeface name\r
438    */\r
439   public String getTextTypefaceName() {\r
440     return mTextTypefaceName;\r
441   }\r
442 \r
443   /**\r
444    * Returns the text typeface style.\r
445    * \r
446    * @return the text typeface style\r
447    */\r
448   public int getTextTypefaceStyle() {\r
449     return mTextTypefaceStyle;\r
450   }\r
451 \r
452   /**\r
453    * Returns the legend text size.\r
454    * \r
455    * @return the legend text size\r
456    */\r
457   public float getLegendTextSize() {\r
458     return mLegendTextSize;\r
459   }\r
460 \r
461   /**\r
462    * Sets the legend text size.\r
463    * \r
464    * @param textSize the legend text size\r
465    */\r
466   public void setLegendTextSize(float textSize) {\r
467     mLegendTextSize = textSize;\r
468   }\r
469 \r
470   /**\r
471    * Sets the text typeface name and style.\r
472    * \r
473    * @param typefaceName the text typeface name\r
474    * @param style the text typeface style\r
475    */\r
476   public void setTextTypeface(String typefaceName, int style) {\r
477     mTextTypefaceName = typefaceName;\r
478     mTextTypefaceStyle = style;\r
479   }\r
480 \r
481   /**\r
482    * Returns the antialiasing flag value.\r
483    * \r
484    * @return the antialiasing value\r
485    */\r
486   public boolean isAntialiasing() {\r
487     return mAntialiasing;\r
488   }\r
489 \r
490   /**\r
491    * Sets the antialiasing value.\r
492    * \r
493    * @param antialiasing the antialiasing\r
494    */\r
495   public void setAntialiasing(boolean antialiasing) {\r
496     mAntialiasing = antialiasing;\r
497   }\r
498 \r
499   /**\r
500    * Returns the value to be used for scaling the chart.\r
501    * \r
502    * @return the scale value\r
503    */\r
504   public float getScale() {\r
505     return mScale;\r
506   }\r
507 \r
508   /**\r
509    * Returns the original value to be used for scaling the chart.\r
510    * \r
511    * @return the original scale value\r
512    */\r
513   public float getOriginalScale() {\r
514     return mOriginalScale;\r
515   }\r
516 \r
517   /**\r
518    * Sets the value to be used for scaling the chart. It works on some charts\r
519    * like pie, doughnut, dial.\r
520    * \r
521    * @param scale the scale value\r
522    */\r
523   public void setScale(float scale) {\r
524     mScale = scale;\r
525   }\r
526 \r
527   /**\r
528    * Returns the enabled state of the zoom.\r
529    * \r
530    * @return if zoom is enabled\r
531    */\r
532   public boolean isZoomEnabled() {\r
533     return mZoomEnabled;\r
534   }\r
535 \r
536   /**\r
537    * Sets the enabled state of the zoom.\r
538    * \r
539    * @param enabled zoom enabled\r
540    */\r
541   public void setZoomEnabled(boolean enabled) {\r
542     mZoomEnabled = enabled;\r
543   }\r
544 \r
545   /**\r
546    * Returns the visible state of the zoom buttons.\r
547    * \r
548    * @return if zoom buttons are visible\r
549    */\r
550   public boolean isZoomButtonsVisible() {\r
551     return mZoomButtonsVisible;\r
552   }\r
553 \r
554   /**\r
555    * Sets the visible state of the zoom buttons.\r
556    * \r
557    * @param visible if the zoom buttons are visible\r
558    */\r
559   public void setZoomButtonsVisible(boolean visible) {\r
560     mZoomButtonsVisible = visible;\r
561   }\r
562 \r
563   /**\r
564    * Returns the enabled state of the external (application implemented) zoom.\r
565    * \r
566    * @return if external zoom is enabled\r
567    */\r
568   public boolean isExternalZoomEnabled() {\r
569     return mExternalZoomEnabled;\r
570   }\r
571 \r
572   /**\r
573    * Sets the enabled state of the external (application implemented) zoom.\r
574    * \r
575    * @param enabled external zoom enabled\r
576    */\r
577   public void setExternalZoomEnabled(boolean enabled) {\r
578     mExternalZoomEnabled = enabled;\r
579   }\r
580 \r
581   /**\r
582    * Returns the zoom rate.\r
583    * \r
584    * @return the zoom rate\r
585    */\r
586   public float getZoomRate() {\r
587     return mZoomRate;\r
588   }\r
589 \r
590   /**\r
591    * Returns the enabled state of the pan.\r
592    * \r
593    * @return if pan is enabled\r
594    */\r
595   public boolean isPanEnabled() {\r
596     return mPanEnabled;\r
597   }\r
598 \r
599   /**\r
600    * Sets the enabled state of the pan.\r
601    * \r
602    * @param enabled pan enabled\r
603    */\r
604   public void setPanEnabled(boolean enabled) {\r
605     mPanEnabled = enabled;\r
606   }\r
607 \r
608   /**\r
609    * Sets the zoom rate.\r
610    * \r
611    * @param rate the zoom rate\r
612    */\r
613   public void setZoomRate(float rate) {\r
614     mZoomRate = rate;\r
615   }\r
616 \r
617   /**\r
618    * Returns the enabled state of the click.\r
619    * \r
620    * @return if click is enabled\r
621    */\r
622   public boolean isClickEnabled() {\r
623     return mClickEnabled;\r
624   }\r
625 \r
626   /**\r
627    * Sets the enabled state of the click.\r
628    * \r
629    * @param enabled click enabled\r
630    */\r
631   public void setClickEnabled(boolean enabled) {\r
632     mClickEnabled = enabled;\r
633   }\r
634 \r
635   /**\r
636    * Returns the selectable radius value around clickable points.\r
637    * \r
638    * @return the selectable radius\r
639    */\r
640   public int getSelectableBuffer() {\r
641     return selectableBuffer;\r
642   }\r
643 \r
644   /**\r
645    * Sets the selectable radius value around clickable points.\r
646    * \r
647    * @param buffer the selectable radius\r
648    */\r
649   public void setSelectableBuffer(int buffer) {\r
650     selectableBuffer = buffer;\r
651   }\r
652 \r
653   /**\r
654    * Returns the legend height.\r
655    * \r
656    * @return the legend height\r
657    */\r
658   public int getLegendHeight() {\r
659     return mLegendHeight;\r
660   }\r
661 \r
662   /**\r
663    * Sets the legend height, in pixels.\r
664    * \r
665    * @param height the legend height\r
666    */\r
667   public void setLegendHeight(int height) {\r
668     mLegendHeight = height;\r
669   }\r
670 \r
671   /**\r
672    * Returns the margin sizes. An array containing the margins in this order:\r
673    * top, left, bottom, right\r
674    * \r
675    * @return the margin sizes\r
676    */\r
677   public int[] getMargins() {\r
678     return mMargins;\r
679   }\r
680 \r
681   /**\r
682    * Sets the margins, in pixels.\r
683    * \r
684    * @param margins an array containing the margin size values, in this order:\r
685    *          top, left, bottom, right\r
686    */\r
687   public void setMargins(int[] margins) {\r
688     mMargins = margins;\r
689   }\r
690 \r
691   /**\r
692    * Returns if the chart is inside a scroll view and doesn't need to shrink.\r
693    * \r
694    * @return if it is inside a scroll view\r
695    */\r
696   public boolean isInScroll() {\r
697     return mInScroll;\r
698   }\r
699 \r
700   /**\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
703    * \r
704    * @param inScroll if it is inside a scroll view\r
705    */\r
706   public void setInScroll(boolean inScroll) {\r
707     mInScroll = inScroll;\r
708   }\r
709 \r
710   /**\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
713    * watch.)\r
714    * \r
715    * @return the start angle in degrees\r
716    */\r
717   public float getStartAngle() {\r
718     return mStartAngle;\r
719   }\r
720 \r
721   /**\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
725    * \r
726    * @param startAngle the start angle in degrees\r
727    */\r
728   public void setStartAngle(float startAngle) {\r
729     mStartAngle = startAngle;\r
730   }\r
731 \r
732   /**\r
733    * Returns if the values should be displayed as text.\r
734    * \r
735    * @return if the values should be displayed as text\r
736    */\r
737   public boolean isDisplayValues() {\r
738     return mDisplayValues;\r
739   }\r
740 \r
741   /**\r
742    * Sets if the values should be displayed as text (supported by pie chart).\r
743    * \r
744    * @param display if the values should be displayed as text\r
745    */\r
746   public void setDisplayValues(boolean display) {\r
747     mDisplayValues = display;\r
748   }\r
749 \r
750 }\r