Class AbstractChart

java.lang.Object
com.codename1.charts.views.AbstractChart
Direct Known Subclasses:
RoundChart, XYChart

public abstract class AbstractChart extends Object
An abstract class to be implemented by the chart rendering classes.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static float[]
    calculateDrawPoints(float p1x, float p1y, float p2x, float p2y, int screenHeight, int screenWidth)
     
    abstract void
    draw(Canvas canvas, int x, int y, int width, int height, Paint paint)
    The graphical representation of the chart.
    protected void
    drawBackground(DefaultRenderer renderer, Canvas canvas, int x, int y, int width, int height, Paint paint, boolean newColor, int color)
    Draws the chart background.
    protected void
    drawLabel(Canvas canvas, String labelText, DefaultRenderer renderer, List<Rectangle2D> prevLabelsBounds, int centerX, int centerY, float shortRadius, float longRadius, float currentAngle, float angle, int left, int right, int color, Paint paint, boolean line, boolean display)
    Draws a text label.
    protected int
    drawLegend(Canvas canvas, DefaultRenderer renderer, String[] titles, int left, int right, int y, int width, int height, int legendSize, Paint paint, boolean calculate)
    Draws the chart legend.
    abstract void
    drawLegendShape(Canvas canvas, SimpleSeriesRenderer renderer, float x, float y, int seriesIndex, Paint paint)
    The graphical representation of the legend shape.
    protected void
    drawPath(Canvas canvas, float[] points, Paint paint, boolean circular)
    The graphical representation of a path.
    protected void
    drawPath(Canvas canvas, List<Float> points, Paint paint, boolean circular)
    The graphical representation of a path.
    protected void
    drawString(Canvas canvas, String text, float x, float y, Paint paint)
    Draw a multiple lines string.
    protected boolean
    getExceed(float currentWidth, DefaultRenderer renderer, int right, int width)
    Calculates if the current width exceeds the total width.
    protected String
    getLabel(NumberFormat format, double label)
    Makes sure the fraction digit is not displayed, if not needed.
    abstract int
    getLegendShapeWidth(int seriesIndex)
    Returns the legend shape width.
    protected int
    getLegendSize(DefaultRenderer renderer, int defaultHeight, float extraHeight)
    Calculates the current legend size.
    Given screen coordinates, returns the series and point indexes of a chart element.
    boolean
    isNullValue(double value)
     
    boolean
    Checks if the current chart is rendered as vertical.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
     
    boolean
    Indicates whether some other object is "equal to" this one.
    final Class
    Returns the runtime class of an object.
    int
    Returns a hash code value for the object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes current thread to wait until another thread invokes the method or the method for this object.
    final void
    wait(long timeout)
    Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
    final void
    wait(long timeout, int nanos)
    Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
  • Constructor Details

    • AbstractChart

      public AbstractChart()
  • Method Details

    • calculateDrawPoints

      protected static float[] calculateDrawPoints(float p1x, float p1y, float p2x, float p2y, int screenHeight, int screenWidth)
    • draw

      public abstract void draw(Canvas canvas, int x, int y, int width, int height, Paint paint)

      The graphical representation of the chart.

      Parameters
      • canvas: the canvas to paint to

      • x: the top left x value of the view to draw to

      • y: the top left y value of the view to draw to

      • width: the width of the view to draw to

      • height: the height of the view to draw to

      • paint: the paint

    • drawBackground

      protected void drawBackground(DefaultRenderer renderer, Canvas canvas, int x, int y, int width, int height, Paint paint, boolean newColor, int color)

      Draws the chart background.

      Parameters
      • renderer: the chart renderer

      • canvas: the canvas to paint to

      • x: the top left x value of the view to draw to

      • y: the top left y value of the view to draw to

      • width: the width of the view to draw to

      • height: the height of the view to draw to

      • paint: the paint used for drawing

      • newColor: if a new color is to be used

      • color: the color to be used

    • drawLegend

      protected int drawLegend(Canvas canvas, DefaultRenderer renderer, String[] titles, int left, int right, int y, int width, int height, int legendSize, Paint paint, boolean calculate)

      Draws the chart legend.

      Parameters
      • canvas: the canvas to paint to

      • renderer: the series renderer

      • titles: the titles to go to the legend

      • left: the left X value of the area to draw to

      • right: the right X value of the area to draw to

      • y: the y value of the area to draw to

      • width: the width of the area to draw to

      • height: the height of the area to draw to

      • legendSize: the legend size

      • paint: the paint to be used for drawing

      • calculate: if only calculating the legend size

      Returns

      the legend height

    • drawString

      protected void drawString(Canvas canvas, String text, float x, float y, Paint paint)

      Draw a multiple lines string.

      Parameters
      • canvas: the canvas to paint to

      • text: the text to be painted

      • x: the x value of the area to draw to

      • y: the y value of the area to draw to

      • paint: the paint to be used for drawing

    • getExceed

      protected boolean getExceed(float currentWidth, DefaultRenderer renderer, int right, int width)

      Calculates if the current width exceeds the total width.

      Parameters
      • currentWidth: the current width

      • renderer: the renderer

      • right: the right side pixel value

      • width: the total width

      Returns

      if the current width exceeds the total width

    • isVertical

      public boolean isVertical(DefaultRenderer renderer)

      Checks if the current chart is rendered as vertical.

      Parameters
      • renderer: the renderer
      Returns

      if the chart is rendered as a vertical one

    • getLabel

      protected String getLabel(NumberFormat format, double label)

      Makes sure the fraction digit is not displayed, if not needed.

      Parameters
      • format: the number format for the label

      • label: the input label value

      Returns

      the label without the useless fraction digit

    • drawPath

      protected void drawPath(Canvas canvas, List<Float> points, Paint paint, boolean circular)

      The graphical representation of a path.

      Parameters
      • canvas: the canvas to paint to

      • points: the points that are contained in the path to paint

      • paint: the paint to be used for painting

      • circular: if the path ends with the start point

    • drawPath

      protected void drawPath(Canvas canvas, float[] points, Paint paint, boolean circular)

      The graphical representation of a path.

      Parameters
      • canvas: the canvas to paint to

      • points: the points that are contained in the path to paint

      • paint: the paint to be used for painting

      • circular: if the path ends with the start point

    • getLegendShapeWidth

      public abstract int getLegendShapeWidth(int seriesIndex)

      Returns the legend shape width.

      Parameters
      • seriesIndex: the series index
      Returns

      the legend shape width

    • drawLegendShape

      public abstract void drawLegendShape(Canvas canvas, SimpleSeriesRenderer renderer, float x, float y, int seriesIndex, Paint paint)

      The graphical representation of the legend shape.

      Parameters
      • canvas: the canvas to paint to

      • renderer: the series renderer

      • x: the x value of the point the shape should be drawn at

      • y: the y value of the point the shape should be drawn at

      • seriesIndex: the series index

      • paint: the paint to be used for drawing

    • getLegendSize

      protected int getLegendSize(DefaultRenderer renderer, int defaultHeight, float extraHeight)

      Calculates the current legend size.

      Parameters
      • renderer: the renderer

      • defaultHeight: the default height

      • extraHeight: the added extra height

      Returns

      the legend size

    • drawLabel

      protected void drawLabel(Canvas canvas, String labelText, DefaultRenderer renderer, List<Rectangle2D> prevLabelsBounds, int centerX, int centerY, float shortRadius, float longRadius, float currentAngle, float angle, int left, int right, int color, Paint paint, boolean line, boolean display)

      Draws a text label.

      Parameters
      • canvas: the canvas

      • labelText: the label text

      • renderer: the renderer

      • prevLabelsBounds: the previous rendered label bounds

      • centerX: the round chart center on X axis

      • centerY: the round chart center on Y axis

      • shortRadius: the short radius for the round chart

      • longRadius: the long radius for the round chart

      • currentAngle: the current angle

      • angle: the label extra angle

      • left: the left side

      • right: the right side

      • color: the label color

      • paint: the paint

      • line: if a line to the label should be drawn

      • display: display the label anyway

    • isNullValue

      public boolean isNullValue(double value)
    • getSeriesAndPointForScreenCoordinate

      public SeriesSelection getSeriesAndPointForScreenCoordinate(Point screenPoint)

      Given screen coordinates, returns the series and point indexes of a chart element. If there is no chart element (line, point, bar, etc) at those coordinates, null is returned.

      Parameters
      • screenPoint
      Returns

      the series and point indexes