summaryrefslogtreecommitdiff
path: root/metapost/context/base/mpiv/mp-lmtx.mpxl
diff options
context:
space:
mode:
Diffstat (limited to 'metapost/context/base/mpiv/mp-lmtx.mpxl')
-rw-r--r--metapost/context/base/mpiv/mp-lmtx.mpxl277
1 files changed, 275 insertions, 2 deletions
diff --git a/metapost/context/base/mpiv/mp-lmtx.mpxl b/metapost/context/base/mpiv/mp-lmtx.mpxl
index 42aa54f9f..070440916 100644
--- a/metapost/context/base/mpiv/mp-lmtx.mpxl
+++ b/metapost/context/base/mpiv/mp-lmtx.mpxl
@@ -531,8 +531,281 @@ vardef lmt_connected(text t) =
save p ; path p ;
p := origin t ;
subpath (1,length(p)) of p
-enddef;
+enddef ;
def lmt_connection expr t =
-- t
-enddef;
+enddef ;
+
+% also
+
+presetparameters "path" [
+ labels = false,
+ controls = false,
+ points = false,
+ path = origin
+] ;
+
+def lmt_path = applyparameters "path" "lmt_do_path" enddef ;
+
+vardef lmt_do_path =
+ image (
+ pushparameters "path" ;
+ save p ; path p ; p := getparameter "path" ;
+ drawpath p ;
+ if getparameter "points" :
+ drawpoints p ;
+ if getparameter "labels" :
+ drawpointlabels p ;
+ fi ;
+ fi ;
+ if getparameter "controls" :
+ drawcontrolpoints p ;
+ drawcontrollines p ;
+ fi ;
+ popparameters ;
+ )
+enddef ;
+
+% more
+
+presetparameters "function" [
+ sx = 1mm,
+ sy = 1mm,
+ offset = 0,
+ xmin = 1,
+ xmax = 1,
+ xstep = 1,
+ xsmall = 1,
+ xlarge = 1,
+ xlabels = "no",
+ xticks = "bottom", % top bottom middle
+ xcaption = "",
+ ymin = 1,
+ ymax = 1,
+ ystep = 1,
+ ysmall = 1,
+ ylarge = 1,
+ ylabels = "no",
+ yticks = "left", % left right middle
+ ycaption = "",
+ code = "",
+ close = false,
+ shape = "curve",
+ fillcolor = "",
+ drawsize = 1,
+ drawcolor = "",
+ frame = "", % yes ticks
+ linewidth = .05mm,
+ pointsymbol = "",
+ pointsize = 2,
+ pointcolor = ""
+] ;
+
+def lmt_function = applyparameters "function" "lmt_do_function" enddef ;
+
+vardef lmt_do_function_p(expr xmin, xmax, xstep, code, shape, close, fcolor, dsize, dcolor, psymbol, psize, pcolor) =
+ save p, q ; path p, q ;
+ p := lua.mp.lmt_function_x(xmin,xmax,xstep,code,shape) ;
+ if close :
+ q := (xmin,0) -- p -- (xmax,0) -- cycle ;
+ fill q withcolor fcolor ;
+ else :
+ draw p withpen currentpen scaled dsize withcolor dcolor
+ ;
+ fi ;
+ if psize > 0 :
+ if psymbol = "dot" :
+ draw image (
+ for i = 0 upto length(p) :
+ draw point i of p ;
+ endfor ;
+ ) withpen currentpen scaled psize withcolor pcolor ;
+ fi ;
+ fi ;
+enddef ;
+
+vardef lmt_do_function =
+ image (
+ pushparameters "function" ;
+ save sx, sy, lw, tl, tr, ts, tt, currentpen ; transform tr, tt ; pen currentpen ;
+ sx := getparameter "sx" ;
+ sy := getparameter "sy" ;
+ lw := getparameter "linewidth" ;
+ tl := 1/20 ; % tick length
+ ts := 1/10 ; % text scale
+ tr := identity xyscaled(10/sx,10/sy) ;
+ 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 ;
+ string code, option ;
+ path txl, txs, tyl, tys ;
+
+ xmin := getparameter "xmin" ;
+ xmax := getparameter "xmax" ;
+ xstep := getparameter "xstep" ;
+ xsmall := getparameter "xsmall" ;
+ xlarge := getparameter "xlarge" ;
+ ymin := getparameter "ymin" ;
+ ymax := getparameter "ymax" ;
+ ystep := getparameter "ystep" ;
+ ysmall := getparameter "ysmall" ;
+ ylarge := getparameter "ylarge" ;
+ code := getparameter "code" ;
+
+ if (getparametercount "functions") > 0 :
+ for s = 1 upto getparametercount "functions" :
+ pushparameters "functions" s ;
+ lmt_do_function_p (
+ getparameterdefault "xmin",
+ getparameterdefault "xmax",
+ getparameterdefault "xstep",
+ getparameterdefault "code",
+ getparameterdefault "shape",
+ getparameterdefault "close",
+ getparameterdefault "fillcolor",
+ getparameterdefault "drawsize",
+ getparameterdefault "drawcolor",
+ getparameterdefault "pointsymbol",
+ getparameterdefault "pointsize",
+ getparameterdefault "pointcolor"
+ ) ;
+ popparameters ;
+ endfor ;
+ elseif code <> "" :
+ lmt_do_function_p (
+ getparameter "xmin",
+ getparameter "xmax",
+ getparameter "xstep",
+ getparameter "code",
+ getparameter "shape",
+ getparameter "close",
+ getparameter "fillcolor",
+ getparameter "drawsize",
+ getparameter "drawcolor",
+ getparameter "pointsymbol",
+ getparameter "pointsize",
+ getparameter "pointcolor"
+ ) ;
+ fi ;
+
+ option := getparameter "xticks" ;
+ if option = "top" :
+ txs := (0,0) -- (0,tl) ;
+ elseif option = "bottom" :
+ txs := (0,-tl) -- (0,0) ;
+ else :
+ txs := (0,-tl) -- (0,tl) ;
+ fi ;
+
+ option := getparameter "yticks" ;
+ if option = "left" :
+ tys := (-tl,0) -- (0,0) ;
+ elseif option = "right" :
+ tys := (0,0) -- (tl,0) ;
+ else :
+ tys := (-tl,0) -- (tl,0) ;
+ fi ;
+
+ txs := txs transformed tr ;
+ tys := tys transformed tr ;
+ txl := txs scaled 2 ;
+ tyl := tys scaled 2 ;
+
+ draw (xmin,0) -- (xmax,0) ;
+ draw (0,ymin) -- (0,ymax) ;
+
+ option := getparameter "frame" ;
+ if option = "yes" :
+ 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 :
+ 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);
+ 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);
+ endfor ;
+ fi ;
+ if ysmall > 1 :
+ 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);
+ 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);
+ endfor ;
+ fi ;
+ fi ;
+
+ if xsmall > 1 :
+ for i = xmin step ((xmax-xmin)/xsmall) until xmax :
+ draw 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 ;
+ endfor ;
+ fi ;
+
+ if ysmall > 1 :
+ for i = ymin step ((ymax-ymin)/ysmall) until ymax :
+ draw tys shifted (0,i) ;
+ endfor ;
+ fi ;
+
+ if ylarge > 1 :
+ 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)) :
+ draw textext.lft(decimal i) transformed tt
+ shifted (1.25*(xpart point 0 of tyl),i) ;
+ fi ;
+ fi ;
+ endfor ;
+ fi ;
+
+ option := getparameter "xcaption" ;
+ if (option <> "") :
+ draw textext.bot(option) transformed tt
+ shifted center bottomboundary currentpicture ;
+ fi ;
+
+ option := getparameter "ycaption" ;
+ if (option <> "") :
+ draw textext.lft(option) transformed tt
+ shifted center leftboundary currentpicture ;
+ fi ;
+ )
+
+ xyscaled(sx,sy) ;
+
+ setbounds currentpicture to
+ boundingbox currentpicture
+ enlarged (getparameter "offset") ;
+
+ popparameters ;
+ )
+enddef ;
+