Phoenard
PHNLineGraph.h
Go to the documentation of this file.
1 /*
2 The MIT License (MIT)
3 
4 This file is part of the Phoenard Arduino library
5 Copyright (c) 2014 Phoenard
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25 
31 #include "PHNWidget.h"
32 
33 #ifndef _PHN_WIDGET_LINE_GRAPH_H_
34 #define _PHN_WIDGET_LINE_GRAPH_H_
35 
44 class PHN_LineGraph : public PHN_Widget {
45  public:
47  PHN_LineGraph() : _pos(0), autoClearDisabled(false) {}
49  void setLineCount(int nrLines);
51  const void setLineColor(unsigned char lineIdx, color_t color) { _lineColors.set(lineIdx, color); }
53  void setRange(float minimum, float maximum);
55  const color_t lineColor(unsigned char lineIdx) { return _lineColors.get(lineIdx); }
57  const unsigned int position(void) { return _pos; }
59  void addValues(const float* values);
61  void addValue(float value);
63  void setAutoClear(bool autoClear) { autoClearDisabled = !autoClear; }
65  void clear(void);
66  virtual void update(void);
67  virtual void draw(void);
68  private:
69  unsigned char _dim;
70  float _min, _max;
71  int _pos;
72  bool autoClearDisabled;
73  DataBuffer _lastValues;
74  PHN_Palette _lineColors;
75 };
76 
77 #endif
virtual void update(void)
Update function routine, where widget logic must be performed.
Definition: PHNLineGraph.cpp:102
const void setLineColor(unsigned char lineIdx, color_t color)
Sets the color of a line.
Definition: PHNLineGraph.h:51
A color Palette that can store up to 256 colors.
Definition: PHNPalette.h:43
virtual void draw(void)
Draw function routine, where widgets must perform drawing.
Definition: PHNLineGraph.cpp:105
Maintains data stored on the heap and frees it when the class is destructed.
Definition: DataBuffer.h:44
void addValue(float value)
Adds a new column of a line of values.
Definition: PHNLineGraph.cpp:43
void setLineCount(int nrLines)
Sets how many lines are displayed.
Definition: PHNLineGraph.cpp:28
PHN_LineGraph()
Initializes a new line graph widget.
Definition: PHNLineGraph.h:47
color_t get(int index) const
Gets a single color set at the index, BLACK if index out of range.
Definition: PHNPalette.cpp:36
void set(int index, color_t color)
Sets a single color at an index in the palette.
Definition: PHNPalette.cpp:40
Draws one or more line graphs.
Definition: PHNLineGraph.h:44
const color_t color(int colorId)
Gets a style color set for this widget.
Definition: PHNWidget.h:178
uint16_t color_t
Definition of the 16-bit 565 color type.
Definition: PHNDisplayHardware.h:97
A single widget which covers a rectangular area of the screen.
Definition: PHNWidget.h:145
void clear(void)
Clears the graph.
Definition: PHNLineGraph.cpp:38
void addValues(const float *values)
Adds a new column of values; values being a value for each line.
Definition: PHNLineGraph.cpp:49
const color_t lineColor(unsigned char lineIdx)
Gets the color set for a line.
Definition: PHNLineGraph.h:55
Holds the PHN_Widget and PHN_WidgetContainer classes used for managing widgets.
void setRange(float minimum, float maximum)
Sets the range of the values displayed.
Definition: PHNLineGraph.cpp:33
const unsigned int position(void)
Gets the current position in the graph being drawn.
Definition: PHNLineGraph.h:57
void setAutoClear(bool autoClear)
Sets whether the graph is automatically cleared every turn.
Definition: PHNLineGraph.h:63