From 361e0ec3f0033eb4777ef2c65da000fa0f36a6ad Mon Sep 17 00:00:00 2001 From: Minijackson Date: Fri, 20 Jan 2023 17:01:39 +0100 Subject: examples/lib-dfscq-log: update to latest lua changes, set nord theme --- examples/lib-dfscq-log/dfscq-log.lua | 273 ++++++++++++++++++++--------------- 1 file changed, 153 insertions(+), 120 deletions(-) diff --git a/examples/lib-dfscq-log/dfscq-log.lua b/examples/lib-dfscq-log/dfscq-log.lua index b4e2f8e..e95fc05 100644 --- a/examples/lib-dfscq-log/dfscq-log.lua +++ b/examples/lib-dfscq-log/dfscq-log.lua @@ -15,11 +15,42 @@ dia.util.eprint("--------------------") -- local serif_family = "Latin Modern Math" -- local serif_family = "Goudy Bookletter 1911 Normal" local serif_family = "OFL Sorts Mill Goudy" -local mono_family = "Fira Mono" - -local active_color = "#5959ff" -local light_gray = "#cccccc" -local dark_gray = "#7f7f7f" +-- local mono_family = "Fira Mono" +local mono_family = "Iosevka" + +local upstream_colors = { + base04 = "#cccccc", + base06 = "#ffffff", + base0B = "#5959ff", + base0F = "#7f7f7f", +} + +local nord_colors = { + base00 = "#2E3440", + base01 = "#3B4252", + base02 = "#434C5E", + base03 = "#4C566A", + base04 = "#D8DEE9", + base05 = "#E5E9F0", + base06 = "#ECEFF4", + base07 = "#8FBCBB", + base08 = "#BF616A", + base09 = "#D08770", + base0A = "#EBCB8B", + base0B = "#A3BE8C", + base0C = "#88C0D0", + base0D = "#81A1C1", + base0E = "#B48EAD", + base0F = "#5E81AC", +} + +-- local colors = upstream_colors +local colors = nord_colors + +local active_color = colors.base0B +local background = colors.base06 +local light_gray = colors.base04 +local dark_gray = colors.base0F local block_unit_width = 24 local block_height = 36 @@ -144,13 +175,15 @@ local function disk_log_legend(params) result.ticks = {} for _, tick in ipairs(params.ticks) do - table.insert(result.ticks, - dia.straight_path.new({ - points = { - { x = tick, y = result.top }, - { x = tick, y = result.bottom }, - } - })) + table.insert( + result.ticks, + dia.straight_path.new({ + points = { + { x = tick, y = result.top }, + { x = tick, y = result.bottom }, + }, + }) + ) end result.baseline = dia.straight_path.new({ @@ -289,7 +322,7 @@ local function layer(params) .new({ top_left = self.top_left, bottom_right = self.bottom_right, - fill_color = "#fff", + fill_color = background, }) :draw() @@ -307,128 +340,128 @@ local function layer(params) end dia.draw({ - content = { - draw = function() - local title_font = dia.text.font({ family = serif_family, size = 50000 }) - local entry_font = dia.text.font({ family = mono_family, size = 20000 }) - local action_font = dia.text.font({ family = mono_family, height = normal_margin }) - - local function action(name) - return dia.layout.margin_top({ - margin_top = small_margin, - content = dia.text.new({ - content = '' .. name .. "", - font = action_font, - height = normal_margin, - }), - }) - end + draw = function(self) + local title_font = dia.text.font({ family = serif_family, size = 50000 }) + local entry_font = dia.text.font({ family = mono_family, size = 20000 }) + local action_font = dia.text.font({ family = mono_family, height = normal_margin }) + + local function action(name) + return dia.layout.margin_top({ + margin_top = small_margin, + content = dia.text.new({ + content = '' .. name .. "", + font = action_font, + height = normal_margin, + }), + }) + end - local layer_right = dia.float.new() - - local log_layer_entry_left = dia.float.new() - local group_commit_entry_left = dia.float.new() - local disk_log_entry_left = dia.float.new() - - local layers = { - layer({ - name = "LogAPI", - title_font = title_font, - -- top_left = { x = normal_margin, y = normal_margin }, - top_left = { x = normal_margin, y = normal_margin }, - content = dia.layout.margin_right({ - content = layer_entry({ - name = "activeTxn", - font = entry_font, - content = active_txn({ - unit_width = block_unit_width, - left = log_layer_entry_left, - }), + local layer_right = dia.float.new() + + local log_layer_entry_left = dia.float.new() + local group_commit_entry_left = dia.float.new() + local disk_log_entry_left = dia.float.new() + + local layers = { + layer({ + name = "LogAPI", + title_font = title_font, + content = dia.layout.margin_right({ + content = layer_entry({ + name = "activeTxn", + font = entry_font, + content = active_txn({ + unit_width = block_unit_width, + left = log_layer_entry_left, }), }), }), - action("commit"), - layer({ - name = "GroupCommit", - title_font = title_font, - -- top_left = { x = 20, y = 100 + 40 }, - -- right = layer_right, - content = dia.layout.margin_right({ - -- HACK: because I know that "GroupCommit" + "commitedTxns:" - -- takes the most space - margin_right = 0, - content = layer_entry({ - name = "commitedTxns", - font = entry_font, - content = block_list({ - elements = { - fixed_blocks({ count = 2 }), - fixed_blocks({ count = 7 }), - fixed_blocks({ count = 4 }), - active_txn({ unit_width = block_unit_width }), - }, - left = group_commit_entry_left, - }), + }), + action("commit"), + layer({ + name = "GroupCommit", + title_font = title_font, + -- top_left = { x = 20, y = 100 + 40 }, + -- right = layer_right, + content = dia.layout.margin_right({ + -- HACK: because I know that "GroupCommit" + "commitedTxns:" + -- takes the most space + margin_right = 0, + content = layer_entry({ + name = "commitedTxns", + font = entry_font, + content = block_list({ + elements = { + fixed_blocks({ count = 2 }), + fixed_blocks({ count = 7 }), + fixed_blocks({ count = 4 }), + active_txn({ unit_width = block_unit_width }), + }, + left = group_commit_entry_left, }), }), }), - action("flush"), - layer({ - name = "DiskLog", - title_font = title_font, - -- top_left = { x = 20, y = 100 + 40 }, - right = layer_right, - content = dia.layout.margin_right({ - margin_right = 0, - content = layer_entry({ - -- TODO: align to blocks - name = "disk log", - font = entry_font, - content = disk_log({ - elements = { - { - -- TODO: seems to fail solving if using other font size within text, or line returns - label = "header", - elements = { - { count = 1, params = { color = "#000", grow = 11 } }, - }, + }), + action("flush"), + layer({ + name = "DiskLog", + title_font = title_font, + -- top_left = { x = 20, y = 100 + 40 }, + right = layer_right, + content = dia.layout.margin_right({ + margin_right = 0, + content = layer_entry({ + -- TODO: align to blocks + name = "disk log", + font = entry_font, + content = disk_log({ + elements = { + { + -- TODO: seems to fail solving if using other font size within text, or line returns + label = "header", + elements = { + { count = 1, params = { color = "#000", grow = 11 } }, }, - { - label = "data", - elements = { - { count = 2, params = { color = light_gray, grow = 13 + 5 } }, - { count = 13, params = { color = dark_gray } }, - { count = 5, params = { color = active_color } }, - }, + }, + { + label = "data", + elements = { + { count = 2, params = { color = light_gray, grow = 13 + 5 } }, + { count = 13, params = { color = dark_gray } }, + { count = 5, params = { color = active_color } }, }, - { - label = "available", - elements = { - { count = 1, params = { color = "#fff", grow = 13 + 5 } }, - }, + }, + { + label = "available", + elements = { + { count = 1, params = { color = "#fff", grow = 13 + 5 } }, }, }, - left = disk_log_entry_left, - }), + }, + left = disk_log_entry_left, }), }), }), - action("apply"), - layer({ - name = "Applier", - title_font = title_font, - right = layer_right, - }), - } - - dia.layout.vstack({ elements = layers, align = "right" }):draw() + }), + action("apply"), + layer({ + name = "Applier", + title_font = title_font, + right = layer_right, + }), + } + + local figure = dia.layout.vstack({ elements = layers, align = "right" }) + figure:draw() + dia.constraint.inset(figure, self, { margin = normal_margin }) + + local layer_entries_text_right = dia.float.new() + for _, entry_left in pairs({ log_layer_entry_left, group_commit_entry_left, disk_log_entry_left }) do + dia.constrain(layer_entries_text_right:eq(entry_left)) + end + end, - local layer_entries_text_right = dia.float.new() - for _, entry_left in pairs({ log_layer_entry_left, group_commit_entry_left, disk_log_entry_left }) do - dia.constrain(layer_entries_text_right:eq(entry_left)) - end - end, - }, + -- TODO: It currently silently panics if output is not there output = {}, }) -- cgit v1.2.3