octave-task-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-task-tracker] [task #14243] Rewrite legend.m


From: Pantxo Diribarne
Subject: [Octave-task-tracker] [task #14243] Rewrite legend.m
Date: Wed, 23 Nov 2016 11:03:45 +0000 (UTC)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0

Follow-up Comment #3, task #14243 (project octave):

Here are a few other tests inspired by the current demos



%% Test the current demos work
%% demo 1: currently fails because text object are deleted/recreated
hf = figure ('visible', 'off');
plot (rand (2));
[hl, hicon] = legend ({"foo"}, "bar");
legend (hl, "location", "northeastoutside");
set (hl, "fontsize", 20);
ht = hicon(strcmp (get (hicon, "type"), "text"));
assert (get (hl, "string"), {"foo", "bar"});
assert (get (ht, "string"), {"foo"; "bar"});
assert (get (ht, "fontsize"), [20; 20])
assert (get (hl, "location"), "northeastoutside")
close (hf);

%% demo 2: 
hf = figure ('visible', 'off');
plot (rand (3));
hl = legend ("show");
assert (get (hl, "string"), {"data1", "data2", "data3"})
close (hf);

%% demo 3: fails because legend without arguments doesn't return hicon 
hf = figure ('visible', 'off');
x = 0:1;
hlines = plot (x,x,";I am Blue;", x,2*x, x,3*x,";I am yellow;");
[hl, hicon] = legend ();
hleglines = hicon(strcmp (get (hicon, "type"), "line"));
assert (get (hlines(3:-2:1), "color"), get (hleglines, "color")); 
close (hf);

%% demo 4:
hf = figure ('visible', 'off');
plot (1:10, 1:10, 1:10, fliplr (1:10));
hl = legend ({"I am blue", "I am orange"}, "location", "east");
legend ("hide")
assert (get (hl, "visible"), "off")
hl2 = legend ("show");
assert (get (hl2, "visible"), "on")
assert (hl, hl2)
close (hf);

%% demo 5:
hf = figure ('visible', 'off');
plot (1:10, 1:10, 1:10, fliplr (1:10));
[hl, hicon] = legend ({"I am blue", "I am orange"}, ...
                      "location", "east", "orientation", "horizontal");
ht = hicon(strcmp (get (hicon, "type"), "text"));
assert (get (ht(1), "position")(1) < get (ht(2), "position")(1))
legend boxoff
assert (get (hl, "box"), "off")
legend boxon
assert (get (hl, "box"), "on")
close (hf);

%% demo 7:
hf = figure ('visible', 'off');
plot (1:10, 1:10, 1:10, fliplr (1:10));
legend ({"I am blue", "I am orange"}, "location", "east");
[hl, hicon] = legend ("left");
ht = hicon(strcmp (get (hicon, "type"), "text"));
hlines = hicon(strcmp (get (hicon, "type"), "line"));
assert (get (ht(1), "position")(1) < get (hlines(1), "xdata")(1))
assert (get (ht(2), "position")(2) < get (hlines(2), "xdata")(2))
close (hf);

%% demo 8
hf = figure ('visible', 'off');
plot (1:10, 1:10, 1:10, fliplr (1:10));
[hl hicon] = legend ({"I am blue", "I am orange"}, "location", "east");
ht = hicon(strcmp (get (hicon, "type"), "text"));
set (hl, "textcolor", [1 0 1]);
assert (get (ht, "color"), {[1 0 1]; [1 0 1]});
close (hf);

%% demo 14
hf = figure ('visible', 'off');
hlines = plot (rand (2));
[hl hicon] = legend ("foo");
ht = hicon(strcmp (get (hicon, "type"), "text"));
hlegline = hicon(strcmp (get (hicon, "type"), "line"));
assert (get (ht, "string"), get (hlines(1), "displayname"))
assert (get (hlegline, "color"), get (hlines(1), "color"))
close (hf);

%% demo 17
hf = figure ('visible', 'off');
subplot (2,1,1);
rand_2x3_data1 = [0.341447, 0.171220, 0.284370; 0.039773, 0.731725,
0.779382];
hbars = bar (rand_2x3_data1);
[hl hicon] = legend ({"1st Bar", "2nd Bar", "3rd Bar"}, ...
                     "location", "northwest");
hicon = hicon(! strcmp (get (hicon, "type"), "text"));
assert (get (hicon, "type"), {"patch"; "patch"; "patch"}) 
assert (get (hicon, "facecolor"), get (hbars, "facecolor")) 
subplot (2,1,2);
x = linspace (0, 10, 20);
hstem(1) = stem (x, 0.5+x.*rand (size (x))/max (x), ...
                 "markeredgecolor", [0 0.7 0]);
hold on;
hstem(2) = stem (x+10/(2*20), x.*(1.0+rand (size (x)))/max (x));
[hl hicon] = legend ({"Multicolor", "Unicolor"}, "location", "northwest");
hicon = hicon(! strcmp (get (hicon, "type"), "text"));
assert (get (hicon, "type"), {"line"; "line"}) 
assert (get (hicon, "color"), get (hstem, "markeredgecolor")) 
close (hf);

%% demo 18
hf = figure ('visible', 'off');
surf (peaks ());
[hl hicon] = legend ("peaks()");
hicon = hicon(! strcmp (get (hicon, "type"), "text"));
assert (get (hicon, "type"), "patch") 
close (hf);

%% demo 21/22/23
hf = figure ('visible', 'off');
x = 0:0.1:10;
plot (x, sin (x), ";sin (x);");
hold on;
plot (x, cos (x), ";cos (x);");
[hl hicon] = legend ();
assert (get (hl, "string"), {"sin (x)", "cos (x)"});
hl = legend ({"Sine", "Cosine"}, "location", "northeastoutside");
assert (get (hl, "string"), {"Sine", "Cosine"});
close (hf);

%% demo 24
hf = figure ('visible', 'off');
plot (1:10);
hl = legend ("foo");
legend off
assert (! ishandle (hl))
close (hf);

%% demo 25
hf = figure ('visible', 'off');
plot (rand (2));
legend ("Hello", "World", "interpreter", "foobar");
assert (lastwarn (), "legend: ignoring extra labels")
close (hf);

%% demo 26/27/28
hf = figure ('visible', 'off');
x = 0:10;
y1 = rand (size (x));
y2 = rand (size (x));
[hax, h1, h2] = plotyy (x, y1, x, y2);
hl = legend ("Blue", "Orange");
assert (get (hl, "string"), {"Blue", "Orange"})
hl = legend ({"Blue", "Orange"});
assert (get (hl, "string"), {"Blue", "Orange"})
hl = legend ([h1, h2], {"Blue", "Orange"});
assert (get (hl, "string"), {"Blue", "Orange"})
close (hf);


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/task/?14243>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]