Skip to content

Commit d703c1f

Browse files
committed
📦 add grid example
1 parent e735f8f commit d703c1f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/examples/grid.lua

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
local Plotter = require 'plotter'
2+
3+
local termw,termh = term.getSize()
4+
local winPlot = window.create(term.current(), 1, 1, termw, termh, true)
5+
6+
local plotter = Plotter(winPlot)
7+
8+
local plotData = {}
9+
local gridOffsetX = 0
10+
local gridGapX = 20
11+
local value = 0
12+
13+
-- preload chart with blank data
14+
for i = 1, plotter.box.width do
15+
table.insert(plotData, plotter.NAN)
16+
end
17+
18+
while true do
19+
value = value + math.random(-90,100)
20+
21+
-- push new value to end, remove first value
22+
table.insert(plotData, type(value) ~= 'nil' and value or plotter.NAN)
23+
table.remove(plotData, 1)
24+
25+
gridOffsetX = (gridOffsetX - 1) % gridGapX
26+
27+
plotter:clear(colors.black)
28+
29+
local min, max = plotter:chartLineAuto(plotData, colors.white)
30+
31+
-- chart grid with specified offset and styles
32+
plotter:chartGrid(#plotData, min, max, gridOffsetX, colors.white, {
33+
-- integer >= 1
34+
xGap = gridGapX,
35+
36+
-- number >= 1
37+
yLinesMin = 3,
38+
39+
-- integer >= 2
40+
yLinesFactor = 2
41+
42+
-- effective yLinesMax: yLinesMin * yLinesFactor
43+
})
44+
45+
winPlot.setVisible(false)
46+
plotter:render()
47+
winPlot.setVisible(true)
48+
49+
sleep(0.1)
50+
end

0 commit comments

Comments
 (0)