Skip to content

Commit

Permalink
fixed visualisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Angeld55 committed Sep 7, 2024
1 parent 5383bdd commit d427220
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 178 deletions.
13 changes: 6 additions & 7 deletions Command_shell/Commands/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,15 @@ std::string VisualizeCommand::execute(const std::vector<std::string>& args)
return "Error! Invalid command! (Error: 1122)";
if (dispatcher.env.getAutomation(args[1], aut) == 0)
{
if (!dispatcher.env.vis.isOkey())
bool visResult = visualize(aut, args[1] + ".html");
if (visResult)
{
dispatcher.env.vis.init();
return "Visualization succesfull! File with name " + args[1] + ".html is created!";
}

if (!dispatcher.env.vis.isOkey())
else
{
return "Error with the visualization!";

dispatcher.env.vis.visualize(aut, args[1] + ".html");
return "Visualization succesfull!";
}
}
else
return "Error! No FSA with ID:" + args[0];
Expand Down
2 changes: 1 addition & 1 deletion Environment/AFL_Environment.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "AFL_Environment.h"

AFL_Environment::AFL_Environment() : vis("header.x", "footer.x")
AFL_Environment::AFL_Environment()
{

}
Expand Down
2 changes: 0 additions & 2 deletions Environment/AFL_Environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class AFL_Environment
FiniteStateAutomation* fsaSecret; //temp place for assignments;

public:
GraphVisualiser vis;

AFL_Environment();
int registerAutomation(const std::string& key, AutomationBase* npda);

Expand Down
81 changes: 42 additions & 39 deletions Graph_visualization_tool/GraphVisualiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,49 @@
#include <streambuf>
#include <string>

bool readFile(const std::string& filePath, std::string& str)
static std::string header = R"(
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GraphViz with Viz.js</title>
</head>
<body>
<div id="graph" style="width: 100%; height: 500px;"></div>
<!-- Include Viz.js from a CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/viz.js/2.1.2/viz.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/viz.js/2.1.2/full.render.js"></script>
<script>
// Your GraphViz dot string
var dotString = `)";



static std::string footer = R"(
`;
// create an instance of Viz
var viz = new Viz();
// Render the dot string as an SVG and append it to the div
viz.renderSVGElement(dotString)
.then(function(element) {
document.getElementById('graph').appendChild(element);
})
.catch(error => {
console.error(error);
});
</script>
</body>
</html>
)";

bool visualize(const AutomationBase* fsa, const std::string& filePath)
{

std::ifstream t(filePath);
if (!t.is_open())
return false;

t.seekg(0, std::ios::end);
str.reserve(t.tellg());
t.seekg(0, std::ios::beg);

str.assign((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());

t.close();

return true;
}

GraphVisualiser::GraphVisualiser(const std::string& headerTemplatePath, const std::string& footerTemplatePath) : headerPath(headerTemplatePath), footerPath(footerTemplatePath), isOkay(false)
{

}

bool GraphVisualiser::init()
{
bool res = readFile(headerPath, header);
if (!res)
return false;
return isOkay = readFile(footerPath, footer);
}
bool GraphVisualiser::visualize(const AutomationBase* fsa, const std::string& filePath)
{
if (!isOkay)
return false;

std::ofstream f(filePath);

if (!f.is_open())
Expand All @@ -50,7 +57,3 @@ bool GraphVisualiser::visualize(const AutomationBase* fsa, const std::string& fi

return true;
}
bool GraphVisualiser::isOkey() const
{
return isOkay;
}
16 changes: 1 addition & 15 deletions Graph_visualization_tool/GraphVisualiser.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
#include <iostream>
#include "../Finate_state_automation/FiniteStateAutomation.h"
class GraphVisualiser
{
std::string headerPath;
std::string footerPath;
std::string header;
std::string footer;
bool isOkay;

public:
GraphVisualiser(const std::string& headerTemplatePath, const std::string& footerTemplatePath);

bool init();
bool isOkey() const;
bool visualize(const AutomationBase* fsa, const std::string& filePath);

};
bool visualize(const AutomationBase* fsa, const std::string& filePath);
8 changes: 0 additions & 8 deletions Graph_visualization_tool/footer.x

This file was deleted.

This file was deleted.

85 changes: 0 additions & 85 deletions Graph_visualization_tool/graphVisualiser_files/site.js.download

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions Graph_visualization_tool/header.x

This file was deleted.

0 comments on commit d427220

Please sign in to comment.