Skip to content

ChartFileDataSource

ClassChartGuruChartGuru
public abstract class ChartFileDataSource : ChartDataSource

Common base for data sources that parse a text payload (CSV, JSON, a Google Sheets export, an HTTP body) into a ChartTabularData and publish it as a typed ChartDataFrame. Subclasses provide the raw text (ChartFileDataSource.LoadText() or ChartFileDataSource.LoadTextAsync(CancellationToken)) and a parser (ChartFileDataSource.ParseToTabular(string)). The base owns the refresh model: synchronous ChartFileDataSource.Refresh(), single-flight latest-request-wins ChartFileDataSource.RefreshAsync(CancellationToken) with parsing on a worker thread, and publishing on the Unity thread. Hosts map the published columns with their definition's layers.

protected string _dateFormat

Returns

System.String

protected string _dateCulture

Returns

System.String

protected string _numberCulture

Returns

System.String

protected int _maxRows

Returns

System.Int32

protected bool _applyOnEnable

Returns

System.Boolean

protected ChartTabularData _snapshot

The most recently parsed dataset. null until the first refresh.

Returns

ChartGuru.ChartTabularData

protected abstract string LoadText()

Subclasses override to obtain the raw text payload synchronously. Return an empty string to signal "no data".

Returns

System.String

protected virtual Task<string> LoadTextAsync(CancellationToken ct)

Async variant. The default implementation snapshots the source text on the Unity thread because a source may read a TextAsset. Subclasses with a true async pipeline should override.

Parameters

Name Type
ct System.Threading.CancellationToken

Returns

System.Threading.Tasks.Task{System.String}

protected abstract ChartTabularData ParseToTabular(string rawText)

Convert raw text to a ChartTabularData. Implemented per source (CSV vs JSON).

Parameters

Name Type
rawText System.String

Returns

ChartGuru.ChartTabularData

protected virtual Task<ChartFileDataSource.ChartTextPayload> LoadPayloadAsync(CancellationToken ct)

Loads one immutable response payload. Network sources can attach response metadata here.

Parameters

Name Type
ct System.Threading.CancellationToken

Returns

System.Threading.Tasks.Task{ChartGuru.ChartFileDataSource.ChartTextPayload}

protected virtual ChartTabularData ParsePayloadToTabular(ChartFileDataSource.ChartTextPayload payload)

Parses one response payload without relying on mutable shared response state.

Parameters

Name Type
payload ChartGuru.ChartFileDataSource.ChartTextPayload

Returns

ChartGuru.ChartTabularData

public virtual Task RefreshAsync(CancellationToken ct = default)

Async single-flight refresh. Starting a newer refresh cancels the previous request, and only the latest generation may update the snapshot or charts. Parsing runs on a worker while all Unity object mutation is marshalled to the Unity thread captured by this component's lifecycle.

Parameters

Name Type
ct System.Threading.CancellationToken

Returns

System.Threading.Tasks.Task

public override void Refresh()

Loads, parses and publishes synchronously, canceling any refresh still in flight.

protected void ApplyParsed(ChartTabularData parsed)

Converts the parsed table into a typed frame and publishes it to bound hosts.

Parameters

Name Type
parsed ChartGuru.ChartTabularData
protected CultureInfo ResolveNumberCulture()

The culture CSV cells write numbers in, or null to read them automatically; pass it to CsvParseOptions.NumberCulture.

Returns

System.Globalization.CultureInfo

protected void QueueRefresh(CancellationToken ct = default)

Starts an observed fire-and-forget refresh for lifecycle and polling callers.

Parameters

Name Type
ct System.Threading.CancellationToken
protected virtual void OnRefreshSucceeded()

Called on the Unity thread after a successful refresh.

protected virtual void PrepareParsedForApply(ChartTabularData parsed)

Applies source-specific mapping changes on the Unity thread before data is promoted.

Parameters

Name Type
parsed ChartGuru.ChartTabularData
protected virtual void OnRefreshFailed(Exception exception)

Called on the Unity thread after a failed refresh.

Parameters

Name Type
exception System.Exception

protected ChartFileDataSource()

public string DateFormat { get; set; }

DateTime.ParseExact format for date columns; empty detects common formats.

Returns

System.String

public string DateCulture { get; set; }

Culture name used to parse dates; empty is invariant.

Returns

System.String

public string NumberCulture { get; set; }

Culture name whose number format CSV cells use, such as de-DE; empty reads invariant numbers with automatic decimal-comma detection. JSON numbers are always invariant.

Returns

System.String

public int MaxRows { get; set; }

Maximum number of rows read; 0 reads every row.

Returns

System.Int32

public ChartTabularData CurrentData { get; }

The latest parsed table, for previews and column pickers.

Returns

ChartGuru.ChartTabularData

public ChartDataRefreshState RefreshState { get; }

Current refresh lifecycle state.

Returns

ChartGuru.ChartDataRefreshState

public bool IsRefreshing { get; }

True while a refresh is loading, parsing, or applying data.

Returns

System.Boolean

public string LastRefreshError { get; }

Sanitized message from the most recent failed refresh.

Returns

System.String

public DateTime? LastRefreshUtc { get; }

UTC completion time of the most recent successful refresh.

Returns

System.Nullable{System.DateTime}

protected virtual bool AutoApplyInEditMode { get; }

Whether this source should populate an edit-mode preview when enabled.

Returns

System.Boolean

public event Action<ChartDataRefreshState> RefreshStateChanged

Raised on the Unity thread whenever ChartFileDataSource.RefreshState changes.

Returns

System.Action{ChartGuru.ChartDataRefreshState}