Class DefaultMatrixChartModel
java.lang.Object
com.arbergashi.charts.model.DefaultMatrixChartModel
- All Implemented Interfaces:
ChartModel, MatrixChartModel
Default implementation for a matrix-based chart model.
- Since:
- 2025-06-01
- Version:
- 1.0.0
- Author:
- Arber Gashi
-
Nested Class Summary
Nested classes/interfaces inherited from interface ChartModel
ChartModel.ChartModelListener -
Field Summary
Fields inherited from interface ChartModel
EMPTY_DOUBLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters a listener for data changes.voidaddPoint(ChartPoint point) voidaddPoints(List<ChartPoint> points) voidclear()getColor()Optional visual color for a series; default is null.Returns the labels for the entities (nodes) in the matrix.double[][]Returns the data as a 2D matrix.getName()Returns the title of the data series.intReturns the number of data points.longOptional timestamp for model updates; default 0 for simple models.doublegetX(int index) Returns the X value at the given index.double[]getXData()Direct access to the X-coordinate array.doublegetY(int index) Returns the Y value at the given index.double[]getYData()Direct access to the Y-coordinate array.voidRemoves a listener.voidOptional setter for a visual color; default no-op.voidvoidsetPoints(List<ChartPoint> points) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ChartModel
getDataRange, getHighData, getLabel, getLowData, getMax, getMin, getOpenData, getValue, getWeight, getWeightData, getY, isEmpty
-
Constructor Details
-
DefaultMatrixChartModel
-
-
Method Details
-
getMatrix
public double[][] getMatrix()Description copied from interface:MatrixChartModelReturns the data as a 2D matrix. The matrix represents the flow or relationship between entities.- Specified by:
getMatrixin interfaceMatrixChartModel- Returns:
- A 2D double array where matrix[i][j] is the value from entity i to j.
-
getEntityLabels
Description copied from interface:MatrixChartModelReturns the labels for the entities (nodes) in the matrix. The size of this list should match the dimensions of the matrix.- Specified by:
getEntityLabelsin interfaceMatrixChartModel- Returns:
- A list of labels for each entity.
-
getName
Description copied from interface:ChartModelReturns the title of the data series.- Specified by:
getNamein interfaceChartModel- Returns:
- Name of the series
-
setName
-
getColor
Description copied from interface:ChartModelOptional visual color for a series; default is null.- Specified by:
getColorin interfaceChartModel
-
setColor
Description copied from interface:ChartModelOptional setter for a visual color; default no-op.- Specified by:
setColorin interfaceChartModel
-
getUpdateStamp
public long getUpdateStamp()Description copied from interface:ChartModelOptional timestamp for model updates; default 0 for simple models.- Specified by:
getUpdateStampin interfaceChartModel
-
getPointCount
public int getPointCount()Description copied from interface:ChartModelReturns the number of data points.- Specified by:
getPointCountin interfaceChartModel- Returns:
- count
-
getX
public double getX(int index) Description copied from interface:ChartModelReturns the X value at the given index.- Specified by:
getXin interfaceChartModel- 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:ChartModelReturns the Y value at the given index.- Specified by:
getYin interfaceChartModel- Parameters:
index- data point index- Returns:
- Y value or 0.0 if out of range
-
addPoint
-
addPoints
-
setPoints
-
clear
public void clear() -
addChangeListener
Description copied from interface:ChartModelRegisters a listener for data changes.- Specified by:
addChangeListenerin interfaceChartModel- Parameters:
listener- The listener
-
removeChangeListener
Description copied from interface:ChartModelRemoves a listener.- Specified by:
removeChangeListenerin interfaceChartModel- Parameters:
listener- The listener
-
getXData
public double[] getXData()Description copied from interface:ChartModelDirect access to the X-coordinate array.Framework contract: Implementations may return either:
- a defensive copy sized to
ChartModel.getPointCount()(safe, but potentially slower), or - a backing array with a capacity larger than
ChartModel.getPointCount()(fast, zero-allocation).
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:
getXDatain interfaceChartModel- Returns:
- X values array (may be larger than logical size)
- a defensive copy sized to
-
getYData
public double[] getYData()Description copied from interface:ChartModelDirect access to the Y-coordinate array.Warning: For performance reasons, the internal array is often returned. Do not modify!
- Specified by:
getYDatain interfaceChartModel- Returns:
- double array of Y values
-