diff --git a/src/graph/CMakeLists.txt b/src/graph/CMakeLists.txt index df15942..379a365 100644 --- a/src/graph/CMakeLists.txt +++ b/src/graph/CMakeLists.txt @@ -1,4 +1,8 @@ cmake_minimum_required(VERSION 3.0) +include_directories(svg) + +add_subdirectory(svg) + add_library(graph graph.cc) -target_link_libraries(graph analyse) +target_link_libraries(graph analyse svg) diff --git a/src/graph/graph.cc b/src/graph/graph.cc index 90b05ab..52b7fee 100644 --- a/src/graph/graph.cc +++ b/src/graph/graph.cc @@ -4,8 +4,32 @@ #include #include +#include "svg.h" + void Graph::svg_demo(Analyse::track_data_t track_data) { + + auto s = SvgRect(); + + s.left = 50; + s.top = 80; + + s.width = 100; + s.height = 200; + + s.radius = 20; + + printf(R"()", 1000, 1000); + printf("\n"); + + std::cout << " " << s.dump() << std::endl; + + printf("\n"); + + return; + + + // // for (uint32_t i = 0; i < track_data.size(); ++i) { // @@ -93,13 +117,13 @@ void Graph::svg_demo(Analyse::track_data_t track_data) { // printf(R"( )", CASE_X, CASE_Y, CASE_WIDTH, CASE_HEIGHT); // printf("\n"); - SvgCase tmp = SvgCase(); - tmp.width = BLOCK_LENGTH; - tmp.gap = BLOCK_GAP; - tmp.left = CASE_X; - tmp.top = CASE_Y; - tmp.code = layer_data[i][j].code; - tmp.render(); +// SvgCase tmp = SvgCase(); +// tmp.width = BLOCK_LENGTH; +// tmp.gap = BLOCK_GAP; +// tmp.left = CASE_X; +// tmp.top = CASE_Y; +// tmp.code = layer_data[i][j].code; +// tmp.render(); } @@ -110,78 +134,78 @@ void Graph::svg_demo(Analyse::track_data_t track_data) { } -void SvgRect::to_xml() const { - // TODO: return std::string - printf(R"()", left, top, width, height); - printf("\n"); -} - -void SvgCase::render() const { - - std::string result; - - uint64_t raw_code = code; - -// std::cout << "start rander" << std::endl; - - auto tmp = SvgRect(); - - tmp.left = left; - tmp.top = top; - tmp.width = width * 4 + gap * 5; - tmp.height = width * 5 + gap * 6; -// std::cout << "main" << std::endl; - tmp.to_xml(); - - for (int addr = 0; raw_code; ++addr, raw_code >>= 3) { - - uint32_t block_x = addr % 4; - uint32_t block_y = (addr - block_x) / 4; - - switch (raw_code & 0b111) { - case B_1x1: - - tmp.top = width * block_y + gap * (block_y + 1) + top; - tmp.left = width * block_x + gap * (block_x + 1) + left; - tmp.height = width; - tmp.width = width; -// std::cout << "1x1" << std::endl; - tmp.to_xml(); - - break; - case B_1x2: - - tmp.top = width * block_y + gap * (block_y + 1) + top; - tmp.left = width * block_x + gap * (block_x + 1) + left; - tmp.height = width; - tmp.width = width * 2 + gap; -// std::cout << "1x2" << std::endl; - tmp.to_xml(); +//void SvgRect::to_xml() const { +// // TODO: return std::string +// printf(R"()", left, top, width, height); +// printf("\n"); +//} - break; - case B_2x1: - - tmp.top = width * block_y + gap * (block_y + 1) + top; - tmp.left = width * block_x + gap * (block_x + 1) + left; - tmp.height = width * 2 + gap; - tmp.width = width; -// std::cout << "2x1" << std::endl; - tmp.to_xml(); - - break; - case B_2x2: - - tmp.top = width * block_y + gap * (block_y + 1) + top; - tmp.left = width * block_x + gap * (block_x + 1) + left; - tmp.height = width * 2 + gap; - tmp.width = width * 2 + gap; -// std::cout << "2x2" << std::endl; - tmp.to_xml(); - - break; - default: - continue; - } - } - -} +//void SvgCase::render() const { +// +// std::string result; +// +// uint64_t raw_code = code; +// +//// std::cout << "start rander" << std::endl; +// +// auto tmp = SvgRect(); +// +// tmp.left = left; +// tmp.top = top; +// tmp.width = width * 4 + gap * 5; +// tmp.height = width * 5 + gap * 6; +//// std::cout << "main" << std::endl; +// tmp.to_xml(); +// +// for (int addr = 0; raw_code; ++addr, raw_code >>= 3) { +// +// uint32_t block_x = addr % 4; +// uint32_t block_y = (addr - block_x) / 4; +// +// switch (raw_code & 0b111) { +// case B_1x1: +// +// tmp.top = width * block_y + gap * (block_y + 1) + top; +// tmp.left = width * block_x + gap * (block_x + 1) + left; +// tmp.height = width; +// tmp.width = width; +//// std::cout << "1x1" << std::endl; +// tmp.to_xml(); +// +// break; +// case B_1x2: +// +// tmp.top = width * block_y + gap * (block_y + 1) + top; +// tmp.left = width * block_x + gap * (block_x + 1) + left; +// tmp.height = width; +// tmp.width = width * 2 + gap; +//// std::cout << "1x2" << std::endl; +// tmp.to_xml(); +// +// break; +// case B_2x1: +// +// tmp.top = width * block_y + gap * (block_y + 1) + top; +// tmp.left = width * block_x + gap * (block_x + 1) + left; +// tmp.height = width * 2 + gap; +// tmp.width = width; +//// std::cout << "2x1" << std::endl; +// tmp.to_xml(); +// +// break; +// case B_2x2: +// +// tmp.top = width * block_y + gap * (block_y + 1) + top; +// tmp.left = width * block_x + gap * (block_x + 1) + left; +// tmp.height = width * 2 + gap; +// tmp.width = width * 2 + gap; +//// std::cout << "2x2" << std::endl; +// tmp.to_xml(); +// +// break; +// default: +// continue; +// } +// } +// +//} diff --git a/src/graph/graph.h b/src/graph/graph.h index dc9f5c7..ea9d232 100644 --- a/src/graph/graph.h +++ b/src/graph/graph.h @@ -2,33 +2,33 @@ #include "analyse.h" -class SvgRect { -public: - uint64_t top; - uint64_t left; - uint64_t width; - uint64_t height; - - // TODO: color options - - void to_xml() const; - -}; - -class SvgCase { -public: - - uint64_t code; - - uint64_t top = 0; - uint64_t left = 0; - - uint32_t gap = 4; - uint32_t width = 12; - - void render() const; - -}; +//class SvgRect { +//public: +// uint64_t top; +// uint64_t left; +// uint64_t width; +// uint64_t height; +// +// // TODO: color options +// +// void to_xml() const; +// +//}; + +//class SvgCase { +//public: +// +// uint64_t code; +// +// uint64_t top = 0; +// uint64_t left = 0; +// +// uint32_t gap = 4; +// uint32_t width = 12; +// +// void render() const; +// +//}; class Graph { diff --git a/src/graph/svg/CMakeLists.txt b/src/graph/svg/CMakeLists.txt new file mode 100644 index 0000000..1c8e024 --- /dev/null +++ b/src/graph/svg/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.0) + +add_library(svg svg.cc) diff --git a/src/graph/svg/svg.cc b/src/graph/svg/svg.cc new file mode 100644 index 0000000..08a8457 --- /dev/null +++ b/src/graph/svg/svg.cc @@ -0,0 +1,50 @@ +#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"("; + +} diff --git a/src/graph/svg/svg.h b/src/graph/svg/svg.h new file mode 100644 index 0000000..57b0f52 --- /dev/null +++ b/src/graph/svg/svg.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +class SvgRect { +public: + uint64_t top; + uint64_t left; + uint64_t width; + uint64_t height; + uint64_t radius = 0; + uint32_t stroke = 1; + + float opacity = 0; + float line_opacity = 0; + std::string color = "pink"; + std::string line_color = "blue"; + + std::string dump() const; +};