[Therion] ***UNCHECKED*** Changing the legend icon for existing points/lines
Tarquin Wilton-Jones
tarquin.wilton-jones at ntlworld.com
Fri Nov 29 21:28:48 CET 2019
> This doesn't seem to work. Neither does "p_anchor_legend". Am I missing
> something; is there a way to do it?
Again, I am going to answer my own question. Bruce, listen up, since I
think you also ran into this problem on
https://therion.speleo.sk/wiki/metapost (search for "not working"). It
is a case of Therion not being as helpful as you might like. It would be
great if it actually respected _legend macros for all points, lines and
areas. It doesn't. Maybe someone can fix that? Pretty please?
Anyway...
With p_u_* and l_u_* and a_u_*, Therion creates a default p_u_*_legend
macro, which you can choose to override with your own. When drawing the
legend, it runs those macros.
beginfig(164);
clean_legend_box;
p_u_foo_legend;
draw_legend_box;
endfig;
With anything else, it does not work that way. Instead, the MetaPost
contains hardcoded calls to the macros, with hardcoded points or paths
defined inline, not via macros and variables. These points and paths can
be seen in the binary source as being tied to the specific symbols (most
symbols use the same few default values, but a few have their own
special ones). It ends up looking like this:
beginfig(161);
clean_legend_box;
drawoptions();
p_anchor((0.5,0.5) inscale,0.0,1.0,(0,0));
draw_legend_box;
endfig;
You can detect this default coordinate in your point/line symbol code,
and respond differently. But it is entirely possible for a legitimate
point in your survey to match "(0.5,0.5) inscale", and you will end up
randomly converting a real point into a special legend version. Not good.
There is no other way to ask "is this code running inside the legend"
since there is no variable that says that the legend has started.
But! You can rewrite the clean_legend_box macro to store a flag, which
you can check in your point code to see if it is running inside one of
those legend sections. Legends are always created as the last step, so
even though that flag will get left forever, it will not be mistaken in
non-legend code.
boolean p_anchor_MY_inlegend;
p_anchor_MY_inlegend:=false;
% store the original clean_legend_box
let p_anchor_MY_legend_box = clean_legend_box;
% redefine clean_legend_box to store the flag, then run the original
def clean_legend_box =
p_anchor_MY_inlegend:=true;
p_anchor_MY_legend_box;
enddef;
def p_anchor_MY (expr P,R,S,A)=
if p_anchor_MY_inlegend:
% this is the legend - make sure the function works normally again
p_anchor_MY_inlegend:=false;
% draw a pretty legend
p_anchor_MY((.7,.3) inscale,270,1,(0,0));
else:
% ... do the regular stuff
fi;
enddef;
Hopefully someone else will find this useful, and with any luck, I will
add it to the wiki soon. Along with all the other stuff I need to add to
the wiki.
More information about the Therion
mailing list