Skip to content
Open
Show file tree
Hide file tree
Changes from 11 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
14 changes: 14 additions & 0 deletions implot.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ typedef int ImPlotColormapScaleFlags; // -> ImPlotColormapScaleFlags_
typedef int ImPlotItemFlags; // -> ImPlotItemFlags_
typedef int ImPlotLineFlags; // -> ImPlotLineFlags_
typedef int ImPlotScatterFlags; // -> ImPlotScatterFlags
typedef int ImPlotQuiverFlags; // -> ImPlotQuiverFlags_
typedef int ImPlotStairsFlags; // -> ImPlotStairsFlags_
typedef int ImPlotShadedFlags; // -> ImPlotShadedFlags_
typedef int ImPlotBarsFlags; // -> ImPlotBarsFlags_
Expand Down Expand Up @@ -246,6 +247,14 @@ enum ImPlotScatterFlags_ {
ImPlotScatterFlags_NoClip = 1 << 10, // markers on the edge of a plot will not be clipped
};

// Flgs for PlotQuiver
enum ImPlotQuiverFlags_ {
ImPlotQuiverFlags_None = 0, // default
ImPlotQuiverFlags_NoClip = 1 << 10, // arrows on the edge of a plot will not be clipped
ImPlotQuiverFlags_FixedSize = 1 << 11, // all arrows will have the same size
ImPlotQuiverFlags_ColorByMagnitude = 1 << 12 // arrow colors will be mapped to their magnitudes
};

// Flags for PlotStairs
enum ImPlotStairsFlags_ {
ImPlotStairsFlags_None = 0, // default
Expand Down Expand Up @@ -868,6 +877,9 @@ 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 standard 2D quiver plot. The direction and magnitude of the arrows are determined by #us and #vs. Set #mag_min and #mag_max to specify a range of magnitudes to map to the arrow colors. Set mag_min = mag_max = 0 to use the full colormap range.
IMPLOT_TMP void PlotQuiver(const char* label_id, const T* xs, const T* ys,const T* us, const T* vs, int count, double mag_min=0, double mag_max=0, ImPlotQuiverFlags flags=0, int offset=0, int stride=sizeof(T));

// 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 Expand Up @@ -1130,6 +1142,8 @@ IMPLOT_API void SetNextLineStyle(const ImVec4& col = IMPLOT_AUTO_COL, float weig
IMPLOT_API void SetNextFillStyle(const ImVec4& col = IMPLOT_AUTO_COL, float alpha_mod = IMPLOT_AUTO);
// Set the marker style for the next item only.
IMPLOT_API void SetNextMarkerStyle(ImPlotMarker marker = IMPLOT_AUTO, float size = IMPLOT_AUTO, const ImVec4& fill = IMPLOT_AUTO_COL, float weight = IMPLOT_AUTO, const ImVec4& outline = IMPLOT_AUTO_COL);
// Set the quiver style for the next item only.
IMPLOT_API void SetNextQuiverStyle(float size, const ImVec4& col = IMPLOT_AUTO_COL);
// Set the error bar style for the next item only.
IMPLOT_API void SetNextErrorBarStyle(const ImVec4& col = IMPLOT_AUTO_COL, float size = IMPLOT_AUTO, float weight = IMPLOT_AUTO);

Expand Down
79 changes: 79 additions & 0 deletions implot_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ void StyleSeaborn();

namespace ImPlot {

static void HelpMarker(const char* desc) {
ImGui::TextDisabled("(?)");
if (ImGui::BeginItemTooltip()) {
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
ImGui::TextUnformatted(desc);
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
}

template <typename T>
inline T RandomRange(T min, T max) {
T scale = rand() / (T) RAND_MAX;
Expand Down Expand Up @@ -415,6 +425,74 @@ void Demo_ScatterPlots() {
ImPlot::EndPlot();
}
}
//-----------------------------------------------------------------------------

void Demo_QuiverPlots(){
static float xs[100], ys[100], us[100], vs[100];
for (int i = 0; i < 10; ++i) {
for(int j = 0; j < 10; ++j){
int idx = i*10 + j;
xs[idx] = ((float)j * 0.1f) - 0.5;
ys[idx] = ((float)i * 0.1f) - 0.5;

// Taylor-Green vortex
float k = 2.0f * 3.14159f;
us[idx] = sinf(k * xs[idx]) * cosf(k * ys[idx]);
vs[idx] = -cosf(k * xs[idx]) * sinf(k * ys[idx]);
}
}

static float mag_min = 0.00f;
static float mag_max = 1.0f;
static float base_size = 12.0f;
static ImPlotColormap map = ImPlotColormap_Viridis;

if (ImPlot::ColormapButton(ImPlot::GetColormapName(map), ImVec2(225,0), map)) {
map = (map + 1) % ImPlot::GetColormapCount();
}
ImGui::SameLine();
ImGui::LabelText("##Colormap Index", "%s", "Change Colormap");

ImGui::SetNextItemWidth(225);
ImGui::DragFloatRange2("Min / Max Magnitude", &mag_min, &mag_max, 0.01f, -20, 20,nullptr,nullptr,ImGuiSliderFlags_AlwaysClamp);
if (mag_max < mag_min) {
mag_max = mag_min;
}
ImGui::SameLine();
HelpMarker("Minumum and maximum magnitudes for color mapping");

ImGui::SetNextItemWidth(225);
ImGui::DragFloat("Base Size", &base_size, 0.1f, 0, 100);
ImGui::SameLine();
HelpMarker("Maximum arrow size in pixels. The actual size will depend on the arrow's magnitude");

static ImPlotQuiverFlags qv_flags = ImPlotQuiverFlags_ColorByMagnitude;

CHECKBOX_FLAG(qv_flags, ImPlotQuiverFlags_NoClip);
ImGui::SameLine();
HelpMarker("Arrows on the edge of the plot will not be clipped");

CHECKBOX_FLAG(qv_flags, ImPlotQuiverFlags_FixedSize);
ImGui::SameLine();
HelpMarker("All arrows will have the length set to base size");

CHECKBOX_FLAG(qv_flags, ImPlotQuiverFlags_ColorByMagnitude);
ImGui::SameLine();
HelpMarker("Arrow will be colored by on their magnitudes");

ImPlot::PushColormap(map);
if (ImPlot::BeginPlot("Quiver Plot", ImVec2(ImGui::GetTextLineHeight()*28, ImGui::GetTextLineHeight()*28))) {
ImPlot::SetupAxisTicks(ImAxis_X1, -0.5, 0.5, 11);
ImPlot::SetupAxisTicks(ImAxis_Y1, -0.5, 0.5, 11);
ImPlot::SetNextQuiverStyle(base_size, ImPlot::GetColormapColor(1));
ImPlot::SetupAxes("x", "y");
ImPlot::PlotQuiver("Magnitude", xs, ys, us, vs, 100, mag_min, mag_max, qv_flags);
ImPlot::EndPlot();
}
ImGui::SameLine();
ImPlot::ColormapScale("##QuiverScale", mag_min, mag_max);
ImPlot::PopColormap();
}

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

Expand Down Expand Up @@ -2248,6 +2326,7 @@ void ShowDemoWindow(bool* p_open) {
DemoHeader("Filled Line Plots", Demo_FilledLinePlots);
DemoHeader("Shaded Plots##", Demo_ShadedPlots);
DemoHeader("Scatter Plots", Demo_ScatterPlots);
DemoHeader("Quiver Plots", Demo_QuiverPlots);
DemoHeader("Realtime Plots", Demo_RealtimePlots);
DemoHeader("Stairstep Plots", Demo_StairstepPlots);
DemoHeader("Bar Plots", Demo_BarPlots);
Expand Down
2 changes: 2 additions & 0 deletions implot_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,7 @@ struct ImPlotNextItemData {
ImPlotMarker Marker;
float MarkerSize;
float MarkerWeight;
float QuiverSize;
float FillAlpha;
float ErrorBarSize;
float ErrorBarWeight;
Expand All @@ -1218,6 +1219,7 @@ struct ImPlotNextItemData {
LineWeight = MarkerSize = MarkerWeight = FillAlpha = ErrorBarSize = ErrorBarWeight = DigitalBitHeight = DigitalBitGap = IMPLOT_AUTO;
Marker = IMPLOT_AUTO;
HasHidden = Hidden = false;

}
};

Expand Down
Loading