Browse Source

perf: svg-rect xml dump

legacy
Dnomd343 2 years ago
parent
commit
386e28d5f8
  1. 6
      src/graph/graph.cc
  2. 66
      src/graph/svg/svg.cc
  3. 6
      src/graph/svg/svg.h

6
src/graph/graph.cc

@ -19,6 +19,12 @@ void Graph::svg_demo(Analyse::track_data_t track_data) {
s.radius = 20; s.radius = 20;
s.opacity = 0.8;
s.line_opacity = 0.5;
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(R"(<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="%d" height="%d">)", 1000, 1000);
printf("\n"); printf("\n");

66
src/graph/svg/svg.cc

@ -1,50 +1,28 @@
#include "svg.h" #include "svg.h"
#include <cstdio>
#include <iostream>
std::string SvgRect::dump() const { std::string SvgRect::dump() const {
/// basic attribute of svg-rect
/// <rect x="120" width="100" height="100" rx="15" /> std::string xml = "<rect ";
xml += "x=\"" + std::to_string(left) + "\" ";
// char *radius_str = nullptr; xml += "y=\"" + std::to_string(top) + "\" ";
// if (radius == 0) { xml += "width=\"" + std::to_string(width) + "\" ";
// asprintf(&radius_str, " "); xml += "height=\"" + std::to_string(height) + "\" ";
// } 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"(<rect x="%ld" y="%ld" width="%ld" height="%ld")", left, top, width, height);
std::string ret(xml);
free(xml);
if (radius != 0) { if (radius != 0) {
char *radius_str = nullptr; xml += "rx=\"" + std::to_string(radius) + "\" ";
asprintf(&radius_str, R"( rx="%lu")", radius);
ret += radius_str;
free(radius_str);
} }
/// style attribute of svg-rect
std::string style = "stroke-width:" + std::to_string(stroke) + ";";
// std::cout << xml << std::endl; if (!color.empty()) {
style += "fill:" + color + ";";
// std::string result = xml; }
if (!line_color.empty()) {
// free(xml); style += "stroke:" + line_color + ";";
}
// std::string xml("<rect "); if (opacity != 0) {
// xml += "x = "; style += "fill-opacity:" + std::to_string(opacity).substr(0, 4) + ";";
// }
// xml += atoi(); if (line_opacity != 0) {
style += "stroke-opacity:" + std::to_string(line_opacity).substr(0, 4) + ";";
return ret + " />"; }
return xml + "style=\"" + style + "\" />";
} }

6
src/graph/svg/svg.h

@ -9,13 +9,15 @@ public:
uint64_t left; uint64_t left;
uint64_t width; uint64_t width;
uint64_t height; uint64_t height;
uint64_t radius = 0; uint64_t radius = 0;
uint32_t stroke = 1; uint32_t stroke = 1;
std::string color;
std::string line_color;
float opacity = 0; float opacity = 0;
float line_opacity = 0; float line_opacity = 0;
std::string color = "pink";
std::string line_color = "blue";
std::string dump() const; std::string dump() const;
}; };

Loading…
Cancel
Save