跳转到主要内容

AbstractDataGraph

An abstract data graph.

Inherits from: Container, Drawable

Inherited by: AbstractDataGraphWithY

Public Classes

classGraphClickEvent
An object of this type is passed with each callback that is sent when the graph is clicked.
classGraphDragEvent
An object of this type is passed with each callback that is sent when the graph is dragged.

Public Functions

AbstractDataGraph(int16_t capacity)
Initializes a new instance of the AbstractDataGraph class.
voidaddBottomElement(AbstractGraphDecoration & d)
Adds an element to be shown in the area below the graph.
voidaddGraphElement(AbstractGraphElement & d)
Adds a graph element which will display the graph.
voidaddLeftElement(AbstractGraphDecoration & d)
Adds an element to be shown in the area to the left of the graph.
voidaddRightElement(AbstractGraphDecoration & d)
Adds an element to be shown in the area to the right of the graph.
voidaddTopElement(AbstractGraphDecoration & d)
Adds an element to be shown in the area above the graph.
virtual voidclear()
Clears the graph to its blank/initial state.
uint8_tgetAlpha() const
Gets the current alpha value of the widget.
int16_tgetGapBeforeIndex() const
Gets gap before index as set using setGapBeforeIndex().
int16_tgetGraphAreaHeight() const
Gets graph area height.
int16_tgetGraphAreaHeightIncludingPadding() const
Gets graph area height including padding (but not margin).
int16_tgetGraphAreaMarginBottom() const
Gets graph margin bottom.
int16_tgetGraphAreaMarginLeft() const
Gets graph margin left.
int16_tgetGraphAreaMarginRight() const
Gets graph margin right.
int16_tgetGraphAreaMarginTop() const
Gets graph margin top.
int16_tgetGraphAreaPaddingBottom() const
Gets graph area padding bottom.
int16_tgetGraphAreaPaddingLeft() const
Gets graph area padding left.
int16_tgetGraphAreaPaddingRight() const
Gets graph area padding right.
int16_tgetGraphAreaPaddingTop() const
Gets graph area padding top.
int16_tgetGraphAreaWidth() const
Gets graph area width.
int16_tgetGraphAreaWidthIncludingPadding() const
Gets graph area width including padding (but not margin).
virtual intgetGraphRangeXMax() const =0
Gets the maximum x coordinate for the graph.
virtual intgetGraphRangeXMin() const =0
Gets the minimum x coordinate for the graph.
virtual floatgetGraphRangeYMaxAsFloat() const =0
Gets maximum y coordinate for the graph.
virtual intgetGraphRangeYMaxAsInt() const =0
Gets maximum y coordinate for the graph.
virtual floatgetGraphRangeYMinAsFloat() const =0
Gets minimum y coordinate for the graph.
virtual intgetGraphRangeYMinAsInt() const =0
Gets minimum y coordinate for the graph.
int16_tgetMaxCapacity() const
Gets the capacity (max number of points) of the graph.
virtual boolgetNearestIndexForScreenX(int16_t x, int16_t & index) const
Gets graph index nearest to the given screen x coordinate.
virtual boolgetNearestIndexForScreenXY(int16_t x, int16_t y, int16_t & index)
Gets graph index nearest to the given screen position.
intgetScale() const
Gets the scaling factor previously set using setScale().
int16_tgetUsedCapacity() const
Gets the number of point used by the graph.
virtual voidhandleClickEvent(const ClickEvent & event)
Defines the event handler interface for ClickEvents.
virtual voidhandleDragEvent(const DragEvent & event)
Defines the event handler interface for DragEvents.
floatindexToDataPointXAsFloat(int16_t index) const
Get the data point x value for the given graph point index.
intindexToDataPointXAsInt(int16_t index) const
Get the data point x value for the given graph point index.
floatindexToDataPointYAsFloat(int16_t index) const
Get the data point y value for the given graph point index.
intindexToDataPointYAsInt(int16_t index) const
Get the data point y value for the given graph point index.
virtual int32_tindexToGlobalIndex(int16_t index) const
Convert an index to global index.
int16_tindexToScreenX(int16_t index) const
Get the screen x coordinate for the given graph point index.
int16_tindexToScreenY(int16_t index) const
Get the screen y coordinate for the given graph point index.
voidsetAlpha(uint8_t newAlpha)
Sets the opacity (alpha value).
voidsetClickAction(GenericCallback< const AbstractDataGraph &, const GraphClickEvent & > & callback)
Sets an action to be executed when the graph is clicked.
voidsetDragAction(GenericCallback< const AbstractDataGraph &, const GraphDragEvent & > & callback)
Sets an action to be executed when the graph is dragged.
voidsetGapBeforeIndex(int16_t index)
Makes gap before the specified index.
voidsetGraphAreaMargin(int16_t top, int16_t left, int16_t right, int16_t bottom)
Sets graph position inside the widget by reserving a margin around the graph.
voidsetGraphAreaPadding(int16_t top, int16_t left, int16_t right, int16_t bottom)
Adds some padding around the graph that will not be drawn in (apart from dots, boxes etc.
voidsetGraphRange(int xMin, int xMax, float yMin, float yMax)
Sets minimum and maximum x and y coordinate ranges for the graph.
voidsetGraphRange(int xMin, int xMax, int yMin, int yMax)
Sets minimum and maximum x and y coordinate ranges for the graph.
virtual voidsetGraphRangeX(int min, int max) =0
Sets minimum and maximum x coordinates for the graph.
virtual voidsetGraphRangeY(float min, float max) =0
Sets minimum and maximum y coordinates for the graph.
virtual voidsetGraphRangeY(int min, int max) =0
Sets minimum and maximum y coordinates for the graph.
virtual voidsetHeight(int16_t height)
Sets the height of this drawable.
virtual voidsetScale(int scale)
Sets a scaling factor to be multiplied on each added element.
virtual voidsetWidth(int16_t width)
Sets the width of this drawable.
intfloat2scaled(float f, int scale)
Multiply a floating point value with a constant and round the result.
intint2scaled(int i, int scale)
Multiply an integer value with a constant.
floatscaled2float(int i, int scale)
Divide a floating point number with a constant.
intscaled2int(int i, int scale)
Divide an integer with a constant and round the result.

Protected Functions

intconvertToGraphScale(int value, int scale) const
Converts a number with one scale to a number that has the same scale as the graph.
intfloat2scaled(float f) const
Same as float2scaled(float,int) using the graph's scale.
virtual intgetGraphRangeYMaxScaled() const =0
Gets maximum y coordinate for the graph.
virtual intgetGraphRangeYMinScaled() const =0
Gets minimum y coordinate for the graph.
virtual intgetXAxisOffsetScaled() const
Get x axis offset as a scaled value.
virtual intgetXAxisScaleScaled() const
Get x axis scale as a scaled value.
virtual intindexToDataPointXScaled(int16_t index) const =0
Same as indexToDataPointXAsInt(int16_t) except the returned value is left scaled.
virtual intindexToDataPointYScaled(int16_t index) const =0
Same as indexToDataPointYAsInt(int16_t) except the returned value is left scaled.
virtual CWRUtil::Q5indexToScreenXQ5(int16_t index) const =0
Gets screen x coordinate for a specific data point added to the graph.
virtual CWRUtil::Q5indexToScreenYQ5(int16_t index) const =0
Gets screen y coordinate for a specific data point added to the graph.
intint2scaled(int i) const
Same as int2scaled(int,int) using the graph's scale.
voidinvalidateAllXAxisPoints()
Invalidate all x axis points.
voidinvalidateGraphArea()
Invalidate entire graph area (the center of the graph).
voidinvalidateGraphPointAt(int16_t index)
Invalidate point at a given index.
voidinvalidateXAxisPointAt(int16_t index)
Invalidate x axis point at the given index.
floatscaled2float(int i) const
Same as scaled2float(int,int) using the graph's scale.
intscaled2int(int i) const
Same as scaled2int(int,int) using the graph's scale.
voidsetGraphRangeScaled(int xMin, int xMax, int yMin, int yMax)
Same as setGraphRange(int,int,int,int) except the passed arguments are assumed scaled.
virtual voidsetGraphRangeYScaled(int min, int max) =0
Same as setGraphRangeY(int,int) except the passed arguments are assumed scaled.
voidupdateAreasPosition()
Updates the position of all elements in all area after a change in size of the graph area and/or label padding.
virtual CWRUtil::Q5valueToScreenXQ5(int x) const =0
Gets screen x coordinate for an absolute value.
virtual CWRUtil::Q5valueToScreenYQ5(int y) const =0
Gets screen y coordinate for an absolute value.
virtual boolxScreenRangeToIndexRange(int16_t xLo, int16_t xHi, int16_t & indexLow, int16_t & indexHigh) const =0
Gets index range for screen x coordinate range taking the current graph range into account.

Protected Attributes

uint8_talpha
The alpha of the entire graph.
ContainerbottomArea
The area below the graph.
int16_tbottomPadding
The graph area bottom padding.
GenericCallback< const AbstractDataGraph &, const GraphClickEvent & > *clickAction
The callback to be executed when this Graph is clicked.
intdataScale
The data scale applied to all values.
GenericCallback< const AbstractDataGraph &, const GraphDragEvent & > *dragAction
The callback to be executed when this Graph is dragged.
int16_tgapBeforeIndex
The graph is disconnected (there is a gap) before this element index.
ContainergraphArea
The graph area (the center area)
ContainerleftArea
The area to the left of the graph.
int16_tleftPadding
The graph area left padding.
int16_tmaxCapacity
Maximum number of points in the graph.
ContainerrightArea
The area to the right of the graph.
int16_trightPadding
The graph area right padding.
ContainertopArea
The area above the graph.
int16_ttopPadding
The graph area top padding.
int16_tusedCapacity
The number of used points in the graph.

Additional inherited members

Public Functions inherited from Container

virtual voidadd(Drawable & d)
Adds a Drawable instance as child to this Container.
Container()
virtual boolcontains(const Drawable & d)
Query if a given Drawable has been added directly to this Container.
virtual voiddraw(const Rect & invalidatedArea) const
Draw this drawable.
virtual voidforEachChild(GenericCallback< Drawable & > * function)
Executes the specified callback function for each child in the Container.
virtual Drawable *getFirstChild()
Obtain a pointer to the first child of this container.
virtual voidgetLastChild(int16_t x, int16_t y, Drawable ** last)
Gets the last child in the list of children in this Container.
virtual RectgetSolidRect() const
Get (the largest possible) rectangle that is guaranteed to be solid (opaque).
virtual voidinsert(Drawable * previous, Drawable & d)
Inserts a Drawable after a specific child node.
virtual voidremove(Drawable & d)
Removes a Drawable from the container by removing it from the linked list of children.
virtual voidremoveAll()
Removes all children in the Container by resetting their parent and sibling pointers.
virtual voidunlink()
Removes all children by unlinking the first child.

Protected Functions inherited from Container

virtual RectgetContainedArea() const
Gets a rectangle describing the total area covered by the children of this container.
virtual voidmoveChildrenRelative(int16_t deltaX, int16_t deltaY)
Calls moveRelative on all children.

Protected Attributes inherited from Container

Drawable *firstChild
Pointer to the first child of this container. Subsequent children can be found through firstChild's nextSibling.

Public Functions inherited from Drawable

virtual voidchildGeometryChanged()
This function can be called on parent nodes to signal that the size or position of one or more of its children has changed.
virtual voiddraw(const Rect & invalidatedArea) const =0
Draw this drawable.
Drawable()
Initializes a new instance of the Drawable class.
voiddrawToDynamicBitmap(BitmapId id)
Render the Drawable object into a dynamic bitmap.
RectgetAbsoluteRect() const
Helper function for obtaining the rectangle this Drawable covers, expressed in absolute coordinates.
virtual Drawable *getFirstChild()
Function for obtaining the first child of this drawable if any.
int16_tgetHeight() const
Gets the height of this Drawable.
virtual voidgetLastChild(int16_t x, int16_t y, Drawable ** last) =0
Function for obtaining the the last child of this drawable that intersects with the specified point.
Drawable *getNextSibling()
Gets the next sibling node.
Drawable *getParent() const
Returns the parent node.
const Rect &getRect() const
Gets the rectangle this Drawable covers, in coordinates relative to its parent.
virtual RectgetSolidRect() const =0
Get (the largest possible) rectangle that is guaranteed to be solid (opaque).
virtual RectgetSolidRectAbsolute()
Helper function for obtaining the largest solid rect (as implemented by getSolidRect()) expressed in absolute coordinates.
virtual voidgetVisibleRect(Rect & rect) const
Function for finding the visible part of this drawable.
int16_tgetWidth() const
Gets the width of this Drawable.
int16_tgetX() const
Gets the x coordinate of this Drawable, relative to its parent.
int16_tgetY() const
Gets the y coordinate of this Drawable, relative to its parent.
virtual voidhandleGestureEvent(const GestureEvent & event)
Defines the event handler interface for GestureEvents.
virtual voidhandleTickEvent()
Called periodically by the framework if the Drawable instance has subscribed to timer ticks.
virtual voidinvalidate() const
Tell the framework that this entire Drawable needs to be redrawn.
virtual voidinvalidateRect(Rect & invalidatedArea) const
Request that a region of this drawable is redrawn.
boolisTouchable() const
Gets whether this Drawable receives touch events or not.
boolisVisible() const
Gets whether this Drawable is visible.
virtual voidmoveRelative(int16_t x, int16_t y)
Moves the drawable.
virtual voidmoveTo(int16_t x, int16_t y)
Moves the drawable.
voidsetPosition(const Drawable & drawable)
Sets the position of the Drawable to the same as the given Drawable.
voidsetPosition(int16_t x, int16_t y, int16_t width, int16_t height)
Sets the size and position of this Drawable, relative to its parent.
voidsetTouchable(bool touch)
Controls whether this Drawable receives touch events or not.
voidsetVisible(bool vis)
Controls whether this Drawable should be visible.
voidsetWidthHeight(const Bitmap & bitmap)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(const Drawable & drawable)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(const Rect & rect)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(int16_t width, int16_t height)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
virtual voidsetX(int16_t x)
Sets the x coordinate of this Drawable, relative to its parent.
voidsetXY(const Drawable & drawable)
Sets the x and y coordinates of this Drawable.
voidsetXY(int16_t x, int16_t y)
Sets the x and y coordinates of this Drawable, relative to its parent.
virtual voidsetY(int16_t y)
Sets the y coordinate of this Drawable, relative to its parent.
virtual voidtranslateRectToAbsolute(Rect & r) const
Helper function for converting a region of this Drawable to absolute coordinates.
virtual ~Drawable()
Finalizes an instance of the Drawable class.

Protected Attributes inherited from Drawable

Drawable *nextSibling
Pointer to the next Drawable.
Drawable *parent
Pointer to this drawable's parent.
Rectrect
The coordinates of this Drawable, relative to its parent.
booltouchable
True if this drawable should receive touch events.
boolvisible
True if this drawable should be drawn.

Public Functions Documentation

AbstractDataGraph

AbstractDataGraph(int16_tcapacity)

Initializes a new instance of the AbstractDataGraph class.

Parameters:
capacityThe capacity.

addBottomElement

Adds an element to be shown in the area below the graph.

Labels and titles can be added here.

Parameters:
See also:

addGraphElement

Adds a graph element which will display the graph.

Several graph elements can be added. Examples of graph elements are lines, dots, histograms as well as horizontal and vertical grid lines.

Parameters:
See also:

addLeftElement

Adds an element to be shown in the area to the left of the graph.

Labels and titles can be added here.

Parameters:
See also:

addRightElement

Adds an element to be shown in the area to the right of the graph.

Labels and titles can be added here.

Parameters:
See also:

addTopElement

Adds an element to be shown in the area above the graph.

Labels and titles can be added here.

Parameters:
See also:

clear

virtual void clear()

Clears the graph to its blank/initial state.

Reimplemented by: touchgfx::DataGraphScroll::clear, touchgfx::DataGraphWrapAndOverwrite::clear

getAlpha

uint8_t getAlpha()const

Gets the current alpha value of the widget.

The alpha value is in range 255 (solid) to 0 (invisible).

Returns:

The current alpha value.

See also:

getGapBeforeIndex

int16_t getGapBeforeIndex()const

Gets gap before index as set using setGapBeforeIndex().

Returns:

The gap before index.

See also:

getGraphAreaHeight

int16_t getGraphAreaHeight()const

Gets graph area height.

This is the height of the actual graph area and is the same as the height of the graph widget where graph area margin and graph area padding has been removed.

Returns:

The graph area height.

getGraphAreaHeightIncludingPadding

Gets graph area height including padding (but not margin).

This is the height of the actual graph area and is the same as the height of the graph widget where graph area margin has been removed.

Returns:

The graph area height including graph padding.

getGraphAreaMarginBottom

int16_t getGraphAreaMarginBottom()const

Gets graph margin bottom.

Returns:

The graph margin bottom.

See also:

getGraphAreaMarginLeft

int16_t getGraphAreaMarginLeft()const

Gets graph margin left.

Returns:

The graph margin left.

See also:

getGraphAreaMarginRight

int16_t getGraphAreaMarginRight()const

Gets graph margin right.

Returns:

The graph margin right.

See also:

getGraphAreaMarginTop

int16_t getGraphAreaMarginTop()const

Gets graph margin top.

Returns:

The graph margin top.

See also:

getGraphAreaPaddingBottom

Gets graph area padding bottom.

Returns:

The graph area padding bottom.

See also:

getGraphAreaPaddingLeft

int16_t getGraphAreaPaddingLeft()const

Gets graph area padding left.

Returns:

The graph area padding left.

See also:

getGraphAreaPaddingRight

int16_t getGraphAreaPaddingRight()const

Gets graph area padding right.

Returns:

The graph area padding right.

See also:

getGraphAreaPaddingTop

int16_t getGraphAreaPaddingTop()const

Gets graph area padding top.

Returns:

The graph areapadding top.

See also:

getGraphAreaWidth

int16_t getGraphAreaWidth()const

Gets graph area width.

This is the width of the actual graph area and is the same as the width of the graph widget where graph area margin and graph area padding has been removed.

Returns:

The graph area width.

getGraphAreaWidthIncludingPadding

Gets graph area width including padding (but not margin).

This is the width of the actual graph area and is the same as the width of the graph widget where graph area margin has been removed.

Returns:

The graph width including graph padding.

getGraphRangeXMax

virtual int getGraphRangeXMax()const =0

Gets the maximum x coordinate for the graph.

Returns:

The maximum x coordinate .

Reimplemented by: touchgfx::AbstractDataGraphWithY::getGraphRangeXMax

getGraphRangeXMin

virtual int getGraphRangeXMin()const =0

Gets the minimum x coordinate for the graph.

Returns:

The minimum x coordinate .

Reimplemented by: touchgfx::AbstractDataGraphWithY::getGraphRangeXMin

getGraphRangeYMaxAsFloat

virtual float getGraphRangeYMaxAsFloat()const =0

Gets maximum y coordinate for the graph.

Returns:

The maximum y coordinate.

Reimplemented by: touchgfx::AbstractDataGraphWithY::getGraphRangeYMaxAsFloat

getGraphRangeYMaxAsInt

virtual int getGraphRangeYMaxAsInt()const =0

Gets maximum y coordinate for the graph.

Returns:

The maximum y coordinate.

Reimplemented by: touchgfx::AbstractDataGraphWithY::getGraphRangeYMaxAsInt

getGraphRangeYMinAsFloat

virtual float getGraphRangeYMinAsFloat()const =0

Gets minimum y coordinate for the graph.

Returns:

The minimum y coordinate.

Reimplemented by: touchgfx::AbstractDataGraphWithY::getGraphRangeYMinAsFloat

getGraphRangeYMinAsInt

virtual int getGraphRangeYMinAsInt()const =0

Gets minimum y coordinate for the graph.

Returns:

The minimum y coordinate.

Reimplemented by: touchgfx::AbstractDataGraphWithY::getGraphRangeYMinAsInt

getMaxCapacity

int16_t getMaxCapacity()const

Gets the capacity (max number of points) of the graph.

Returns:

The capacity.

getNearestIndexForScreenX

virtual bool getNearestIndexForScreenX(int16_tx ,const
int16_t &indexconst
)const

Gets graph index nearest to the given screen x coordinate.

The index of the graph point closest to the given x coordinate is handed back.

Parameters:
xThe x coordinate.
indexZero-based index of the.
Returns:

True if it succeeds, false if it fails.

See also:

getNearestIndexForScreenXY

virtual bool getNearestIndexForScreenXY(int16_tx ,
int16_ty ,
int16_t &index
)

Gets graph index nearest to the given screen position.

The distance to each point on the graph is measured and the index of the point closest to the given position handed back.

Parameters:
xThe x coordinate.
yThe y coordinate.
indexZero-based index of the point closest to the given position.
Returns:

True if it succeeds, false if it fails.

See also:

getScale

int getScale()const

Gets the scaling factor previously set using setScale().

Returns:

The scaling factor.

See also:

getUsedCapacity

int16_t getUsedCapacity()const

Gets the number of point used by the graph.

Returns:

The number of point used by the graph.

handleClickEvent

virtual void handleClickEvent(const ClickEvent &event)

Defines the event handler interface for ClickEvents.

The default implementation ignores the event. The event is only received if the Drawable is touchable and visible.

Parameters:
eventThe ClickEvent received from the HAL.

Reimplements: touchgfx::Drawable::handleClickEvent

handleDragEvent

virtual void handleDragEvent(const DragEvent &event)

Defines the event handler interface for DragEvents.

The default implementation ignores the event. The event is only received if the drawable is touchable and visible.

Parameters:
eventThe DragEvent received from the HAL.

Reimplements: touchgfx::Drawable::handleDragEvent

indexToDataPointXAsFloat

float indexToDataPointXAsFloat(int16_tindex)

Get the data point x value for the given graph point index.

Parameters:
indexZero-based index of the point.
Returns:

The data point x value.

indexToDataPointXAsInt

int indexToDataPointXAsInt(int16_tindex)

Get the data point x value for the given graph point index.

Parameters:
indexZero-based index of the point.
Returns:

The data point x value.

indexToDataPointYAsFloat

float indexToDataPointYAsFloat(int16_tindex)

Get the data point y value for the given graph point index.

Parameters:
indexZero-based index of the point.
Returns:

The data point y value.

indexToDataPointYAsInt

int indexToDataPointYAsInt(int16_tindex)

Get the data point y value for the given graph point index.

Parameters:
indexZero-based index of the point.
Returns:

The data point y value.

indexToGlobalIndex

virtual int32_t indexToGlobalIndex(int16_tindex)

Convert an index to global index.

The index is the index of any data point, The global index is a value that keeps growing whenever a new data point is added the the graph.

Parameters:
indexZero-based index of the point.
Returns:

The global index.

Reimplemented by: touchgfx::DataGraphScroll::indexToGlobalIndex, touchgfx::DataGraphWrapAndClear::indexToGlobalIndex, touchgfx::DataGraphWrapAndOverwrite::indexToGlobalIndex

indexToScreenX

int16_t indexToScreenX(int16_tindex)

Get the screen x coordinate for the given graph point index.

Parameters:
indexZero-based index of the point.
Returns:

The screen x coordinate.

indexToScreenY

int16_t indexToScreenY(int16_tindex)

Get the screen y coordinate for the given graph point index.

Parameters:
indexZero-based index of the point.
Returns:

The screen x coordinate.

setAlpha

void setAlpha(uint8_tnewAlpha)

Sets the opacity (alpha value).

This can be used to fade it away by gradually decreasing the alpha value from 255 (solid) to 0 (invisible).

Parameters:
newAlphaThe new alpha value. 255=solid, 0=invisible.
Note

The user code must call invalidate() in order to update the display.All graph elements have to take this alpha into consideration.

See also:

setClickAction

Sets an action to be executed when the graph is clicked.

Parameters:
callbackThe callback.
See also:

setDragAction

void setDragAction(GenericCallback< const AbstractDataGraph &, const GraphDragEvent & > &callback)

Sets an action to be executed when the graph is dragged.

Parameters:
callbackThe callback.
See also:

setGapBeforeIndex

void setGapBeforeIndex(int16_tindex)

Makes gap before the specified index.

This can be used to split a graph in two, but for some graph types, e.g. histograms, this has no effect. Only one gap can be specified at a time. Specifying a new gap automatically removes the previous gap.

Parameters:
indexZero-based index where the gap should be placed.

setGraphAreaMargin

void setGraphAreaMargin(int16_ttop ,
int16_tleft ,
int16_tright ,
int16_tbottom
)

Sets graph position inside the widget by reserving a margin around the graph.

These areas to the left, the right, above and below are used for optional axis and titles.

Parameters:
topThe top margin in pixels.
leftThe left margin in pixels.
rightThe right margin in pixels.
bottomThe bottom margin in pixels.
Note

The graph is automatically invalidated when the graph margins are changed.

See also:

setGraphAreaPadding

void setGraphAreaPadding(int16_ttop ,
int16_tleft ,
int16_tright ,
int16_tbottom
)

Adds some padding around the graph that will not be drawn in (apart from dots, boxes etc.

that extend around the actual data point). The set padding will also work to make a gap between the graph and any labels that might have been added to the graph. To reserve an area that the graph will not be drawn in, use setGraphAreaMargin.

Parameters:
topThe top padding in pixels.
leftThe left padding in pixels.
rightThe right padding in pixels.
bottomThe bottom padding in pixels.
Note

The graph is automatically invalidated when the margins are set.

See also:

setGraphRange

void setGraphRange(intxMin ,
intxMax ,
floatyMin ,
floatyMax
)

Sets minimum and maximum x and y coordinate ranges for the graph.

This can be used to zoom in or out and only show parts of the graph.

Parameters:
xMinThe minimum x coordinate.
xMaxThe maximum x coordinate.
yMinThe minimum y coordinate.
yMaxThe maximum y coordinate.
See also:

setGraphRange

void setGraphRange(intxMin ,
intxMax ,
intyMin ,
intyMax
)

Sets minimum and maximum x and y coordinate ranges for the graph.

This can be used to zoom in or out and only show parts of the graph.

Parameters:
xMinThe minimum x coordinate.
xMaxThe maximum x coordinate.
yMinThe minimum y coordinate.
yMaxThe maximum y coordinate.
See also:

setGraphRangeX

virtual void setGraphRangeX(intmin ,=0
intmax=0
)=0

Sets minimum and maximum x coordinates for the graph.

This can be used to zoom in or out and only show parts of the graph.

Parameters:
minThe minimum x coordinate.
maxThe maximum x coordinate.
Note

The graph as well as the area above and below are automatically redrawn (invalidated).

Reimplemented by: touchgfx::AbstractDataGraphWithY::setGraphRangeX

setGraphRangeY

virtual void setGraphRangeY(floatmin ,=0
floatmax=0
)=0

Sets minimum and maximum y coordinates for the graph.

This can be used to zoom in or out and only show parts of the graph.

Parameters:
minThe minimum y coordinate.
maxThe maximum y coordinate.
Note

The graph as well as the area to the left and to the right of the graph are automatically redrawn (invalidated)

Reimplemented by: touchgfx::AbstractDataGraphWithY::setGraphRangeY

setGraphRangeY

virtual void setGraphRangeY(intmin ,=0
intmax=0
)=0

Sets minimum and maximum y coordinates for the graph.

This can be used to zoom in or out and only show parts of the graph.

Parameters:
minThe minimum y coordinate.
maxThe maximum y coordinate.
Note

The graph as well as the area to the left and to the right of the graph are automatically redrawn (invalidated)

Reimplemented by: touchgfx::AbstractDataGraphWithY::setGraphRangeY

setHeight

virtual void setHeight(int16_theight)

Sets the height of this drawable.

Parameters:
heightThe new height.
Note

For most Drawable widgets, changing this does normally not automatically yield a redraw.

Reimplements: touchgfx::Drawable::setHeight

setScale

virtual void setScale(intscale)

Sets a scaling factor to be multiplied on each added element.

Since the graph only stores integer values internally, it is possible to set a scale to e.g. 1000 and make the graph work as if there are three digits of precision. The addDataPoint() will multiply the argument with the scaling factor and store this value.

By setting the scale to 1 it is possible to simply use integer values for the graph.

Parameters:
scaleThe scaling factor.
Note

Calling setScale after adding points to the graph has undefined behaviour. The scale should be set as the first thing before other settings of the graph is being set.

See also:

Reimplemented by: touchgfx::AbstractDataGraphWithY::setScale

setWidth

virtual void setWidth(int16_twidth)

Sets the width of this drawable.

Parameters:
widthThe new width.
Note

For most Drawable widgets, changing this does normally not automatically yield a redraw.

Reimplements: touchgfx::Drawable::setWidth

float2scaled

static int float2scaled(floatf ,
intscale
)

Multiply a floating point value with a constant and round the result.

Parameters:
fthe value to scale.
scaleThe scale.
Returns:

The product of the two numbers, rounded to nearest integer value.

int2scaled

static int int2scaled(inti ,
intscale
)

Multiply an integer value with a constant.

Parameters:
ithe value to scale.
scaleThe scale.
Returns:

The product of the two numbers.

scaled2float

static float scaled2float(inti ,
intscale
)

Divide a floating point number with a constant.

Parameters:
iThe number to divide.
scaleThe divisor (scale).
Returns:

The number divided by the scale.

scaled2int

static int scaled2int(inti ,
intscale
)

Divide an integer with a constant and round the result.

Parameters:
iThe number to divide.
scaleThe divisor (scale).
Returns:

The number divided by the scale, rounded to nearest integer.

Protected Functions Documentation

convertToGraphScale

int convertToGraphScale(intvalue ,const
intscaleconst
)const

Converts a number with one scale to a number that has the same scale as the graph.

Parameters:
valueThe value to convert.
scaleThe scale.
Returns:

The given data converted to the graph scale.

Note

For internal use.

float2scaled

int float2scaled(floatf)

Same as float2scaled(float,int) using the graph's scale.

Parameters:
fThe floating point value to scale.
Returns:

The scaled value.

Note

For internal use.

getGraphRangeYMaxScaled

virtual int getGraphRangeYMaxScaled()const =0

Gets maximum y coordinate for the graph.

Returns:

The maximum y coordinate.

Note

The returned value is left scaled.For internal use.

See also:

Reimplemented by: touchgfx::AbstractDataGraphWithY::getGraphRangeYMaxScaled

getGraphRangeYMinScaled

virtual int getGraphRangeYMinScaled()const =0

Gets minimum y coordinate for the graph.

Returns:

The minimum y coordinate.

Note

The returned value is left scaled.For internal use.

See also:

Reimplemented by: touchgfx::AbstractDataGraphWithY::getGraphRangeYMinScaled

getXAxisOffsetScaled

virtual int getXAxisOffsetScaled()const

Get x axis offset as a scaled value.

Returns:

The x axis offset (left scaled).

Note

For internal use.

Reimplemented by: touchgfx::AbstractDataGraphWithY::getXAxisOffsetScaled

getXAxisScaleScaled

virtual int getXAxisScaleScaled()const

Get x axis scale as a scaled value.

Returns:

The x axis scale (left scaled).

Note

For internal use.

Reimplemented by: touchgfx::AbstractDataGraphWithY::getXAxisScaleScaled

indexToDataPointXScaled

virtual int indexToDataPointXScaled(int16_tindex)

Same as indexToDataPointXAsInt(int16_t) except the returned value is left scaled.

Parameters:
indexZero-based index of the data point.
Returns:

The data point x value scaled.

Note

For internal use.

See also:

Reimplemented by: touchgfx::AbstractDataGraphWithY::indexToDataPointXScaled

indexToDataPointYScaled

virtual int indexToDataPointYScaled(int16_tindex)

Same as indexToDataPointYAsInt(int16_t) except the returned value is left scaled.

Parameters:
indexZero-based index of the data point.
Returns:

The data point y value scaled.

Note

For internal use.

See also:

Reimplemented by: touchgfx::AbstractDataGraphWithY::indexToDataPointYScaled

indexToScreenXQ5

virtual CWRUtil::Q5 indexToScreenXQ5(int16_tindex)

Gets screen x coordinate for a specific data point added to the graph.

Parameters:
indexThe index of the element to get the x coordinate for.
Returns:

The screen x coordinate for the specific data point.

Reimplemented by: touchgfx::AbstractDataGraphWithY::indexToScreenXQ5

indexToScreenYQ5

virtual CWRUtil::Q5 indexToScreenYQ5(int16_tindex)

Gets screen y coordinate for a specific data point added to the graph.

Parameters:
indexThe index of the element to get the y coordinate for.
Returns:

The screen x coordinate for the specific data point.

Reimplemented by: touchgfx::AbstractDataGraphWithY::indexToScreenYQ5

int2scaled

int int2scaled(inti)

Same as int2scaled(int,int) using the graph's scale.

Parameters:
iThe integer value to scale.
Returns:

The scaled integer.

Note

For internal use.

invalidateAllXAxisPoints

Invalidate all x axis points.

Similar to invalidateXAxisPointAt, this function will iterate all visible x values and invalidate them in turn.

See also:

invalidateGraphArea

Invalidate entire graph area (the center of the graph).

This is often useful when a graph is cleared or the X or Y range is changed.

invalidateGraphPointAt

void invalidateGraphPointAt(int16_tindex)

Invalidate point at a given index.

This will call the function invalidateGraphPointAt() on every element added to the graphArea which in turn is responsible for invalidating the part of the screen occupied by its element.

Parameters:
indexZero-based index of the element to invalidate.

invalidateXAxisPointAt

void invalidateXAxisPointAt(int16_tindex)

Invalidate x axis point at the given index.

Since the y axis is often static, the x axis can change, and all labels need to be updated wihtout redrawing the entire graph.

Parameters:
indexThe x index to invalidate.
See also:

scaled2float

float scaled2float(inti)

Same as scaled2float(int,int) using the graph's scale.

Parameters:
iThe scaled value to convert to a floating point value.
Returns:

The unscaled value.

Note

For internal use.

scaled2int

int scaled2int(inti)

Same as scaled2int(int,int) using the graph's scale.

Parameters:
iThe scaled value to convert to an integer.
Returns:

The unscaled value.

Note

For internal use.

setGraphRangeScaled

void setGraphRangeScaled(intxMin ,
intxMax ,
intyMin ,
intyMax
)

Same as setGraphRange(int,int,int,int) except the passed arguments are assumed scaled.

Parameters:
xMinThe minimum x coordinate.
xMaxThe maximum x coordinate.
yMinThe minimum y coordinate.
yMaxThe maximum y coordinate.
Note

For internal use.

See also:

setGraphRangeYScaled

virtual void setGraphRangeYScaled(intmin ,=0
intmax=0
)=0

Same as setGraphRangeY(int,int) except the passed arguments are assumed scaled.

Parameters:
minThe minimum y coordinate.
maxThe maximum y coordinate.
Note

For internal use.

See also:

Reimplemented by: touchgfx::AbstractDataGraphWithY::setGraphRangeYScaled

updateAreasPosition

Updates the position of all elements in all area after a change in size of the graph area and/or label padding.

Note

The entire graph area is invalidated.

valueToScreenXQ5

virtual CWRUtil::Q5 valueToScreenXQ5(intx)

Gets screen x coordinate for an absolute value.

Parameters:
xThe x value.
Returns:

The screen x coordinate for the given value.

Reimplemented by: touchgfx::AbstractDataGraphWithY::valueToScreenXQ5

valueToScreenYQ5

virtual CWRUtil::Q5 valueToScreenYQ5(inty)

Gets screen y coordinate for an absolute value.

Parameters:
yThe y value.
Returns:

The screen y coordinate for the given value.

Reimplemented by: touchgfx::AbstractDataGraphWithY::valueToScreenYQ5

xScreenRangeToIndexRange

virtual bool xScreenRangeToIndexRange(int16_txLo ,const =0
int16_txHi ,const =0
int16_t &indexLow ,const =0
int16_t &indexHighconst =0
)const =0

Gets index range for screen x coordinate range taking the current graph range into account.

Parameters:
xLoThe low screen x coordinate.
xHiThe high screen x coordinate.
indexLowThe low element index.
indexHighThe high element index.
Returns:

True if the range from low index to high index is legal.

Note

For internal use.

Reimplemented by: touchgfx::AbstractDataGraphWithY::xScreenRangeToIndexRange

Protected Attributes Documentation

alpha

uint8_t alpha

The alpha of the entire graph.

bottomArea

Container bottomArea

The area below the graph.

bottomPadding

int16_t bottomPadding

The graph area bottom padding.

clickAction

GenericCallback< const AbstractDataGraph &, const GraphClickEvent & > * clickAction

The callback to be executed when this Graph is clicked.

dataScale

int dataScale

The data scale applied to all values.

dragAction

GenericCallback< const AbstractDataGraph &, const GraphDragEvent & > * dragAction

The callback to be executed when this Graph is dragged.

gapBeforeIndex

int16_t gapBeforeIndex

The graph is disconnected (there is a gap) before this element index.

graphArea

Container graphArea

The graph area (the center area)

leftArea

Container leftArea

The area to the left of the graph.

leftPadding

int16_t leftPadding

The graph area left padding.

maxCapacity

int16_t maxCapacity

Maximum number of points in the graph.

rightArea

Container rightArea

The area to the right of the graph.

rightPadding

int16_t rightPadding

The graph area right padding.

topArea

Container topArea

The area above the graph.

topPadding

int16_t topPadding

The graph area top padding.

usedCapacity

int16_t usedCapacity

The number of used points in the graph.