Difference between revisions of "Axes Tick Marks and Labels"
(→Tick Mark and Resizing Functions) |
(→Tick Mark and Resizing Functions) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 17: | Line 17: | ||
The following functions are involved in making tick marks and resizing them when a graph is resized: | The following functions are involved in making tick marks and resizing them when a graph is resized: | ||
− | *'''ravemaketextticks''' - This function is called by ravecreate<keyword>, usually near the end of the file. Based on the variable displayed on each axis and its datatype, this function decides | + | *'''ravemaketextticks''' - This function is called by ravecreate<keyword>, usually near the end of the file. Based on the variable displayed on each axis and its datatype, this function decides what strings to use for tick marks and where to place tick marks default matlab tick mark system or to create text ticks using ravemakecustomticks. |
− | *'''ravemakecustomticks''' - This function makes text object tick labels with the strings sent to it by ravemaketextticks. Its main purpose is to | + | *'''ravemakecustomticks''' - This function makes text object tick labels with the strings sent to it by ravemaketextticks. Its main purpose is to create the text objects with the proper strings. This function does NOT handle string wrapping or rotation. This function also does not place the tick marks at their proper locations. |
− | *'''raveresizeaxes''' - | + | *'''raveresizeaxes''' - Called in response to a graph changing size, this function resizes handles.allgraphs(ai) to fit inside handles.allblockers(ai) while leaving sufficient room for all axes/tick labels etc. |
− | *'''ravearrangeobjects''' - | + | *'''ravearrangeobjects''' - Called by raveresizeaxes (at the end), this function places all visual elements relative to handles.allgraphs(ai) |
− | *'''ravemovecustomticks''' - | + | *'''ravemovecustomticks''' - Called by ravearrangeobjects (at the end), This function determines if tick labels need to be wrapped or rotated, and puts them at the proper x/y/z locations in axes coordinates. |
− | *'''betterlinewrap''' - This function attempts to wrap a string by making an educated guess at how many pixels it will render to on screen. | + | *'''betterlinewrap''' - This function attempts to wrap a string by making an educated guess at how many pixels it will render to on screen. Called by ravemovecustomticks |
− | *'''raveniceticks''' - Calculates tick mark locations for a graph, similar to MATLAB's automatic xtick/ytick/ztick mode. | + | *'''raveniceticks''' - (Currently Unused) Calculates tick mark locations for a graph, similar to MATLAB's automatic xtick/ytick/ztick mode. |
*'''axeschangelistener''' - | *'''axeschangelistener''' - | ||
− | *'''raveupdateticksKEYWORD''' - | + | *'''raveupdateticksKEYWORD''' - This function is called by axeschangelistener whenever the ticks of graph change in response to zooming, changing axis limits, or resizing |
+ | |||
+ | *'''ravesynchaxes''' - Called by ravearrangeobjects for 3d graphs. |
Latest revision as of 12:27, 16 August 2012
Contents
Introduction
Getting tick marks to work correctly in Rave was hard. MATLAB offers NO way to get the handles of axes tick labels, so when Rave needs to do something special it has to create tick labels from scratch as text objects.
Axis tick marks must be set in one of three ways:
- For normal numerical tick mark labels, you can use the normal MATLAB axes command x/y/ztick x/y/zticklabel properties.
- If the graph can (ever) display text variables such that the tick labels need to be text strings, call the function "ravemaketextticks" near the end of the ravecreateKEYWORD.m file. This function will create text object tick labels that smartly wrap/rotate. Non-text tick labels will use MATLAB's default way of making tick labels.
- If the graph needs custom tick labels (i.e. anything not covered by the first two bullets), call the function "ravemakecustomticks". Note that ravemaketextticks is essentially just a wrapper for ravemakecustomticks that automaticates the proper syntax. When you need more flexibility, use ravemakecustomticks.
Tick Label Sizing/Text Wrapping
Tick labels are drawn in the font and fontsize in raveprefs.fonts.graphname and raveprefs.fonts.graphsize. When these properties are changed via the setup tab (raveeditthemefontsgui), the function characterwidths is called. This function attempts to determine how many pixels each keyboard character will occupy on screen, and stores this info in raveprefs.fonts.graphwidth. (Non-keyboard ASCII characters are treated as 1 pixel. The characterwidths function could easily be modified to include other ASCII characters if needed.)
Tick label wrapping is really only an issue for the x-axis, since y-axis text is stacked vertically so the labels never interfere with each other. The function ravemovecustomticks is called by raveresizeaxes to move tick labels as a graph is moved/resized and to wrap text tick labels when necessary/possible. The function betterlinewrap determines if the ticklabel should be wrapped by comparing the available on-screen pixels (i.e. the distance between tick marks) to the estimated width of the ticklabel. If the width>available space, the string will be wrapped after a space or any of the characters +-/*})],_ or before the characters {([. If the string cannot be sufficiently wrapped (for example because it is one long word with no spaces or if even after wrapping it is still too wide) then ALL ticklabels for that axis will be rotated so the text reads vertically.
Tick Mark Locations
Tick Mark and Resizing Functions
The following functions are involved in making tick marks and resizing them when a graph is resized:
- ravemaketextticks - This function is called by ravecreate<keyword>, usually near the end of the file. Based on the variable displayed on each axis and its datatype, this function decides what strings to use for tick marks and where to place tick marks default matlab tick mark system or to create text ticks using ravemakecustomticks.
- ravemakecustomticks - This function makes text object tick labels with the strings sent to it by ravemaketextticks. Its main purpose is to create the text objects with the proper strings. This function does NOT handle string wrapping or rotation. This function also does not place the tick marks at their proper locations.
- raveresizeaxes - Called in response to a graph changing size, this function resizes handles.allgraphs(ai) to fit inside handles.allblockers(ai) while leaving sufficient room for all axes/tick labels etc.
- ravearrangeobjects - Called by raveresizeaxes (at the end), this function places all visual elements relative to handles.allgraphs(ai)
- ravemovecustomticks - Called by ravearrangeobjects (at the end), This function determines if tick labels need to be wrapped or rotated, and puts them at the proper x/y/z locations in axes coordinates.
- betterlinewrap - This function attempts to wrap a string by making an educated guess at how many pixels it will render to on screen. Called by ravemovecustomticks
- raveniceticks - (Currently Unused) Calculates tick mark locations for a graph, similar to MATLAB's automatic xtick/ytick/ztick mode.
- axeschangelistener -
- raveupdateticksKEYWORD - This function is called by axeschangelistener whenever the ticks of graph change in response to zooming, changing axis limits, or resizing
- ravesynchaxes - Called by ravearrangeobjects for 3d graphs.