-rw-r--r-- | demos/plot.lua | 3 | ||||
-rw-r--r-- | graph-init.lua | 8 |
diff --git a/demos/plot.lua b/demos/plot.lua index b95e4a58..1ae6eb67 100644 --- a/demos/plot.lua +++ b/demos/plot.lua @@ -125,6 +125,7 @@ local function legend_demo() local p = graph.legend { {'sinus', 'red', 'line'}, {'cosinus', 'blue', 'line', {{'dash', 7, 3}}}, + {'exp', 'red', 'circle'}, } p:show() @@ -133,9 +134,11 @@ local function legend_demo() local mp = graph.fxplot(math.sin, 0, 2*pi, 'red', 32) mp:addline(graph.fxline(math.cos, 0, 2*pi, 32), 'blue', {{'dash', 7,3}}) + mp:add(graph.fxline(|x| math.exp(-x), 0, 2*pi, 32), 'red', {{'marker', size=5, mark='circle'}}) mp.title = 'Plot example' mp.xtitle = 'x axis title' + mp.clip = false mp:set_mini(p) mp:save_svg('demo.svg', 600, 400) p:save_svg('legend.svg', 400, 200) diff --git a/graph-init.lua b/graph-init.lua index 48f0f828..e233fb0f 100644 --- a/graph-init.lua +++ b/graph-init.lua @@ -280,14 +280,10 @@ function graph.plot_lines(ln, title) end local function legend_symbol(sym, dx, dy) - if sym == 'square' then - return graph.rect(5+dx, 5+dy, 15+dx, 15+dy) - elseif sym == 'circle' then - return graph.ellipse(10+dx, 10+dy, 5, 5) - elseif sym == 'line' then + if sym == 'line' then return graph.segment(2+dx, 10+dy, 18+dx, 10+dy), {'stroke'} else - error('invalid legend symbol: ' .. sym) + return graph.marker(10+dx, 10+dy, sym, 8) end end |