Skip to content
Giorgio Caviglia edited this page Apr 3, 2014 · 7 revisions

Since most (D3) layouts operates on specific data structures (e.g. hierarchies for Bubble Charts or nodes-links for Force-directed Graphs), RAW provides an interface (both logical and graphical) to let users transforming the data into the appropriate structure required by the chart. This can be done through models. In short, a model transforms data records into the 'something else' charts need to work with. Differently from the native JavaScript map function (which always creates a one-to-one map), models can return any sort of object (i.e. arrays, objects, numbers, strings...). RAW will create the necessary GUI elements to let the users decide which dimensions using within the transformation process.

raw.model()

Constructs a new model. A model works through a map function and one or more map dimensions. The map function takes the original data (records) in input and transform them into the structure required by the chart. Model dimensions define those transformation variables needed to be exposed to - and controlled by - the user.

model(records)

Applies the model on the data, by running the map function to the records. Within the RAW application there is no need to directly call the model, since it will be automatically called before the chart, passing it the structured data.

model.map([function])

If function is specified, sets the map function to the specified function. If function is not specified, returns the current map function. The map function is invoked for the (whole) input data and can return any value needed by the chart (usually arrays or objects).

The default map function is the identity function and thus returns the input data.

function map(data) {
	return data;
}

model.dimensions()

Returns the dimensions associated to the model. Dimensions are stored as a d3.map object.

model.clear()

Reset all the dimensions in the model by calling the clear method of each dimension.

model.dimension([name])

Constructs a new dimension. Dimensions are used to expose map variables to the users, allowing them to choose the appropriate column(s) to build the structure. For each dimension in the model, RAW creates a GUI element which allows the user to associate the dimension with one or more columns in the data.

If name is specified, it will be used to identify and retrieve the dimension. Otherwise, a default unique identifier will be created.

dimension(object)

If object is specified, returns the value(s) for the column(s) associated to the dimension. In case of multiple columns, an array containing the corresponding value for each column will be returned.

If object is not specified, returns the column or the columns addociated with the dimensions.

Dimensions are meant to be called within the map function to access the columns chosen by the user and use them within the transformation process.

dimension.multiple([boolean])

If boolean is specified, enables or disables multiple columns accordingly. If boolean is not specified, returns the current multiple value. By default, this option is disabled and each dimension can be associated only to one column. When boolean is true users could associate any number of columns to the dimension.

dimension.types(types...)

If types is specified, forces the dimensions to accept only columns with those data types. Currently, the following data types are available: Number, String, Date. The types need to be listed as built-in Javascript classes (e.g. Number). If types is not specified, returns the currently accepted types. By default all the previous data types are accepted.

dimension.title([text])

If text is specified, sets the title of the dimension to the specified text. If text is not specified, returns the current title. The default value is "Untitled". The title will be displayed in the GUI.

dimension.description([text])

If text is specified, sets the description to be displayed to the specified text. If text is not specified, returns the current description. The default value is null.

dimension.clear()

Reset the value of the dimension, by clearing its value.

##Built-in Models

Since most of the layouts share the same structure, RAW comes with some built-in models, ready to be used for new charts. In

var points = raw.models.points();

model.dimensions().remove('dimension')

###Points

raw.models.points(records)

Creates a new model to transform data records into an array of points. Each point is an object with

{
	x : 0.123,
	y : 4.456,
	size : 7890,
	label : '
	color : 	
}

x

points.dimensions().get('x')
points.dimensions().remove('x')

y

size

color

label

###Tree

raw.models.tree(records)

hierarchy

size

color

label

###Graph

raw.models.graph(records)

steps

size

###Identity

raw.models.identity(records)

Clone this wiki locally