Skip to content
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
14 changes: 14 additions & 0 deletions implot.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ typedef int ImPlotStemsFlags; // -> ImPlotStemsFlags_
typedef int ImPlotInfLinesFlags; // -> ImPlotInfLinesFlags_
typedef int ImPlotPieChartFlags; // -> ImPlotPieChartFlags_
typedef int ImPlotHeatmapFlags; // -> ImPlotHeatmapFlags_
typedef int ImPlotQuiverFlags; // -> ImPlotQuiverFlags_
typedef int ImPlotHistogramFlags; // -> ImPlotHistogramFlags_
typedef int ImPlotDigitalFlags; // -> ImPlotDigitalFlags_
typedef int ImPlotImageFlags; // -> ImPlotImageFlags_
Expand Down Expand Up @@ -309,6 +310,14 @@ enum ImPlotHeatmapFlags_ {
ImPlotHeatmapFlags_ColMajor = 1 << 10, // data will be read in column major order
};

// Flags 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 PlotHistogram and PlotHistogram2D
enum ImPlotHistogramFlags_ {
ImPlotHistogramFlags_None = 0, // default
Expand Down Expand Up @@ -915,6 +924,9 @@ IMPLOT_TMP void PlotPieChart(const char* const label_ids[], const T* values, int
// Plots a 2D heatmap chart. Values are expected to be in row-major order by default. Leave #scale_min and scale_max both at 0 for automatic color scaling, or set them to a predefined range. #label_fmt can be set to nullptr for no labels.
IMPLOT_TMP void PlotHeatmap(const char* label_id, const T* values, int rows, int cols, double scale_min=0, double scale_max=0, const char* label_fmt="%.1f", const ImPlotPoint& bounds_min=ImPlotPoint(0,0), const ImPlotPoint& bounds_max=ImPlotPoint(1,1), ImPlotHeatmapFlags 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 horizontal histogram. #bins can be a positive integer or an ImPlotBin_ method. If #range is left unspecified, the min/max of #values will be used as the range.
// Otherwise, outlier values outside of the range are not binned. The largest bin count or density is returned.
IMPLOT_TMP double PlotHistogram(const char* label_id, const T* values, int count, int bins=ImPlotBin_Sturges, double bar_scale=1.0, ImPlotRange range=ImPlotRange(), ImPlotHistogramFlags flags=0);
Expand Down Expand Up @@ -1142,6 +1154,8 @@ IMPLOT_API void SetNextFillStyle(const ImVec4& col = IMPLOT_AUTO_COL, float alph
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 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);
// Set the quiver style for the next item only.
IMPLOT_API void SetNextQuiverStyle(float size, const ImVec4& col = IMPLOT_AUTO_COL);

// Gets the last item primary color (i.e. its legend icon color)
IMPLOT_API ImVec4 GetLastItemColor();
Expand Down
80 changes: 80 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 @@ -737,6 +747,75 @@ void Demo_Heatmaps() {

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

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();
}

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

void Demo_Histogram() {
static ImPlotHistogramFlags hist_flags = ImPlotHistogramFlags_Density;
static int bins = 50;
Expand Down Expand Up @@ -2286,6 +2365,7 @@ void ShowDemoWindow(bool* p_open) {
DemoHeader("Infinite Lines", Demo_InfiniteLines);
DemoHeader("Pie Charts", Demo_PieCharts);
DemoHeader("Heatmaps", Demo_Heatmaps);
DemoHeader("Quiver Plots", Demo_QuiverPlots);
DemoHeader("Histogram", Demo_Histogram);
DemoHeader("Histogram 2D", Demo_Histogram2D);
DemoHeader("Digital Plots", Demo_DigitalPlots);
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