# HG changeset patch # User Rik # Date 1471220346 25200 # Node ID 378f8c0de848c5acf66ffd74479218b71d3bad21 # Parent 5e27d8d4e3c1a4a9b99fb859f33a1c952b4623ad Implement TitleFontSizeMultiplier, LabelFontSizeMultiplier, TitleFontWeight props. * title.m: Don't call __axis_label__. Set properties of title text object directly from title.m. Set FontSize equal to TitleFontSizeMultiplier * AxesFontSize. Set FontWeight equal to TitleFontWeight. * xlabel.m, ylabel.m, zlabel.m: Expand BIST tests to check LabelFontSizeMultiplier. * __axis_label__.m: Set FontSize equal to TitleFontSizeMultiplier * AxesFontSize. Add listener on [xyz]color property of axes to change label color when property is changed. diff -r 5e27d8d4e3c1 -r 378f8c0de848 scripts/plot/appearance/private/__axis_label__.m --- a/scripts/plot/appearance/private/__axis_label__.m Sun Aug 14 17:31:59 2016 +0100 +++ b/scripts/plot/appearance/private/__axis_label__.m Sun Aug 14 17:19:06 2016 -0700 @@ -30,14 +30,26 @@ set (h, "fontangle", get (hax, "fontangle"), "fontname", get (hax, "fontname"), "fontunits", get (hax, "fontunits"), # must precede fontsize - "fontsize", get (hax, "fontsize"), + "fontsize", get (hax, "LabelFontSizeMultiplier") * + get (hax, "fontsize"), "fontweight", get (hax, "fontweight"), "string", txt, varargin{:}); + ## FIXME: It would be better to delete only the listener that [xyz]label + ## installed. But this didn't work, so instead it deletes all + ## listener's on the [xyz]color property. + dellistener (hax, [caller(1) "color"]); + addlistener (hax, [caller(1) "color"], {@cb_color, h, caller(1)}); + if (nargout > 0) retval = h; endif endfunction +## Callback to update label color when axes color is changed +function cb_color (hax, ~, hlabel, axis2label) + set (hlabel, "color", get (hax, [axis2label "color"])); +endfunction + diff -r 5e27d8d4e3c1 -r 378f8c0de848 scripts/plot/appearance/title.m --- a/scripts/plot/appearance/title.m Sun Aug 14 17:31:59 2016 +0100 +++ b/scripts/plot/appearance/title.m Sun Aug 14 17:19:06 2016 -0700 @@ -48,7 +48,16 @@ print_usage (); endif - htmp = __axis_label__ (hax, "title", varargin{:}); + htmp = get (hax, "title"); + + set (htmp, "fontangle", get (hax, "fontangle"), + "fontname", get (hax, "fontname"), + "fontunits", get (hax, "fontunits"), # must precede fontsize + "fontsize", get (hax, "TitleFontSizeMultiplier") * + get (hax, "fontsize"), + "fontweight", get (hax, "titlefontweight"), + "string", varargin{1}, + varargin{2:end}); if (nargout > 0) h = htmp; @@ -59,28 +68,22 @@ %!demo %! clf; -%! ax = axes (); -%! h = get (ax, 'title'); -%! title ('Test Title Text'); +%! title ("Test Title Text"); %!demo %! clf; -%! ax = axes (); -%! h = get (ax, 'title'); -%! title ({'Multi-line'; 'Title'; 'Text'}); +%! title ({"Multi-line"; "Title"; "Text"}); %!demo %! clf; %! plot3 ([0,1], [0,1], [0,1]); -%! h = get (gca, 'title'); -%! title ('Test FontSize Property', 'fontsize', 16); +%! title ("Test FontSize Property", "fontsize", 16); %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! ax = axes (); -%! h = get (ax, "title"); %! title ("Test Title Text"); +%! h = get (gca, "title"); %! assert (get (h, "string"), "Test Title Text"); %! unwind_protect_cleanup %! close (hf); @@ -89,10 +92,20 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! ax = axes (); -%! h = get (ax, "title"); -%! title ({'Multi-line'; 'Title'; 'Text'}); -%! assert (get (h, "string"), {'Multi-line'; 'Title'; 'Text'}); +%! title ({"Multi-line"; "Title"; "Text"}); +%! h = get (gca, "title"); +%! assert (get (h, "string"), {"Multi-line"; "Title"; "Text"}); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! set (gca, "fontsize", 5, "titlefontsizemultiplier", 3); +%! ht = title ("title_string", "color", "r"); +%! assert (get (ht, "fontsize"), 15); +%! assert (get (ht, "color"), [1 0 0]); %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect @@ -101,11 +114,10 @@ %! hf = figure ("visible", "off"); %! unwind_protect %! plot3 ([0,1], [0,1], [0,1]); +%! title ("Test FontSize Property", "fontsize", 16); %! h = get (gca, "title"); -%! title ("Test FontSize Property", "fontsize", 16); %! assert (get (h, "string"), "Test FontSize Property"); %! assert (get (h, "fontsize"), 16); - %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect diff -r 5e27d8d4e3c1 -r 378f8c0de848 scripts/plot/appearance/xlabel.m --- a/scripts/plot/appearance/xlabel.m Sun Aug 14 17:31:59 2016 +0100 +++ b/scripts/plot/appearance/xlabel.m Sun Aug 14 17:19:06 2016 -0700 @@ -49,7 +49,8 @@ endif htmp = __axis_label__ (hax, "xlabel", varargin{1}, - "color", get (hax, "xcolor"), varargin{2:end}); + "color", get (hax, "xcolor"), + varargin{2:end}); if (nargout > 0) h = htmp; @@ -61,13 +62,24 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! x = xlabel ("xlabel_string", "color", "r"); -%! assert (get (gca, "xlabel"), x); -%! assert (get (x, "type"), "text"); -%! assert (get (x, "visible"), "on"); -%! assert (get (x, "string"), "xlabel_string"); -%! assert (get (x, "color"), [1 0 0]); +%! hx = xlabel ("xlabel_string"); +%! assert (get (gca, "xlabel"), hx); +%! assert (get (hx, "type"), "text"); +%! assert (get (hx, "visible"), "on"); +%! assert (get (hx, "string"), "xlabel_string"); +%! assert (get (hx, "color"), get (0, "defaultaxesxcolor")); %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! set (gca, "fontsize", 5, "labelfontsizemultiplier", 3); +%! hx = xlabel ("xlabel_string", "color", "r"); +%! assert (get (hx, "fontsize"), 15); +%! assert (get (hx, "color"), [1 0 0]); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + diff -r 5e27d8d4e3c1 -r 378f8c0de848 scripts/plot/appearance/ylabel.m --- a/scripts/plot/appearance/ylabel.m Sun Aug 14 17:31:59 2016 +0100 +++ b/scripts/plot/appearance/ylabel.m Sun Aug 14 17:19:06 2016 -0700 @@ -51,7 +51,8 @@ endif htmp = __axis_label__ (hax, "ylabel", varargin{1}, - "color", get (hax, "ycolor"), varargin{2:end}); + "color", get (hax, "ycolor"), + varargin{2:end}); if (nargout > 0) h = htmp; @@ -63,13 +64,24 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! y = ylabel ("ylabel_string", "color", "r"); -%! assert (get (gca, "ylabel"), y); -%! assert (get (y, "type"), "text"); -%! assert (get (y, "visible"), "on"); -%! assert (get (y, "string"), "ylabel_string"); -%! assert (get (y, "color"), [1 0 0]); +%! hy = ylabel ("ylabel_string"); +%! assert (get (gca, "ylabel"), hy); +%! assert (get (hy, "type"), "text"); +%! assert (get (hy, "visible"), "on"); +%! assert (get (hy, "string"), "ylabel_string"); +%! assert (get (hy, "color"), get (0, "defaultaxesycolor")); %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect +%!test +%! hf = figure ("visible", "off"); +%! unwind_protect +%! set (gca, "fontsize", 5, "labelfontsizemultiplier", 3); +%! hy = ylabel ("ylabel_string", "color", "r"); +%! assert (get (hy, "fontsize"), 15); +%! assert (get (hy, "color"), [1 0 0]); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect + diff -r 5e27d8d4e3c1 -r 378f8c0de848 scripts/plot/appearance/zlabel.m --- a/scripts/plot/appearance/zlabel.m Sun Aug 14 17:31:59 2016 +0100 +++ b/scripts/plot/appearance/zlabel.m Sun Aug 14 17:19:06 2016 -0700 @@ -48,7 +48,8 @@ endif htmp = __axis_label__ (hax, "zlabel", varargin{1}, - "color", get (hax, "zcolor"), varargin{2:end}); + "color", get (hax, "zcolor"), + varargin{2:end}); if (nargout > 0) h = htmp; @@ -60,24 +61,24 @@ %!test %! hf = figure ("visible", "off"); %! unwind_protect -%! z = zlabel ("zlabel_string", "color", "r"); -%! assert (get (gca, "zlabel"), z); -%! assert (get (z, "type"), "text"); -%! assert (get (z, "visible"), "off"); -%! assert (get (z, "string"), "zlabel_string"); -%! assert (get (z, "color"), [1 0 0]); +%! view (3); +%! hz = zlabel ("zlabel_string"); +%! assert (get (gca, "zlabel"), hz); +%! assert (get (hz, "type"), "text"); +%! assert (get (hz, "visible"), "off"); +%! assert (get (hz, "string"), "zlabel_string"); +%! assert (get (hz, "color"), get (0, "defaultaxeszcolor")); %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect %!test %! hf = figure ("visible", "off"); -%! plot3 (0, 0, 0); %! unwind_protect -%! z = zlabel ("zlabel_string"); -%! assert (get (gca, "zlabel"), z); -%! assert (get (z, "type"), "text"); -%! assert (get (z, "string"), "zlabel_string"); +%! set (gca, "fontsize", 5, "labelfontsizemultiplier", 3); +%! hz = zlabel ("zlabel_string", "color", "r"); +%! assert (get (hz, "fontsize"), 15); +%! assert (get (hz, "color"), [1 0 0]); %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect