Recent

Author Topic: Questions about TFuncSeries  (Read 5031 times)

hedgehog

  • Jr. Member
  • **
  • Posts: 98
Re: Questions about TFuncSeries
« Reply #15 on: March 10, 2026, 02:03:29 pm »
Quote
But applied to the topic of this post, massive oversampling is the only way to detect such a sharp maximum (or minimum), isn't it

Yes, that's correct.
Note that the calculations are performed on the original data, which is very fast.
I ran tests and found that the simplification function runs in 0.3 ms for a screen width of 900 pixels and in 0.6 ms for a screen width of 1800 pixels.
Furthermore, this function creates a polyline from just a few dozen points! This significantly reduces rendering time.

hedgehog

  • Jr. Member
  • **
  • Posts: 98
Re: Questions about TFuncSeries
« Reply #16 on: March 11, 2026, 09:50:46 am »
Quote
Looking along the direction of A the left vector is B, and conversely, the same result is obtained when looking along B where A is on the right side, i.d. the "left" vector must be B.

You've noticed that correctly.

But the algorithm is symmetrical about the x-axis.

Nevertheless, to avoid confusion, I've made the appropriate changes.
Also:
Vectors have been renamed (UpVector, DownVector)
Since we're dealing with a function (where x is monotonically increasing), the vector type simply degenerates into a real number. (type TVector = double)

Moreover, with minimal modifications, this also applies to time series.
« Last Edit: March 11, 2026, 09:53:25 am by hedgehog »

wp

  • Hero Member
  • *****
  • Posts: 13485
Re: Questions about TFuncSeries
« Reply #17 on: March 13, 2026, 12:36:23 am »
Now I spent some time with this algorithm and was able to integrate it into TAChart's TFuncSeries. I am attaching a small demo testing a variety of topics (rotation of axes, axis transforms, domain exclusions), and it seems to me that everything is working correctly, but I would appreciate if you could test it before I commit it to the Lazarus repository.

Make a backup copy of your tafuncseries.pas and tacustomfuncseries.pas files (in folder components/tachart of your Lazarus installation) and replace these two files by those that you find in the attached zip. Rebuild the IDE.

The TFuncSeries has a few new properties now:
- StepMode = (smConstant, smAdaptive) -- constant is the previous (and still default) behaviour with constant steps, adaptive is the new behaviour. Having StepSize=smAdaptive replaces the curve drawing method ForEachPoint by a new method ForEachAdaptivePoint
- PixelOversampling -- determines how often a pixel is sampled at different locations. This is the constant 100 or 15 that you mentioned in reply #10.
- Epsilon -- determines the maximum pixel deviation in y direction at which a line segment is drawn.

The old property Step is reused as maximum step size after which a line segment is drawn for sure. Switching StepMode stores the current Step settings and restores those for the other mode.

There seems to be an issue in the combination of "xy rotated" and "y logarithmic", but the standard TFuncSeries has the same, therefore, I am ignoring this for the moment.
« Last Edit: March 13, 2026, 12:40:14 am by wp »

hedgehog

  • Jr. Member
  • **
  • Posts: 98
Re: Questions about TFuncSeries
« Reply #18 on: March 14, 2026, 08:37:54 am »
Hi.

In my case (Lazarus 4.4 and Windows 10 64-bit), rebuilding the IDE causes a compilation error in the TACustomFuncSeries unit.

tacustomfuncseries.pas(202,11) Error: identifier idents no member "SetEnhancedBrokenLines"
tacustomfuncseries.pas(203,28) Error: identifier idents no member "GetPenStyle"
tacustomfuncseries.pas(211,11) Error: identifier idents no member "SetEnhancedBrokenLines"
tacustomfuncseries.pas(212,11) Error: identifier idents no member "SetPenStyle"

wp

  • Hero Member
  • *****
  • Posts: 13485
Re: Questions about TFuncSeries
« Reply #19 on: March 14, 2026, 10:43:38 am »
Comment these lines out. They belong to features planned for Laz 5.0. The modified funcseries should work without them.

hedgehog

  • Jr. Member
  • **
  • Posts: 98
Re: Questions about TFuncSeries
« Reply #20 on: March 14, 2026, 02:14:17 pm »
Unfortunately, the result was negative.
I had to comment out about 300..400 lines in unit TAFuncSeries.

Result: nothing. :(

« Last Edit: March 14, 2026, 02:17:09 pm by hedgehog »

wp

  • Hero Member
  • *****
  • Posts: 13485
Re: Questions about TFuncSeries
« Reply #21 on: March 14, 2026, 03:05:31 pm »
I see that the EnhancedChartPen is used at many many places. It would have been better for me to tell you that you should redefine a dummy pen type TEnhancedChartPen instead...

Please test the attached files in which I made all modification needed for Laz 4.4 (TATypes is included now, too, because this is where TEnhancedChartPen is declared). Tested on my system (Windows 11), and the demo is working fine.

hedgehog

  • Jr. Member
  • **
  • Posts: 98
Re: Questions about TFuncSeries
« Reply #22 on: March 15, 2026, 06:58:29 am »
Hi, wp
Yes, everything is fine now.

So, at first glance, the function series with adaptive stepping works perfectly.

P.S.
I ran some tests and measured the rendering time. The results are extremely interesting. In some cases, the function graph rendering speed is 2-4 times faster when using simplification.
Code: Pascal  [Select][+][-]
  1. Draw with simplify  (epsilon=1; step = 20; PixelOversampling = 16)
  2. Width=900; Pen=1;  t = 0.65 ms; 58 pts
  3. Width=900; Pen=3;  t = 0.85 ms; 58 pts
  4. Width=1900; Pen=1; t = 1.7 ms;  97 pts
  5. Width=1900; Pen=3; t = 2.0 ms;  97 pts
  6.  
  7. Dummy draw (step = 1)
  8. Width=900; Pen=1;  t = 0.83 ms; 901 pts
  9. Width=900; Pen=3;  t = 3.61 ms; 901 pts
  10. Width=1900; Pen=1; t = 2.1 ms; 1901 pts
  11. Width=1900; Pen=3; t = 7.8 ms; 1901 pts
  12.  
  13. Dummy draw (step = 2)
  14. Width=900; Pen=1;  t = 0.5 ms; 451 pts
  15. Width=900; Pen=3;  t = 1.9 ms; 451 pts
  16. Width=1900; Pen=1; t = 1.4 ms; 954 pts
  17. Width=1900; Pen=3; t = 4.3 ms; 954 pts

 

TinyPortal © 2005-2018