From 2d2bb40fa808643260d38c4b2d8898b0e75a99a9 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 20 Jan 2023 20:59:12 +0800 Subject: [PATCH] perf: enhance SvgGraph module --- src/graph/graph.cc | 38 ++++++++++++------------- src/graph/svg/svg.cc | 66 ++++++++++++++++++-------------------------- src/graph/svg/svg.h | 34 ++++++++++------------- 3 files changed, 60 insertions(+), 78 deletions(-) diff --git a/src/graph/graph.cc b/src/graph/graph.cc index afdcb9c..64e2ae5 100644 --- a/src/graph/graph.cc +++ b/src/graph/graph.cc @@ -9,21 +9,21 @@ void Graph::svg_demo(Analyse::track_data_t track_data) { - auto s = SvgRect(); + auto s = new SvgRect(); - s.left = 50; - s.top = 80; + s->left = 50; + s->top = 80; - s.width = 100; - s.height = 200; + s->width = 100; + s->height = 200; - s.radius = 20; + s->radius = 20; - s.opacity = 0.8; - s.line_opacity = 0.5; + s->opacity = 0.8; + s->line_opacity = 0.5; - s.color = "blue"; - s.line_color = "green"; + s->color = "blue"; + s->line_color = "green"; // printf(R"()", 1000, 1000); // printf("\n"); @@ -32,21 +32,21 @@ void Graph::svg_demo(Analyse::track_data_t track_data) { // // printf("\n"); - auto l = SvgLine(); - l.start_x = 100; - l.start_y = 200; + auto l = new SvgLine(); + l->start_x = 100; + l->start_y = 200; - l.end_x = 300; - l.end_y = 400; + l->end_x = 300; + l->end_y = 400; - auto sg = SvgGraph(); + auto sg = SvgGraph(1000, 2000); // sg.insert(&s); // sg.insert(&l); - sg.insert(std::move(s)); - sg.insert(std::move(l)); + sg.insert(s); + sg.insert(l); - sg.dump(); + std::cout << sg.dump() << std::endl; return; diff --git a/src/graph/svg/svg.cc b/src/graph/svg/svg.cc index 098fc8b..90acabb 100644 --- a/src/graph/svg/svg.cc +++ b/src/graph/svg/svg.cc @@ -1,7 +1,27 @@ #include "svg.h" +#include + + +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 ""; + +} + std::string SvgRect::dump() const { - /// basic attribute of svg-rect + /// basic attributes of svg-rect std::string xml = ""; } - -SvgGraph::~SvgGraph() { - for (auto &object : objects) { - delete object; - } -} - -//void SvgGraph::insert(SvgObject *obj) { -// objects.emplace_back(obj); -//} - -#include - std::string SvgGraph::dump() const { - - for (auto o : objects) { - std::cout << o->dump() << std::endl; + std::string xml = R"(\n"; + for (const auto *object : objects) { + xml += " " + object->dump() + "\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 ""; - + return xml + "\n"; } diff --git a/src/graph/svg/svg.h b/src/graph/svg/svg.h index be2651c..7808a29 100644 --- a/src/graph/svg/svg.h +++ b/src/graph/svg/svg.h @@ -10,6 +10,20 @@ public: 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 objects; +}; + class SvgLine : public SvgObject { public: uint64_t start_x; @@ -42,23 +56,3 @@ public: ~SvgRect() override = default; std::string dump() const override; }; - -class SvgGraph { -public: - - std::vector 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(); - -};