Satimage Previous | Next
The chart view
Home Documentation SmileLab Scripting Graphic objects Graphic view Chart view  
Table of contents
Introduction
The chart view is a virtual class. The chart view class defines a number of properties that the plot view and the planar view share. You use these properties to adjust the plot to your data, and to bring changes to the various visual components of the plots:
  • [the axes:] primary (those that display the scales) and secondary (the two other edges of the plot frame)
  • [the ticks on the axes:] major (the tags for the scales) and minor
  • [the grid:] the lattice of lines that prolong the ticks
Setting the scales
  • log xaxis and log yaxis are boolean properties that let you choose whether each axis is linear or logarithmic. By default these properties are set to false.
  • limits is a list of four numbers. The four values in limits are, in that order: xmin, xmax, ymin, ymax. By default, limits is set to {"auto", "auto", "auto", "auto"}.
    You can set any of these values to the string "auto" instead of a real number in which case the corresponding limit will be computed according to the data. Note that there are cases where the plot cannot automatically compute valid limits, e.g. if all points have the same ordinate. In such cases the plot may remain blank.
  • current limits is a read-only list of four numbers that returns the plot's current limits. current limits and limits will differ one from the other, either if limits contains "auto", or if the view was zoomed in.
Graphic options for the chart view
We give here some general conventions regarding data in Smile.
  • Properties that define a color expect a "rgba" color. A rgba color is a list of three or four real numbers in the range [0..1]: {r, g, b, a}, the red, green and blue components and the opacity {0.0: transparent, 1.0: opaque}, optional.
  • Properties that define a font expect a font name. To view all the font names available pull down the Text ▸ Font menu.
  • Properties that define a string - such as name, xlabel or ylabel - support a set of coded symbols which allow to write mathematical expressions, a subset of the mathematical symbols that LaTeX defines. For instance \Gamma\rightarrow\pm\infty will display Γ→±∞. The metacharacters that you can use in SmileLab are the same as you can use with the DrawString command of the Graphic Library: please refer to Drawing texts with the graphic engine.
Here is how to set the graphic options for the chart view.
frame kind
frame kind specifies several options of the plot. frame kind is an integer in the range [0..15], each bit of which controls one feature (setting a given bit activates the corresponding feature). By default frame kind is 15 (all bits are set).
Bit 1 controls drawing of the secondary axes.
Bit 2 controls whether the secondary axes will display ticks.
Bit 3 controls the grid.
Bit 4 controls whether the ticks are drawn inside the plot frame.
set x to runningsum (randomarray 20)
set c to QuickCurve({}, x, 0)
set v to chart view of c
set frame kind of v to 0
draw v
major tick length, minor tick length, pen width
to control the ticks, use frame kind to choose whether the ticks will draw inwards or outwards, and set their sizes by loading new values (in pixels) into major tick length and minor tick length. The pen width property defines the thickness of the axis.
grid color, grid pen width, grid dash
to control the grid, use frame kind to turn it on and off, use grid color (the color for the grid lines), grid pen width (the thickness of the grid lines, in pixels) and grid dash. grid dash should be a list such as {phase, s1, w1,.., sn, wn}. All quantities are in pixels. s1, s2 ... are the successive lengths of the strokes, w1, w2 ... are the successive lengths of the spaces between subsequent strokes, and phase specifies the beginning of the dash, for instance if phase is equal to s1 + w1 the dash will start with the stroke #2.
fill color
fill color defines the background color of the plot.
pen color
pen color defines the color for the axes.
back pdf, front pdf
back pdf and front pdf are the properties that allow to display (in addition to the plot), either in the background or over the plot, a graphic from a PDF document or a scripted graphic. The instructions are the same as given for the picture views. Please refer to The picture view object.
convert coordinates
to convert a (x,y) pair given in user's units (the units of the axes) into the coordinates in pixels of the corresponding point use the convert coordinates ... in command like in the example below where the point of the arrow is computed to be on the curve. The coordinates that convert coordinates returns are relative to the chart view's frame's origin.
set c to QuickCurve({}, "0.5+0.25*sin(2*pi*x*x)", 0)
set v to container of c -- v is the graphic view
set p to {1 / (sqrt (2)), 0.5}
set p to convert coordinates p in v
set m to sublist p with {30, 0}
BeginFrontFigure(v)
MoveTo(m)
LineTo(p)
SetArrowSize({10, 15, 4})
ArrowPath(0)
DrawPath(3)
EndFrontFigure()
draw v
name, xlabel, ylabel
The name of the view is displayed above the frame of the view. This name can contains several lines.
each axis supports one label, a string that will be printed under the x-axis (resp. on the left of the y-axis). To define these strings use xlabel and ylabel.
xlabel offset, ylabel offset
To customize the distance of the labels to the axes provide values (in pixels) for xlabel offset and/or ylabel offset. The larger xlabel offset the lower the label for the x-axis. The larger ylabel offset the further leftwards the label for the y-axis.
label text font, label text size
Use label text font and label text size to have the labels print in a different font or font size.
text font, text size
You can change the font for the scales by providing a font name as text font and/or an integer as text size. To remove the scales set text size to 0.
xaxis labels positions, xaxis labels tilt, xaxis labels
You can change the location of the strings by providing a custom list of abscissae (in user units, i.e. in the unit of the x-axis) as the xaxis labels positions.
You can change the angle of the strings by providing a non-zero angle in radian as xaxis labels tilt.
Finally you can customize to whole extent the axis by supplying custom strings as the xaxis labels property. Use this feature when numeric scales do not make sense (e.g. the x units are the 12 months). A custom xaxis labels list will be taken into account only if you provide the corresponding xaxis labels positions property. Both lists should have the same size.
set x to runningsum (randomarray 21 range {-1 / 2, 1})
set c to QuickCurve({}, x, 0)
set v to c's chart view
set text size of v to 12
set xaxis labels of v to {"", "10.2.1", "10.2.3", "10.2.4", "10.2.6"}
set xaxis labels positions of v to {0, 5, 10, 15, 20}
set xaxis labels tilt of v to pi / 6
draw v
legend text font, legend text size, legend pen width, legend fill color
though the legends of the sub-classes of chart view differ one from each other for the aspect, chart view defines the general settings for the legend: the font used in the legend is controlled with legend text font and legend text size, the legend's frame's width is legend pen width (in pixels) and the legend's background color is legend fill color.
-- semi-transparent yellow legend background
set legend fill color of v to {1, 1, 0.8, 0.5}
-- thin legend boundaries
set legend pen width of v to 0.25
draw v
Copyright ©2008 Paris, Satimage