2021-07-05 23:27:43 -04:00
|
|
|
local M = {}
|
|
|
|
|
2021-07-29 22:37:30 -04:00
|
|
|
local F = require 'primitive'
|
2021-07-29 22:39:38 -04:00
|
|
|
local util = require 'util'
|
2021-07-29 22:18:29 -04:00
|
|
|
local theme = require 'theme'
|
2021-07-29 22:37:30 -04:00
|
|
|
local dial = require 'dial'
|
|
|
|
local rect = require 'rect'
|
|
|
|
local fillrect = require 'fillrect'
|
|
|
|
local compounddial = require 'compounddial'
|
|
|
|
local arc = require 'arc'
|
|
|
|
local text = require 'text'
|
|
|
|
local tbl = require 'texttable'
|
|
|
|
local compoundbar = require 'compoundbar'
|
|
|
|
local thresholdtext = require 'thresholdtext'
|
|
|
|
local textcolumn = require 'textcolumn'
|
|
|
|
local line = require 'line'
|
|
|
|
local timeseries = require 'timeseries'
|
|
|
|
local scaledtimeseries = require 'scaledtimeseries'
|
2021-07-24 00:32:56 -04:00
|
|
|
local s = require 'style'
|
2021-07-05 23:27:43 -04:00
|
|
|
|
2021-07-11 21:11:38 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- constants
|
|
|
|
|
|
|
|
local FONT = 'Neuropolitical'
|
|
|
|
|
|
|
|
local NORMAL_FONT_SIZE = 13
|
|
|
|
local PLOT_LABEL_FONT_SIZE = 8
|
|
|
|
local TABLE_FONT_SIZE = 11
|
2021-07-05 23:27:43 -04:00
|
|
|
local HEADER_FONT_SIZE = 15
|
2021-07-11 21:11:38 -04:00
|
|
|
|
|
|
|
local HEADER_HEIGHT = 45
|
2021-07-05 23:27:43 -04:00
|
|
|
local HEADER_UNDERLINE_CAP = CAIRO_LINE_CAP_ROUND
|
2021-07-11 21:11:38 -04:00
|
|
|
local HEADER_UNDERLINE_OFFSET = 26
|
2021-07-05 23:27:43 -04:00
|
|
|
local HEADER_UNDERLINE_THICKNESS = 3
|
|
|
|
|
2021-07-11 21:11:38 -04:00
|
|
|
local SEPARATOR_THICKNESS = 1
|
|
|
|
|
|
|
|
local TABLE_BODY_FORMAT = 8
|
|
|
|
local TABLE_VERT_PAD = 15
|
|
|
|
local TABLE_HORZ_PAD = 5
|
|
|
|
local TABLE_HEADER_PAD = 20
|
|
|
|
local TABLE_LINE_THICKNESS = 1
|
|
|
|
|
|
|
|
local PLOT_NUM_POINTS = 90
|
|
|
|
local PLOT_GRID_X_N = 9
|
|
|
|
local PLOT_GRID_Y_N = 4
|
|
|
|
|
|
|
|
local ARC_WIDTH = 2
|
|
|
|
|
2021-07-11 23:10:35 -04:00
|
|
|
local DIAL_THETA0 = 90
|
|
|
|
local DIAL_THETA1 = 360
|
|
|
|
|
2021-07-11 21:11:38 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- helper functions
|
|
|
|
|
2021-07-28 23:36:46 -04:00
|
|
|
local make_font_spec = function(f, s, bold)
|
2021-07-06 00:11:00 -04:00
|
|
|
return {
|
|
|
|
family = f,
|
|
|
|
size = s,
|
|
|
|
weight = bold and CAIRO_FONT_WEIGHT_BOLD or CAIRO_FONT_WEIGHT_NORMAL,
|
|
|
|
slant = CAIRO_FONT_WEIGHT_NORMAL,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-07-28 23:36:46 -04:00
|
|
|
local normal_font_spec = make_font_spec(FONT, NORMAL_FONT_SIZE, false)
|
|
|
|
local label_font_spec = make_font_spec(FONT, PLOT_LABEL_FONT_SIZE, false)
|
2021-07-06 00:11:00 -04:00
|
|
|
|
2021-07-11 23:57:56 -04:00
|
|
|
local _text_row_style = function(x_align, color)
|
2021-07-29 22:37:30 -04:00
|
|
|
return text.style(normal_font_spec, color, x_align, 'center')
|
2021-07-11 23:57:56 -04:00
|
|
|
end
|
2021-07-10 17:13:17 -04:00
|
|
|
|
2021-07-29 22:18:29 -04:00
|
|
|
local left_text_style = _text_row_style('left', theme.INACTIVE_TEXT_FG)
|
|
|
|
local right_text_style = _text_row_style('right', theme.PRIMARY_FG)
|
2021-07-10 17:13:17 -04:00
|
|
|
|
2021-07-29 22:37:30 -04:00
|
|
|
local _bare_text = function(pt, _text, style)
|
2021-07-29 23:04:39 -04:00
|
|
|
return text.make_plain(pt, _text, style)
|
2021-07-10 17:13:17 -04:00
|
|
|
end
|
|
|
|
|
2021-07-29 22:37:30 -04:00
|
|
|
local _left_text = function(pt, _text)
|
|
|
|
return _bare_text(pt, _text, left_text_style)
|
2021-07-10 17:13:17 -04:00
|
|
|
end
|
|
|
|
|
2021-07-29 22:37:30 -04:00
|
|
|
local _right_text = function(pt, _text)
|
|
|
|
return _bare_text(pt, _text, right_text_style)
|
2021-07-10 17:13:17 -04:00
|
|
|
end
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- header
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.make_header = function(x, y, w, _text)
|
2021-07-05 23:27:43 -04:00
|
|
|
local bottom_y = y + HEADER_HEIGHT
|
2021-07-11 21:11:38 -04:00
|
|
|
local underline_y = y + HEADER_UNDERLINE_OFFSET
|
|
|
|
return {
|
2021-07-29 23:04:39 -04:00
|
|
|
text = text.make_plain(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_point(x, y),
|
2021-07-29 22:37:30 -04:00
|
|
|
_text,
|
|
|
|
text.style(
|
2021-07-28 23:36:46 -04:00
|
|
|
make_font_spec(FONT, HEADER_FONT_SIZE, true),
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.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-29 23:04:39 -04:00
|
|
|
underline = line.make(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_point(x, underline_y),
|
|
|
|
F.make_point(x + w, underline_y),
|
2021-07-29 22:37:30 -04:00
|
|
|
line.config(
|
2021-07-24 01:29:02 -04:00
|
|
|
s.line(HEADER_UNDERLINE_THICKNESS, HEADER_UNDERLINE_CAP),
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.HEADER_FG,
|
2021-07-24 01:29:02 -04:00
|
|
|
true
|
2021-07-10 23:07:27 -04:00
|
|
|
)
|
2021-07-08 23:26:38 -04:00
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.draw_header = function(cr, header)
|
2021-07-29 22:37:30 -04:00
|
|
|
text.draw(header.text, cr)
|
|
|
|
line.draw(header.underline, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- label plot
|
|
|
|
|
2021-07-29 22:37:30 -04:00
|
|
|
local default_grid_config = timeseries.grid_config(
|
2021-07-11 21:11:38 -04:00
|
|
|
PLOT_GRID_X_N,
|
|
|
|
PLOT_GRID_Y_N,
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.PLOT_GRID_FG
|
2021-07-11 21:11:38 -04:00
|
|
|
)
|
2021-07-11 14:48:51 -04:00
|
|
|
|
2021-07-29 22:37:30 -04:00
|
|
|
local default_plot_config = timeseries.config(
|
2021-07-11 21:11:38 -04:00
|
|
|
PLOT_NUM_POINTS,
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.PLOT_OUTLINE_FG,
|
|
|
|
theme.PLOT_FILL_BORDER_PRIMARY,
|
|
|
|
theme.PLOT_FILL_BG_PRIMARY,
|
2021-07-28 23:36:46 -04:00
|
|
|
default_grid_config
|
2021-07-11 14:48:51 -04:00
|
|
|
)
|
|
|
|
|
2021-07-29 22:37:30 -04:00
|
|
|
M.percent_label_config = timeseries.label_config(
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.INACTIVE_TEXT_FG,
|
2021-07-28 23:36:46 -04:00
|
|
|
label_font_spec,
|
2021-07-29 22:39:38 -04:00
|
|
|
function(_) return function(z) return util.round_to_string(z * 100)..'%' end end
|
2021-07-11 14:48:51 -04:00
|
|
|
)
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.make_label_timeseries = function(x, y, w, h, label_config, update_freq)
|
|
|
|
return timeseries.make(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_box(x, y, w, h),
|
2021-07-17 16:43:00 -04:00
|
|
|
update_freq,
|
2021-07-28 23:36:46 -04:00
|
|
|
default_plot_config,
|
2021-07-24 01:02:12 -04:00
|
|
|
label_config
|
2021-07-11 14:48:51 -04:00
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- percent plot (label plot with percent signs and some indicator data above it)
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.make_percent_timeseries_formatted = function(x, y, w, h, spacing, label, update_freq, format)
|
2021-07-05 23:27:43 -04:00
|
|
|
return {
|
2021-07-18 23:45:16 -04:00
|
|
|
label = _left_text(F.make_point(x, y), label),
|
2021-07-29 23:04:39 -04:00
|
|
|
value = thresholdtext.make_formatted(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_point(x + w, y),
|
2021-07-09 22:22:49 -04:00
|
|
|
nil,
|
2021-07-28 23:36:46 -04:00
|
|
|
right_text_style,
|
2021-07-13 00:14:04 -04:00
|
|
|
format,
|
2021-07-29 22:37:30 -04:00
|
|
|
thresholdtext.style(theme.CRITICAL_FG, 80)
|
2021-07-09 22:22:49 -04:00
|
|
|
),
|
2021-07-29 23:04:39 -04:00
|
|
|
plot = M.make_label_timeseries(
|
2021-07-11 14:48:51 -04:00
|
|
|
x,
|
|
|
|
y + spacing,
|
|
|
|
w,
|
|
|
|
h,
|
2021-07-24 01:02:12 -04:00
|
|
|
M.percent_label_config,
|
2021-07-17 16:43:00 -04:00
|
|
|
update_freq
|
2021-07-11 14:48:51 -04:00
|
|
|
),
|
2021-07-05 23:27:43 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.make_percent_timeseries = function(x, y, w, h, spacing, label, update_freq)
|
|
|
|
return M.make_percent_timeseries_formatted(x, y, w, h, spacing, label, update_freq, '%s%%')
|
2021-07-13 00:14:04 -04:00
|
|
|
end
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.percent_timeseries_draw_static = function(pp, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
text.draw(pp.label, cr)
|
|
|
|
timeseries.draw_static(pp.plot, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.percent_timeseries_draw_dynamic = function(pp, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
thresholdtext.draw(pp.value, cr)
|
|
|
|
timeseries.draw_dynamic(pp.plot, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
2021-07-13 00:14:04 -04:00
|
|
|
-- TODO this is pretty confusing, nil means -1 which gets fed to any text
|
|
|
|
-- formatting functions
|
2021-07-29 23:04:39 -04:00
|
|
|
M.percent_timeseries_set = function(pp, value)
|
2021-07-13 00:14:04 -04:00
|
|
|
local t = -1
|
|
|
|
local p = 0
|
|
|
|
if value ~= nil then
|
|
|
|
t = math.floor(value)
|
|
|
|
p = value * 0.01
|
|
|
|
end
|
2021-07-29 22:37:30 -04:00
|
|
|
text.set(pp.value, t)
|
|
|
|
timeseries.update(pp.plot, p)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- scaled plot
|
|
|
|
|
2021-07-18 19:18:14 -04:00
|
|
|
-- Generate a format string for labels on y axis of plots. If the max of the
|
|
|
|
-- plot if numerically less than the number of grid lines, this means that
|
|
|
|
-- some number of decimal places are necessary to accurately display the number.
|
|
|
|
-- Note that this for now only works when the number of y grid lines if 4, as
|
|
|
|
-- it gives enough resolution for 1, 0.75, 0.5, and 0.25 but no more
|
|
|
|
M.y_label_format_string = function(plot_max, unit)
|
|
|
|
local num_fmt
|
|
|
|
if plot_max < 2 then
|
|
|
|
num_fmt = '%.2f'
|
|
|
|
elseif plot_max < 4 then
|
|
|
|
num_fmt = '%.1f'
|
|
|
|
else
|
|
|
|
num_fmt = '%.0f'
|
|
|
|
end
|
|
|
|
return string.format('%s %s', num_fmt, unit)
|
|
|
|
end
|
|
|
|
|
|
|
|
M.converted_y_label_format_generator = function(unit)
|
|
|
|
return function(plot_max)
|
2021-07-29 22:39:38 -04:00
|
|
|
local new_prefix, new_max = util.convert_data_val(plot_max)
|
2021-07-18 19:18:14 -04:00
|
|
|
local conversion_factor = plot_max / new_max
|
|
|
|
local fmt = M.y_label_format_string(new_max, new_prefix..unit..'/s')
|
|
|
|
return function(bytes)
|
|
|
|
return string.format(fmt, bytes / conversion_factor)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
local base_2_scale_data = function(m)
|
2021-07-29 22:37:30 -04:00
|
|
|
return scaledtimeseries.scaling_parameters(2, m, 0.9)
|
2021-07-13 22:54:41 -04:00
|
|
|
end
|
2021-07-11 14:48:51 -04:00
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.make_scaled_timeseries = function(x, y, w, h, f, min_domain, update_freq)
|
|
|
|
return scaledtimeseries.make(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_box(x, y, w, h),
|
2021-07-17 16:43:00 -04:00
|
|
|
update_freq,
|
2021-07-28 23:36:46 -04:00
|
|
|
default_plot_config,
|
2021-07-29 23:04:39 -04:00
|
|
|
timeseries.label_config(theme.INACTIVE_TEXT_FG, label_font_spec, f),
|
|
|
|
base_2_scale_data(min_domain)
|
2021-07-11 14:48:51 -04:00
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- scaled plot (with textual data above it)
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.make_labeled_scaled_timeseries = function(x, y, w, h, format_fun, label_fun,
|
|
|
|
spacing, label, min_domain,
|
|
|
|
update_freq)
|
2021-07-05 23:27:43 -04:00
|
|
|
return {
|
2021-07-18 23:45:16 -04:00
|
|
|
label = _left_text(F.make_point(x, y), label),
|
2021-07-29 23:04:39 -04:00
|
|
|
value = text.make_formatted(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_point(x + w, y),
|
2021-07-11 20:26:02 -04:00
|
|
|
0,
|
2021-07-28 23:36:46 -04:00
|
|
|
right_text_style,
|
2021-07-11 20:26:02 -04:00
|
|
|
format_fun
|
2021-07-09 23:53:21 -04:00
|
|
|
),
|
2021-07-29 23:04:39 -04:00
|
|
|
plot = M.make_scaled_timeseries(x, y + spacing, w, h, label_fun, min_domain, update_freq),
|
2021-07-05 23:27:43 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-07-30 22:02:46 -04:00
|
|
|
M.labeled_scale_plot_draw_static = function(asp, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
text.draw(asp.label, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
2021-07-30 22:02:46 -04:00
|
|
|
M.labeled_scale_plot_draw_dynamic = function(asp, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
text.draw(asp.value, cr)
|
|
|
|
scaledtimeseries.draw_dynamic(asp.plot, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
2021-07-30 22:02:46 -04:00
|
|
|
M.labeled_scale_plot_set = function(asp, value)
|
2021-07-29 22:37:30 -04:00
|
|
|
text.set(asp.value, value)
|
|
|
|
scaledtimeseries.update(asp.plot, value)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
2021-07-19 23:58:58 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- rate timecourse plots
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
local make_differential = function(update_frequency)
|
2021-07-19 23:58:58 -04:00
|
|
|
return function(x0, x1)
|
|
|
|
-- mask overflow
|
|
|
|
if x1 > x0 then
|
|
|
|
return (x1 - x0) * update_frequency
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.make_rate_timeseries = function(x, y, w, h, format_fun, label_fun, spacing,
|
2021-07-19 23:58:58 -04:00
|
|
|
label, min_domain, update_freq, init)
|
|
|
|
return {
|
|
|
|
label = _left_text(F.make_point(x, y), label),
|
2021-07-29 23:04:39 -04:00
|
|
|
value = text.make_formatted(
|
2021-07-19 23:58:58 -04:00
|
|
|
F.make_point(x + w, y),
|
|
|
|
0,
|
2021-07-28 23:36:46 -04:00
|
|
|
right_text_style,
|
2021-07-19 23:58:58 -04:00
|
|
|
format_fun
|
|
|
|
),
|
2021-07-29 23:04:39 -04:00
|
|
|
plot = M.make_scaled_timeseries(x, y + spacing, w, h, label_fun, min_domain, update_freq),
|
2021-07-19 23:58:58 -04:00
|
|
|
prev_value = init,
|
2021-07-29 23:04:39 -04:00
|
|
|
derive = make_differential(update_freq),
|
2021-07-19 23:58:58 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-07-26 23:45:54 -04:00
|
|
|
M.update_rate_timeseries = function(obj, value)
|
2021-07-19 23:58:58 -04:00
|
|
|
local rate = obj.derive(obj.prev_value, value)
|
2021-07-29 22:37:30 -04:00
|
|
|
text.set(obj.value, rate)
|
|
|
|
scaledtimeseries.update(obj.plot, rate)
|
2021-07-19 23:58:58 -04:00
|
|
|
obj.prev_value = value
|
|
|
|
end
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- ring
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.make_circle = function(x, y, r)
|
|
|
|
return arc.make(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_semicircle(x, y, r, 0, 360),
|
2021-07-29 22:37:30 -04:00
|
|
|
arc.config(s.line(ARC_WIDTH, CAIRO_LINE_CAP_BUTT), theme.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-29 23:04:39 -04:00
|
|
|
M.make_text_circle = function(x, y, r, fmt, limit)
|
2021-07-05 23:27:43 -04:00
|
|
|
return {
|
2021-07-29 23:04:39 -04:00
|
|
|
ring = M.make_circle(x, y, r),
|
|
|
|
value = thresholdtext.make_formatted(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_point(x, y),
|
2021-07-19 01:37:47 -04:00
|
|
|
0,
|
2021-07-29 23:04:39 -04:00
|
|
|
text.style(normal_font_spec, theme.PRIMARY_FG, 'center', 'center'),
|
2021-07-10 22:50:30 -04:00
|
|
|
fmt,
|
2021-07-29 22:37:30 -04:00
|
|
|
thresholdtext.style(theme.CRITICAL_FG, limit)
|
2021-07-09 22:22:49 -04:00
|
|
|
),
|
2021-07-05 23:27:43 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-07-30 22:02:46 -04:00
|
|
|
M.text_circle_draw_static = function(tr, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
arc.draw(tr.ring, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
2021-07-30 22:02:46 -04:00
|
|
|
M.text_circle_draw_dynamic = function(tr, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
thresholdtext.draw(tr.value, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
2021-07-30 22:02:46 -04:00
|
|
|
M.text_circle_set = function(tr, value)
|
2021-07-29 22:37:30 -04:00
|
|
|
thresholdtext.set(tr.value, value)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2021-07-11 23:02:45 -04:00
|
|
|
-- dial
|
|
|
|
|
2021-07-11 23:57:56 -04:00
|
|
|
local threshold_indicator = function(threshold)
|
2021-07-18 23:45:16 -04:00
|
|
|
return F.threshold_style(
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.INDICATOR_FG_PRIMARY,
|
|
|
|
theme.INDICATOR_FG_CRITICAL,
|
2021-07-11 23:57:56 -04:00
|
|
|
threshold
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-07-30 22:02:46 -04:00
|
|
|
M.make_dial = function(x, y, radius, thickness, threshold, format)
|
2021-07-19 21:14:38 -04:00
|
|
|
return {
|
2021-07-29 23:04:39 -04:00
|
|
|
dial = dial.make(
|
2021-07-19 21:14:38 -04:00
|
|
|
F.make_semicircle(x, y, radius, DIAL_THETA0, DIAL_THETA1),
|
2021-07-29 22:37:30 -04:00
|
|
|
arc.config(s.line(thickness, CAIRO_LINE_CAP_BUTT), theme.INDICATOR_BG),
|
2021-07-19 21:14:38 -04:00
|
|
|
threshold_indicator(threshold)
|
|
|
|
),
|
2021-07-30 22:02:46 -04:00
|
|
|
text_circle = M.make_text_circle(x, y, radius - thickness / 2 - 2, format, threshold),
|
2021-07-19 21:14:38 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-07-26 23:45:54 -04:00
|
|
|
M.dial_set = function(dl, value)
|
2021-07-29 22:37:30 -04:00
|
|
|
dial.set(dl.dial, value)
|
2021-07-30 22:02:46 -04:00
|
|
|
M.text_circle_set(dl.text_circle, value)
|
2021-07-19 21:14:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
M.dial_draw_static = function(dl, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
dial.draw_static(dl.dial, cr)
|
2021-07-30 22:02:46 -04:00
|
|
|
M.text_circle_draw_static(dl.text_circle, cr)
|
2021-07-19 21:14:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
M.dial_draw_dynamic = function(dl, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
dial.draw_dynamic(dl.dial, cr)
|
2021-07-30 22:02:46 -04:00
|
|
|
M.text_circle_draw_dynamic(dl.text_circle, cr)
|
2021-07-11 23:02:45 -04:00
|
|
|
end
|
2021-07-05 23:27:43 -04:00
|
|
|
|
2021-07-11 23:10:35 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- compound dial
|
|
|
|
|
2021-07-30 22:02:46 -04:00
|
|
|
M.make_compound_dial = function(x, y, outer_radius, inner_radius, thickness,
|
2021-07-11 23:10:35 -04:00
|
|
|
threshold, num_dials)
|
2021-07-29 23:04:39 -04:00
|
|
|
return compounddial.make(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_semicircle(x, y, outer_radius, DIAL_THETA0, DIAL_THETA1),
|
2021-07-29 22:37:30 -04:00
|
|
|
arc.config(s.line(thickness, CAIRO_LINE_CAP_BUTT), theme.INDICATOR_BG),
|
2021-07-11 23:57:56 -04:00
|
|
|
threshold_indicator(threshold),
|
2021-07-11 23:10:35 -04:00
|
|
|
inner_radius,
|
|
|
|
num_dials
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-07-11 23:57:56 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- annotated compound bar
|
|
|
|
|
2021-07-30 22:02:46 -04:00
|
|
|
M.make_compound_bar = function(x, y, w, pad, labels, spacing, thickness, threshold)
|
2021-07-11 23:57:56 -04:00
|
|
|
return {
|
2021-07-29 23:04:39 -04:00
|
|
|
labels = textcolumn.make(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_point(x, y),
|
2021-07-11 23:57:56 -04:00
|
|
|
labels,
|
2021-07-28 23:36:46 -04:00
|
|
|
left_text_style,
|
2021-07-11 23:57:56 -04:00
|
|
|
nil,
|
|
|
|
spacing
|
|
|
|
),
|
2021-07-29 23:04:39 -04:00
|
|
|
bars = compoundbar.make(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_point(x + pad, y),
|
2021-07-11 23:57:56 -04:00
|
|
|
w - pad,
|
2021-07-29 22:37:30 -04:00
|
|
|
line.config(
|
2021-07-24 01:29:02 -04:00
|
|
|
s.line(thickness, CAIRO_LINE_CAP_BUTT),
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.INDICATOR_BG,
|
2021-07-22 01:50:15 -04:00
|
|
|
true
|
2021-07-11 23:57:56 -04:00
|
|
|
),
|
|
|
|
threshold_indicator(threshold),
|
|
|
|
spacing,
|
|
|
|
#labels,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
M.compound_bar_draw_static = function(cb, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
textcolumn.draw(cb.labels, cr)
|
|
|
|
compoundbar.draw_static(cb.bars, cr)
|
2021-07-11 23:57:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
M.compound_bar_draw_dynamic = function(cb, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
compoundbar.draw_dynamic(cb.bars, cr)
|
2021-07-11 23:57:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
M.compound_bar_set = function(cb, i, value)
|
2021-07-29 22:37:30 -04:00
|
|
|
compoundbar.set(cb.bars, i, value)
|
2021-07-11 23:57:56 -04:00
|
|
|
end
|
|
|
|
|
2021-07-11 23:02:45 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- separator (eg a horizontal line)
|
2021-07-11 21:11:38 -04:00
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.make_separator = function(x, y, w)
|
|
|
|
return line.make(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_point(x, y),
|
|
|
|
F.make_point(x + w, y),
|
2021-07-29 22:37:30 -04:00
|
|
|
line.config(
|
2021-07-24 01:29:02 -04:00
|
|
|
s.line(SEPARATOR_THICKNESS, CAIRO_LINE_CAP_BUTT),
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.BORDER_FG,
|
2021-07-24 01:29:02 -04:00
|
|
|
true
|
2021-07-10 23:07:27 -04:00
|
|
|
)
|
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-29 23:04:39 -04:00
|
|
|
M.make_text_row = function(x, y, w, label)
|
2021-07-05 23:27:43 -04:00
|
|
|
return {
|
2021-07-18 23:45:16 -04:00
|
|
|
label = _left_text(F.make_point(x, y), label),
|
|
|
|
value = _right_text(F.make_point(x + w, y), nil),
|
2021-07-05 23:27:43 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
M.text_row_draw_static = function(row, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
text.draw(row.label, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
M.text_row_draw_dynamic = function(row, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
text.draw(row.value, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
2021-07-26 23:45:54 -04:00
|
|
|
M.text_row_set = function(row, value)
|
2021-07-29 22:37:30 -04:00
|
|
|
text.set(row.value, value)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- text row with critical indicator
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.make_threshold_text_row = function(x, y, w, label, append_end, limit)
|
2021-07-05 23:27:43 -04:00
|
|
|
return{
|
2021-07-18 23:45:16 -04:00
|
|
|
label = _left_text(F.make_point(x, y), label),
|
2021-07-29 23:04:39 -04:00
|
|
|
value = thresholdtext.make_formatted(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_point(x + w, y),
|
2021-07-09 22:22:49 -04:00
|
|
|
nil,
|
2021-07-29 22:37:30 -04:00
|
|
|
text.style(
|
2021-07-28 23:36:46 -04:00
|
|
|
normal_font_spec,
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.PRIMARY_FG,
|
2021-07-11 18:53:57 -04:00
|
|
|
'right',
|
|
|
|
'center'
|
2021-07-10 17:13:17 -04:00
|
|
|
),
|
2021-07-11 21:11:38 -04:00
|
|
|
append_end,
|
2021-07-29 22:37:30 -04:00
|
|
|
thresholdtext.style(theme.CRITICAL_FG, limit)
|
2021-07-09 22:22:49 -04:00
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-07-30 22:02:46 -04:00
|
|
|
M.threshold_text_row_draw_static = M.text_row_draw_static
|
2021-07-05 23:27:43 -04:00
|
|
|
|
2021-07-30 22:02:46 -04:00
|
|
|
M.threshold_text_row_draw_dynamic = function(row, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
thresholdtext.draw(row.value, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
2021-07-30 22:02:46 -04:00
|
|
|
M.threshold_text_row_set = function(row, value)
|
2021-07-29 22:37:30 -04:00
|
|
|
thresholdtext.set(row.value, value)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- multiple text row separated by spacing
|
|
|
|
|
2021-07-30 22:02:46 -04:00
|
|
|
M.make_text_rows_formatted = function(x, y, w, spacing, labels, format)
|
2021-07-05 23:27:43 -04:00
|
|
|
return {
|
2021-07-29 23:04:39 -04:00
|
|
|
labels = textcolumn.make(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_point(x, y),
|
2021-07-10 17:13:17 -04:00
|
|
|
labels,
|
2021-07-28 23:36:46 -04:00
|
|
|
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
|
|
|
),
|
2021-07-29 23:04:39 -04:00
|
|
|
values = textcolumn.make_n(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_point(x + w, y),
|
2021-07-10 17:13:17 -04:00
|
|
|
#labels,
|
2021-07-30 22:02:46 -04:00
|
|
|
_text_row_style('right', theme.PRIMARY_FG),
|
2021-07-11 23:57:56 -04:00
|
|
|
format,
|
2021-07-19 01:34:03 -04:00
|
|
|
spacing,
|
|
|
|
0
|
2021-07-09 22:22:49 -04:00
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.make_text_rows = function(x, y, w, spacing, labels)
|
|
|
|
return M.make_text_rows_formatted(
|
2021-07-18 14:38:41 -04:00
|
|
|
x,
|
|
|
|
y,
|
|
|
|
w,
|
|
|
|
spacing,
|
|
|
|
labels,
|
2021-07-11 23:57:56 -04:00
|
|
|
nil
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-07-05 23:27:43 -04:00
|
|
|
M.text_rows_draw_static = function(rows, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
textcolumn.draw(rows.labels, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
M.text_rows_draw_dynamic = function(rows, cr)
|
2021-07-29 22:37:30 -04:00
|
|
|
textcolumn.draw(rows.values, cr)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
2021-07-26 23:45:54 -04:00
|
|
|
M.text_rows_set = function(rows, i, value)
|
2021-07-29 22:37:30 -04:00
|
|
|
textcolumn.set(rows.values, i, value)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- table
|
|
|
|
|
2021-07-28 23:36:46 -04:00
|
|
|
local default_table_font_spec = make_font_spec(FONT, TABLE_FONT_SIZE, false)
|
2021-07-11 16:53:25 -04:00
|
|
|
|
2021-07-29 22:37:30 -04:00
|
|
|
local default_table_style = tbl.style(
|
|
|
|
rect.config(
|
2021-07-24 00:32:56 -04:00
|
|
|
s.closed_poly(TABLE_LINE_THICKNESS, CAIRO_LINE_JOIN_MITER),
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.BORDER_FG
|
2021-07-11 16:53:25 -04:00
|
|
|
),
|
2021-07-29 22:37:30 -04:00
|
|
|
line.config(
|
2021-07-24 01:29:02 -04:00
|
|
|
s.line(TABLE_LINE_THICKNESS, CAIRO_LINE_CAP_BUTT),
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.BORDER_FG,
|
2021-07-24 01:29:02 -04:00
|
|
|
true
|
2021-07-11 16:53:25 -04:00
|
|
|
),
|
2021-07-29 22:37:30 -04:00
|
|
|
tbl.header_config(
|
2021-07-28 23:36:46 -04:00
|
|
|
default_table_font_spec,
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.PRIMARY_FG,
|
2021-07-11 21:11:38 -04:00
|
|
|
TABLE_HEADER_PAD
|
2021-07-11 16:53:25 -04:00
|
|
|
),
|
2021-07-29 22:37:30 -04:00
|
|
|
tbl.body_config(
|
2021-07-28 23:36:46 -04:00
|
|
|
default_table_font_spec,
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.INACTIVE_TEXT_FG,
|
2021-07-11 21:11:38 -04:00
|
|
|
TABLE_BODY_FORMAT
|
2021-07-11 16:53:25 -04:00
|
|
|
),
|
2021-07-18 23:45:16 -04:00
|
|
|
F.padding(
|
2021-07-11 21:11:38 -04:00
|
|
|
TABLE_HORZ_PAD,
|
|
|
|
TABLE_VERT_PAD,
|
|
|
|
TABLE_HORZ_PAD,
|
|
|
|
TABLE_VERT_PAD
|
|
|
|
)
|
2021-07-11 16:53:25 -04:00
|
|
|
)
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.make_text_table = function(x, y, w, h, n, labels)
|
|
|
|
return tbl.make(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_box(x, y, w, h),
|
2021-07-11 16:53:25 -04:00
|
|
|
n,
|
|
|
|
labels,
|
2021-07-28 23:36:46 -04:00
|
|
|
default_table_style
|
2021-07-11 16:53:25 -04:00
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- panel
|
|
|
|
|
2021-07-29 23:04:39 -04:00
|
|
|
M.make_panel = function(x, y, w, h, thickness)
|
|
|
|
return fillrect.make(
|
2021-07-18 23:45:16 -04:00
|
|
|
F.make_box(x, y, w, h),
|
2021-07-29 22:37:30 -04:00
|
|
|
rect.config(
|
2021-07-24 00:32:56 -04:00
|
|
|
s.closed_poly(thickness, CAIRO_LINE_JOIN_MITER),
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.BORDER_FG
|
2021-07-24 00:32:56 -04:00
|
|
|
),
|
2021-07-29 22:18:29 -04:00
|
|
|
theme.PANEL_BG
|
2021-07-10 00:22:02 -04:00
|
|
|
)
|
2021-07-05 23:27:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|