[vtkusers] Setting axis text label orientation in vtkChartXY
Marcus D. Hanwell
marcus.hanwell at kitware.com
Wed Mar 9 11:24:45 EST 2011
On Tue, Mar 8, 2011 at 3:03 PM, Steven Chall <stevec at renci.org> wrote:
> On 7 March 2011 17:25, Eric E. Monson <emonson at cs.duke.edu> wrote:
> ...
>> Regarding the font size and tick spacing, you can get around this problem in a manual way by specifying the tick positions and labels and their font sizes. vtkAxis has SetTickPositions() and SetTickLabels(), both of which internally set Behavior = 2 (CUSTOM), which turns off automatic tick spacing calculations. Then you can use GetLabelProperties() to set the font size to a reasonable one for the image size you want. It's not a very automatic solution, but it gets around the problem.
> ...
>
> Here's an apparently similar situation: For the vertical axis in vtkChartXY the default text orientation is vertical. I'd like to set it to horizontal, i.e., the usual way to place text. For vtkChartXY *chart, I call:
>
> chart->GetAxis(vtkAxis::LEFT)->GetTitleProperties()->SetOrientation(90.0);
>
> which does nothing right now, for any orientation values, although the orientation is apparently actually being set, since:
>
> double yOr = chart->GetAxis(vtkAxis::LEFT)->GetTitleProperties()->GetOrientation();
>
> always sets yOr to the expected orientation value, and even though I *think* I'm (inadvertently) following Eric's recommendation for setting Behavior = 2 (CUSTOM) by first doing this (turning off ticks and tick labels by using instantiated but empty vtkDoubleArray *tickPositions and vtkStringArray *tickLabels as args, since chart->GetAxis(vtkAxis::LEFT)->SetNumberOfTicks(0) doesn't seem to do anything, either) :
>
> chart->GetAxis(vtkAxis::LEFT)->SetTickPositions(tickPositions);
> chart->GetAxis(vtkAxis::LEFT)->SetTickLabels(tickLabels);
>
> Furthermore, this, called right after SetOrientation(...), *does* work:
>
> chart->GetAxis(vtkAxis::LEFT)->GetTitleProperties()->SetLineOffset(-193);
>
> Now I just noticed that I'm using [GS]etTitleProperties() instead of [GS]etLabelProperties() as in Eric's email, so I replaced all of the former with the latter, and got the same results, with one exception: ...->SetLineOffset(-193) no longer seems to work, either.
>
> Thanks for any suggestions you may have.
>
Which version of VTK are you using here? I went through the vtkAxis
class to ensure that the text properties are used, and these fixes
will be in the VTK 5.8 release. I don't think they were in VTK 5.6.1
if you are using the previous release of VTK. If there is anything I
missed then it is a bug, and I will fix it.
Marcus
More information about the vtkusers
mailing list