Skip to content

Commit

Permalink
Merge pull request #555 from pangenome/draw_svg
Browse files Browse the repository at this point in the history
`odgi draw`: fix SVG output
  • Loading branch information
AndreaGuarracino authored Feb 7, 2024
2 parents c5093a3 + d46016f commit 9ae6a65
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/algorithms/atomic_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,20 @@ std::string to_rgba(const color_t& c) {
ss << (int)c.c.r << ",";
ss << (int)c.c.g << ",";
ss << (int)c.c.b << ",";
ss << (int)c.c.a << ")";
ss << (int)c.c.a << ")";
return ss.str();
}

std::string to_hexrgb(const color_t& c) {
std::stringstream ss;
ss << "#";
ss << std::hex << std::uppercase; // Use hexadecimal format
ss << std::setfill('0') << std::setw(2) << (int)c.c.r;
ss << std::setfill('0') << std::setw(2) << (int)c.c.g;
ss << std::setfill('0') << std::setw(2) << (int)c.c.b;
return ss.str();
}

// helpers

double u_ipart(double x) { return std::floor(x); }
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/atomic_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ color_t mix(const color_t& a, const color_t& b, const double& f);

std::string to_hex(const color_t& c);
std::string to_rgba(const color_t& c);
std::string to_hexrgb(const color_t& c);

const color_t COLOR_BLACK = { 0xff000000 };
const color_t COLOR_LIGHTGRAY = { 0xffD3D3D3 };
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void draw_svg(std::ostream &out,
<< (Y[a] * scale) + y_off
<< "\" y2=\""
<< (Y[a + 1] * scale) + y_off
<< "\" stroke=\"" << to_rgba(color)
<< "\" stroke=\"" << to_hexrgb(color) //to_rgba(color) // with rgb, nodes are invisible with InkScape
<< "\" stroke-width=\"" << line_width
<< "\"/>"
<< std::endl;
Expand Down
4 changes: 2 additions & 2 deletions src/subcommand/draw_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main_draw(int argc, char **argv) {
args::Flag color_paths(visualizations_opts, "color-paths", "Color paths (in PNG output).", {'C', "color-paths"});
args::ValueFlag<double> render_scale(visualizations_opts, "N", "Image scaling (default 0.001).", {'R', "scale"});
args::ValueFlag<double> render_border(visualizations_opts, "N", "Image border (in approximate bp) (default 100.0).", {'B', "border"});
args::ValueFlag<double> png_line_width(visualizations_opts, "N", "Line width (in approximate bp) (default 0.0).", {'w', "line-width"});
args::ValueFlag<double> png_line_width(visualizations_opts, "N", "Line width (in approximate bp) (default 10.0).", {'w', "line-width"});
//args::ValueFlag<double> png_line_overlay(parser, "N", "line width (in approximate bp) (default 10.0)", {'O', "line-overlay"});
args::ValueFlag<double> png_path_line_spacing(visualizations_opts, "N", "Spacing between path lines in PNG layout (in approximate bp) (default 0.0).", {'S', "path-line-spacing"});
args::ValueFlag<std::string> _path_bed_file(visualizations_opts, "FILE",
Expand Down Expand Up @@ -171,7 +171,7 @@ int main_draw(int argc, char **argv) {
}

const uint64_t _png_height = png_height ? args::get(png_height) : 1000;
const double _png_line_width = png_line_width ? args::get(png_line_width) : 0;
const double _png_line_width = png_line_width ? args::get(png_line_width) : 10.0;
const bool _color_paths = args::get(color_paths);
const double _png_path_line_spacing = png_path_line_spacing ? args::get(png_path_line_spacing) : 0.0;
const double svg_scale = !render_scale ? 0.01 : args::get(render_scale);
Expand Down

0 comments on commit 9ae6a65

Please sign in to comment.