diff --git a/achartengine/src/org/achartengine/chart/XYChart.java b/achartengine/src/org/achartengine/chart/XYChart.java index f1d2296..a47b10f 100644 --- a/achartengine/src/org/achartengine/chart/XYChart.java +++ b/achartengine/src/org/achartengine/chart/XYChart.java @@ -1,12 +1,12 @@ /** * Copyright (C) 2009 - 2013 SC 4ViewSoft SRL - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,14 +15,9 @@ */ package org.achartengine.chart; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.SortedMap; +import android.graphics.*; +import android.graphics.Paint.Align; +import android.graphics.Paint.Style; import org.achartengine.model.Point; import org.achartengine.model.SeriesSelection; @@ -36,17 +31,14 @@ import org.achartengine.renderer.XYSeriesRenderer; import org.achartengine.util.MathHelper; -import android.graphics.Canvas; -import android.graphics.DashPathEffect; -import android.graphics.Paint; -import android.graphics.Paint.Align; -import android.graphics.Paint.Cap; -import android.graphics.Paint.Join; -import android.graphics.Paint.Style; -import android.graphics.PathEffect; -import android.graphics.Rect; -import android.graphics.RectF; -import android.graphics.Typeface; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.SortedMap; /** * The XY chart rendering class. @@ -75,12 +67,17 @@ public abstract class XYChart extends AbstractChart { */ private Map> clickableAreas = new HashMap>(); + { + mGridPaint = new Paint(Paint.ANTI_ALIAS_FLAG); + mGridPaint.setStyle(Style.STROKE); + } + protected XYChart() { } /** * Builds a new XY chart instance. - * + * * @param dataset the multiple series dataset * @param renderer the multiple series renderer */ @@ -91,14 +88,14 @@ public XYChart(XYMultipleSeriesDataset dataset, XYMultipleSeriesRenderer rendere // TODO: javadoc protected void setDatasetRenderer(XYMultipleSeriesDataset dataset, - XYMultipleSeriesRenderer renderer) { + XYMultipleSeriesRenderer renderer) { mDataset = dataset; mRenderer = renderer; } /** * The graphical representation of the XY chart. - * + * * @param canvas the canvas to paint to * @param x the top left x value of the view to draw to * @param y the top left y value of the view to draw to @@ -120,7 +117,7 @@ public void draw(Canvas canvas, int x, int y, int width, int height, Paint paint } if (mRenderer.isFitLegend() && mRenderer.isShowLegend()) { legendSize = drawLegend(canvas, mRenderer, titles, left, right, y, width, height, legendSize, - paint, true); + paint, true); } int bottom = y + height - margins[2] - legendSize; if (mScreenR == null) { @@ -130,15 +127,15 @@ public void draw(Canvas canvas, int x, int y, int width, int height, Paint paint drawBackground(mRenderer, canvas, x, y, width, height, paint, false, DefaultRenderer.NO_COLOR); if (paint.getTypeface() == null - || (mRenderer.getTextTypeface() != null && paint.getTypeface().equals( + || (mRenderer.getTextTypeface() != null && paint.getTypeface().equals( mRenderer.getTextTypeface())) - || !paint.getTypeface().toString().equals(mRenderer.getTextTypefaceName()) - || paint.getTypeface().getStyle() != mRenderer.getTextTypefaceStyle()) { + || !paint.getTypeface().toString().equals(mRenderer.getTextTypefaceName()) + || paint.getTypeface().getStyle() != mRenderer.getTextTypefaceStyle()) { if (mRenderer.getTextTypeface() != null) { paint.setTypeface(mRenderer.getTextTypeface()); } else { paint.setTypeface(Typeface.create(mRenderer.getTextTypefaceName(), - mRenderer.getTextTypefaceStyle())); + mRenderer.getTextTypefaceStyle())); } } Orientation or = mRenderer.getOrientation(); @@ -232,36 +229,28 @@ public void draw(Canvas canvas, int x, int y, int width, int height, Paint paint } } - boolean hasValues = false; - for (int i = 0; i < sLength; i++) { - XYSeries series = mDataset.getSeriesAt(i); - if (series.getItemCount() == 0) { - continue; - } - hasValues = true; - } - - boolean showLabels = mRenderer.isShowLabels() && hasValues; boolean showGridX = mRenderer.isShowGridX(); boolean showGridY = mRenderer.isShowGridY(); + boolean showCustomTextXLabels = mRenderer.isShowCustomTextXLabels(); + boolean showCustomTextYLabels = mRenderer.isShowCustomTextYLabels(); + if (showGridX || showGridY) { // Draw the grid lines under everything else. List xLabels = getValidLabels(getXLabels(minX[0], maxX[0], mRenderer.getXLabels())); Map> allYLabels = getYLabels(minY, maxY, maxScaleNumber); - int xLabelsLeft = left; boolean showXLabels = mRenderer.isShowXLabels(); boolean showYLabels = mRenderer.isShowYLabels(); // Only draw the grid. mRenderer.setShowLabels(false); - if (mGridPaint == null) { - mGridPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - } - drawXLabels(xLabels, mRenderer.getXTextLabelLocations(), canvas, paint, xLabelsLeft, top, + mRenderer.setShowCustomTextLabels(false); + + drawXLabels(xLabels, mRenderer.getXTextLabelLocations(), canvas, paint, left, top, bottom, xPixelsPerUnit[0], minX[0], maxX[0]); - drawYLabels(allYLabels, canvas, paint, maxScaleNumber, left, right, bottom, yPixelsPerUnit, - minY); + drawYLabels(allYLabels, canvas, paint, maxScaleNumber, left, right, bottom, yPixelsPerUnit, minY); + mRenderer.setShowLabels(showXLabels, showYLabels); + mRenderer.setShowCustomTextLabels(showCustomTextXLabels, showCustomTextYLabels); } // use a linked list for these reasons: @@ -290,7 +279,7 @@ public void draw(Canvas canvas, int x, int y, int width, int height, Paint paint synchronized (series) { SortedMap range = series.getRange(minX[scale], maxX[scale], - seriesRenderer.isDisplayBoundingPoints()); + seriesRenderer.isDisplayBoundingPoints()); int startIndex = -1; for (Entry value : range.entrySet()) { @@ -316,9 +305,9 @@ public void draw(Canvas canvas, int x, int y, int width, int height, Paint paint } else { if (points.size() > 0) { drawSeries(series, canvas, paint, points, seriesRenderer, yAxisValue, i, or, - startIndex); + startIndex); ClickableArea[] clickableAreasForSubSeries = clickableAreasForPoints(points, values, - yAxisValue, i, startIndex); + yAxisValue, i, startIndex); clickableArea.addAll(Arrays.asList(clickableAreasForSubSeries)); points.clear(); values.clear(); @@ -336,11 +325,11 @@ public void draw(Canvas canvas, int x, int y, int width, int height, Paint paint Rect bound = new Rect(); for (int j = 0; j < count; j++) { float xS = (float) (left + xPixelsPerUnit[scale] - * (series.getAnnotationX(j) - minX[scale])); + * (series.getAnnotationX(j) - minX[scale])); float yS = (float) (bottom - yPixelsPerUnit[scale] - * (series.getAnnotationY(j) - minY[scale])); + * (series.getAnnotationY(j) - minY[scale])); paint.getTextBounds(series.getAnnotationAt(j), 0, series.getAnnotationAt(j).length(), - bound); + bound); if (xS < (xS + bound.width()) && yS < canvas.getHeight()) { drawString(canvas, series.getAnnotationAt(j), xS, yS, paint); } @@ -350,142 +339,199 @@ public void draw(Canvas canvas, int x, int y, int width, int height, Paint paint if (points.size() > 0) { drawSeries(series, canvas, paint, points, seriesRenderer, yAxisValue, i, or, startIndex); ClickableArea[] clickableAreasForSubSeries = clickableAreasForPoints(points, values, - yAxisValue, i, startIndex); + yAxisValue, i, startIndex); clickableArea.addAll(Arrays.asList(clickableAreasForSubSeries)); } } } // draw stuff over the margins so that data doesn't render on these areas drawBackground(mRenderer, canvas, x, bottom, width, height - bottom, paint, true, - mRenderer.getMarginsColor()); + mRenderer.getMarginsColor()); drawBackground(mRenderer, canvas, x, y, width, margins[0], paint, true, - mRenderer.getMarginsColor()); + mRenderer.getMarginsColor()); if (or == Orientation.HORIZONTAL) { drawBackground(mRenderer, canvas, x, y, left - x, height - y, paint, true, - mRenderer.getMarginsColor()); + mRenderer.getMarginsColor()); drawBackground(mRenderer, canvas, right, y, margins[3], height - y, paint, true, - mRenderer.getMarginsColor()); + mRenderer.getMarginsColor()); } else if (or == Orientation.VERTICAL) { drawBackground(mRenderer, canvas, right, y, width - right, height - y, paint, true, - mRenderer.getMarginsColor()); + mRenderer.getMarginsColor()); drawBackground(mRenderer, canvas, x, y, left - x, height - y, paint, true, - mRenderer.getMarginsColor()); + mRenderer.getMarginsColor()); + } + + boolean hasValues = false; + for (int i = 0; i < sLength; i++) { + XYSeries series = mDataset.getSeriesAt(i); + if (series.getItemCount() == 0) { + continue; + } + hasValues = true; } + boolean showXLabels = mRenderer.isShowXLabels() && hasValues; + boolean showYLabels = mRenderer.isShowYLabels() && hasValues; + + boolean showLabels = mRenderer.isShowLabels() && hasValues; boolean showTickMarks = mRenderer.isShowTickMarks(); // boolean showCustomTextGridX = mRenderer.isShowCustomTextGridX(); boolean showCustomTextGridY = mRenderer.isShowCustomTextGridY(); - if (showLabels) { + + if (showXLabels) { List xLabels = getValidLabels(getXLabels(minX[0], maxX[0], mRenderer.getXLabels())); - Map> allYLabels = getYLabels(minY, maxY, maxScaleNumber); - int xLabelsLeft = left; - if (showLabels) { - paint.setColor(mRenderer.getXLabelsColor()); - paint.setTextSize(mRenderer.getLabelsTextSize()); - paint.setTextAlign(mRenderer.getXLabelsAlign()); - // if (mRenderer.getXLabelsAlign() == Align.LEFT) { - // xLabelsLeft += mRenderer.getLabelsTextSize() / 4; - // } - } + paint.setColor(mRenderer.getXLabelsColor()); + paint.setTextSize(mRenderer.getLabelsTextSize()); + paint.setTextAlign(mRenderer.getXLabelsAlign()); + // Draw just the labels and not the grid lines. mRenderer.setShowGrid(false); - drawXLabels(xLabels, mRenderer.getXTextLabelLocations(), canvas, paint, xLabelsLeft, top, - bottom, xPixelsPerUnit[0], minX[0], maxX[0]); - drawYLabels(allYLabels, canvas, paint, maxScaleNumber, left, right, bottom, yPixelsPerUnit, - minY); + drawXLabels(xLabels, mRenderer.getXTextLabelLocations(), canvas, paint, left, top, + bottom, xPixelsPerUnit[0], minX[0], maxX[0]); mRenderer.setShowGridX(showGridX); + + paint.setColor(mRenderer.getLabelsColor()); + float size = mRenderer.getAxisTitleTextSize(); + paint.setTextSize(size); + paint.setTextAlign(Align.CENTER); + if (or == Orientation.HORIZONTAL) { + drawText(canvas, + mRenderer.getXTitle(), + x + width / 2, + bottom + mRenderer.getLabelsTextSize() * 4 / 3 + mRenderer.getXLabelsPadding() + size, + paint, 0); + + } else if (or == Orientation.VERTICAL) { + drawText(canvas, mRenderer.getXTitle(), x + width / 2, + y + height - size + mRenderer.getXLabelsPadding(), paint, -90); + } + } + + if (showCustomTextXLabels) { + drawXTextLabels(mRenderer.getXTextLabelLocations(), canvas, paint, true, left, top, bottom, xPixelsPerUnit[0], minX[0], maxX[0]); + } + + if (showYLabels) { + Map> allYLabels = getYLabels(minY, maxY, maxScaleNumber); + + paint.setColor(mRenderer.getXLabelsColor()); + paint.setTextSize(mRenderer.getLabelsTextSize()); + paint.setTextAlign(mRenderer.getXLabelsAlign()); + + // Draw just the labels and not the grid lines. + mRenderer.setShowGrid(false); + drawYLabels(allYLabels, canvas, paint, maxScaleNumber, left, right, bottom, yPixelsPerUnit, minY); mRenderer.setShowGridY(showGridY); - if (showLabels) { - paint.setColor(mRenderer.getLabelsColor()); + paint.setColor(mRenderer.getLabelsColor()); + float size = mRenderer.getAxisTitleTextSize(); + paint.setTextSize(size); + paint.setTextAlign(Align.CENTER); + if (or == Orientation.HORIZONTAL) { for (int i = 0; i < maxScaleNumber; i++) { Align axisAlign = mRenderer.getYAxisAlign(i); - Double[] yTextLabelLocations = mRenderer.getYTextLabelLocations(i); - for (Double location : yTextLabelLocations) { - if (minY[i] <= location && location <= maxY[i]) { - float yLabel = (float) (bottom - yPixelsPerUnit[i] - * (location.doubleValue() - minY[i])); - String label = mRenderer.getYTextLabel(location, i); - paint.setColor(mRenderer.getYLabelsColor(i)); - paint.setTextAlign(mRenderer.getYLabelsAlign(i)); - if (or == Orientation.HORIZONTAL) { - if (axisAlign == Align.LEFT) { - if (showTickMarks) { - canvas.drawLine(left + getLabelLinePos(axisAlign), yLabel, left, yLabel, paint); - } - drawText(canvas, label, left - mRenderer.getYLabelsPadding(), - yLabel - mRenderer.getYLabelsVerticalPadding(), paint, - mRenderer.getYLabelsAngle()); - } else { - if (showTickMarks) { - canvas.drawLine(right, yLabel, right + getLabelLinePos(axisAlign), yLabel, - paint); - } - drawText(canvas, label, right - mRenderer.getYLabelsPadding(), - yLabel - mRenderer.getYLabelsVerticalPadding(), paint, - mRenderer.getYLabelsAngle()); - } + if (axisAlign == Align.LEFT) { + drawText(canvas, mRenderer.getYTitle(i), x + size, y + height / 2, paint, -90); + } else { + drawText(canvas, mRenderer.getYTitle(i), x + width, y + height / 2, paint, -90); + } + } + } else if (or == Orientation.VERTICAL) { + drawText(canvas, mRenderer.getYTitle(), right + 20, y + height / 2, paint, 0); + } + } - if (showCustomTextGridY) { - paint.setColor(mRenderer.getGridColor(i)); - canvas.drawLine(left, yLabel, right, yLabel, paint); + if (showCustomTextYLabels) { + paint.setColor(mRenderer.getLabelsColor()); + paint.setTextSize(mRenderer.getLabelsTextSize()); + paint.setTextAlign(mRenderer.getXLabelsAlign()); + + for (int i = 0; i < maxScaleNumber; i++) { + Align axisAlign = mRenderer.getYAxisAlign(i); + Double[] yTextLabelLocations = mRenderer.getYTextLabelLocations(i); + for (Double location : yTextLabelLocations) { + if (minY[i] <= location && location <= maxY[i]) { + float yLabel = (float) (bottom - yPixelsPerUnit[i] + * (location.doubleValue() - minY[i])); + String label = mRenderer.getYTextLabel(location, i); + paint.setColor(mRenderer.getYLabelsColor(i)); + paint.setTextAlign(mRenderer.getYLabelsAlign(i)); + + if (or == Orientation.HORIZONTAL) { + if (axisAlign == Align.LEFT) { + if (showTickMarks) { + canvas.drawLine(left + getLabelLinePos(axisAlign), yLabel, left, yLabel, paint); } + drawText(canvas, label, left - mRenderer.getYLabelsPadding(), + yLabel - mRenderer.getYLabelsVerticalPadding(), paint, + mRenderer.getYLabelsAngle()); } else { if (showTickMarks) { - canvas.drawLine(right - getLabelLinePos(axisAlign), yLabel, right, yLabel, paint); - } - drawText(canvas, label, right + 10, yLabel - mRenderer.getYLabelsVerticalPadding(), - paint, mRenderer.getYLabelsAngle()); - if (showCustomTextGridY) { - paint.setColor(mRenderer.getGridColor(i)); - canvas.drawLine(right, yLabel, left, yLabel, paint); + canvas.drawLine(right, yLabel, right + getLabelLinePos(axisAlign), yLabel, + paint); } + drawText(canvas, label, right - mRenderer.getYLabelsPadding(), + yLabel - mRenderer.getYLabelsVerticalPadding(), paint, + mRenderer.getYLabelsAngle()); + } + if (showCustomTextGridY) { + setStroke(mRenderer.getGridLineYStroke(), mGridPaint); + mGridPaint.setStrokeWidth(mRenderer.getGridLineWidth()); + mGridPaint.setColor(mRenderer.getGridColor(i)); + + Path gridLinePath = new Path(); + gridLinePath.moveTo(left, yLabel); + gridLinePath.lineTo(right, yLabel); + canvas.drawPath(gridLinePath, mGridPaint); + + } + } else { + if (showTickMarks) { + canvas.drawLine(right - getLabelLinePos(axisAlign), yLabel, right, yLabel, paint); + } + drawText(canvas, label, right + 10, yLabel - mRenderer.getYLabelsVerticalPadding(), + paint, mRenderer.getYLabelsAngle()); + if (showCustomTextGridY) { + setStroke(mRenderer.getGridLineYStroke(), mGridPaint); + mGridPaint.setStrokeWidth(mRenderer.getGridLineWidth()); + mGridPaint.setColor(mRenderer.getGridColor(i)); + + Path gridLinePath = new Path(); + gridLinePath.moveTo(right, yLabel); + gridLinePath.lineTo(left, yLabel); + canvas.drawPath(gridLinePath, mGridPaint); } } } } } + } if (showLabels) { - paint.setColor(mRenderer.getLabelsColor()); - float size = mRenderer.getAxisTitleTextSize(); - paint.setTextSize(size); - paint.setTextAlign(Align.CENTER); - if (or == Orientation.HORIZONTAL) { - drawText( - canvas, - mRenderer.getXTitle(), - x + width / 2, - bottom + mRenderer.getLabelsTextSize() * 4 / 3 + mRenderer.getXLabelsPadding() + size, - paint, 0); - for (int i = 0; i < maxScaleNumber; i++) { - Align axisAlign = mRenderer.getYAxisAlign(i); - if (axisAlign == Align.LEFT) { - drawText(canvas, mRenderer.getYTitle(i), x + size, y + height / 2, paint, -90); - } else { - drawText(canvas, mRenderer.getYTitle(i), x + width, y + height / 2, paint, -90); - } - } + paint.setColor(mRenderer.getLabelsColor()); + float axisTitleTextSize = mRenderer.getAxisTitleTextSize(); + paint.setTextSize(axisTitleTextSize); + paint.setTextAlign(Align.CENTER); paint.setTextSize(mRenderer.getChartTitleTextSize()); - drawText(canvas, mRenderer.getChartTitle(), x + width / 2, - y + mRenderer.getChartTitleTextSize(), paint, 0); - } else if (or == Orientation.VERTICAL) { - drawText(canvas, mRenderer.getXTitle(), x + width / 2, - y + height - size + mRenderer.getXLabelsPadding(), paint, -90); - drawText(canvas, mRenderer.getYTitle(), right + 20, y + height / 2, paint, 0); - paint.setTextSize(mRenderer.getChartTitleTextSize()); - drawText(canvas, mRenderer.getChartTitle(), x + size, top + height / 2, paint, 0); - } + + if (or == Orientation.HORIZONTAL) { + drawText(canvas, mRenderer.getChartTitle(), x + width / 2, + y + mRenderer.getChartTitleTextSize(), paint, 0); + + } else if (or == Orientation.VERTICAL) { + drawText(canvas, mRenderer.getChartTitle(), x + axisTitleTextSize, top + height / 2, paint, 0); + } } - } + + if (or == Orientation.HORIZONTAL) { drawLegend(canvas, mRenderer, titles, left, right, y + (int) mRenderer.getXLabelsPadding(), - width, height, legendSize, paint, false); + width, height, legendSize, paint, false); } else if (or == Orientation.VERTICAL) { transform(canvas, angle, true); drawLegend(canvas, mRenderer, titles, left, right, y + (int) mRenderer.getXLabelsPadding(), - width, height, legendSize, paint, false); + width, height, legendSize, paint, false); transform(canvas, angle, false); } if (mRenderer.isShowAxes()) { @@ -518,7 +564,7 @@ protected Map> getYLabels(double[] minY, double[] maxY, in Map> allYLabels = new HashMap>(); for (int i = 0; i < maxScaleNumber; i++) { allYLabels.put(i, - getValidLabels(MathHelper.getLabels(minY[i], maxY[i], mRenderer.getYLabels()))); + getValidLabels(MathHelper.getLabels(minY[i], maxY[i], mRenderer.getYLabels()))); } return allYLabels; } @@ -543,7 +589,7 @@ private List getValidLabels(List labels) { /** * Draws the series. - * + * * @param series the series * @param canvas the canvas * @param paint the paint object @@ -555,44 +601,35 @@ private List getValidLabels(List labels) { * @param startIndex the start index of the rendering points */ protected void drawSeries(XYSeries series, Canvas canvas, Paint paint, List pointsList, - XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, Orientation or, - int startIndex) { + XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, Orientation or, + int startIndex) { + + Paint paintCopy = new Paint(paint); + BasicStroke stroke = seriesRenderer.getStroke(); - Cap cap = paint.getStrokeCap(); - Join join = paint.getStrokeJoin(); - float miter = paint.getStrokeMiter(); - PathEffect pathEffect = paint.getPathEffect(); - Style style = paint.getStyle(); + if (stroke != null) { - PathEffect effect = null; - if (stroke.getIntervals() != null) { - effect = new DashPathEffect(stroke.getIntervals(), stroke.getPhase()); - } - setStroke(stroke.getCap(), stroke.getJoin(), stroke.getMiter(), Style.FILL_AND_STROKE, - effect, paint); + setStroke(stroke, paintCopy); } // float[] points = MathHelper.getFloats(pointsList); - drawSeries(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex); - drawPoints(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex); - paint.setTextSize(seriesRenderer.getChartValuesTextSize()); + drawSeries(canvas, paintCopy, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex); + drawPoints(canvas, paintCopy, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex); + + paintCopy.setTextSize(seriesRenderer.getChartValuesTextSize()); if (or == Orientation.HORIZONTAL) { - paint.setTextAlign(Align.CENTER); + paintCopy.setTextAlign(Align.CENTER); } else { - paint.setTextAlign(Align.LEFT); + paintCopy.setTextAlign(Align.LEFT); } if (seriesRenderer.isDisplayChartValues()) { - paint.setTextAlign(seriesRenderer.getChartValuesTextAlign()); - drawChartValuesText(canvas, series, seriesRenderer, paint, pointsList, seriesIndex, - startIndex); - } - if (stroke != null) { - setStroke(cap, join, miter, style, pathEffect, paint); + paintCopy.setTextAlign(seriesRenderer.getChartValuesTextAlign()); + drawChartValuesText(canvas, series, seriesRenderer, paintCopy, pointsList, seriesIndex, startIndex); } } /** * Draws the series points. - * + * * @param canvas the canvas * @param paint the paint object * @param pointsList the points to be rendered @@ -602,28 +639,34 @@ protected void drawSeries(XYSeries series, Canvas canvas, Paint paint, List pointsList, - XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, int startIndex) { + XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, int startIndex) { if (isRenderPoints(seriesRenderer)) { ScatterChart pointsChart = getPointsChart(); if (pointsChart != null) { pointsChart.drawSeries(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, - startIndex); + startIndex); } } } - private void setStroke(Cap cap, Join join, float miter, Style style, PathEffect pathEffect, - Paint paint) { - paint.setStrokeCap(cap); - paint.setStrokeJoin(join); - paint.setStrokeMiter(miter); - paint.setPathEffect(pathEffect); - paint.setStyle(style); + private void setStroke(BasicStroke stroke, Paint paint) { + if (stroke == null || paint == null) { + return; + } + paint.setStrokeCap(stroke.getCap()); + paint.setStrokeJoin(stroke.getJoin()); + paint.setStrokeMiter(stroke.getMiter()); + + if (stroke.getIntervals() != null) { + DashPathEffect effect = new DashPathEffect(stroke.getIntervals(), stroke.getPhase()); + paint.setPathEffect(effect); + } + paint.setStyle(Style.FILL_AND_STROKE); } /** * The graphical representation of the series values as text. - * + * * @param canvas the canvas to paint to * @param series the series to be painted * @param renderer the series renderer @@ -633,23 +676,23 @@ private void setStroke(Cap cap, Join join, float miter, Style style, PathEffect * @param startIndex the start index of the rendering points */ protected void drawChartValuesText(Canvas canvas, XYSeries series, XYSeriesRenderer renderer, - Paint paint, List points, int seriesIndex, int startIndex) { + Paint paint, List points, int seriesIndex, int startIndex) { if (points.size() > 2) { // there are more than one point // record the first point's position float previousPointX = points.get(0); float previousPointY = points.get(1); for (int k = 0; k < points.size(); k += 2) { if (k == 2) { // decide whether to display first two points' values or - // not + // not if (Math.abs(points.get(2) - points.get(0)) > renderer.getDisplayChartValuesDistance() - || Math.abs(points.get(3) - points.get(1)) > renderer.getDisplayChartValuesDistance()) { + || Math.abs(points.get(3) - points.get(1)) > renderer.getDisplayChartValuesDistance()) { // first point drawText(canvas, getLabel(renderer.getChartValuesFormat(), series.getY(startIndex)), - points.get(0), points.get(1) - renderer.getChartValuesSpacing(), paint, 0); + points.get(0), points.get(1) - renderer.getChartValuesSpacing(), paint, 0); // second point drawText(canvas, - getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + 1)), - points.get(2), points.get(3) - renderer.getChartValuesSpacing(), paint, 0); + getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + 1)), + points.get(2), points.get(3) - renderer.getChartValuesSpacing(), paint, 0); previousPointX = points.get(2); previousPointY = points.get(3); @@ -658,11 +701,11 @@ protected void drawChartValuesText(Canvas canvas, XYSeries series, XYSeriesRende // compare current point's position with the previous point's, if they // are not too close, display if (Math.abs(points.get(k) - previousPointX) > renderer.getDisplayChartValuesDistance() - || Math.abs(points.get(k + 1) - previousPointY) > renderer + || Math.abs(points.get(k + 1) - previousPointY) > renderer .getDisplayChartValuesDistance()) { drawText(canvas, - getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + k / 2)), - points.get(k), points.get(k + 1) - renderer.getChartValuesSpacing(), paint, 0); + getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + k / 2)), + points.get(k), points.get(k + 1) - renderer.getChartValuesSpacing(), paint, 0); previousPointX = points.get(k); previousPointY = points.get(k + 1); } @@ -671,8 +714,8 @@ protected void drawChartValuesText(Canvas canvas, XYSeries series, XYSeriesRende } else { // if only one point, display it for (int k = 0; k < points.size(); k += 2) { drawText(canvas, - getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + k / 2)), - points.get(k), points.get(k + 1) - renderer.getChartValuesSpacing(), paint, 0); + getLabel(renderer.getChartValuesFormat(), series.getY(startIndex + k / 2)), + points.get(k), points.get(k + 1) - renderer.getChartValuesSpacing(), paint, 0); } } } @@ -680,7 +723,7 @@ protected void drawChartValuesText(Canvas canvas, XYSeries series, XYSeriesRende /** * The graphical representation of a text, to handle both HORIZONTAL and * VERTICAL orientations and extra rotation angles. - * + * * @param canvas the canvas to paint to * @param text the text to be rendered * @param x the X axis location of the text @@ -689,7 +732,7 @@ protected void drawChartValuesText(Canvas canvas, XYSeries series, XYSeriesRende * @param extraAngle the text angle */ protected void drawText(Canvas canvas, String text, float x, float y, Paint paint, - float extraAngle) { + float extraAngle) { float angle = -mRenderer.getOrientation().getAngle() + extraAngle; if (angle != 0) { // canvas.scale(1 / mScale, mScale); @@ -705,7 +748,7 @@ protected void drawText(Canvas canvas, String text, float x, float y, Paint pain /** * Transform the canvas such as it can handle both HORIZONTAL and VERTICAL * orientations. - * + * * @param canvas the canvas to paint to * @param angle the angle of rotation * @param inverse if the inverse transform needs to be applied @@ -724,7 +767,7 @@ private void transform(Canvas canvas, float angle, boolean inverse) { /** * The graphical representation of the labels on the X axis. - * + * * @param xLabels the X labels values * @param xTextLabelLocations the X text label locations * @param canvas the canvas to paint to @@ -737,35 +780,40 @@ private void transform(Canvas canvas, float angle, boolean inverse) { * @param maxX the maximum value on the X axis in the chart */ protected void drawXLabels(List xLabels, Double[] xTextLabelLocations, Canvas canvas, - Paint paint, int left, int top, int bottom, double xPixelsPerUnit, double minX, double maxX) { - int length = xLabels.size(); + Paint paint, int left, int top, int bottom, double xPixelsPerUnit, double minX, double maxX) { + boolean showXLabels = mRenderer.isShowXLabels(); - boolean showGridY = mRenderer.isShowGridY(); - if (showGridY) { - mGridPaint.setStyle(Style.STROKE); - mGridPaint.setStrokeWidth(mRenderer.getGridLineWidth()); - } + boolean showCustomXLabels = mRenderer.isShowCustomTextXLabels(); + boolean showGridX = mRenderer.isShowGridX(); boolean showTickMarks = mRenderer.isShowTickMarks(); - for (int i = 0; i < length; i++) { + + for (int i = 0; i < xLabels.size(); i++) { double label = xLabels.get(i); float xLabel = (float) (left + xPixelsPerUnit * (label - minX)); + if (showXLabels) { paint.setColor(mRenderer.getXLabelsColor()); + if (showTickMarks) { - canvas - .drawLine(xLabel, bottom, xLabel, bottom + mRenderer.getLabelsTextSize() / 3, paint); + canvas.drawLine(xLabel, bottom, xLabel, bottom + mRenderer.getLabelsTextSize() / 3, paint); } drawText(canvas, getLabel(mRenderer.getXLabelFormat(), label), xLabel, - bottom + mRenderer.getLabelsTextSize() * 4 / 3 + mRenderer.getXLabelsPadding(), paint, - mRenderer.getXLabelsAngle()); + bottom + mRenderer.getLabelsTextSize() * 4 / 3 + mRenderer.getXLabelsPadding(), paint, + mRenderer.getXLabelsAngle()); } - if (showGridY) { + if (showGridX) { + setStroke(mRenderer.getGridLineXStroke(), mGridPaint); + mGridPaint.setStrokeWidth(mRenderer.getGridLineWidth()); mGridPaint.setColor(mRenderer.getGridColor(0)); - canvas.drawLine(xLabel, bottom, xLabel, top, mGridPaint); + + Path gridLinePath = new Path(); + gridLinePath.moveTo(xLabel, bottom); + gridLinePath.lineTo(xLabel, top); + canvas.drawPath(gridLinePath, mGridPaint); } } - drawXTextLabels(xTextLabelLocations, canvas, paint, showXLabels, left, top, bottom, - xPixelsPerUnit, minX, maxX); + drawXTextLabels(xTextLabelLocations, canvas, paint, showCustomXLabels, left, top, bottom, + xPixelsPerUnit, minX, maxX); } /** @@ -782,24 +830,24 @@ protected void drawXLabels(List xLabels, Double[] xTextLabelLocations, C * @param minY the minimum value on the Y axis in the chart */ protected void drawYLabels(Map> allYLabels, Canvas canvas, Paint paint, - int maxScaleNumber, int left, int right, int bottom, double[] yPixelsPerUnit, double[] minY) { + int maxScaleNumber, int left, int right, int bottom, double[] yPixelsPerUnit, double[] minY) { + Orientation or = mRenderer.getOrientation(); - boolean showGridX = mRenderer.isShowGridX(); - if (showGridX) { - mGridPaint.setStyle(Style.STROKE); - mGridPaint.setStrokeWidth(mRenderer.getGridLineWidth()); - } + boolean showGridY = mRenderer.isShowGridY(); boolean showYLabels = mRenderer.isShowYLabels(); boolean showTickMarks = mRenderer.isShowTickMarks(); + for (int i = 0; i < maxScaleNumber; i++) { paint.setTextAlign(mRenderer.getYLabelsAlign(i)); List yLabels = allYLabels.get(i); int length = yLabels.size(); + for (int j = 0; j < length; j++) { double label = yLabels.get(j); Align axisAlign = mRenderer.getYAxisAlign(i); boolean textLabel = mRenderer.getYTextLabel(label, i) != null; float yLabel = (float) (bottom - yPixelsPerUnit[i] * (label - minY[i])); + if (or == Orientation.HORIZONTAL) { if (showYLabels && !textLabel) { paint.setColor(mRenderer.getYLabelsColor(i)); @@ -808,22 +856,28 @@ protected void drawYLabels(Map> allYLabels, Canvas canvas, canvas.drawLine(left + getLabelLinePos(axisAlign), yLabel, left, yLabel, paint); } drawText(canvas, getLabel(mRenderer.getYLabelFormat(i), label), - left - mRenderer.getYLabelsPadding(), - yLabel - mRenderer.getYLabelsVerticalPadding(), paint, - mRenderer.getYLabelsAngle()); + left - mRenderer.getYLabelsPadding(), + yLabel - mRenderer.getYLabelsVerticalPadding(), paint, + mRenderer.getYLabelsAngle()); } else { if (showTickMarks) { canvas.drawLine(right, yLabel, right + getLabelLinePos(axisAlign), yLabel, paint); } drawText(canvas, getLabel(mRenderer.getYLabelFormat(i), label), - right + mRenderer.getYLabelsPadding(), - yLabel - mRenderer.getYLabelsVerticalPadding(), paint, - mRenderer.getYLabelsAngle()); + right + mRenderer.getYLabelsPadding(), + yLabel - mRenderer.getYLabelsVerticalPadding(), paint, + mRenderer.getYLabelsAngle()); } } - if (showGridX) { + if (showGridY) { + setStroke(mRenderer.getGridLineYStroke(), mGridPaint); + mGridPaint.setStrokeWidth(mRenderer.getGridLineWidth()); mGridPaint.setColor(mRenderer.getGridColor(i)); - canvas.drawLine(left, yLabel, right, yLabel, mGridPaint); + + Path gridLinePath = new Path(); + gridLinePath.moveTo(left, yLabel); + gridLinePath.lineTo(right, yLabel); + canvas.drawPath(gridLinePath, mGridPaint); } } else if (or == Orientation.VERTICAL) { if (showYLabels && !textLabel) { @@ -832,10 +886,10 @@ protected void drawYLabels(Map> allYLabels, Canvas canvas, canvas.drawLine(right - getLabelLinePos(axisAlign), yLabel, right, yLabel, paint); } drawText(canvas, getLabel(mRenderer.getLabelFormat(), label), - right + 10 + mRenderer.getYLabelsPadding(), - yLabel - mRenderer.getYLabelsVerticalPadding(), paint, mRenderer.getYLabelsAngle()); + right + 10 + mRenderer.getYLabelsPadding(), + yLabel - mRenderer.getYLabelsVerticalPadding(), paint, mRenderer.getYLabelsAngle()); } - if (showGridX) { + if (showGridY) { mGridPaint.setColor(mRenderer.getGridColor(i)); if (showTickMarks) { canvas.drawLine(right, yLabel, left, yLabel, mGridPaint); @@ -848,7 +902,7 @@ protected void drawYLabels(Map> allYLabels, Canvas canvas, /** * The graphical representation of the text labels on the X axis. - * + * * @param xTextLabelLocations the X text label locations * @param canvas the canvas to paint to * @param paint the paint to be used for drawing @@ -860,30 +914,46 @@ protected void drawYLabels(Map> allYLabels, Canvas canvas, * @param maxX the maximum value on the X axis in the chart */ protected void drawXTextLabels(Double[] xTextLabelLocations, Canvas canvas, Paint paint, - boolean showLabels, int left, int top, int bottom, double xPixelsPerUnit, double minX, - double maxX) { - boolean showCustomTextGridX = mRenderer.isShowCustomTextGridX(); - boolean showTickMarks = mRenderer.isShowTickMarks(); - if (showLabels) { + boolean showCustomXLabels, int left, int top, int bottom, double xPixelsPerUnit, double minX, + double maxX) { + if (!showCustomXLabels) { + return; + } + boolean showCustomTextGridX = mRenderer.isShowCustomTextGridX(); + boolean showTickMarks = mRenderer.isShowTickMarks(); + paint.setColor(mRenderer.getXLabelsColor()); - for (Double location : xTextLabelLocations) { + paint.setTextSize(mRenderer.getLabelsTextSize()); + paint.setTextAlign(mRenderer.getXLabelsAlign()); + + for (Double location : xTextLabelLocations) { if (minX <= location && location <= maxX) { float xLabel = (float) (left + xPixelsPerUnit * (location.doubleValue() - minX)); paint.setColor(mRenderer.getXLabelsColor()); if (showTickMarks) { canvas.drawLine(xLabel, bottom, xLabel, bottom + mRenderer.getLabelsTextSize() / 3, - paint); + paint); } drawText(canvas, mRenderer.getXTextLabel(location), xLabel, - bottom + mRenderer.getLabelsTextSize() * 4 / 3 + mRenderer.getXLabelsPadding(), - paint, mRenderer.getXLabelsAngle()); + bottom + mRenderer.getLabelsTextSize() * 4 / 3 + mRenderer.getXLabelsPadding(), + paint, mRenderer.getXLabelsAngle()); + if (showCustomTextGridX) { - paint.setColor(mRenderer.getGridColor(0)); - canvas.drawLine(xLabel, bottom, xLabel, top, paint); + if (minX == location) { + setStroke(BasicStroke.SOLID, mGridPaint); + } else { + setStroke(mRenderer.getGridLineXStroke(), mGridPaint); + } + mGridPaint.setStrokeWidth(mRenderer.getGridLineWidth()); + mGridPaint.setColor(mRenderer.getGridColor(0)); + + Path gridLinePath = new Path(); + gridLinePath.moveTo(xLabel, bottom); + gridLinePath.lineTo(xLabel, top); + canvas.drawPath(gridLinePath, mGridPaint); } } } - } } // TODO: docs @@ -921,7 +991,7 @@ private int getLabelLinePos(Align align) { /** * Transforms a screen point to a real coordinates point. - * + * * @param screenX the screen x axis value * @param screenY the screen y axis value * @return the real coordinates point @@ -932,7 +1002,7 @@ public double[] toRealPoint(float screenX, float screenY, int scale) { double realMinY = mRenderer.getYAxisMin(scale); double realMaxY = mRenderer.getYAxisMax(scale); if (!mRenderer.isMinXSet(scale) || !mRenderer.isMaxXSet(scale) || !mRenderer.isMinYSet(scale) - || !mRenderer.isMaxYSet(scale)) { + || !mRenderer.isMaxYSet(scale)) { double[] calcRange = getCalcRange(scale); if (calcRange != null) { realMinX = calcRange[0]; @@ -943,9 +1013,9 @@ public double[] toRealPoint(float screenX, float screenY, int scale) { } if (mScreenR != null) { return new double[] { - (screenX - mScreenR.left) * (realMaxX - realMinX) / mScreenR.width() + realMinX, - (mScreenR.top + mScreenR.height() - screenY) * (realMaxY - realMinY) / mScreenR.height() - + realMinY }; + (screenX - mScreenR.left) * (realMaxX - realMinX) / mScreenR.width() + realMinX, + (mScreenR.top + mScreenR.height() - screenY) * (realMaxY - realMinY) / mScreenR.height() + + realMinY }; } else { return new double[] { screenX, screenY }; } @@ -957,7 +1027,7 @@ public double[] toScreenPoint(double[] realPoint, int scale) { double realMinY = mRenderer.getYAxisMin(scale); double realMaxY = mRenderer.getYAxisMax(scale); if (!mRenderer.isMinXSet(scale) || !mRenderer.isMaxXSet(scale) || !mRenderer.isMinYSet(scale) - || !mRenderer.isMaxYSet(scale)) { + || !mRenderer.isMaxYSet(scale)) { double[] calcRange = getCalcRange(scale); realMinX = calcRange[0]; realMaxX = calcRange[1]; @@ -966,8 +1036,8 @@ public double[] toScreenPoint(double[] realPoint, int scale) { } if (mScreenR != null) { return new double[] { - (realPoint[0] - realMinX) * mScreenR.width() / (realMaxX - realMinX) + mScreenR.left, - (realMaxY - realPoint[1]) * mScreenR.height() / (realMaxY - realMinY) + mScreenR.top }; + (realPoint[0] - realMinX) * mScreenR.width() / (realMaxX - realMinX) + mScreenR.left, + (realMaxY - realPoint[1]) * mScreenR.height() / (realMaxY - realMinY) + mScreenR.top }; } else { return realPoint; } @@ -999,7 +1069,7 @@ public SeriesSelection getSeriesAndPointForScreenCoordinate(final Point screenPo /** * The graphical representation of a series. - * + * * @param canvas the canvas to paint to * @param paint the paint to be used for drawing * @param points the array of points to be used for drawing the series @@ -1009,11 +1079,11 @@ public SeriesSelection getSeriesAndPointForScreenCoordinate(final Point screenPo * @param startIndex the start index of the rendering points */ public abstract void drawSeries(Canvas canvas, Paint paint, List points, - XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, int startIndex); + XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, int startIndex); /** * Returns the clickable areas for all passed points - * + * * @param points the array of points * @param values the array of values of each point * @param yAxisValue the minimum value of the y axis @@ -1022,11 +1092,11 @@ public abstract void drawSeries(Canvas canvas, Paint paint, List points, * @param startIndex the start index of the rendering points */ protected abstract ClickableArea[] clickableAreasForPoints(List points, - List values, float yAxisValue, int seriesIndex, int startIndex); + List values, float yAxisValue, int seriesIndex, int startIndex); /** * Returns if the chart should display the null values. - * + * * @return if null values should be rendered */ protected boolean isRenderNullValues() { @@ -1035,7 +1105,7 @@ protected boolean isRenderNullValues() { /** * Returns if the chart should display the points as a certain shape. - * + * * @param renderer the series renderer */ public boolean isRenderPoints(SimpleSeriesRenderer renderer) { @@ -1044,7 +1114,7 @@ public boolean isRenderPoints(SimpleSeriesRenderer renderer) { /** * Returns the default axis minimum. - * + * * @return the default axis minimum */ public double getDefaultMinimum() { @@ -1053,7 +1123,7 @@ public double getDefaultMinimum() { /** * Returns the scatter chart to be used for drawing the data points. - * + * * @return the data points scatter chart */ public ScatterChart getPointsChart() { @@ -1062,7 +1132,7 @@ public ScatterChart getPointsChart() { /** * Returns the chart type identifier. - * + * * @return the chart type */ public abstract String getChartType(); diff --git a/achartengine/src/org/achartengine/renderer/DefaultRenderer.java b/achartengine/src/org/achartengine/renderer/DefaultRenderer.java index 6c7c59b..84f26b7 100644 --- a/achartengine/src/org/achartengine/renderer/DefaultRenderer.java +++ b/achartengine/src/org/achartengine/renderer/DefaultRenderer.java @@ -1,12 +1,12 @@ /** * Copyright (C) 2009 - 2013 SC 4ViewSoft SRL - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -38,7 +38,7 @@ public class DefaultRenderer implements Serializable { public static final int TEXT_COLOR = Color.LTGRAY; /** A text font for regular text, like the chart labels. */ private static final Typeface REGULAR_TEXT_FONT = Typeface - .create(Typeface.SERIF, Typeface.NORMAL); + .create(Typeface.SERIF, Typeface.NORMAL); /** The typeface name for the texts. */ private String mTextTypefaceName = REGULAR_TEXT_FONT.toString(); /** The typeface style for the texts. */ @@ -77,10 +77,18 @@ public class DefaultRenderer implements Serializable { private boolean mShowGridY = false; /** The grid width. */ private float mGridLineWidth; + /** Grid X stroke */ + private BasicStroke mGridLineXStroke; + /** Grid Y stroke */ + private BasicStroke mGridLineYStroke; /** If the custom text grid should be displayed on the X axis. */ private boolean mShowCustomTextGridX = false; /** If the custom text grid should be displayed on the Y axis. */ private boolean mShowCustomTextGridY = false; + /** If the custom text should be displayed on the X axis. */ + private boolean mShowCustomTextXLabels = true; + /** If the custom text should be displayed on the Y axis. */ + private boolean mShowCustomTextYLabels = true; /** The simple renderers that are included in this multiple series renderer. */ private List mRenderers = new ArrayList(); /** The antialiasing flag. */ @@ -120,7 +128,7 @@ public class DefaultRenderer implements Serializable { /** * Returns the chart title. - * + * * @return the chart title */ public String getChartTitle() { @@ -129,7 +137,7 @@ public String getChartTitle() { /** * Sets the chart title. - * + * * @param title the chart title */ public void setChartTitle(String title) { @@ -138,7 +146,7 @@ public void setChartTitle(String title) { /** * Returns the chart title text size. - * + * * @return the chart title text size */ public float getChartTitleTextSize() { @@ -147,7 +155,7 @@ public float getChartTitleTextSize() { /** * Sets the chart title text size. - * + * * @param textSize the chart title text size */ public void setChartTitleTextSize(float textSize) { @@ -156,7 +164,7 @@ public void setChartTitleTextSize(float textSize) { /** * Adds a simple renderer to the multiple renderer. - * + * * @param renderer the renderer to be added */ public void addSeriesRenderer(SimpleSeriesRenderer renderer) { @@ -165,7 +173,7 @@ public void addSeriesRenderer(SimpleSeriesRenderer renderer) { /** * Adds a simple renderer to the multiple renderer. - * + * * @param index the index in the renderers list * @param renderer the renderer to be added */ @@ -175,7 +183,7 @@ public void addSeriesRenderer(int index, SimpleSeriesRenderer renderer) { /** * Removes a simple renderer from the multiple renderer. - * + * * @param renderer the renderer to be removed */ public void removeSeriesRenderer(SimpleSeriesRenderer renderer) { @@ -191,7 +199,7 @@ public void removeAllRenderers() { /** * Returns the simple renderer from the multiple renderer list. - * + * * @param index the index in the simple renderers list * @return the simple renderer at the specified index */ @@ -201,7 +209,7 @@ public SimpleSeriesRenderer getSeriesRendererAt(int index) { /** * Returns the simple renderers count in the multiple renderer list. - * + * * @return the simple renderers count */ public int getSeriesRendererCount() { @@ -210,7 +218,7 @@ public int getSeriesRendererCount() { /** * Returns an array of the simple renderers in the multiple renderer list. - * + * * @return the simple renderers array */ public SimpleSeriesRenderer[] getSeriesRenderers() { @@ -219,7 +227,7 @@ public SimpleSeriesRenderer[] getSeriesRenderers() { /** * Returns the background color. - * + * * @return the background color */ public int getBackgroundColor() { @@ -228,7 +236,7 @@ public int getBackgroundColor() { /** * Sets the background color. - * + * * @param color the background color */ public void setBackgroundColor(int color) { @@ -237,7 +245,7 @@ public void setBackgroundColor(int color) { /** * Returns if the background color should be applied. - * + * * @return the apply flag for the background color. */ public boolean isApplyBackgroundColor() { @@ -246,7 +254,7 @@ public boolean isApplyBackgroundColor() { /** * Sets if the background color should be applied. - * + * * @param apply the apply flag for the background color */ public void setApplyBackgroundColor(boolean apply) { @@ -255,7 +263,7 @@ public void setApplyBackgroundColor(boolean apply) { /** * Returns the axes color. - * + * * @return the axes color */ public int getAxesColor() { @@ -268,7 +276,7 @@ public int getAxesColor() { /** * Sets the axes color. - * + * * @param color the axes color */ public void setAxesColor(int color) { @@ -278,7 +286,7 @@ public void setAxesColor(int color) { /** * Returns the color of the Y axis - * + * * @return the Y axis color */ public int getYAxisColor() { @@ -287,7 +295,7 @@ public int getYAxisColor() { /** * Sets the Y axis color. - * + * * @param color the Y axis color */ public void setYAxisColor(int color) { @@ -296,7 +304,7 @@ public void setYAxisColor(int color) { /** * Returns the color of the X axis - * + * * @return the X axis color */ public int getXAxisColor() { @@ -305,7 +313,7 @@ public int getXAxisColor() { /** * Sets the X axis color. - * + * * @param color the X axis color */ public void setXAxisColor(int color) { @@ -314,7 +322,7 @@ public void setXAxisColor(int color) { /** * Returns the labels color. - * + * * @return the labels color */ public int getLabelsColor() { @@ -323,7 +331,7 @@ public int getLabelsColor() { /** * Sets the labels color. - * + * * @param color the labels color */ public void setLabelsColor(int color) { @@ -332,7 +340,7 @@ public void setLabelsColor(int color) { /** * Returns the labels text size. - * + * * @return the labels text size */ public float getLabelsTextSize() { @@ -341,7 +349,7 @@ public float getLabelsTextSize() { /** * Sets the labels text size. - * + * * @param textSize the labels text size */ public void setLabelsTextSize(float textSize) { @@ -350,7 +358,7 @@ public void setLabelsTextSize(float textSize) { /** * Returns if the axes should be visible. - * + * * @return the visibility flag for the axes */ public boolean isShowAxes() { @@ -359,7 +367,7 @@ public boolean isShowAxes() { /** * Sets if the axes should be visible. - * + * * @param showAxes the visibility flag for the axes */ public void setShowAxes(boolean showAxes) { @@ -416,7 +424,7 @@ public void setShowLabels(boolean showLabels) { /** * Returns if the tick marks should be visible. - * + * * @return */ public boolean isShowTickMarks() { @@ -425,16 +433,16 @@ public boolean isShowTickMarks() { /** * Sets if the tick marks should be visible. - * + * * @param showTickMarks the visibility flag for the tick marks */ - public void setShowTickMarks(boolean mShowTickMarks) { - this.mShowTickMarks = mShowTickMarks; + public void setShowTickMarks(boolean showTickMarks) { + this.mShowTickMarks = showTickMarks; } /** * Returns if the X axis grid should be visible. - * + * * @return the visibility flag for the X axis grid */ public boolean isShowGridX() { @@ -443,7 +451,7 @@ public boolean isShowGridX() { /** * Returns if the Y axis grid should be visible. - * + * * @return the visibility flag for the Y axis grid */ public boolean isShowGridY() { @@ -452,7 +460,7 @@ public boolean isShowGridY() { /** * Sets if the X axis grid should be visible. - * + * * @param showGrid the visibility flag for the X axis grid */ public void setShowGridX(boolean showGrid) { @@ -477,9 +485,50 @@ public float getGridLineWidth() { return mGridLineWidth; } + /** + * Gets the grid line X stroke. + * @return the grid line X stroke + */ + public BasicStroke getGridLineXStroke() { + return mGridLineXStroke; + } + + /** + * Sets the grid line X stroke. + * @param gridLineXStroke grid line X stroke + */ + public void setGridLineXStroke(BasicStroke gridLineXStroke) { + this.mGridLineXStroke = gridLineXStroke; + } + + /** + * Gets the grid line Y stroke. + * @return the grid line Y stroke + */ + public BasicStroke getGridLineYStroke() { + return mGridLineYStroke; + } + + /** + * Sets the grid line Y stroke. + * @param gridLineYStroke grid line Y stroke + */ + public void setGridLineYStroke(BasicStroke gridLineYStroke) { + this.mGridLineYStroke = gridLineYStroke; + } + + /** + * Sets the stroke for X and Y grid lines. + * @param gridLineStroke grid line stroke for X and Y + */ + public void setGridLineStroke(BasicStroke gridLineStroke) { + this.mGridLineXStroke = gridLineStroke; + this.mGridLineYStroke = gridLineStroke; + } + /** * Sets if the Y axis grid should be visible. - * + * * @param showGrid the visibility flag for the Y axis grid */ public void setShowGridY(boolean showGrid) { @@ -488,7 +537,7 @@ public void setShowGridY(boolean showGrid) { /** * Sets if the grid should be visible. - * + * * @param showGrid the visibility flag for the grid */ public void setShowGrid(boolean showGrid) { @@ -498,7 +547,7 @@ public void setShowGrid(boolean showGrid) { /** * Returns if the X axis custom text grid should be visible. - * + * * @return the visibility flag for the X axis custom text grid */ public boolean isShowCustomTextGridX() { @@ -507,7 +556,7 @@ public boolean isShowCustomTextGridX() { /** * Returns if the Y axis custom text grid should be visible. - * + * * @return the visibility flag for the custom text Y axis grid */ public boolean isShowCustomTextGridY() { @@ -516,7 +565,7 @@ public boolean isShowCustomTextGridY() { /** * Sets if the X axis custom text grid should be visible. - * + * * @param showGrid the visibility flag for the X axis custom text grid */ public void setShowCustomTextGridX(boolean showGrid) { @@ -525,16 +574,42 @@ public void setShowCustomTextGridX(boolean showGrid) { /** * Sets if the Y axis custom text grid should be visible. - * + * * @param showGrid the visibility flag for the Y axis custom text grid */ public void setShowCustomTextGridY(boolean showGrid) { mShowCustomTextGridY = showGrid; } + public boolean isShowCustomTextXLabels() { + return mShowCustomTextXLabels; + } + + public void setShowCustomTextXLabels(boolean mShowCustomTextXLabels) { + this.mShowCustomTextXLabels = mShowCustomTextXLabels; + } + + public boolean isShowCustomTextYLabels() { + return mShowCustomTextYLabels; + } + + public void setShowCustomTextYLabels(boolean mShowCustomTextYLabels) { + this.mShowCustomTextYLabels = mShowCustomTextYLabels; + } + + public void setShowCustomTextLabels(boolean mShowCustomTextLabels) { + this.mShowCustomTextXLabels = mShowCustomTextLabels; + this.mShowCustomTextYLabels = mShowCustomTextLabels; + } + + public void setShowCustomTextLabels(boolean showCustomTextXLabels, boolean showCustomTextYLabels) { + this.mShowCustomTextXLabels = showCustomTextXLabels; + this.mShowCustomTextYLabels = showCustomTextYLabels; + } + /** * Sets if the grid for custom X or Y labels should be visible. - * + * * @param showGrid the visibility flag for the custom text grid */ public void setShowCustomTextGrid(boolean showGrid) { @@ -544,7 +619,7 @@ public void setShowCustomTextGrid(boolean showGrid) { /** * Returns if the legend should be visible. - * + * * @return the visibility flag for the legend */ public boolean isShowLegend() { @@ -553,7 +628,7 @@ public boolean isShowLegend() { /** * Sets if the legend should be visible. - * + * * @param showLegend the visibility flag for the legend */ public void setShowLegend(boolean showLegend) { @@ -562,7 +637,7 @@ public void setShowLegend(boolean showLegend) { /** * Returns if the legend should size to fit. - * + * * @return the fit behavior */ public boolean isFitLegend() { @@ -571,7 +646,7 @@ public boolean isFitLegend() { /** * Sets if the legend should size to fit. - * + * * @param fit the fit behavior */ public void setFitLegend(boolean fit) { @@ -580,7 +655,7 @@ public void setFitLegend(boolean fit) { /** * Returns the text typeface name. - * + * * @return the text typeface name */ public String getTextTypefaceName() { @@ -589,7 +664,7 @@ public String getTextTypefaceName() { /** * Returns the text typeface style. - * + * * @return the text typeface style */ public int getTextTypefaceStyle() { @@ -598,7 +673,7 @@ public int getTextTypefaceStyle() { /** * Returns the text typeface. - * + * * @return the text typeface */ public Typeface getTextTypeface() { @@ -607,7 +682,7 @@ public Typeface getTextTypeface() { /** * Returns the legend text size. - * + * * @return the legend text size */ public float getLegendTextSize() { @@ -616,7 +691,7 @@ public float getLegendTextSize() { /** * Sets the legend text size. - * + * * @param textSize the legend text size */ public void setLegendTextSize(float textSize) { @@ -625,7 +700,7 @@ public void setLegendTextSize(float textSize) { /** * Sets the text typeface name and style. - * + * * @param typefaceName the text typeface name * @param style the text typeface style */ @@ -636,7 +711,7 @@ public void setTextTypeface(String typefaceName, int style) { /** * Sets the text typeface. - * + * * @param typeface the typeface */ public void setTextTypeface(Typeface typeface) { @@ -645,7 +720,7 @@ public void setTextTypeface(Typeface typeface) { /** * Returns the antialiasing flag value. - * + * * @return the antialiasing value */ public boolean isAntialiasing() { @@ -654,7 +729,7 @@ public boolean isAntialiasing() { /** * Sets the antialiasing value. - * + * * @param antialiasing the antialiasing */ public void setAntialiasing(boolean antialiasing) { @@ -663,7 +738,7 @@ public void setAntialiasing(boolean antialiasing) { /** * Returns the value to be used for scaling the chart. - * + * * @return the scale value */ public float getScale() { @@ -672,7 +747,7 @@ public float getScale() { /** * Returns the original value to be used for scaling the chart. - * + * * @return the original scale value */ public float getOriginalScale() { @@ -682,7 +757,7 @@ public float getOriginalScale() { /** * Sets the value to be used for scaling the chart. It works on some charts * like pie, doughnut, dial. - * + * * @param scale the scale value */ public void setScale(float scale) { @@ -691,7 +766,7 @@ public void setScale(float scale) { /** * Returns the enabled state of the zoom. - * + * * @return if zoom is enabled */ public boolean isZoomEnabled() { @@ -700,7 +775,7 @@ public boolean isZoomEnabled() { /** * Sets the enabled state of the zoom. - * + * * @param enabled zoom enabled */ public void setZoomEnabled(boolean enabled) { @@ -709,7 +784,7 @@ public void setZoomEnabled(boolean enabled) { /** * Returns the visible state of the zoom buttons. - * + * * @return if zoom buttons are visible */ public boolean isZoomButtonsVisible() { @@ -718,7 +793,7 @@ public boolean isZoomButtonsVisible() { /** * Sets the visible state of the zoom buttons. - * + * * @param visible if the zoom buttons are visible */ public void setZoomButtonsVisible(boolean visible) { @@ -727,7 +802,7 @@ public void setZoomButtonsVisible(boolean visible) { /** * Returns the enabled state of the external (application implemented) zoom. - * + * * @return if external zoom is enabled */ public boolean isExternalZoomEnabled() { @@ -736,7 +811,7 @@ public boolean isExternalZoomEnabled() { /** * Sets the enabled state of the external (application implemented) zoom. - * + * * @param enabled external zoom enabled */ public void setExternalZoomEnabled(boolean enabled) { @@ -745,7 +820,7 @@ public void setExternalZoomEnabled(boolean enabled) { /** * Returns the zoom rate. - * + * * @return the zoom rate */ public float getZoomRate() { @@ -754,7 +829,7 @@ public float getZoomRate() { /** * Returns the enabled state of the pan. - * + * * @return if pan is enabled */ public boolean isPanEnabled() { @@ -763,7 +838,7 @@ public boolean isPanEnabled() { /** * Sets the enabled state of the pan. - * + * * @param enabled pan enabled */ public void setPanEnabled(boolean enabled) { @@ -772,7 +847,7 @@ public void setPanEnabled(boolean enabled) { /** * Sets the zoom rate. - * + * * @param rate the zoom rate */ public void setZoomRate(float rate) { @@ -781,7 +856,7 @@ public void setZoomRate(float rate) { /** * Returns the enabled state of the click. - * + * * @return if click is enabled */ public boolean isClickEnabled() { @@ -790,7 +865,7 @@ public boolean isClickEnabled() { /** * Sets the enabled state of the click. - * + * * @param enabled click enabled */ public void setClickEnabled(boolean enabled) { @@ -799,7 +874,7 @@ public void setClickEnabled(boolean enabled) { /** * Returns the selectable radius value around clickable points. - * + * * @return the selectable radius */ public int getSelectableBuffer() { @@ -808,7 +883,7 @@ public int getSelectableBuffer() { /** * Sets the selectable radius value around clickable points. - * + * * @param buffer the selectable radius */ public void setSelectableBuffer(int buffer) { @@ -817,7 +892,7 @@ public void setSelectableBuffer(int buffer) { /** * Returns the legend height. - * + * * @return the legend height */ public int getLegendHeight() { @@ -826,7 +901,7 @@ public int getLegendHeight() { /** * Sets the legend height, in pixels. - * + * * @param height the legend height */ public void setLegendHeight(int height) { @@ -836,7 +911,7 @@ public void setLegendHeight(int height) { /** * Returns the margin sizes. An array containing the margins in this order: * top, left, bottom, right - * + * * @return the margin sizes */ public int[] getMargins() { @@ -845,7 +920,7 @@ public int[] getMargins() { /** * Sets the margins, in pixels. - * + * * @param margins an array containing the margin size values, in this order: * top, left, bottom, right */ @@ -855,7 +930,7 @@ public void setMargins(int[] margins) { /** * Returns if the chart is inside a scroll view and doesn't need to shrink. - * + * * @return if it is inside a scroll view */ public boolean isInScroll() { @@ -865,7 +940,7 @@ public boolean isInScroll() { /** * To be set if the chart is inside a scroll view and doesn't need to shrink * when not enough space. - * + * * @param inScroll if it is inside a scroll view */ public void setInScroll(boolean inScroll) { @@ -876,7 +951,7 @@ public void setInScroll(boolean inScroll) { * Returns the start angle for circular charts such as pie, doughnut. An angle * of 0 degrees correspond to the geometric angle of 0 degrees (3 o'clock on a * watch.) - * + * * @return the start angle in degrees */ public float getStartAngle() { @@ -887,7 +962,7 @@ public float getStartAngle() { * Sets the start angle for circular charts such as pie, doughnut, etc. An * angle of 0 degrees correspond to the geometric angle of 0 degrees (3 * o'clock on a watch.) - * + * * @param startAngle the start angle in degrees */ public void setStartAngle(float startAngle) { @@ -899,7 +974,7 @@ public void setStartAngle(float startAngle) { /** * Returns if the values should be displayed as text. - * + * * @return if the values should be displayed as text */ public boolean isDisplayValues() { @@ -908,7 +983,7 @@ public boolean isDisplayValues() { /** * Sets if the values should be displayed as text (supported by pie chart). - * + * * @param display if the values should be displayed as text */ public void setDisplayValues(boolean display) {