Skip to content

Commit

Permalink
Fix: linking of curve plot axes separated from bar plots
Browse files Browse the repository at this point in the history
(cherry picked from commit 422562d364f06fd99441b60d9b3a6bc71efe762d)
  • Loading branch information
dzid26 committed May 18, 2024
1 parent 3676a8e commit b391a55
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 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,20 @@ 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;
if (remainingSpace / (curvePlots + barPlots) < 300 )
remainingSpace = 300 * (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,12 +55,24 @@ 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)
Expand Down

0 comments on commit b391a55

Please sign in to comment.