File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313#include < iostream>
1414#include < sstream>
1515#include < tuple>
16+ #include < vector>
1617
1718namespace actsvg {
1819
1920namespace utils {
2021
22+ // How to format values in string output
23+ enum class value_format : unsigned int {
24+ e_scientific,
25+ e_default,
26+ };
27+
2128/* * Helper method to run enumerate(...) with structured binding
2229 * over STL type containers.
2330 *
@@ -135,7 +142,8 @@ std::string id_to_url(const std::string &id_);
135142 *
136143 * @return a string
137144 */
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);
139147
140148/* * Helper to format point2
141149 *
Original file line number Diff line number Diff line change @@ -1086,18 +1086,19 @@ svg::object gradient_box(
10861086
10871087 // Create the tick value
10881088 scalar value = std::get<1 >(stops_[is]);
1089+ std::string val_str{utils::to_string (value, 4 , utils::value_format::e_scientific)};
10891090
10901091 svg::object tval =
10911092 vertical
10921093 ? draw::text (
10931094 id_ + " _tick_val_" + std::to_string (is),
10941095 {static_cast <scalar>(p_[0 ] + w_ + 0.2 * font_._size ),
10951096 p_[1 ] + h_ * s.first },
1096- {utils::to_string (value) }, font_)
1097+ {val_str }, font_)
10971098 : draw::text (id_ + " _tick_val_" + std::to_string (is),
10981099 {p_[0 ] + w_ * s.first ,
10991100 static_cast <scalar>(p_[1 ] - 1.2 * font_._size )},
1100- {utils::to_string (value) }, font_);
1101+ {val_str }, font_);
11011102 tval._sterile = true ;
11021103 tval._attribute_map [" alignment-baseline" ] = " middle" ;
11031104 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 {
4242 s_ < 0 ._scalar ? 0 ._scalar : (s_ > 1 ._scalar ? 1 ._scalar : s_);
4343 // find our stops
4444 unsigned int is = 1u ;
45- for (; is <= _stops.size (); ++is) {
45+ for (; is < _stops.size (); ++is) {
4646 if (_stops[is].first > s_reg) {
4747 break ;
4848 }
Original file line number Diff line number Diff line change 1313#include < tuple>
1414
1515#include " actsvg/core/defs.hpp"
16+ #include " actsvg/core/utils.hpp"
1617
1718namespace actsvg {
1819
@@ -21,8 +22,11 @@ std::string id_to_url(const std::string &id_) {
2122 return std::string (" url(#" ) + id_ + " )" ;
2223}
2324
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_ ) {
2526 std::stringstream sstream;
27+ if (f_ == value_format::e_scientific) {
28+ sstream << std::scientific;
29+ }
2630 sstream << std::setprecision (pr_) << s_;
2731 return sstream.str ();
2832}
You can’t perform that action at this time.
0 commit comments