SuperCollider CLASSES

GridLines

given a spec and the actual data's min and max values, calculates the ideal spacing and labelling of grid lines for plotting
Inherits from: Object
Subclasses: BlankGridLines

Description

GridLines is a strategy object that implements a general strategy for finding a suitable min max range for graphing and suitable intervals for grid lines and labelling.

The object that does the actual drawing on a view is DrawGrid.

A GridLines object uses a ControlSpec to define the minimum and maximum possible values. Given a data set's actual minimum and maximum values, the GridLines object can choose a logical range for graphing that encompasses the data that will be plotted.

Future development work will add subclasses of GridLines that can bind more tightly with the data they are representing. For instance a FreqGridLines (not yet implemented) could apply stronger lines to octave divisions. A DegreeGridLines could be used to draw pitch degree gridlines behind a frequency plot.

Spec has a .grid variable that points to its preferred GridLines object that should be used for graphing.

\freq.asSpec.grid

This default implementation does not know anything about the data is displaying:

DrawGrid.test( nil, \midinote.asSpec.grid );

A MidinoteGrid could be written that labels these correctly, shows octaves and individual notes depending on the current zoom.

Note that the GridLines does not know which axis it is to be used on and could also be used in polar plots or in 3D rendering.

Class Methods

*new (spec)

Arguments:

spec

The ControlSpec that defines the mininum and maximum values, warn and step.

Returns:

a GridLines

Inherited class methods

Instance Methods

-spec

-spec = value

get/set the spec

Returns:

a ControlSpec

-asGrid

return self. nil.asGrid would return a BlankGridLines which is a subclass of GridLines. So when plotting if you specify a grid of nil then you will get no lines at all.

Returns:

self

-niceNum (val, round)

Based on: http://books.google.de/books?id=fvA7zLEFWZgC&pg=PA61&lpg=PA61This rounds a value to a logical nice number. It is mostly used to support internal calculation, though it may be useful for other applications.

Arguments:

val

The value.

round

Boolean. Rounding uses a specific algorithm. This is not simple rounding to an integer value.

Returns:

the nice number

-ideals (min, max, ntick: 5)

for internal use

Arguments:

min

(describe argument here)

max

(describe argument here)

ntick

(describe argument here)

Returns:

(returnvalue)

-looseRange (min, max, ntick: 5)

Returns the logical minimum and maximum that will contain the data.

Arguments:

min

minimum value

max

maximum value.

ntick

the number of lines you would like (which usually varies by how much screen space you have and what you consider cluttered)

Returns:

[ideal min, ideal max]

-getParams (valueMin, valueMax, pixelMin, pixelMax, numTicks)

Specifically for use by DrawGrid. This returns a dictionary filled with: 'lines': an array of values where lines should be drawn 'labels': [value, formatted label] for each line

Arguments:

valueMin

minimum value of the data to be plotted

valueMax

maximum value of the data to be plotted

pixelMin

If numTicks is nil: used to guess the ideal numTicks based on the graph size.

pixelMax

If numTicks is nil: used to guess the ideal numTicks based on the graph size.

numTicks

Explicit number of ticks you would like to see on the graph.

Returns:

A dictionary

-formatLabel (val, numDecimalPlaces)

Round the value and append the spec's units

Arguments:

val

The value

numDecimalPlaces

Number of decimal places

Returns:

a string

Inherited instance methods