Browse Source

feat: SvgGraph module

legacy
Dnomd343 2 years ago
parent
commit
20ae12cb24
  1. 24
      src/graph/graph.cc
  2. 42
      src/graph/svg/svg.cc
  3. 43
      src/graph/svg/svg.h

24
src/graph/graph.cc

@ -25,12 +25,28 @@ void Graph::svg_demo(Analyse::track_data_t track_data) {
s.color = "blue";
s.line_color = "green";
printf(R"(<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="%d" height="%d">)", 1000, 1000);
printf("\n");
// printf(R"(<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="%d" height="%d">)", 1000, 1000);
// printf("\n");
//
// std::cout << " " << s.dump() << std::endl;
//
// printf("</svg>\n");
std::cout << " " << s.dump() << std::endl;
auto l = SvgLine();
l.start_x = 100;
l.start_y = 200;
printf("</svg>\n");
l.end_x = 300;
l.end_y = 400;
auto sg = SvgGraph();
// sg.insert(&s);
// sg.insert(&l);
sg.insert(std::move(s));
sg.insert(std::move(l));
sg.dump();
return;

42
src/graph/svg/svg.cc

@ -26,3 +26,45 @@ std::string SvgRect::dump() const {
}
return xml + "style=\"" + style + "\" />";
}
SvgGraph::~SvgGraph() {
for (auto &object : objects) {
delete object;
}
}
//void SvgGraph::insert(SvgObject *obj) {
// objects.emplace_back(obj);
//}
#include <iostream>
std::string SvgGraph::dump() const {
for (auto o : objects) {
std::cout << o->dump() << std::endl;
}
return "svg result";
}
void SvgGraph::insert(const SvgRect &rect) {
//void SvgGraph::insert(SvgRect rect) {
auto s = new SvgRect(rect);
objects.emplace_back(s);
}
void SvgGraph::insert(const SvgLine &line) {
auto l = new SvgLine(line);
objects.emplace_back(l);
}
std::string SvgLine::dump() const {
return "<line />";
}

43
src/graph/svg/svg.h

@ -2,8 +2,28 @@
#include <string>
#include <cstdint>
#include <vector>
class SvgRect {
class SvgObject {
public:
virtual ~SvgObject() = default;
virtual std::string dump() const = 0;
};
class SvgLine : public SvgObject {
public:
uint64_t start_x;
uint64_t start_y;
uint64_t end_x;
uint64_t end_y;
~SvgLine() override = default;
std::string dump() const override;
};
class SvgRect : public SvgObject {
public:
uint64_t top;
uint64_t left;
@ -19,5 +39,26 @@ public:
float opacity = 0;
float line_opacity = 0;
~SvgRect() override = default;
std::string dump() const override;
};
class SvgGraph {
public:
std::vector<SvgObject*> objects;
// void insert(SvgObject *obj);
void insert(const SvgRect &rect);
void insert(const SvgLine &line);
// void insert(SvgRect rect);
// void insert(SvgLine line);
std::string dump() const;
~SvgGraph();
};

Loading…
Cancel
Save