Skip to content

ChartFileDataSourceBase

ClassChartGuruChartGuru
public abstract class ChartFileDataSourceBase : ChartDataSourceBase, IChartDataSource

Common base for every data source that parses a text payload (CSV, JSON, Google Sheets export, an HTTP body, …) into a ChartGuru.ChartTabularData, then maps it through a ChartGuru.ChartDataMapping to produce ChartGuru.IChartMarks.

Subclasses provide just two things:

  1. A way to obtain the raw text — synchronously (`ChartGuru.ChartFileDataSourceBase.LoadText`) or asynchronously (`ChartGuru.ChartFileDataSourceBase.LoadTextAsync(System.Threading.CancellationToken)`);
  2. A parser that converts that text into a [ChartGuru.ChartTabularData](/tools/chartguru/api/chartguru-charttabulardata/) (`ChartGuru.ChartFileDataSourceBase.ParseToTabular(System.String)`).

The base class handles mapping suggestion (when `ChartGuru.ChartFileDataSourceBase.AutoMapping` is on), snapshot caching, the diff fast-path (SetValues when shape is unchanged, otherwise SetData), async refresh with `ChartGuru.ChartFileDataSourceBase.Refresh` / `ChartGuru.ChartFileDataSourceBase.RefreshAsync(System.Threading.CancellationToken)`, and forwarding to the UI Toolkit pipeline via BuildMarksForChartType.

[Header("Mapping")]
[Tooltip("Mapping that ties parsed columns to chart axes/series. When 'Auto Mapping' is on and Y columns are empty, the mapping is suggested heuristically on the first parse.")]
[SerializeField]
protected ChartDataMapping _mapping

No description is available for this member.

Returns

ChartGuru.ChartDataMapping — No return description is available.

[Tooltip("If on, the mapping is automatically inferred whenever the dataset shape changes and YColumns is empty. Turn off to fully control the mapping yourself.")]
[SerializeField]
protected bool _autoMapping

No description is available for this member.

Returns

System.Boolean — No return description is available.

[Header("Refresh")]
[Tooltip("Apply the data automatically when this component is enabled at runtime.")]
[SerializeField]
protected bool _applyOnEnable

No description is available for this member.

Returns

System.Boolean — No return description is available.

protected ChartTabularData _snapshot

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

Returns

ChartGuru.ChartTabularData — No return description is available.

protected ChartDataMapping _appliedMapping

Mapping snapshot that was last applied — used by the diff fast-path.

Returns

ChartGuru.ChartDataMapping — No return description is available.

public ChartDataMapping Mapping { get; set; }

Inspector-editable mapping. Subclasses and inspectors mutate via this property.

Returns

ChartGuru.ChartDataMapping — No return description is available.

public bool AutoMapping { get; set; }

When true, missing Y columns will be auto-suggested on parse.

Returns

System.Boolean — No return description is available.

public ChartTabularData CurrentData { get; }

The last parsed snapshot. May be null.

Returns

ChartGuru.ChartTabularData — No return description is available.

protected abstract string LoadText()

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

Returns

System.String — No return description is available.

protected virtual Task<string> LoadTextAsync(CancellationToken ct)

Async variant. The default implementation invokes ChartGuru.ChartFileDataSourceBase.LoadText on a thread-pool worker. Subclasses with a true async pipeline (UnityWebRequest, file-stream ReadAsync) should override.

Parameters

Name Type Description
ct System.Threading.CancellationToken

Returns

System.Threading.Tasks.Task{System.String} — No return description is available.

protected abstract ChartTabularData ParseToTabular(string rawText)

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

Parameters

Name Type Description
rawText System.String

Returns

ChartGuru.ChartTabularData — No return description is available.

public virtual void Refresh()

Drive a synchronous load → parse → push cycle. Equivalent to ChartGuru.ChartFileDataSourceBase.ApplyData; provided as a more discoverable alias.

public virtual Task RefreshAsync(CancellationToken ct = default)

Async refresh. Loads + parses on a background thread, then marshals the apply step back to the captured Unity main-thread context. Cancellation is honored across each await boundary.

Parameters

Name Type Description
ct System.Threading.CancellationToken

Returns

System.Threading.Tasks.Task — No return description is available.

public override void ApplyData()

Synchronous ChartGuru.ChartFileDataSourceBase.ApplyData override. Loads the text, parses it, and pushes the result to all resolved target charts. Errors are caught and logged so a single misconfigured source does not break a whole scene.

BuildMarksForChartType(ChartType, ChartAuthoringStyleOptions)

Section titled “BuildMarksForChartType(ChartType, ChartAuthoringStyleOptions)”
public override List<IChartMark> BuildMarksForChartType(ChartType chartType, ChartAuthoringStyleOptions style)

UI Toolkit / runtime-pull entry point. Returns marks shaped for chartType from the cached snapshot. If the snapshot is empty, a fresh load+parse is attempted (best-effort).

Parameters

Name Type Description
chartType ChartGuru.ChartType
style ChartGuru.ChartAuthoringStyleOptions

Returns

System.Collections.Generic.List{ChartGuru.IChartMark} — No return description is available.

protected override void OnEnable()

No description is available for this member.

protected void ApplyParsed(ChartTabularData parsed)

Push a freshly parsed dataset to every resolved chart. Updates existing marks in place when the shape is identical to the previous push, otherwise replaces the mark set with SetData.

Parameters

Name Type Description
parsed ChartGuru.ChartTabularData
protected void PromoteSnapshot(ChartTabularData parsed)

Cache parsed and (if ChartGuru.ChartFileDataSourceBase.AutoMapping is on and Y columns are empty) populate the mapping from the suggester.

Parameters

Name Type Description
parsed ChartGuru.ChartTabularData