comparison libinterp/interpfcn/graphics.cc @ 16840:969233a27bce

maint: Use octave coding conventions for changeset fd5a4b7f59f7. * libinterp/interpfcn/graphics.cc: Add ';' to end of %!test expressions. Use space between function name and '('. Replace homebrew token splitting code with getline call with delimiter option.
author Rik <rik@octave.org>
date Mon, 24 Jun 2013 15:06:36 -0700
parents e528beb2d774
children 2ce1ddead134
comparison
equal deleted inserted replaced
16839:905329f73b4a 16840:969233a27bce
2059 } 2059 }
2060 2060
2061 /* 2061 /*
2062 ## test set ticklabels for compatibility 2062 ## test set ticklabels for compatibility
2063 %!test 2063 %!test
2064 %! set (gcf (), "visible", "off") 2064 %! set (gcf (), "visible", "off");
2065 %! set (gca (), "xticklabel", [0, 0.2, 0.4, 0.6, 0.8, 1]) 2065 %! set (gca (), "xticklabel", [0, 0.2, 0.4, 0.6, 0.8, 1]);
2066 %! xticklabel = get (gca (), "xticklabel"); 2066 %! xticklabel = get (gca (), "xticklabel");
2067 %! assert (class (xticklabel), "char") 2067 %! assert (class (xticklabel), "char");
2068 %! assert (size (xticklabel), [6, 3]) 2068 %! assert (size (xticklabel), [6, 3]);
2069 %!test 2069 %!test
2070 %! set (gcf (), "visible", "off") 2070 %! set (gcf (), "visible", "off");
2071 %! set (gca (), "xticklabel", "0|0.2|0.4|0.6|0.8|1") 2071 %! set (gca (), "xticklabel", "0|0.2|0.4|0.6|0.8|1");
2072 %! xticklabel = get (gca (), "xticklabel"); 2072 %! xticklabel = get (gca (), "xticklabel");
2073 %! assert (class (xticklabel), "char") 2073 %! assert (class (xticklabel), "char");
2074 %! assert (size (xticklabel), [6, 3]) 2074 %! assert (size (xticklabel), [6, 3]);
2075 %!test 2075 %!test
2076 %! set (gcf (), "visible", "off") 2076 %! set (gcf (), "visible", "off");
2077 %! set (gca (), "xticklabel", ["0 "; "0.2"; "0.4"; "0.6"; "0.8"; "1 "]) 2077 %! set (gca (), "xticklabel", ["0 "; "0.2"; "0.4"; "0.6"; "0.8"; "1 "]);
2078 %! xticklabel = get (gca (), "xticklabel"); 2078 %! xticklabel = get (gca (), "xticklabel");
2079 %! assert (class (xticklabel), "char") 2079 %! assert (class (xticklabel), "char");
2080 %! assert (size (xticklabel), [6, 3]) 2080 %! assert (size (xticklabel), [6, 3]);
2081 %!xtest 2081 %!xtest
2082 %! set (gcf (), "visible", "off") 2082 %! set (gcf (), "visible", "off");
2083 %! set (gca (), "xticklabel", {"0", "0.2", "0.4", "0.6", "0.8", "1"}) 2083 %! set (gca (), "xticklabel", {"0", "0.2", "0.4", "0.6", "0.8", "1"});
2084 %! xticklabel = get (gca (), "xticklabel"); 2084 %! xticklabel = get (gca (), "xticklabel");
2085 %! assert (class (xticklabel), "cell") 2085 %! assert (class (xticklabel), "cell");
2086 %! assert (size (xticklabel), [6, 1]) 2086 %! assert (size (xticklabel), [6, 1]);
2087 */ 2087 */
2088 2088
2089 /* 2089 /*
2090 ## test set with struct arguments 2090 ## test set with struct arguments
2091 %!test 2091 %!test
2099 %! assert (get (h, "linewidth"), {10; 10}); 2099 %! assert (get (h, "linewidth"), {10; 10});
2100 ## test ordering 2100 ## test ordering
2101 %!test 2101 %!test
2102 %! markchanged = @(h, foobar, name) set (h, "userdata", [get(h,"userdata"); {name}]); 2102 %! markchanged = @(h, foobar, name) set (h, "userdata", [get(h,"userdata"); {name}]);
2103 %! figure (1, "visible", "off") 2103 %! figure (1, "visible", "off")
2104 %! clf () 2104 %! clf ();
2105 %! h = line (); 2105 %! h = line ();
2106 %! set (h, "userdata", {}) 2106 %! set (h, "userdata", {});
2107 %! addlistener (h, "color", {markchanged, "color"}) 2107 %! addlistener (h, "color", {markchanged, "color"});
2108 %! addlistener (h, "linewidth", {markchanged, "linewidth"}) 2108 %! addlistener (h, "linewidth", {markchanged, "linewidth"});
2109 %! # "linewidth" first 2109 %! # "linewidth" first
2110 %! props.linewidth = 2; 2110 %! props.linewidth = 2;
2111 %! props.color = "r"; 2111 %! props.color = "r";
2112 %! set (h, props); 2112 %! set (h, props);
2113 %! assert (get (h, "userdata"), fieldnames (props)) 2113 %! assert (get (h, "userdata"), fieldnames (props));
2114 %! clear props 2114 %! clear props
2115 %! clf () 2115 %! clf ();
2116 %! h = line (); 2116 %! h = line ();
2117 %! set (h, "userdata", {}) 2117 %! set (h, "userdata", {});
2118 %! addlistener (h, "color", {markchanged, "color"}) 2118 %! addlistener (h, "color", {markchanged, "color"});
2119 %! addlistener (h, "linewidth", {markchanged, "linewidth"}) 2119 %! addlistener (h, "linewidth", {markchanged, "linewidth"});
2120 %! # "color" first 2120 %! # "color" first
2121 %! props.color = "r"; 2121 %! props.color = "r";
2122 %! props.linewidth = 2; 2122 %! props.linewidth = 2;
2123 %! set (h, props); 2123 %! set (h, props);
2124 %! assert (get (h, "userdata"), fieldnames (props)) 2124 %! assert (get (h, "userdata"), fieldnames (props));
2125 %! close (1) 2125 %! close (1);
2126 */ 2126 */
2127 2127
2128 // Set a property to a value or to its (factory) default value. 2128 // Set a property to a value or to its (factory) default value.
2129 2129
2130 void 2130 void
3745 3745
3746 /* 3746 /*
3747 %!test 3747 %!test
3748 %! figure (1, "visible", "off"); 3748 %! figure (1, "visible", "off");
3749 %! set (1, "paperunits", "inches"); 3749 %! set (1, "paperunits", "inches");
3750 %! set (1, "papersize", [5, 4]) 3750 %! set (1, "papersize", [5, 4]);
3751 %! set (1, "paperunits", "points"); 3751 %! set (1, "paperunits", "points");
3752 %! assert (get (1, "papersize"), [5, 4] * 72, 1) 3752 %! assert (get (1, "papersize"), [5, 4] * 72, 1);
3753 %! papersize = get (gcf, "papersize"); 3753 %! papersize = get (gcf, "papersize");
3754 %! set (1, "papersize", papersize + 1); 3754 %! set (1, "papersize", papersize + 1);
3755 %! set (1, "papersize", papersize) 3755 %! set (1, "papersize", papersize);
3756 %! assert (get (1, "papersize"), [5, 4] * 72, 1) 3756 %! assert (get (1, "papersize"), [5, 4] * 72, 1);
3757 %! close (1) 3757 %! close (1);
3758 %!test 3758 %!test
3759 %! figure (1, "visible", "off"); 3759 %! figure (1, "visible", "off");
3760 %! set (1, "paperunits", "inches"); 3760 %! set (1, "paperunits", "inches");
3761 %! set (1, "papersize", [5, 4]) 3761 %! set (1, "papersize", [5, 4]);
3762 %! set (1, "paperunits", "centimeters"); 3762 %! set (1, "paperunits", "centimeters");
3763 %! assert (get (1, "papersize"), [5, 4] * 2.54, 2.54/72) 3763 %! assert (get (1, "papersize"), [5, 4] * 2.54, 2.54/72);
3764 %! papersize = get (gcf, "papersize"); 3764 %! papersize = get (gcf, "papersize");
3765 %! set (1, "papersize", papersize + 1); 3765 %! set (1, "papersize", papersize + 1);
3766 %! set (1, "papersize", papersize) 3766 %! set (1, "papersize", papersize);
3767 %! assert (get (1, "papersize"), [5, 4] * 2.54, 2.54/72) 3767 %! assert (get (1, "papersize"), [5, 4] * 2.54, 2.54/72);
3768 %! close (1) 3768 %! close (1);
3769 */ 3769 */
3770 3770
3771 void 3771 void
3772 figure::properties::update_paperorientation (void) 3772 figure::properties::update_paperorientation (void)
3773 { 3773 {
5089 ## FIXME: A demo can't be called in a C++ file. This should be made a test 5089 ## FIXME: A demo can't be called in a C++ file. This should be made a test
5090 ## or moved to a .m file where it can be called. 5090 ## or moved to a .m file where it can be called.
5091 %!demo 5091 %!demo
5092 %! clf; 5092 %! clf;
5093 %! subplot (2,1,1); 5093 %! subplot (2,1,1);
5094 %! plot (rand (3)); 5094 %! plot (rand (3));
5095 %! xlabel xlabel; 5095 %! xlabel xlabel;
5096 %! ylabel ylabel; 5096 %! ylabel ylabel;
5097 %! title title; 5097 %! title title;
5098 %! subplot (2,1,2); 5098 %! subplot (2,1,2);
5099 %! plot (rand (3)); 5099 %! plot (rand (3));
5100 %! set (gca, "ticklength", get (gca, "ticklength") * 2, "tickdir", "out"); 5100 %! set (gca, "ticklength", get (gca, "ticklength") * 2, "tickdir", "out");
5101 %! xlabel xlabel; 5101 %! xlabel xlabel;
5102 %! ylabel ylabel; 5102 %! ylabel ylabel;
5103 %! title title; 5103 %! title title;
5104 */ 5104 */
5105 5105
5106 static bool updating_xlabel_position = false; 5106 static bool updating_xlabel_position = false;
5107 5107
5108 void 5108 void
5742 5742
5743 return ext; 5743 return ext;
5744 } 5744 }
5745 5745
5746 static octave_value 5746 static octave_value
5747 convert_ticklabel_string(const octave_value& val) 5747 convert_ticklabel_string (const octave_value& val)
5748 { 5748 {
5749 octave_value retval = val; 5749 octave_value retval = val;
5750 5750
5751 if (!val.is_cellstr ()) 5751 if (!val.is_cellstr ())
5752 { 5752 {
5753 string_vector str; 5753 string_vector str;
5754 if (val.is_float_type () || val.is_integer_type ()) 5754 if (val.is_numeric_type ())
5755 { 5755 {
5756 NDArray data = val.array_value (); 5756 NDArray data = val.array_value ();
5757 std::ostringstream s; 5757 std::ostringstream oss;
5758 s.precision (5); 5758 oss.precision (5);
5759 for (octave_idx_type i = 0; i < val.numel (); i++) 5759 for (octave_idx_type i = 0; i < val.numel (); i++)
5760 { 5760 {
5761 s.str(""); 5761 oss.str ("");
5762 s << data(i); 5762 oss << data(i);
5763 str.append (s.str()); 5763 str.append (oss.str ());
5764 } 5764 }
5765 } 5765 }
5766 else if (val.is_string () && val.rows () == 1) 5766 else if (val.is_string () && val.rows () == 1)
5767 { 5767 {
5768 std::string tmpstr(val.string_value ()); 5768 std::istringstream iss (val.string_value ());
5769 char separator = '|'; 5769 std::string tmpstr;
5770 size_t pos = 0; 5770
5771 while (true) 5771 // Split string with delimiter '|'
5772 while (std::getline (iss, tmpstr, '|'))
5772 { 5773 {
5773 size_t new_pos = tmpstr.find_first_of (separator, pos); 5774 str.append (tmpstr);
5774
5775 if (new_pos == std::string::npos)
5776 {
5777 std::string tmp = tmpstr.substr (pos);
5778 str.append(tmp);
5779 break;
5780 }
5781 else
5782 {
5783 std::string tmp = tmpstr.substr (pos, new_pos - pos);
5784 str.append (tmp);
5785 }
5786 pos = new_pos + 1;
5787 } 5775 }
5788 } 5776 }
5789 else 5777 else
5790 return retval; 5778 return retval;
5791 5779
5792 charMatrix ch(str); 5780 charMatrix ch (str);
5793 for (octave_idx_type i = 0; i < ch.numel(); i++) 5781
5782 for (octave_idx_type i = 0; i < ch.numel (); i++)
5794 if (ch(i) == 0) 5783 if (ch(i) == 0)
5795 ch(i) = ' '; 5784 ch(i) = ' ';
5796 retval = octave_value(ch); 5785
5786 retval = octave_value (ch);
5797 5787
5798 } 5788 }
5799 return retval; 5789 return retval;
5800 } 5790 }
5801 5791
5802 void 5792 void
5803 axes::properties::set_xticklabel(const octave_value& v) 5793 axes::properties::set_xticklabel (const octave_value& v)
5804 { 5794 {
5805 if (!error_state) 5795 if (!error_state)
5806 { 5796 {
5807 if (xticklabel.set(convert_ticklabel_string(v), false)) 5797 if (xticklabel.set (convert_ticklabel_string (v), false))
5808 { 5798 {
5809 set_xticklabelmode("manual"); 5799 set_xticklabelmode ("manual");
5810 xticklabel.run_listeners(POSTSET); 5800 xticklabel.run_listeners (POSTSET);
5811 mark_modified(); 5801 mark_modified ();
5812 } 5802 }
5813 else 5803 else
5814 set_xticklabelmode("manual"); 5804 set_xticklabelmode ("manual");
5815 } 5805 }
5816 } 5806 }
5817 5807
5818 void 5808 void
5819 axes::properties::set_yticklabel(const octave_value& v) 5809 axes::properties::set_yticklabel (const octave_value& v)
5820 { 5810 {
5821 if (!error_state) 5811 if (!error_state)
5822 { 5812 {
5823 if (yticklabel.set(convert_ticklabel_string(v), false)) 5813 if (yticklabel.set (convert_ticklabel_string (v), false))
5824 { 5814 {
5825 set_yticklabelmode("manual"); 5815 set_yticklabelmode ("manual");
5826 yticklabel.run_listeners(POSTSET); 5816 yticklabel.run_listeners (POSTSET);
5827 mark_modified(); 5817 mark_modified ();
5828 } 5818 }
5829 else 5819 else
5830 set_yticklabelmode("manual"); 5820 set_yticklabelmode ("manual");
5831 } 5821 }
5832 } 5822 }
5833 5823
5834 void 5824 void
5835 axes::properties::set_zticklabel(const octave_value& v) 5825 axes::properties::set_zticklabel (const octave_value& v)
5836 { 5826 {
5837 if (!error_state) 5827 if (!error_state)
5838 { 5828 {
5839 if (zticklabel.set(convert_ticklabel_string(v), false)) 5829 if (zticklabel.set (convert_ticklabel_string (v), false))
5840 { 5830 {
5841 set_zticklabelmode("manual"); 5831 set_zticklabelmode ("manual");
5842 zticklabel.run_listeners(POSTSET); 5832 zticklabel.run_listeners (POSTSET);
5843 mark_modified(); 5833 mark_modified ();
5844 } 5834 }
5845 else 5835 else
5846 set_zticklabelmode("manual"); 5836 set_zticklabelmode ("manual");
5847 } 5837 }
5848 } 5838 }
5849 5839
5850 void 5840 void
5851 axes::properties::set_units (const octave_value& v) 5841 axes::properties::set_units (const octave_value& v)