Added new graphing feature (#1358)

Co-authored-by: Synco Reynders <synco@deviceware.co.nz>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
synco 2021-09-20 19:30:36 +12:00 committed by GitHub
parent 83feee1c99
commit 33040afbb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 108 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

View File

@ -370,6 +370,114 @@ Configuration variables:
RGB displays use red, green, and blue, while grayscale displays may use white.
Graphs
******
You can display a graph of a sensor value(s) using this component. Examples:
.. figure:: images/graph_screen.png
:align: center
:width: 60.0%
.. figure:: images/graph_dualtrace.png
:align: center
:width: 60.0%
Graph component with options for grids, border and line-types.
.. code-block:: yaml
graph:
# Show bare-minimum auto-ranged graph
- id: single_temperature_graph
sensor: my_temperature
duration: 1h
width: 151
height: 51
# Show multi-trace graph
- id: multi_temperature_graph
duration: 1h
x_grid: 10min
y_grid: 1.0 # degC/div
width: 151
height: 51
traces:
- sensor: my_inside_temperature
line_type: DASHED
line_thickness: 2
color: my_red
- sensor: my_outside_temperature
line_type: SOLID
line_thickness: 3
color: my_blue
- sensor: my_beer_temperature
line_type: DOTTED
line_thickness: 2
color: my_green
Configuration variables:
- **id** (**Required**, :ref:`config-id`): The ID with which you will be able to reference the graph later
in your display code.
- **width** (**Required**, integer): The graph width in pixels
- **height** (**Required**, integer): The graph height in pixels
- **duration** (**Required**, seconds): The total graph history duration.
- **border** (*Optional*, boolean): Specifics if a border will be draw around the graph. Default is True.
- **x_grid** (*Optional*): Specifies the time per division. If not specified, no vertical grid will be drawn.
- **y_grid** (*Optional*, float): Specifics the number of units per division. If not specified, no horizontal grid will be drawn.
- **max_range** (*Optional*): Specifies the maximum Y-axis range.
- **min_range** (*Optional*): Specifies the minimum Y-axis range.
- **max_value** (*Optional*): Specifies the maximum Y-axis value.
- **min_value** (*Optional*): Specifies the minimum Y-axis value.
- **traces** (*Optional*): Use this to specify more than a single trace.
Trace specific fields:
- **sensor** (*Optional*, id): The sensor value to plot
- **line_thickness** (*Optional*): Defaults to 3
- **line_type** (*Optional*): Specifies the plot line-type. Can be one of the following: ``SOLID``, ``DOTTED``, ``DASHED``. Defaults to ``SOLID``.
- **color** (*Optional*): Sets the color of the sensor trace.
And then later in code:
.. code-block:: yaml
display:
- platform: ...
# ...
pages:
- id: page1
lambda: |-
// Draw the graph at position [x=10,y=20]
it.graph(10, 20, id(simple_temperature_graph));
- id: page2
lambda: |-
// Draw the graph at position [x=10,y=20]
it.graph(10, 20, id(multi_temperature_graph), my_yellow);
color:
- id: my_red
red: 100%
green: 0%
blue: 0%
- id: my_green
red: 0%
green: 100%
blue: 0%
- id: my_blue
red: 0%
green: 0%
blue: 100%
- id: my_yellow
red: 100%
green: 100%
blue: 0%
.. note::
Here are some things to note:
- Setting ``y_grid`` will expand any specified range to the nearest multiple of grid spacings.
- Axis labels are currently not possible without manually placing them.
- The grid and border color is set with it.graph(), while the traces are defined separately.
Images
******