From 6ced9ab760dfda4df860c9433fa8566dc66cc225 Mon Sep 17 00:00:00 2001 From: Jonathan Hoffstadt Date: Thu, 13 Aug 2020 12:06:10 -0500 Subject: [PATCH] [PLOTS] check if plot commands are called on actual plots --- DearPyGui/src/Core/mvMarvel.cpp | 114 ++++++++++++++++++++++++++++++++ DearSandbox/Demo.py | 2 - 2 files changed, 114 insertions(+), 2 deletions(-) diff --git a/DearPyGui/src/Core/mvMarvel.cpp b/DearPyGui/src/Core/mvMarvel.cpp index 0fd130322..d38095fe5 100644 --- a/DearPyGui/src/Core/mvMarvel.cpp +++ b/DearPyGui/src/Core/mvMarvel.cpp @@ -862,6 +862,14 @@ namespace Marvel { ThrowPythonException(message + " plot does not exist."); return mvPythonTranslator::GetPyNone(); } + + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } + mvPlot* graph = static_cast(aplot); graph->clear(); @@ -883,6 +891,14 @@ namespace Marvel { ThrowPythonException(message + " plot does not exist."); return mvPythonTranslator::GetPyNone(); } + + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } + mvPlot* graph = static_cast(aplot); graph->resetXTicks(); @@ -904,6 +920,14 @@ namespace Marvel { ThrowPythonException(message + " plot does not exist."); return mvPythonTranslator::GetPyNone(); } + + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } + mvPlot* graph = static_cast(aplot); graph->resetXTicks(); @@ -926,6 +950,14 @@ namespace Marvel { ThrowPythonException(message + " plot does not exist."); return mvPythonTranslator::GetPyNone(); } + + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } + mvPlot* graph = static_cast(aplot); auto mlabel_pairs = mvPythonTranslator::ToVectPairStringFloat(label_pairs); @@ -959,6 +991,14 @@ namespace Marvel { ThrowPythonException(message + " plot does not exist."); return mvPythonTranslator::GetPyNone(); } + + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } + mvPlot* graph = static_cast(aplot); auto mlabel_pairs = mvPythonTranslator::ToVectPairStringFloat(label_pairs); @@ -991,6 +1031,13 @@ namespace Marvel { ThrowPythonException(message + " plot does not exist."); return mvPythonTranslator::GetPyNone(); } + + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } mvPlot* graph = static_cast(aplot); graph->setXLimitsAuto(); @@ -1012,6 +1059,14 @@ namespace Marvel { ThrowPythonException(message + " plot does not exist."); return mvPythonTranslator::GetPyNone(); } + + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } + mvPlot* graph = static_cast(aplot); graph->setYLimitsAuto(); @@ -1035,6 +1090,14 @@ namespace Marvel { ThrowPythonException(message + " plot does not exist."); return mvPythonTranslator::GetPyNone(); } + + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } + mvPlot* graph = static_cast(aplot); graph->setXLimits(xmin, xmax); @@ -1058,6 +1121,13 @@ namespace Marvel { ThrowPythonException(message + " plot does not exist."); return mvPythonTranslator::GetPyNone(); } + + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } mvPlot* graph = static_cast(aplot); graph->setYLimits(ymin, ymax); @@ -1079,6 +1149,13 @@ namespace Marvel { ThrowPythonException(message + " plot does not exist."); return mvPythonTranslator::GetPyNone(); } + + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } mvPlot* graph = static_cast(aplot); return Py_BuildValue("b", graph->isPlotQueried()); @@ -1098,6 +1175,13 @@ namespace Marvel { ThrowPythonException(message + " plot does not exist."); return mvPythonTranslator::GetPyNone(); } + + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } mvPlot* graph = static_cast(aplot); auto area = graph->getPlotQueryArea(); @@ -1120,6 +1204,14 @@ namespace Marvel { ThrowPythonException(message + " plot does not exist."); return mvPythonTranslator::GetPyNone(); } + + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } + mvPlot* graph = static_cast(aplot); graph->SetColorMap(map); @@ -1191,6 +1283,13 @@ namespace Marvel { return mvPythonTranslator::GetPyNone(); } + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } + mvPlot* graph = static_cast(aplot); auto datapoints = mvPythonTranslator::ToVectVec2(data); @@ -1249,6 +1348,13 @@ namespace Marvel { return mvPythonTranslator::GetPyNone(); } + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } + mvPlot* graph = static_cast(aplot); auto datapoints = mvPythonTranslator::ToVectVec2(data); @@ -1290,6 +1396,14 @@ namespace Marvel { ThrowPythonException(message + " plot does not exist."); return mvPythonTranslator::GetPyNone(); } + + if (aplot->getType() != mvAppItemType::Plot) + { + std::string message = plot; + ThrowPythonException(message + " is not a plot."); + return mvPythonTranslator::GetPyNone(); + } + mvPlot* graph = static_cast(aplot); mvSeries* series = new mvLabelSeries(name, { {(float)x, (float)y} }, xoffset, yoffset, vertical); diff --git a/DearSandbox/Demo.py b/DearSandbox/Demo.py index 3ca47752c..1133b5b9c 100644 --- a/DearSandbox/Demo.py +++ b/DearSandbox/Demo.py @@ -236,8 +236,6 @@ def InsertCol(sender, data): add_button("Plot data", callback="PlotCallback") add_listbox("Colormaps", ("Default", "Dark", "Pastel", "Paired", "Viridis", "Plasma", "Hot", "Cool", "Pink", "Jet"), width=500, height=3, callback="colormapCallback") add_plot("Plot", "x-axis", "y-axis", height=-1); -set_xticks("Plot", [["X-axis", 0], ["1", 1]]) -set_yticks("Plot", [["Y-axis", 0], ["1", 1]]) end_tab() add_tab("Simple Plots") add_simple_plot("Simpleplot1", (0.3, 0.9, 2.5, 8.9))