* * *

Author Topic: Why does it wobble? Please stop wobbling...  (Read 1737 times)

jayjay

  • Newbie
  • Posts: 3
Why does it wobble? Please stop wobbling...
« on: January 08, 2018, 02:21:31 am »
Hi All,

When I drag the contents of a TAChart along with the right mouse button, the whole chart content wobbles and the top and right border of the chart move. This stems from TAChart seemingly re-calculating the chart contents' size when axis markers appear, disappear or change.

I mean I get it, when numbers appear or disappear on the axes, their extent probably should change. But the size of the area where the actual graph is drawn should always stay the same.

I consider this a bug.


So far I tried:


Nothing worked.

I have video screen capture of this, but it's too big to upload here. So, for now, just 2 screenshots. Watch the difference in the position of the top border of the chart. Same happens on the X axis.


wp

  • Hero Member
  • *****
  • Posts: 4391
Re: Why does it wobble? Please stop wobbling...
« Reply #1 on: January 08, 2018, 09:11:17 am »
I have video screen capture of this, but it's too big to upload here.
Video capture is not much help. Please provide a sample project which reproduces the observed behavior (only pas, lfm, lpi and lpr files, packed into a single zip, upload here under "Attachments and other options").
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wp

  • Hero Member
  • *****
  • Posts: 4391
Re: Why does it wobble? Please stop wobbling...
« Reply #2 on: January 09, 2018, 11:13:59 am »
If I understand correctly you should use the property LabelSize of the LeftAxis to fix the position of the y axis line with respect to the position of the axis title. Make the LabelSize large enough to "swallow"the varying length of the y axis labels.

See also: http://wiki.lazarus.freepascal.org/TAChart_documentation#Axis_LabelSize
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

jayjay

  • Newbie
  • Posts: 3
Re: Why does it wobble? Please stop wobbling...
« Reply #3 on: January 10, 2018, 03:08:24 am »
Hi wp, thanks for the suggestion with LabelSize. It didn't work, though.

I attached 2 code samples which, I hope, make it clearer what I mean. I just took the basic example from the TAChart demos.

Run the samples (doesn't matter which one, just the LabelSize is different, which has no effect), add some lines or area graphs...

Then, slowly, move the graph from left to right and up and down (dragging it with the right mouse button). While you do watch the RIGHT and TOP edges of the chart. They move, which they should not! The size of the whole chart area is changed when numbers appear or disappear at the axes, which makes the displayed chart contents wobble.

For kicks add a pie chart. Watch it wobble as the chart area's size changes when dragging.

I consider it a bug that the chart area's size changes on moving the chart. The size should only change on resize events, i.e. resizing the surrounding container.

wp

  • Hero Member
  • *****
  • Posts: 4391
Re: Why does it wobble? Please stop wobbling...
« Reply #4 on: January 10, 2018, 09:18:18 am »
Thank you. When dragging to the right, this happens when the right-most axis label is at the very edge of the chart. If you drag further to the right this label should disappear because it would be truncated. But the chart keeps it and compensates this by reducing the chart area. This is a bug, I'll try if I can find it.

You can avoid it if you add a right axis, turn off its marks (Chart.AxisList[2].Marks.Visible := false) and increase its LabelSize (Chart.AxisList[2].Marks.LabelSize := 10). The same with a new top axis to avoid the vertical jitter.

To add an additional axis click on the '...' next to "AxisList" (or right-click on the "AxisList" in the component tree), select "Add item" and set the "Alignment" of the new axis to calRight or calTop for a right or top axis, respectively.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wp

  • Hero Member
  • *****
  • Posts: 4391
Re: Why does it wobble? Please stop wobbling...
« Reply #5 on: January 10, 2018, 05:25:09 pm »
Thank you. When dragging to the right, this happens when the right-most axis label is at the very edge of the chart. If you drag further to the right this label should disappear because it would be truncated. But the chart keeps it and compensates this by reducing the chart area. This is a bug,
Not sure about this statement any more...

Suppose a chart with x ranging between 0 and 1000, then it is very logical that labels are placed at 0, 200, 400, 600, 800, 1000 (at the very right end). But for the right-most label to be placed at the axis, the chart must move the right edge of the chart to the left to make place for the label. On the other hand, if x would range only between 0 and 900, then the last label would be at 800, and this would fit on the axis without any adjustments.

Of course, the jitter while dragging the series is annoying, but I think it is unavoidable if these arguments are accepted. Of course you could say: TAChart should calculate the labelsize for me, it knows the length of labels -- well, the latter sentence is not correct: it does not know the labels per se, TFuncSeries, for example, if dragged can reach any x value and it is not excluded that the initially calculated LabelSize could not become too small after dragging.

Therefore, I'd say it is the responsibility of the programme to take care of the jitter if he does not like it. TAChart is suffciently modular so that this can be done: Just add a right and top axis with sufficiently large LabelSize as explained in the previous post.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

jayjay

  • Newbie
  • Posts: 3
Re: Why does it wobble? Please stop wobbling...
« Reply #6 on: January 12, 2018, 02:31:58 am »
Thank you wp for the work around. It works and since this is for a real world application I'm OK with it.

I still maintain, though, that moving the graph around should not trigger re-layouting / re-sizing. If numbers on an axis don't fit why not just clip them.

If you take the stock axis demo and click on the last tab ("position") you can see this quite well: instead of just being clipped  the axes get special treatment and the chart resizes on all 4 borders. It's not what the user expects.

Out of curiosity: I'm guessing TAChart always repaints all points when dragging the graph around, right? I can't imagine otherwise when it resizes during that operation.

A fixed size would make it possible to only draw newly uncovered points and just move (bitblit) the others.


wp

  • Hero Member
  • *****
  • Posts: 4391
Re: Why does it wobble? Please stop wobbling...
« Reply #7 on: January 12, 2018, 10:35:28 am »
A fixed size would make it possible to only draw newly uncovered points and just move (bitblit) the others.
I won't do this because it goes into the heart of TAChart's drawing process and will keep me busy for a long time. A patch would be welcome, though. But it must not break ANY feature of TAChart.

If numbers on an axis don't fit why not just clip them.
Absolutely no. A clipped label will be annoying all the time while the jitter occurs only during the short time while the chart is dragged.

I found a solution now which freezes the size of the chart area when the pandrag tool is activated and recalculates it when dragging ends. This avoids the jitter (your issue) and recalculates the labels at the end of the drag (my issue). Please test r57059 of Laz trunk.
« Last Edit: January 12, 2018, 10:40:44 am by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus