diff options
author | Context Git Mirror Bot <phg42.2a@gmail.com> | 2016-09-12 09:56:30 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2016-09-12 09:56:30 +0200 |
commit | fbf22006525c920e93b9f671c2af3d4df2be902e (patch) | |
tree | 34d00873adf1442775edd4aa8cd5edc7da73919f /tex/context/modules/mkiv | |
parent | bfc2e20d0dfa0dfaf04b0c2c81aed20638f21c91 (diff) | |
download | context-fbf22006525c920e93b9f671c2af3d4df2be902e.tar.gz |
2016-09-12 08:18:00
Diffstat (limited to 'tex/context/modules/mkiv')
-rw-r--r-- | tex/context/modules/mkiv/m-chart.lua | 120 | ||||
-rw-r--r-- | tex/context/modules/mkiv/m-chart.mkvi | 62 |
2 files changed, 119 insertions, 63 deletions
diff --git a/tex/context/modules/mkiv/m-chart.lua b/tex/context/modules/mkiv/m-chart.lua index f1e7f4cb9..66f2b4c5f 100644 --- a/tex/context/modules/mkiv/m-chart.lua +++ b/tex/context/modules/mkiv/m-chart.lua @@ -10,24 +10,28 @@ if not modules then modules = { } end modules ['x-flow'] = { -- use metapost.graphic(....) directly -- todo: labels +-- todo: named colors -moduledata.charts = moduledata.charts or { } +local type, tonumber, rawget, next = type, tonumber, rawget, next +local gsub, find, lower = string.gsub, string.find, string.lower +local P, S, C, Cc, lpegmatch = lpeg.P, lpeg.S, lpeg.C, lpeg.Cc, lpeg.match -local gsub, match, find, format, lower = string.gsub, string.match, string.find, string.format, string.lower +local formatters = string.formatters local setmetatableindex = table.setmetatableindex -local P, S, C, Cc, lpegmatch = lpeg.P, lpeg.S, lpeg.C, lpeg.Cc, lpeg.match -local report_chart = logs.reporter("chart") +moduledata.charts = moduledata.charts or { } + +local report_chart = logs.reporter("chart") -local variables = interfaces.variables +local variables = interfaces.variables -local v_yes = variables.yes -local v_no = variables.no -local v_none = variables.none -local v_standard = variables.standard -local v_overlay = variables.overlay -local v_round = variables.round -local v_test = variables.test +local v_yes = variables.yes +local v_no = variables.no +local v_none = variables.none +local v_standard = variables.standard +local v_overlay = variables.overlay +local v_round = variables.round +local v_test = variables.test local defaults = { chart = { @@ -252,8 +256,8 @@ end function commands.flow_set_text(align,str) temp.texts[#temp.texts+1] = { - location = align, - text = str, + align = align, + text = str, } end @@ -504,7 +508,7 @@ local function process_cells(chart,xoffset,yoffset) if shapedata.kind == "line" then local linesettings = settings.line context("flow_shape_line_color := \\MPcolor{%s} ;", linesettings.color) - context("flow_shape_fill_color := \\MPcolor{%s} ;", linesettings.backgroundcolor) + context("flow_shape_fill_color := black ;") context("flow_shape_line_width := %p ; ", linesettings.rulethickness) elseif focus[cell.focus] or focus[cell.name] then local focussettings = settings.focus @@ -597,9 +601,17 @@ local function process_connections(chart,xoffset,yoffset) end end -local texttemplate = "\\setvariables[flowcell:text][x=%s,y=%s,text={%s},align={%s},figure={%s},destination={%s}]" +local f_texttemplate_t = formatters["\\setvariables[flowcell:text][x=%s,y=%s,n=%i,align={%s},figure={%s},overlay={%s},destination={%s}]"] +local f_texttemplate_l = formatters["\\doFLOWlabel{%i}{%i}{%i}"] -local splitter = lpeg.splitat(":") +local splitter = lpeg.splitat(":") +local charttexts = { } -- permits " etc in mp + +function commands.flow_get_text(n) + if n > 0 then + context(charttexts[n]) + end +end local function process_texts(chart,xoffset,yoffset) local data = chart.data @@ -607,41 +619,59 @@ local function process_texts(chart,xoffset,yoffset) if not data then return end + charttexts = { } for i=1,#data do local cell = visible(chart,data[i]) if cell then - local x = cell.x or 1 - local y = cell.y or 1 - local texts = cell.texts - for i=1,#texts do - local text = texts[i] - local data = text.text - local align = validlabellocations[text.align or ""] or text.align or "" - local figure = i == 1 and cell.figure or "" - local destination = i == 1 and cell.destination or "" - context('flow_chart_draw_text(%s,%s,textext("%s")) ;',x,y,format(texttemplate,x,y,data,align,figure,destination)) + local x = cell.x or 1 + local y = cell.y or 1 + local figure = cell.figure or "" + local overlay = cell.overlay or "" + local destination = cell.destination or "" + local texts = cell.texts + local noftexts = #texts + if noftexts > 0 then + for i=1,noftexts do + local text = texts[i] + local data = text.text + local align = text.align or "" + local align = validlabellocations[align] or align + charttexts[#charttexts+1] = data + context('flow_chart_draw_text(%s,%s,textext("%s")) ;',x,y,f_texttemplate_t(x,y,#charttexts,align,figure,overlay,destination)) + if i == 1 then + figure = "" + overlay = "" + destination = "" + end + end + elseif figure ~= "" or overlay ~= "" or destination ~= "" then + context('flow_chart_draw_text(%s,%s,textext("%s")) ;',x,y,f_texttemplate_t(x,y,0,"",figure,overlay,destination)) end local labels = cell.labels for i=1,#labels do - local label = labels[i] - local text = label.text - local location = validlabellocations[label.location or ""] or label.location or "" - if text and location then - context('flow_chart_draw_label(%s,%s,"%s",textext("\\strut %s")) ;',x,y,location,text) + local label = labels[i] + local text = label.text + local location = label.location or "" + local location = validlabellocations[location] or location + if text and text ~= "" then + charttexts[#charttexts+1] = text + context('flow_chart_draw_label(%s,%s,"%s",textext("%s")) ;',x,y,location,f_texttemplate_l(x,y,#charttexts)) end end local exits = cell.exits for i=1,#exits do - local exit = exits[i] - local text = exit.text - local location = validlabellocations[exit.location or ""] - if text and location then + local exit = exits[i] + local text = exit.text + local location = exit.location or "" + local location = validlabellocations[location] or location + if text ~= "" then -- maybe make autoexit an option if location == "l" and x == chart.from_x + 1 or location == "r" and x == chart.to_x - 1 or location == "t" and y == chart.to_y - 1 or location == "b" and y == chart.from_y + 1 then - context('flow_chart_draw_exit(%s,%s,"%s",textext("\\strut %s")) ;',x,y,location,text) + charttexts[#charttexts+1] = text + context('flow_chart_draw_exit(%s,%s,"%s",textext("%s")) ;',x,y,location,f_texttemplate_l(x,y,#charttexts)) end end end @@ -649,10 +679,10 @@ local function process_texts(chart,xoffset,yoffset) for i=1,#connections do local comments = connections[i].comments for j=1,#comments do - local comment = comments[j] - local text = comment.text + local comment = comments[j] + local text = comment.text local location = comment.location or "" - local length = 0 + local length = 0 -- "tl" "tl:*" "tl:0.5" local loc, len = lpegmatch(splitter,location) -- do the following in lpeg if len == "*" then @@ -664,12 +694,13 @@ local function process_texts(chart,xoffset,yoffset) end elseif loc then location = validcommentlocations[loc] or "*" - length = tonumber(len) or 0 + length = tonumber(len) or 0 else location = validcommentlocations[location] or "" end - if text and location then - context('flow_chart_draw_comment(%s,%s,%s,"%s",%s,textext("\\strut %s")) ;',x,y,i,location,length,text) + if text and text ~= "" then + charttexts[#charttexts+1] = text + context('flow_chart_draw_comment(%s,%s,%s,"%s",%s,textext("%s")) ;',x,y,i,location,length,f_texttemplate_l(x,y,#charttexts)) end end end @@ -837,6 +868,9 @@ local function makechart(chart) context("flow_chart_offset := %p ;",offset) -- context("flow_reverse_y := true ;") +if chartsettings.option == v_test then + context("flow_draw_test_shapes ;") +end process_cells(chart,0,0) process_connections(chart,0,0) process_texts(chart,0,0) diff --git a/tex/context/modules/mkiv/m-chart.mkvi b/tex/context/modules/mkiv/m-chart.mkvi index a0c8b2244..a1def7065 100644 --- a/tex/context/modules/mkiv/m-chart.mkvi +++ b/tex/context/modules/mkiv/m-chart.mkvi @@ -15,7 +15,6 @@ % flowsets % autoscaling (bodyfontsteps) % comment -% overlay % % todo: % \useFLOWchart[name][parent][setting,setting][additional settings] @@ -63,8 +62,6 @@ \c!commentoffset=.5\bodyfontsize, \c!exitoffset=\zeropoint, % \c!split=\v!no, - % \c!maxwidth=, - % \c!maxheight=, % \c!option=, % \c!bodyfont=, % \c!dot=, % private option @@ -307,7 +304,7 @@ \unexpanded\def\module_charts_FLOW_include [#name][#settings]{% \begingroup - \getparameters[FLOWi][x=1,y=1,#settings]% + \getparameters[FLOWi][\c!x=1,\c!y=1,#settings]% \ctxcommand{flow_set_include("#name",\number\FLOWix,\number\FLOWiy,\!!bs\detokenize{#settings}\!!es)}% \endgroup \ignorespaces @@ -315,7 +312,8 @@ \setvariables [flowcell:text] - [x=1, + [n=0, + x=1, y=1, text=, align=, @@ -324,8 +322,6 @@ \def\FLOWx{\getvariable{flowcell:text}{x}} % compatibility (for Willi) \def\FLOWy{\getvariable{flowcell:text}{y}} % compatibility (for Willi) -% \c!background={\@@FLOWbackground,\FLOWoverlay}, - \defineoverlay [flowcell:figure] [\overlayfigure{\getvariable{flowcell:text}{figure}}] @@ -335,13 +331,15 @@ \iftrialtypesetting \directsetup{flowcell:text:place:indeed} \else \iflocation - \doifelsenothing {\getvariable{flowcell:text}{destination}} { + \edef\flowcelldestination{\getvariable{flowcell:text}{destination}}% + \ifx\flowcelldestination\empty \directsetup{flowcell:text:place:indeed} - } { + \else % tricky: scaling and moving around is not taken into account - \setupinteraction[\c!color=,\c!contrastcolor=] - \gotobox{\directsetup{flowcell:text:place:indeed}}[\getvariable{flowcell:text}{destination}] - } + \letinteractionparameter\c!color\empty + \letinteractionparameter\c!contrastcolor\empty + \gotobox{\directsetup{flowcell:text:place:indeed}}[\flowcelldestination] + \fi \else \directsetup{flowcell:text:place:indeed} \fi \fi @@ -351,17 +349,41 @@ \startsetups flowcell:text:place:indeed \begingroup \directsetup{flowcell:text:user} - \doifelsenothing {\getvariable{flowcell:text}{figure}} { - \expandcheckedcsname{flowcell:}{\getvariable{flowcell:text}{align}}\empty - {\getvariable{flowcell:text}{text}} - } { - \expandcheckedcsname{flowcell:}{\getvariable{flowcell:text}{align}}\empty - [\c!background=flowcell:figure] - {\getvariable{flowcell:text}{text}} - } + \edef\flowcellfigure {\getvariable{flowcell:text}{figure}}% + \edef\flowcelloverlay{\getvariable{flowcell:text}{overlay}}% + \edef\flowcellalign {\getvariable{flowcell:text}{align}}% + \edef\flowcellindex {\getvariable{flowcell:text}{n}}% + \ifx\flowcellfigure\empty + \ifx\flowcelloverlay\empty + \expandcheckedcsname{flowcell:}\flowcellalign\empty + % {\getvariable{flowcell:text}{text}} + {\getFLOWtext\flowcellindex} + \else + \expandcheckedcsname{flowcell:}\flowcellalign\empty + [\c!background={\flowcelloverlay}] + % {\getvariable{flowcell:text}{text}} + {\getFLOWtext\flowcellindex} + \fi + \else + \expandcheckedcsname{flowcell:}\flowcellalign\empty + [\c!background=flowcell:figure] + % {\getvariable{flowcell:text}{text}} + {\getFLOWtext\flowcellindex} + \fi \endgroup \stopsetups +\unexpanded\def\doFLOWlabel#1#2#3% + {\begingroup + \def\FLOWx{#1}% + \def\FLOWy{#2}% + \strut + \getFLOWtext{#3}% + \endgroup} + +\unexpanded\def\getFLOWtext#1% + {\ifcase#1\else\ctxcommand{flow_get_text(#1)}\fi} + \defineframed % to be discussed: shape or global [flowcell:base] [\c!offset=\v!overlay, % no strut ? |