File tree Expand file tree Collapse file tree 4 files changed +21
-6
lines changed Expand file tree Collapse file tree 4 files changed +21
-6
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,25 +1086,27 @@ 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{
1090
+ utils::to_string (value, 4 , utils::value_format::e_scientific)};
1089
1091
1090
1092
svg::object tval =
1091
1093
vertical
1092
1094
? draw::text (
1093
1095
id_ + " _tick_val_" + std::to_string (is),
1094
1096
{static_cast <scalar>(p_[0 ] + w_ + 0.2 * font_._size ),
1095
1097
p_[1 ] + h_ * s.first },
1096
- {utils::to_string (value) }, font_)
1098
+ {val_str }, font_)
1097
1099
: draw::text (id_ + " _tick_val_" + std::to_string (is),
1098
1100
{p_[0 ] + w_ * s.first ,
1099
1101
static_cast <scalar>(p_[1 ] - 1.2 * font_._size )},
1100
- {utils::to_string (value) }, font_);
1102
+ {val_str }, font_);
1101
1103
tval._sterile = true ;
1102
1104
tval._attribute_map [" alignment-baseline" ] = " middle" ;
1103
1105
if (not vertical) {
1104
1106
tval._attribute_map [" text-anchor" ] = " middle" ;
1105
1107
}
1106
1108
font_.attach_attributes (tval);
1107
- tval._field = {utils::to_string (value )};
1109
+ tval._field = {std::move (val_str )};
1108
1110
g.add_object (tval);
1109
1111
}
1110
1112
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 6
6
// License, v. 2.0. If a copy of the MPL was not distributed with this
7
7
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
8
9
+ #include " actsvg/core/utils.hpp"
10
+
9
11
#include < cmath>
10
12
#include < iomanip>
11
13
#include < iostream>
@@ -21,8 +23,11 @@ std::string id_to_url(const std::string &id_) {
21
23
return std::string (" url(#" ) + id_ + " )" ;
22
24
}
23
25
24
- std::string to_string (const scalar &s_, size_t pr_) {
26
+ std::string to_string (const scalar &s_, size_t pr_, value_format f_ ) {
25
27
std::stringstream sstream;
28
+ if (f_ == value_format::e_scientific) {
29
+ sstream << std::scientific;
30
+ }
26
31
sstream << std::setprecision (pr_) << s_;
27
32
return sstream.str ();
28
33
}
You can’t perform that action at this time.
0 commit comments