TinyMaterialDesign
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
LineChart< RGB_T > Class Template Reference

Line chart with one or more series, a vertical value scale with round-numbered grid lines, optional reference lines, and an optional card frame with a title and a footer line. More...

#include <LineChart.h>

Inheritance diagram for LineChart< RGB_T >:
Inheritance graph
[legend]
Collaboration diagram for LineChart< RGB_T >:
Collaboration graph
[legend]

Public Types

using AxisFormatter = std::function< void(float value, char *buf, size_t len)>
 Formats a value of an axis label.
 

Public Member Functions

 LineChart ()=default
 
 LineChart (Bounds bounds, const char *title=nullptr)
 
void setTitle (const char *title)
 
void setFooter (const char *footer)
 One line of text below the plot, e.g. a summary of the values.
 
int addSeries (RGB_T color, uint8_t width=2)
 Adds a series and returns its index.
 
int seriesCount () const
 
void setSeriesLabel (int index, const char *label)
 
void setSeriesDashed (int index, bool dashed)
 Draw the series dashed.
 
ChartSeries< RGB_T > & series (int index)
 
void setValues (int index, const std::vector< float > &values)
 Replaces the values of the series index.
 
void setValues (int index, const float *values, size_t count)
 
void addValue (int index, float value, size_t maxPoints=0)
 
int addReferenceLine (float value, RGB_T color, bool dashed=true)
 Adds a horizontal reference line and returns its index.
 
void setReferenceLine (int index, float value)
 
void setYRange (float minValue, float maxValue)
 Fixes the value range of the Y axis.
 
void clearYRange ()
 Goes back to an automatic Y range.
 
void setGridCount (int count)
 Approximate number of grid lines of the automatic scale (default 4).
 
void setGridValues (const std::vector< float > &values)
 Uses exactly these grid values (labelled) instead of the automatic ones.
 
void setVisiblePoints (int count)
 
void setXAxis (float first, float last, int ticks=3, AxisFormatter format=nullptr)
 
void clearXAxis ()
 Removes the X axis labels.
 
void draw (tinygpu::ISurface< RGB_T > &target) override
 
- Public Member Functions inherited from Widget< RGB_T >
virtual ~Widget ()=default
 
virtual void setTheme (const MaterialTheme< RGB_T > &theme)
 
virtual void draw (tinygpu::ISurface< RGB_T > &target)=0
 
virtual bool onGesture (const tinygpu::GestureEvent &event)
 Handles one gesture event. Returns true if this widget consumed it.
 
virtual bool update (uint32_t nowMs)
 
virtual bool isDraggable () const
 
virtual bool isDraggableAt (int32_t x, int32_t y) const
 
virtual int childCount () const
 
virtual Widget< RGB_T > * child (int index)
 
virtual void drawBackground (tinygpu::ISurface< RGB_T > &target)
 
virtual void setThemeTint (RGB_T background, RGB_T foreground)
 
virtual bool isContainer () const
 Provides true if the widget is a container.
 

Public Attributes

bool card = true
 
- Public Attributes inherited from Widget< RGB_T >
Bounds bounds
 
bool visible = true
 
bool enabled = true
 

Additional Inherited Members

- Protected Member Functions inherited from Widget< RGB_T >
const MaterialTheme< RGB_T > & theme () const
 Convenience accessor for draw() overrides - see theme_.
 
- Protected Attributes inherited from Widget< RGB_T >
const MaterialTheme< RGB_T > * theme_ = nullptr
 

Detailed Description

template<typename RGB_T = TINYMD_DEFAULT_RGB_T>
class tinymd::LineChart< RGB_T >

Line chart with one or more series, a vertical value scale with round-numbered grid lines, optional reference lines, and an optional card frame with a title and a footer line.

LineChart<RGB565> chart(Bounds(8, 8, 224, 140), "Temperature"); int s = chart.addSeries(colorFromHex<RGB565>(0x06B6D4)); chart.addReferenceLine(25.0f, colorFromHex<RGB565>(0xF59E0B)); chart.setValues(s, readings); // std::vector<float> screen.invalidate(); // data changed outside a gesture

Y axis: automatic (the range of all visible values, snapped outward to a 1/2/5 x 10^n step - see setGridCount()) or fixed via setYRange(); the grid values can also be given explicitly via setGridValues().

X axis: by default the points of each series are stretched over the full plot width. setVisiblePoints(n) instead gives every point a fixed spacing of width / (n - 1) with the newest point at the right edge - a rolling "oscilloscope" trace that scrolls in from the right as points are added.

Series with more points than the plot has pixel columns are drawn as a min/max envelope per column, so peaks are never lost however many points there are. All drawing goes through clipped primitives, so the chart works inside a scrolling Container.

Member Typedef Documentation

◆ AxisFormatter

using AxisFormatter = std::function<void(float value, char* buf, size_t len)>

Formats a value of an axis label.

Constructor & Destructor Documentation

◆ LineChart() [1/2]

LineChart ( )
default

◆ LineChart() [2/2]

LineChart ( Bounds  bounds,
const char *  title = nullptr 
)
inlineexplicit

Member Function Documentation

◆ addReferenceLine()

int addReferenceLine ( float  value,
RGB_T  color,
bool  dashed = true 
)
inline

Adds a horizontal reference line and returns its index.

◆ addSeries()

int addSeries ( RGB_T  color,
uint8_t  width = 2 
)
inline

Adds a series and returns its index.

◆ addValue()

void addValue ( int  index,
float  value,
size_t  maxPoints = 0 
)
inline

Appends one value to the series index, dropping the oldest value once the series holds maxPoints values (0 = unlimited).

◆ clearXAxis()

void clearXAxis ( )
inline

Removes the X axis labels.

◆ clearYRange()

void clearYRange ( )
inline

Goes back to an automatic Y range.

◆ draw()

void draw ( tinygpu::ISurface< RGB_T > &  target)
inlineoverridevirtual

Renders the widget into target using colors/fonts/tokens from its own theme (see theme()/setTheme()).

Implements Widget< RGB_T >.

◆ series()

ChartSeries< RGB_T > & series ( int  index)
inline

◆ seriesCount()

int seriesCount ( ) const
inline

◆ setFooter()

void setFooter ( const char *  footer)
inline

One line of text below the plot, e.g. a summary of the values.

◆ setGridCount()

void setGridCount ( int  count)
inline

Approximate number of grid lines of the automatic scale (default 4).

◆ setGridValues()

void setGridValues ( const std::vector< float > &  values)
inline

Uses exactly these grid values (labelled) instead of the automatic ones.

◆ setReferenceLine()

void setReferenceLine ( int  index,
float  value 
)
inline

◆ setSeriesDashed()

void setSeriesDashed ( int  index,
bool  dashed 
)
inline

Draw the series dashed.

◆ setSeriesLabel()

void setSeriesLabel ( int  index,
const char *  label 
)
inline

Name of the series in the legend (drawn above the footer when at least one series has a label).

◆ setTitle()

void setTitle ( const char *  title)
inline

◆ setValues() [1/2]

void setValues ( int  index,
const float *  values,
size_t  count 
)
inline

◆ setValues() [2/2]

void setValues ( int  index,
const std::vector< float > &  values 
)
inline

Replaces the values of the series index.

◆ setVisiblePoints()

void setVisiblePoints ( int  count)
inline

Fixed spacing for count points with the newest at the right edge (see the class comment); 0 stretches all points over the width (default).

◆ setXAxis()

void setXAxis ( float  first,
float  last,
int  ticks = 3,
AxisFormatter  format = nullptr 
)
inline

Labels the X axis: the left edge of the plot is first, the right edge last, with ticks (>= 2) evenly spaced labels and tick marks including both edges. The values only label the axis - the points are still placed as described in the class comment. Example for a rolling minute: chart.setXAxis(-60, 0, 4, [](float v, char* b, size_t n) { snprintf(b, n, v == 0 ? "now" : "%.0fs", v); });

◆ setYRange()

void setYRange ( float  minValue,
float  maxValue 
)
inline

Fixes the value range of the Y axis.

Member Data Documentation

◆ card

bool card = true

Draws a rounded card behind the chart (default) - set to false to draw the chart directly on the screen background.


The documentation for this class was generated from the following file: