Improve legend creation to accept a list of entries - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/graph-init.lua
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2012年01月30日 09:42:48 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年01月30日 21:26:02 +0100
commit6af0ec5348f2b5cdcc9d21968fa5a8d670aab643 (patch)
tree3cef99036558342d1477ab925ea1203b45dc8c3c /graph-init.lua
parent896d5ee99b9db8bbb3a1a17b7ca4b1aea56e3282 (diff)
downloadgsl-shell-6af0ec5348f2b5cdcc9d21968fa5a8d670aab643.tar.gz
Improve legend creation to accept a list of entries
Diffstat (limited to 'graph-init.lua')
-rw-r--r--graph-init.lua 15
1 files changed, 9 insertions, 6 deletions
diff --git a/graph-init.lua b/graph-init.lua
index 5e1df2c9..8510a2f5 100644
--- a/graph-init.lua
+++ b/graph-init.lua
@@ -289,27 +289,30 @@ local function legend_symbol(sym, dx, dy)
return graph.ellipse(10+dx, 10+dy, 5, 5)
elseif sym == 'line' then
return graph.segment(2+dx, 10+dy, 18+dx, 10+dy), {'stroke'}
+ else
+ error('invalid legend symbol: ' .. sym)
end
end
-function graph.legend(labels, symbol, colors, trans)
- local n = #labels
+function graph.legend(entries)
+ local n = #entries
local p = graph.plot()
p.units, p.clip = false, false
for k= 1, n do
+ local text, color, symspec, trans = unpack(entries[k])
local y = (k-1) * 20
- local sym, symtr = legend_symbol(symbol, 0, y)
+ local sym, symtr = legend_symbol(symspec, 0, y)
local tr
if symtr then
tr = { symtr }
if trans then
- for j= 1, #trans do tr[#tr+1] = trans[j] end
+ for j, xtr in ipairs(trans) do tr[#tr+1] = xtr end
end
else
tr = trans
end
- p:add(sym, colors[k], tr)
- p:add(graph.textshape(25, y + 6, labels[k], 10), 'black')
+ p:add(sym, color, tr)
+ p:add(graph.textshape(25, y + 6, text, 10), 'black')
end
return p
end
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月24日 19:18:52 +0000

AltStyle によって変換されたページ (->オリジナル) /