# HG changeset patch # User Stefan Mahr # Date 1370956601 -28800 # Node ID fd5a4b7f59f79788aa089e5b98fdcb3965fa00c5 # Parent c9007267cbf50bbb1ec094fbd3ba2212c85b2b34 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 diff --git a/libinterp/interpfcn/graphics.cc b/libinterp/interpfcn/graphics.cc --- 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) { diff --git a/libinterp/interpfcn/graphics.in.h b/libinterp/interpfcn/graphics.in.h --- a/libinterp/interpfcn/graphics.in.h +++ b/libinterp/interpfcn/graphics.in.h @@ -3777,9 +3777,9 @@ bool_property yminortick , "off" bool_property zminortick , "off" // FIXME -- should be kind of string array. - any_property xticklabel m , "" - any_property yticklabel m , "" - any_property zticklabel m , "" + any_property xticklabel S , "" + any_property yticklabel S , "" + any_property zticklabel S , "" radio_property xticklabelmode u , "{auto}|manual" radio_property yticklabelmode u , "{auto}|manual" radio_property zticklabelmode u , "{auto}|manual"