Recent

Author Topic: Bug or not a bug - this is the question  (Read 1621 times)

Nicole

  • Hero Member
  • *****
  • Posts: 1009
Bug or not a bug - this is the question
« on: September 23, 2024, 04:09:58 pm »
Here is something I have very little idea about, TA-Chart, scaling.
When I try calling my drawing method for the first time, I get an ugly error message, see below.
The second call works fine. So the problem with the first call shall be "empty values".
Sure, my problem, but TAChart shall work for dummies as well.

This is the error message:

Code: Text  [Select][+][-]
  1. [Window Title]
  2. Fehler
  3.  
  4. [Content]
  5. Projekt project1 hat Exception-Klasse »External: FLT OVERFLOW« ausgelöst.
  6.  
  7.  In Datei 'tatransformations.pas' in Zeile 751
  8.  
  9. [Ok]

It jumps to

unit TATransformations;

Code: Text  [Select][+][-]
  1. procedure TAutoScaleAxisTransform.UpdateBounds(var AMin, AMax: Double);
  2. begin
  3.   // Auto-scale is only defined for finite bounds.
  4.   if IsInfinite(AMin) or IsInfinite(AMax) then exit;
  5.   with TAutoScaleTransformData(FDrawData) do begin
  6.     UpdateMinMax(AMin, FMin, FMax);
  7.     UpdateMinMax(AMax, FMin, FMax);
  8.     if FMax = FMin then
  9.       FScale := 1.0
  10.     else
  11.       FScale := (MaxValue - MinValue) / (FMax - FMin);
  12.     FOffset := MinValue - FMin * FScale;
  13.   end;
  14.   AMin := MinValue;
  15.   AMax := MaxValue;
  16. end;


My idea:
Should there be some more lines making sure, there will not be "problem"-values?
One line, making sure, we do not divide by zero?

If somebody thinks "yes", I would be grateful, if he could post the lines here.
So I can parse them directly without re-installing new versions of anything.

And one suggestion more:
Write the date and version of the unit into the top-lines-comments. As it is not there, I am not sure, which version I use.

Zvoni

  • Hero Member
  • *****
  • Posts: 2793
Re: Bug or not a bug - this is the question
« Reply #1 on: September 23, 2024, 04:25:52 pm »
Going out on a Limb: Do you call your Drawing-Method in OnCreate of your Form?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

wp

  • Hero Member
  • *****
  • Posts: 12523
Re: Bug or not a bug - this is the question
« Reply #2 on: September 23, 2024, 04:39:56 pm »
Here is something I have very little idea about, TA-Chart, scaling.
When I try calling my drawing method for the first time, I get an ugly error message, see below.
The second call works fine. So the problem with the first call shall be "empty values".
Sure, my problem, but TAChart shall work for dummies as well.
I have no idea about what you are doing and how to help you. Please post a little project which demonstrates the issue.

Code: Text  [Select][+][-]
  1. procedure TAutoScaleAxisTransform.UpdateBounds(var AMin, AMax: Double);
  2. begin
  3.   // Auto-scale is only defined for finite bounds.
  4.   if IsInfinite(AMin) or IsInfinite(AMax) then exit;
  5.   with TAutoScaleTransformData(FDrawData) do begin
  6.     UpdateMinMax(AMin, FMin, FMax);
  7.     UpdateMinMax(AMax, FMin, FMax);
  8.     if FMax = FMin then
  9.       FScale := 1.0
  10.     else
  11.       FScale := (MaxValue - MinValue) / (FMax - FMin);
  12.     FOffset := MinValue - FMin * FScale;
  13.   end;
  14.   AMin := MinValue;
  15.   AMax := MaxValue;
  16. end;

My idea:
Should there be some more lines making sure, there will not be "problem"-values?
One line, making sure, we do not divide by zero?
Division by zero is avoided in the line "if FMax = FMin" (line #9).

And one suggestion more:
Write the date and version of the unit into the top-lines-comments. As it is not there, I am not sure, which version I use.
I don't think that it is practical because this information would have to be updated again and again even for unchanged files. There is the trunk version, the fixes version, the release, ther first bug-fix of the release etc. Since TAChart is tied to Lazarus its version number is the same as the Lazarus version number which you see in the About screen at startup, or in "Help" > "About Lazarus".

Nicole

  • Hero Member
  • *****
  • Posts: 1009
Re: Bug or not a bug - this is the question
« Reply #3 on: September 23, 2024, 06:53:19 pm »
Thank you for your replies.

Zvoni:
Going out on a Limb: Do you call your Drawing-Method in OnCreate of your Form?

Äh, huch? How do I have to do this?
There is a button, which Click-Event grabs the data and adds them by a loop alike
Code: Pascal  [Select][+][-]
  1. SeriesKontrakt_1.AddXOHLC(kurse1[i].Datum, kurse1[i].open, kurse1[i].high, kurse1[i].low, kurse1[i].close);
to the series.

And this is the reason, why it would be a work of several days to generate such a demo. It is deeply nested into my database-requests and var-declarations. Sure, the problem can be there as well. So if you think, all values will work, then I search on for this or live with clicking away the ugly error-message.

Or I hope, that Zvoni give me a crucial hint for my programming live about this onCreate-thing?

wp

  • Hero Member
  • *****
  • Posts: 12523
Re: Bug or not a bug - this is the question
« Reply #4 on: September 23, 2024, 07:30:12 pm »
I don't care about the database, it has nothing to do with TAChart, just add random data to the series. My point is: I know almost nothing about your chart, there is an OHLCseries and a AutoscaleAxisTransform, that's all. Can you tell me how I am supposed to find a bug in this constellation? I understand that you do not spend days in preparing a demo. But please understand yourself that I cannot find a bug without anything, the error message can have lots of reasons...

A wild guess: One common mistake in working with AxisTransformations is that the AxisIndex of the linked axis is not assigned to the series (AxisIndexX and/or AxisIndexY series properties).

Nicole

  • Hero Member
  • *****
  • Posts: 1009
Re: Bug or not a bug - this is the question
« Reply #5 on: September 23, 2024, 08:27:06 pm »
I am sorry for the poor code I can provide.

About this wild guess: I understand every vocabulary and never the less, I do not know, how to do this. How to assign it?

I make my charts by drag and drop: I double click every where and try to find the appropriate things in the object-inspector. This is indeed overwhelming, because there are so many values and I just need it twice a year. For some tasks I made how-to-lists (e.g. you explained me once how to made a nicely formatted data-axis, this works since then), for others I do not, because I hardly can reproduce what I did.

To sum up:
How to assign what you wrote?

wp

  • Hero Member
  • *****
  • Posts: 12523
Re: Bug or not a bug - this is the question
« Reply #6 on: September 23, 2024, 08:56:46 pm »
How to assign what you wrote?
You mean what I wrote about the axis index? Select the series in the object tree (above the object inspector) --> the object inspector is loaded with the properties of the series. You'll see properties AxisIndexX and AxisIndexY. Which axis do you want to transform with the AutoscaleTransform? I presume it is the y axis. Then your chart must contain at least a second y axis, usually at the right. In the object tree you can see all axes below the AxisList node of the chart; each axis has a number (e.g. '0 - Left, 1 - Bottom, 2 - Right'). When your series will be plotted on the left axis, set its AxisIndexY to 0 because this is the index of the "left" axis, well, at least in my example. Or when you want to plot the series on the right axis, you must set its AxisIndexY to 2 because this is the index of my "right" axis. Repeat this with every series; every series must have its own axis and TChartAxisTransformations. Look at the tutorial https://wiki.lazarus.freepascal.org/TAChart_Tutorial:_Dual_y_axis,_Legend which describes the steps to create a dual-y-axis chart.

Nicole

  • Hero Member
  • *****
  • Posts: 1009
Re: Bug or not a bug - this is the question
« Reply #7 on: September 24, 2024, 11:57:03 am »
Thank you for your explanation. This should have been set correctly. "should", Because I can remember, that I added - long ago- , deleted and rearranged some axis. There has been an error in the past with it, which "should" not occur. If this is the case, then I am in trouble. In the past I had to start all over again with my chart setup, which is a lot of work.

Or there is something wrong in the unit never the less?
Can you pls have a look at the value list? If it does not make sense, pls be patient with me. I am no programmer and do not understand this unit.

wp

  • Hero Member
  • *****
  • Posts: 12523
Re: Bug or not a bug - this is the question
« Reply #8 on: September 24, 2024, 12:36:44 pm »
Thank you for your explanation. This should have been set correctly. "should", Because I can remember, that I added - long ago- , deleted and rearranged some axis.
"Should"? Why don't you check it? If the series is created at designtime it appears in the object tree. Click on it to load it into the object inspector so that you can see the properties, among them AxisIndexX and AxisIndexY. And if you create the series by code at runtime search the unit for "AxisIndex" and make sure that it is set appropriately.

Or there is something wrong in the unit never the less?
Bugs never can be ruled out. But the AutoScaleAxisTransform has been used many many times, and I have never seen such an issue. Therefore I think that the issue is somewhere in your code or in faulty setup of the chart/series/axis/transform parameters. Since there are so many possibilities I need a sample project...

Can you pls have a look at the value list?
Which "value list"?

Nicole

  • Hero Member
  • *****
  • Posts: 1009
Re: Bug or not a bug - this is the question
« Reply #9 on: September 24, 2024, 03:25:58 pm »
Code: Text  [Select][+][-]
  1. "Should"? Why don't you check it? If the series is created at designtime it appears in the object tree. Click on it to load it into the object inspector so that you can see the properties, among them AxisIndexX and AxisIndexY. And if you create the series by code at runtime search the unit for "AxisIndex" and make sure that it is set appropriately.

I have seen this before more than one time over the years.: Everything looks ok, but something strange happens. A complete new beginning with just the same ideas - helped. Naturally there is no demo for this. If I would be aware wich click out of thousands is responsible for this, I would change this click instead of setting up the whole thing from scratch.

Code: Text  [Select][+][-]
  1.     Can you pls have a look at the value list?
  2.  
  3. Which "value list"?

pls see the attached screenshot of the last posting.

rvk

  • Hero Member
  • *****
  • Posts: 6641
Re: Bug or not a bug - this is the question
« Reply #10 on: September 24, 2024, 03:29:06 pm »
pls see the attached screenshot of the last posting.
You set a watch for FMax and FMin. But these are values from FDrawData.
You can see it is wrapped in a "with" clause.

So try to set the watch at TAutoScaleTransformData(FDrawData).FMin and TAutoScaleTransformData(FDrawData).FMax if possible.

Those are probably still on SafeInfinity and NegInfinity when called. So if you want this resolved you need to show more code on how you use this.
Create a small sample project showing the problem.
« Last Edit: September 24, 2024, 03:46:07 pm by rvk »

Nicole

  • Hero Member
  • *****
  • Posts: 1009
Re: Bug or not a bug - this is the question
« Reply #11 on: September 25, 2024, 08:01:26 pm »
In recent days I have problems with connecting to the server, so my answer took until today: I tried to put the verbose term into the watch window and it worked fine. The values were as they should. So I put the verbose terms into the code - with the same results as before. Fuzzy and unpredictable. To my mind there is anything undefined, a pointer to nil or whatever.

Generating a demo would solve this quite sure. Then I have a working demo and a still not working code.

Can you recommend a way to initialize the series? Or to put a condition before "addXY()" to make sure, the software drops an error message instead of an exception? Yes, for this you would need to know, what is the problem. The problem is, that I do not know it. If you say "my glass ball is broken", I can understand it.

wp

  • Hero Member
  • *****
  • Posts: 12523
Re: Bug or not a bug - this is the question
« Reply #12 on: September 25, 2024, 10:34:16 pm »
There is no need to initialize a series - create it and add values, as simple as that. But - maybe - you are drawing the chart too early, and the scaling factors have not yet been calculated (as noted similarly in Zvoni's post). Please try to call Chart.Prepare when all data have been added to the series.

Nicole

  • Hero Member
  • *****
  • Posts: 1009
Re: Bug or not a bug - this is the question
« Reply #13 on: October 02, 2024, 04:12:11 pm »
I found it.
There was one array, where there in the deep nesting was a case, that a value stayed undefined.
This value was later added within a loop by AddXY() to one of the series.

This was the reason, why initialization of the series or chart.prepare did not help.
The rotten tomato was thrown after this.

Why the second attempt of another data-choice did not "throw the tomato" (it was the same problem of a missing line), I cannot guess.

 

TinyPortal © 2005-2018