-
Notifications
You must be signed in to change notification settings - Fork 11
Line Chart
Displays sensor data as points connected by lines.
-
config
: Config – chart configuration object describing axes and signals-
Config:
-
yAxes
: Axis[] – an array of axis configuration objects, defaults to[{ visible: true }]
(one axis for all the data) -
signalSets
: SignalSet[] – an array of signal set specifications
-
-
Axis:
-
visible
: boolean – determines if the axis is visible, defaults tofalse
-
label
: string – a label to display next to the axis -
labelOffset
: number – offset of the axis label from the axis, defaults to40
-
includedMin
: number – a value that is always displayed on the axis. The real minimum of the axis can be lower if there are lower values in the data. -
belowMin
: number – free space below the data, specified as a multiple of the range of the data -
limitMin
: number – limit to the minimum of the axis, it can't be lower than this value even if there are smaller values in the data -
includedMax
: number – a value that is always displayed on the axis. The real maximum of the axis can be higher if there are higher values in the data. -
aboveMax
: number – free space above the data, specified as a multiple of the range of the data -
limitMax
: number – limit to the maximum of the axis, it can't be higher than this value even if there are higher values in the data
-
-
SignalSet:
-
cid
: string – the identifier of the signal set -
tsSigCid
: string – the identifier of the timestamp signal, defaults to"ts"
-
signals
: Signal[] – array of signal specifications
-
-
Signal:
-
cid
: string – the identifier of the signal in the signal set -
label
: string – signal label, the signal is only shown if not null TODO: check -
enabled
: boolean – the signal is shown iftrue
orundefined
-
axis
: number – index of an axis for the signal values, defaults to0
-
color
: d3-color.color – color of the line -
lineWidth
: number – width of the line
-
-
Config:
-
height
: number – the height of the chart in pixels, defaults to500
margin
: Margin-
withToolTip
: boolean – enables a tooltip displaying signal values, defaults totrue
-
toolTipExtraProps
: ToolTipProps – extra properties for the tooltip-
ToolTipExtraProps:
-
width
: number – determines the width of the tooltip box, defaults to350
-
-
ToolTipExtraProps:
-
withBrush
: boolean – enables selecting part of a chart to zoom in, defaults totrue
-
withZoom
: boolean – enables zoom -
zoomUpdateReloadInterval
: number – milliseconds after the last zoom event ends before new data are fetched; set tonull
to disable automatic updates of the data -
controlTimeIntervalChartWidth
: boolean – TODO, defaults totrue
-
lineVisibility
: function – determines whether lines and points are visible, defaults tolineWithoutPointsAndPointsOnNoAggregation()
- recommended values (can be imported from
ivis
package):lineWithoutPointsAndPointsOnNoAggregation()
,lineWithPointsOnHover()
,lineWithoutPoints()
,nolineWithPointsAlways()
- recommended values (can be imported from
-
contentComponent
: function – React component rendered on top of the chart, mutually exclusive withcontentRender
-
contentRender
: function – the returned value is rendered on top of the chart, mutually exclusive withcontentComponent
-
onClick
: function – TODO -
tooltipContentComponent
: function – React component rendered inside the tooltip, mutually exclusive withtooltipContentRender
-
tooltipContentRender
: function – the returned value is rendered inside the tooltip, mutually exclusive withtooltipContentComponent
-
getExtraQueries
: function – should return an array of extra queries to fetch data from the server (see ...draw extra data below) -
prepareExtraData
: function – processes the data from extra queries before they are saved into the state (see ...draw extra data below) -
getSvgDefs
: function – the function should return<defs>
SVG element which is placed inside the chart's SVG -
getGraphContent
: function – gets the SVG for the content of the chart (see ...draw marks in the chart area below) -
createChart
: function – draws the data to the prepared SVG (see ...draw marks in the chart area below) -
compareConfigs
: function – function to be used when comparing changes inconfig
property, called only if the default comparison function doesn't find any differences -
lineCurve
: function (d3-shape.curve*) – line interpolation between the data points, defaults tod3-shape.curveLinear
(straight line) -
lineWidth
: number – the width of lines in chart (used only if line width is not set in Signal config), defaults to1.5
Use the config.signalSets
property. You can also set the labels and colors of the signals there.
See the Linechart template example for an example of how this can be done using the panel parameters.
Set the config.yAxes
property. All the values are in the same units as the data. The minimum and maximum of the axis are computed as follows:
- The
min
is set to the smaller of the valuesincludedMin
(if specified) and the smallest value from the fetched data. Similarly, themax
is set to the higher of the valuesincludedMax
(if specified) and the highest value from the fetched data. - If
belowMin
is specified, themin
is set tomin - belowMin * (max - min)
. Similarly, ifaboveMax
is specified, themax
is set tomax + aboveMax * (max - min)
. - If
limitMin
is specified, themin
is clamped so it isn't smaller thanlimitMin
. Similarly, iflimitMax
is specified, the max is clamped so it isn't higher thanlimitMax
.
Set both the includedMin
and limitMin
(or includedMax
and aboveMax
) to the same value.
Prepare the axes in the config.yAxes
property (one item in the array for each axis – up to 4 axes can be rendered simultaneously). If you don't want to set the labels or limits of the axes, you can just put { visible: true }
(for each axis) there, the limits will be determined from the data.
When you specify the signals inside the config.signalSets
property, use the axis
field of Signal configuration to set the axis for the signal. This field is an index of the axis in the config.yAxes
array.
Use the withZoom
and withBrush
properties. They are enabled by default.
If zoom is enabled, the user can use the mouse wheel to zoom in and out. They can also drag the chart with the mouse to pan. Touchscreen controls (pinch zoom) are also available. When the visible region of the chart is changed, new data are fetched automatically after zoomUpdateReloadInterval
milliseconds. Set the zoomUpdateReloadInterval
to null
to disable this behaviour.
If brush is enabled, the user can draw a region with their mouse and the chart will zoom to that region. The CTRL key must be held down to enable this behaviour.
- The color of the lines can be set in the
color
property of the Signal. - The width of the lines can be set in the
lineWidth
property of the Signal or in thelineWidth
property of the chart (for all signals). - The interpolation of the lines between points (e.g. using a curve instead of straight line) can be set using the
lineCurve
property. See d3-shape Curves for list of available curves.
Use the tooltipContentComponent
or tooltipContentRender
properties. See the TooltipContent
class in TimeBasedChartBase.js
file for reference (that is the default tooltip).
-
If you need any
<defs>
in your SVG, specify them using thegetSvgDefs
property. The function should return the<defs>
SVG element. -
Use the
getGraphContent
property to prepare the SVG for your marks. When this function is called, the data and the axes of the chart are not prepared yet so you don't have access to them (that is done in thecreateChart
function, see step 3). This property is a function which gets theLineChart
and thepaths
(SVG prepared for the lines) as arguments and the returned value is rendered inside the chart area. If you modify this function, you should always return thepaths
, otherwise the rendering of the lines of theLineChart
will result in an exception. Example (the marks will be rendered behind the lines):const getGraphContent = (base, paths) => { return [ <g ref={node => base.marks = select(node)} key="marks" />, ...paths ]; };
-
The
createChart
function is called whenever the chart needs to be redrawn. Use it to draw the marks to the prepared SVG. ThecreateChart
function has the following arguments:-
base
: LineChart – theLineChart
object -
signalSetsData
: object (withcid
s ofconfig.signalSets
as keys) – the data returned from the server -
baseState
: object – thestate
of theLineChart
object -
abs
– the time interval currently visible in the chart -
xScale
– the scale to convert values along the x-axis (time) into pixels on screen -
yScales
– the scaleS to convert values along the y-axis into pixels on screen, one for each axis inconfig.yAxes
-
points
: object (withcid
s ofconfig.signalSets
as keys) – data representing the points on the chart
-
This is similar to the previous section with some additional steps:
-
To fetch the data, use the
getExtraQueries
property. The function gets theLineChart
object and the currently displayed time interval (abs
argument in thecreateChart
function) as its arguments and should return an array of queries (of shape { type, args }). The queries are then executed. -
To process the results of the queries, use the
prepareExtraData
property. This function gets theLineChart
object, the results from the standard ("timeSeries"
) queries and the results of the extra queries as its parameters. The results are then saved into theLineChart
's state, which can be then accessed as thebaseState
argument in thecreateChart
function.