Browse Source

feat: single case graph render

legacy
Dnomd343 2 years ago
parent
commit
e723b1627b
  1. 98
      src/graph/graph.cc
  2. 38
      src/graph/graph.h
  3. 4
      src/graph/svg/svg.cc
  4. 13
      src/graph/svg/svg.h

98
src/graph/graph.cc

@ -31,6 +31,22 @@ void Graph::svg_demo(Analyse::track_data_t track_data) {
//
// }
auto p = Point{100, 200};
auto rc = RawCode::unsafe_create(0x0603EDF5CAFFF5E2);
auto gc = GraphCase(p, rc, BLOCK_GAP, BLOCK_LENGTH);
auto skin = CaseSkin();
auto svg = SvgGraph(2000, 2000);
gc.render(svg, skin);
std::cout << svg.dump() << std::endl;
return;
struct inner_t {
uint64_t code;
uint32_t layer_num;
@ -69,16 +85,6 @@ void Graph::svg_demo(Analyse::track_data_t track_data) {
// std::cout << "MAIN_WIDTH = " << MAIN_WIDTH << std::endl;
// std::cout << "MAIN_HEIGHT = " << MAIN_HEIGHT << std::endl;
printf(R"(<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="%ld" height="%ld">)", 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) {
@ -187,3 +193,75 @@ void Graph::svg_demo(Analyse::track_data_t track_data) {
// }
//
//}
void GraphCase::render(SvgGraph &svg, const CaseSkin &skin) const {
// std::cout << "render begin" << std::endl;
auto raw_code = (uint64_t)code;
uint32_t case_width = block_width * 4 + block_gap * 5;
uint32_t case_height = block_width * 5 + block_gap * 6;
auto skeleton = new SvgRect {start, case_width, case_height};
skeleton->color = "pink";
svg.insert(skeleton);
for (int addr = 0; raw_code; ++addr, raw_code >>= 3) {
uint32_t block_x = addr % 4;
uint32_t block_y = (addr - block_x) / 4;
// TODO: same start point
switch (raw_code & 0b111) {
case B_1x1:
svg.insert(new SvgRect {
{
start.x + block_x * block_width + (block_x + 1) * block_gap,
start.y + block_y * block_width + (block_y + 1) * block_gap,
},
block_width, block_width,
});
break;
case B_1x2:
svg.insert(new SvgRect {
{
start.x + block_x * block_width + (block_x + 1) * block_gap,
start.y + block_y * block_width + (block_y + 1) * block_gap,
},
block_width * 2 + block_gap, block_width,
});
break;
case B_2x1:
svg.insert(new SvgRect {
{
start.x + block_x * block_width + (block_x + 1) * block_gap,
start.y + block_y * block_width + (block_y + 1) * block_gap,
},
block_width, block_width * 2 + block_gap,
});
break;
case B_2x2:
svg.insert(new SvgRect {
{
start.x + block_x * block_width + (block_x + 1) * block_gap,
start.y + block_y * block_width + (block_y + 1) * block_gap,
},
block_width * 2 + block_gap, block_width * 2 + block_gap,
});
break;
default:
continue;
}
}
}

38
src/graph/graph.h

@ -1,20 +1,20 @@
#pragma once
#include "analyse.h"
#include "svg/svg.h"
//class SvgRect {
//public:
// uint64_t top;
// uint64_t left;
// uint64_t width;
// uint64_t height;
//
// // TODO: color options
//
// void to_xml() const;
//
#include "raw_code.h"
//struct BlockOpt {
// uint32_t gap;
// uint32_t width;
//};
class CaseSkin {
public:
std::string color = "pink";
};
//class SvgCase {
//public:
//
@ -30,6 +30,22 @@
//
//};
class GraphCase {
public:
Point start;
RawCode code;
uint32_t block_gap;
uint32_t block_width;
GraphCase(Point p, RawCode c, uint32_t gap, uint32_t width) : start(p), code(c) {
block_gap = gap;
block_width = width;
}
void render(SvgGraph &svg, const CaseSkin &skin) const;
};
class Graph {
public:

4
src/graph/svg/svg.cc

@ -23,8 +23,8 @@ std::string SvgLine::dump() const {
std::string SvgRect::dump() const {
/// basic attributes of svg-rect
std::string xml = "<rect ";
xml += "x=\"" + std::to_string(left) + "\" ";
xml += "y=\"" + std::to_string(top) + "\" ";
xml += "x=\"" + std::to_string(start.x) + "\" ";
xml += "y=\"" + std::to_string(start.y) + "\" ";
xml += "width=\"" + std::to_string(width) + "\" ";
xml += "height=\"" + std::to_string(height) + "\" ";
if (radius != 0) {

13
src/graph/svg/svg.h

@ -4,6 +4,12 @@
#include <cstdint>
#include <vector>
class Point {
public:
uint64_t x;
uint64_t y;
};
class SvgObject {
public:
virtual ~SvgObject() = default;
@ -42,8 +48,9 @@ public:
class SvgRect : public SvgObject {
public:
uint64_t top;
uint64_t left;
Point start;
// uint64_t top;
// uint64_t left;
uint64_t width;
uint64_t height;
@ -58,5 +65,5 @@ public:
~SvgRect() override = default;
std::string dump() const override;
SvgRect(uint64_t t, uint64_t l, uint64_t w, uint64_t h) : top(t), left(l), width(w), height(h) {}
SvgRect(Point p, uint64_t w, uint64_t h) : start(p), width(w), height(h) {}
};

Loading…
Cancel
Save