Forum > TAChart

Fastline series with simplification

(1/4) > >>

hedgehog:
Hi!
Once upon a time, for one of my projects, I made a Fastline series for TAChart.
I recently added a polyline simplification feature.
Hope this will be useful for someone.
Criticism and suggestions are welcome.

I added a test project

wp:
Although I did not fully understand your algorithm (what are this CalculateAngles and the Epsilon good for?) I guess that you try to reduce the number of datapoints. Could you explain the idea in a few sentences?

Wouldn't this better fit into the chart source than into the series? The advantage would be that the point elimination would have to be calculated only once (however, this would interfere with the need to probably repeat the calculation whenever the size or zoom level of the chart changes).

I modified your test project by plotting 2 millions of data points rather than just a few so that the speed can be measured. I used the same data points to plot also a standard TLineSeries for comparison. In the unfiltered mode there is a speed advantage of your fast line series by a factor 2-3 compared to TLineSeries, but TFastlineSeries becomes slower than TLineSeries when the filter is activated probably because the arctan2 needed for CalculateAngles is quite expensive.

TFastlineSeries calculates the image points by calling Chart.GraphToImage. But this ignores axis transformations. I thought that the following code (note the inserted AxisToGraph) would be better, but it causes a severe slow-down of the series:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var P: TDoublePoint;...    with Source[i]^ do    begin      P := DoublePoint(X, Y);;      P := AxisToGraph(P);  // Deactivate this to ignore axis transformations      points[i] := ParentChart.GraphToImage(P);    end;  
Another problem is that when you zoom into the series (by dragging a smaller rectangle around the read of interest) the time to draw the series decreases in proportion to the number of still visible data points for the TLineSeries while the time to draw a zoomed view of the TFastlineseries remains constant. This is because you do not call PrepareGraphPoints which finds only those datapoints within the visible viewport.

hedgehog:
I will answer in several messages

--- Quote from: wp on January 02, 2024, 12:33:53 pm ---Although I did not fully understand your algorithm (what are this CalculateAngles and the Epsilon good for?) I guess that you try to reduce the number of datapoints. Could you explain the idea in a few sentences?

--- End quote ---
The main idea of my polyline simplification algorithm is in this screenshot.
The algorithm guarantees that all discarded points are located at a distance less than Epsilon from the drawn line.

wp:
Thanks for clarification. This sounds interesting.

hedgehog:

--- Quote from: wp on January 02, 2024, 12:33:53 pm ---Wouldn't this better fit into the chart source than into the series? The advantage would be that the point elimination would have to be calculated only once (however, this would interfere with the need to probably repeat the calculation whenever the size or zoom level of the chart changes).

--- End quote ---
Firstly, I want to say that I am not at all an expert in TAChart :(


--- Quote from: wp link ---I modified your test project by plotting 2 millions of data points rather than just a few so that the speed can be measured. I used the same data points to plot also a standard TLineSeries for comparison. In the unfiltered mode there is a speed advantage of your fast line series by a factor 2-3 compared to TLineSeries, but TFastlineSeries becomes slower than TLineSeries when the filter is activated probably because the arctan2 needed for CalculateAngles is quite expensive.

--- End quote ---
Throwing out “extra” points is, of course, not an end in itself. There are many cases where "you can't see the forest for the trees".
For example, you need to draw a polyline of a million points on a 32*32 pixel bitmap, maintaining all trends.

Yes, Arctan is calculated twice for each point.
This is the price for the fact that the algorithm is one-pass.
The second time arctg is calculated for sufficiently small angles and is approximately equal to the value of the angle itself (in radians).
This can be optimized in the future.

Navigation

[0] Message Index

[#] Next page

Go to full version