summaryrefslogtreecommitdiffstats
path: root/examples/lib-dfscq-log/dfscq-log.lua
blob: c54e4f241a3212168558af9217d14ab2ac654e43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
local diaphragm = require("diaphragm")

-- TODO: anyone can use metatable?

local Blocks = diaphragm.Drawable:new()
Blocks.elements = {}
Blocks.unit_width = diaphragm.float()

function Blocks:draw()
	local len = #self.elements
	assert(len >= 1, "Blocks must have at least 1 element")

	local total_grow = 0
	for el in self.elements do
		total_grow = el.grow or 1
	end

	diaphragm.constrain(self.width == self.unit_width * total_grow)

	local param = self.elements[0]

	-- TODO: this would be written with layout.hstack

	local block = diaphragm.shape.Rectangle:new()
	block.fill(param.color)
	diaphragm.constrain(block.left() == self.left())
	diaphragm.constrain(block.top() == self.top())
	diaphragm.constrain(block.bottom() == self.bottom())
	diaphragm.constrain(block.width() == (param.grow or 1) * self.unit_width)

	block.draw()

	local previous_right = block.right()

	for i = 2, len do
		param = self.elements[i]

		block = diaphragm.shape.Rectangle:new()
		block.fill(param.color)

		diaphragm.constrain(block.left() == previous_right)
		diaphragm.constrain(block.top() == self.top())
		diaphragm.constrain(block.bottom() == self.bottom())
		diaphragm.constrain(block.width() == (param.grow or 1) * self.unit_width)

		block.draw()

		previous_right = block.right()
	end
end

-- Library
----------

local function block(color)
	local res = diaphragm.shape.Rectangle:new()
	res.fill(color)
	return res
end

local function blocks_by_len(count, color)
	local res = {}
	for i = 1, count do
		res[i] = block(color)
	end

	-- TODO: rename cons? Misleading
	diaphragm.cons.same_size(res)
	return diaphragm.layout.hstack(res)
end

local function layer(config)
	local name = config.name or ""
	local entries = config.entries or {}

	-- TODO: how to do it without box?
	-- TODO: implement union or combine
	--       probably combine because
	--       union could remove some
	--       strokes
	return diaphragm.layout.box({})
end

-- Parameters
-------------

local blue = diaphragm.color.from_rgb(0.35, 0.35, 1.)

local active_txn_count = 5

-- Log API
----------

local log_api = layer({
	name = "LogAPI",
	entries = {
		{
			name = "activeTxn",
			content = blocks_by_len(active_txn_count, blue),
		},
	},
})

-- Group Commit
---------------

-- local group_commit = nil

-- Disk Log
-----------

-- local disk_log = nil

-- Applier
----------

-- local applier = nil

diaphragm.draw(diaphragm.layout.vstack({
	log_api,
	-- group_commit,
	-- disk_log,
	-- applier,
}))