Skip to content

Commit

Permalink
📦 plotter chart auto-resizing for #38
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberbit committed Jan 2, 2024
1 parent bddc385 commit f7f2ac0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/telem/lib/Backplane.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,28 @@ function Backplane:cycleEvery(seconds)
return selfCycle
end

-- trigger eager layout updates on all attached outputs with updateLayout functions
function Backplane:updateLayouts()
self:dlog('Backplane:updateLayouts :: Updating layouts...')

for _, key in pairs(self.outputKeys) do
local output = self.outputs[key]

if type(output.updateLayout) == 'function' then
self:dlog('Backplane:updateLayouts :: - ' .. key)

local results = {pcall(output.updateLayout, output)}

if not table.remove(results, 1) then
t.log('Update layout fault for "' .. key .. '":')
t.pprint(table.remove(results, 1))
end
end
end

self:dlog('Backplane:updateLayouts :: Layouts updated')
end

function Backplane:debug(debug)
self.debugState = debug and true or false

Expand Down
24 changes: 21 additions & 3 deletions src/telem/lib/output/plotter/ChartLineOutputAdapter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ function ChartLineOutputAdapter:register ()
self:dlog('ChartLineOutputAdapter:boot :: plotter ready.')
end

self.plotter = plotterFactory(self.win)
self:updateLayout()

for i = 1, self.MAX_ENTRIES do
t.constrainAppend(self.plotData, self.plotter.NAN, self.MAX_ENTRIES)
end
end

function ChartLineOutputAdapter:updateLayout (bypassRender)
self.plotter = plotterFactory(self.win)

if not bypassRender then
self:render()
end
end

function ChartLineOutputAdapter:write (collection)
assert(o.instanceof(collection, MetricCollection), 'Collection must be a MetricCollection')

Expand All @@ -69,6 +77,18 @@ function ChartLineOutputAdapter:write (collection)
self.gridOffsetX = 0
end

-- lazy layout update
local winw, winh = self.win.getSize()
if winw ~= self.plotter.box.term_width or winh ~= self.plotter.box.term_height then
self:updateLayout(true)
end

self:render()

return self
end

function ChartLineOutputAdapter:render ()
local dataw = #{self.plotData}

local actualmin, actualmax = math.huge, -math.huge
Expand Down Expand Up @@ -134,8 +154,6 @@ function ChartLineOutputAdapter:write (collection)
end

self.win.setVisible(true)

return self
end

return ChartLineOutputAdapter

0 comments on commit f7f2ac0

Please sign in to comment.