Dynamically adjust y-axis range so that x-axis labels are visible in plot space

80 views
Skip to first unread message

Chetan Gandhi

unread,
May 15, 2013, 8:22:07 AM5/15/13
to coreplot...@googlegroups.com
In my graph I have scatter plot with x-axis orthogonalCoordinateDecimal 0.0 so that x-axis can change its location according to y-axis range.
I want to expand y-axis range according to the x-axis labels size so that x-axis labels are always visible.
I have custom x-axis labels rotated by some angle. 
I want to keep padding 0 for all side of plot area frame.
Please help me, how can I achieve this.
Plot datasource is combination of  positive and negative values.

Eric

unread,
May 16, 2013, 7:19:51 PM5/16/13
to coreplot...@googlegroups.com
Do you always want the axes to cross at zero? If not, use the axisConstraints to fix the x-axis at a good distance from the bottom edge of the graph and let it float along the y-axis.

If you have to keep the crossing point at zero, use the plot space to convert the desired pixel offset from the edge into data coordinates. Convert two points (e.g., (0, 0) and (0, y)) and compute the difference between the resulting y-values. That is the minimum amount that the location of the yRange should be below zero.

Eric

Chetan Gandhi

unread,
May 20, 2013, 6:14:48 AM5/20/13
to coreplot...@googlegroups.com
Hi Eric,

Thanks for help, But I have got another problem now. As is said, size of axis labels will change according to text size, now i also have to add support for scrolling and zooming in my app. So I was thinking to keep the axis labels as it is and have some bottom padding so that some part of labels is visible. I can have user to scroll the plot space to view whole label. The only problem is that I cannot limit user to zoom-in to certain extend and the graph looks ugly. How can I use the  plot-space delegate methods so that I can have the limit on how much user can zoom-in and scroll. I am currently able to limit the user so that he/she cannot scroll beyond location 0 and some max value on x-axis.

Eric

unread,
May 20, 2013, 7:50:27 PM5/20/13
to coreplot...@googlegroups.com
If all you need to do is limit the scrolling and zooming, use the globalXRange and globalYRange. These constrain the scrolling limits automatically. You can do the same with a delegate, but its more complicated in this case.

Eric

Chetan Gandhi

unread,
May 24, 2013, 1:58:48 AM5/24/13
to coreplot...@googlegroups.com
Thanks Eric,

I have got a way to limit zooming-in of plot space, I am checking length of newRange in plot space delegate method and if this length is less that certain value I am returring current range for corresponding coordinate.
where as zoom-out is limited by setting global range.
I dont know is this the correct way to do this, but its working very well.
Thanks a lot for your help.

Eric

unread,
May 24, 2013, 7:51:59 AM5/24/13
to coreplot...@googlegroups.com
Sounds good. That's how I would do it.

Eric
Reply all
Reply to author
Forward
0 new messages