Commit 7788e556 authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

implot: add new plot library

parent 16d22725
Pipeline #15048 passed with stage
in 1 minute and 7 seconds
......@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(irritator-gui VERSION 0.1.0 LANGUAGES CXX)
set(gui_sources
dialog-file.cpp gui.hpp imnodes.cpp imnodes.hpp window-logger.cpp
node-editor.hpp node-editor.cpp
dialog-file.cpp gui.hpp imnodes.cpp imnodes.hpp implot.h implot.cpp
window-logger.cpp node-editor.hpp node-editor.cpp
${PROJECT_SOURCE_DIR}/../../external/imgui/imgui.cpp
${PROJECT_SOURCE_DIR}/../../external/imgui/imgui.h
${PROJECT_SOURCE_DIR}/../../external/imgui/imgui_demo.cpp
......
This diff is collapsed.
This diff is collapsed.
......@@ -10,6 +10,7 @@
#include "node-editor.hpp"
#include "gui.hpp"
#include "imnodes.hpp"
#include "implot.h"
#include <fstream>
#include <string>
......@@ -38,8 +39,7 @@ static auto automatic_layout_y_distance = 350.f;
static auto grid_layout_x_distance = 250.f;
static auto grid_layout_y_distance = 250.f;
static ImVec4
operator*(const ImVec4& lhs, const float rhs) noexcept
static ImVec4 operator*(const ImVec4& lhs, const float rhs) noexcept
{
return ImVec4(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs, lhs.w * rhs);
}
......@@ -659,8 +659,9 @@ struct copier
auto ret = sim.dispatch(
mdl->type,
[this, &sim, mdl, &mdl_id_dst]<typename DynamicsM>(
DynamicsM& dynamics_models) -> status {
[ this, &sim, mdl, &
mdl_id_dst ]<typename DynamicsM>(DynamicsM & dynamics_models)
->status {
using Dynamics = typename DynamicsM::value_type;
irt_return_if_fail(dynamics_models.can_alloc(1),
......@@ -2618,12 +2619,52 @@ node_editor_initialize()
}
}
void
show_plot_box(bool* show_plot)
{
// static editor_id current_editor_id = static_cast<editor_id>(0);
ImGui::SetNextWindowSize(ImVec2(400, 400), ImGuiCond_Always);
if (!ImGui::Begin("Plot", show_plot)) {
ImGui::End();
return;
}
if (ImGui::CollapsingHeader("Line Plots")) {
static float xs1[1001], ys1[1001];
for (int i = 0; i < 1001; ++i) {
xs1[i] = (float)i * 0.001f;
ys1[i] = 0.5f + 0.5f * std::sin(50 * xs1[i]);
}
static float xs2[11], ys2[11];
for (int i = 0; i < 11; ++i) {
xs2[i] = (float)i * 0.1f;
ys2[i] = xs2[i] * xs2[i];
}
static float weight = ImPlot::GetStyle().LineWeight;
ImGui::BulletText("Anti-aliasing can be enabled from the plot's "
"context menu (see Help).");
ImGui::DragFloat("Line Weight", &weight, 0.05f, 1.0f, 5.0f, "%.2f px");
if (ImPlot::BeginPlot("Line Plot", "x", "f(x)")) {
ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, weight);
ImPlot::PlotLine("0.5 + 0.5*sin(50*x)", xs1, ys1, 1001);
ImPlot::PushStyleVar(ImPlotStyleVar_Marker, ImPlotMarker_Circle);
ImPlot::PlotLine("x^2", xs2, ys2, 11);
ImPlot::PopStyleVar(2);
ImPlot::EndPlot();
}
}
ImGui::End();
}
bool
node_editor_show()
{
static bool show_log = true;
static bool show_simulation = true;
static bool show_demo = false;
static bool show_plot = false;
static bool show_settings = false;
bool ret = true;
......@@ -2647,7 +2688,7 @@ node_editor_show()
ImGui::MenuItem(ed->name.c_str(), nullptr, &ed->show);
ImGui::MenuItem("Simulation", nullptr, &show_simulation);
ImGui::MenuItem("Plot", nullptr, &show_plot);
ImGui::MenuItem("Settings", nullptr, &show_settings);
ImGui::MenuItem("Log", nullptr, &show_log);
......@@ -2680,6 +2721,9 @@ node_editor_show()
if (show_simulation)
show_simulation_box(&show_simulation);
if (show_plot)
show_plot_box(&show_plot);
if (show_demo)
ImGui::ShowDemoWindow();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment