File tree Expand file tree Collapse file tree 4 files changed +18
-5
lines changed Expand file tree Collapse file tree 4 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 13
13
#include < iostream>
14
14
#include < sstream>
15
15
#include < tuple>
16
+ #include < vector>
16
17
17
18
namespace actsvg {
18
19
19
20
namespace utils {
20
21
22
+ // How to format values in string output
23
+ enum class value_format : unsigned int {
24
+ e_scientific,
25
+ e_default,
26
+ };
27
+
21
28
/* * Helper method to run enumerate(...) with structured binding
22
29
* over STL type containers.
23
30
*
@@ -135,7 +142,8 @@ std::string id_to_url(const std::string &id_);
135
142
*
136
143
* @return a string
137
144
*/
138
- std::string to_string (const scalar &s_, size_t pr_ = 4 );
145
+ std::string to_string (const scalar &s_, size_t pr_ = 4 ,
146
+ value_format f_ = value_format::e_default);
139
147
140
148
/* * Helper to format point2
141
149
*
Original file line number Diff line number Diff line change @@ -1086,18 +1086,19 @@ svg::object gradient_box(
1086
1086
1087
1087
// Create the tick value
1088
1088
scalar value = std::get<1 >(stops_[is]);
1089
+ std::string val_str{utils::to_string (value, 4 , utils::value_format::e_scientific)};
1089
1090
1090
1091
svg::object tval =
1091
1092
vertical
1092
1093
? draw::text (
1093
1094
id_ + " _tick_val_" + std::to_string (is),
1094
1095
{static_cast <scalar>(p_[0 ] + w_ + 0.2 * font_._size ),
1095
1096
p_[1 ] + h_ * s.first },
1096
- {utils::to_string (value) }, font_)
1097
+ {val_str }, font_)
1097
1098
: draw::text (id_ + " _tick_val_" + std::to_string (is),
1098
1099
{p_[0 ] + w_ * s.first ,
1099
1100
static_cast <scalar>(p_[1 ] - 1.2 * font_._size )},
1100
- {utils::to_string (value) }, font_);
1101
+ {val_str }, font_);
1101
1102
tval._sterile = true ;
1102
1103
tval._attribute_map [" alignment-baseline" ] = " middle" ;
1103
1104
if (not vertical) {
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ rgb gradient::rgb_from_scale(scalar s_) const {
42
42
s_ < 0 ._scalar ? 0 ._scalar : (s_ > 1 ._scalar ? 1 ._scalar : s_);
43
43
// find our stops
44
44
unsigned int is = 1u ;
45
- for (; is <= _stops.size (); ++is) {
45
+ for (; is < _stops.size (); ++is) {
46
46
if (_stops[is].first > s_reg) {
47
47
break ;
48
48
}
Original file line number Diff line number Diff line change 13
13
#include < tuple>
14
14
15
15
#include " actsvg/core/defs.hpp"
16
+ #include " actsvg/core/utils.hpp"
16
17
17
18
namespace actsvg {
18
19
@@ -21,8 +22,11 @@ std::string id_to_url(const std::string &id_) {
21
22
return std::string (" url(#" ) + id_ + " )" ;
22
23
}
23
24
24
- std::string to_string (const scalar &s_, size_t pr_) {
25
+ std::string to_string (const scalar &s_, size_t pr_, value_format f_ ) {
25
26
std::stringstream sstream;
27
+ if (f_ == value_format::e_scientific) {
28
+ sstream << std::scientific;
29
+ }
26
30
sstream << std::setprecision (pr_) << s_;
27
31
return sstream.str ();
28
32
}
You can’t perform that action at this time.
0 commit comments