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

Fix linking curve plot axes #68

Closed
wants to merge 2 commits into from
Closed
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
44 changes: 31 additions & 13 deletions src/Gui/GuiPlots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ void Gui::dragAndDropPlot(Plot* plot)

void Gui::drawPlots()
{
uint32_t tablePlots = 0;
uint8_t tablePlots = 0;
uint8_t barPlots = 0;
uint8_t curvePlots = 0;

ImVec2 initialCursorPos = ImGui::GetCursorPos();

Expand All @@ -31,17 +33,21 @@ void Gui::drawPlots()
if (plt->getVisibility())
tablePlots++;
}
else if (plt->getType() == Plot::Type::BAR && plt->getVisibility())
barPlots++;
else if (plt->getType() == Plot::Type::CURVE && plt->getVisibility())
curvePlots++;
}
curvePlots = (barPlots + curvePlots > 0) ? curvePlots : 1;

uint32_t curveBarPlotsCnt = plotHandler->getVisiblePlotsCount() - tablePlots;
uint32_t row = curveBarPlotsCnt > 0 ? curveBarPlotsCnt : 1;
float remainingSpace = (ImGui::GetWindowPos().y + ImGui::GetWindowSize().y) - (ImGui::GetCursorPos().y + initialCursorPos.y) - ImGui::GetStyle().WindowPadding.y * 3;
const float minSubPlotHeight = 237; //calibrated to show 4 subplots without a scrollbar on a FUllHD monitor
if (remainingSpace / (curvePlots + barPlots) < minSubPlotHeight )
remainingSpace = minSubPlotHeight * (curvePlots + barPlots);
ImVec2 curvePlotSize(-1, remainingSpace * curvePlots / (curvePlots + barPlots));
ImVec2 barPlotSize(-1, remainingSpace * barPlots / (curvePlots + barPlots));

const float remainingSpace = (ImGui::GetWindowPos().y + ImGui::GetWindowSize().y) - (ImGui::GetCursorPos().y + initialCursorPos.y);
ImVec2 plotSize(-1, -1);
if (remainingSpace < 300)
plotSize.y = 300;

if (ImPlot::BeginSubplots("##subplos", row, 1, plotSize, 0))
if (curvePlots && ImPlot::BeginSubplots("##curveplots", curvePlots, 1, curvePlotSize, 0))
{
for (std::shared_ptr<Plot> plt : *plotHandler)
{
Expand All @@ -50,17 +56,29 @@ void Gui::drawPlots()

if (plt->getType() == Plot::Type::CURVE)
drawPlotCurve(plt.get(), plt->getTimeSeries(), plt->getSeriesMap(), tablePlots);
else if (plt->getType() == Plot::Type::BAR)
drawPlotBar(plt.get(), plt->getTimeSeries(), plt->getSeriesMap(), tablePlots);
}

ImPlot::EndSubplots();
}

if (barPlots && ImPlot::BeginSubplots("##barplots", barPlots, 1, barPlotSize, 0))
{
for (std::shared_ptr<Plot> plt : *plotHandler)
{
if (!plt->getVisibility())
continue;

if (plt->getType() == Plot::Type::BAR)
drawPlotBar(plt.get(), plt->getTimeSeries(), plt->getSeriesMap(), tablePlots);
}

ImPlot::EndSubplots();
}
}

void Gui::drawPlotCurve(Plot* plot, ScrollingBuffer<double>& time, std::map<std::string, std::shared_ptr<Plot::Series>>& seriesMap, uint32_t curveBarPlots)
{
if (ImPlot::BeginPlot(plot->getName().c_str(), ImVec2(-1, -1), ImPlotFlags_NoChild))
if (ImPlot::BeginPlot(plot->getName().c_str(), ImVec2(-1, -1), ImPlotFlags_None))
{
if (plotHandler->getViewerState() == PlotHandler::state::RUN)
{
Expand Down Expand Up @@ -136,7 +154,7 @@ void Gui::drawPlotCurve(Plot* plot, ScrollingBuffer<double>& time, std::map<std:
}
void Gui::drawPlotBar(Plot* plot, ScrollingBuffer<double>& time, std::map<std::string, std::shared_ptr<Plot::Series>>& seriesMap, uint32_t curveBarPlots)
{
if (ImPlot::BeginPlot(plot->getName().c_str(), ImVec2(-1, -1), ImPlotFlags_NoChild))
if (ImPlot::BeginPlot(plot->getName().c_str(), ImVec2(-1, -1), ImPlotFlags_None))
{
std::vector<const char*> glabels;
std::vector<double> positions;
Expand Down