Skip to content

Commit

Permalink
add stems and fix bug with marker size
Browse files Browse the repository at this point in the history
  • Loading branch information
epezent committed Sep 2, 2020
1 parent 624feda commit c8b21a6
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 65 deletions.
2 changes: 1 addition & 1 deletion implot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

// ImPlot v0.5 WIP
// ImPlot v0.6 WIP

/*
Expand Down
10 changes: 8 additions & 2 deletions implot.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

// ImPlot v0.5 WIP
// ImPlot v0.6 WIP

#pragma once
#include "imgui.h"
Expand All @@ -30,7 +30,7 @@
//-----------------------------------------------------------------------------

// ImPlot version string
#define IMPLOT_VERSION "0.5 WIP"
#define IMPLOT_VERSION "0.6 WIP"
// Indicates variable should deduced automatically.
#define IMPLOT_AUTO -1
// Special color used to indicate that a color should be deduced automatically.
Expand Down Expand Up @@ -348,6 +348,12 @@ void PlotErrorBarsH(const char* label_id, const double* xs, const double* ys, co
void PlotErrorBarsH(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 PlotErrorBarsH(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 vertical stems.
void PlotStems(const char* label_id, const float* values, int count, float y_ref = 0, int offset = 0, int stride = sizeof(float));
void PlotStems(const char* label_id, const double* values, int count, double y_ref = 0, int offset = 0, int stride = sizeof(double));
void PlotStems(const char* label_id, const float* xs, const float* ys, int count, float y_ref = 0, int offset = 0, int stride = sizeof(float));
void PlotStems(const char* label_id, const double* xs, const double* ys, int count, double y_ref = 0, int offset = 0, int stride = sizeof(double));

// Plots a pie chart. If the sum of values > 1 or normalize is true, each value will be normalized. Center and radius are in plot units. #label_fmt can be set to NULL for no labels.
void PlotPieChart(const char** label_ids, const float* values, int count, float x, float y, float radius, bool normalize = false, const char* label_fmt = "%.1f", float angle0 = 90);
void PlotPieChart(const char** label_ids, const double* values, int count, double x, double y, double radius, bool normalize = false, const char* label_fmt = "%.1f", double angle0 = 90);
Expand Down
25 changes: 22 additions & 3 deletions implot_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

// ImPlot v0.5 WIP
// ImPlot v0.6 WIP

#include "implot.h"
#include <math.h>
Expand Down Expand Up @@ -394,6 +394,25 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot();
}
}
if (ImGui::CollapsingHeader("Stem Plots")) {
static t_float xs[51], ys1[51], ys2[51];
for (int i = 0; i < 51; ++i) {
xs[i] = i * 0.02f;
ys1[i] = 1.0f + 0.5f * Sin(25*xs[i])*Cos(2*xs[i]);
ys2[i] = 0.5f + 0.25f * Sin(10*xs[i]) * Sin(xs[i]);
}
ImPlot::SetNextPlotLimits(0,1,0,1.6);
if (ImPlot::BeginPlot("Stem Plots")) {

ImPlot::PlotStems("Stems 1",xs,ys1,51);

ImPlot::SetNextLineStyle(ImVec4(1,0.5f,0,0.75f));
ImPlot::SetNextMarkerStyle(ImPlotMarker_Square,5,ImVec4(1,0.5f,0,0.25f));
ImPlot::PlotStems("Stems 2", xs, ys2,51);

ImPlot::EndPlot();
}
}
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Pie Charts")) {
static const char* labels1[] = {"Frogs","Hogs","Dogs","Logs"};
Expand Down Expand Up @@ -1301,10 +1320,10 @@ namespace ImPlot {

struct BenchmarkItem {
BenchmarkItem() {
float y = RandomRange(0,1);
float y = (float)RandomRange(0,1);
Data = new float[1000];
for (int i = 0; i < 1000; ++i) {
Data[i] = y + RandomRange(-0.01f,0.01f);
Data[i] = y + (float)RandomRange(-0.01f,0.01f);
}
Col = ImVec4((float)RandomRange(0,1),(float)RandomRange(0,1),(float)RandomRange(0,1),1);
}
Expand Down
16 changes: 8 additions & 8 deletions implot_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

// ImPlot v0.5 WIP
// ImPlot v0.6 WIP

// You may use this file to debug, understand or extend ImPlot features but we
// don't provide any guarantee of forward compatibility!
Expand Down Expand Up @@ -134,12 +134,12 @@ struct ImBufferWriter
}
};

// Fixed size array
template <typename T, int N>
struct ImArray {
inline T& operator[](int i) { return Data[i]; }
inline const T& operator[](int i) const { return Data[i]; }
T Data[N];
// Fixed size point array
template <int N>
struct ImPlotPointArray {
inline ImPlotPoint& operator[](int i) { return Data[i]; }
inline const ImPlotPoint& operator[](int i) const { return Data[i]; }
ImPlotPoint Data[N];
const int Size = N;
};

Expand Down Expand Up @@ -388,7 +388,7 @@ struct ImPlotItemStyle {
ImPlotItemStyle() {
for (int i = 0; i < 5; ++i)
Colors[i] = IMPLOT_AUTO_COL;
LineWeight = MarkerWeight = FillAlpha = ErrorBarSize =
LineWeight = MarkerSize = MarkerWeight = FillAlpha = ErrorBarSize =
ErrorBarSize = ErrorBarWeight = DigitalBitHeight = DigitalBitGap = IMPLOT_AUTO;
Marker = IMPLOT_AUTO;
}
Expand Down
Loading

0 comments on commit c8b21a6

Please sign in to comment.