Class DefaultMatrixChartModel

java.lang.Object
com.arbergashi.charts.model.DefaultMatrixChartModel
All Implemented Interfaces:
ChartModel, MatrixChartModel

public class DefaultMatrixChartModel extends Object implements MatrixChartModel
Default implementation for a matrix-based chart model.
Since:
2025-06-01
Version:
1.0.0
Author:
Arber Gashi
  • Constructor Details

    • DefaultMatrixChartModel

      public DefaultMatrixChartModel(double[][] matrix, List<String> labels)
  • Method Details

    • getMatrix

      public double[][] getMatrix()
      Description copied from interface: MatrixChartModel
      Returns the data as a 2D matrix. The matrix represents the flow or relationship between entities.
      Specified by:
      getMatrix in interface MatrixChartModel
      Returns:
      A 2D double array where matrix[i][j] is the value from entity i to j.
    • getEntityLabels

      public List<String> getEntityLabels()
      Description copied from interface: MatrixChartModel
      Returns the labels for the entities (nodes) in the matrix. The size of this list should match the dimensions of the matrix.
      Specified by:
      getEntityLabels in interface MatrixChartModel
      Returns:
      A list of labels for each entity.
    • getName

      public String getName()
      Description copied from interface: ChartModel
      Returns the title of the data series.
      Specified by:
      getName in interface ChartModel
      Returns:
      Name of the series
    • setName

      public void setName(String name)
    • getColor

      public Color getColor()
      Description copied from interface: ChartModel
      Optional visual color for a series; default is null.
      Specified by:
      getColor in interface ChartModel
    • setColor

      public void setColor(Color color)
      Description copied from interface: ChartModel
      Optional setter for a visual color; default no-op.
      Specified by:
      setColor in interface ChartModel
    • getUpdateStamp

      public long getUpdateStamp()
      Description copied from interface: ChartModel
      Optional timestamp for model updates; default 0 for simple models.
      Specified by:
      getUpdateStamp in interface ChartModel
    • getPointCount

      public int getPointCount()
      Description copied from interface: ChartModel
      Returns the number of data points.
      Specified by:
      getPointCount in interface ChartModel
      Returns:
      count
    • getX

      public double getX(int index)
      Description copied from interface: ChartModel
      Returns the X value at the given index.
      Specified by:
      getX in interface ChartModel
      Parameters:
      index - data point index
      Returns:
      X value or 0.0 if out of range
    • getY

      public double getY(int index)
      Description copied from interface: ChartModel
      Returns the Y value at the given index.
      Specified by:
      getY in interface ChartModel
      Parameters:
      index - data point index
      Returns:
      Y value or 0.0 if out of range
    • addPoint

      public void addPoint(ChartPoint point)
    • addPoints

      public void addPoints(List<ChartPoint> points)
    • setPoints

      public void setPoints(List<ChartPoint> points)
    • clear

      public void clear()
    • addChangeListener

      public void addChangeListener(ChartModel.ChartModelListener listener)
      Description copied from interface: ChartModel
      Registers a listener for data changes.
      Specified by:
      addChangeListener in interface ChartModel
      Parameters:
      listener - The listener
    • removeChangeListener

      public void removeChangeListener(ChartModel.ChartModelListener listener)
      Description copied from interface: ChartModel
      Removes a listener.
      Specified by:
      removeChangeListener in interface ChartModel
      Parameters:
      listener - The listener
    • getXData

      public double[] getXData()
      Description copied from interface: ChartModel
      Direct access to the X-coordinate array.

      Framework contract: Implementations may return either:

      Consumers must never assume getXData().length == getPointCount(). Always bound iteration by the logical size:

      int n = Math.min(model.getPointCount(), model.getXData().length);
      

      Performance note: If you need strict size and immutability semantics, use a model implementation that returns copies (e.g. DefaultChartModel).

      Specified by:
      getXData in interface ChartModel
      Returns:
      X values array (may be larger than logical size)
    • getYData

      public double[] getYData()
      Description copied from interface: ChartModel
      Direct access to the Y-coordinate array.

      Warning: For performance reasons, the internal array is often returned. Do not modify!

      Specified by:
      getYData in interface ChartModel
      Returns:
      double array of Y values