diff options
author | Minijackson <minijackson@riseup.net> | 2023-01-20 17:01:39 +0100 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2023-01-20 17:01:39 +0100 |
commit | 361e0ec3f0033eb4777ef2c65da000fa0f36a6ad (patch) | |
tree | 68ca5a10bbd7ac2f1847f232c59758bdcd9fe32a /examples/lib-dfscq-log/dfscq-log.lua | |
parent | c80cd630f48550b32c6891c5aa473f615f521d47 (diff) | |
download | diaphragm-361e0ec3f0033eb4777ef2c65da000fa0f36a6ad.tar.gz diaphragm-361e0ec3f0033eb4777ef2c65da000fa0f36a6ad.zip |
examples/lib-dfscq-log: update to latest lua changes, set nord theme
Diffstat (limited to 'examples/lib-dfscq-log/dfscq-log.lua')
-rw-r--r-- | examples/lib-dfscq-log/dfscq-log.lua | 273 |
1 files 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("--------------------") | |||
15 | -- local serif_family = "Latin Modern Math" | 15 | -- local serif_family = "Latin Modern Math" |
16 | -- local serif_family = "Goudy Bookletter 1911 Normal" | 16 | -- local serif_family = "Goudy Bookletter 1911 Normal" |
17 | local serif_family = "OFL Sorts Mill Goudy" | 17 | local serif_family = "OFL Sorts Mill Goudy" |
18 | local mono_family = "Fira Mono" | 18 | -- local mono_family = "Fira Mono" |
19 | 19 | local mono_family = "Iosevka" | |
20 | local active_color = "#5959ff" | 20 | |
21 | local light_gray = "#cccccc" | 21 | local upstream_colors = { |
22 | local dark_gray = "#7f7f7f" | 22 | base04 = "#cccccc", |
23 | base06 = "#ffffff", | ||
24 | base0B = "#5959ff", | ||
25 | base0F = "#7f7f7f", | ||
26 | } | ||
27 | |||
28 | local nord_colors = { | ||
29 | base00 = "#2E3440", | ||
30 | base01 = "#3B4252", | ||
31 | base02 = "#434C5E", | ||
32 | base03 = "#4C566A", | ||
33 | base04 = "#D8DEE9", | ||
34 | base05 = "#E5E9F0", | ||
35 | base06 = "#ECEFF4", | ||
36 | base07 = "#8FBCBB", | ||
37 | base08 = "#BF616A", | ||
38 | base09 = "#D08770", | ||
39 | base0A = "#EBCB8B", | ||
40 | base0B = "#A3BE8C", | ||
41 | base0C = "#88C0D0", | ||
42 | base0D = "#81A1C1", | ||
43 | base0E = "#B48EAD", | ||
44 | base0F = "#5E81AC", | ||
45 | } | ||
46 | |||
47 | -- local colors = upstream_colors | ||
48 | local colors = nord_colors | ||
49 | |||
50 | local active_color = colors.base0B | ||
51 | local background = colors.base06 | ||
52 | local light_gray = colors.base04 | ||
53 | local dark_gray = colors.base0F | ||
23 | 54 | ||
24 | local block_unit_width = 24 | 55 | local block_unit_width = 24 |
25 | local block_height = 36 | 56 | local block_height = 36 |
@@ -144,13 +175,15 @@ local function disk_log_legend(params) | |||
144 | 175 | ||
145 | result.ticks = {} | 176 | result.ticks = {} |
146 | for _, tick in ipairs(params.ticks) do | 177 | for _, tick in ipairs(params.ticks) do |
147 | table.insert(result.ticks, | 178 | table.insert( |
148 | dia.straight_path.new({ | 179 | result.ticks, |
149 | points = { | 180 | dia.straight_path.new({ |
150 | { x = tick, y = result.top }, | 181 | points = { |
151 | { x = tick, y = result.bottom }, | 182 | { x = tick, y = result.top }, |
152 | } | 183 | { x = tick, y = result.bottom }, |
153 | })) | 184 | }, |
185 | }) | ||
186 | ) | ||
154 | end | 187 | end |
155 | 188 | ||
156 | result.baseline = dia.straight_path.new({ | 189 | result.baseline = dia.straight_path.new({ |
@@ -289,7 +322,7 @@ local function layer(params) | |||
289 | .new({ | 322 | .new({ |
290 | top_left = self.top_left, | 323 | top_left = self.top_left, |
291 | bottom_right = self.bottom_right, | 324 | bottom_right = self.bottom_right, |
292 | fill_color = "#fff", | 325 | fill_color = background, |
293 | }) | 326 | }) |
294 | :draw() | 327 | :draw() |
295 | 328 | ||
@@ -307,128 +340,128 @@ local function layer(params) | |||
307 | end | 340 | end |
308 | 341 | ||
309 | dia.draw({ | 342 | dia.draw({ |
310 | content = { | 343 | draw = function(self) |
311 | draw = function() | 344 | local title_font = dia.text.font({ family = serif_family, size = 50000 }) |
312 | local title_font = dia.text.font({ family = serif_family, size = 50000 }) | 345 | local entry_font = dia.text.font({ family = mono_family, size = 20000 }) |
313 | local entry_font = dia.text.font({ family = mono_family, size = 20000 }) | 346 | local action_font = dia.text.font({ family = mono_family, height = normal_margin }) |
314 | local action_font = dia.text.font({ family = mono_family, height = normal_margin }) | 347 | |
315 | 348 | local function action(name) | |
316 | local function action(name) | 349 | return dia.layout.margin_top({ |
317 | return dia.layout.margin_top({ | 350 | margin_top = small_margin, |
318 | margin_top = small_margin, | 351 | content = dia.text.new({ |
319 | content = dia.text.new({ | 352 | content = '<span foreground="' .. active_color .. '">' .. name .. "</span>", |
320 | content = '<span foreground="' .. active_color .. '">' .. name .. "</span>", | 353 | font = action_font, |
321 | font = action_font, | 354 | height = normal_margin, |
322 | height = normal_margin, | 355 | }), |
323 | }), | 356 | }) |
324 | }) | 357 | end |
325 | end | ||
326 | 358 | ||
327 | local layer_right = dia.float.new() | 359 | local layer_right = dia.float.new() |
328 | 360 | ||
329 | local log_layer_entry_left = dia.float.new() | 361 | local log_layer_entry_left = dia.float.new() |
330 | local group_commit_entry_left = dia.float.new() | 362 | local group_commit_entry_left = dia.float.new() |
331 | local disk_log_entry_left = dia.float.new() | 363 | local disk_log_entry_left = dia.float.new() |
332 | 364 | ||
333 | local layers = { | 365 | local layers = { |
334 | layer({ | 366 | layer({ |
335 | name = "LogAPI", | 367 | name = "LogAPI", |
336 | title_font = title_font, | 368 | title_font = title_font, |
337 | -- top_left = { x = normal_margin, y = normal_margin }, | 369 | content = dia.layout.margin_right({ |
338 | top_left = { x = normal_margin, y = normal_margin }, | 370 | content = layer_entry({ |
339 | content = dia.layout.margin_right({ | 371 | name = "activeTxn", |
340 | content = layer_entry({ | 372 | font = entry_font, |
341 | name = "activeTxn", | 373 | content = active_txn({ |
342 | font = entry_font, | 374 | unit_width = block_unit_width, |
343 | content = active_txn({ | 375 | left = log_layer_entry_left, |
344 | unit_width = block_unit_width, | ||
345 | left = log_layer_entry_left, | ||
346 | }), | ||
347 | }), | 376 | }), |
348 | }), | 377 | }), |
349 | }), | 378 | }), |
350 | action("commit"), | 379 | }), |
351 | layer({ | 380 | action("commit"), |
352 | name = "GroupCommit", | 381 | layer({ |
353 | title_font = title_font, | 382 | name = "GroupCommit", |
354 | -- top_left = { x = 20, y = 100 + 40 }, | 383 | title_font = title_font, |
355 | -- right = layer_right, | 384 | -- top_left = { x = 20, y = 100 + 40 }, |
356 | content = dia.layout.margin_right({ | 385 | -- right = layer_right, |
357 | -- HACK: because I know that "GroupCommit" + "commitedTxns:" | 386 | content = dia.layout.margin_right({ |
358 | -- takes the most space | 387 | -- HACK: because I know that "GroupCommit" + "commitedTxns:" |
359 | margin_right = 0, | 388 | -- takes the most space |
360 | content = layer_entry({ | 389 | margin_right = 0, |
361 | name = "commitedTxns", | 390 | content = layer_entry({ |
362 | font = entry_font, | 391 | name = "commitedTxns", |
363 | content = block_list({ | 392 | font = entry_font, |
364 | elements = { | 393 | content = block_list({ |
365 | fixed_blocks({ count = 2 }), | 394 | elements = { |
366 | fixed_blocks({ count = 7 }), | 395 | fixed_blocks({ count = 2 }), |
367 | fixed_blocks({ count = 4 }), | 396 | fixed_blocks({ count = 7 }), |
368 | active_txn({ unit_width = block_unit_width }), | 397 | fixed_blocks({ count = 4 }), |
369 | }, | 398 | active_txn({ unit_width = block_unit_width }), |
370 | left = group_commit_entry_left, | 399 | }, |
371 | }), | 400 | left = group_commit_entry_left, |
372 | }), | 401 | }), |
373 | }), | 402 | }), |
374 | }), | 403 | }), |
375 | action("flush"), | 404 | }), |
376 | layer({ | 405 | action("flush"), |
377 | name = "DiskLog", | 406 | layer({ |
378 | title_font = title_font, | 407 | name = "DiskLog", |
379 | -- top_left = { x = 20, y = 100 + 40 }, | 408 | title_font = title_font, |
380 | right = layer_right, | 409 | -- top_left = { x = 20, y = 100 + 40 }, |
381 | content = dia.layout.margin_right({ | 410 | right = layer_right, |
382 | margin_right = 0, | 411 | content = dia.layout.margin_right({ |
383 | content = layer_entry({ | 412 | margin_right = 0, |
384 | -- TODO: align to blocks | 413 | content = layer_entry({ |
385 | name = "disk log", | 414 | -- TODO: align to blocks |
386 | font = entry_font, | 415 | name = "disk log", |
387 | content = disk_log({ | 416 | font = entry_font, |
388 | elements = { | 417 | content = disk_log({ |
389 | { | 418 | elements = { |
390 | -- TODO: seems to fail solving if using other font size within text, or line returns | 419 | { |
391 | label = "header", | 420 | -- TODO: seems to fail solving if using other font size within text, or line returns |
392 | elements = { | 421 | label = "header", |
393 | { count = 1, params = { color = "#000", grow = 11 } }, | 422 | elements = { |
394 | }, | 423 | { count = 1, params = { color = "#000", grow = 11 } }, |
395 | }, | 424 | }, |
396 | { | 425 | }, |
397 | label = "data", | 426 | { |
398 | elements = { | 427 | label = "data", |
399 | { count = 2, params = { color = light_gray, grow = 13 + 5 } }, | 428 | elements = { |
400 | { count = 13, params = { color = dark_gray } }, | 429 | { count = 2, params = { color = light_gray, grow = 13 + 5 } }, |
401 | { count = 5, params = { color = active_color } }, | 430 | { count = 13, params = { color = dark_gray } }, |
402 | }, | 431 | { count = 5, params = { color = active_color } }, |
403 | }, | 432 | }, |
404 | { | 433 | }, |
405 | label = "available", | 434 | { |
406 | elements = { | 435 | label = "available", |
407 | { count = 1, params = { color = "#fff", grow = 13 + 5 } }, | 436 | elements = { |
408 | }, | 437 | { count = 1, params = { color = "#fff", grow = 13 + 5 } }, |
409 | }, | 438 | }, |
410 | }, | 439 | }, |
411 | left = disk_log_entry_left, | 440 | }, |
412 | }), | 441 | left = disk_log_entry_left, |
413 | }), | 442 | }), |
414 | }), | 443 | }), |
415 | }), | 444 | }), |
416 | action("apply"), | 445 | }), |
417 | layer({ | 446 | action("apply"), |
418 | name = "Applier", | 447 | layer({ |
419 | title_font = title_font, | 448 | name = "Applier", |
420 | right = layer_right, | 449 | title_font = title_font, |
421 | }), | 450 | right = layer_right, |
422 | } | 451 | }), |
423 | 452 | } | |
424 | dia.layout.vstack({ elements = layers, align = "right" }):draw() | 453 | |
454 | local figure = dia.layout.vstack({ elements = layers, align = "right" }) | ||
455 | figure:draw() | ||
456 | dia.constraint.inset(figure, self, { margin = normal_margin }) | ||
457 | |||
458 | local layer_entries_text_right = dia.float.new() | ||
459 | for _, entry_left in pairs({ log_layer_entry_left, group_commit_entry_left, disk_log_entry_left }) do | ||
460 | dia.constrain(layer_entries_text_right:eq(entry_left)) | ||
461 | end | ||
462 | end, | ||
425 | 463 | ||
426 | local layer_entries_text_right = dia.float.new() | 464 | -- TODO: It currently silently panics if output is not there |
427 | for _, entry_left in pairs({ log_layer_entry_left, group_commit_entry_left, disk_log_entry_left }) do | ||
428 | dia.constrain(layer_entries_text_right:eq(entry_left)) | ||
429 | end | ||
430 | end, | ||
431 | }, | ||
432 | output = {}, | 465 | output = {}, |
433 | }) | 466 | }) |
434 | 467 | ||