diff --git a/src/graph/graph.cc b/src/graph/graph.cc index cd13391..90b05ab 100644 --- a/src/graph/graph.cc +++ b/src/graph/graph.cc @@ -1,4 +1,5 @@ #include "graph.h" +#include "common.h" #include #include @@ -69,6 +70,14 @@ void Graph::svg_demo(Analyse::track_data_t track_data) { printf(R"()", MAIN_WIDTH, MAIN_HEIGHT); printf("\n"); +// SvgCase test = SvgCase(); +// test.width = BLOCK_LENGTH; +// test.gap = BLOCK_GAP; +// test.left = 50; +// test.top = 100; +// test.code = layer_data[0][0].code; +// test.render(); + for (uint32_t i = 0; i < layer_data.size(); ++i) { uint64_t CASE_Y = CASE_GAP_Y * (i + 1) + CASE_HEIGHT * i; @@ -81,8 +90,16 @@ void Graph::svg_demo(Analyse::track_data_t track_data) { uint64_t CASE_X = CASE_GAP_X * (j + 1) + CASE_WIDTH * j + left_offset; // printf("(%ld, %ld, %ld, %ld)\n", CASE_Y, CASE_X, CASE_WIDTH, CASE_HEIGHT); - printf(R"( )", CASE_X, CASE_Y, CASE_WIDTH, CASE_HEIGHT); - printf("\n"); +// 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(); } @@ -92,3 +109,79 @@ 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(); + + 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 6608a29..dc9f5c7 100644 --- a/src/graph/graph.h +++ b/src/graph/graph.h @@ -2,7 +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 Graph {