Skip to content

Commit

Permalink
chore: consolidated mvPlotAxis.h to mvPlotting.h
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed May 17, 2022
1 parent 031e11e commit c3e4789
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 447 deletions.
1 change: 0 additions & 1 deletion DearPyGui/cmake/dpg_sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ set(MARVEL_SOURCES
"src/ui/AppItems/composite/mvFileDialog.cpp"
"src/ui/AppItems/composite/mvFileExtension.cpp"
"src/ui/AppItems/plots/mvPlot.cpp"
"src/ui/AppItems/plots/mvPlotAxis.cpp"

# imnodes
"vendor/imnodes/imnodes.cpp"
Expand Down
36 changes: 24 additions & 12 deletions DearPyGui/src/modules/dearpygui_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ bind_colormap(PyObject* self, PyObject* args, PyObject* kwargs)
if (aitem->type == mvAppItemType::mvPlot)
{
mvPlot* graph = static_cast<mvPlot*>(aitem);
graph->SetColorMap((ImPlotColormap)source);
graph->_colormap = (ImPlotColormap)source;
graph->_useColorMap = true;
graph->_newColorMap = true;
}

else if (aitem->type == mvAppItemType::mvColorMapScale)
Expand Down Expand Up @@ -1003,7 +1005,7 @@ is_plot_queried(PyObject* self, PyObject* args, PyObject* kwargs)

mvPlot* graph = static_cast<mvPlot*>(aplot);

return ToPyBool(graph->isPlotQueried());
return ToPyBool(graph->_queried);
}

mv_internal mv_python_function
Expand Down Expand Up @@ -1035,7 +1037,7 @@ get_plot_query_area(PyObject* self, PyObject* args, PyObject* kwargs)

mvPlot* graph = static_cast<mvPlot*>(aplot);

double* result = graph->getPlotQueryArea();
double* result = graph->_queryArea;
return Py_BuildValue("(dddd)", result[0], result[1], result[2], result[3]);
}

Expand Down Expand Up @@ -1079,8 +1081,15 @@ set_axis_ticks(PyObject* self, PyObject* args, PyObject* kwargs)
labels.emplace_back(item.first.c_str());
locations.emplace_back((double)item.second);
}
graph->resetYTicks();
graph->setYTicks(labels, locations);

graph->configData.labels.clear();
graph->configData.clabels.clear();
graph->configData.labelLocations.clear();
graph->configData.labels = labels;
graph->configData.labelLocations = locations;

for (const auto& item : graph->configData.labels)
graph->configData.clabels.push_back(item.data());

return GetPyNone();
}
Expand Down Expand Up @@ -1115,9 +1124,8 @@ set_axis_limits(PyObject* self, PyObject* args, PyObject* kwargs)
}

mvPlotAxis* graph = static_cast<mvPlotAxis*>(aplot);

graph->setLimits(ymin, ymax);

graph->configData.setLimits = true;
graph->configData.limits = ImVec2(ymin, ymax);
return GetPyNone();
}

Expand Down Expand Up @@ -1150,7 +1158,7 @@ set_axis_limits_auto(PyObject* self, PyObject* args, PyObject* kwargs)

mvPlotAxis* graph = static_cast<mvPlotAxis*>(aplot);

graph->setLimitsAuto();
graph->configData.setLimits = false;

return GetPyNone();
}
Expand Down Expand Up @@ -1184,7 +1192,9 @@ fit_axis_data(PyObject* self, PyObject* args, PyObject* kwargs)

mvPlotAxis* graph = static_cast<mvPlotAxis*>(aplot);

graph->fitAxisData();
// fit axis data
static_cast<mvPlot*>(graph->info.parentPtr)->_fitDirty = true;
static_cast<mvPlot*>(graph->info.parentPtr)->_axisfitDirty[graph->info.location] = true;

return GetPyNone();
}
Expand Down Expand Up @@ -1218,7 +1228,7 @@ get_axis_limits(PyObject* self, PyObject* args, PyObject* kwargs)

mvPlotAxis* graph = static_cast<mvPlotAxis*>(aplot);

const ImVec2& lim = graph->getYLimits();
const ImVec2& lim = graph->configData.limits_actual;
return ToPyPair(lim.x, lim.y);
}

Expand Down Expand Up @@ -1251,7 +1261,9 @@ reset_axis_ticks(PyObject* self, PyObject* args, PyObject* kwargs)

mvPlotAxis* graph = static_cast<mvPlotAxis*>(aplot);

graph->resetYTicks();
graph->configData.labels.clear();
graph->configData.clabels.clear();
graph->configData.labelLocations.clear();

return GetPyNone();
}
Expand Down
1 change: 1 addition & 0 deletions DearPyGui/src/mvDearPyGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct mvColorMapScaleConfig;
struct mvColorMapSliderConfig;

// plots
struct mvPlotAxisConfig;
struct mvAnnotationConfig;
struct mvSubPlotsConfig;
struct mvPlotLegendConfig;
Expand Down
28 changes: 12 additions & 16 deletions DearPyGui/src/ui/AppItems/mvAppItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5379,14 +5379,14 @@ DearPyGui::OnChildAdded(mvAppItem* item, mvRef<mvAppItem> child)
case mvAppItemType::mvPlot:
{
mvPlot* actualItem = (mvPlot*)item;
actualItem->onChildAdd(child);
return;
}

case mvAppItemType::mvPlotAxis:
{
mvPlotAxis* actualItem = (mvPlotAxis*)item;
actualItem->onChildAdd(child);
if (child->type == mvAppItemType::mvPlotLegend)
actualItem->_flags &= ~ImPlotFlags_NoLegend;
if (child->type == mvAppItemType::mvPlotAxis)
{
actualItem->updateFlags();
actualItem->updateAxesNames();
}
return;
}

Expand Down Expand Up @@ -5429,14 +5429,10 @@ DearPyGui::OnChildRemoved(mvAppItem* item, mvRef<mvAppItem> child)
case mvAppItemType::mvPlot:
{
mvPlot* actualItem = (mvPlot*)item;
actualItem->onChildRemoved(child);
return;
}

case mvAppItemType::mvPlotAxis:
{
mvPlotAxis* actualItem = (mvPlotAxis*)item;
actualItem->onChildRemoved(child);
if (child->type == mvAppItemType::mvPlotLegend)
actualItem->_flags |= ImPlotFlags_NoLegend;
if (child->type == mvAppItemType::mvPlotAxis)
actualItem->updateFlags();
return;
}

Expand Down
1 change: 0 additions & 1 deletion DearPyGui/src/ui/AppItems/mvAppItemCommons.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@
#include "composite/mvFileExtension.h"

#include "plots/mvPlot.h"
#include "plots/mvPlotAxis.h"
168 changes: 166 additions & 2 deletions DearPyGui/src/ui/AppItems/mvPlotting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,77 @@ DearPyGui::set_data_source(mvAppItem& item, mvUUID dataSource, mvRef<std::vector
outValue = *static_cast<std::shared_ptr<std::vector<std::vector<double>>>*>(srcItem->getValue());
}

void
DearPyGui::draw_plot_axis(ImDrawList* drawlist, mvAppItem& item, mvPlotAxisConfig& config)
{
if (!item.config.show)
return;

// todo: add check
if (config.axis != 0)
ImPlot::SetPlotYAxis(item.info.location - 1);

for (auto& item : item.childslots[1])
item->draw(drawlist, ImPlot::GetPlotPos().x, ImPlot::GetPlotPos().y);

// x axis
if (config.axis == 0)
{
config.limits_actual.x = (float)ImPlot::GetPlotLimits(item.info.location).X.Min;
config.limits_actual.y = (float)ImPlot::GetPlotLimits(item.info.location).X.Max;
auto context = ImPlot::GetCurrentContext();
config.flags = context->CurrentPlot->XAxis.Flags;

}

// y axis
else
{
config.limits_actual.x = (float)ImPlot::GetPlotLimits(item.info.location - 1).Y.Min;
config.limits_actual.y = (float)ImPlot::GetPlotLimits(item.info.location - 1).Y.Max;
auto context = ImPlot::GetCurrentContext();
config.flags = context->CurrentPlot->YAxis[item.info.location - 1].Flags;
}


UpdateAppItemState(item.state);

if (item.font)
{
ImGui::PopFont();
}

if (item.theme)
{
static_cast<mvTheme*>(item.theme.get())->customAction();
}

if (item.config.dropCallback)
{
ScopedID id(item.uuid);
if (item.info.location == 0 && ImPlot::BeginDragDropTargetX())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(item.config.payloadType.c_str()))
{
auto payloadActual = static_cast<const mvDragPayload*>(payload->Data);
mvAddCallback(item.config.dropCallback, item.uuid, payloadActual->getDragData(), nullptr);
}

ImPlot::EndDragDropTarget();
}
else if (ImPlot::BeginDragDropTargetY(item.info.location - 1))
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(item.config.payloadType.c_str()))
{
auto payloadActual = static_cast<const mvDragPayload*>(payload->Data);
mvAddCallback(item.config.dropCallback, item.uuid, payloadActual->getDragData(), nullptr);
}

ImPlot::EndDragDropTarget();
}
}
}

void
DearPyGui::draw_subplots(ImDrawList* drawlist, mvAppItem& item, mvSubPlotsConfig& config)
{
Expand Down Expand Up @@ -1978,6 +2049,17 @@ DearPyGui::set_required_configuration(PyObject* inDict, mvCustomSeriesConfig& ou
}
}

void
DearPyGui::set_required_configuration(PyObject* inDict, mvPlotAxisConfig& outConfig)
{
if (!VerifyRequiredArguments(GetParsers()[GetEntityCommand(mvAppItemType::mvPlotAxis)], inDict))
return;

outConfig.axis = ToInt(PyTuple_GetItem(inDict, 0));
if (outConfig.axis > 1)
outConfig.axis = 1;
}

void
DearPyGui::set_configuration(PyObject* inDict, mvDragLineConfig& outConfig)
{
Expand Down Expand Up @@ -2017,7 +2099,7 @@ DearPyGui::set_configuration(PyObject* inDict, mvPlotLegendConfig& outConfig, mv
{
item.info.shownLastFrame = false;
if (auto plot = static_cast<mvPlot*>(item.info.parentPtr))
plot->removeFlag(ImPlotFlags_NoLegend);
plot->_flags &= ~ImPlotFlags_NoLegend;
else if (auto plot = static_cast<mvSubPlots*>(item.info.parentPtr))
plot->removeFlag(ImPlotSubplotFlags_NoLegend);
item.config.show = true;
Expand All @@ -2027,7 +2109,7 @@ DearPyGui::set_configuration(PyObject* inDict, mvPlotLegendConfig& outConfig, mv
{
item.info.hiddenLastFrame = false;
if (auto plot = static_cast<mvPlot*>(item.info.parentPtr))
plot->addFlag(ImPlotFlags_NoLegend);
plot->_flags |= ImPlotFlags_NoLegend;
else if (auto plot = static_cast<mvSubPlots*>(item.info.parentPtr))
plot->addFlag(ImPlotSubplotFlags_NoLegend);
item.config.show = false;
Expand Down Expand Up @@ -2303,6 +2385,51 @@ DearPyGui::set_configuration(PyObject* inDict, mvSubPlotsConfig& outConfig)
flagop("column_major", ImPlotSubplotFlags_ColMajor, outConfig.flags);
}

void
DearPyGui::set_configuration(PyObject* inDict, mvPlotAxisConfig& outConfig, mvAppItem& item)
{
if (inDict == nullptr)
return;

// helper for bit flipping
auto flagop = [inDict](const char* keyword, int flag, int& flags)
{
if (PyObject* item = PyDict_GetItemString(inDict, keyword)) ToBool(item) ? flags |= flag : flags &= ~flag;
};

// axis flags
flagop("no_gridlines", ImPlotAxisFlags_NoGridLines, outConfig.flags);
flagop("no_tick_marks", ImPlotAxisFlags_NoTickMarks, outConfig.flags);
flagop("no_tick_labels", ImPlotAxisFlags_NoTickLabels, outConfig.flags);
flagop("log_scale", ImPlotAxisFlags_LogScale, outConfig.flags);
flagop("invert", ImPlotAxisFlags_Invert, outConfig.flags);
flagop("lock_min", ImPlotAxisFlags_LockMin, outConfig.flags);
flagop("lock_max", ImPlotAxisFlags_LockMax, outConfig.flags);
flagop("time", ImPlotAxisFlags_Time, outConfig.flags);

if (item.info.parentPtr)
{
static_cast<mvPlot*>(item.info.parentPtr)->updateFlags();
static_cast<mvPlot*>(item.info.parentPtr)->updateAxesNames();
}

if (item.info.shownLastFrame)
{
item.info.shownLastFrame = false;
if (auto plot = static_cast<mvPlot*>(item.info.parentPtr))
plot->_flags &= ~ImPlotFlags_NoLegend;
item.config.show = true;
}

if (item.info.hiddenLastFrame)
{
item.info.hiddenLastFrame = false;
if (auto plot = static_cast<mvPlot*>(item.info.parentPtr))
plot->_flags |= ImPlotFlags_NoLegend;
item.config.show = false;
}
}

void
DearPyGui::fill_configuration_dict(const mvDragLineConfig& inConfig, PyObject* outDict)
{
Expand Down Expand Up @@ -2530,6 +2657,30 @@ DearPyGui::fill_configuration_dict(const mvSubPlotsConfig& inConfig, PyObject* o
checkbitset("column_major", ImPlotSubplotFlags_ColMajor, inConfig.flags);
}

void
DearPyGui::fill_configuration_dict(const mvPlotAxisConfig& inConfig, PyObject* outDict)
{
if (outDict == nullptr)
return;

// helper to check and set bit
auto checkbitset = [outDict](const char* keyword, int flag, const int& flags)
{
mvPyObject py_result = ToPyBool(flags & flag);
PyDict_SetItemString(outDict, keyword, py_result);
};

// plot flags
checkbitset("no_gridlines", ImPlotAxisFlags_NoGridLines, inConfig.flags);
checkbitset("no_tick_marks", ImPlotAxisFlags_NoTickMarks, inConfig.flags);
checkbitset("no_tick_labels", ImPlotAxisFlags_NoTickLabels, inConfig.flags);
checkbitset("log_scale", ImPlotAxisFlags_LogScale, inConfig.flags);
checkbitset("invert", ImPlotAxisFlags_Invert, inConfig.flags);
checkbitset("lock_min", ImPlotAxisFlags_LockMin, inConfig.flags);
checkbitset("lock_max", ImPlotAxisFlags_LockMax, inConfig.flags);
checkbitset("time", ImPlotAxisFlags_Time, inConfig.flags);
}

void
DearPyGui::apply_template(const mvSubPlotsConfig& sourceConfig, mvSubPlotsConfig& dstConfig)
{
Expand Down Expand Up @@ -2708,6 +2859,19 @@ DearPyGui::apply_template(const mvAnnotationConfig& sourceConfig, mvAnnotationCo
dstConfig.pixOffset = sourceConfig.pixOffset;
}

void
DearPyGui::apply_template(const mvPlotAxisConfig& sourceConfig, mvPlotAxisConfig& dstConfig)
{
dstConfig.flags = sourceConfig.flags;
dstConfig.axis = sourceConfig.axis;
dstConfig.setLimits = sourceConfig.setLimits;
dstConfig.limits = sourceConfig.limits;
dstConfig.limits_actual = sourceConfig.limits_actual;
dstConfig.labels = sourceConfig.labels;
dstConfig.labelLocations = sourceConfig.labelLocations;
dstConfig.clabels = sourceConfig.clabels;
}

//-----------------------------------------------------------------------------
// Old Classes, in the process of removing OOP crap
//-----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit c3e4789

Please # to comment.