Pre loader

Is it possible to do point simple transformations?

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

Answered
1
0

Suppose I have an XYSeries dataset. For this example, Y is a temperature value in Celsius.

The XYSeries without modification I will call raw space. I assume that there is some matrix stack that transforms my “raw space” data series to screen space (the actual pixel on the screen).

Basic Point Transform assumption from my limited Graphics experience:
(Raw Space -> View Space (axis transforms etc) -> Culled Space (culled and interpolated points) -> Screen Space (positioned properly on the screen))

Now all is well if I am just running this graph in Celsius, but perhaps my user wants to change the Y axis to Fahrenheit. For maximum speed I want to generate a transform to edit the dataset, creating an extra space which I will call “Transformed Space”

(Raw Space -> Transformed Space -> View Space -> Culled Space -> Screen Space)

The matrix transform to Fahrenheit (Transformed Space) would be:

| 1   0    0 | | x |  
| 0  1.8  32 | | y |
| 0   0    1 | | 1 |

Is it possible to build transforms like this in Scichart or a partial matrices approach like in WPF? Or do I need to loop through and change my raw series every time the units change?

Thank You,
Nicholas Louks

Version
v7.0
  • You must to post comments
Best Answer
0
0

Hi Nicholas,

You’ve just described the Filters API. Here is a link to the documentation. Filters perform transforms at the data stage so if you create a DataSeries, then create a filter on that series, any time the underlying data changes, the filter recalculates.

This can be used to create Smoothing, Moving Averages, Scale or Offset a series, or custom transformations on data.

SciChart comes with many filters out of the box. However, take a look at the CustomFilter page. This shows you how to create your own transformation.

To create a custom filter, inherit FilterBase, and override at least FilterAll. If you do frequent data-updates and want better performance you can also override FilterOnAppend, FilterOnInsert, FilterOnRemove and FilterOnUpdate.

// Example custom filter from the Filters API Docs
public class CustomFilter : FilterBase
{
    private readonly XyDataSeries<TimeSpan, double> _originalDataSeries;
    private readonly XyDataSeries<TimeSpan, double> _filteredDataSeries = new XyDataSeries<TimeSpan, double>();
    public CustomFilter(XyDataSeries<TimeSpan,double> originalDataSeries) : base(originalDataSeries)
    {
        _originalDataSeries = originalDataSeries;
        // Store a reference in the base class to the FilteredDataSeries
        FilteredDataSeries = _filteredDataSeries;
        // Update the filter
        FilterAll();
    }
    protected override void FilterOnAppend(int index)
    {
        // Override FilterOnAppend to update just the latest data-point in _filteredDataSeries for a more efficient filter
        base.FilterOnAppend(index);
    }
    protected override void FilterOnInsert(int startIndex, int count)
    {
        // Override FilterOnInsert to update just the inserted data-point in _filteredDataSeries for a more efficient filter
        base.FilterOnInsert(startIndex, count);
    }
    protected override void FilterOnRemove(int startIndex, int count)
    {
        // Override FilterOnRemove to update just the removed data-point in _filteredDataSeries for a more efficient filter
        base.FilterOnRemove(startIndex, count);
    }
    protected override void FilterOnUpdate(int index)
    {
        // Override FilterOnUpdate to update just the updated data-point in _filteredDataSeries for a more efficient filter
        base.FilterOnUpdate(index);
    }
    public override void FilterAll()
    {
        // When FilterAll is called, recreate the FilteredDataSeries and apply the filtering.
        _filteredDataSeries.Clear();
        _filteredDataSeries.Append(_originalDataSeries.XValues[0], _originalDataSeries.YValues[0]);
        const double beta = 0.2;
        // Implementing a simple low pass filter https://kiritchatterjee.wordpress.com/2014/11/10/a-simple-digital-low-pass-filter-in-c/
        for (int i = 1; i < _originalDataSeries.Count; i++)
        {
            TimeSpan xValue = _originalDataSeries.XValues[i];
            double yValue = beta * _originalDataSeries.YValues[i] + (1 - beta) * _filteredDataSeries.YValues[i - 1];
            _filteredDataSeries.Append(xValue, yValue);
        }
    }
}

Now you can apply it to a dataseries like this:

using SciChart.Charting.Model.Filters; // Required for class FilterBase

var dataSeries = new XyDataSeries<double,double>(); // Original Data
dataSeries.Append(0,1);
dataSeries.Append(2,2);

var customFilter = new CustomFilter(dataSeries); // Create the custom filter.
var customFilteredDataSeries = customFilter.FilteredDataSeries;

var lineRenderableSeries = new FastLineRenderableSeries()
{
    DataSeries = customFilteredDataSeries , // Apply the Custom Filtered Data to a Line Series
}

If you want to perform transforms on pixels on the screen, that would require a different API, but sounds like for Celsius to Fahrenheit this should work!

Best regards,
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies