2021-07-05 23:27:43 -04:00
|
|
|
local M = {}
|
|
|
|
|
2021-07-11 14:48:51 -04:00
|
|
|
local Util = require 'Util'
|
2021-07-05 23:27:43 -04:00
|
|
|
local Arc = require 'Arc'
|
|
|
|
local Text = require 'Text'
|
|
|
|
local CriticalText = require 'CriticalText'
|
|
|
|
local TextColumn = require 'TextColumn'
|
|
|
|
local Line = require 'Line'
|
|
|
|
local LabelPlot = require 'LabelPlot'
|
|
|
|
local ScalePlot = require 'ScalePlot'
|
|
|
|
|
|
|
|
local HEADER_HEIGHT = 45
|
|
|
|
local HEADER_FONT_SIZE = 15
|
|
|
|
-- TODO move all this font stuff to the theme file
|
|
|
|
local HEADER_UNDERLINE_CAP = CAIRO_LINE_CAP_ROUND
|
|
|
|
local HEADER_UNDERLINE_OFFSET = -20
|
|
|
|
local HEADER_UNDERLINE_THICKNESS = 3
|
|
|
|
|
2021-07-06 00:11:00 -04:00
|
|
|
M.make_font_spec = function(f, s, bold)
|
|
|
|
return {
|
|
|
|
family = f,
|
|
|
|
size = s,
|
|
|
|
weight = bold and CAIRO_FONT_WEIGHT_BOLD or CAIRO_FONT_WEIGHT_NORMAL,
|
|
|
|
slant = CAIRO_FONT_WEIGHT_NORMAL,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
M.normal_font_spec = M.make_font_spec(_G_Patterns_.FONT, 13, false)
|
|
|
|
M.label_font_spec = M.make_font_spec(_G_Patterns_.FONT, 8, false)
|
|
|
|
|
2021-07-10 17:13:17 -04:00
|
|
|
M.left_text_style = _G_Widget_.text_style(
|
|
|
|
M.normal_font_spec,
|
|
|
|
_G_Patterns_.INACTIVE_TEXT_FG,
|
2021-07-11 18:53:57 -04:00
|
|
|
'left',
|
|
|
|
'center'
|
2021-07-10 17:13:17 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
M.right_text_style = _G_Widget_.text_style(
|
|
|
|
M.normal_font_spec,
|
|
|
|
_G_Patterns_.PRIMARY_FG,
|
2021-07-11 18:53:57 -04:00
|
|
|
'right',
|
|
|
|
'center'
|
2021-07-10 17:13:17 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
local _bare_text = function(pt, text, style)
|
2021-07-10 19:28:49 -04:00
|
|
|
return _G_Widget_.plainText(pt, text, style)
|
2021-07-10 17:13:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
local _left_text = function(pt, text)
|
|
|
|
return _bare_text(pt, text, M.left_text_style)
|
|
|
|
end
|
|
|
|
|
|
|
|
local _right_text = function(pt, text)
|
|
|
|
return _bare_text(pt, text, M.right_text_style)
|
|
|
|
end
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- header
|
|
|
|
|
|
|
|
M.Header = function(x, y, w, s)
|
|
|
|
-- TODO what's the point of bottom_y?
|
|
|
|
local bottom_y = y + HEADER_HEIGHT
|
|
|
|
local underline_y = bottom_y + HEADER_UNDERLINE_OFFSET
|
|
|
|
|
|
|
|
local obj = {
|
2021-07-10 19:28:49 -04:00
|
|
|
text = _G_Widget_.plainText(
|
2021-07-09 23:53:21 -04:00
|
|
|
_G_Widget_.make_point(x, y),
|
2021-07-09 00:10:59 -04:00
|
|
|
s,
|
2021-07-10 17:13:17 -04:00
|
|
|
_G_Widget_.text_style(
|
|
|
|
M.make_font_spec(_G_Patterns_.FONT, HEADER_FONT_SIZE, true),
|
|
|
|
_G_Patterns_.HEADER_FG,
|
2021-07-11 18:53:57 -04:00
|
|
|
'left',
|
|
|
|
'top'
|
2021-07-10 19:28:49 -04:00
|
|
|
)
|
2021-07-09 00:10:59 -04:00
|
|
|
),
|
2021-07-05 23:27:43 -04:00
|
|
|
bottom_y = bottom_y,
|
2021-07-08 23:26:38 -04:00
|
|
|
underline = _G_Widget_.Line(
|
2021-07-10 23:07:27 -04:00
|
|
|
_G_Widget_.make_point(x, underline_y),
|
|
|
|
_G_Widget_.make_point(x + w, underline_y),
|
|
|
|
_G_Widget_.line_style(
|
|
|
|
HEADER_UNDERLINE_THICKNESS,
|
|
|
|
_G_Patterns_.HEADER_FG,
|
|
|
|
HEADER_UNDERLINE_CAP
|
|
|
|
)
|
2021-07-08 23:26:38 -04:00
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return obj
|
|
|
|
end
|
|
|
|
|
|
|
|
M.drawHeader = function(cr, header)
|
|
|
|
Text.draw(header.text, cr)
|
|
|
|
Line.draw(header.underline, cr)
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- label plot
|
|
|
|
|
2021-07-11 14:48:51 -04:00
|
|
|
M.default_grid_style = _G_Widget_.grid_style(9, 4, _G_Patterns_.BORDER_FG)
|
|
|
|
|
|
|
|
M.default_plot_style = _G_Widget_.plot_style(
|
|
|
|
90,
|
|
|
|
_G_Patterns_.BORDER_FG,
|
|
|
|
_G_Patterns_.PLOT_FILL_BORDER_PRIMARY,
|
|
|
|
_G_Patterns_.PLOT_FILL_BG_PRIMARY,
|
|
|
|
M.default_grid_style
|
|
|
|
)
|
|
|
|
|
|
|
|
M.percent_label_style = _G_Widget_.label_style(
|
|
|
|
_G_Patterns_.INACTIVE_TEXT_FG,
|
|
|
|
M.label_font_spec,
|
|
|
|
function(z) return Util.round_to_string(z * 100)..'%' end,
|
|
|
|
1
|
|
|
|
)
|
|
|
|
|
|
|
|
M.initThemedLabelPlot = function(x, y, w, h, label_style)
|
|
|
|
return _G_Widget_.LabelPlot(
|
2021-07-11 18:12:39 -04:00
|
|
|
_G_Widget_.make_box(x, y, w, h),
|
2021-07-11 14:48:51 -04:00
|
|
|
M.default_plot_style,
|
|
|
|
label_style
|
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- percent plot (label plot with percent signs and some indicator data above it)
|
|
|
|
|
|
|
|
M.initPercentPlot = function(x, y, w, h, spacing, label)
|
|
|
|
return {
|
2021-07-10 17:13:17 -04:00
|
|
|
label = _left_text(_G_Widget_.make_point(x, y), label),
|
2021-07-10 19:44:32 -04:00
|
|
|
value = _G_Widget_.formattedThresholdText(
|
2021-07-10 13:57:58 -04:00
|
|
|
_G_Widget_.make_point(x + w, y),
|
2021-07-09 22:22:49 -04:00
|
|
|
nil,
|
2021-07-10 19:44:32 -04:00
|
|
|
M.right_text_style,
|
2021-07-10 22:50:30 -04:00
|
|
|
'%s%%',
|
2021-07-10 23:33:25 -04:00
|
|
|
_G_Widget_.threshold_text_style(
|
|
|
|
_G_Patterns_.CRITICAL_FG,
|
|
|
|
80
|
|
|
|
)
|
2021-07-09 22:22:49 -04:00
|
|
|
),
|
2021-07-11 14:48:51 -04:00
|
|
|
plot = M.initThemedLabelPlot(
|
|
|
|
x,
|
|
|
|
y + spacing,
|
|
|
|
w,
|
|
|
|
h,
|
|
|
|
M.percent_label_style
|
|
|
|
),
|
2021-07-05 23:27:43 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
M.percent_plot_draw_static = function(pp, cr)
|
|
|
|
Text.draw(pp.label, cr)
|
|
|
|
LabelPlot.draw_static(pp.plot, cr)
|
|
|
|
end
|
|
|
|
|
|
|
|
M.percent_plot_draw_dynamic = function(pp, cr)
|
|
|
|
CriticalText.draw(pp.value, cr)
|
|
|
|
LabelPlot.draw_dynamic(pp.plot, cr)
|
|
|
|
end
|
|
|
|
|
|
|
|
M.percent_plot_set = function(pp, cr, value)
|
|
|
|
Text.set(pp.value, cr, math.floor(value))
|
|
|
|
LabelPlot.update(pp.plot, value * 0.01)
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- scaled plot
|
|
|
|
|
2021-07-11 14:48:51 -04:00
|
|
|
M.base_2_scale_data = _G_Widget_.scale_data(2, 1, 0.9)
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
M.initThemedScalePlot = function(x, y, w, h, f)
|
2021-07-11 14:48:51 -04:00
|
|
|
return _G_Widget_.ScalePlot(
|
2021-07-11 18:12:39 -04:00
|
|
|
_G_Widget_.make_box(x, y, w, h),
|
2021-07-11 14:48:51 -04:00
|
|
|
M.default_plot_style,
|
|
|
|
_G_Widget_.label_style(
|
|
|
|
_G_Patterns_.INACTIVE_TEXT_FG,
|
|
|
|
M.label_font_spec,
|
|
|
|
f,
|
|
|
|
1
|
|
|
|
),
|
|
|
|
M.base_2_scale_data
|
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- scaled plot (with textual data above it)
|
|
|
|
|
|
|
|
M.initLabeledScalePlot = function(x, y, w, h, f, spacing, label)
|
|
|
|
return {
|
2021-07-09 23:53:21 -04:00
|
|
|
label = _left_text(
|
|
|
|
_G_Widget_.make_point(x, y),
|
2021-07-10 17:13:17 -04:00
|
|
|
label
|
2021-07-09 23:53:21 -04:00
|
|
|
),
|
|
|
|
value = _right_text(
|
|
|
|
_G_Widget_.make_point(x + w, y),
|
2021-07-10 17:13:17 -04:00
|
|
|
label
|
2021-07-09 23:53:21 -04:00
|
|
|
),
|
2021-07-05 23:27:43 -04:00
|
|
|
plot = M.initThemedScalePlot(x, y + spacing, w, h, f),
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
M.annotated_scale_plot_draw_static = function(asp, cr)
|
|
|
|
Text.draw(asp.label, cr)
|
|
|
|
end
|
|
|
|
|
|
|
|
M.annotated_scale_plot_draw_dynamic = function(asp, cr)
|
|
|
|
Text.draw(asp.value, cr)
|
|
|
|
ScalePlot.draw_dynamic(asp.plot, cr)
|
|
|
|
end
|
|
|
|
|
|
|
|
M.annotated_scale_plot_set = function(asp, cr, text_value, plot_value)
|
|
|
|
-- TODO this could be made more intelligent
|
|
|
|
Text.set(asp.value, cr, text_value)
|
|
|
|
ScalePlot.update(asp.plot, cr, plot_value)
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- ring
|
|
|
|
|
|
|
|
M.initRing = function(x, y, r)
|
2021-07-08 22:57:35 -04:00
|
|
|
return _G_Widget_.Arc(
|
2021-07-11 18:19:09 -04:00
|
|
|
_G_Widget_.make_semicircle(x, y, r, 0, 360),
|
2021-07-10 14:43:20 -04:00
|
|
|
_G_Widget_.arc_style(
|
|
|
|
2,
|
|
|
|
_G_Patterns_.BORDER_FG
|
|
|
|
)
|
2021-07-08 22:57:35 -04:00
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- ring with text data in the center
|
|
|
|
|
2021-07-10 19:07:45 -04:00
|
|
|
M.initTextRing = function(x, y, r, fmt, limit)
|
2021-07-05 23:27:43 -04:00
|
|
|
return {
|
|
|
|
ring = M.initRing(x, y, r),
|
2021-07-10 19:44:32 -04:00
|
|
|
value = _G_Widget_.formattedThresholdText(
|
2021-07-09 23:53:21 -04:00
|
|
|
_G_Widget_.make_point(x, y),
|
2021-07-09 22:22:49 -04:00
|
|
|
nil,
|
2021-07-10 17:13:17 -04:00
|
|
|
_G_Widget_.text_style(
|
|
|
|
M.normal_font_spec,
|
|
|
|
_G_Patterns_.PRIMARY_FG,
|
2021-07-11 18:53:57 -04:00
|
|
|
'center',
|
|
|
|
'center'
|
2021-07-10 17:13:17 -04:00
|
|
|
),
|
2021-07-10 22:50:30 -04:00
|
|
|
fmt,
|
2021-07-10 23:33:25 -04:00
|
|
|
_G_Widget_.threshold_text_style(
|
|
|
|
_G_Patterns_.CRITICAL_FG,
|
|
|
|
limit
|
|
|
|
)
|
2021-07-09 22:22:49 -04:00
|
|
|
),
|
2021-07-05 23:27:43 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
M.text_ring_draw_static = function(tr, cr)
|
|
|
|
Arc.draw(tr.ring, cr)
|
|
|
|
end
|
|
|
|
|
|
|
|
M.text_ring_draw_dynamic = function(tr, cr)
|
|
|
|
CriticalText.draw(tr.value, cr)
|
|
|
|
end
|
|
|
|
|
|
|
|
M.text_ring_set = function(tr, cr, value)
|
|
|
|
CriticalText.set(tr.value, cr, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- separator (eg a horizontal line)
|
|
|
|
|
|
|
|
M.initSeparator = function(x, y, w)
|
2021-07-08 23:26:38 -04:00
|
|
|
return _G_Widget_.Line(
|
2021-07-10 23:07:27 -04:00
|
|
|
_G_Widget_.make_point(x, y),
|
|
|
|
_G_Widget_.make_point(x + w, y),
|
|
|
|
_G_Widget_.line_style(
|
|
|
|
1,
|
|
|
|
_G_Patterns_.BORDER_FG,
|
|
|
|
CAIRO_LINE_CAP_BUTT
|
|
|
|
)
|
2021-07-08 23:26:38 -04:00
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- text row (label with a value, aligned as far apart as possible)
|
|
|
|
|
2021-07-09 00:10:59 -04:00
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
M.initTextRow = function(x, y, w, label)
|
|
|
|
return {
|
2021-07-09 00:10:59 -04:00
|
|
|
label = _left_text(
|
2021-07-09 23:53:21 -04:00
|
|
|
_G_Widget_.make_point(x, y),
|
2021-07-10 17:13:17 -04:00
|
|
|
label
|
2021-07-09 00:10:59 -04:00
|
|
|
),
|
|
|
|
value = _right_text(
|
2021-07-09 23:53:21 -04:00
|
|
|
_G_Widget_.make_point(x + w, y),
|
2021-07-10 17:13:17 -04:00
|
|
|
nil
|
2021-07-09 00:10:59 -04:00
|
|
|
),
|
2021-07-05 23:27:43 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
M.text_row_draw_static = function(row, cr)
|
|
|
|
Text.draw(row.label, cr)
|
|
|
|
end
|
|
|
|
|
|
|
|
M.text_row_draw_dynamic = function(row, cr)
|
|
|
|
Text.draw(row.value, cr)
|
|
|
|
end
|
|
|
|
|
|
|
|
M.text_row_set = function(row, cr, value)
|
|
|
|
Text.set(row.value, cr, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- text row with critical indicator
|
|
|
|
|
2021-07-06 18:56:24 -04:00
|
|
|
M.initTextRowCrit = function(x, y, w, label, append_end, limit)
|
2021-07-05 23:27:43 -04:00
|
|
|
return{
|
2021-07-09 00:10:59 -04:00
|
|
|
label = _left_text(
|
2021-07-09 23:53:21 -04:00
|
|
|
_G_Widget_.make_point(x, y),
|
2021-07-10 17:13:17 -04:00
|
|
|
label
|
2021-07-09 00:10:59 -04:00
|
|
|
),
|
2021-07-10 19:44:32 -04:00
|
|
|
value = _G_Widget_.formattedThresholdText(
|
2021-07-09 23:53:21 -04:00
|
|
|
_G_Widget_.make_point(x + w, y),
|
2021-07-09 22:22:49 -04:00
|
|
|
nil,
|
2021-07-10 17:13:17 -04:00
|
|
|
_G_Widget_.text_style(
|
|
|
|
M.normal_font_spec,
|
|
|
|
_G_Patterns_.PRIMARY_FG,
|
2021-07-11 18:53:57 -04:00
|
|
|
'right',
|
|
|
|
'center'
|
2021-07-10 17:13:17 -04:00
|
|
|
),
|
2021-07-10 23:33:25 -04:00
|
|
|
append_end,
|
|
|
|
_G_Widget_.threshold_text_style(
|
|
|
|
_G_Patterns_.CRITICAL_FG,
|
|
|
|
limit
|
|
|
|
)
|
2021-07-09 22:22:49 -04:00
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
M.text_row_crit_draw_static = M.text_row_draw_static
|
|
|
|
|
|
|
|
M.text_row_crit_draw_dynamic = function(row, cr)
|
|
|
|
CriticalText.draw(row.value, cr)
|
|
|
|
end
|
|
|
|
|
|
|
|
M.text_row_crit_set = function(row, cr, value)
|
|
|
|
CriticalText.set(row.value, cr, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- multiple text row separated by spacing
|
|
|
|
|
|
|
|
M.initTextRows = function(x, y, w, spacing, labels)
|
|
|
|
return {
|
2021-07-09 22:22:49 -04:00
|
|
|
labels = _G_Widget_.TextColumn(
|
2021-07-09 23:53:21 -04:00
|
|
|
_G_Widget_.make_point(x, y),
|
2021-07-10 17:13:17 -04:00
|
|
|
labels,
|
|
|
|
M.left_text_style,
|
2021-07-10 22:50:30 -04:00
|
|
|
nil,
|
2021-07-10 17:13:17 -04:00
|
|
|
spacing
|
2021-07-09 22:22:49 -04:00
|
|
|
),
|
|
|
|
values = _G_Widget_.initTextColumnN(
|
2021-07-09 23:53:21 -04:00
|
|
|
_G_Widget_.make_point(x + w, y),
|
2021-07-10 17:13:17 -04:00
|
|
|
#labels,
|
|
|
|
M.right_text_style,
|
2021-07-10 22:50:30 -04:00
|
|
|
nil,
|
2021-07-10 17:13:17 -04:00
|
|
|
spacing
|
2021-07-09 22:22:49 -04:00
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
M.text_rows_draw_static = function(rows, cr)
|
|
|
|
TextColumn.draw(rows.labels, cr)
|
|
|
|
end
|
|
|
|
|
|
|
|
M.text_rows_draw_dynamic = function(rows, cr)
|
|
|
|
TextColumn.draw(rows.values, cr)
|
|
|
|
end
|
|
|
|
|
|
|
|
M.text_rows_set = function(rows, cr, i, value)
|
|
|
|
TextColumn.set(rows.values, cr, i, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- table
|
|
|
|
|
2021-07-11 16:53:25 -04:00
|
|
|
M.default_table_font_spec = M.make_font_spec(_G_Patterns_.FONT, 11, false)
|
|
|
|
|
|
|
|
M.default_table_style = _G_Widget_.table_style(
|
|
|
|
_G_Widget_.rect_style(
|
|
|
|
1,
|
|
|
|
_G_Patterns_.BORDER_FG
|
|
|
|
),
|
|
|
|
_G_Widget_.line_style(
|
|
|
|
1,
|
|
|
|
_G_Patterns_.BORDER_FG,
|
|
|
|
CAIRO_LINE_CAP_BUTT
|
|
|
|
),
|
|
|
|
_G_Widget_.table_header_style(
|
|
|
|
M.default_table_font_spec,
|
|
|
|
_G_Patterns_.PRIMARY_FG,
|
|
|
|
20
|
|
|
|
),
|
|
|
|
_G_Widget_.table_body_style(
|
|
|
|
M.default_table_font_spec,
|
|
|
|
_G_Patterns_.INACTIVE_TEXT_FG,
|
|
|
|
8
|
|
|
|
),
|
|
|
|
_G_Widget_.padding(5, 15, 5, 15)
|
|
|
|
)
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
M.initTable = function(x, y, w, h, n, labels)
|
2021-07-11 16:53:25 -04:00
|
|
|
return _G_Widget_.Table(
|
2021-07-11 18:12:39 -04:00
|
|
|
_G_Widget_.make_box(x, y, w, h),
|
2021-07-11 16:53:25 -04:00
|
|
|
n,
|
|
|
|
labels,
|
|
|
|
M.default_table_style
|
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- panel
|
|
|
|
|
2021-07-10 13:52:28 -04:00
|
|
|
M.initPanel = function(x, y, w, h, thickness)
|
2021-07-10 00:22:02 -04:00
|
|
|
return _G_Widget_.FillRect(
|
2021-07-11 18:12:39 -04:00
|
|
|
_G_Widget_.make_box(x, y, w, h),
|
|
|
|
_G_Widget_.rect_style(thickness, _G_Patterns_.BORDER_FG),
|
2021-07-10 00:22:02 -04:00
|
|
|
_G_Patterns_.PANEL_BG
|
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|