Recent

Author Topic: Resizable panes again  (Read 4352 times)

kapibara

  • Hero Member
  • *****
  • Posts: 572
Re: Resizable panes again
« Reply #15 on: June 13, 2022, 10:42:38 am »
I found the "dangling" divider happens only for panes added at the bottom, not top.

This divider appears to belong to the neighbor pane, which doesn't need divider anymore when the pane below is deleted. Hmm, how to best delete a divider that belongs to another pane than the deleted one?
« Last Edit: June 13, 2022, 11:09:24 am by kapibara »
Lazarus trunk / fpc 3.2.2 / Kubuntu 21.10 - 64 bit

kapibara

  • Hero Member
  • *****
  • Posts: 572
Re: Resizable panes again
« Reply #16 on: June 14, 2022, 07:28:58 am »
Turned out the Divider was not dangling. It just belonged to the pane above and seemed to be left over since the neighboring pane below was deleted.

I solved it in the new version by introducing a RemoveDivider procedure in TChartBox.
So thats some progress, but here's a situation I'd like to handle next:

Pane 1 is added topmost
Pane 2 is added bottommost
Pane 3 is added bottommost
Pane 4 is added topmost

But remove Pane 4 and Pane 3, and the party is over and panes misalign.
If possible, it should be solved in a way that allows for a pane between other panes to be selected and deleted.
« Last Edit: June 20, 2022, 03:44:02 am by kapibara »
Lazarus trunk / fpc 3.2.2 / Kubuntu 21.10 - 64 bit

kapibara

  • Hero Member
  • *****
  • Posts: 572
Re: Resizable panes again
« Reply #17 on: June 15, 2022, 06:40:57 am »
I think maybe I get it now, how it should work.

Except how to get a pane by clicking the chart.


Lazarus trunk / fpc 3.2.2 / Kubuntu 21.10 - 64 bit

wp

  • Hero Member
  • *****
  • Posts: 9902
Re: Resizable panes again
« Reply #18 on: June 15, 2022, 10:46:21 am »
I think maybe I get it now, how it should work.

Except how to get a pane by clicking the chart.
Good that you found it yourself.

For finding the clicked pane, you could add a TUserDefinedTool to the ChartBox and implement a handler for the OnAfterMouseDown event. Here you get the X,Y coordinates of the clicked point in image coordinates. Convert it to graph coordinates (Chart.ImageToGraph) which is the unit system in which the pane borders are defined in the MinValue and MaxValue of the axis tranform. Then, iterate over all panes and check whether the clicked graph point is within the MinValue-to-MaxValue range of the pane's axis transform.

kapibara

  • Hero Member
  • *****
  • Posts: 572
Re: Resizable panes again
« Reply #19 on: June 20, 2022, 03:42:46 am »
Well, it's getting closer, but still the problem that panes get incorrect size after deleting one of them. I don't understand how to fix it.

I wrote the procedure AdjustPanesAfterDelete to see what happens if to keep the default min/max values for pane 0 and up. The adjustment is shown in the legend after deleting a pane. You can just comment it out.
« Last Edit: June 20, 2022, 04:32:51 am by kapibara »
Lazarus trunk / fpc 3.2.2 / Kubuntu 21.10 - 64 bit

kapibara

  • Hero Member
  • *****
  • Posts: 572
Re: Resizable panes again
« Reply #20 on: June 20, 2022, 10:15:20 pm »
I changed TChartPane's destructor how to remove transformations from a pane. Hope its OK to remove them like this?

Code: Pascal  [Select][+][-]
  1.   destructor TChartPane.Destroy;
  2.   ..
  3.     AxisTransform.Free;
  4.     FAxis.Transformations.Free;
  5.     FAxis.Transformations:= NIL;
  6.  
  7.     FAxis.Free;
  8.   ..
  9.   end;

Lazarus trunk / fpc 3.2.2 / Kubuntu 21.10 - 64 bit

wp

  • Hero Member
  • *****
  • Posts: 9902
Re: Resizable panes again
« Reply #21 on: June 20, 2022, 11:33:00 pm »

kapibara

  • Hero Member
  • *****
  • Posts: 572
Re: Resizable panes again
« Reply #22 on: June 22, 2022, 12:28:04 am »
Thanks.
It seems that my problem with the axes is because when a pane is deleted an axis is removed, and then the axis indexes of the remaining panes dont match the AxisIndexY of the LineSeries. What to do?

I added some panels to view whats going on inside.

Edit: If the panes are added at the bottom, they can be deleted and axes still works. Only adding at the top causes a problem.
« Last Edit: June 22, 2022, 12:38:19 am by kapibara »
Lazarus trunk / fpc 3.2.2 / Kubuntu 21.10 - 64 bit

wp

  • Hero Member
  • *****
  • Posts: 9902
Re: Resizable panes again
« Reply #23 on: June 22, 2022, 07:22:44 am »
It seems that my problem with the axes is because when a pane is deleted an axis is removed, and then the axis indexes of the remaining panes dont match the AxisIndexY of the LineSeries. What to do?
Good catch. The AxisIndex seems to be a bad concept for identification of an axis in such an application...

Anyway, so when you delete an axis why don't you iterate over all series and decrement their AxisIndexY if it is greater than the Index of the deleted axis? In fact, you already have it in TChartBox.RemovePane, but commented it out. Just store the axisindex before deleting the pane (--> pane_axisindex), remove the comment slashes and add an "if AxisIndexY > pane_axisindex":

Code: Pascal  [Select][+][-]
  1. procedure TChartBox.RemovePane(APaneIndex: Integer);
  2. var
  3.   ...
  4.   pane_axisindex: Integer;  
  5. begin
  6.   ...
  7.   pane:= TChartPane(FPaneList[APaneIndex]);
  8.   pane_axisindex := pane.Axis.Index;                             // <--- new
  9.   //When deleting the bottom-most pane (has no divider),
  10.   //the divider of its neighbor must be removed instead.
  11.   if (APaneIndex = 0) and (PaneCount > 1) then
  12.   begin
  13.     divider_pane:= TChartPane(FPaneList[APaneIndex +1]);
  14. //    divider_pane.axis.Visible:=false;
  15.     divider_pane.RemoveDivider;
  16.     pane.Free;  //Also removes series from chart
  17.     FPaneList.Delete(APaneIndex);
  18.     //AdjustPanesAfterDelete;
  19.     for i:=0 to FChart.SeriesCount -1 do begin                  // <-- uncommented
  20.       if FChart.Series[i] is TLineSeries then
  21.       with FChart.Series[i] as TLineSeries do
  22.         if AxisIndexY > pane_axisIndex then                    // <--- new
  23.           AxisIndexY:= AxisIndexY -1;
  24.     end;
  25.   end
  26.  

kapibara

  • Hero Member
  • *****
  • Posts: 572
Re: Resizable panes again
« Reply #24 on: June 23, 2022, 05:53:29 am »
That addition made it possible to remove panes both from the top and from the bottom with axes working as they should. Super!
Lazarus trunk / fpc 3.2.2 / Kubuntu 21.10 - 64 bit

 

TinyPortal © 2005-2018