Skip to content

Commit

Permalink
ENH: Update method names to dump a DataStructure hierarchy to text or…
Browse files Browse the repository at this point in the history
… .dot (#780)

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson authored Nov 30, 2023
1 parent 749a340 commit b32d15b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
70 changes: 36 additions & 34 deletions src/complex/DataStructure/DataStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,72 +870,74 @@ void DataStructure::resetIds(DataObject::IdType startingId)
m_RootGroup.updateIds(updatedIds);
}

void DataStructure::exportHeirarchyAsGraphViz(std::ostream& outputStream) const
void DataStructure::exportHierarchyAsGraphViz(std::ostream& outputStream) const
{
// initialize dot file
outputStream << "digraph DataGraph {\n"
<< "\tlabelloc =\"t\"\n"
<< "\trankdir=LR;\n\n";

<< "\trankdir=LR;\n"
<< "\tlabel=\"DataStructure Hierarchy\"\n"
<< "\tlabelloc=\"t\"\n"
<< "\tfontcolor=\"#FFFFFA\"\n"
<< "\tfontsize=12\n"
<< "\tgraph [splines=true bgcolor=\"#242627\"]\n"
<< "\tnode [shape=record style=\"filled\" fillcolor=\"#1D7ECD\" fontsize=12 fontcolor=\"#FFFFFA\"]\n"
<< "\tedge [dir=front arrowtail=empty style=\"\" color=\"#FFFFFA\"]\n\n";
// set base case
for(const auto* object : getTopLevelData())
{
auto topLevelPath = DataPath::FromString(object->getDataPaths()[0].getTargetName()).value();
auto optionalDataPaths = GetAllChildDataPaths(*this, topLevelPath);
outputStream << "\n/* Top level DataObject: " << topLevelPath.getTargetName() << " */\n\"" << topLevelPath.getTargetName() << "\";\n";

if(!optionalDataPaths.has_value() || optionalDataPaths.value().size() == 0)
if(optionalDataPaths.has_value() && !optionalDataPaths.value().empty())
{
outputStream << "\"" << topLevelPath.getTargetName() << "\";\n\n";
// Begin recursion
recurseHierarchyToGraphViz(outputStream, optionalDataPaths.value(), topLevelPath.getTargetName());
}

// Begin recursion
recurseHeirarchyToGraphViz(outputStream, optionalDataPaths.value(), topLevelPath.getTargetName());
}

// close dot file
outputStream << "}" << std::endl; // for readability
outputStream << "}\n"; // for readability
}

void DataStructure::recurseHeirarchyToGraphViz(std::ostream& outputStream, const std::vector<DataPath> paths, const std::string& parent) const
void DataStructure::exportHierarchyAsText(std::ostream& outputStream) const
{
for(const auto& path : paths)
// set base case
for(const auto* object : getTopLevelData())
{
// Output parent node, child node, and edge connecting them in .dot format
outputStream << "\"" << parent << "\" -> \"" << path.getTargetName() << "\"\n";
auto topLevelPath = DataPath::FromString(object->getDataPaths()[0].getTargetName()).value();
outputStream << k_Delimiter << topLevelPath.getTargetName() << "\n";
auto optionalChildPaths = GetAllChildDataPaths(*this, topLevelPath);

// pull child paths or skip to next iteration
auto optionalChildPaths = GetAllChildDataPaths(*this, path);
if(!optionalChildPaths.has_value() || optionalChildPaths.value().size() == 0)
if(optionalChildPaths.has_value() && !optionalChildPaths.value().empty())
{
continue;
// Begin recursion
recurseHierarchyToText(outputStream, optionalChildPaths.value(), "");
}

// recurse
recurseHeirarchyToGraphViz(outputStream, optionalChildPaths.value(), path.getTargetName());
}
outputStream << "\n"; // for readability
outputStream << '\n'; // for readability
}

void DataStructure::exportHeirarchyAsText(std::ostream& outputStream) const
void DataStructure::recurseHierarchyToGraphViz(std::ostream& outputStream, const std::vector<DataPath> paths, const std::string& parent) const
{
// set base case
for(const auto* object : getTopLevelData())
for(const auto& path : paths)
{
auto topLevelPath = DataPath::FromString(object->getDataPaths()[0].getTargetName()).value();
auto optionalDataPaths = GetAllChildDataPaths(*this, topLevelPath);

outputStream << k_Delimiter << topLevelPath.getTargetName() << "\n";
auto* dataObjectPtr = getData(path);
// Output parent node, child node, and edge connecting them in .dot format
outputStream << "\"" << parent << "\" -> \"" << path.getTargetName() << "\"\n";

if(optionalDataPaths.has_value() || optionalDataPaths.value().size() != 0)
// pull child paths or skip to next iteration
auto optionalChildPaths = GetAllChildDataPaths(*this, path);
if(optionalChildPaths.has_value() && !optionalChildPaths.value().empty())
{
// Begin recursion
recurseHeirarchyToText(outputStream, optionalDataPaths.value(), "");
recurseHierarchyToGraphViz(outputStream, optionalChildPaths.value(), path.getTargetName());
}
}
outputStream << std::endl; // for readability
}

void DataStructure::recurseHeirarchyToText(std::ostream& outputStream, const std::vector<DataPath> paths, std::string indent) const
void DataStructure::recurseHierarchyToText(std::ostream& outputStream, const std::vector<DataPath> paths, std::string indent) const
{
indent += " ";

Expand All @@ -946,13 +948,13 @@ void DataStructure::recurseHeirarchyToText(std::ostream& outputStream, const std

// pull child paths or skip to next iteration
auto optionalChildPaths = GetAllChildDataPaths(*this, path);
if(!optionalChildPaths.has_value() || optionalChildPaths.value().size() == 0)
if(!optionalChildPaths.has_value() || optionalChildPaths.value().empty())
{
continue;
}

// recurse
recurseHeirarchyToText(outputStream, optionalChildPaths.value(), indent);
recurseHierarchyToText(outputStream, optionalChildPaths.value(), indent);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/complex/DataStructure/DataStructure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,14 +665,14 @@ class COMPLEX_EXPORT DataStructure
* @param outputStream the child class of ostream to output dot syntax to
* @return
*/
void exportHeirarchyAsGraphViz(std::ostream& outputStream) const;
void exportHierarchyAsGraphViz(std::ostream& outputStream) const;

/**
* @brief Outputs data graph in console readable format
* @param outputStream the child class of ostream to output to
* @return
*/
void exportHeirarchyAsText(std::ostream& outputStream) const;
void exportHierarchyAsText(std::ostream& outputStream) const;

/**
* @brief Copy assignment operator. The copied DataStructure's observers are not retained.
Expand Down Expand Up @@ -800,7 +800,7 @@ class COMPLEX_EXPORT DataStructure
* @param parent name of the calling parent to output
* @return
*/
void recurseHeirarchyToGraphViz(std::ostream& outputStream, const std::vector<DataPath> paths, const std::string& parent) const;
void recurseHierarchyToGraphViz(std::ostream& outputStream, const std::vector<DataPath> paths, const std::string& parent) const;

/**
* @brief The recursive function to parse graph and dump names to and output stream in
Expand All @@ -810,7 +810,7 @@ class COMPLEX_EXPORT DataStructure
* @param indent the indent for the heirarchy
* @return
*/
void recurseHeirarchyToText(std::ostream& outputStream, const std::vector<DataPath> paths, std::string indent) const;
void recurseHierarchyToText(std::ostream& outputStream, const std::vector<DataPath> paths, std::string indent) const;

/**
* @brief Notifies observers to the provided message.
Expand Down

0 comments on commit b32d15b

Please sign in to comment.