-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmonitor.html
176 lines (124 loc) · 4.05 KB
/
monitor.html
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!doctype html>
<html>
<head>
<title>Underview monitor</title>
<script src="underview.js"></script>
</head>
<body>
<canvas id="canvas_hist" width="600" height="800"></canvas>
<br />
<!-- <canvas id="canvas_tree" width="1000" height="200"></canvas> -->
<script>
// http://jackschaedler.github.io/goya/
// popup = window.open('http://127.0.0.1/~dann/underview/monitor.html')
// copy flattener!
// fun = function(x) {if(!x) return; popup.postMessage(flatten(x), "*")}
// in main:
// fun(hi); return xi=this,zi=b.__om_app_state,
// or (hi,ii,ji)
var ctx_hist = document.getElementById('canvas_hist').getContext('2d')
// var ctx_tree = document.getElementById('canvas_tree').getContext('2d')
var pipeline = ['valuation', 'colorize', 'shift-columns', 'draw-columns']
var renderer = UV.build_renderer(pipeline, ctx_hist)
window.addEventListener("message", receiveMessage, false);
function receiveMessage(event) {
var data = event.data
renderer.draw(data)
// draw_tree(data, ctx_tree, 0, 0)
}
////////////////////////
XSIZE=3
YSIZE=1
function draw_tree(data, context, x, y) {
x = x || 0
y = y || 0
var todo = [data, NaN]
var longest = Object.keys(data).length
var maxes = [longest]
var generation = 0
var min_y = y
while(todo.length) {
var data = todo.shift() // opt
if(data !== data) {
if(!todo.length) return true
maxes.push(longest)
x += XSIZE * maxes[generation] + XSIZE
longest = 0
y = min_y
generation++
todo.push(NaN)
}
if(!data || typeof data != 'object') continue
draw_list(data, context, x, y)
y += YSIZE * 1
// var count = 0
var keys = Object.keys(data)
// var len = keys.length
keys.forEach(function(key) {
if(data[key] && typeof data[key] == 'object') {
todo.push(data[key])
longest = Math.max(longest, Object.keys(data[key]).length)
// count++
// draw_tree(data[key], context, x + len, y + count*15)
}
})
}
}
function draw_list(data, context, x, y) {
var index = 0
Object.keys(data).forEach(function(key) {
var item = data[key]
var hue = 0, sat = '0%', lit = '0%'
if(item && isFinite(item)) {
hue = item || 0
sat = '60%'
lit = '60%'
}
if(typeof item == 'string') {
lit = '80%'
sat = '100%'
hue = 100
}
if(item && typeof item == 'object') {
lit = '80%'
sat = '100%'
hue = 200
}
var c = 'hsl(' + hue + ', ' + sat + ', ' + lit + ')'
context.fillStyle = c
context.fillRect(+x+index*XSIZE, y, XSIZE, YSIZE);
index++
})
}
/*
- spacing for subsections
- try for linked lists
- find a vlist implementation
- linked canvases: to data display, from compact timeline
sliders for colors:
- hot pink for pointers
- neon blue for nulls
- ghostly orange for strings
times = function(n) {if(n < 1) return false; setImmediate(function() {go(); times(n-1)})}
go = function() {var n = rand(350000) + 1
data = data.set('a'+n, n)
ctx.clearRect(0,0,900,900); draw_tree(data, ctx, 20, 0);}
data = new Immutable.Map()
///////
go = function() {var n = rand(350000) + 1
data = mori.assoc(data, 'a'+n, n)
ctx.clearRect(0,0,900,900); draw_tree(data, ctx, 20, 0);}
data = mori.hash_map()
///////
data1 = mori.hash_map()
data2 = new Immutable.Map()
go = function() {var n = rand(350000) + 1
data2 = data2.set('a'+n, n)
data1 = mori.assoc(data1, 'a'+n, n)
ctx.clearRect(0,0,900,900)
draw_tree(data1, ctx, 0, 0)
draw_tree(data2, ctx, 450, 0)}
*/
</script>
</body>
</html>