[deutsch]

Object management in Kontrast

Creating objects

In Kontrast, objects are created according to the hierarchy listed below. All objects are ultimately the child of the global kontrast object.

There are two ways to create objects in Kontrast:

  1. You can call the function createX, where X is Figure, Graph, Points, Lines, …

    The createX function needs to be called on the parent object. For example, to create a graph inside a figure, you can call figure.createGraph({ … }):

  2. You can include an object inside an initializer property. The following code achieves the same result as the snippet above:

    Note that the name property (name: 'upperGraph') is automatically assigned when using the initializer property.

A more elaborate example is the basic setup of a figure with a single graph that contains an abscissa, an ordinate and a point plot.

Accessing child objects

You can access all child objects that belong to a certain parent object by accessing the corresponding collection. For example, each figure has a property named graphs. A collection property is simply a JavaScript object, i.e. a list of keyvalue pairs. The key is the child object name, the corresponding value is the child object.

The following code snippet iterates over all graphs of a figure. It prints a list of their names and their aspect ratio to the console:

The following code snippet colors all line plots blue.