mirror of
https://github.com/gwm17/implot.git
synced 2024-11-22 18:28:53 -05:00
use different types in demo
This commit is contained in:
parent
2eeceb3e22
commit
8fdeacac54
2
implot.h
2
implot.h
|
@ -330,6 +330,8 @@ template <typename T> void PlotBarsH(const char* label_id, const T* values, int
|
|||
template <typename T> void PlotBarsH(const char* label_id, const T* xs, const T* ys, int count, double height, int offset = 0, int stride = sizeof(T));
|
||||
void PlotBarsHG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, double height, int offset = 0);
|
||||
|
||||
// TODO ...
|
||||
|
||||
// Plots vertical error bar. The label_id should be the same as the label_id of the associated line or bar plot.
|
||||
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 double* xs, const double* ys, const double* err, int count, int offset = 0, int stride = sizeof(double));
|
||||
|
|
|
@ -246,12 +246,12 @@ void ShowDemoWindow(bool* p_open) {
|
|||
}
|
||||
//-------------------------------------------------------------------------
|
||||
if (ImGui::CollapsingHeader("Line Plots")) {
|
||||
static t_float xs1[1001], ys1[1001];
|
||||
static 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] + DEMO_TIME / 10));
|
||||
ys1[i] = 0.5f + 0.5f * sinf(50 * (xs1[i] + DEMO_TIME / 10));
|
||||
}
|
||||
static t_float xs2[11], ys2[11];
|
||||
static double xs2[11], ys2[11];
|
||||
for (int i = 0; i < 11; ++i) {
|
||||
xs2[i] = i * 0.1f;
|
||||
ys2[i] = xs2[i] * xs2[i];
|
||||
|
@ -349,12 +349,15 @@ void ShowDemoWindow(bool* p_open) {
|
|||
}
|
||||
//-------------------------------------------------------------------------
|
||||
if (ImGui::CollapsingHeader("Bar Plots")) {
|
||||
|
||||
static bool horz = false;
|
||||
static ImS8 midtm[10] = {83, 67, 23, 89, 83, 78, 91, 82, 85, 90};
|
||||
static ImS16 final[10] = {80, 62, 56, 99, 55, 78, 88, 78, 90, 100};
|
||||
static ImS32 grade[10] = {80, 69, 52, 92, 72, 78, 75, 76, 89, 95};
|
||||
|
||||
static const char* labels[] = {"S1","S2","S3","S4","S5","S6","S7","S8","S9","S10"};
|
||||
static const double positions[] = {0,1,2,3,4,5,6,7,8,9};
|
||||
static bool horz = false;
|
||||
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};
|
||||
|
||||
ImGui::Checkbox("Horizontal",&horz);
|
||||
|
||||
if (horz) {
|
||||
|
@ -369,14 +372,14 @@ void ShowDemoWindow(bool* p_open) {
|
|||
ImVec2(-1,0), 0, 0, horz ? ImPlotAxisFlags_Invert : 0))
|
||||
{
|
||||
if (horz) {
|
||||
ImPlot::PlotBarsH("Midterm Exam", midtm, 10, 0.2f, -0.2f);
|
||||
ImPlot::PlotBarsH("Final Exam", final, 10, 0.2f, 0);
|
||||
ImPlot::PlotBarsH("Course Grade", grade, 10, 0.2f, 0.2f);
|
||||
ImPlot::PlotBarsH("Midterm Exam", midtm, 10, 0.2, -0.2);
|
||||
ImPlot::PlotBarsH("Final Exam", final, 10, 0.2, 0);
|
||||
ImPlot::PlotBarsH("Course Grade", grade, 10, 0.2, 0.2);
|
||||
}
|
||||
else {
|
||||
ImPlot::PlotBars("Midterm Exam", midtm, 10, 0.2f, -0.2f);
|
||||
ImPlot::PlotBars("Final Exam", final, 10, 0.2f, 0);
|
||||
ImPlot::PlotBars("Course Grade", grade, 10, 0.2f, 0.2f);
|
||||
ImPlot::PlotBars("Midterm Exam", midtm, 10, 0.2, -0.2);
|
||||
ImPlot::PlotBars("Final Exam", final, 10, 0.2, 0);
|
||||
ImPlot::PlotBars("Course Grade", grade, 10, 0.2, 0.2);
|
||||
}
|
||||
ImPlot::EndPlot();
|
||||
}
|
||||
|
|
|
@ -1227,6 +1227,7 @@ template void PlotBarsH<ImS64>(const char* label_id, const ImS64* xs, const ImS6
|
|||
template void PlotBarsH<ImU64>(const char* label_id, const ImU64* xs, const ImU64* ys, int count, double height, int offset, int stride);
|
||||
template void PlotBarsH<float>(const char* label_id, const float* xs, const float* ys, int count, double height, int offset, int stride);
|
||||
template void PlotBarsH<double>(const char* label_id, const double* xs, const double* ys, int count, double height, int offset, int stride);
|
||||
|
||||
// custom
|
||||
void PlotBarsHG(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, double height, int offset) {
|
||||
GetterFuncPtrImPlotPoint getter(getter_func, data, count, offset);
|
||||
|
|
Loading…
Reference in New Issue
Block a user