Mercurial > octave-nkf
comparison scripts/plot/legend.m @ 12390:7428d177f00a release-3-4-x
Fix for inline legends (#32022, #32343)
author | David Bateman <dbateman@free.fr> |
---|---|
date | Sat, 05 Feb 2011 10:19:13 -0500 |
parents | c792872f8942 |
children | d63007ac067a |
comparison
equal
deleted
inserted
replaced
12386:c1ea9b90a272 | 12390:7428d177f00a |
---|---|
773 | 773 |
774 function updatelegend (h, d) | 774 function updatelegend (h, d) |
775 persistent recursive = false; | 775 persistent recursive = false; |
776 if (! recursive) | 776 if (! recursive) |
777 recursive = true; | 777 recursive = true; |
778 hax = getfield (get (h, "userdata"), "handle"); | 778 unwind_protect |
779 [hplots, text_strings] = getlegenddata (h); | 779 hax = getfield (get (h, "userdata"), "handle"); |
780 h = legend (hax, flipud (hplots), get (h, "string")); | 780 [hplots, text_strings] = __getlegenddata__ (h); |
781 recursive = false; | 781 h = legend (hax, hplots, get (h, "string")); |
782 unwind_protect_cleanup | |
783 recursive = false; | |
784 end_unwind_protect | |
782 endif | 785 endif |
783 endfunction | 786 endfunction |
784 | 787 |
785 function updatelegendtext (h, d) | 788 function updatelegendtext (h, d) |
786 kids = get (h, "children"); | 789 kids = get (h, "children"); |
893 if ((isempty (displayname) | 896 if ((isempty (displayname) |
894 || (strcmp (marker, "none") && strcmp (linestyle, "none"))) | 897 || (strcmp (marker, "none") && strcmp (linestyle, "none"))) |
895 && (! isempty (lm) || isempty (ll))) | 898 && (! isempty (lm) || isempty (ll))) |
896 ## An element was removed from the legend. Need to recall the | 899 ## An element was removed from the legend. Need to recall the |
897 ## legend function to recreate a new legend | 900 ## legend function to recreate a new legend |
898 [hplots, text_strings] = getlegenddata (hlegend); | 901 [hplots, text_strings] = __getlegenddata__ (hlegend); |
899 for i = 1 : numel (hplots) | 902 for i = 1 : numel (hplots) |
900 if (hplots (i) == h) | 903 if (hplots (i) == h) |
901 hplots(i) = []; | 904 hplots(i) = []; |
902 text_strings(i) = []; | 905 text_strings(i) = []; |
903 break; | 906 break; |
907 elseif ((!isempty (displayname) | 910 elseif ((!isempty (displayname) |
908 && (! strcmp (marker, "none") || ! strcmp (linestyle, "none"))) | 911 && (! strcmp (marker, "none") || ! strcmp (linestyle, "none"))) |
909 && isempty (lm) && isempty (ll)) | 912 && isempty (lm) && isempty (ll)) |
910 ## An element was added to the legend. Need to recall the | 913 ## An element was added to the legend. Need to recall the |
911 ## legend function to recreate a new legend | 914 ## legend function to recreate a new legend |
912 [hplots, text_strings] = getlegenddata (hlegend); | 915 [hplots, text_strings] = __getlegenddata__ (hlegend); |
913 hplots = [hplots, h]; | 916 hplots = [hplots, h]; |
914 text_strings = {text_strings{:}, displayname}; | 917 text_strings = {text_strings{:}, displayname}; |
915 legend (hplots, text_strings); | 918 legend (hplots, text_strings); |
916 else | 919 else |
917 if (! isempty (ll)) | 920 if (! isempty (ll)) |
943 "userdata", h, "parent", hlegend); | 946 "userdata", h, "parent", hlegend); |
944 endif | 947 endif |
945 endif | 948 endif |
946 endfunction | 949 endfunction |
947 | 950 |
948 function [hplots, text_strings] = getlegenddata (hlegend) | |
949 hplots = []; | |
950 text_strings = {}; | |
951 ca = getfield (get (hlegend, "userdata"), "handle"); | |
952 kids = []; | |
953 for i = 1 : numel (ca) | |
954 kids = [kids; get(ca (i), "children")]; | |
955 endfor | |
956 k = numel (kids); | |
957 while (k > 0) | |
958 typ = get (kids(k), "type"); | |
959 while (k > 0 | |
960 && ! (strcmp (typ, "line") || strcmp (typ, "surface") | |
961 || strcmp (typ, "patch") || strcmp (typ, "hggroup"))) | |
962 typ = get (kids(--k), "type"); | |
963 endwhile | |
964 if (k > 0) | |
965 if (strcmp (get (kids(k), "type"), "hggroup")) | |
966 hgkids = get (kids(k), "children"); | |
967 for j = 1 : length (hgkids) | |
968 hgobj = get (hgkids (j)); | |
969 if (isfield (hgobj, "displayname") | |
970 && ! isempty (hgobj.displayname)) | |
971 hplots = [hplots, hgkids(j)]; | |
972 text_strings = {text_strings{:}, hbobj.displayname}; | |
973 break; | |
974 endif | |
975 endfor | |
976 else | |
977 if (! isempty (get (kids (k), "displayname"))) | |
978 hplots = [hplots, kids(k)]; | |
979 text_strings = {text_strings{:}, get(kids (k), "displayname")}; | |
980 endif | |
981 endif | |
982 if (--k == 0) | |
983 break; | |
984 endif | |
985 endif | |
986 endwhile | |
987 endfunction | |
988 | |
989 %!demo | 951 %!demo |
990 %! clf | 952 %! clf |
991 %! x = 0:1; | 953 %! x = 0:1; |
992 %! plot (x, x, ";I am Blue;", x, 2*x, ";I am Green;", x, 3*x, ";I am Red;") | 954 %! plot (x, x, ";I am Blue;", x, 2*x, ";I am Green;", x, 3*x, ";I am Red;") |
993 | 955 |