Axis
An axis defines how data is graphically represented. There are spatial axes, such as abscissae and ordinates. Spatial axes are used to map data to a specific position in space. Additionally, there are color axes, opacity axes and thickness axes that can be used to visualize data with the respective graphical property.
Available axis types
Kontrast provides three (Cartesian) spatial axes:
- Abscissa
- Ordinate
- Applicate
And there are three axis types that can be used to map data to color, opacity or thickness:
How to create axes
Usually they are created inside the createGraph()
like
shown below (please refer also to the
tutorial):
You can also create them separately.
These two code snippets are equivalent (see also object management).
Interface
The following functions and properties are common for all axis objects.
Functions
-
showEverything()
Set the minimum and maximum value of the axis so that all valid data points used in plots associated with the axis are within the (min
tomax
) range.
General properties
-
name
:KontrastName
The name of the axis. The name has to be unique within the graph the axis belongs to. The name must not be empty and must not contain a dot, colon, semicolon or a hash (
#
). The name defaults toaxisN
, whereN
is a non-negative integer. We recommend you choose a meaningful name for each axis, so that it can be easily accessed via the development console or the Kontrast menu. -
label
:KontrastAxisLabel
The label of the axis.
-
hidden
:KontrastBoolean
(default value:false
)When set to true, the axis is hidden (i.e. invisible).
-
excludeFromLayout
:KontrastBoolean
(default value:false
)Whether the axis is excluded from the layout algorithm. If set to
true
, the axis might be still visible but the margins of the zone where the annotations is placed in are not influenced by the annotation. -
relative
:KontrastBoolean
(default value:false
)When set to true, the axis acts like a scale bar (omitting absolute values and only showing the relative length of the axis).
-
mapping
:KontrastMapping
(default value:'linear'
, possible values:'linear'
,'date'
,'degree'
,'radianAsDegree'
,'ln'
,'log10'
,'log2'
,'positiveReciprocal'
)The mapping of the axis.
-
numberFormat
:KontrastSelection
(default value:'scientificBase1000'
, possible values:'scientificBase1000'
,'scientificBase10'
)This property determines whether tick exponents are preferred to be divisible by 3 (
'scientificBase1000'
, sometimes referred to as engineering notation) or not ('scientificBase10'
, sometimes referred to as scientific notation). -
renderIndex
:KontrastNumber
(default value:0
)This number determines the order in which graphical elements (the axes and the plots) are drawn. The behavior is similar to the concept of a
layer
: First, the object with the lowestrenderIndex
is drawn on the screen. The object with the largestrenderIndex
within the graph is drawn last.Example: Fine-tuning the drawing order using the render index
-
reverseDirection
:KontrastBoolean
(default value:false
)Reverse the role of
min
andmax
. -
markerQuantity
:KontrastString
(default value: empty string)If this string is not empty, it is used as the prefix text inside hover markers. It may consist of HTML and is typically used to denote the physical quantity shown on an axis.
See also: Marker documentation
-
markerUnit
:KontrastString
(default value: empty string)This string is used as a suffix for the hover marker. It may consist of HTML and is typically used to denote the unit of the quantity shown on the axis. Since the marker unit is appended without any additional space between the number, please add a space to the unit if necessary.
See also: Marker documentation
-
excludeFromHoverMarker
:KontrastBoolean
(default value:false
)When set to
true
, the axis is not considered for showing data inside a hover marker.See also: Marker documentation
-
tickCallback
:KontrastCallback
A callback function that can be used to customize the placement and content of tick labels.
See also: Custom ticks
Range properties
These properties specify the minimum and maximum value (i.e. the lower and upper limit) of the axis.
-
min
:KontrastNumber
(default value:0
)The minimum value (i.e. the lower limit) of the axis.
-
max
:KontrastNumber
(default value:1
)The maximum value (i.e. the upper limit) of the axis.
Line appearance properties
These specify the properties of the line segment of the axis.
lineLength
is the length of the axis line. A value of 2
corresponds to the full length
(since relative coordinates
refer to a unit cube that ranges from
-1 to
1).
-
lineColor
:KontrastColor
(default value:'black'
) -
lineOpacity
:KontrastNumber
(default value:1
) -
lineThickness
:KontrastNumber
(default value:2
) -
lineLength
:KontrastNumber
(default value:2
)
Example: Appearance of Cartesian axes
Tick properties
These specify the appearance of ticks (short line segments on the axis) and labels (numbers) on the axis.
-
tickColor
:KontrastColor
(default value:'black'
) -
tickOpacity
:KontrastNumber
(default value:1
) -
tickLabelColor
:KontrastColor
(default value:'black'
) -
tickLabelOpacity
:KontrastNumber
(default value:1
)
The rotation of the tick labels can be controlled using the following two properties:
-
tickLabelRotation
:KontrastNumber
(default value:0
)The clockwise rotation angle of the tick labels (in radians).
-
tickLabelRotateRelativeToLine
:KontrastBoolean
(default value:false
)This boolean decides whether the rotation angle of the tick labels is measured relative to the axis line (
true
) or not (false
).
Cartesian axes
The available Cartesian axes cover the types
abscissa
(x),
ordinate
(y) and
applicate
(z).
Please refer to the tutorial for an example of 2D graphs and to the Example: 3D coordinate system for 3D graphs.
In addition to the common functions and properties (and events) of axis objects, these objects have the following properties.
Arrow properties
These properties specify the style of the arrow head of the axis.
-
arrowColor
:KontrastColor
(default value:'black'
) -
arrowOpacity
:KontrastNumber
(default value:1
) -
arrowThickness
:KontrastNumber
(default value:10
)
Grid properties
The following properties specify the style of the axis grid. You can set the grid opacity or the grid thickness to zero if you wish to hide/disable the grid. See also Example: Axis grid lines.
-
gridColor
:KontrastColor
(default value:'black'
) -
gridOpacity
:KontrastNumber
(default value:1
) -
gridThickness
:KontrastNumber
(default value:0.1
) -
gridRenderIndex
:KontrastNumber
(default value:-1
)
Positioning properties
Axes can be positioned using two types of properties: The
origin and the anchor. The origin describes a
coordinate within the relative coordinate system (from
-1 to
+1 in each dimension) of the
graph. The anchor describes a position within the axis (in the
relative coordinates of that object). For example,
xAnchor = -1
refers to the left side of the axis and
yAnchor = 1
refers to the top of the axis. The
coordinates (xAnchor, yAnchor) = (0, 0)
refer to the
center and (xAnchor, yAnchor) = (1, 1)
the top right
position of the axis.
Kontrast will place the axis in such a way that the specified origin and the anchor coincide.
-
xAnchor
:KontrastNumber
(default value:0
) -
yAnchor
:KontrastNumber
(default value:0
) -
zAnchor
:KontrastNumber
(default value:0
) -
xOrigin
:KontrastNumber
(default value:0
) -
yOrigin
:KontrastNumber
(default value:0
) -
zOrigin
:KontrastNumber
(default value:0
)
The following code means that the center of the ordinate is placed at the center of the graph.
The following code places the axes in a way that its lower position
(yAnchor = -1
, where the minimum number is shown) is
placed in the middle of the graph (yOrigin = 0
)
See also Example: Axis placement using origin and anchor.
The alignment of tick lines on a Cartesian axes can be determined using the following property:
-
tickAlignment
:KontrastNumber
(default value:0
)The alignment of the tick lines. Use a value of
1
for outside ticks,0
for centered ticks and-1
for inside ticks.
Color, opacity and thickness axes
These objects are used to visualize data as color, opacity and thickness, respectively.
A simple example how to specify the values is as follows:
In this example the points (0, 1), (1, 2) and (2, 3) have the values of 4, 5 and 6 for the color axis, respectively.
Properties
-
orientation
:KontrastSelection
(default value:'vertical'
, possible values:'vertical'
,'horizontal'
)The orientation of the axis.
-
horizontalOrigin
:KontrastNumber
(default value:0
)The horizontal (i.e. the x) origin of the axis line.
-
verticalOrigin
:KontrastNumber
(default value:0
)The vertical (i.e. the y) origin of the axis line.
-
horizontalAnchor
:KontrastNumber
(default value:0
)The horizontal (i.e. the x) anchor of the axis line.
-
verticalAnchor
:KontrastNumber
(default value:0
)The vertical (i.e. the y) anchor of the axis line.
-
zone
:KontrastSelection
(default value:'inside'
, possible values:'inside'
,'left'
,'right'
,'top'
,'bottom'
,'top-left'
,'top-right'
,'bottom-left'
,'bottom-right'
)The zone in which the axis is placed.
Color axis
In addition to the common functions and properties (and events) of axes-objects, this object has the following properties.
Properties
-
colorNaN
:KontrastColor
(default value:'blue'
) -
colorBelow
:KontrastColor
(default value:'black'
) -
color0
:KontrastColor
(default value:'black'
) -
color1
:KontrastColor
(default value:'white'
) -
color2
:KontrastColor
(default value:'black'
) -
color3
:KontrastColor
(default value:'black'
) -
color4
:KontrastColor
(default value:'black'
) -
colorAbove
:KontrastColor
(default value:'white'
) -
stop1
:KontrastNumber
(default value:1
) -
stop2
:KontrastNumber
(default value:1
) -
stop3
:KontrastNumber
(default value:1
)
These properties control the gradations of the axis. By default the
gradation from color0
to color1
is used. If
the data is less than min
or greater than
max
, the colors colorBelow
and
colorAbove
are used, respectively.
colorNaN
is a color for NaN
(not a number).
To make more detailed gradation, stop1
,
stop2
, stop3
and color0
, ...,
color4
are used.
stop1
, stop2
and stop3
specify
relative positions of the color axis (each from 0 to 1, in ascending
order). The colors color0
, ...,
color4
correspond to 0 (min
),
stop1
, stop2
, stop3
and 1
(max
) respectively.
If the value in a relative position of [0, stop1
] of the
axis, a gradient from color0
to color1
is
used. Similarly if the value in a relative position between
[stop1
, stop2
] of the axis, a gradient from
color1
to color2
is used.
Examples
- 3D coordinate system with color axis
- Appearance of color, opacity and thickness axes
- Color axis
- Tiles plot
- Volumetric cube plots
Opacity axis
In addition to the common functions and properties (and events) of axes-objects, this object has the following properties.
Properties
-
opacityBelow
:KontrastNumber
(default value:0
) -
opacityMin
:KontrastNumber
(default value:0
) -
opacityMax
:KontrastNumber
(default value:1
) -
opacityAbove
:KontrastNumber
(default value:1
)
All opacity properties accept values between (and including) 0 and 1. The value 0 means that the object is invisible and a value of 1 means that the object is fully visible (opaque).
The opacity of
opacityBelow
/ opacityAbove
is used, if the
value for the opacityAxis
is smaller / grater than
min
/ max
. opacityMin
and
opacityMax
are the opacity for the value of
min
and max
respectively.
Examples
- 3D coordinate system with opacity axis
- Animation
- Appearance of color, opacity and thickness axes
- Opacity axis
- Volumetric cube plots
Thickness axis
In addition to the common functions and properties (and events) of axes-objects, this object has the following properties.
Properties
-
thicknessBelow
:KontrastNumber
(default value:0
) -
thicknessMin
:KontrastNumber
(default value:0
) -
thicknessMax
:KontrastNumber
(default value:10
) -
thicknessAbove
:KontrastNumber
(default value:10
)
The thickness of
thicknessBelow
/ thicknessAbove
is used, if
the value for the thicknessAxis
is smaller / grater than
min
/ max
. thicknessMin
and
thicknessMax
are the thickness for the value of
min
and max
respectively.
Examples
- 3D coordinate system with thickness axis
- Appearance of color, opacity and thickness axes
- Thickness axis
Custom ticks
The tick callback function accepts a single parameter object with the
properties axis
, tickMap
and
tickSet
. The callback function is not expected to return
a value; any return value of the callback function is ignored.
The axis
is the axis object that initiates the callback.
The axis property is provided for convenience, as it might be useful
to request some state of the axis (e.g. the minimum and maximum
value).
The tickMap
is a JavaScript
Map
(a key-value data structure) that contains the default ticks. The keys
are the position of the tick. The values are objects with a mandatory
label
string property and an optional
importance
number property (which defaults to
0
). You can remove, change or add your own ticks by
adding, modifying or removing items from and to the tick map. The
label
string determines the displayed label of the tick.
In case of tick label overlaps, the tick with the larger
importance
is shown.
The position of grid lines is determined by the
gridSet
property, which is a JavaScript
Set. The values in the set are simply the positions of the grid lines.
In order to add or remove grid lines, you can add or remove items to
and from the set using the add(value)
and
delete(value)
methods (or the clear()
method
to delete all grid lines).