mirror of
https://github.com/gwm17/implot.git
synced 2024-11-23 02:38:53 -05:00
double precision work complete
This commit is contained in:
parent
5e82afdbdd
commit
43625257b0
529
implot.cpp
529
implot.cpp
|
@ -20,7 +20,7 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// ImPlot v0.2 WIP
|
||||
// ImPlot v0.3 WIP
|
||||
|
||||
/*
|
||||
|
||||
|
@ -31,6 +31,7 @@ Below is a change-log of API breaking changes only. If you are using one of the
|
|||
When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all implot files.
|
||||
You can read releases logs https://github.com/epezent/implot/releases for more details.
|
||||
|
||||
- 2020/05/29 (0.3) - The signature of ImPlotLimits::Contains was changed to take two doubles instead of ImVec2
|
||||
- 2020/05/16 (0.2) - All plotting functions were reverted to being prefixed with "Plot" to maintain a consistent VerbNoun style. `Plot` was split into `PlotLine`
|
||||
and `PlotScatter` (however, `PlotLine` can still be used to plot scatter points as `Plot` did before.). `Bar` is not `PlotBars`, to indicate
|
||||
that multiple bars will be plotted.
|
||||
|
@ -78,6 +79,9 @@ You can read releases logs https://github.com/epezent/implot/releases for more d
|
|||
// The maximum number of support y-axes
|
||||
#define MAX_Y_AXES 3
|
||||
|
||||
// static inline float ImLog10(float x) { return log10f(x); }
|
||||
static inline double ImLog10(double x) { return log10(x); }
|
||||
|
||||
ImPlotStyle::ImPlotStyle() {
|
||||
LineWeight = 1;
|
||||
Marker = ImPlotMarker_None;
|
||||
|
@ -108,18 +112,18 @@ ImPlotRange::ImPlotRange() {
|
|||
Max = NAN;
|
||||
}
|
||||
|
||||
bool ImPlotRange::Contains(ImPlotFloat v) const {
|
||||
bool ImPlotRange::Contains(double v) const {
|
||||
return v >= Min && v <= Max;
|
||||
}
|
||||
|
||||
ImPlotFloat ImPlotRange::Size() const {
|
||||
double ImPlotRange::Size() const {
|
||||
return Max - Min;
|
||||
}
|
||||
|
||||
ImPlotLimits::ImPlotLimits() {}
|
||||
|
||||
bool ImPlotLimits::Contains(const ImVec2& p) const {
|
||||
return X.Contains(p.x) && Y.Contains(p.y);
|
||||
bool ImPlotLimits::Contains(double x, double y) const {
|
||||
return X.Contains(x) && Y.Contains(y);
|
||||
}
|
||||
|
||||
namespace ImPlot {
|
||||
|
@ -130,30 +134,6 @@ namespace {
|
|||
// Private Utils
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <typename F>
|
||||
struct FloatProps {
|
||||
static inline F Min();
|
||||
static inline F Max();
|
||||
static inline F Eps();
|
||||
static inline F Inf();
|
||||
};
|
||||
|
||||
template <>
|
||||
struct FloatProps<float> {
|
||||
static inline float Min() { return FLT_MIN; }
|
||||
static inline float Max() { return FLT_MAX; }
|
||||
static inline float Eps() { return FLT_EPSILON; }
|
||||
static inline float Inf() { return HUGE_VALF; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct FloatProps<double> {
|
||||
static inline double Min() { return DBL_MIN; }
|
||||
static inline double Max() { return DBL_MAX; }
|
||||
static inline double Eps() { return DBL_EPSILON; }
|
||||
static inline double Inf() { return HUGE_VAL; }
|
||||
};
|
||||
|
||||
/// Returns true if a flag is set
|
||||
template <typename TSet, typename TFlag>
|
||||
inline bool HasFlag(TSet set, TFlag flag) {
|
||||
|
@ -172,23 +152,23 @@ inline float Remap(float x, float x0, float x1, float y0, float y1) {
|
|||
}
|
||||
|
||||
/// Turns NANs to 0s
|
||||
inline ImPlotFloat ConstrainNan(ImPlotFloat val) {
|
||||
inline double ConstrainNan(double val) {
|
||||
return isnan(val) ? 0 : val;
|
||||
}
|
||||
|
||||
/// Turns infinity to floating point maximums
|
||||
inline ImPlotFloat ConstrainInf(ImPlotFloat val) {
|
||||
return val == FloatProps<ImPlotFloat>::Inf() ? FloatProps<ImPlotFloat>::Max() : val == -FloatProps<ImPlotFloat>::Inf() ? - FloatProps<ImPlotFloat>::Max() : val;
|
||||
inline double ConstrainInf(double val) {
|
||||
return val == HUGE_VAL ? DBL_MAX : val == -HUGE_VAL ? - DBL_MAX : val;
|
||||
}
|
||||
|
||||
/// Turns numbers less than or equal to 0 to 0.001 (sort of arbitrary, is there a better way?)
|
||||
inline ImPlotFloat ConstrainLog(ImPlotFloat val) {
|
||||
inline double ConstrainLog(double val) {
|
||||
return val <= 0 ? 0.001f : val;
|
||||
}
|
||||
|
||||
/// Returns true if val is NAN or INFINITY
|
||||
inline bool NanOrInf(ImPlotFloat val) {
|
||||
return val == FloatProps<ImPlotFloat>::Inf() || val == -FloatProps<ImPlotFloat>::Inf() || isnan(val);
|
||||
inline bool NanOrInf(double val) {
|
||||
return val == HUGE_VAL || val == -HUGE_VAL || isnan(val);
|
||||
}
|
||||
|
||||
/// Utility function to that rounds x to powers of 2,5 and 10 for generating axis labels
|
||||
|
@ -196,7 +176,7 @@ inline bool NanOrInf(ImPlotFloat val) {
|
|||
inline double NiceNum(double x, bool round) {
|
||||
double f; /* fractional part of x */
|
||||
double nf; /* nice, rounded fraction */
|
||||
int expv = (int)floor(log10(x));
|
||||
int expv = (int)floor(ImLog10(x));
|
||||
f = x / ImPow(10.0, (double)expv); /* between 1 and 10 */
|
||||
if (round)
|
||||
if (f < 1.5)
|
||||
|
@ -260,12 +240,12 @@ ImVec4 NextColor();
|
|||
|
||||
/// Tick mark info
|
||||
struct ImTick {
|
||||
ImTick(ImPlotFloat value, bool major, bool render_label = true) {
|
||||
ImTick(double value, bool major, bool render_label = true) {
|
||||
PlotPos = value;
|
||||
Major = major;
|
||||
RenderLabel = render_label;
|
||||
}
|
||||
ImPlotFloat PlotPos;
|
||||
double PlotPos;
|
||||
float PixelPos;
|
||||
ImVec2 Size;
|
||||
int TextOffset;
|
||||
|
@ -380,11 +360,11 @@ struct ImPlotContext {
|
|||
// Transformation cache
|
||||
ImRect PixelRange[MAX_Y_AXES];
|
||||
// linear scale (slope)
|
||||
ImPlotFloat Mx;
|
||||
ImPlotFloat My[MAX_Y_AXES];
|
||||
double Mx;
|
||||
double My[MAX_Y_AXES];
|
||||
// log scale denominator
|
||||
ImPlotFloat LogDenX;
|
||||
ImPlotFloat LogDenY[MAX_Y_AXES];
|
||||
double LogDenX;
|
||||
double LogDenY[MAX_Y_AXES];
|
||||
// Data extents
|
||||
ImPlotRange ExtentsX;
|
||||
ImPlotRange ExtentsY[MAX_Y_AXES];
|
||||
|
@ -451,9 +431,9 @@ inline void UpdateTransformCache() {
|
|||
|
||||
gp.My[i] = (gp.PixelRange[i].Max.y - gp.PixelRange[i].Min.y) / gp.CurrentPlot->YAxis[i].Range.Size();
|
||||
}
|
||||
gp.LogDenX = log10(gp.CurrentPlot->XAxis.Range.Max / gp.CurrentPlot->XAxis.Range.Min);
|
||||
gp.LogDenX = ImLog10(gp.CurrentPlot->XAxis.Range.Max / gp.CurrentPlot->XAxis.Range.Min);
|
||||
for (int i = 0; i < MAX_Y_AXES; i++) {
|
||||
gp.LogDenY[i] = log10(gp.CurrentPlot->YAxis[i].Range.Max / gp.CurrentPlot->YAxis[i].Range.Min);
|
||||
gp.LogDenY[i] = ImLog10(gp.CurrentPlot->YAxis[i].Range.Max / gp.CurrentPlot->YAxis[i].Range.Min);
|
||||
}
|
||||
gp.Mx = (gp.PixelRange[0].Max.x - gp.PixelRange[0].Min.x) / gp.CurrentPlot->XAxis.Range.Size();
|
||||
}
|
||||
|
@ -465,12 +445,12 @@ inline ImPlotPoint PixelsToPlot(float x, float y, int y_axis_in = -1) {
|
|||
plt.x = (x - gp.PixelRange[y_axis].Min.x) / gp.Mx + gp.CurrentPlot->XAxis.Range.Min;
|
||||
plt.y = (y - gp.PixelRange[y_axis].Min.y) / gp.My[y_axis] + gp.CurrentPlot->YAxis[y_axis].Range.Min;
|
||||
if (HasFlag(gp.CurrentPlot->XAxis.Flags, ImPlotAxisFlags_LogScale)) {
|
||||
ImPlotFloat t = (plt.x - gp.CurrentPlot->XAxis.Range.Min) / gp.CurrentPlot->XAxis.Range.Size();
|
||||
plt.x = pow(10.0f, t * gp.LogDenX) * gp.CurrentPlot->XAxis.Range.Min;
|
||||
double t = (plt.x - gp.CurrentPlot->XAxis.Range.Min) / gp.CurrentPlot->XAxis.Range.Size();
|
||||
plt.x = ImPow(10, t * gp.LogDenX) * gp.CurrentPlot->XAxis.Range.Min;
|
||||
}
|
||||
if (HasFlag(gp.CurrentPlot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) {
|
||||
ImPlotFloat t = (plt.y - gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.CurrentPlot->YAxis[y_axis].Range.Size();
|
||||
plt.y = pow(10.0f, t * gp.LogDenY[y_axis]) * gp.CurrentPlot->YAxis[y_axis].Range.Min;
|
||||
double t = (plt.y - gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.CurrentPlot->YAxis[y_axis].Range.Size();
|
||||
plt.y = ImPow(10, t * gp.LogDenY[y_axis]) * gp.CurrentPlot->YAxis[y_axis].Range.Min;
|
||||
}
|
||||
return plt;
|
||||
}
|
||||
|
@ -480,16 +460,16 @@ ImPlotPoint PixelsToPlot(const ImVec2& pix, int y_axis) {
|
|||
}
|
||||
|
||||
// This function is convenient but should not be used to process a high volume of points. Use the Transformer structs below instead.
|
||||
inline ImVec2 PlotToPixels(ImPlotFloat x, ImPlotFloat y, int y_axis_in = -1) {
|
||||
inline ImVec2 PlotToPixels(double x, double y, int y_axis_in = -1) {
|
||||
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PlotToPixels() Needs to be called between BeginPlot() and EndPlot()!");
|
||||
const int y_axis = y_axis_in >= 0 ? y_axis_in : gp.CurrentPlot->CurrentYAxis;
|
||||
ImVec2 pix;
|
||||
if (HasFlag(gp.CurrentPlot->XAxis.Flags, ImPlotAxisFlags_LogScale)) {
|
||||
ImPlotFloat t = log10(x / gp.CurrentPlot->XAxis.Range.Min) / gp.LogDenX;
|
||||
double t = ImLog10(x / gp.CurrentPlot->XAxis.Range.Min) / gp.LogDenX;
|
||||
x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, (float)t);
|
||||
}
|
||||
if (HasFlag(gp.CurrentPlot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) {
|
||||
ImPlotFloat t = log10(y / gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.LogDenY[y_axis];
|
||||
double t = ImLog10(y / gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.LogDenY[y_axis];
|
||||
y = ImLerp(gp.CurrentPlot->YAxis[y_axis].Range.Min, gp.CurrentPlot->YAxis[y_axis].Range.Max, (float)t);
|
||||
}
|
||||
pix.x = (float)(gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min));
|
||||
|
@ -502,13 +482,13 @@ ImVec2 PlotToPixels(const ImPlotPoint& plt, int y_axis) {
|
|||
return PlotToPixels(plt.x, plt.y, y_axis);
|
||||
}
|
||||
|
||||
// Transformer structs
|
||||
// Transformer functors
|
||||
|
||||
struct TransformerLinLin {
|
||||
TransformerLinLin(int y_axis_in) : y_axis(y_axis_in) {}
|
||||
|
||||
inline ImVec2 operator()(const ImPlotPoint& plt) { return (*this)(plt.x, plt.y); }
|
||||
inline ImVec2 operator()(ImPlotFloat x, ImPlotFloat y) {
|
||||
inline ImVec2 operator()(double x, double y) {
|
||||
return ImVec2( (float)(gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min)),
|
||||
(float)(gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min)) );
|
||||
}
|
||||
|
@ -520,8 +500,8 @@ struct TransformerLogLin {
|
|||
TransformerLogLin(int y_axis_in) : y_axis(y_axis_in) {}
|
||||
|
||||
inline ImVec2 operator()(const ImPlotPoint& plt) { return (*this)(plt.x, plt.y); }
|
||||
inline ImVec2 operator()(ImPlotFloat x, ImPlotFloat y) {
|
||||
ImPlotFloat t = log10(x / gp.CurrentPlot->XAxis.Range.Min) / gp.LogDenX;
|
||||
inline ImVec2 operator()(double x, double y) {
|
||||
double t = ImLog10(x / gp.CurrentPlot->XAxis.Range.Min) / gp.LogDenX;
|
||||
x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, (float)t);
|
||||
return ImVec2( (float)(gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min)),
|
||||
(float)(gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min)) );
|
||||
|
@ -534,9 +514,9 @@ struct TransformerLinLog {
|
|||
TransformerLinLog(int y_axis_in) : y_axis(y_axis_in) {}
|
||||
|
||||
inline ImVec2 operator()(const ImPlotPoint& plt) { return (*this)(plt.x, plt.y); }
|
||||
inline ImVec2 operator()(ImPlotFloat x, ImPlotFloat y) {
|
||||
ImPlotFloat t = log10(y / gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.LogDenY[y_axis];
|
||||
y = ImLerp(gp.CurrentPlot->YAxis[y_axis].Range.Min, gp.CurrentPlot->YAxis[y_axis].Range.Max, (float)t);
|
||||
inline ImVec2 operator()(double x, double y) {
|
||||
double t = ImLog10(y / gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.LogDenY[y_axis];
|
||||
y = ImLerp(gp.CurrentPlot->YAxis[y_axis].Range.Min, gp.CurrentPlot->YAxis[y_axis].Range.Max, (float)t);
|
||||
return ImVec2( (float)(gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min)),
|
||||
(float)(gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min)) );
|
||||
}
|
||||
|
@ -549,11 +529,11 @@ struct TransformerLogLog {
|
|||
}
|
||||
|
||||
inline ImVec2 operator()(const ImPlotPoint& plt) { return (*this)(plt.x, plt.y); }
|
||||
inline ImVec2 operator()(ImPlotFloat x, ImPlotFloat y) {
|
||||
ImPlotFloat t = log10(x / gp.CurrentPlot->XAxis.Range.Min) / gp.LogDenX;
|
||||
x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, (float)t);
|
||||
t = log10(y / gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.LogDenY[y_axis];
|
||||
y = ImLerp(gp.CurrentPlot->YAxis[y_axis].Range.Min, gp.CurrentPlot->YAxis[y_axis].Range.Max, (float)t);
|
||||
inline ImVec2 operator()(double x, double y) {
|
||||
double t = ImLog10(x / gp.CurrentPlot->XAxis.Range.Min) / gp.LogDenX;
|
||||
x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, (float)t);
|
||||
t = ImLog10(y / gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.LogDenY[y_axis];
|
||||
y = ImLerp(gp.CurrentPlot->YAxis[y_axis].Range.Min, gp.CurrentPlot->YAxis[y_axis].Range.Max, (float)t);
|
||||
return ImVec2( (float)(gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min)),
|
||||
(float)(gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min)) );
|
||||
}
|
||||
|
@ -601,17 +581,17 @@ inline void GetTicks(const ImPlotRange& range, int nMajor, int nMinor, bool logs
|
|||
if (logscale) {
|
||||
if (range.Min <= 0 || range.Max <= 0)
|
||||
return;
|
||||
int exp_min = (int)log10(range.Min);
|
||||
int exp_max = (int)(ceil(log10(range.Max)));
|
||||
int exp_min = (int)ImLog10(range.Min);
|
||||
int exp_max = (int)(ceil(ImLog10(range.Max)));
|
||||
for (int e = exp_min - 1; e < exp_max + 1; ++e) {
|
||||
double major1 = ImPow(10, (double)(e));
|
||||
double major2 = ImPow(10, (double)(e + 1));
|
||||
double interval = (major2 - major1) / 9;
|
||||
if (major1 >= (range.Min - FloatProps<ImPlotFloat>::Eps()) && major1 <= (range.Max + FloatProps<ImPlotFloat>::Eps()))
|
||||
if (major1 >= (range.Min - DBL_EPSILON) && major1 <= (range.Max + DBL_EPSILON))
|
||||
out.push_back(ImTick(major1, true));
|
||||
for (int i = 1; i < 9; ++i) {
|
||||
double minor = major1 + i * interval;
|
||||
if (minor >= (range.Min - FloatProps<ImPlotFloat>::Eps()) && minor <= (range.Max + FloatProps<ImPlotFloat>::Eps()))
|
||||
if (minor >= (range.Min - DBL_EPSILON) && minor <= (range.Max + DBL_EPSILON))
|
||||
out.push_back(ImTick(minor, false, false));
|
||||
}
|
||||
}
|
||||
|
@ -844,10 +824,10 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
|||
}
|
||||
|
||||
if (plot.XAxis.Range.Max <= plot.XAxis.Range.Min)
|
||||
plot.XAxis.Range.Max = plot.XAxis.Range.Min + FloatProps<ImPlotFloat>::Eps();
|
||||
plot.XAxis.Range.Max = plot.XAxis.Range.Min + DBL_EPSILON;
|
||||
for (int i = 0; i < MAX_Y_AXES; i++) {
|
||||
if (plot.YAxis[i].Range.Max <= plot.YAxis[i].Range.Min)
|
||||
plot.YAxis[i].Range.Max = plot.YAxis[i].Range.Min + FloatProps<ImPlotFloat>::Eps();
|
||||
plot.YAxis[i].Range.Max = plot.YAxis[i].Range.Min + DBL_EPSILON;
|
||||
}
|
||||
|
||||
// adaptive divisions
|
||||
|
@ -1322,11 +1302,11 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
|||
// reset items count
|
||||
gp.VisibleItemCount = 0;
|
||||
// reset extents
|
||||
gp.ExtentsX.Min = FloatProps<ImPlotFloat>::Inf();
|
||||
gp.ExtentsX.Max = -FloatProps<ImPlotFloat>::Inf();
|
||||
gp.ExtentsX.Min = HUGE_VAL;
|
||||
gp.ExtentsX.Max = -HUGE_VAL;
|
||||
for (int i = 0; i < MAX_Y_AXES; i++) {
|
||||
gp.ExtentsY[i].Min = FloatProps<ImPlotFloat>::Inf();
|
||||
gp.ExtentsY[i].Max = -FloatProps<ImPlotFloat>::Inf();
|
||||
gp.ExtentsY[i].Min = HUGE_VAL;
|
||||
gp.ExtentsY[i].Max = -HUGE_VAL;
|
||||
}
|
||||
// clear item names
|
||||
gp.LegendLabels.Buf.resize(0);
|
||||
|
@ -1341,17 +1321,17 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <typename F>
|
||||
bool DragImPlotFloat(const char* label, F* v, float v_speed, F v_min, F v_max) {
|
||||
bool Dragdouble(const char* label, F* v, float v_speed, F v_min, F v_max) {
|
||||
return false;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool DragImPlotFloat<double>(const char* label, double* v, float v_speed, double v_min, double v_max) {
|
||||
bool Dragdouble<double>(const char* label, double* v, float v_speed, double v_min, double v_max) {
|
||||
return ImGui::DragScalar(label, ImGuiDataType_Double, v, v_speed, &v_min, &v_max, "%.3f", 1);
|
||||
}
|
||||
|
||||
template <>
|
||||
bool DragImPlotFloat<float>(const char* label, float* v, float v_speed, float v_min, float v_max) {
|
||||
bool Dragdouble<float>(const char* label, float* v, float v_speed, float v_min, float v_max) {
|
||||
return ImGui::DragScalar(label, ImGuiDataType_Float, v, v_speed, &v_min, &v_max, "%.3f", 1);
|
||||
}
|
||||
|
||||
|
@ -1371,7 +1351,7 @@ inline void AxisMenu(ImPlotAxis& Axis) {
|
|||
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.25f);
|
||||
}
|
||||
DragImPlotFloat("Min", &Axis.Range.Min, 0.01f + 0.01f * (float)Axis.Range.Size(), -FloatProps<ImPlotFloat>::Inf(), Axis.Range.Max - FloatProps<ImPlotFloat>::Eps());
|
||||
Dragdouble("Min", &Axis.Range.Min, 0.01f + 0.01f * (float)Axis.Range.Size(), -HUGE_VAL, Axis.Range.Max - DBL_EPSILON);
|
||||
if (lock_min) {
|
||||
ImGui::PopItemFlag();
|
||||
ImGui::PopStyleVar(); }
|
||||
|
@ -1382,7 +1362,7 @@ inline void AxisMenu(ImPlotAxis& Axis) {
|
|||
if (lock_max) {
|
||||
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.25f); }
|
||||
DragImPlotFloat("Max", &Axis.Range.Max, 0.01f + 0.01f * (float)Axis.Range.Size(), Axis.Range.Min + FloatProps<ImPlotFloat>::Eps(), FloatProps<ImPlotFloat>::Inf());
|
||||
Dragdouble("Max", &Axis.Range.Max, 0.01f + 0.01f * (float)Axis.Range.Size(), Axis.Range.Min + DBL_EPSILON, HUGE_VAL);
|
||||
if (lock_max) {
|
||||
ImGui::PopItemFlag();
|
||||
ImGui::PopStyleVar();
|
||||
|
@ -1752,12 +1732,12 @@ void EndPlot() {
|
|||
// MISC API
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void SetNextPlotLimits(ImPlotFloat x_min, ImPlotFloat x_max, ImPlotFloat y_min, ImPlotFloat y_max, ImGuiCond cond) {
|
||||
void SetNextPlotLimits(double x_min, double x_max, double y_min, double y_max, ImGuiCond cond) {
|
||||
SetNextPlotLimitsX(x_min, x_max, cond);
|
||||
SetNextPlotLimitsY(y_min, y_max, cond);
|
||||
}
|
||||
|
||||
void SetNextPlotLimitsX(ImPlotFloat x_min, ImPlotFloat x_max, ImGuiCond cond) {
|
||||
void SetNextPlotLimitsX(double x_min, double x_max, ImGuiCond cond) {
|
||||
IM_ASSERT(cond == 0 || ImIsPowerOfTwo(cond)); // Make sure the user doesn't attempt to combine multiple condition flags.
|
||||
gp.NextPlotData.HasXRange = true;
|
||||
gp.NextPlotData.XRangeCond = cond;
|
||||
|
@ -1765,7 +1745,7 @@ void SetNextPlotLimitsX(ImPlotFloat x_min, ImPlotFloat x_max, ImGuiCond cond) {
|
|||
gp.NextPlotData.X.Max = x_max;
|
||||
}
|
||||
|
||||
void SetNextPlotLimitsY(ImPlotFloat y_min, ImPlotFloat y_max, ImGuiCond cond, int y_axis) {
|
||||
void SetNextPlotLimitsY(double y_min, double y_max, ImGuiCond cond, int y_axis) {
|
||||
IM_ASSERT_USER_ERROR(y_axis >= 0 && y_axis < MAX_Y_AXES, "y_axis Needs to be between 0 and MAX_Y_AXES");
|
||||
IM_ASSERT(cond == 0 || ImIsPowerOfTwo(cond)); // Make sure the user doesn't attempt to combine multiple condition flags.
|
||||
gp.NextPlotData.HasYRange[y_axis] = true;
|
||||
|
@ -2070,7 +2050,7 @@ inline void MarkerCross(ImDrawList& DrawList, const ImVec2& c, float s, bool /*o
|
|||
}
|
||||
|
||||
template <typename Transformer, typename Getter>
|
||||
inline void RenderMarkers(Transformer transformer, ImDrawList& DrawList, Getter getter, int count, int offset, bool rend_mk_line, ImU32 col_mk_line, bool rend_mk_fill, ImU32 col_mk_fill, bool cull) {
|
||||
inline void RenderMarkers(Getter getter, Transformer transformer, ImDrawList& DrawList, int count, int offset, bool rend_mk_line, ImU32 col_mk_line, bool rend_mk_fill, ImU32 col_mk_fill, bool cull) {
|
||||
int idx = offset;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
ImVec2 c;
|
||||
|
@ -2140,8 +2120,8 @@ inline void RenderLineAA(ImDrawList& DrawList, const ImVec2& p1, const ImVec2& p
|
|||
DrawList.AddLine(p1, p2, col_line, line_weight);
|
||||
}
|
||||
|
||||
template <typename Transformer, typename Getter>
|
||||
inline void RenderLineStrip(Transformer transformer, ImDrawList& DrawList, Getter getter, int count, int offset, float line_weight, ImU32 col_line, bool cull) {
|
||||
template <typename Getter, typename Transformer>
|
||||
inline void RenderLineStrip(Getter getter, Transformer transformer, ImDrawList& DrawList, int count, int offset, float line_weight, ImU32 col_line, bool cull) {
|
||||
// render line segments
|
||||
offset %= count;
|
||||
if (offset < 0) offset += count; // shift negative offset to positive range
|
||||
|
@ -2199,8 +2179,8 @@ struct GetterYs {
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct Getter2D {
|
||||
Getter2D(const T* xs, const T* ys, int stride) { Xs = xs; Ys = ys; Stride = stride; }
|
||||
struct GetterXsYs {
|
||||
GetterXsYs(const T* xs, const T* ys, int stride) { Xs = xs; Ys = ys; Stride = stride; }
|
||||
const T* Xs;
|
||||
const T* Ys;
|
||||
int Stride;
|
||||
|
@ -2209,6 +2189,19 @@ struct Getter2D {
|
|||
}
|
||||
};
|
||||
|
||||
struct GetterImPlotPoint {
|
||||
GetterImPlotPoint(const ImPlotPoint* data) { Data = data; }
|
||||
inline ImPlotPoint operator()(int idx) { return Data[idx]; }
|
||||
const ImPlotPoint* Data;
|
||||
};
|
||||
|
||||
struct GetterFuncPtrImPlotPoint {
|
||||
GetterFuncPtrImPlotPoint(ImPlotPoint (*g)(void* data, int idx), void* d) { getter = g; data = d;}
|
||||
inline ImPlotPoint operator()(int idx) { return getter(data, idx); }
|
||||
ImPlotPoint (*getter)(void* data, int idx);
|
||||
void* data;
|
||||
};
|
||||
|
||||
struct GetterImVec2 {
|
||||
GetterImVec2(const ImVec2* data) { Data = data; }
|
||||
inline ImPlotPoint operator()(int idx) { return ImPlotPoint(Data[idx].x, Data[idx].y); }
|
||||
|
@ -2222,13 +2215,6 @@ struct GetterFuncPtrImVec2 {
|
|||
void* data;
|
||||
};
|
||||
|
||||
struct GetterFuncPtrImVec4 {
|
||||
GetterFuncPtrImVec4(ImVec4 (*g)(void* data, int idx), void* d) { getter = g; data = d;}
|
||||
inline ImVec4 operator()(int idx) { return getter(data, idx); }
|
||||
ImVec4 (*getter)(void* data, int idx);
|
||||
void* data;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// PLOT
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -2271,35 +2257,38 @@ inline void PlotEx(const char* label_id, Getter getter, int count, int offset)
|
|||
PushPlotClipRect();
|
||||
if (count > 1 && rend_line) {
|
||||
if (HasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale) && HasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale))
|
||||
RenderLineStrip(TransformerLogLog(y_axis), DrawList, getter, count, offset, line_weight, col_line, cull);
|
||||
RenderLineStrip(getter, TransformerLogLog(y_axis), DrawList, count, offset, line_weight, col_line, cull);
|
||||
else if (HasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale))
|
||||
RenderLineStrip(TransformerLogLin(y_axis), DrawList, getter, count, offset, line_weight, col_line, cull);
|
||||
RenderLineStrip(getter, TransformerLogLin(y_axis), DrawList, count, offset, line_weight, col_line, cull);
|
||||
else if (HasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale))
|
||||
RenderLineStrip(TransformerLinLog(y_axis), DrawList, getter, count, offset, line_weight, col_line, cull);
|
||||
RenderLineStrip(getter, TransformerLinLog(y_axis), DrawList, count, offset, line_weight, col_line, cull);
|
||||
else
|
||||
RenderLineStrip(TransformerLinLin(y_axis), DrawList, getter, count, offset, line_weight, col_line, cull);
|
||||
RenderLineStrip(getter, TransformerLinLin(y_axis), DrawList, count, offset, line_weight, col_line, cull);
|
||||
}
|
||||
// render markers
|
||||
if (gp.Style.Marker != ImPlotMarker_None) {
|
||||
if (HasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale) && HasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale))
|
||||
RenderMarkers(TransformerLogLog(y_axis), DrawList, getter, count, offset, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill, cull);
|
||||
RenderMarkers(getter, TransformerLogLog(y_axis), DrawList, count, offset, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill, cull);
|
||||
else if (HasFlag(plot->XAxis.Flags, ImPlotAxisFlags_LogScale))
|
||||
RenderMarkers(TransformerLogLin(y_axis), DrawList, getter, count, offset, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill, cull);
|
||||
RenderMarkers(getter, TransformerLogLin(y_axis), DrawList, count, offset, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill, cull);
|
||||
else if (HasFlag(plot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale))
|
||||
RenderMarkers(TransformerLinLog(y_axis), DrawList, getter, count, offset, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill, cull);
|
||||
RenderMarkers(getter, TransformerLinLog(y_axis), DrawList, count, offset, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill, cull);
|
||||
else
|
||||
RenderMarkers(TransformerLinLin(y_axis), DrawList, getter, count, offset, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill, cull);
|
||||
RenderMarkers(getter, TransformerLinLin(y_axis), DrawList, count, offset, rend_mk_line, col_mk_line, rend_mk_fill, col_mk_fill, cull);
|
||||
}
|
||||
PopPlotClipRect();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// float
|
||||
|
||||
void PlotLine(const char* label_id, const float* values, int count, int offset, int stride) {
|
||||
GetterYs getter(values,stride);
|
||||
GetterYs<float> getter(values,stride);
|
||||
PlotEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
void PlotLine(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) {
|
||||
Getter2D getter(xs,ys,stride);
|
||||
GetterXsYs<float> getter(xs,ys,stride);
|
||||
return PlotEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
|
@ -2313,56 +2302,99 @@ void PlotLine(const char* label_id, ImVec2 (*getter_func)(void* data, int idx),
|
|||
return PlotEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// double
|
||||
|
||||
void PlotLine(const char* label_id, const double* values, int count, int offset, int stride) {
|
||||
GetterYs<double> getter(values,stride);
|
||||
PlotEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
void PlotLine(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride) {
|
||||
GetterXsYs<double> getter(xs,ys,stride);
|
||||
return PlotEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
void PlotLine(const char* label_id, const ImPlotPoint* data, int count, int offset) {
|
||||
GetterImPlotPoint getter(data);
|
||||
return PlotEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
void PlotLine(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, int offset) {
|
||||
GetterFuncPtrImPlotPoint getter(getter_func,data);
|
||||
return PlotEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// PLOT SCATTER
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void PlotScatter(const char* label_id, const float* values, int count, int offset, int stride) {
|
||||
int pops = 1;
|
||||
inline int PushScatterStyle() {
|
||||
int vars = 1;
|
||||
PushStyleVar(ImPlotStyleVar_LineWeight, 0);
|
||||
if (GetStyle().Marker == ImPlotMarker_None) {
|
||||
PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
|
||||
pops++;
|
||||
vars++;
|
||||
}
|
||||
PlotLine(label_id, values, count, offset, stride);
|
||||
PopStyleVar(pops);
|
||||
}
|
||||
|
||||
void PlotScatter(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) {
|
||||
int pops = 1;
|
||||
PushStyleVar(ImPlotStyleVar_LineWeight, 0);
|
||||
if (GetStyle().Marker == ImPlotMarker_None) {
|
||||
PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
|
||||
pops++;
|
||||
}
|
||||
PlotLine(label_id, xs, ys, count, offset, stride);
|
||||
PopStyleVar(pops);
|
||||
}
|
||||
|
||||
void PlotScatter(const char* label_id, const ImVec2* data, int count, int offset) {
|
||||
int pops = 1;
|
||||
PushStyleVar(ImPlotStyleVar_LineWeight, 0);
|
||||
if (GetStyle().Marker == ImPlotMarker_None) {
|
||||
PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
|
||||
pops++;
|
||||
}
|
||||
PlotLine(label_id, data, count, offset);
|
||||
PopStyleVar(pops);
|
||||
}
|
||||
|
||||
void PlotScatter(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, int offset) {
|
||||
int pops = 1;
|
||||
PushStyleVar(ImPlotStyleVar_LineWeight, 0);
|
||||
if (GetStyle().Marker == ImPlotMarker_None) {
|
||||
PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
|
||||
pops++;
|
||||
}
|
||||
PlotLine(label_id, getter, data, count, offset);
|
||||
PopStyleVar(pops);
|
||||
return vars;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// PLOT BAR
|
||||
// float
|
||||
|
||||
void PlotScatter(const char* label_id, const float* values, int count, int offset, int stride) {
|
||||
int vars = PushScatterStyle();
|
||||
PlotLine(label_id, values, count, offset, stride);
|
||||
PopStyleVar(vars);
|
||||
}
|
||||
|
||||
void PlotScatter(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) {
|
||||
int vars = PushScatterStyle();
|
||||
PlotLine(label_id, xs, ys, count, offset, stride);
|
||||
PopStyleVar(vars);
|
||||
}
|
||||
|
||||
void PlotScatter(const char* label_id, const ImVec2* data, int count, int offset) {
|
||||
int vars = PushScatterStyle();
|
||||
PlotLine(label_id, data, count, offset);
|
||||
PopStyleVar(vars);
|
||||
}
|
||||
|
||||
void PlotScatter(const char* label_id, ImVec2 (*getter)(void* data, int idx), void* data, int count, int offset) {
|
||||
int vars = PushScatterStyle();
|
||||
PlotLine(label_id, getter, data, count, offset);
|
||||
PopStyleVar(vars);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// double
|
||||
|
||||
void PlotScatter(const char* label_id, const double* values, int count, int offset, int stride) {
|
||||
int vars = PushScatterStyle();
|
||||
PlotLine(label_id, values, count, offset, stride);
|
||||
PopStyleVar(vars);
|
||||
}
|
||||
|
||||
void PlotScatter(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride) {
|
||||
int vars = PushScatterStyle();
|
||||
PlotLine(label_id, xs, ys, count, offset, stride);
|
||||
PopStyleVar(vars);
|
||||
}
|
||||
|
||||
void PlotScatter(const char* label_id, const ImPlotPoint* data, int count, int offset) {
|
||||
int vars = PushScatterStyle();
|
||||
PlotLine(label_id, data, count, offset);
|
||||
PopStyleVar(vars);
|
||||
}
|
||||
|
||||
void PlotScatter(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset) {
|
||||
int vars = PushScatterStyle();
|
||||
PlotLine(label_id, getter, data, count, offset);
|
||||
PopStyleVar(vars);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// PLOT BAR V
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <typename T>
|
||||
|
@ -2380,8 +2412,8 @@ struct GetterBarH {
|
|||
};
|
||||
|
||||
|
||||
template <typename Getter>
|
||||
void PlotBarsEx(const char* label_id, Getter getter, int count, float width, int offset) {
|
||||
template <typename Getter, typename TWidth>
|
||||
void PlotBarsEx(const char* label_id, Getter getter, int count, TWidth width, int offset) {
|
||||
|
||||
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "Bar() Needs to be called between BeginPlot() and EndPlot()!");
|
||||
|
||||
|
@ -2405,7 +2437,7 @@ void PlotBarsEx(const char* label_id, Getter getter, int count, float width, int
|
|||
|
||||
PushPlotClipRect();
|
||||
|
||||
float half_width = width * 0.5f;
|
||||
TWidth half_width = width / 2;
|
||||
|
||||
// find data extents
|
||||
if (gp.FitThisFrame) {
|
||||
|
@ -2433,13 +2465,16 @@ void PlotBarsEx(const char* label_id, Getter getter, int count, float width, int
|
|||
PopPlotClipRect();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// float
|
||||
|
||||
void PlotBars(const char* label_id, const float* values, int count, float width, float shift, int offset, int stride) {
|
||||
GetterBarV getter(values,shift,stride);
|
||||
GetterBarV<float> getter(values,shift,stride);
|
||||
PlotBarsEx(label_id, getter, count, width, offset);
|
||||
}
|
||||
|
||||
void PlotBars(const char* label_id, const float* xs, const float* ys, int count, float width, int offset, int stride) {
|
||||
Getter2D getter(xs,ys,stride);
|
||||
GetterXsYs<float> getter(xs,ys,stride);
|
||||
PlotBarsEx(label_id, getter, count, width, offset);
|
||||
}
|
||||
|
||||
|
@ -2449,9 +2484,29 @@ void PlotBars(const char* label_id, ImVec2 (*getter_func)(void* data, int idx),
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// double
|
||||
|
||||
template <typename Getter>
|
||||
void PlotBarsHEx(const char* label_id, Getter getter, int count, float height, int offset) {
|
||||
void PlotBars(const char* label_id, const double* values, int count, double width, double shift, int offset, int stride) {
|
||||
GetterBarV<double> getter(values,shift,stride);
|
||||
PlotBarsEx(label_id, getter, count, width, offset);
|
||||
}
|
||||
|
||||
void PlotBars(const char* label_id, const double* xs, const double* ys, int count, double width, int offset, int stride) {
|
||||
GetterXsYs<double> getter(xs,ys,stride);
|
||||
PlotBarsEx(label_id, getter, count, width, offset);
|
||||
}
|
||||
|
||||
void PlotBars(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, double width, int offset) {
|
||||
GetterFuncPtrImPlotPoint getter(getter_func, data);
|
||||
PlotBarsEx(label_id, getter, count, width, offset);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// PLOT BAR H
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <typename Getter, typename THeight>
|
||||
void PlotBarsHEx(const char* label_id, Getter getter, int count, THeight height, int offset) {
|
||||
|
||||
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "BarH() Needs to be called between BeginPlot() and EndPlot()!");
|
||||
|
||||
|
@ -2475,7 +2530,7 @@ void PlotBarsHEx(const char* label_id, Getter getter, int count, float height,
|
|||
|
||||
PushPlotClipRect();
|
||||
|
||||
float half_height = height * 0.5f;
|
||||
THeight half_height = height / 2;
|
||||
|
||||
// find data extents
|
||||
if (gp.FitThisFrame) {
|
||||
|
@ -2503,13 +2558,16 @@ void PlotBarsHEx(const char* label_id, Getter getter, int count, float height,
|
|||
PopPlotClipRect();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// float
|
||||
|
||||
void PlotBarsH(const char* label_id, const float* values, int count, float height, float shift, int offset, int stride) {
|
||||
GetterBarH getter(values,shift,stride);
|
||||
GetterBarH<float> getter(values,shift,stride);
|
||||
PlotBarsHEx(label_id, getter, count, height, offset);
|
||||
}
|
||||
|
||||
void PlotBarsH(const char* label_id, const float* xs, const float* ys, int count, float height, int offset, int stride) {
|
||||
Getter2D getter(xs,ys,stride);
|
||||
GetterXsYs<float> getter(xs,ys,stride);
|
||||
PlotBarsHEx(label_id, getter, count, height, offset);
|
||||
}
|
||||
|
||||
|
@ -2518,20 +2576,46 @@ void PlotBarsH(const char* label_id, ImVec2 (*getter_func)(void* data, int idx),
|
|||
PlotBarsHEx(label_id, getter, count, height, offset);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// double
|
||||
|
||||
void PlotBarsH(const char* label_id, const double* values, int count, double height, double shift, int offset, int stride) {
|
||||
GetterBarH<double> getter(values,shift,stride);
|
||||
PlotBarsHEx(label_id, getter, count, height, offset);
|
||||
}
|
||||
|
||||
void PlotBarsH(const char* label_id, const double* xs, const double* ys, int count, double height, int offset, int stride) {
|
||||
GetterXsYs<double> getter(xs,ys,stride);
|
||||
PlotBarsHEx(label_id, getter, count, height, offset);
|
||||
}
|
||||
|
||||
void PlotBarsH(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, double height, int offset) {
|
||||
GetterFuncPtrImPlotPoint getter(getter_func, data);
|
||||
PlotBarsHEx(label_id, getter, count, height, offset);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// PLOT ERROR BARS
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct ImPlotPointError {
|
||||
ImPlotPointError(double _x, double _y, double _neg, double _pos) {
|
||||
x = _x; y = _y; neg = _neg; pos = _pos;
|
||||
}
|
||||
double x, y, neg, pos;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct GetterError {
|
||||
const float* Xs; const float* Ys; const float* Neg; const float* Pos; int Stride;
|
||||
GetterError(const float* xs, const float* ys, const float* neg, const float* pos, int stride) {
|
||||
const T* Xs; const T* Ys; const T* Neg; const T* Pos; int Stride;
|
||||
GetterError(const T* xs, const T* ys, const T* neg, const T* pos, int stride) {
|
||||
Xs = xs; Ys = ys; Neg = neg; Pos = pos; Stride = stride;
|
||||
}
|
||||
ImVec4 operator()(int idx) {
|
||||
return ImVec4(StrideIndex(Xs, idx, Stride),
|
||||
StrideIndex(Ys, idx, Stride),
|
||||
StrideIndex(Neg, idx, Stride),
|
||||
StrideIndex(Pos, idx, Stride));
|
||||
ImPlotPointError operator()(int idx) {
|
||||
return ImPlotPointError(StrideIndex(Xs, idx, Stride),
|
||||
StrideIndex(Ys, idx, Stride),
|
||||
StrideIndex(Neg, idx, Stride),
|
||||
StrideIndex(Pos, idx, Stride));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2556,19 +2640,18 @@ void PlotErrorBarsEx(const char* label_id, Getter getter, int count, int offset)
|
|||
// find data extents
|
||||
if (gp.FitThisFrame) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
ImVec4 e = getter(i);
|
||||
FitPoint(ImPlotPoint(e.x , e.y - e.z));
|
||||
FitPoint(ImPlotPoint(e.x , e.y + e.w ));
|
||||
ImPlotPointError e = getter(i);
|
||||
FitPoint(ImPlotPoint(e.x , e.y - e.neg));
|
||||
FitPoint(ImPlotPoint(e.x , e.y + e.pos ));
|
||||
}
|
||||
}
|
||||
|
||||
int idx = offset;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
ImVec4 e;
|
||||
e = getter(idx);
|
||||
ImPlotPointError e = getter(idx);
|
||||
idx = (idx + 1) % count;
|
||||
ImVec2 p1 = PlotToPixels(e.x, e.y - e.z);
|
||||
ImVec2 p2 = PlotToPixels(e.x, e.y + e.w);
|
||||
ImVec2 p1 = PlotToPixels(e.x, e.y - e.neg);
|
||||
ImVec2 p2 = PlotToPixels(e.x, e.y + e.pos);
|
||||
DrawList.AddLine(p1,p2,col, gp.Style.ErrorBarWeight);
|
||||
if (rend_whisker) {
|
||||
DrawList.AddLine(p1 - ImVec2(half_whisker, 0), p1 + ImVec2(half_whisker, 0), col, gp.Style.ErrorBarWeight);
|
||||
|
@ -2578,44 +2661,55 @@ void PlotErrorBarsEx(const char* label_id, Getter getter, int count, int offset)
|
|||
PopPlotClipRect();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// float
|
||||
|
||||
void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* err, int count, int offset, int stride) {
|
||||
GetterError getter(xs, ys, err, err, stride);
|
||||
GetterError<float> getter(xs, ys, err, err, stride);
|
||||
PlotErrorBarsEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset, int stride) {
|
||||
GetterError getter(xs, ys, neg, pos, stride);
|
||||
PlotErrorBarsEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
void PlotErrorBars(const char* label_id, ImVec4 (*getter_func)(void* data, int idx), void* data, int count, int offset) {
|
||||
GetterFuncPtrImVec4 getter(getter_func, data);
|
||||
GetterError<float> getter(xs, ys, neg, pos, stride);
|
||||
PlotErrorBarsEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// PLOT MISC
|
||||
// double
|
||||
|
||||
void PlotErrorBars(const char* label_id, const double* xs, const double* ys, const double* err, int count, int offset, int stride) {
|
||||
GetterError<double> getter(xs, ys, err, err, stride);
|
||||
PlotErrorBarsEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
void PlotErrorBars(const char* label_id, const double* xs, const double* ys, const double* neg, const double* pos, int count, int offset, int stride) {
|
||||
GetterError<double> getter(xs, ys, neg, pos, stride);
|
||||
PlotErrorBarsEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// PLOT PIE CHART
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
inline void DrawPieSlice(ImDrawList& DrawList, const ImPlotPoint& center, float radius, float a0, float a1, ImU32 col) {
|
||||
inline void DrawPieSlice(ImDrawList& DrawList, const ImPlotPoint& center, double radius, double a0, double a1, ImU32 col) {
|
||||
static const float resolution = 50 / (2 * IM_PI);
|
||||
static ImVec2 buffer[50];
|
||||
buffer[0] = PlotToPixels(center);
|
||||
int n = ImMax(3, (int)((a1 - a0) * resolution));
|
||||
float da = (a1 - a0) / (n - 1);
|
||||
double da = (a1 - a0) / (n - 1);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
float a = a0 + i * da;
|
||||
double a = a0 + i * da;
|
||||
buffer[i + 1] = PlotToPixels(center.x + radius * cos(a), center.y + radius * sin(a));
|
||||
}
|
||||
DrawList.AddConvexPolyFilled(buffer, n + 1, col);
|
||||
}
|
||||
|
||||
|
||||
void PlotPieChart(const char** label_ids, float* values, int count, float x, float y, float radius, bool show_percents, float angle0) {
|
||||
template <typename T>
|
||||
void PlotPieChartEx(const char** label_ids, T* values, int count, T x, T y, T radius, bool show_percents, T angle0) {
|
||||
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PieChart() Needs to be called between BeginPlot() and EndPlot()!");
|
||||
ImDrawList & DrawList = *ImGui::GetWindowDrawList();
|
||||
|
||||
float sum = 0;
|
||||
T sum = 0;
|
||||
for (int i = 0; i < count; ++i)
|
||||
sum += values[i];
|
||||
|
||||
|
@ -2624,12 +2718,12 @@ void PlotPieChart(const char** label_ids, float* values, int count, float x, flo
|
|||
ImPlotPoint center(x,y);
|
||||
|
||||
PushPlotClipRect();
|
||||
float a0 = angle0 * 2 * IM_PI / 360.0f;
|
||||
float a1 = angle0 * 2 * IM_PI / 360.0f;
|
||||
T a0 = angle0 * 2 * IM_PI / 360.0f;
|
||||
T a1 = angle0 * 2 * IM_PI / 360.0f;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
ImPlotItem* item = RegisterItem(label_ids[i]);
|
||||
ImU32 col = ImGui::GetColorU32(item->Color);
|
||||
float percent = normalize ? values[i] / sum : values[i];
|
||||
T percent = normalize ? values[i] / sum : values[i];
|
||||
a1 = a0 + 2 * IM_PI * percent;
|
||||
if (item->Show) {
|
||||
if (percent < 0.5) {
|
||||
|
@ -2643,7 +2737,7 @@ void PlotPieChart(const char** label_ids, float* values, int count, float x, flo
|
|||
char buffer[8];
|
||||
sprintf(buffer, "%.0f%%", percent * 100);
|
||||
ImVec2 size = ImGui::CalcTextSize(buffer);
|
||||
float angle = a0 + (a1 - a0) * 0.5f;
|
||||
T angle = a0 + (a1 - a0) * 0.5f;
|
||||
ImVec2 pos = PlotToPixels(center.x + 0.5f * radius * cos(angle), center.y + 0.5f * radius * sin(angle));
|
||||
DrawList.AddText(pos - size * 0.5f + ImVec2(1,1), IM_COL32(0,0,0,255), buffer);
|
||||
DrawList.AddText(pos - size * 0.5f, IM_COL32(255,255,255,255), buffer);
|
||||
|
@ -2654,18 +2748,24 @@ void PlotPieChart(const char** label_ids, float* values, int count, float x, flo
|
|||
PopPlotClipRect();
|
||||
}
|
||||
|
||||
void PlotText(const char* text, float x, float y, bool vertical, const ImVec2& pixel_offset) {
|
||||
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "Text() Needs to be called between BeginPlot() and EndPlot()!");
|
||||
ImDrawList & DrawList = *ImGui::GetWindowDrawList();
|
||||
PushPlotClipRect();
|
||||
ImVec2 pos = PlotToPixels(ImPlotPoint(x,y)) + pixel_offset;
|
||||
if (vertical)
|
||||
AddTextVertical(&DrawList, text, pos, gp.Col_Txt);
|
||||
else
|
||||
DrawList.AddText(pos, gp.Col_Txt, text);
|
||||
PopPlotClipRect();
|
||||
//-----------------------------------------------------------------------------
|
||||
// float
|
||||
|
||||
void PlotPieChart(const char** label_ids, float* values, int count, float x, float y, float radius, bool show_percents, float angle0) {
|
||||
return PlotPieChartEx(label_ids, values, count, x, y, radius, show_percents, angle0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// double
|
||||
|
||||
void PlotPieChart(const char** label_ids, double* values, int count, double x, double y, double radius, bool show_percents, double angle0) {
|
||||
return PlotPieChartEx(label_ids, values, count, x, y, radius, show_percents, angle0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// PLOT DIGITAL
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template <typename Getter>
|
||||
inline void PlotDigitalEx(const char* label_id, Getter getter, int count, int offset)
|
||||
{
|
||||
|
@ -2747,8 +2847,11 @@ inline void PlotDigitalEx(const char* label_id, Getter getter, int count, int of
|
|||
ImGui::PopClipRect();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// float
|
||||
|
||||
void PlotDigital(const char* label_id, const float* xs, const float* ys, int count, int offset, int stride) {
|
||||
Getter2D getter(xs,ys,stride);
|
||||
GetterXsYs<float> getter(xs,ys,stride);
|
||||
return PlotDigitalEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
|
@ -2757,4 +2860,40 @@ void PlotDigital(const char* label_id, ImVec2 (*getter_func)(void* data, int idx
|
|||
return PlotDigitalEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// double
|
||||
|
||||
void PlotDigital(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride) {
|
||||
GetterXsYs<double> getter(xs,ys,stride);
|
||||
return PlotDigitalEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
void PlotDigital(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, int offset) {
|
||||
GetterFuncPtrImPlotPoint getter(getter_func,data);
|
||||
return PlotDigitalEx(label_id, getter, count, offset);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// PLOT TEXT
|
||||
//-----------------------------------------------------------------------------
|
||||
// float
|
||||
|
||||
void PlotText(const char* text, float x, float y, bool vertical, const ImVec2& pixel_offset) {
|
||||
return PlotText(text, (double)x, (double)y, vertical, pixel_offset);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// double
|
||||
void PlotText(const char* text, double x, double y, bool vertical, const ImVec2& pixel_offset) {
|
||||
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "Text() Needs to be called between BeginPlot() and EndPlot()!");
|
||||
ImDrawList & DrawList = *ImGui::GetWindowDrawList();
|
||||
PushPlotClipRect();
|
||||
ImVec2 pos = PlotToPixels(ImPlotPoint(x,y)) + pixel_offset;
|
||||
if (vertical)
|
||||
AddTextVertical(&DrawList, text, pos, gp.Col_Txt);
|
||||
else
|
||||
DrawList.AddText(pos, gp.Col_Txt, text);
|
||||
PopPlotClipRect();
|
||||
}
|
||||
|
||||
} // namespace ImPlot
|
65
implot.h
65
implot.h
|
@ -20,14 +20,11 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// ImPlot v0.2 WIP
|
||||
// ImPlot v0.3 WIP
|
||||
|
||||
#pragma once
|
||||
#include "imgui.h"
|
||||
|
||||
// The desired plot precision (float or double)
|
||||
typedef double ImPlotFloat;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Basic types and flags
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -117,25 +114,31 @@ enum ImPlotMarker_ {
|
|||
ImPlotMarker_Asterisk = 1 << 10, // a asterisk marker will be rendered at each point (not filled)
|
||||
};
|
||||
|
||||
/// Double precision version of ImVec2 used by ImPlot and extensible by end users
|
||||
struct ImPlotPoint {
|
||||
ImPlotFloat x, y;
|
||||
ImPlotPoint() { x = y = 0; }
|
||||
ImPlotPoint(ImPlotFloat _x, ImPlotFloat _y) { x = _x; y = _y; }
|
||||
double x, y;
|
||||
ImPlotPoint() { x = y = 0.0; }
|
||||
ImPlotPoint(double _x, double _y) { x = _x; y = _y; }
|
||||
double operator[] (size_t idx) const { return (&x)[idx]; }
|
||||
double& operator[] (size_t idx) { return (&x)[idx]; }
|
||||
#ifdef IMPLOT_POINT_CLASS_EXTRA
|
||||
IMPLOT_POINT_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your math types and ImVec2.
|
||||
#endif
|
||||
};
|
||||
|
||||
// A range defined by a min/max value. Used for plot axes ranges.
|
||||
struct ImPlotRange {
|
||||
ImPlotFloat Min, Max;
|
||||
double Min, Max;
|
||||
ImPlotRange();
|
||||
bool Contains(ImPlotFloat value) const;
|
||||
ImPlotFloat Size() const;
|
||||
bool Contains(double value) const;
|
||||
double Size() const;
|
||||
};
|
||||
|
||||
// Combination of two ranges for X and Y axes.
|
||||
struct ImPlotLimits {
|
||||
ImPlotRange X, Y;
|
||||
ImPlotLimits();
|
||||
bool Contains(const ImVec2& p) const;
|
||||
bool Contains(double x, double y) const;
|
||||
};
|
||||
|
||||
// Plot style structure
|
||||
|
@ -177,7 +180,7 @@ bool BeginPlot(const char* title_id,
|
|||
void EndPlot();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Plot Items (float)
|
||||
// Plot Items (single precision data)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Plots a standard 2D line plot.
|
||||
|
@ -201,7 +204,6 @@ void PlotBarsH(const char* label_id, ImVec2 (*getter)(void* data, int idx), void
|
|||
// Plots vertical error bar.
|
||||
void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* err, int count, int offset = 0, int stride = sizeof(float));
|
||||
void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset = 0, int stride = sizeof(float));
|
||||
void PlotErrorBars(const char* label_id, ImVec4 (*getter)(void* data, int idx), void* data, int count, int offset = 0);
|
||||
// Plots a pie chart. If the sum of values > 1, each value will be normalized. Center and radius are in plot coordinates.
|
||||
void PlotPieChart(const char** label_ids, float* values, int count, float x, float y, float radius, bool show_percents = true, float angle0 = 90);
|
||||
// Plots digital data.
|
||||
|
@ -210,7 +212,38 @@ void PlotDigital(const char* label_id, ImVec2 (*getter)(void* data, int idx), vo
|
|||
// Plots a text label at point x,y.
|
||||
void PlotText(const char* text, float x, float y, bool vertical = false, const ImVec2& pixel_offset = ImVec2(0,0));
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Plot Items (double precision data)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Plots a standard 2D line plot.
|
||||
void PlotLine(const char* label_id, const double* values, int count, int offset = 0, int stride = sizeof(double));
|
||||
void PlotLine(const char* label_id, const double* xs, const double* ys, int count, int offset = 0, int stride = sizeof(double));
|
||||
void PlotLine(const char* label_id, const ImPlotPoint* data, int count, int offset = 0);
|
||||
void PlotLine(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset = 0);
|
||||
// Plots a standard 2D scatter plot.
|
||||
void PlotScatter(const char* label_id, const double* values, int count, int offset = 0, int stride = sizeof(double));
|
||||
void PlotScatter(const char* label_id, const double* xs, const double* ys, int count, int offset = 0, int stride = sizeof(double));
|
||||
void PlotScatter(const char* label_id, const ImPlotPoint* data, int count, int offset = 0);
|
||||
void PlotScatter(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset = 0);
|
||||
// Plots a vertical bar graph.
|
||||
void PlotBars(const char* label_id, const double* values, int count, double width = 0.67f, double shift = 0, int offset = 0, int stride = sizeof(double));
|
||||
void PlotBars(const char* label_id, const double* xs, const double* ys, int count, double width, int offset = 0, int stride = sizeof(double));
|
||||
void PlotBars(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, double width, int offset = 0);
|
||||
// Plots a horizontal bar graph.
|
||||
void PlotBarsH(const char* label_id, const double* values, int count, double height = 0.67f, double shift = 0, int offset = 0, int stride = sizeof(double));
|
||||
void PlotBarsH(const char* label_id, const double* xs, const double* ys, int count, double height, int offset = 0, int stride = sizeof(double));
|
||||
void PlotBarsH(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, double height, int offset = 0);
|
||||
// Plots vertical error bar.
|
||||
void PlotErrorBars(const char* label_id, const double* xs, const double* ys, const double* err, int count, int offset = 0, int stride = sizeof(double));
|
||||
void PlotErrorBars(const char* label_id, const double* xs, const double* ys, const double* neg, const double* pos, int count, int offset = 0, int stride = sizeof(double));
|
||||
// Plots a pie chart. If the sum of values > 1, each value will be normalized. Center and radius are in plot coordinates.
|
||||
void PlotPieChart(const char** label_ids, double* values, int count, double x, double y, double radius, bool show_percents = true, double angle0 = 90);
|
||||
// Plots digital data.
|
||||
void PlotDigital(const char* label_id, const double* xs, const double* ys, int count, int offset = 0, int stride = sizeof(double));
|
||||
void PlotDigital(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset = 0);
|
||||
// Plots a text label at point x,y.
|
||||
void PlotText(const char* text, double x, double y, bool vertical = false, const ImVec2& pixel_offset = ImVec2(0,0));
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Plot Queries
|
||||
|
@ -258,11 +291,11 @@ void PopStyleVar(int count = 1);
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// Set the axes range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axes limits will be locked.
|
||||
void SetNextPlotLimits(ImPlotFloat x_min, ImPlotFloat x_max, ImPlotFloat y_min, ImPlotFloat y_max, ImGuiCond cond = ImGuiCond_Once);
|
||||
void SetNextPlotLimits(double x_min, double x_max, double y_min, double y_max, ImGuiCond cond = ImGuiCond_Once);
|
||||
/// Set the X axis range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axis limits will be locked.
|
||||
void SetNextPlotLimitsX(ImPlotFloat x_min, ImPlotFloat x_max, ImGuiCond cond = ImGuiCond_Once);
|
||||
void SetNextPlotLimitsX(double x_min, double x_max, ImGuiCond cond = ImGuiCond_Once);
|
||||
/// Set the Y axis range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axis limits will be locked.
|
||||
void SetNextPlotLimitsY(ImPlotFloat y_min, ImPlotFloat y_max, ImGuiCond cond = ImGuiCond_Once, int y_axis = 0);
|
||||
void SetNextPlotLimitsY(double y_min, double y_max, ImGuiCond cond = ImGuiCond_Once, int y_axis = 0);
|
||||
|
||||
/// Select which Y axis will be used for subsequent plot elements. The default is '0', or the first Y axis.
|
||||
void SetPlotYAxis(int y_axis);
|
||||
|
|
229
implot_demo.cpp
229
implot_demo.cpp
|
@ -20,40 +20,62 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// ImPlot v0.2 WIP
|
||||
|
||||
// ImPlot v0.3 WIP
|
||||
|
||||
#include "implot.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <cmath> // for 'float' overloads of elementary functions (sin,cos,etc)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define sprintf sprintf_s
|
||||
#endif
|
||||
|
||||
/// Choose whether the demo uses double or float versions of the ImPlot API.
|
||||
/// NB: You don't ever need to typdef of define values for ImPlot. This
|
||||
/// is only being done here for the sake of demoing both precision types.
|
||||
|
||||
// #define IMPLOT_DEMO_USE_DOUBLE
|
||||
#ifdef IMPLOT_DEMO_USE_DOUBLE
|
||||
typedef double t_float;
|
||||
typedef ImPlotPoint t_float2;
|
||||
#define Sin sin
|
||||
#define Cos cos
|
||||
#define Pow pow
|
||||
#define Log log
|
||||
#define Fmod fmod
|
||||
#else
|
||||
typedef float t_float;
|
||||
typedef ImVec2 t_float2;
|
||||
#define Sin sinf
|
||||
#define Cos cosf
|
||||
#define Pow powf
|
||||
#define Log logf
|
||||
#define Fmod fmodf
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
float RandomRange( float min, float max ) {
|
||||
float scale = rand() / (float) RAND_MAX;
|
||||
t_float RandomRange(t_float min, t_float max) {
|
||||
t_float scale = rand() / (t_float) RAND_MAX;
|
||||
return min + scale * ( max - min );
|
||||
}
|
||||
|
||||
// utility structure for realtime plot
|
||||
struct ScrollingData {
|
||||
int MaxSize;
|
||||
int Offset;
|
||||
ImVector<ImVec2> Data;
|
||||
ImVector<t_float2> Data;
|
||||
ScrollingData() {
|
||||
MaxSize = 1000;
|
||||
Offset = 0;
|
||||
Data.reserve(MaxSize);
|
||||
}
|
||||
void AddPoint(float x, float y) {
|
||||
void AddPoint(t_float x, t_float y) {
|
||||
if (Data.size() < MaxSize)
|
||||
Data.push_back(ImVec2(x,y));
|
||||
Data.push_back(t_float2(x,y));
|
||||
else {
|
||||
Data[Offset] = ImVec2(x,y);
|
||||
Data[Offset] = t_float2(x,y);
|
||||
Offset = (Offset + 1) % MaxSize;
|
||||
}
|
||||
}
|
||||
|
@ -65,33 +87,35 @@ struct ScrollingData {
|
|||
}
|
||||
};
|
||||
|
||||
// utility structure for realtime plot
|
||||
struct RollingData {
|
||||
float Span;
|
||||
ImVector<ImVec2> Data;
|
||||
t_float Span;
|
||||
ImVector<t_float2> Data;
|
||||
RollingData() {
|
||||
Span = 10.0f;
|
||||
Data.reserve(1000);
|
||||
}
|
||||
void AddPoint(float x, float y) {
|
||||
float xmod = fmodf(x, Span);
|
||||
void AddPoint(t_float x, t_float y) {
|
||||
t_float xmod = Fmod(x, Span);
|
||||
if (!Data.empty() && xmod < Data.back().x)
|
||||
Data.shrink(0);
|
||||
Data.push_back(ImVec2(xmod, y));
|
||||
Data.push_back(t_float2(xmod, y));
|
||||
}
|
||||
};
|
||||
|
||||
// utility structure for benchmark data
|
||||
struct BenchmarkItem {
|
||||
BenchmarkItem() {
|
||||
float y = RandomRange(0,1);
|
||||
Data = new ImVec2[1000];
|
||||
t_float y = RandomRange(0,1);
|
||||
Data = new t_float2[1000];
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
Data[i].x = i*0.001f;
|
||||
Data[i].y = y + RandomRange(-0.01f,0.01f);
|
||||
}
|
||||
Col = ImVec4(RandomRange(0,1),RandomRange(0,1),RandomRange(0,1),1);
|
||||
Col = ImVec4((float)RandomRange(0,1),(float)RandomRange(0,1),(float)RandomRange(0,1),1);
|
||||
}
|
||||
~BenchmarkItem() { delete Data; }
|
||||
ImVec2* Data;
|
||||
t_float2* Data;
|
||||
ImVec4 Col;
|
||||
};
|
||||
|
||||
|
@ -139,15 +163,21 @@ void ShowDemoWindow(bool* p_open) {
|
|||
ImGui::Unindent();
|
||||
ImGui::BulletText("Double right click to open the plot context menu.");
|
||||
ImGui::BulletText("Click legend label icons to show/hide plot items.");
|
||||
#ifdef IMPLOT_DEMO_USE_DOUBLE
|
||||
ImGui::BulletText("The demo data precision is: double");
|
||||
#else
|
||||
ImGui::BulletText("The demo data precision is: float");
|
||||
#endif
|
||||
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
if (ImGui::CollapsingHeader("Line Plots")) {
|
||||
static float xs1[1001], ys1[1001];
|
||||
static t_float xs1[1001], ys1[1001];
|
||||
for (int i = 0; i < 1001; ++i) {
|
||||
xs1[i] = i * 0.001f;
|
||||
ys1[i] = 0.5f + 0.5f * sin(50 * xs1[i]);
|
||||
ys1[i] = 0.5f + 0.5f * Sin(50 * xs1[i]);
|
||||
}
|
||||
static float xs2[11], ys2[11];
|
||||
static t_float xs2[11], ys2[11];
|
||||
for (int i = 0; i < 11; ++i) {
|
||||
xs2[i] = i * 0.1f;
|
||||
ys2[i] = xs2[i] * xs2[i];
|
||||
|
@ -163,19 +193,18 @@ void ShowDemoWindow(bool* p_open) {
|
|||
//-------------------------------------------------------------------------
|
||||
if (ImGui::CollapsingHeader("Scatter Plots")) {
|
||||
srand(0);
|
||||
static float xs1[100], ys1[100];
|
||||
static t_float xs1[100], ys1[100];
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
xs1[i] = i * 0.01f;
|
||||
ys1[i] = xs1[i] + 0.1f * ((float)rand() / (float)RAND_MAX);
|
||||
ys1[i] = xs1[i] + 0.1f * ((t_float)rand() / (t_float)RAND_MAX);
|
||||
}
|
||||
static float xs2[50], ys2[50];
|
||||
static t_float xs2[50], ys2[50];
|
||||
for (int i = 0; i < 50; i++) {
|
||||
xs2[i] = 0.25f + 0.2f * ((float)rand() / (float)RAND_MAX);
|
||||
ys2[i] = 0.75f + 0.2f * ((float)rand() / (float)RAND_MAX);
|
||||
xs2[i] = 0.25f + 0.2f * ((t_float)rand() / (t_float)RAND_MAX);
|
||||
ys2[i] = 0.75f + 0.2f * ((t_float)rand() / (t_float)RAND_MAX);
|
||||
}
|
||||
if (ImPlot::BeginPlot("Scatter Plot", NULL, NULL)) {
|
||||
ImPlot::PlotScatter("Data 1", xs1, ys1, 100);
|
||||
|
||||
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 6);
|
||||
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Square);
|
||||
ImPlot::PushStyleColor(ImPlotCol_MarkerFill, ImVec4(1,0,0,0.25f));
|
||||
|
@ -183,7 +212,6 @@ void ShowDemoWindow(bool* p_open) {
|
|||
ImPlot::PlotScatter("Data 2", xs2, ys2, 50);
|
||||
ImPlot::PopStyleColor(2);
|
||||
ImPlot::PopStyleVar(2);
|
||||
|
||||
ImPlot::EndPlot();
|
||||
}
|
||||
}
|
||||
|
@ -192,13 +220,13 @@ void ShowDemoWindow(bool* p_open) {
|
|||
static bool horz = false;
|
||||
ImGui::Checkbox("Horizontal",&horz);
|
||||
if (horz)
|
||||
ImPlot::SetNextPlotLimits(0, 110, -0.5f, 9.5f, ImGuiCond_Always);
|
||||
ImPlot::SetNextPlotLimits(0, 110, -0.5, 9.5, ImGuiCond_Always);
|
||||
else
|
||||
ImPlot::SetNextPlotLimits(-0.5f, 9.5f, 0, 110, ImGuiCond_Always);
|
||||
ImPlot::SetNextPlotLimits(-0.5, 9.5, 0, 110, ImGuiCond_Always);
|
||||
if (ImPlot::BeginPlot("Bar Plot", horz ? "Score": "Student", horz ? "Student" : "Score")) {
|
||||
static float midtm[10] = {83, 67, 23, 89, 83, 78, 91, 82, 85, 90};
|
||||
static float final[10] = {80, 62, 56, 99, 55, 78, 88, 78, 90, 100};
|
||||
static float grade[10] = {80, 69, 52, 92, 72, 78, 75, 76, 89, 95};
|
||||
static t_float midtm[10] = {83, 67, 23, 89, 83, 78, 91, 82, 85, 90};
|
||||
static t_float final[10] = {80, 62, 56, 99, 55, 78, 88, 78, 90, 100};
|
||||
static t_float grade[10] = {80, 69, 52, 92, 72, 78, 75, 76, 89, 95};
|
||||
if (horz) {
|
||||
ImPlot::PlotBarsH("Midterm Exam", midtm, 10, 0.2f, -0.2f);
|
||||
ImPlot::PlotBarsH("Final Exam", final, 10, 0.2f, 0);
|
||||
|
@ -214,17 +242,15 @@ void ShowDemoWindow(bool* p_open) {
|
|||
}
|
||||
//-------------------------------------------------------------------------
|
||||
if (ImGui::CollapsingHeader("Error Bars")) {
|
||||
float xs[5] = {1,2,3,4,5};
|
||||
float lin[5] = {8,8,9,7,8};
|
||||
float bar[5] = {1,2,5,3,4};
|
||||
float err1[5] = {0.2f, 0.4f, 0.2f, 0.6f, 0.4f};
|
||||
float err2[5] = {0.4f, 0.2f, 0.4f, 0.8f, 0.6f};
|
||||
t_float xs[5] = {1,2,3,4,5};
|
||||
t_float lin[5] = {8,8,9,7,8};
|
||||
t_float bar[5] = {1,2,5,3,4};
|
||||
t_float err1[5] = {0.2f, 0.4f, 0.2f, 0.6f, 0.4f};
|
||||
t_float err2[5] = {0.4f, 0.2f, 0.4f, 0.8f, 0.6f};
|
||||
ImPlot::SetNextPlotLimits(0, 6, 0, 10);
|
||||
if (ImPlot::BeginPlot("##ErrorBars",NULL,NULL)) {
|
||||
|
||||
ImPlot::PlotBars("Bar", xs, bar, 5, 0.5f);
|
||||
ImPlot::PlotErrorBars("Bar", xs, bar, err1, 5);
|
||||
|
||||
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
|
||||
ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 3);
|
||||
ImPlot::PushStyleColor(ImPlotCol_ErrorBar, ImVec4(1,0,0,1));
|
||||
|
@ -232,14 +258,13 @@ void ShowDemoWindow(bool* p_open) {
|
|||
ImPlot::PlotLine("Line", xs, lin, 5);
|
||||
ImPlot::PopStyleVar(2);
|
||||
ImPlot::PopStyleColor();
|
||||
|
||||
ImPlot::EndPlot();
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
if (ImGui::CollapsingHeader("Pie Charts")) {
|
||||
static const char* labels1[] = {"Frogs","Hogs","Dogs","Logs"};
|
||||
static float pre_normalized[] = {0.15f, 0.30f, 0.45f, 0.10f};
|
||||
static t_float pre_normalized[] = {0.15f, 0.30f, 0.45f, 0.10f};
|
||||
|
||||
SetNextPlotLimits(0,1,0,1,ImGuiCond_Always);
|
||||
if (ImPlot::BeginPlot("##Pie1", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) {
|
||||
|
@ -258,7 +283,7 @@ void ShowDemoWindow(bool* p_open) {
|
|||
ImPlot::SetPalette(YlOrRd, 5);
|
||||
SetNextPlotLimits(0,1,0,1,ImGuiCond_Always);
|
||||
static const char* labels2[] = {"One","Two","Three","Four","Five"};
|
||||
static float not_normalized[] = {1,2,3,4,5};
|
||||
static t_float not_normalized[] = {1,2,3,4,5};
|
||||
if (ImPlot::BeginPlot("##Pie2", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) {
|
||||
ImPlot::PlotPieChart(labels2, not_normalized, 5, 0.5f, 0.5f, 0.4f);
|
||||
ImPlot::EndPlot();
|
||||
|
@ -273,7 +298,7 @@ void ShowDemoWindow(bool* p_open) {
|
|||
static ScrollingData sdata1, sdata2;
|
||||
static RollingData rdata1, rdata2;
|
||||
ImVec2 mouse = ImGui::GetMousePos();
|
||||
static float t = 0;
|
||||
static t_float t = 0;
|
||||
if (!paused) {
|
||||
t += ImGui::GetIO().DeltaTime;
|
||||
sdata1.AddPoint(t, mouse.x * 0.0005f);
|
||||
|
@ -284,14 +309,14 @@ void ShowDemoWindow(bool* p_open) {
|
|||
ImPlot::SetNextPlotLimitsX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
|
||||
static int rt_axis = ImPlotAxisFlags_Default & ~ImPlotAxisFlags_TickLabels;
|
||||
if (ImPlot::BeginPlot("##Scrolling", NULL, NULL, ImVec2(-1,150), ImPlotFlags_Default, rt_axis, rt_axis)) {
|
||||
ImPlot::PlotLine("Data 1", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), sdata1.Offset, 2 * sizeof(float));
|
||||
ImPlot::PlotLine("Data 2", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), sdata2.Offset, 2 * sizeof(float));
|
||||
ImPlot::PlotLine("Data 1", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), sdata1.Offset, 2 * sizeof(t_float));
|
||||
ImPlot::PlotLine("Data 2", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), sdata2.Offset, 2 * sizeof(t_float));
|
||||
ImPlot::EndPlot();
|
||||
}
|
||||
ImPlot::SetNextPlotLimitsX(0, 10, ImGuiCond_Always);
|
||||
if (ImPlot::BeginPlot("##Rolling", NULL, NULL, ImVec2(-1,150), ImPlotFlags_Default, rt_axis, rt_axis)) {
|
||||
ImPlot::PlotLine("Data 1", &rdata1.Data[0].x, &rdata1.Data[0].y, rdata1.Data.size(), 0, 2 * sizeof(float));
|
||||
ImPlot::PlotLine("Data 2", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.Data.size(), 0, 2 * sizeof(float));
|
||||
ImPlot::PlotLine("Data 1", &rdata1.Data[0].x, &rdata1.Data[0].y, rdata1.Data.size(), 0, 2 * sizeof(t_float));
|
||||
ImPlot::PlotLine("Data 2", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.Data.size(), 0, 2 * sizeof(t_float));
|
||||
ImPlot::EndPlot();
|
||||
}
|
||||
}
|
||||
|
@ -299,8 +324,8 @@ void ShowDemoWindow(bool* p_open) {
|
|||
if (ImGui::CollapsingHeader("Markers and Text")) {
|
||||
ImPlot::SetNextPlotLimits(0, 10, 0, 12);
|
||||
if (ImPlot::BeginPlot("##MarkerStyles", NULL, NULL, ImVec2(-1,0), 0, 0, 0)) {
|
||||
float xs[2] = {1,4};
|
||||
float ys[2] = {10,11};
|
||||
t_float xs[2] = {1,4};
|
||||
t_float ys[2] = {10,11};
|
||||
// filled
|
||||
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
|
||||
ImPlot::PlotLine("Circle##Fill", xs, ys, 2);
|
||||
|
@ -374,14 +399,14 @@ void ShowDemoWindow(bool* p_open) {
|
|||
//-------------------------------------------------------------------------
|
||||
if (ImGui::CollapsingHeader("Log Scale")) {
|
||||
ImGui::BulletText("Open the plot context menu (double right click) to change scales.");
|
||||
static float xs[1001], ys1[1001], ys2[1001], ys3[1001];
|
||||
static t_float xs[1001], ys1[1001], ys2[1001], ys3[1001];
|
||||
for (int i = 0; i < 1001; ++i) {
|
||||
xs[i] = (float)(i*0.1f);
|
||||
ys1[i] = sin(xs[i]) + 1;
|
||||
ys2[i] = log(xs[i]);
|
||||
ys3[i] = pow(10.0f, xs[i]);
|
||||
xs[i] = i*0.1f;
|
||||
ys1[i] = Sin(xs[i]) + 1;
|
||||
ys2[i] = Log(xs[i]);
|
||||
ys3[i] = Pow(10.0f, xs[i]);
|
||||
}
|
||||
ImPlot::SetNextPlotLimits(0.1f, 100, 0, 10);
|
||||
ImPlot::SetNextPlotLimits(0.1, 100, 0, 10);
|
||||
if (ImPlot::BeginPlot("Log Plot", NULL, NULL, ImVec2(-1,0), ImPlotFlags_Default, ImPlotAxisFlags_Default | ImPlotAxisFlags_LogScale )) {
|
||||
ImPlot::PlotLine("f(x) = x", xs, xs, 1001);
|
||||
ImPlot::PlotLine("f(x) = sin(x)+1", xs, ys1, 1001);
|
||||
|
@ -398,7 +423,7 @@ void ShowDemoWindow(bool* p_open) {
|
|||
static ImVec4 y2_col = txt_col;
|
||||
static ImVec4 y3_col = txt_col;
|
||||
|
||||
static float xs[1001], xs2[1001], ys1[1001], ys2[1001], ys3[1001];
|
||||
static t_float xs[1001], xs2[1001], ys1[1001], ys2[1001], ys3[1001];
|
||||
static bool y2_axis = true;
|
||||
static bool y3_axis = false;
|
||||
ImGui::Checkbox("Y-Axis 2", &y2_axis);
|
||||
|
@ -411,13 +436,13 @@ void ShowDemoWindow(bool* p_open) {
|
|||
ImGui::SameLine();
|
||||
ImGui::ColorEdit4("##Col3", &y3_col.x, ImGuiColorEditFlags_NoInputs);
|
||||
for (int i = 0; i < 1001; ++i) {
|
||||
xs[i] = (float)(i*0.1f);
|
||||
ys1[i] = sin(xs[i]) * 3 + 1;
|
||||
ys2[i] = cos(xs[i]) * 0.2f + 0.5f;
|
||||
ys3[i] = sin(xs[i]+0.5f) * 100 + 200;
|
||||
xs[i] = (i*0.1f);
|
||||
ys1[i] = Sin(xs[i]) * 3 + 1;
|
||||
ys2[i] = Cos(xs[i]) * 0.2f + 0.5f;
|
||||
ys3[i] = Sin(xs[i]+0.5f) * 100 + 200;
|
||||
xs2[i] = xs[i] + 10.0f;
|
||||
}
|
||||
ImPlot::SetNextPlotLimits(0.1f, 100, 0, 10);
|
||||
ImPlot::SetNextPlotLimits(0.1, 100, 0, 10);
|
||||
ImPlot::SetNextPlotLimitsY(0, 1, ImGuiCond_Once, 1);
|
||||
ImPlot::SetNextPlotLimitsY(0, 300, ImGuiCond_Once, 2);
|
||||
ImPlot::PushStyleColor(ImPlotCol_YAxis, y1_col);
|
||||
|
@ -454,23 +479,23 @@ void ShowDemoWindow(bool* p_open) {
|
|||
ImGui::BulletText("Hold Shift to expand query vertically.");
|
||||
ImGui::BulletText("The query rect can be dragged after it's created.");
|
||||
ImGui::Unindent();
|
||||
static ImVector<ImVec2> data;
|
||||
static ImVector<t_float2> data;
|
||||
ImPlotLimits range, query;
|
||||
if (ImPlot::BeginPlot("##Drawing", NULL, NULL, ImVec2(-1,0), ImPlotFlags_Default | ImPlotFlags_Query, ImPlotAxisFlags_GridLines, ImPlotAxisFlags_GridLines)) {
|
||||
if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(0) && ImGui::GetIO().KeyCtrl) {
|
||||
ImPlotPoint pt = ImPlot::GetPlotMousePos();
|
||||
|
||||
data.push_back(ImVec2((float)pt.x, (float)pt.y));
|
||||
data.push_back(t_float2((t_float)pt.x, (t_float)pt.y));
|
||||
}
|
||||
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Diamond);
|
||||
if (data.size() > 0)
|
||||
ImPlot::PlotScatter("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(float));
|
||||
ImPlot::PlotScatter("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(t_float));
|
||||
if (ImPlot::IsPlotQueried() && data.size() > 0) {
|
||||
ImPlotLimits range2 = ImPlot::GetPlotQuery();
|
||||
int cnt = 0;
|
||||
ImVec2 avg;
|
||||
t_float2 avg;
|
||||
for (int i = 0; i < data.size(); ++i) {
|
||||
if (range2.Contains(data[i])) {
|
||||
if (range2.Contains(data[i].x, data[i].y)) {
|
||||
avg.x += data[i].x;
|
||||
avg.y += data[i].y;
|
||||
cnt++;
|
||||
|
@ -493,22 +518,22 @@ void ShowDemoWindow(bool* p_open) {
|
|||
//-------------------------------------------------------------------------
|
||||
if (ImGui::CollapsingHeader("Views")) {
|
||||
// mimic's soulthread's imgui_plot demo
|
||||
static float x_data[512];
|
||||
static float y_data1[512];
|
||||
static float y_data2[512];
|
||||
static float y_data3[512];
|
||||
static float sampling_freq = 44100;
|
||||
static float freq = 500;
|
||||
static t_float x_data[512];
|
||||
static t_float y_data1[512];
|
||||
static t_float y_data2[512];
|
||||
static t_float y_data3[512];
|
||||
static t_float sampling_freq = 44100;
|
||||
static t_float freq = 500;
|
||||
for (size_t i = 0; i < 512; ++i) {
|
||||
const float t = i / sampling_freq;
|
||||
const t_float t = i / sampling_freq;
|
||||
x_data[i] = t;
|
||||
const float arg = 2 * 3.14f * freq * t;
|
||||
y_data1[i] = sin(arg);
|
||||
y_data2[i] = y_data1[i] * -0.6f + sin(2 * arg) * 0.4f;
|
||||
y_data3[i] = y_data2[i] * -0.6f + sin(3 * arg) * 0.4f;
|
||||
const t_float arg = 2 * 3.14f * freq * t;
|
||||
y_data1[i] = Sin(arg);
|
||||
y_data2[i] = y_data1[i] * -0.6f + Sin(2 * arg) * 0.4f;
|
||||
y_data3[i] = y_data2[i] * -0.6f + Sin(3 * arg) * 0.4f;
|
||||
}
|
||||
ImGui::BulletText("Query the first plot to render a subview in the second plot (see above for controls).");
|
||||
ImPlot::SetNextPlotLimits(0,0.01f,-1,1);
|
||||
ImPlot::SetNextPlotLimits(0,0.01,-1,1);
|
||||
ImPlotAxisFlags flgs = ImPlotAxisFlags_Default & ~ImPlotAxisFlags_TickLabels;
|
||||
ImPlotLimits query;
|
||||
if (ImPlot::BeginPlot("##View1",NULL,NULL,ImVec2(-1,150), ImPlotFlags_Default | ImPlotFlags_Query, flgs, flgs)) {
|
||||
|
@ -563,23 +588,23 @@ void ShowDemoWindow(bool* p_open) {
|
|||
}
|
||||
ImGui::EndGroup();
|
||||
ImGui::SameLine();
|
||||
static float t = 0;
|
||||
static t_float t = 0;
|
||||
if (!paused) {
|
||||
t += ImGui::GetIO().DeltaTime;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
if (show[i])
|
||||
data[i].AddPoint(t, data[i].Data.empty() ?
|
||||
0.25f + 0.5f * (float)rand() / float(RAND_MAX) :
|
||||
data[i].Data.back().y + (0.005f + 0.0002f * (float)rand() / float(RAND_MAX)) * (-1 + 2 * (float)rand() / float(RAND_MAX)));
|
||||
0.25f + 0.5f * (t_float)rand() / t_float(RAND_MAX) :
|
||||
data[i].Data.back().y + (0.005f + 0.0002f * (t_float)rand() / t_float(RAND_MAX)) * (-1 + 2 * (t_float)rand() / t_float(RAND_MAX)));
|
||||
}
|
||||
}
|
||||
ImPlot::SetNextPlotLimitsX(t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
|
||||
ImPlot::SetNextPlotLimitsX((double)t - 10, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
|
||||
if (ImPlot::BeginPlot("##DND")) {
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
if (show[i]) {
|
||||
char label[8];
|
||||
sprintf(label, "data_%d", i);
|
||||
ImPlot::PlotLine(label, &data[i].Data[0].x, &data[i].Data[0].y, data[i].Data.size(), data[i].Offset, 2 * sizeof(float));
|
||||
ImPlot::PlotLine(label, &data[i].Data[0].x, &data[i].Data[0].y, data[i].Data.size(), data[i].Offset, 2 * sizeof(t_float));
|
||||
}
|
||||
}
|
||||
ImPlot::EndPlot();
|
||||
|
@ -645,38 +670,38 @@ void ShowDemoWindow(bool* p_open) {
|
|||
}
|
||||
ImGui::EndGroup();
|
||||
ImGui::SameLine();
|
||||
static float t = 0;
|
||||
static t_float t = 0;
|
||||
if (!paused) {
|
||||
t += ImGui::GetIO().DeltaTime;
|
||||
//digital signal values
|
||||
int i = 0;
|
||||
if (showDigital[i])
|
||||
dataDigital[i].AddPoint(t, sin(2*t) > 0.45);
|
||||
dataDigital[i].AddPoint(t, Sin(2*t) > 0.45);
|
||||
i++;
|
||||
if (showDigital[i])
|
||||
dataDigital[i].AddPoint(t, sin(2*t) < 0.45);
|
||||
dataDigital[i].AddPoint(t, Sin(2*t) < 0.45);
|
||||
i++;
|
||||
if (showDigital[i])
|
||||
dataDigital[i].AddPoint(t, fmod(t,5.0f));
|
||||
dataDigital[i].AddPoint(t, Fmod(t,5.0f));
|
||||
i++;
|
||||
if (showDigital[i])
|
||||
dataDigital[i].AddPoint(t, sin(2*t) < 0.17);
|
||||
dataDigital[i].AddPoint(t, Sin(2*t) < 0.17);
|
||||
//Analog signal values
|
||||
i = 0;
|
||||
if (showAnalog[i])
|
||||
dataAnalog[i].AddPoint(t, sin(2*t));
|
||||
dataAnalog[i].AddPoint(t, Sin(2*t));
|
||||
i++;
|
||||
if (showAnalog[i])
|
||||
dataAnalog[i].AddPoint(t, cos(2*t));
|
||||
dataAnalog[i].AddPoint(t, Cos(2*t));
|
||||
i++;
|
||||
if (showAnalog[i])
|
||||
dataAnalog[i].AddPoint(t, sin(2*t) * cos(2*t));
|
||||
dataAnalog[i].AddPoint(t, Sin(2*t) * Cos(2*t));
|
||||
i++;
|
||||
if (showAnalog[i])
|
||||
dataAnalog[i].AddPoint(t, sin(2*t) - cos(2*t));
|
||||
dataAnalog[i].AddPoint(t, Sin(2*t) - Cos(2*t));
|
||||
}
|
||||
ImPlot::SetNextPlotLimitsY(-1, 1);
|
||||
ImPlot::SetNextPlotLimitsX(t - 10.0f, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
|
||||
ImPlot::SetNextPlotLimitsX(t - 10.0, t, paused ? ImGuiCond_Once : ImGuiCond_Always);
|
||||
if (ImPlot::BeginPlot("##Digital")) {
|
||||
for (int i = 0; i < K_PLOT_DIGITAL_CH_COUNT; ++i) {
|
||||
if (showDigital[i]) {
|
||||
|
@ -684,7 +709,7 @@ void ShowDemoWindow(bool* p_open) {
|
|||
sprintf(label, "digital_%d", i);
|
||||
ImPlot::PushStyleVar(ImPlotStyleVar_DigitalBitHeight, bitHeight);
|
||||
ImPlot::PushStyleVar(ImPlotStyleVar_DigitalBitGap, bitGap);
|
||||
ImPlot::PlotDigital(label, &dataDigital[i].Data[0].x, &dataDigital[i].Data[0].y, dataDigital[i].Data.size(), dataDigital[i].Offset, 2 * sizeof(float));
|
||||
ImPlot::PlotDigital(label, &dataDigital[i].Data[0].x, &dataDigital[i].Data[0].y, dataDigital[i].Data.size(), dataDigital[i].Offset, 2 * sizeof(t_float));
|
||||
ImPlot::PopStyleVar(2);
|
||||
}
|
||||
}
|
||||
|
@ -693,7 +718,7 @@ void ShowDemoWindow(bool* p_open) {
|
|||
char label[32];
|
||||
sprintf(label, "analog_%d", i);
|
||||
if (dataAnalog[i].Data.size() > 0)
|
||||
ImPlot::PlotLine(label, &dataAnalog[i].Data[0].x, &dataAnalog[i].Data[0].y, dataAnalog[i].Data.size(), dataAnalog[i].Offset, 2 * sizeof(float));
|
||||
ImPlot::PlotLine(label, &dataAnalog[i].Data[0].x, &dataAnalog[i].Data[0].y, dataAnalog[i].Data.size(), dataAnalog[i].Offset, 2 * sizeof(t_float));
|
||||
}
|
||||
}
|
||||
ImPlot::EndPlot();
|
||||
|
@ -717,10 +742,10 @@ void ShowDemoWindow(bool* p_open) {
|
|||
}
|
||||
//-------------------------------------------------------------------------
|
||||
if (ImGui::CollapsingHeader("Offset Data")) {
|
||||
float xs[50], ys[50];
|
||||
t_float xs[50], ys[50];
|
||||
for (int i = 0; i < 50; ++i) {
|
||||
xs[i] = 0.5f + 0.4f * cos(i/50.f * 6.28f);
|
||||
ys[i] = 0.5f + 0.4f * sin(i/50.f * 6.28f);
|
||||
xs[i] = 0.5f + 0.4f * Cos(i/50.f * 6.28f);
|
||||
ys[i] = 0.5f + 0.4f * Sin(i/50.f * 6.28f);
|
||||
}
|
||||
static int offset = 0;
|
||||
ImGui::SliderInt("Offset", &offset, -100, 100);
|
||||
|
@ -745,9 +770,9 @@ void ShowDemoWindow(bool* p_open) {
|
|||
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 2);
|
||||
ImPlot::SetNextPlotLimits(-0.5f, 9.5f, -0.5f, 9.5f);
|
||||
if (ImPlot::BeginPlot("##Custom", NULL, NULL, ImVec2(-1,0), ImPlotFlags_Default & ~ImPlotFlags_Legend, 0)) {
|
||||
float lin[10] = {8,8,9,7,8,8,8,9,7,8};
|
||||
float bar[10] = {1,2,5,3,4,1,2,5,3,4};
|
||||
float dot[10] = {7,6,6,7,8,5,6,5,8,7};
|
||||
t_float lin[10] = {8,8,9,7,8,8,8,9,7,8};
|
||||
t_float bar[10] = {1,2,5,3,4,1,2,5,3,4};
|
||||
t_float dot[10] = {7,6,6,7,8,5,6,5,8,7};
|
||||
ImPlot::PlotBars("Bar", bar, 10, 0.5f);
|
||||
ImPlot::PlotLine("Line", lin, 10);
|
||||
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 0);
|
||||
|
|
Loading…
Reference in New Issue
Block a user