Line |
Branch |
Exec |
Source |
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" |
21 |
|
|
#include "util/Plot/Colormap.hpp" |
22 |
|
|
#include "util/Plot/PlotEventTooltip.hpp" |
23 |
|
|
#include "util/Container/ScrollingBuffer.hpp" |
24 |
|
|
|
25 |
|
|
namespace NAV |
26 |
|
|
{ |
27 |
|
|
|
28 |
|
|
/// @brief Specifying the look of a certain line in the plot |
29 |
|
|
struct PlotItemStyle |
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 |
43 |
|
|
LineType lineType = LineType::Line; |
44 |
|
|
/// Line Color |
45 |
|
|
ImVec4 color = IMPLOT_AUTO_COL; |
46 |
|
|
/// Colormap mask (pair: type and id) |
47 |
|
404 |
std::pair<ColormapMaskType, int64_t> colormapMask = { ColormapMaskType::None, -1 }; |
48 |
|
|
/// Index of the plot data to compare for the color |
49 |
|
|
size_t colormapMaskDataCmpIdx = 0; |
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 |
|
404 |
std::pair<ColormapMaskType, int64_t> markerColormapMask = { ColormapMaskType::None, -1 }; |
60 |
|
|
/// Index of the plot data to compare for the color |
61 |
|
|
size_t markerColormapMaskDataCmpIdx = 0; |
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 |
78 |
|
|
size_t errorBoundsDataIdx = 0; |
79 |
|
|
/// Alpha value for the error bounds |
80 |
|
|
float errorBoundsAlpha = 0.25F; |
81 |
|
|
/// Expression to modify the error bounds with |
82 |
|
|
std::string errorBoundsModifierExpression; |
83 |
|
|
/// Expression to modify the error bounds with (temporary GUI variable, till it is a valid expression) |
84 |
|
|
std::string errorBoundsModifierExpressionTemp; |
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 |
99 |
|
|
std::string eventTooltipFilterRegex; |
100 |
|
|
|
101 |
|
|
/// @brief Legend popup return type |
102 |
|
|
struct LegendPopupReturn |
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 |
157 |
|
|
void 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 |
161 |
|
|
void from_json(const json& j, PlotItemStyle& style); |
162 |
|
|
|
163 |
|
|
} // namespace NAV |
164 |
|
|
|