@@ -168,29 +168,7 @@ coColorBar::coColorBar(const std::string &name, const ColorMap &map, bool inMenu
168168 speciesLabel_ = new vrui::coLabel ();
169169 speciesLabel_->setUniqueName (" speciesLabel" );
170170
171- std::string precision = covise::coCoviseConfig::getEntry (" COVER.Plugin.ColorBars.Precision" );
172- if (!precision.empty ())
173- {
174- sprintf (format_str_, " %%.%sf" , precision.c_str ());
175- }
176- else if ((fabs (map.max ()) > 1e-4 || fabs (map.min ()) > 1e-4 ) && fabs (map.min ()) < 1e+6 && fabs (map.max ()) < 1e+6 )
177- {
178- int ndig = 5 ;
179- int prec = std::max (0 , ndig-(int )std::log10 (std::max (fabs (map.min ()), fabs (map.max ()))));
180- std::string sign = " " ;
181- if (map.min () < 0 || map.max () < 0 )
182- sign = " +" ;
183- sprintf (format_str_, " %%%s%d.%df" , sign.c_str (), ndig-prec, prec);
184- }
185- else if (map.min () < 0 )
186- {
187- sprintf (format_str_, " %%+g" );
188- }
189- else
190- {
191- sprintf (format_str_, " %%g" );
192- }
193-
171+ precision_ = covise::coCoviseConfig::getEntry (" COVER.Plugin.ColorBars.Precision" );
194172 // create texture
195173 image_.resize (4 * 256 * 2 ); // 4 componenten, 256*2 gross
196174 makeImage (map, map.min () > map.max ());
@@ -274,16 +252,38 @@ void
274252coColorBar::update (const ColorMap &map)
275253{
276254 char str[100 ];
277- // use - and + symbyls with same width
255+ // use - and + symbols with same width
278256 // const char minus[] = "\u2212"; // minus
279- // const char minus[] = "\uff0d"; // full-width hypen minus
257+ // const char minus[] = "\uff0d"; // full-width hyphen minus
280258 const char minus[] = " \u2013 " ; // en-dash
281259 // const char plus[] = "\uff0b"; // full-width plus
282260 const char plus[] = " +" ;
283261 // const char space[] = "\u2002"; // en-space
284262 const char space[] = " " ;
285263 const size_t off = std::max (sizeof space, std::max (sizeof minus,sizeof plus)-2 ); // reuse one char, don't count terminating 0
286264
265+ if (!precision_.empty ())
266+ {
267+ sprintf (format_str_, " %%.%sf" , precision_.c_str ());
268+ }
269+ else if ((fabs (map.max ()) > 1e-4 || fabs (map.min ()) > 1e-4 ) && fabs (map.min ()) < 1e+6 && fabs (map.max ()) < 1e+6 )
270+ {
271+ int ndig = 5 ;
272+ int prec = std::max (0 , ndig - (int )std::log10 (std::max (fabs (map.min ()), fabs (map.max ()))));
273+ std::string sign = " " ;
274+ if (map.min () < 0 || map.max () < 0 )
275+ sign = " +" ;
276+ sprintf (format_str_, " %%%s%d.%df" , sign.c_str (), ndig - prec, prec);
277+ }
278+ else if (map.min () < 0 )
279+ {
280+ sprintf (format_str_, " %%+g" );
281+ }
282+ else
283+ {
284+ sprintf (format_str_, " %%g" );
285+ }
286+
287287 // remove old labels
288288 for (size_t i = 0 ; i < MAX_LABELS ; i++)
289289 {
@@ -307,13 +307,13 @@ coColorBar::update(const ColorMap &map)
307307 }
308308 else if (str[off] == ' +' )
309309 {
310- for (size_t j= 0 ; j< sizeof plus- 1 ; ++j)
310+ for (size_t j = 0 ; j < sizeof ( plus) - 1 ; ++j)
311311 str[off+2 -sizeof (plus)+j] = plus[j];
312312 labels_[i]->setString (str+off+2 -sizeof plus);
313313 }
314314 else if (str[off] == ' ' )
315315 {
316- for (size_t j= 0 ; j< sizeof space- 1 ; ++j)
316+ for (size_t j = 0 ; j < sizeof ( space) - 1 ; ++j)
317317 str[off+2 -sizeof (space)] = space[j];
318318 labels_[i]->setString (str+off+2 -sizeof space);
319319 }
0 commit comments