ENH make some things local that don't need to be global

This commit is contained in:
Nathan Dwarshuis 2021-07-28 23:36:46 -04:00
parent a1582ce094
commit 12da82ac49
1 changed files with 28 additions and 29 deletions

View File

@ -53,7 +53,7 @@ local DIAL_THETA1 = 360
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- helper functions -- helper functions
M.make_font_spec = function(f, s, bold) local make_font_spec = function(f, s, bold)
return { return {
family = f, family = f,
size = s, size = s,
@ -62,27 +62,26 @@ M.make_font_spec = function(f, s, bold)
} }
end end
M.normal_font_spec = M.make_font_spec(FONT, NORMAL_FONT_SIZE, false) local normal_font_spec = make_font_spec(FONT, NORMAL_FONT_SIZE, false)
M.label_font_spec = M.make_font_spec(FONT, PLOT_LABEL_FONT_SIZE, false) local label_font_spec = make_font_spec(FONT, PLOT_LABEL_FONT_SIZE, false)
local _text_row_style = function(x_align, color) local _text_row_style = function(x_align, color)
return Text.style(M.normal_font_spec, color, x_align, 'center') return Text.style(normal_font_spec, color, x_align, 'center')
end end
M.left_text_style = _text_row_style('left', Theme.INACTIVE_TEXT_FG) local left_text_style = _text_row_style('left', Theme.INACTIVE_TEXT_FG)
local right_text_style = _text_row_style('right', Theme.PRIMARY_FG)
M.right_text_style = _text_row_style('right', Theme.PRIMARY_FG)
local _bare_text = function(pt, text, style) local _bare_text = function(pt, text, style)
return Text.build_plain(pt, text, style) return Text.build_plain(pt, text, style)
end end
local _left_text = function(pt, text) local _left_text = function(pt, text)
return _bare_text(pt, text, M.left_text_style) return _bare_text(pt, text, left_text_style)
end end
local _right_text = function(pt, text) local _right_text = function(pt, text)
return _bare_text(pt, text, M.right_text_style) return _bare_text(pt, text, right_text_style)
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -96,7 +95,7 @@ M.Header = function(x, y, w, text)
F.make_point(x, y), F.make_point(x, y),
text, text,
Text.style( Text.style(
M.make_font_spec(FONT, HEADER_FONT_SIZE, true), make_font_spec(FONT, HEADER_FONT_SIZE, true),
Theme.HEADER_FG, Theme.HEADER_FG,
'left', 'left',
'top' 'top'
@ -123,23 +122,23 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- label plot -- label plot
M.default_grid_config = Timeseries.grid_config( local default_grid_config = Timeseries.grid_config(
PLOT_GRID_X_N, PLOT_GRID_X_N,
PLOT_GRID_Y_N, PLOT_GRID_Y_N,
Theme.PLOT_GRID_FG Theme.PLOT_GRID_FG
) )
M.default_plot_style = Timeseries.config( local default_plot_config = Timeseries.config(
PLOT_NUM_POINTS, PLOT_NUM_POINTS,
Theme.PLOT_OUTLINE_FG, Theme.PLOT_OUTLINE_FG,
Theme.PLOT_FILL_BORDER_PRIMARY, Theme.PLOT_FILL_BORDER_PRIMARY,
Theme.PLOT_FILL_BG_PRIMARY, Theme.PLOT_FILL_BG_PRIMARY,
M.default_grid_config default_grid_config
) )
M.percent_label_config = Timeseries.label_config( M.percent_label_config = Timeseries.label_config(
Theme.INACTIVE_TEXT_FG, Theme.INACTIVE_TEXT_FG,
M.label_font_spec, label_font_spec,
function(_) return function(z) return Util.round_to_string(z * 100)..'%' end end function(_) return function(z) return Util.round_to_string(z * 100)..'%' end end
) )
@ -147,7 +146,7 @@ M.initThemedLabelPlot = function(x, y, w, h, label_config, update_freq)
return Timeseries.build( return Timeseries.build(
F.make_box(x, y, w, h), F.make_box(x, y, w, h),
update_freq, update_freq,
M.default_plot_style, default_plot_config,
label_config label_config
) )
end end
@ -161,7 +160,7 @@ M.initPercentPlot_formatted = function(x, y, w, h, spacing, label, update_freq,
value = ThresholdText.build_formatted( value = ThresholdText.build_formatted(
F.make_point(x + w, y), F.make_point(x + w, y),
nil, nil,
M.right_text_style, right_text_style,
format, format,
ThresholdText.style(Theme.CRITICAL_FG, 80) ThresholdText.style(Theme.CRITICAL_FG, 80)
), ),
@ -242,10 +241,10 @@ M.initThemedScalePlot = function(x, y, w, h, f, min_domain, update_freq)
return ScaledTimeseries.build( return ScaledTimeseries.build(
F.make_box(x, y, w, h), F.make_box(x, y, w, h),
update_freq, update_freq,
M.default_plot_style, default_plot_config,
Timeseries.label_config( Timeseries.label_config(
Theme.INACTIVE_TEXT_FG, Theme.INACTIVE_TEXT_FG,
M.label_font_spec, label_font_spec,
f f
), ),
M.base_2_scale_data(min_domain) M.base_2_scale_data(min_domain)
@ -262,7 +261,7 @@ M.initLabeledScalePlot = function(x, y, w, h, format_fun, label_fun, spacing,
value = Text.build_formatted( value = Text.build_formatted(
F.make_point(x + w, y), F.make_point(x + w, y),
0, 0,
M.right_text_style, right_text_style,
format_fun format_fun
), ),
plot = M.initThemedScalePlot(x, y + spacing, w, h, label_fun, min_domain, update_freq), plot = M.initThemedScalePlot(x, y + spacing, w, h, label_fun, min_domain, update_freq),
@ -313,7 +312,7 @@ M.build_rate_timeseries = function(x, y, w, h, format_fun, label_fun, spacing,
value = Text.build_formatted( value = Text.build_formatted(
F.make_point(x + w, y), F.make_point(x + w, y),
0, 0,
M.right_text_style, right_text_style,
format_fun format_fun
), ),
plot = M.initThemedScalePlot(x, y + spacing, w, h, label_fun, min_domain, update_freq), plot = M.initThemedScalePlot(x, y + spacing, w, h, label_fun, min_domain, update_freq),
@ -362,7 +361,7 @@ M.initTextRing = function(x, y, r, fmt, limit)
F.make_point(x, y), F.make_point(x, y),
0, 0,
Text.style( Text.style(
M.normal_font_spec, normal_font_spec,
Theme.PRIMARY_FG, Theme.PRIMARY_FG,
'center', 'center',
'center' 'center'
@ -444,7 +443,7 @@ M.compound_bar = function(x, y, w, pad, labels, spacing, thickness, threshold)
labels = TextColumn.build( labels = TextColumn.build(
F.make_point(x, y), F.make_point(x, y),
labels, labels,
M.left_text_style, left_text_style,
nil, nil,
spacing spacing
), ),
@ -524,7 +523,7 @@ M.initTextRowCrit = function(x, y, w, label, append_end, limit)
F.make_point(x + w, y), F.make_point(x + w, y),
nil, nil,
Text.style( Text.style(
M.normal_font_spec, normal_font_spec,
Theme.PRIMARY_FG, Theme.PRIMARY_FG,
'right', 'right',
'center' 'center'
@ -566,7 +565,7 @@ M.initTextRows_color = function(x, y, w, spacing, labels, color, format)
labels = TextColumn.build( labels = TextColumn.build(
F.make_point(x, y), F.make_point(x, y),
labels, labels,
M.left_text_style, left_text_style,
nil, nil,
spacing spacing
), ),
@ -619,9 +618,9 @@ end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- table -- table
M.default_table_font_spec = M.make_font_spec(FONT, TABLE_FONT_SIZE, false) local default_table_font_spec = make_font_spec(FONT, TABLE_FONT_SIZE, false)
M.default_table_style = Table.style( local default_table_style = Table.style(
Rect.config( Rect.config(
s.closed_poly(TABLE_LINE_THICKNESS, CAIRO_LINE_JOIN_MITER), s.closed_poly(TABLE_LINE_THICKNESS, CAIRO_LINE_JOIN_MITER),
Theme.BORDER_FG Theme.BORDER_FG
@ -632,12 +631,12 @@ M.default_table_style = Table.style(
true true
), ),
Table.header_config( Table.header_config(
M.default_table_font_spec, default_table_font_spec,
Theme.PRIMARY_FG, Theme.PRIMARY_FG,
TABLE_HEADER_PAD TABLE_HEADER_PAD
), ),
Table.body_config( Table.body_config(
M.default_table_font_spec, default_table_font_spec,
Theme.INACTIVE_TEXT_FG, Theme.INACTIVE_TEXT_FG,
TABLE_BODY_FORMAT TABLE_BODY_FORMAT
), ),
@ -654,7 +653,7 @@ M.initTable = function(x, y, w, h, n, labels)
F.make_box(x, y, w, h), F.make_box(x, y, w, h),
n, n,
labels, labels,
M.default_table_style default_table_style
) )
end end