git.s-ol.nu alive / 13f9543
add vis/bar s-ol 1 year, 3 months ago
1 changed file(s) with 41 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 import Constant, Op, T, Input, sig, evt from require 'alv.base'
1
2 bar = Constant.meta
3 meta:
4 name: 'bar'
5 summary: "visualize number as a bar."
6 examples: { '(vis/bar val [[min] max])' }
7 description: "
8 Visualizes `val` as a bar with range `min, max`.
9 `val` can be a `num~` or `num!`, `min` and `max` are optional `num~`.
10 `min` defaults to `0` and `max` defaults to `1`."
11
12 value: class extends Op
13 pattern = (sig.num / evt.num) + -sig.num + -sig.num
14 setup: (inputs, scope) =>
15 { val, min, max } = pattern\match inputs
16 if not max
17 min, max = nil, min
18
19 @out = val.result\fork!
20
21 super
22 val: Input.hot val
23 min: Input.cold min or Constant.num 0
24 max: Input.cold max or Constant.num 1
25
26 tick: =>
27 { :val, :min, :max } = @unwrap_all!
28 delta = max - min
29 @state = (val / delta) - min
30 @out\set val
31
32 vis: =>
33 {
34 type: 'bar'
35 bar: @state
36 }
37
38 {
39 :bar
40 }