summaryrefslogtreecommitdiff
path: root/metapost/context
diff options
context:
space:
mode:
Diffstat (limited to 'metapost/context')
-rw-r--r--metapost/context/base/mpiv/mp-lmtx.mpxl125
-rw-r--r--metapost/context/base/mpiv/mp-luas.mpxl4
-rw-r--r--metapost/context/base/mpiv/mp-mlib.mpiv2
3 files changed, 85 insertions, 46 deletions
diff --git a/metapost/context/base/mpiv/mp-lmtx.mpxl b/metapost/context/base/mpiv/mp-lmtx.mpxl
index deeba988f..fe511b74f 100644
--- a/metapost/context/base/mpiv/mp-lmtx.mpxl
+++ b/metapost/context/base/mpiv/mp-lmtx.mpxl
@@ -532,7 +532,8 @@ enddef ;
% )
% enddef ;
-% more
+% Here we use nodraw and dodraw to create efficient axis ticks. Yet another demo
+% of coding.
presetparameters "function" [
sx = 1mm,
@@ -541,16 +542,20 @@ presetparameters "function" [
xmin = 1,
xmax = 1,
xstep = 1,
- xsmall = 1,
- xlarge = 1,
+ xsmall = 0,
+ xlarge = 0,
xlabels = "no",
xticks = "bottom", % top bottom middle
xcaption = "",
ymin = 1,
ymax = 1,
ystep = 1,
- ysmall = 1,
- ylarge = 1,
+ ysmall = 0,
+ ylarge = 0,
+ % xfirst = 0,
+ % xlast = 0,
+ % yfirst = 0,
+ % ylast = 0,
ylabels = "no",
yticks = "left", % left right middle
ycaption = "",
@@ -567,6 +572,7 @@ presetparameters "function" [
pointcolor = "",
xarrow = "",
yarrow = "",
+ reverse = false,
] ;
def lmt_function = applyparameters "function" "lmt_do_function" enddef ;
@@ -605,10 +611,11 @@ vardef lmt_do_function =
tt := identity xyscaled(ts/sx,ts/sy) ;
pickup pencircle xyscaled(lw/sx,lw/sy) ;
draw image (
- save xmin, xmax, xstep, xsmall, xlarge, ymin, ymax, ystep, ysmall, ylarge ;
- save code, option, txl, txs, tyl, tys ;
+ save xmin, xmax, xstep, xsmall, xlarge, ymin, ymax, ystep, ysmall, ylarge, p ;
+ save code, option, txl, txs, tyl, tys, swap ;
string code, option ;
- path txl, txs, tyl, tys ;
+ path txl, txs, tyl, tys ; boolean swap ;
+ picture p ;
xmin := getparameter "xmin" ;
xmax := getparameter "xmax" ;
@@ -621,6 +628,9 @@ vardef lmt_do_function =
ysmall := getparameter "ysmall" ;
ylarge := getparameter "ylarge" ;
code := getparameter "code" ;
+ swap := getparameter "reverse" ;
+
+ if swap : p := image ( fi
if (getparametercount "functions") > 0 :
for s = 1 upto getparametercount "functions" :
@@ -658,6 +668,8 @@ vardef lmt_do_function =
) ;
fi ;
+ if swap : ) ; fi
+
option := getparameter "xticks" ;
if option = "top" :
txs := (0,0) -- (0,tl) ;
@@ -683,6 +695,11 @@ vardef lmt_do_function =
% this arrow head scaling is for Alan to sort out ...
+ xmin := getparameterdefault "xfirst" xmin ;
+ xmax := getparameterdefault "xlast" xmax ;
+ ymin := getparameterdefault "yfirst" ymin ;
+ ymax := getparameterdefault "ylast" ymax ;
+
option := getparameter "xarrow" ;
if option = "yes" :
save ahlength ; ahlength := tl ;
@@ -696,9 +713,9 @@ vardef lmt_do_function =
if option = "yes" :
save ahlength ; ahlength := tl ;
% save ahangle ; ahangle := 100/sx ;
- drawarrow (0,ymin) -- (0,ymax) ;
+ drawarrow (xmin,ymin) -- (xmin,ymax) ;
else :
- draw (0,ymin) -- (0,ymax) ;
+ draw (xmin,ymin) -- (xmin,ymax) ;
fi ;
option := getparameter "frame" ;
@@ -706,81 +723,101 @@ vardef lmt_do_function =
draw (xmin,ymin) -- (xmax,ymin) -- (xmax,ymax) -- (xmin,ymax) -- cycle ;
elseif (option = "ticks") or (option = "sticks") :
draw (xmin,ymin) -- (xmax,ymin) -- (xmax,ymax) -- (xmin,ymax) -- cycle ;
- if xsmall > 1 :
+ if xsmall > 0 :
txs := ((0,0) -- (0,tl)) if option = "sticks" : rotated 180 fi ;
txs := txs transformed tr ;
for i = xmin step ((xmax-xmin)/xsmall) until xmax :
- draw txs shifted (i,ymin);
+ nodraw txs shifted (i,ymin) ;
endfor ;
txs := (0,0) -- (0,-tl) if option = "sticks" : rotated 180 fi ;
txs := txs transformed tr ;
for i = xmin step ((xmax-xmin)/xsmall) until xmax :
- draw txs shifted (i,ymax);
+ nodraw txs shifted (i,ymax) ;
endfor ;
+ dodraw (xmin,ymin) ; % flush snippets
fi ;
- if ysmall > 1 :
+ if ysmall > 0 :
tys := (0,0) -- (tl,0) if option = "sticks" : rotated 180 fi ;
tys := tys transformed tr ;
- for i = ymin step ((ymax-ymin)/ysmall) until ymax :
- draw tys shifted (xmin,i);
+ for i = ymin step ysmall until ymax :
+ nodraw tys shifted (xmin,i) ;
endfor ;
tys := (0,0) -- (-tl,0) if option = "sticks" : rotated 180 fi ;
tys := tys transformed tr ;
- for i = ymin step ((ymax-ymin)/ysmall) until ymax :
- draw tys shifted (xmax,i);
+ for i = ymin step ysmall until ymax :
+ nodraw tys shifted (xmax,i) ;
endfor ;
+ dodraw (xmin,ymin) ; % flush snippets
fi ;
fi ;
- if xsmall > 1 :
- for i = xmin step ((xmax-xmin)/xsmall) until xmax :
- draw txs shifted (i,0) ;
+ if xsmall > 0 :
+ for i = xmin step xsmall until xmax :
+ nodraw txs shifted (i,0) ;
endfor ;
fi ;
- if xlarge > 1 :
- option := getparameter "xlabels" ;
- for i = xmin step ((xmax-xmin)/xlarge) until xmax :
- draw txl shifted (i,0) ;
- if (option <> "no") and (i <> 0) :
- if (option <> "nolimits") or ((i > xmin) and (i < xmax)) :
- draw textext.bot(decimal i) transformed tt
- shifted (i,1.25*(ypart point 0 of txl)) ;
- fi ;
- fi ;
+ if xlarge > 0 :
+ for i = xmin step xlarge until xmax :
+ nodraw txl shifted (i,0) ;
+ endfor ;
+ dodraw (xmin,0) ; % flush snippets
+ elseif xsmall > 0 :
+ dodraw (xmin,0) ; % flush snippets
+ fi ;
+
+ if ysmall > 0 :
+ for i = ymin step ysmall until ymax :
+ nodraw tys shifted (xmin,i) ;
endfor ;
fi ;
- if ysmall > 1 :
- for i = ymin step ((ymax-ymin)/ysmall) until ymax :
- draw tys shifted (0,i) ;
+ if ylarge > 0 :
+ for i = ymin step ylarge until ymax :
+ nodraw tyl shifted (xmin,i) ;
endfor ;
+ dodraw (xmin,ymin) ; % flush snippets
+ elseif ysmall > 0 :
+ dodraw (xmin,ymin) ; % flush snippets
+ fi ;
+
+ if swap : draw p fi ;
+
+ if xlarge > 0 :
+ option := getparameter "xlabels" ;
+ if option <> "no" :
+ for i = xmin step xlarge until xmax :
+ if ((i <> 0) and ((option <> "nolimits") or ((i > xmin) and (i < xmax)))) :
+ draw textext.bot(decimal i) transformed tt
+ shifted (i,1.25*(ypart point 0 of txl)) ;
+ fi ;
+ endfor ;
+ fi ;
fi ;
- if ylarge > 1 :
+ if ylarge > 0 :
option := getparameter "ylabels" ;
- for i = ymin step ((ymax-ymin)/ylarge) until ymax :
- draw tyl shifted (0,i) ;
- if (option <> "no") and (i <> 0) :
- if (option <> "nolimits") or ((i > ymin) and (i < ymax)) :
+ if option <> "no" :
+ for i = ymin step ylarge until ymax :
+ if ((i <> 0) and ((option <> "nolimits") or ((i > ymin) and (i < ymax)))) :
draw textext.lft(decimal i) transformed tt
- shifted (1.25*(xpart point 0 of tyl),i) ;
+ shifted (xmin+1.25*(xpart point 0 of tyl),i) ;
fi ;
- fi ;
- endfor ;
+ endfor ;
+ fi ;
fi ;
option := getparameter "xcaption" ;
if (option <> "") :
draw textext.bot(option) transformed tt
- shifted (0,-tl)
+ shifted (xmin,-tl)
shifted center bottomboundary currentpicture ;
fi ;
option := getparameter "ycaption" ;
if (option <> "") :
draw textext.lft(option) transformed tt
- shifted (-tl,0)
+ shifted (xmin-tl,0)
shifted center leftboundary currentpicture ;
fi ;
)
diff --git a/metapost/context/base/mpiv/mp-luas.mpxl b/metapost/context/base/mpiv/mp-luas.mpxl
index a4c921b72..cd6733f84 100644
--- a/metapost/context/base/mpiv/mp-luas.mpxl
+++ b/metapost/context/base/mpiv/mp-luas.mpxl
@@ -210,7 +210,7 @@ newinternal mfid_getparametercount ; mfid_getparametercount := scriptindex
newinternal mfid_getmaxparametercount ; mfid_getmaxparametercount := scriptindex "getmaxparametercount" ;
newinternal mfid_getparameterpath ; mfid_getparameterpath := scriptindex "getparameterpath" ;
newinternal mfid_getparametertext ; mfid_getparametertext := scriptindex "getparametertext" ;
-newinternal mfid_getparameteroption ; mfid_getparameteroption := scriptindex "getparameteroption" ;
+%%%%%%%%%%% mfid_getparameteroption ; mfid_getparameteroption := scriptindex "getparameteroption" ;
newinternal mfid_applyparameters ; mfid_applyparameters := scriptindex "applyparameters" ;
newinternal mfid_pushparameters ; mfid_pushparameters := scriptindex "pushparameters" ;
newinternal mfid_popparameters ; mfid_popparameters := scriptindex "popparameters" ;
@@ -225,7 +225,7 @@ def getparametercount = runscript mfid_getparametercount enddef ;
def getmaxparametercount = runscript mfid_getmaxparametercount enddef ;
def getparameterpath = runscript mfid_getparameterpath enddef ;
def getparametertext = runscript mfid_getparametertext enddef ;
-def getparameteroption = runscript mfid_getparameteroption enddef ;
+%%% getparameteroption = runscript mfid_getparameteroption enddef ;
def applyparameters = runscript mfid_applyparameters enddef ;
def pushparameters = runscript mfid_pushparameters enddef ;
def popparameters = runscript mfid_popparameters enddef ;
diff --git a/metapost/context/base/mpiv/mp-mlib.mpiv b/metapost/context/base/mpiv/mp-mlib.mpiv
index a651d2270..7d20da104 100644
--- a/metapost/context/base/mpiv/mp-mlib.mpiv
+++ b/metapost/context/base/mpiv/mp-mlib.mpiv
@@ -1680,6 +1680,8 @@ def eofillup text t = draw t withpostscript "eoboth" enddef ; % we use draw bec
def eofill text t = fill t withpostscript "evenodd" enddef ;
def nofill text t = fill t withpostscript "collect" enddef ;
def nodraw text t = draw t withpostscript "collect" enddef ;
+def dodraw text t = draw t withpostscript "flush" enddef ;
+def dofill text t = fill t withpostscript "flush" enddef ;
%%% eoclip text t = clip t withpostscript "evenodd" enddef ; % no postscripts yet
% def withrule expr r =