0.4.1
Loading...
Searching...
No Matches
PlotItemStyle.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9/// @file PlotItemStyle.hpp
10/// @brief Specifying the look of a certain line in the plot
11/// @author T. Topp (topp@ins.uni-stuttgart.de)
12/// @date 2024-08-15
13
14#pragma once
15
16#include <string>
17#include <imgui.h>
18#include <implot.h>
19
20#include "util/Json.hpp"
24
25namespace NAV
26{
27
28/// @brief Specifying the look of a certain line in the plot
30{
31 /// @brief Possible line types
32 enum class LineType : uint8_t
33 {
34 Scatter, ///< Scatter plot (only markers)
35 Line, ///< Line plot
36 };
37
38 /// Display name in the legend (if not set falls back to PlotData::displayName)
39 std::string legendName;
40 /// Legend name which gets changed in the gui
41 std::string legendNameGui;
42 /// Line type
44 /// Line Color
45 ImVec4 color = IMPLOT_AUTO_COL;
46 /// Colormap mask (pair: type and id)
47 std::pair<ColormapMaskType, int64_t> colormapMask = { ColormapMaskType::None, -1 };
48 /// Index of the plot data to compare for the color
50 /// Line thickness
51 float thickness = 1.0F;
52 /// Line Flags (overrides the plot selection)
53 std::optional<ImPlotLineFlags> lineFlags;
54
55 /// Amount of points to skip for plotting
56 int stride = 0;
57
58 /// Colormap mask (pair: type and id)
59 std::pair<ColormapMaskType, int64_t> markerColormapMask = { ColormapMaskType::None, -1 };
60 /// Index of the plot data to compare for the color
62 /// Display markers for the line plot (no effect for scatter type)
63 bool markers = false;
64 /// Style of the marker to display
65 ImPlotMarker markerStyle = ImPlotMarker_Cross;
66 /// Size of the markers (makes the marker smaller/bigger)
67 float markerSize = 1.0F;
68 /// Weight of the markers (increases thickness of marker lines)
69 float markerWeight = 1.0F;
70 /// Fill color for markers
71 ImVec4 markerFillColor = IMPLOT_AUTO_COL;
72 /// Outline/Border color for markers
73 ImVec4 markerOutlineColor = IMPLOT_AUTO_COL;
74
75 /// Wether to plot the error bounds
76 bool errorBoundsEnabled = false;
77 /// Index of the plot data to use for error bounds
79 /// Alpha value for the error bounds
80 float errorBoundsAlpha = 0.25F;
81 /// Expression to modify the error bounds with
83 /// Expression to modify the error bounds with (temporary GUI variable, till it is a valid expression)
85
86 /// Show events on this data
87 bool eventsEnabled = false;
88 /// Style of the marker to display
89 ImPlotMarker eventMarkerStyle = ImPlotMarker_Cross;
90 /// Size of the markers (makes the marker smaller/bigger)
91 float eventMarkerSize = 6.0F;
92 /// Weight of the markers (increases thickness of marker lines)
93 float eventMarkerWeight = 2.0F;
94 /// Fill color for markers
95 ImVec4 eventMarkerFillColor = ImVec4(1.0, 0.0, 0.0, 1.0);
96 /// Outline/Border color for markers
97 ImVec4 eventMarkerOutlineColor = ImVec4(1.0, 0.0, 0.0, 1.0);
98 /// Tooltip search regex
100
101 /// @brief Legend popup return type
103 {
104 bool changed = false; ///< Some setting changed
105 bool errorBoundsReCalcNeeded = false; ///< Settings of the error bounds changed and needs to be recalculated
106 };
107
108 /// @brief Shows a legend popup for plot items
109 /// @param[in] id Unique id for the popup (should not change while open)
110 /// @param[in] displayTitle Display title
111 /// @param[in] plotDataBufferSize Buffer size of the data
112 /// @param[in] plotElementIdx Plot element index
113 /// @param[in] nameId Name and id of the calling node (logging)
114 /// @param[in] plotLineFlags LineFlags from a parent plot
115 /// @param[in, out] colormapMaskColors Buffer for the colormap mask of line plots
116 /// @param[in, out] markerColormapMaskColors Buffer for the colormap mask of the markers
117 /// @param[in] ShowDataReferenceChooser Function to call to show a Combo to select the data reference
118 /// @param[in, out] eventMarker Buffer for event markers
119 /// @param[in, out] eventTooltips List of tooltips (x,y, tooltip)
120 /// @return True if a change was made
121 LegendPopupReturn showLegendPopup(const char* id,
122 const char* displayTitle,
123 int plotDataBufferSize,
124 int plotElementIdx,
125 const char* nameId,
126 ImPlotLineFlags plotLineFlags = ImPlotLineFlags_NoClip | ImPlotLineFlags_SkipNaN,
127 ScrollingBuffer<ImU32>* colormapMaskColors = nullptr,
128 ScrollingBuffer<ImU32>* markerColormapMaskColors = nullptr,
129 const std::function<bool(size_t&, const char*)>& ShowDataReferenceChooser = nullptr,
130 ScrollingBuffer<double>* eventMarker = nullptr,
131 std::vector<std::tuple<double, double, PlotEventTooltip>>* eventTooltips = nullptr);
132
133 /// @brief Plots the data with the style
134 /// @param[in] plotName Plot name
135 /// @param[in] xData Data on the x axis
136 /// @param[in] yData Data on the y axis
137 /// @param[in] plotElementIdx Plot element index
138 /// @param[in] defaultStride Default stride size
139 /// @param[in] plotLineFlags LineFlags from a parent plot
140 /// @param[in] colormapMaskColors Buffer for the colormap mask of line plots
141 /// @param[in] markerColormapMaskColors Buffer for the colormap mask of the markers
142 /// @param[in] yErrorData Lower and upper data for error bounds
143 void plotData(const char* plotName,
144 const ScrollingBuffer<double>& xData,
145 const ScrollingBuffer<double>& yData,
146 int plotElementIdx,
147 int defaultStride = 1,
148 ImPlotLineFlags plotLineFlags = ImPlotLineFlags_NoClip | ImPlotLineFlags_SkipNaN,
149 ScrollingBuffer<ImU32>* colormapMaskColors = nullptr,
150 ScrollingBuffer<ImU32>* markerColormapMaskColors = nullptr,
151 const std::array<ScrollingBuffer<double>, 2>* yErrorData = nullptr) const;
152};
153
154/// @brief Write info to a json object
155/// @param[out] j Json output
156/// @param[in] style Object to read info from
157void to_json(json& j, const PlotItemStyle& style);
158/// @brief Read info from a json object
159/// @param[in] j Json variable to read info from
160/// @param[out] style Output object
161void from_json(const json& j, PlotItemStyle& style);
162
163} // namespace NAV
Colormap.
nlohmann::json json
json namespace
Defines how to save certain datatypes to json.
Tooltips for a plot events.
A buffer which is overwriting itself from the start when full.
A buffer which is overwriting itself from the start when full.
void to_json(json &j, const Node &node)
Converts the provided node into a json object.
Definition Node.cpp:990
@ None
Do not use a colormap mask.
Definition Colormap.hpp:119
void from_json(const json &j, Node &node)
Converts the provided json object into a node object.
Definition Node.cpp:1007
bool errorBoundsReCalcNeeded
Settings of the error bounds changed and needs to be recalculated.
Specifying the look of a certain line in the plot.
float eventMarkerSize
Size of the markers (makes the marker smaller/bigger)
float errorBoundsAlpha
Alpha value for the error bounds.
std::string legendNameGui
Legend name which gets changed in the gui.
float thickness
Line thickness.
ImVec4 eventMarkerFillColor
Fill color for markers.
bool eventsEnabled
Show events on this data.
void plotData(const char *plotName, const ScrollingBuffer< double > &xData, const ScrollingBuffer< double > &yData, int plotElementIdx, int defaultStride=1, ImPlotLineFlags plotLineFlags=ImPlotLineFlags_NoClip|ImPlotLineFlags_SkipNaN, ScrollingBuffer< ImU32 > *colormapMaskColors=nullptr, ScrollingBuffer< ImU32 > *markerColormapMaskColors=nullptr, const std::array< ScrollingBuffer< double >, 2 > *yErrorData=nullptr) const
Plots the data with the style.
std::string eventTooltipFilterRegex
Tooltip search regex.
ImVec4 color
Line Color.
ImPlotMarker markerStyle
Style of the marker to display.
float markerWeight
Weight of the markers (increases thickness of marker lines)
int stride
Amount of points to skip for plotting.
std::optional< ImPlotLineFlags > lineFlags
Line Flags (overrides the plot selection)
float markerSize
Size of the markers (makes the marker smaller/bigger)
LegendPopupReturn showLegendPopup(const char *id, const char *displayTitle, int plotDataBufferSize, int plotElementIdx, const char *nameId, ImPlotLineFlags plotLineFlags=ImPlotLineFlags_NoClip|ImPlotLineFlags_SkipNaN, ScrollingBuffer< ImU32 > *colormapMaskColors=nullptr, ScrollingBuffer< ImU32 > *markerColormapMaskColors=nullptr, const std::function< bool(size_t &, const char *)> &ShowDataReferenceChooser=nullptr, ScrollingBuffer< double > *eventMarker=nullptr, std::vector< std::tuple< double, double, PlotEventTooltip > > *eventTooltips=nullptr)
Shows a legend popup for plot items.
size_t markerColormapMaskDataCmpIdx
Index of the plot data to compare for the color.
std::string errorBoundsModifierExpression
Expression to modify the error bounds with.
ImVec4 eventMarkerOutlineColor
Outline/Border color for markers.
LineType
Possible line types.
@ Scatter
Scatter plot (only markers)
ImVec4 markerFillColor
Fill color for markers.
std::string errorBoundsModifierExpressionTemp
Expression to modify the error bounds with (temporary GUI variable, till it is a valid expression)
size_t errorBoundsDataIdx
Index of the plot data to use for error bounds.
float eventMarkerWeight
Weight of the markers (increases thickness of marker lines)
ImPlotMarker eventMarkerStyle
Style of the marker to display.
ImVec4 markerOutlineColor
Outline/Border color for markers.
bool errorBoundsEnabled
Wether to plot the error bounds.
size_t colormapMaskDataCmpIdx
Index of the plot data to compare for the color.
LineType lineType
Line type.
std::pair< ColormapMaskType, int64_t > markerColormapMask
Colormap mask (pair: type and id)
bool markers
Display markers for the line plot (no effect for scatter type)
std::string legendName
Display name in the legend (if not set falls back to PlotData::displayName)
std::pair< ColormapMaskType, int64_t > colormapMask
Colormap mask (pair: type and id)