Recent

Author Topic: LineSeries.GetMax, GetMin. Error in use of NaN  (Read 576 times)

arneolav

  • Full Member
  • ***
  • Posts: 126
    • ElTranslador
LineSeries.GetMax, GetMin. Error in use of NaN
« on: May 16, 2020, 11:25:28 pm »
Hi!
I'v got an error on LineSeries.GetMax/GetMin

Max/MinValue : Double

LineSeries.AddXY(DateTime, NaN, ReferenceText, clBlack)
Error on:   
LineSeries.GetMax(MaxDateTime, MaxValue); (Same error on GetMin)

This is ok:
AreaSeries.AddXY(DateTime, NaN, ReferenceText,  clBlack)
AreaSeries.GetMax(MaxDateTime, MaxValue);         
AreaSeries.GetMin(MinDateTime, MinValue);         

Error dump attached:
Win XP, Win7, Win 10 win64 , Lazarus 2.0.8
Delphi/DevExpress

wp

  • Hero Member
  • *****
  • Posts: 7081
Re: LineSeries.GetMax, GetMin. Error in use of NaN
« Reply #1 on: May 17, 2020, 11:02:08 am »
I can reproduce the issue with the line series, but I cannot reproduce that there is no error for the area series, in other words: I see the crash also with TAreaSeries, and this is to be expected since the bug is a missing check for NaN in TListChartsource which is used by both series types. Please specify what exactly you are doing. Ideally, upload a simple demo program showing that TLineSeries does not work but TAreaSeries does.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

arneolav

  • Full Member
  • ***
  • Posts: 126
    • ElTranslador
Re: LineSeries.GetMax, GetMin. Error in use of NaN
« Reply #2 on: May 17, 2020, 02:22:30 pm »
After some more testing I'v found the same error in AreaSeries.
When only a few (up to 7) numbers are greater than limit value, then both Area and Line does work.
With some more numbers, non of them does work.



« Last Edit: May 17, 2020, 03:27:05 pm by arneolav »
Win XP, Win7, Win 10 win64 , Lazarus 2.0.8
Delphi/DevExpress

wp

  • Hero Member
  • *****
  • Posts: 7081
Re: LineSeries.GetMax, GetMin. Error in use of NaN
« Reply #3 on: May 18, 2020, 11:46:14 am »
Added the missing NaN check to trunk (and requested backporting to Laz fixes). Please check. If you do not use trunk you can fix it yourself easily:
  • Open file tacustomsources.pas from folder (lazarus)/components/tachart.
  • Find the implementation of TCustomChartSource.XOfMax().
  • Replace the line "if Y = Extent.b.Y then begin" by "if not IsNaN(Y) and (Y = Extent.b.Y) then begin".
  • Do the same with TCustomChartSource.XOfMin().
I noticed that there is another bug: the area series crashes when y of the first or last data point is NaN. Trying to fix it...
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

arneolav

  • Full Member
  • ***
  • Posts: 126
    • ElTranslador
Re: LineSeries.GetMax, GetMin. Error in use of NaN
« Reply #4 on: May 18, 2020, 01:37:39 pm »
Thanks!
Did some testing, all ok in normal test. Example on celcius numbers > 10 are removed ok.
But on Area, test Lux > 0, to provocate first/last error;
No "dump error", but first numbers are set to negative.  (Lux values are never negative in input.)
I'll look more on this.
Win XP, Win7, Win 10 win64 , Lazarus 2.0.8
Delphi/DevExpress

wp

  • Hero Member
  • *****
  • Posts: 7081
Re: LineSeries.GetMax, GetMin. Error in use of NaN
« Reply #5 on: May 18, 2020, 01:40:24 pm »
... celcius numbers ... test Lux > 0 ... dump error ...
Sorry, I don't know what you are talking about.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

arneolav

  • Full Member
  • ***
  • Posts: 126
    • ElTranslador
Re: LineSeries.GetMax, GetMin. Error in use of NaN
« Reply #6 on: May 18, 2020, 06:23:56 pm »
celcius numbers: degree Celsius numbers ( °C )

Sensors may report light as Lux, Lumen or Candela
The lux (symbol: lx) is the SI derived unit of illuminance, measuring luminous flux per unit area. (Sunlight illuminance)
The lumen (symbol: lm) is the SI derived unit for brightness.
A candela is the SI base unit of luminous intensity. It measures how bright something is

dump error: I mean I got no error. (no dump, no error).
....

Negative numbers:
There are no negative numbers in the actual test input from sensor, (Lux, Sunlight).
By night the sensors are reporting 0, zero. (no light, input value = 0).
But the AreaSerie display 0 numbers as a range from zero to -1.
This is not new now and is not an problem.

....
The fix in  tacustomsources.pas did solve the problem, Thank you!

Win XP, Win7, Win 10 win64 , Lazarus 2.0.8
Delphi/DevExpress

wp

  • Hero Member
  • *****
  • Posts: 7081
Re: LineSeries.GetMax, GetMin. Error in use of NaN
« Reply #7 on: May 18, 2020, 06:56:10 pm »
I know about these units, but was not aware that you had plotted such values. It just came out of nothing.

Yes, Areaderies plots down to neg infinity. But you can activate the UseZeroLevel, then the area will start at 0 (or whatever you choose as zero level). With only zeros in the ChartSource the left axis still goes down to -1. You can force the y axis to begin at 0 by setting Chart.Extent.YMin = 0 and chart.Extent.UseYMin = true.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

arneolav

  • Full Member
  • ***
  • Posts: 126
    • ElTranslador
Re: LineSeries.GetMax, GetMin. Error in use of NaN
« Reply #8 on: May 18, 2020, 08:59:42 pm »
UseZeroLevel.... Of course, there is also a solution for this in TaChart.
I am constantly amazed at how many opportunities exist in TaChart, far beyond my imagination!
Again Thanks!
Win XP, Win7, Win 10 win64 , Lazarus 2.0.8
Delphi/DevExpress

 

TinyPortal © 2005-2018