Page 1 of 1

Manual axis layout and automatic margins?

Posted: Mon Apr 20, 2015 11:24 am
by jrvdboom
When I set automatic Y axis layout to Off, the margins aren't updated automatically anymore.
Is there a workaround for this?

Thanks,
Joost

Re: Manual axis layout and automatic margins?

Posted: Tue Apr 21, 2015 8:17 am
by ArctionPasi
Can you be more specific?

If ViewXY.AxisLayout.AutoAdjustMargins is enabled, it uses automatic margins set by axes. By disabling AutoAdjustMargins, ViewXY.Margins property applies, and ViewXY.AxisLayout.YAxisAutoPlacement repositions the axes but don't change the margins.

If AutoAdjustMargins is enabled, YAxisAutoPlacement adjusts the margins. By setting YAxisAutoPlacement = AllLeft, AllRight, LeftThenRight, RightThenLeft, it adjusts the margins based on the axis labels, ticks and titles. When setting YAxisAutoPlacement = Off, ViewXY.Margins.Left and Right applies.

That is the designed functionality and by testing it seems to work correctly.

Re: Manual axis layout and automatic margins?

Posted: Tue Apr 21, 2015 8:46 am
by jrvdboom
ArctionPasi wrote: If AutoAdjustMargins is enabled, YAxisAutoPlacement adjusts the margins. By setting YAxisAutoPlacement = AllLeft, AllRight, LeftThenRight, RightThenLeft, it adjusts the margins based on the axis labels, ticks and titles. When setting YAxisAutoPlacement = Off, ViewXY.Margins.Left and Right applies.

That is the designed functionality and by testing it seems to work correctly.
That's exactly what I do, but the margins needed when YAxisAutoPlacement = Off are not known. If I have a Y axis at position 0 (or 100), the required margin to make it look good depends on the tick-labels of the axis as well as the axis title. Is there a way to determine the total width of the axis so that I can use that as input for the margins?

For me it would be even better if I could use AutoAdjustMargins in combination with YAxisAutoPlacement = Off.

Re: Manual axis layout and automatic margins?

Posted: Tue Apr 21, 2015 3:57 pm
by ArctionPasi
It'll need manual calculation of axis space. Approx. like this:

yAxis.AxisThickness + yAxis.MajorDivTickStyle.LineLenght + yAxis.LabelTicksGap + chart.MeasureText(yAxis.Maximum.ToString(), yAxis.LabelFont).X+ yAxis.Title.DistanceToAxis + chart.MeasureText(yAxis.Title.Text).Y / 2.

I didn't try but should be pretty near.

Disable chart.ViewXY.AxisLayout.YAxisTitleAutoPlacement otherwise the title calculation doesn't match.