Mercurial > hg > octave-nkf
diff libinterp/interpfcn/graphics.cc @ 16750:fd5a4b7f59f7
add format option to ticklabel (bug #34906)
* graphics.cc: add new functions to support different input arguments to
xyzticklabel. Add tests.
* graphics.in.h: define set_xyzticklabel as external function
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Tue, 11 Jun 2013 21:16:41 +0800 |
parents | d81ef5e64cf1 |
children | 64e7bb01fce2 |
line wrap: on
line diff
--- a/libinterp/interpfcn/graphics.cc +++ b/libinterp/interpfcn/graphics.cc @@ -2059,6 +2059,34 @@ } /* +## test set ticklabels for compatibility +%!test +%! set (gcf (), "visible", "off") +%! set (gca (), "xticklabel", [0, 0.2, 0.4, 0.6, 0.8, 1]) +%! xticklabel = get (gca (), "xticklabel"); +%! assert (class (xticklabel), "char") +%! assert (size (xticklabel), [6, 3]) +%!test +%! set (gcf (), "visible", "off") +%! set (gca (), "xticklabel", "0|0.2|0.4|0.6|0.8|1") +%! xticklabel = get (gca (), "xticklabel"); +%! assert (class (xticklabel), "char") +%! assert (size (xticklabel), [6, 3]) +%!test +%! set (gcf (), "visible", "off") +%! set (gca (), "xticklabel", ["0 "; "0.2"; "0.4"; "0.6"; "0.8"; "1 "]) +%! xticklabel = get (gca (), "xticklabel"); +%! assert (class (xticklabel), "char") +%! assert (size (xticklabel), [6, 3]) +%!xtest +%! set (gcf (), "visible", "off") +%! set (gca (), "xticklabel", {"0", "0.2", "0.4", "0.6", "0.8", "1"}) +%! xticklabel = get (gca (), "xticklabel"); +%! assert (class (xticklabel), "cell") +%! assert (size (xticklabel), [6, 1]) +*/ + +/* ## test set with struct arguments %!test %! set (gcf, "visible", "off"); @@ -5708,6 +5736,110 @@ return ext; } +static octave_value +convert_ticklabel_string(const octave_value& val) +{ + octave_value retval = val; + + if (!val.is_cellstr ()) + { + string_vector str; + if (val.is_float_type () || val.is_integer_type ()) + { + NDArray data = val.array_value (); + std::ostringstream s; + s.precision (5); + for (octave_idx_type i = 0; i < val.numel (); i++) + { + s.str(""); + s << data(i); + str.append (s.str()); + } + } + else if (val.is_string () && val.rows () == 1) + { + std::string tmpstr(val.string_value ()); + char separator = '|'; + size_t pos = 0; + while (true) + { + size_t new_pos = tmpstr.find_first_of (separator, pos); + + if (new_pos == std::string::npos) + { + std::string tmp = tmpstr.substr (pos); + str.append(tmp); + break; + } + else + { + std::string tmp = tmpstr.substr (pos, new_pos - pos); + str.append (tmp); + } + pos = new_pos + 1; + } + } + else + return retval; + + charMatrix ch(str); + for (octave_idx_type i = 0; i < ch.numel(); i++) + if (ch(i) == 0) + ch(i) = ' '; + retval = octave_value(ch); + + } + return retval; +} + +void +axes::properties::set_xticklabel(const octave_value& v) +{ + if (!error_state) + { + if (xticklabel.set(convert_ticklabel_string(v), false)) + { + set_xticklabelmode("manual"); + xticklabel.run_listeners(POSTSET); + mark_modified(); + } + else + set_xticklabelmode("manual"); + } +} + +void +axes::properties::set_yticklabel(const octave_value& v) +{ + if (!error_state) + { + if (yticklabel.set(convert_ticklabel_string(v), false)) + { + set_yticklabelmode("manual"); + yticklabel.run_listeners(POSTSET); + mark_modified(); + } + else + set_yticklabelmode("manual"); + } +} + +void +axes::properties::set_zticklabel(const octave_value& v) +{ + if (!error_state) + { + if (zticklabel.set(convert_ticklabel_string(v), false)) + { + set_zticklabelmode("manual"); + zticklabel.run_listeners(POSTSET); + mark_modified(); + } + else + set_zticklabelmode("manual"); + } +} + void axes::properties::set_units (const octave_value& v) {