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.tools;
\r
18 import org.achartengine.chart.AbstractChart;
\r
19 import org.achartengine.chart.XYChart;
\r
20 import org.achartengine.renderer.XYMultipleSeriesRenderer;
\r
23 * Abstract class for being extended by graphical view tools.
\r
25 public abstract class AbstractTool {
\r
27 protected AbstractChart mChart;
\r
28 /** The renderer. */
\r
29 protected XYMultipleSeriesRenderer mRenderer;
\r
32 * Abstract tool constructor.
\r
34 * @param chart the chart
\r
36 public AbstractTool(AbstractChart chart) {
\r
38 if (chart instanceof XYChart) {
\r
39 mRenderer = ((XYChart) chart).getRenderer();
\r
44 * Returns the current chart range.
\r
46 * @param scale the scale
\r
47 * @return the chart range
\r
49 public double[] getRange(int scale) {
\r
50 double minX = mRenderer.getXAxisMin(scale);
\r
51 double maxX = mRenderer.getXAxisMax(scale);
\r
52 double minY = mRenderer.getYAxisMin(scale);
\r
53 double maxY = mRenderer.getYAxisMax(scale);
\r
54 return new double[] { minX, maxX, minY, maxY };
\r
58 * Sets the range to the calculated one, if not already set.
\r
60 * @param range the range
\r
61 * @param scale the scale
\r
63 public void checkRange(double[] range, int scale) {
\r
64 if (mChart instanceof XYChart) {
\r
65 double[] calcRange = ((XYChart) mChart).getCalcRange(scale);
\r
66 if (calcRange != null) {
\r
67 if (!mRenderer.isMinXSet(scale)) {
\r
68 range[0] = calcRange[0];
\r
69 mRenderer.setXAxisMin(range[0], scale);
\r
71 if (!mRenderer.isMaxXSet(scale)) {
\r
72 range[1] = calcRange[1];
\r
73 mRenderer.setXAxisMax(range[1], scale);
\r
75 if (!mRenderer.isMinYSet(scale)) {
\r
76 range[2] = calcRange[2];
\r
77 mRenderer.setYAxisMin(range[2], scale);
\r
79 if (!mRenderer.isMaxYSet(scale)) {
\r
80 range[3] = calcRange[3];
\r
81 mRenderer.setYAxisMax(range[3], scale);
\r
88 * Sets a new range on the X axis.
\r
90 * @param min the minimum value
\r
91 * @param max the maximum value
\r
92 * @param scale the scale
\r
94 protected void setXRange(double min, double max, int scale) {
\r
95 mRenderer.setXAxisMin(min, scale);
\r
96 mRenderer.setXAxisMax(max, scale);
\r
100 * Sets a new range on the Y axis.
\r
102 * @param min the minimum value
\r
103 * @param max the maximum value
\r
104 * @param scale the scale
\r
106 protected void setYRange(double min, double max, int scale) {
\r
107 mRenderer.setYAxisMin(min, scale);
\r
108 mRenderer.setYAxisMax(max, scale);
\r