Skip to content

ChartDataSource

ClassChartGuruChartGuru
public abstract class ChartDataSource : MonoBehaviour

Base class for components that supply chart data. A source publishes ChartDataFrames that hosts treat as immutable; chart hosts bind a source and rebuild from its latest frame. A source that streams values into a frame of fixed shape, such as a waterfall grid, overwrites the values of its latest frame in place with ChartDataSource.OverwriteValues<T>(ChartDataColumn<T>, ReadOnlySpan<T>) and announces them with ChartDataSource.PublishValueChange(), so hosts update their marks in place. Sources never search for charts, so one source can feed any number of 2D, 3D and UI Toolkit hosts.

public abstract void Refresh()

Loads, parses or regenerates the data and publishes a new frame.

public ChartDataFrame GetOrLoadFrame()

Returns the latest frame, loading it synchronously first if nothing was published yet.

Returns

ChartGuru.ChartDataFrame

protected void Publish(ChartDataFrame frame, bool shapeChanged = true)

Publishes a frame to every bound host.

Parameters

Name Type
frame ChartGuru.ChartDataFrame
shapeChanged System.Boolean
protected void PublishValueChange()

Announces the values written into the published frame with ChartDataSource.OverwriteValues<T>(ChartDataColumn<T>, ReadOnlySpan<T>), once for all columns written: ChartDataSource.Revision advances and ChartDataSource.FrameChanged reports no shape change, so hosts update the values of their marks in place. Does nothing before a frame is published.

OverwriteValues(ChartDataColumn, ReadOnlySpan)

Section titled “OverwriteValues(ChartDataColumn, ReadOnlySpan)”
protected void OverwriteValues<T>(ChartDataColumn<T> column, ReadOnlySpan<T> values)

Overwrites the values of column, a column of the published ChartDataSource.Frame, in place and without allocating, for sources that stream values into a frame of fixed shape such as a spectrogram grid. Write every column that changed, then call ChartDataSource.PublishValueChange() once. values replaces the column row for row, so it holds one value per row; the column keeps its validity, and NaN in a numeric column reads as a missing value. Hosts keep their marks and update them in place, and rebuild when the new values add, remove or regroup marks, for example a changed category. Call it on the Unity thread, and publish a new frame instead when the columns or the row count change.

Parameters

Name Type
column ChartGuru.ChartDataColumn{{T}}
values System.ReadOnlySpan{{T}}
protected void ClearFrame()

Forgets the published frame, for example when the source is reconfigured.

protected ChartDataSource()

public ChartDataFrame Frame { get; }

The latest published frame, or null until the first load.

Returns

ChartGuru.ChartDataFrame

public int Revision { get; }

Increments with every published frame and every value change announced by ChartDataSource.PublishValueChange(); a frame read at one revision may hold other values at the next.

Returns

System.Int32

public event Action<ChartDataSource, bool> FrameChanged

Raised on the Unity thread after a new frame or a value change is published. The flag is false when only values changed, which lets hosts update marks in place without allocating.

Returns

System.Action{ChartGuru.ChartDataSource,System.Boolean}