Recent

Author Topic: [possible bug] adding a mark always changes axis range min/max  (Read 1850 times)

Muso

  • Sr. Member
  • ****
  • Posts: 356
I stumbled over an issue that is possibly a bug:

- take the attached example and run it- double-click on the left chart axis and in the appearing dialog uncheck autoscaling and use 2.00 as max range for the axisresult: everything looks fine, see attached

- now add a mark by Ctrl+Click on a datapoint in the chart
result: the y-axis max is now 2.2 instead of the specified 2.0. So my max setting is overwritten and looking at the chart, see attached there is no need to change the range because the mark does not consume this space

The axis range is set in my example in the file ceAxisFrame and there in "TChartAxisFrame.seMaximumChange" I have
Code: Pascal  [Select][+][-]
  1. FAxis.Range.Max := seMaximum.Value;
So I think I made everything correctly.
maybe there is a way to disable the automatic range max/min change by the marks? if so, what could the side effects?

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: [possible bug] adding a mark always changes axis range min/max
« Reply #1 on: July 15, 2022, 02:56:43 pm »
result: the y-axis max is now 2.2 instead of the specified 2.0.

I found now out that setting the marks property "AutoMargins" to "False" the problem goes away.

However, for AutoMargins I cannot find a documentation therefore I don't know what side effect this change would have.
Does anybody know this?

I see that when I disable it and a mark would need more y-space to be shown, it might be invisible.

So I think the AutoMargins feature should work this way:- if a new mark needs more y- space, the axis range max is adjusted- if its top edge is lower than the max y-value of the series, the axis range max is not changed.
« Last Edit: July 15, 2022, 03:00:45 pm by Muso »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: [possible bug] adding a mark always changes axis range min/max
« Reply #2 on: July 15, 2022, 04:41:28 pm »
This is intended. The algorithm does not check whether the mark would fit into the axis range defined and therefore automatically creates space for the worst case. Positioning of the marks per series can be controlled by the MarkPositions property; I had thought that the lmpInside option puts the marks in the space BETWEEN max and min, but as I see the axis is rescaled here as well - maybe this is a bug, I'll have to investigate.

Setting AutoMargins to false is not a solution in case of default settings because the label will be truncated if it is placed near the maximum of the series. What you can do is to provide extra margin either by increasing the Left.Axis.Range (Chart.LeftAxis.Range.Max := 1.2, .Min := -1.2, .UseMax := true, .UseMin := true), or by increasing the Margins.Top and . Bottom of the chart. The latter is a bit more predictable: Font height is about 10 px, the length of the link line (Distance) is 10, the mark.Margins.Top and .Bottom are 2 each, plus 2px for the Marks border --> 36 px, plus some safety margin --> 40 px should work for a single-line mark.


wp

  • Hero Member
  • *****
  • Posts: 11916
Re: [possible bug] adding a mark always changes axis range min/max
« Reply #3 on: July 15, 2022, 06:13:03 pm »
I think I found a fix for the issue that the axis range expands when Marks are displayed even with MarkPositions=lmpInside. Before I commit I would ask you to open unit TACustomSeries and find the procedure TBasicPointSeries.UpdateMargins. Before "m[dir] := Max(m[dir], dist + scMarksDistance);" add "if MarkPositions <> lmpInside then". The center part of the method should be like this now:
Code: Pascal  [Select][+][-]
  1. procedure TBasicPointSeries.UpdateMargins(
  2.   ADrawer: IChartDrawer; var AMargins: TRect);
  3. ...
  4.       UpdateLabelDirectionReferenceLevel(i, j, center);
  5.       dir := GetLabelDirection(TDoublePointBoolArr(gp)[not IsRotated], center);
  6.       with Marks.MeasureLabel(ADrawer, labelText) do
  7.         dist := IfThen(dir in [ldLeft, ldRight], cx, cy);
  8.       if Marks.DistanceToCenter then
  9.         dist := dist div 2;
  10.  
  11.       if MarkPositions <> lmpInside then     // <--- ADDED
  12.         m[dir] := Max(m[dir], dist + scMarksDistance);
  13.  
  14.       if (Source.YCount > 1) and (j = 0) then begin
  15.         if FStacked then begin
  16. ...
  17.  

Please test with Series.MarkPositions = lmpInside: The axis limits should not move any more (provided that the range covered by the data is large enough to contain the marks).

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: [possible bug] adding a mark always changes axis range min/max
« Reply #4 on: July 18, 2022, 03:03:49 pm »
Before I commit I would ask you to open unit TACustomSeries

Many thanks! Yes, this fixes the issue for me with lmpInside.

For my application however I realized that I  cannot use lmpInside because this looks awful since the main use case is to have several similar LineSeries, just with a small y-offset. (ideally this offset should even be zero) Therefore lmpOutside looks better for my application.

Then it is important to get in every case the range one wants. Data is more important than the marks and when scaling in one is interested in the data.

As wish, these things would be cool:
- being able to set a short text for the mark and by hovering the mouse over the mark, one gets the full text. This would be cool, because sometimes one need more text but don't wand to clutter the chart with large text

- easier selection of existing marks, so that one can e.g. double-click on a mark to alter it

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: [possible bug] adding a mark always changes axis range min/max
« Reply #5 on: July 18, 2022, 04:47:43 pm »
- being able to set a short text for the mark and by hovering the mouse over the mark, one gets the full text. This would be cool, because sometimes one need more text but don't wand to clutter the chart with large text
You have everything needed. The series has an OnGetMark event in which you can decide what will be shown as data point label finally. And you can add a TDataPointHintTool which displays a popup hint window and has an OnHint event, again to determine which text will be in the popup. The basic idea is to merge both kinds of information into the Text field of the datapoint: simply separate them by an unused character, e.g. a "|". Both events must read tha datapoint Text string, split it at the "|" - the first part goes to the series marks, the second part goes to the hint tool (or reverse). See attached demo.

- easier selection of existing marks, so that one can e.g. double-click on a mark to alter it
Isn't the datapoint click tool enough?

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: [possible bug] adding a mark always changes axis range min/max
« Reply #6 on: July 22, 2022, 05:11:47 pm »
You have everything needed. The series has an OnGetMark event in which you can decide what will be shown as data point label finally.
It is not about the data point but the area of the mark. For my application, the DataPointHintTool shows the value of the data as popup. This is fine. For a mark however, I need a popup when hovering with the mouse over the mark area (so not above the data point).I attached a screencast to demonstrate what I mean.

I am not the only user of the program and the feedback I got is that people expect they can either hover with the mouse over the mark's area or click into it.I add the the program description that they need to zoom in, select the data point and first then can change the mark. But who reads docs  ;) ? So I cot complaints once per user that the marks cannot be changed. Looking at other laboratory software one can directly click on a mark to change. So people are used to that.

However, as I wrote, this is something for the future. As it is, it is fine in my opinion. I think people will understand that every program is a bit different and I am also no service provider to please my colleagues  :) .

Isn't the datapoint click tool enough?
No, because one first has to zoom in a lot to pick the data point that holds the mark. (There is a datapoint every 3 seconds and the measurements take usually weeks.)

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: [possible bug] adding a mark always changes axis range min/max
« Reply #7 on: July 23, 2022, 01:06:57 am »
The problem with a "TMarksClickTool" is that all marks border polygons should be stored somewhere, and the ChartSources are not prepared for that. Or the marks rectangles should be recalculated at real time whenever the tool is active (in the worst case: whenever the mouse is moved), and I am afraid that the chart could become quite slow this way in case of many marks. As already said marks borders are polygons rather than rectangles which even can be rotated; their calculation is quite complex.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: [possible bug] adding a mark always changes axis range min/max
« Reply #8 on: July 23, 2022, 07:42:52 pm »
Added an experimental TDatapointMarksClickTool. It was not as difficult as expected; the code is not very intelligent, though, mostly copy and paste of existing fragments with minor adjustments. But anyway, it seems to work, also with rotated labels and with an elliptic shapes. See attached test program (IMPORTANT: requires the TAChart version of Laz/Main!)

Please do not yet consider the current code as stable, there may still be some code-breaking changes in the next days after some more testing.

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: [possible bug] adding a mark always changes axis range min/max
« Reply #9 on: July 25, 2022, 06:49:23 pm »
(IMPORTANT: requires the TAChart version of Laz/Main!)
Please do not yet consider the current code as stable, there may still be some code-breaking changes in the next days after some more testing.
Many thanks!
As I wrote, these were just ideas. I feel that I set you under pressure but that was not my intention. Sorry.

However, of course I will test  :) . However, I cannot do this this week, but next weekend I should have some time and have then access to FPCupDeluxe and thus to Main. So please tell me what I should/could test on Friday.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: [possible bug] adding a mark always changes axis range min/max
« Reply #10 on: July 25, 2022, 06:58:36 pm »
So please tell me what I should/could test on Friday.
Write a litte chart application with some dummy series, similar to what you do in your real application(s). Add the new tool and try to find out how to use it. Play with it and tell me if there is something which behaves incorrectly or is not intuitive (I can't promise that I'll change it, but if you don't tell me it certainly will never be changed).

Muso

  • Sr. Member
  • ****
  • Posts: 356
Re: [possible bug] adding a mark always changes axis range min/max
« Reply #11 on: July 27, 2022, 09:54:17 pm »
Write a litte chart application with some dummy series, similar to what you do in your real application(s). Add the new tool and try to find out how to use it. Play with it and tell me if there is something which behaves incorrectly or is not intuitive
I could not resist and thus tested it before the weekend  :)
Awesome work!

Here are some comments after an hour of playing with the tool in my real-life application:

- my experience is that users need a visual hint that something is clickable. Therefore the tool should have an "onHover" event. The idea is that when the user moved the mouse over a mark the cursor changes. Moreover I would also need this feature to display something.

- a new experience for me is that some people love writing lengthy texts into the marks and they clutter the chart. my idea is that there is a setting in marks that when on, will only display the first 3 words (adjustable). When the user moves the mouse over a mark, the full mark text is displayed as a popup (like a tooltip).

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: [possible bug] adding a mark always changes axis range min/max
« Reply #12 on: July 28, 2022, 12:13:26 am »
- my experience is that users need a visual hint that something is clickable. Therefore the tool should have an "onHover" event. The idea is that when the user moved the mouse over a mark the cursor changes. Moreover I would also need this feature to display something.
No idea, at the moment. Each tool has an ActiveCursor property which you could set to crHandPoint. But this becomes active only with the tool, i.e. when the click already has occured.

- a new experience for me is that some people love writing lengthy texts into the marks and they clutter the chart. my idea is that there is a setting in marks that when on, will only display the first 3 words (adjustable). When the user moves the mouse over a mark, the full mark text is displayed as a popup (like a tooltip).
I think this requires yet another new tool, a TDatapointMarkHintTool... Beyond that, I think I gave an example of a "dual-use" mark text recently. Each series has an OnGetMark event which defines the text displayed as mark - extract the first 3 words from the full mark text (stored in the Text field of the datapoint record). The tool, on the other hand, could display the full mark text.

 

TinyPortal © 2005-2018