Class CartesianPlotContext

java.lang.Object
com.arbergashi.charts.api.CartesianPlotContext
All Implemented Interfaces:
PlotContext

public class CartesianPlotContext extends Object implements PlotContext
Standard PlotContext implementation for Cartesian coordinate systems.

This context is optimized for rendering performance. It precomputes linear scaling factors so mapToPixel(double, double, double[]) and mapToData(double, double, double[]) run in constant time with no intermediate allocations.

Since:
2025-06-01
Version:
1.0.0
Author:
Arber Gashi
  • Constructor Details

    • CartesianPlotContext

      public CartesianPlotContext(Rectangle2D bounds, double minX, double maxX, double minY, double maxY)
      Creates a new context for the given data range and plot bounds.
      Parameters:
      bounds - the plot area in pixel coordinates
      minX - minimum visible X value (data coordinates)
      maxX - maximum visible X value (data coordinates)
      minY - minimum visible Y value (data coordinates)
      maxY - maximum visible Y value (data coordinates)
      Throws:
      IllegalArgumentException - if minX >= maxX or minY >= maxY
  • Method Details

    • mapToPixel

      public void mapToPixel(double dataX, double dataY, double[] dest)
      Maps data coordinates to pixel coordinates.

      Allocation-free: writes the result to dest where dest[0] is X and dest[1] is Y.

      Specified by:
      mapToPixel in interface PlotContext
      Parameters:
      dataX - X in data coordinates
      dataY - Y in data coordinates
      dest - output array of length at least 2
    • mapToData

      public void mapToData(double pixelX, double pixelY, double[] dest)
      Maps pixel coordinates to data coordinates.

      Allocation-free: writes the result to dest where dest[0] is X and dest[1] is Y.

      Specified by:
      mapToData in interface PlotContext
      Parameters:
      pixelX - X in pixel coordinates
      pixelY - Y in pixel coordinates
      dest - output array of length at least 2
    • plotBounds

      public Rectangle2D plotBounds()
      Returns the plot bounds in pixel coordinates.
      Specified by:
      plotBounds in interface PlotContext
    • minX

      public double minX()
      Description copied from interface: PlotContext
      Minimum visible X value (data coordinates).
      Specified by:
      minX in interface PlotContext
      Returns:
      minimum visible X value (data coordinates)
    • maxX

      public double maxX()
      Description copied from interface: PlotContext
      Maximum visible X value (data coordinates).
      Specified by:
      maxX in interface PlotContext
      Returns:
      maximum visible X value (data coordinates)
    • minY

      public double minY()
      Description copied from interface: PlotContext
      Minimum visible Y value (data coordinates).
      Specified by:
      minY in interface PlotContext
      Returns:
      minimum visible Y value (data coordinates)
    • maxY

      public double maxY()
      Description copied from interface: PlotContext
      Maximum visible Y value (data coordinates).
      Specified by:
      maxY in interface PlotContext
      Returns:
      maximum visible Y value (data coordinates)