Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substrate heatmaps in SVGs, defined in config file #219

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add substrate label to colorbar in svg plot
Also, add the substrate element to the template project's SVG element in the config file. set to enabled="false" so as not to force this
  • Loading branch information
drbergman committed Apr 15, 2024
commit 3ab55766bff3761ab719cab9c0739a01395c16b6
11 changes: 11 additions & 0 deletions modules/PhysiCell_SVG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ bool Write_SVG_text( std::ostream& os, const char* str , double position_x, doub
return true;
}

void Write_SVG_text(std::ostream& os, const char* str , double position_x, double position_y, double font_size , const char* color , const char* font, double rotation)
{
double text_width = font_size * strlen(str) / 2.0; // estimate the width of the text
double text_height = font_size / 2.0; // estimate the height of the text

double center_x = position_x + text_width / 2.0;
double center_y = position_y + text_height / 2.0;

os << "<text x=\"" << position_x << "\" y=\"" << position_y << "\" font-size=\"" << font_size << "\" fill=\"" << color << "\" font-family=\"" << font << "\" transform=\"rotate(" << rotation << " " << center_x << " " << center_y << ")\">" << str << "</text>\n";
}

bool Write_SVG_circle( std::ostream& os, double center_x, double center_y, double radius, double stroke_size,
std::string stroke_color , std::string fill_color )
{
Expand Down
3 changes: 3 additions & 0 deletions modules/PhysiCell_SVG.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>

#ifndef _PhysiCell_SVG_h_
#define _PhysiCell_SVG_h_
Expand All @@ -78,6 +79,8 @@ bool Write_SVG_start( std::ostream& os, double width, double height );
bool Write_SVG_end( std::ostream& os );

bool Write_SVG_text( std::ostream& os, const char* str , double position_x, double position_y, double font_size , const char* color , const char* font);
void Write_SVG_text(std::ostream& os, const char* str , double position_x, double position_y, double font_size , const char* color , const char* font, double rotation);

bool Write_SVG_circle( std::ostream& os, double center_x, double center_y, double radius, double stroke_size, std::string stroke_color , std::string fill_color );

bool Write_SVG_rect( std::ostream& os , double UL_corner_x, double UL_corner_y, double width, double height,
Expand Down
4 changes: 4 additions & 0 deletions modules/PhysiCell_pathology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,10 @@ void SVG_plot(std::string filename, Microenvironment &M, double z_slice, double
PhysiCell_SVG_options.font_color.c_str(), PhysiCell_SVG_options.font.c_str()); // misterious values set with a trial and error approach due to OCD. But now the legend is coherent at pixel level

delete[] szString;

// add a label to the right of the colorbar defined by above Write_SVG_rect calls
Write_SVG_text(os, PhysiCell_settings.substrate_to_monitor.c_str(), upper_left_x + 35, top_margin + plot_height / 2, font_size,
PhysiCell_SVG_options.font_color.c_str(), PhysiCell_SVG_options.font.c_str(), 90.0);
}

Write_SVG_rect(os, 25.0 + plot_width, top_margin, 25.0, plot_height - 25, 0.002 * plot_height, "black", "none"); // nice black contour around the legend
Expand Down
6 changes: 6 additions & 0 deletions sample_projects/template/config/PhysiCell_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
<SVG>
<interval units="min">60</interval>
<enable>true</enable>
<plot_substrate enabled="false" limits="true">
<substrate>substrate</substrate>
<colormap>YlOrRd</colormap>
<min_conc>0</min_conc>
<max_conc>1</max_conc>
</plot_substrate>
</SVG>

<legacy_data>
Expand Down
Loading