Header-only C++ data structure visualizer. Generate an HTML view for lists and trees without changing your structs.
- C++11 or newer
- A web browser (opens automatically)
- Copy the folder include/vis into your project.
- Include the header:
#include "vis/Vis.hpp"
- Build and run your program.
This project uses CMake. Configure and build from the repo root:
cmake -S . -B build
cmake --build buildAfter building, run the example binaries from the build folder:
./build/examples/basic_list
./build/examples/basic_treeEach example writes an HTML file in the repo root and opens it in your default browser.
Define a node type, then call vis::writeListHTMLFile.
#include "vis/Vis.hpp"
struct Node {
int data;
Node* next;
};
int main() {
Node c{3, nullptr};
Node b{2, &c};
Node a{1, &b};
vis::writeListHTMLFile(&a, "list.html");
return 0;
}Output: an HTML file is created and opened in your browser.
For trees (or graphs), pass lambdas that describe how to read node data and children.
#include "vis/Vis.hpp"
#include <vector>
struct TreeNode {
std::string value;
TreeNode* left;
TreeNode* right;
};
int main() {
TreeNode c{"C", nullptr, nullptr};
TreeNode b{"B", nullptr, nullptr};
TreeNode a{"A", &b, &c};
auto getData = [](TreeNode* n) { return n->value; };
auto getChildren = [](TreeNode* n) {
std::vector<TreeNode*> kids;
if (n->left) kids.push_back(n->left);
if (n->right) kids.push_back(n->right);
return kids;
};
vis::writeTreeHTMLFile(&a, "tree.html", getData, getChildren);
return 0;
}- Linked list example: examples/basic_list.cpp
- Tree example: examples/basic_tree.cpp