From 386e28d5f8c4f9f8f62a824581b6417857e8b847 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 20 Jan 2023 20:10:29 +0800 Subject: [PATCH] perf: svg-rect xml dump --- src/graph/graph.cc | 6 ++++ src/graph/svg/svg.cc | 66 +++++++++++++++----------------------------- src/graph/svg/svg.h | 6 ++-- 3 files changed, 32 insertions(+), 46 deletions(-) diff --git a/src/graph/graph.cc b/src/graph/graph.cc index 52b7fee..c02a572 100644 --- a/src/graph/graph.cc +++ b/src/graph/graph.cc @@ -19,6 +19,12 @@ void Graph::svg_demo(Analyse::track_data_t track_data) { s.radius = 20; + s.opacity = 0.8; + s.line_opacity = 0.5; + + s.color = "blue"; + s.line_color = "green"; + printf(R"()", 1000, 1000); printf("\n"); diff --git a/src/graph/svg/svg.cc b/src/graph/svg/svg.cc index 08a8457..e7d6c7b 100644 --- a/src/graph/svg/svg.cc +++ b/src/graph/svg/svg.cc @@ -1,50 +1,28 @@ #include "svg.h" -#include - -#include - std::string SvgRect::dump() const { - - /// - -// char *radius_str = nullptr; -// if (radius == 0) { -// asprintf(&radius_str, " "); -// } else { -// asprintf(&radius_str, R"( rx="%lu" )", radius); -// } - - std::string style; - -// style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.9" - - char *xml = nullptr; - asprintf(&xml, R"("; - + /// style attribute of svg-rect + std::string style = "stroke-width:" + std::to_string(stroke) + ";"; + if (!color.empty()) { + style += "fill:" + color + ";"; + } + if (!line_color.empty()) { + style += "stroke:" + line_color + ";"; + } + if (opacity != 0) { + style += "fill-opacity:" + std::to_string(opacity).substr(0, 4) + ";"; + } + if (line_opacity != 0) { + style += "stroke-opacity:" + std::to_string(line_opacity).substr(0, 4) + ";"; + } + return xml + "style=\"" + style + "\" />"; } diff --git a/src/graph/svg/svg.h b/src/graph/svg/svg.h index 57b0f52..6e75f39 100644 --- a/src/graph/svg/svg.h +++ b/src/graph/svg/svg.h @@ -9,13 +9,15 @@ public: uint64_t left; uint64_t width; uint64_t height; + uint64_t radius = 0; uint32_t stroke = 1; + std::string color; + std::string line_color; + float opacity = 0; float line_opacity = 0; - std::string color = "pink"; - std::string line_color = "blue"; std::string dump() const; };