Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PlotBubbles #611

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The list below represents a combination of high-priority work, nice-to-have feat

## Plot Items

- add `PlotBubbles` (see MATLAB bubble chart)
- add legend for `PlotBubbles` (see MATLAB bubble chart)
- add non-zero references for `PlotBars` etc.
- fix appearance of `PlotBars` spacing

Expand Down
25 changes: 25 additions & 0 deletions implot.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ typedef int ImPlotColormapScaleFlags; // -> ImPlotColormapScaleFlags_
typedef int ImPlotItemFlags; // -> ImPlotItemFlags_
typedef int ImPlotLineFlags; // -> ImPlotLineFlags_
typedef int ImPlotScatterFlags; // -> ImPlotScatterFlags
typedef int ImPlotBubblesFlags; // -> ImPlotBubblesFlags
typedef int ImPlotStairsFlags; // -> ImPlotStairsFlags_
typedef int ImPlotShadedFlags; // -> ImPlotShadedFlags_
typedef int ImPlotBarsFlags; // -> ImPlotBarsFlags_
Expand Down Expand Up @@ -242,6 +243,12 @@ enum ImPlotScatterFlags_ {
ImPlotScatterFlags_NoClip = 1 << 10, // markers on the edge of a plot will not be clipped
};

// Flags for PlotBubbles
enum ImPlotBubblesFlags_ {
ImPlotBubblesFlags_None = 0, // default
ImPlotBubblesFlags_NoClip = 1 << 10, // markers on the edge of a plot will not be clipped
};

// Flags for PlotStairs
enum ImPlotStairsFlags_ {
ImPlotStairsFlags_None = 0, // default
Expand Down Expand Up @@ -481,6 +488,18 @@ struct ImPlotPoint {
};
IM_MSVC_RUNTIME_CHECKS_RESTORE

// Double precision point with three coordinates used by ImPlot.
IM_MSVC_RUNTIME_CHECKS_OFF
struct ImPlotPoint3D {
double x, y, z;
constexpr ImPlotPoint3D() : x(0.0), y(0.0), z(0.0) { }
constexpr ImPlotPoint3D(double _x, double _y, double _z) : x(_x), y(_y), z(_z) { }
double& operator[] (size_t idx) { IM_ASSERT(idx == 0 || idx == 1 || idx == 2); return ((double*)(void*)(char*)this)[idx]; }
double operator[] (size_t idx) const { IM_ASSERT(idx == 0 || idx == 1 || idx == 2); return ((const double*)(const void*)(const char*)this)[idx]; }

};
IM_MSVC_RUNTIME_CHECKS_RESTORE

// Range defined by a min/max value.
struct ImPlotRange {
double Min, Max;
Expand Down Expand Up @@ -588,6 +607,7 @@ typedef int (*ImPlotFormatter)(double value, char* buff, int size, void* user_da

// Callback signature for data getter.
typedef ImPlotPoint (*ImPlotGetter)(int idx, void* user_data);
typedef ImPlotPoint3D (*ImPlotGetter3D)(int idx, void* user_data);

// Callback signature for axis transform.
typedef double (*ImPlotTransform)(double value, void* user_data);
Expand Down Expand Up @@ -864,6 +884,11 @@ IMPLOT_TMP void PlotScatter(const char* label_id, const T* values, int count, do
IMPLOT_TMP void PlotScatter(const char* label_id, const T* xs, const T* ys, int count, ImPlotScatterFlags flags=0, int offset=0, int stride=sizeof(T));
IMPLOT_API void PlotScatterG(const char* label_id, ImPlotGetter getter, void* data, int count, ImPlotScatterFlags flags=0);

// Plots a bubble graph. Default marker is ImPlotMarker_Circle.
IMPLOT_TMP void PlotBubbles(const char* label_id, const T* values, const T* szs, int count, double xscale=1, double xstart=0, ImPlotBubblesFlags flags=0, float min_pxsize=3, float max_pxsize=50, int offset=0, int stride=sizeof(T));
IMPLOT_TMP void PlotBubbles(const char* label_id, const T* xs, const T* ys, const T* szs, int count, ImPlotBubblesFlags flags=0, float min_pxsize=3, float max_pxsize=50, int offset=0, int stride=sizeof(T));
IMPLOT_API void PlotBubblesG(const char* label_id, ImPlotGetter3D getter, void* data, int count, ImPlotBubblesFlags flags=0, float min_pxsize=3, float max_pxsize=50);

// Plots a a stairstep graph. The y value is continued constantly to the right from every x position, i.e. the interval [x[i], x[i+1]) has the value y[i]
IMPLOT_TMP void PlotStairs(const char* label_id, const T* values, int count, double xscale=1, double xstart=0, ImPlotStairsFlags flags=0, int offset=0, int stride=sizeof(T));
IMPLOT_TMP void PlotStairs(const char* label_id, const T* xs, const T* ys, int count, ImPlotStairsFlags flags=0, int offset=0, int stride=sizeof(T));
Expand Down
24 changes: 24 additions & 0 deletions implot_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,29 @@ void Demo_ScatterPlots() {

//-----------------------------------------------------------------------------

void Demo_BubblePlots() {
srand(0);
static float xs[20], ys1[20], ys2[20], szs1[20], szs2[20];
for (int i = 0; i < 20; ++i) {
xs[i] = i * 0.01f;
ys1[i] = (float)rand() / (float)RAND_MAX;
ys2[i] = 0.5f + 0.3f * (2.0f * ((float)rand() / (float)RAND_MAX) - 1.0f);

szs1[i] = 10.0f + 1000.0f * ((float)rand() / (float)RAND_MAX);
szs2[i] = 5.0f + 200.0f * ((float)rand() / (float)RAND_MAX);
}


if (ImPlot::BeginPlot("Bubble Plot")) {
ImPlot::PlotBubbles("Data 1", xs, ys1, szs1, 20);
ImPlot::SetNextMarkerStyle(IMPLOT_AUTO, IMPLOT_AUTO, IMPLOT_AUTO_COL, 1, IMPLOT_AUTO_COL);
ImPlot::PlotBubbles("Data 2", xs, ys2, szs2, 20, ImPlotBubblesFlags_None, 5, 20);
ImPlot::EndPlot();
}
}

//-----------------------------------------------------------------------------

void Demo_StairstepPlots() {
static float ys1[21], ys2[21];
for (int i = 0; i < 21; ++i) {
Expand Down Expand Up @@ -2231,6 +2254,7 @@ void ShowDemoWindow(bool* p_open) {
DemoHeader("Filled Line Plots", Demo_FilledLinePlots);
DemoHeader("Shaded Plots##", Demo_ShadedPlots);
DemoHeader("Scatter Plots", Demo_ScatterPlots);
DemoHeader("Bubble Plots", Demo_BubblePlots);
DemoHeader("Realtime Plots", Demo_RealtimePlots);
DemoHeader("Stairstep Plots", Demo_StairstepPlots);
DemoHeader("Bar Plots", Demo_BarPlots);
Expand Down
Loading