Skip to content

Commit

Permalink
EpsPlumes: add labels for the background
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvielamythepaut committed Feb 15, 2023
1 parent deb34de commit 7ba905f
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/attributes/EpsPlumeAttributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ EpsPlumeAttributes::EpsPlumeAttributes():
shading_levels_(ParameterManager::getDoubleArray("eps_plume_shading_level_list")),
shading_colours_(ParameterManager::getStringArray("eps_plume_shading_colour_list")),
background_level_list_(ParameterManager::getDoubleArray("eps_plume_background_level_list")),
background_colour_list_(ParameterManager::getStringArray("eps_plume_background_colour_list"))
background_colour_list_(ParameterManager::getStringArray("eps_plume_background_colour_list")),
background_label_list_(ParameterManager::getStringArray("eps_plume_background_label_list")),
background_label_font_(ParameterManager::getString("eps_plume_background_label_font")),
background_label_font_size_(ParameterManager::getDouble("eps_plume_background_label_font_size")),
background_label_font_style_(ParameterManager::getString("eps_plume_background_label_font_style"))
,
line_colour_(MagTranslator<string, Colour>().magics("eps_plume_line_colour")),
line_style_(MagTranslator<string, LineStyle>().magics("eps_plume_line_style")),
Expand All @@ -48,7 +52,8 @@ EpsPlumeAttributes::EpsPlumeAttributes():
control_line_colour_(MagTranslator<string, Colour>().magics("eps_plume_control_line_colour")),
control_line_style_(MagTranslator<string, LineStyle>().magics("eps_plume_control_line_style")),
median_line_colour_(MagTranslator<string, Colour>().magics("eps_plume_median_line_colour")),
median_line_style_(MagTranslator<string, LineStyle>().magics("eps_plume_median_line_style"))
median_line_style_(MagTranslator<string, LineStyle>().magics("eps_plume_median_line_style")),
background_label_font_colour_(MagTranslator<string, Colour>().magics("eps_plume_background_label_font_colour"))

{
}
Expand Down Expand Up @@ -82,6 +87,10 @@ void EpsPlumeAttributes::set(const std::map<string, string>& params)
setAttribute(prefix, "eps_plume_shading_colour_list", shading_colours_, params);
setAttribute(prefix, "eps_plume_background_level_list", background_level_list_, params);
setAttribute(prefix, "eps_plume_background_colour_list", background_colour_list_, params);
setAttribute(prefix, "eps_plume_background_label_list", background_label_list_, params);
setAttribute(prefix, "eps_plume_background_label_font", background_label_font_, params);
setAttribute(prefix, "eps_plume_background_label_font_size", background_label_font_size_, params);
setAttribute(prefix, "eps_plume_background_label_font_style", background_label_font_style_, params);

setMember(prefix, "eps_plume_line_colour", line_colour_, params);
setAttribute(prefix, "eps_plume_line_style", line_style_, params);
Expand All @@ -91,6 +100,7 @@ void EpsPlumeAttributes::set(const std::map<string, string>& params)
setAttribute(prefix, "eps_plume_control_line_style", control_line_style_, params);
setMember(prefix, "eps_plume_median_line_colour", median_line_colour_, params);
setAttribute(prefix, "eps_plume_median_line_style", median_line_style_, params);
setMember(prefix, "eps_plume_background_label_font_colour", background_label_font_colour_, params);

}

Expand All @@ -111,6 +121,10 @@ void EpsPlumeAttributes::copy(const EpsPlumeAttributes& other)
shading_colours_ = other.shading_colours_;
background_level_list_ = other.background_level_list_;
background_colour_list_ = other.background_colour_list_;
background_label_list_ = other.background_label_list_;
background_label_font_ = other.background_label_font_;
background_label_font_size_ = other.background_label_font_size_;
background_label_font_style_ = other.background_label_font_style_;
line_colour_ = unique_ptr<Colour>(other.line_colour_->clone());
line_style_ = other.line_style_;
forecast_line_colour_ = unique_ptr<Colour>(other.forecast_line_colour_->clone());
Expand All @@ -119,6 +133,7 @@ void EpsPlumeAttributes::copy(const EpsPlumeAttributes& other)
control_line_style_ = other.control_line_style_;
median_line_colour_ = unique_ptr<Colour>(other.median_line_colour_->clone());
median_line_style_ = other.median_line_style_;
background_label_font_colour_ = unique_ptr<Colour>(other.background_label_font_colour_->clone());

}

Expand Down Expand Up @@ -172,6 +187,10 @@ void EpsPlumeAttributes::print(ostream& out) const
out << " shading_colours = " << shading_colours_;
out << " background_level_list = " << background_level_list_;
out << " background_colour_list = " << background_colour_list_;
out << " background_label_list = " << background_label_list_;
out << " background_label_font = " << background_label_font_;
out << " background_label_font_size = " << background_label_font_size_;
out << " background_label_font_style = " << background_label_font_style_;
out << " line_colour = " << *line_colour_;
out << " line_style = " << line_style_;
out << " forecast_line_colour = " << *forecast_line_colour_;
Expand All @@ -180,6 +199,7 @@ void EpsPlumeAttributes::print(ostream& out) const
out << " control_line_style = " << control_line_style_;
out << " median_line_colour = " << *median_line_colour_;
out << " median_line_style = " << median_line_style_;
out << " background_label_font_colour = " << *background_label_font_colour_;

out << "]" << "\n";
}
Expand Down Expand Up @@ -217,6 +237,14 @@ void EpsPlumeAttributes::toxml(ostream& out) const
niceprint(out,background_level_list_);
out << ", \"eps_plume_background_colour_list\":";
niceprint(out,background_colour_list_);
out << ", \"eps_plume_background_label_list\":";
niceprint(out,background_label_list_);
out << ", \"eps_plume_background_label_font\":";
niceprint(out,background_label_font_);
out << ", \"eps_plume_background_label_font_size\":";
niceprint(out,background_label_font_size_);
out << ", \"eps_plume_background_label_font_style\":";
niceprint(out,background_label_font_style_);
out << ", \"eps_plume_line_colour\":";
niceprint(out, *line_colour_);
out << ", \"eps_plume_line_style\":";
Expand All @@ -233,6 +261,8 @@ void EpsPlumeAttributes::toxml(ostream& out) const
niceprint(out, *median_line_colour_);
out << ", \"eps_plume_median_line_style\":";
niceprint(out, median_line_style_);
out << ", \"eps_plume_background_label_font_colour\":";
niceprint(out, *background_label_font_colour_);

}

Expand All @@ -251,6 +281,10 @@ static MagicsParameter<doublearray> eps_plume_shading_level_list("eps_plume_shad
static MagicsParameter<stringarray> eps_plume_shading_colour_list("eps_plume_shading_colour_list", stringarray());
static MagicsParameter<doublearray> eps_plume_background_level_list("eps_plume_background_level_list", floatarray());
static MagicsParameter<stringarray> eps_plume_background_colour_list("eps_plume_background_colour_list", stringarray());
static MagicsParameter<stringarray> eps_plume_background_label_list("eps_plume_background_label_list", stringarray());
static MagicsParameter<string> eps_plume_background_label_font("eps_plume_background_label_font", "sansserif");
static MagicsParameter<double> eps_plume_background_label_font_size("eps_plume_background_label_font_size", 0.25);
static MagicsParameter<string> eps_plume_background_label_font_style("eps_plume_background_label_font_style", "");
static MagicsParameter<string> eps_plume_line_colour("eps_plume_line_colour", "magenta");
static MagicsParameter<string> eps_plume_line_style("eps_plume_line_style", "solid");
static MagicsParameter<string> eps_plume_forecast_line_colour("eps_plume_forecast_line_colour", "cyan");
Expand All @@ -259,3 +293,4 @@ static MagicsParameter<string> eps_plume_control_line_colour("eps_plume_control_
static MagicsParameter<string> eps_plume_control_line_style("eps_plume_control_line_style", "solid");
static MagicsParameter<string> eps_plume_median_line_colour("eps_plume_median_line_colour", "cyan");
static MagicsParameter<string> eps_plume_median_line_style("eps_plume_median_line_style", "solid");
static MagicsParameter<string> eps_plume_background_label_font_colour("eps_plume_background_label_font_colour", "black");
5 changes: 5 additions & 0 deletions src/attributes/EpsPlumeAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class EpsPlumeAttributes
stringarray shading_colours_;
doublearray background_level_list_;
stringarray background_colour_list_;
stringarray background_label_list_;
string background_label_font_;
double background_label_font_size_;
string background_label_font_style_;
unique_ptr<Colour> line_colour_;
LineStyle line_style_;
unique_ptr<Colour> forecast_line_colour_;
Expand All @@ -74,6 +78,7 @@ class EpsPlumeAttributes
LineStyle control_line_style_;
unique_ptr<Colour> median_line_colour_;
LineStyle median_line_style_;
unique_ptr<Colour> background_label_font_colour_;


private:
Expand Down
23 changes: 23 additions & 0 deletions src/attributes/EpsPlumeWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,23 @@ void EpsPlumeWrapper::set(const MagRequest& request)
background_colour_list_value.push_back((string)request("EPS_PLUME_BACKGROUND_COLOUR_LIST", i));
if ( !background_colour_list_value.empty() )
epsplume_->background_colour_list_ = background_colour_list_value;
stringarray background_label_list_value;
for (int i = 0; i < request.countValues("EPS_PLUME_BACKGROUND_LABEL_LIST"); i++)
background_label_list_value.push_back((string)request("EPS_PLUME_BACKGROUND_LABEL_LIST", i));
if ( !background_label_list_value.empty() )
epsplume_->background_label_list_ = background_label_list_value;
if (request.countValues("EPS_PLUME_BACKGROUND_LABEL_FONT") ) {
string background_label_font_value = request("EPS_PLUME_BACKGROUND_LABEL_FONT");
epsplume_->background_label_font_ = background_label_font_value;
}
if (request.countValues("EPS_PLUME_BACKGROUND_LABEL_FONT_SIZE") ) {
double background_label_font_size_value = request("EPS_PLUME_BACKGROUND_LABEL_FONT_SIZE");
epsplume_->background_label_font_size_ = background_label_font_size_value;
}
if (request.countValues("EPS_PLUME_BACKGROUND_LABEL_FONT_STYLE") ) {
string background_label_font_style_value = request("EPS_PLUME_BACKGROUND_LABEL_FONT_STYLE");
epsplume_->background_label_font_style_ = background_label_font_style_value;
}

if (request.countValues("EPS_PLUME_LINE_COLOUR") ) {
string line_colour_value = request("EPS_PLUME_LINE_COLOUR");
Expand Down Expand Up @@ -176,6 +193,11 @@ void EpsPlumeWrapper::set(const MagRequest& request)
epsplume_->median_line_style_ = MagTranslator<string, LineStyle>()(median_line_style_value);
}

if (request.countValues("EPS_PLUME_BACKGROUND_LABEL_FONT_COLOUR") ) {
string background_label_font_colour_value = request("EPS_PLUME_BACKGROUND_LABEL_FONT_COLOUR");
epsplume_->background_label_font_colour_ = unique_ptr<Colour>(MagTranslator<string, Colour>()(background_label_font_colour_value));
}


}

Expand All @@ -193,3 +215,4 @@ void EpsPlumeWrapper::print(ostream& out) const




31 changes: 31 additions & 0 deletions src/params/EpsPlume.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,37 @@ does it submit to any jurisdiction.
name="eps_plume_background_colour_list">
<documentation>Background colour list</documentation>
</parameter>
<parameter member="background_label_list"
to="stringarray"
default="stringarray()"
from="stringarray"
name="eps_plume_background_label_list">
<documentation>Background colour list</documentation>
</parameter>
<parameter xml="background_label_"
from="string"
name="eps_plume_background_label_font"
default="sansserif"
member="background_label_font"
to="string"></parameter>
<parameter xml="font_size"
from="float"
name="eps_plume_background_label_font_size"
default="0.25"
member="background_label_font_size"
to="float"></parameter>
<parameter xml="background_label_style"
from="string"
name="eps_plume_background_label_font_style"
default=""
member="background_label_font_style"
to="string"></parameter>
<parameter xml="font_colour"
from="string"
name="eps_plume_background_label_font_colour"
default="black"
member="background_label_font_colour"
to="Colour"></parameter>

</class>
</magics>
16 changes: 16 additions & 0 deletions src/visualisers/EpsGraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2682,6 +2682,7 @@ void EpsPlume::background(BasicGraphicsObjectContainer& visitor) {
auto colour = background_colour_list_.begin();

auto level = background_level_list_.begin();
auto label = background_label_list_.begin();
double from = *level;
++level;

Expand All @@ -2706,6 +2707,21 @@ void EpsPlume::background(BasicGraphicsObjectContainer& visitor) {
area->push_back(PaperPoint(transformation.getMinX(), from));


}
if ( label != background_label_list_.end() ) {

Text* text = new Text();
text->setText(*label);
text->setJustification(Justification::LEFT);
MagFont font(background_label_font_, background_label_font_style_, background_label_font_size_);
font.colour(*background_label_font_colour_);
text->setFont(font);
double x = transformation.getMinX() + (transformation.getMaxX() - transformation.getMinX())*0.01;
double y = from + (to-from)*0.1;

text->push_back(PaperPoint(x, y));
visitor.push_back(text);
++label;
}
from = *level;
++colour;
Expand Down

0 comments on commit 7ba905f

Please sign in to comment.