Browse Source

perf: enhance SvgGraph module

legacy
Dnomd343 2 years ago
parent
commit
2d2bb40fa8
  1. 38
      src/graph/graph.cc
  2. 66
      src/graph/svg/svg.cc
  3. 34
      src/graph/svg/svg.h

38
src/graph/graph.cc

@ -9,21 +9,21 @@
void Graph::svg_demo(Analyse::track_data_t track_data) { void Graph::svg_demo(Analyse::track_data_t track_data) {
auto s = SvgRect(); auto s = new SvgRect();
s.left = 50; s->left = 50;
s.top = 80; s->top = 80;
s.width = 100; s->width = 100;
s.height = 200; s->height = 200;
s.radius = 20; s->radius = 20;
s.opacity = 0.8; s->opacity = 0.8;
s.line_opacity = 0.5; s->line_opacity = 0.5;
s.color = "blue"; s->color = "blue";
s.line_color = "green"; s->line_color = "green";
// printf(R"(<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="%d" height="%d">)", 1000, 1000); // printf(R"(<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="%d" height="%d">)", 1000, 1000);
// printf("\n"); // printf("\n");
@ -32,21 +32,21 @@ void Graph::svg_demo(Analyse::track_data_t track_data) {
// //
// printf("</svg>\n"); // printf("</svg>\n");
auto l = SvgLine(); auto l = new SvgLine();
l.start_x = 100; l->start_x = 100;
l.start_y = 200; l->start_y = 200;
l.end_x = 300; l->end_x = 300;
l.end_y = 400; l->end_y = 400;
auto sg = SvgGraph(); auto sg = SvgGraph(1000, 2000);
// sg.insert(&s); // sg.insert(&s);
// sg.insert(&l); // sg.insert(&l);
sg.insert(std::move(s)); sg.insert(s);
sg.insert(std::move(l)); sg.insert(l);
sg.dump(); std::cout << sg.dump() << std::endl;
return; return;

66
src/graph/svg/svg.cc

@ -1,7 +1,27 @@
#include "svg.h" #include "svg.h"
#include <iostream>
SvgGraph::~SvgGraph() {
for (auto *object : objects) {
delete object;
}
}
void SvgGraph::insert(SvgObject *obj) {
objects.emplace_back(obj);
}
std::string SvgLine::dump() const {
/// basic attributes of svg-line
return "<line />";
}
std::string SvgRect::dump() const { std::string SvgRect::dump() const {
/// basic attribute of svg-rect /// basic attributes of svg-rect
std::string xml = "<rect "; std::string xml = "<rect ";
xml += "x=\"" + std::to_string(left) + "\" "; xml += "x=\"" + std::to_string(left) + "\" ";
xml += "y=\"" + std::to_string(top) + "\" "; xml += "y=\"" + std::to_string(top) + "\" ";
@ -27,44 +47,12 @@ std::string SvgRect::dump() const {
return xml + "style=\"" + style + "\" />"; 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 { std::string SvgGraph::dump() const {
std::string xml = R"(<svg xmlns="http://www.w3.org/2000/svg" version="1.1")";
for (auto o : objects) { xml += " width=\"" + std::to_string(width) + "\"";
std::cout << o->dump() << std::endl; xml += " height=\"" + std::to_string(height) + "\">\n";
for (const auto *object : objects) {
xml += " " + object->dump() + "\n";
} }
return xml + "</svg>\n";
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 />";
} }

34
src/graph/svg/svg.h

@ -10,6 +10,20 @@ public:
virtual std::string dump() const = 0; virtual std::string dump() const = 0;
}; };
class SvgGraph {
public:
uint64_t width;
uint64_t height;
~SvgGraph();
std::string dump() const;
void insert(SvgObject *obj);
SvgGraph(uint64_t w, uint64_t h) : width(w), height(h) {}
private:
std::vector<SvgObject*> objects;
};
class SvgLine : public SvgObject { class SvgLine : public SvgObject {
public: public:
uint64_t start_x; uint64_t start_x;
@ -42,23 +56,3 @@ public:
~SvgRect() override = default; ~SvgRect() override = default;
std::string dump() const override; 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