canvas Y-coordinate...

Notifications
Clear all

# canvas Y-coordinate of labels

2 Posts
2 Users
0 Likes
380 Views
Posts: 6
Customer
Topic starter
Active Member
Joined: 2 years ago

Hello,

What is a good approach to find the canvas Y-coordinates of labels? For example, in the attached file I want to know the canvas Y-coordinate of "Debt Fraction" so I can align "60%" accordingly.

Topic Tags
1 Reply
Posts: 24
Member
Joined: 2 years ago

You would be finding the y-coordinate from inside an OnGraphDraw or OnGraphClick attribute, of course. For your example graph image,

Local (x,y) := GraphToCanvasCoord(info, roles, 'Debt Fraction', -240K);

would give you the point along the Y-axis right at the center of the bar. I read off the -240K from your horizontal axis. You could put anything in there (e.g., 0) and then use

info[OnGraphDrawItem='PlotAreaLeft']

for the horizontal pixel coord.  Also, it appears that your index Input_assumptions has text labels since they aren't blue in your image. If it has handles, then you would write

Local (x,y) := GraphToCanvasCoord(info,roles, Handle(Debt_Fraction), -240K);

The order of the two graph-values -- i.e., 'Debt Fraction' and -240K -- is vertical axis first, horizontal axis second in this case. That is because this graph has "swap XY" on. The vertical axis is the logical X axis (independent variable), the horizontal is the logical Y axis (dependent variable) when swap XY is on.

In your image, you have shifted the label down a bit from the center for your desired position. If you to use

Local (x,y) := GraphToCanvasCoord(info,roles, 'Debt Fraction', -240K);
CanvasDrawText(canv,"test",x,y)

the top of the text would be aligned with the center of the bar. A second piece here is to figure out how much space you have to shift that label down if you don't want it centered. I expected this to work:

Local (x,y) := GraphToCanvasCoord(info,roles, 'A', -220K);
Local bw := info[OnGraphDrawItem='BarWidthPix'];
CanvasDrawText(canv,"test",x,y+bw/2,vAlign:'Bottom')

but discovered that (at least in release 6.2) that BarWidthPix is only correct when SwapXY is off. I expect that to be fixed in 6.3. A workaround is this:

Local (x,y) := GraphToCanvasCoord(info,roles, 'Debt Fraction', -240K);
Local bw := If info[OnGraphDrawItem='SwapXY']
Then
info[OnGraphDrawItem='PlotAreaHeight'] /
size(#roles[GraphingRole='X axis',GraphFillerInfo='Labels'])
Else
info[OnGraphDrawItem='BarWidthPix'];
CanvasDrawText(canv,"test",x,y+bw/2,vAlign:'Bottom')

This ends up putting the label at the position in your example screenshot.

Share:
Scroll to Top