summaryrefslogtreecommitdiff
path: root/metapost/context/base/mpxl/mp-lmtx.mpxl
diff options
context:
space:
mode:
Diffstat (limited to 'metapost/context/base/mpxl/mp-lmtx.mpxl')
-rw-r--r--metapost/context/base/mpxl/mp-lmtx.mpxl154
1 files changed, 62 insertions, 92 deletions
diff --git a/metapost/context/base/mpxl/mp-lmtx.mpxl b/metapost/context/base/mpxl/mp-lmtx.mpxl
index be4ae716b..acf3dcbef 100644
--- a/metapost/context/base/mpxl/mp-lmtx.mpxl
+++ b/metapost/context/base/mpxl/mp-lmtx.mpxl
@@ -1,5 +1,5 @@
%D \module
-%D [ file=mp-luas.lmtx,
+%D [ file=mp-lmtx.lmtx,
%D version=2019.06.23,
%D title=\CONTEXT\ \METAPOST\ graphics,
%D subtitle=\LUA,
@@ -1041,9 +1041,11 @@ presetparameters "chart" [
"darkyellow", "darkmagenta", "darkcyan",
"darkgray"
},
+ linecolors = { },
colormode = "global",
linewidth = .25mm,
+ % linegap = 0,
legendcolor = "",
legendstyle = "",
@@ -1082,16 +1084,18 @@ def lmt_chart_bar = applyparameters "chart:bar" "lmt_do_chart_bar"
def lmt_do_chart_start (expr what) =
pushparameters what ;
- save width, height, distance, linewidth, labelgap, labelfraction, value, nofsamples, nofsamplesets ;
- save fillcolor, drawcolor, labelcolor, labelstyle, labelformat, labelstrut, labelanchor, colormode ;
- string fillcolor, drawcolor, labelcolor, labelstyle, labelformat, labelstrut, labelanchor, colormode ;
+ save width, height, depth, distance, linewidth, linegap, labelgap, labelfraction, value, nofsamples, nofsamplesets ;
+ save fillcolor, linecolor, drawcolor, labelcolor, labelstyle, labelformat, labelstrut, labelanchor, colormode ;
+ string fillcolor, linecolor, drawcolor, labelcolor, labelstyle, labelformat, labelstrut, labelanchor, colormode ;
if hasparameter "sampleset" :
setluaparameter what "samples" (getparameter "sampleset") ;
fi ;
height := getparameter "height" ;
+ depth := max((getparameter "originsize"), (getparameter "innerradius")) ;
width := getparameter "width" ;
distance := getparameter "distance" ;
linewidth := getparameter "linewidth" ;
+ linegap := getparameterdefault "linegap" linewidth ;
drawcolor := getparameter "drawcolor" ;
colormode := getparameter "colormode" ;
labelcolor := getparameter "labelcolor" ;
@@ -1168,75 +1172,28 @@ def lmt_do_chart_legend =
fi ;
enddef ;
-% vardef lmt_do_chart_circle =
-% image (
-% lmt_do_chart_start("chart:circle") ;
-% if (nofsamplesets > 0) and (nofsamples > 0) :
-% nofsamplesets := 1 ;
-% save p, r, s, first, last, total, factor, n, percentage ;
-% path p, r, s[] ; boolean percentage ;
-% percentage := getparameter "percentage" ;
-% total := 0 ;
-% for i = 1 upto nofsamples :
-% total := total + getparameter "samples" (1) i ; % () is needed else 1i
-% endfor ;
-% factor := 100/total ;
-% first := 0 ;
-% p := fullcircle ysized (height) ;
-% r := origin -- (2*height,0) ;
-% for i = 1 upto nofsamples :
-% fillcolor := getparameter "fillcolors" i ;
-% value := (getparameter "samples" (1) i) * factor ;
-% last := first + (360/100) * value ;
-% s[i] := ((p cutbefore (r rotated first)) cutafter (r rotated last)) ;
-% % fill
-% % (if innerradius > 0 : reverse (s[i] scaled innerradius) else : origin fi) -- s[i] -- cycle
-% % withcolor fillcolor
-% % ;
-% fill origin -- s[i] -- cycle withcolor fillcolor ;
-% first := last ;
-% endfor ;
-% if linewidth > 0 :
-% if drawcolor = "" :
-% drawcolor := backgroundcolor ;
-% fi ;
-% for i = 1 upto nofsamples :
-% interim linecap := butt ;
-% draw origin -- (point 0 of s[i]) withpen pencircle scaled linewidth withcolor drawcolor ;
-% draw origin -- (point length(s[i]) of s[i]) withpen pencircle scaled linewidth withcolor drawcolor ;
-% endfor ;
-% fi ;
-% if getparameter "showlabels" :
-% first := 0 ;
-% for i = 1 upto nofsamples :
-% value := getparameter "samples" (1) i ;
-% last := first + (360/100) * value * factor ;
-% draw lmt_do_chart_text (s,i,value)
-% shifted ((labelfraction*(height/2),0) rotated ((first+last)/2)) ;
-% first := last ;
-% endfor ;
-% fi ;
-% lmt_do_chart_legend ;
-% n := getparameter "originsize" ;
-% if n > 0 :
-% fill fullcircle scaled n withcolor "white" ;
-% fi ;
-% n := getparameter "innerradius" ;
-% if n > 0 :
-% fill fullcircle scaled n withcolor "white" ;
-% fi ;
-% fi ;
-% lmt_do_chart_stop ;
-% )
-% enddef ;
+% draw lmt_chart_circle [
+% height = 4cm,
+% innerradius = 2.0cm,
+% samples = { { 10, 20, 30, 40, 50 } },
+% percentage = false,
+% initialangle = 90,
+% linewidth = .125mm,
+% originsize = 0,
+% showlabels = false,
+% drawcolor = "white",
+% fillcolors = { "red", "green", "blue", "", "cyan" },
+% linecolors = { "magenta", "orange", "darkgray", "orange", "darkgray" }
+% linecolors = { "", "orange", "", "orange", "" }
+% ] ;
vardef lmt_do_chart_circle =
image (
lmt_do_chart_start("chart:circle") ;
if (nofsamplesets > 0) and (nofsamples > 0) :
nofsamplesets := 1 ;
- save p, r, s, first, last, total, factor, n, percentage, initial, clockwise ;
- path p, r, s[] ; boolean percentage, clockwise ;
+ save p, q, r, s, t, pl, ql, first, last, total, factor, n, percentage, initial, clockwise ;
+ path p, q, r, s[], t[] ; boolean percentage, clockwise ;
clockwise := true ;
percentage := getparameter "percentage" ;
initial := if not clockwise : - fi getparameter "initialangle" ; % watch sign
@@ -1248,54 +1205,67 @@ vardef lmt_do_chart_circle =
first := initial ;
if clockwise :
p := (reverse fullcircle rotated first) ysized (height) ;
+ q := (reverse fullcircle rotated first) ysized (depth) ;
else :
p := fullcircle ysized (height) ;
+ q := fullcircle ysized (depth) ;
fi ;
r := origin -- (2*height,0) ;
+ pl := ((linewidth + linegap) / (arclength p)) * 360;
+ ql := ((linewidth + linegap) / (arclength q)) * 360;
for i = 1 upto nofsamples :
fillcolor := getparameter "fillcolors" i ;
- value := (getparameter "samples" (1) i) * factor ;
- if (value > -eps) and (value < eps) :
- value := eps ; % otherwise weird effects with zero
+ linecolor := getparameterdefault "linecolors" i "" ;
+ if linecolor = "" :
+ linecolor := fillcolor ;
fi ;
+ value := (getparameter "samples" (1) i) * factor ;
+if (value > -eps) and (value < eps) :
+ s[i] := origin ;
+ t[i] := origin ;
+else :
+% if (value > -eps) and (value < eps) :
+% value := eps ; % otherwise weird effects with zero
+% fi ;
last := first if clockwise : - else : + fi (360/100) * value ;
- s[i] := ((p cutbefore (r rotated first)) cutafter (r rotated last)) ;
- % fill
- % (if innerradius > 0 : reverse (s[i] scaled innerradius) else : origin fi) -- s[i] -- cycle
- % withcolor fillcolor
- % ;
- fill origin -- s[i] -- cycle withcolor fillcolor ;
+ s[i] := ((p cutbefore (r rotated first)) cutafter (r rotated (last + pl))) ;
+ t[i] := reverse ((q cutbefore (r rotated first)) cutafter (r rotated (last + ql))) ;
+ path piece ; piece := s[i] -- t[i] -- cycle ;
+ if fillcolor <> "" :
+ fill piece
+ withpen pencircle scaled linewidth
+ withcolor fillcolor
+ ;
+ fi ;
+ if linecolor <> "" :
+ if linewidth > 0 :
+ interim linecap := butt ;
+ draw piece
+ withpen pencircle scaled linewidth
+ withcolor if linecolor <> "" : linecolor else drawcolor : fi
+ ;
+ fi ;
+ fi ;
first := last ;
+fi ;
endfor ;
if linewidth > 0 :
- if drawcolor = "" :
- drawcolor := backgroundcolor ;
- fi ;
- for i = 1 upto nofsamples :
- interim linecap := butt ;
- draw origin -- (point 0 of s[i]) withpen pencircle scaled linewidth withcolor drawcolor ;
- draw origin -- (point length(s[i]) of s[i]) withpen pencircle scaled linewidth withcolor drawcolor ;
- endfor ;
+ clip currentpicture to p enlarged linewidth ;
fi ;
if getparameter "showlabels" :
first := initial ;
for i = 1 upto nofsamples :
value := getparameter "samples" (1) i ;
last := first if clockwise : - else : + fi (360/100) * value * factor ;
+if (value > -eps) and (value < eps) :
+else :
draw lmt_do_chart_text (s,i,value)
shifted ((labelfraction*(height/2),0) rotated ((first+last)/2)) ;
first := last ;
+fi ;
endfor ;
fi ;
lmt_do_chart_legend ;
- n := getparameter "originsize" ;
- if n > 0 :
- fill fullcircle scaled n withcolor "white" ;
- fi ;
- n := getparameter "innerradius" ;
- if n > 0 :
- fill fullcircle scaled n withcolor "white" ;
- fi ;
fi ;
lmt_do_chart_stop ;
)