Skip to content

ScatterPlotList: re-evaluate API, improve documentation, and add generic support #1463

@tyrbentsen

Description

@tyrbentsen

Features Suggestion

Feature description:
Currently the AddSignal() method only accepts an ys argument of type double[]. The API would be much more flexible if the method would accept a generic collection like an IEnumerable<double>. Or if ScottPlot internally needs to know the number of items in the collection then use ICollection<double> or if it needs to index into the collection then use an IList<double>.

An example case that would really benefit from this: plotting growing data. Now you need to manage the resizing of growing array by yourself. It would be much more practical if an List<double> could be used.

Note: Using an IEnumerable, ICollection or IList in most cases does not have a performance penalty with respect to a plain array. If a specific memory layout is assumed in the ScottPlot implementation, Span<T> may provide the necessary constraints.

Code example:

Growing data with array:

// Original array.
var dataArray = new double[] { 1, 4, 9, 16, 25 };
var signalPlot = avaPlot1.Plot.AddSignal(dataArray);
avaPlot1.Plot.Render();

// Resize
Array.Resize(ref dataArray, dataArray.Length * 2);
avaPlot1.Plot.Remove(signalPlot);
var signalPlot2 = avaPlot1.Plot.AddSignal(dataArray);

// Add new element and Render
dataArray[5] = 36;
avaPlot1.Plot.Render();

Growing data with List:

// Original List.
var dataList = new List<double> { 1, 4, 9, 16, 25 };
var signalPlot = avaPlot1.Plot.AddSignal(dataList);
avaPlot1.Plot.Render();

// Add new element (List is resized automatically) and Render.
dataList.Add(36);
avaPlot1.Plot.Render();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions