git ssb

0+

cel / ssb-activity



Commit ba8080319c06284e2f8fe71cddad735d3897657a

Show date and users count for day

cel committed on 11/17/2019, 11:12:20 PM
Parent: f97d1056daa9154ab13a44d173700ec4f3e94d1a

Files changed

common.jschanged
index.htmlchanged
run.jschanged
common.jsView
@@ -1,6 +1,8 @@
11 var common = typeof window !== 'undefined' ? window : exports
22
3 +common.startTime = new Date('2015-08-05').getTime()
4 +
35 var colors20 = [
46 [255, 106, 152], [255, 98, 188], [250, 98, 219], [231, 107, 243],
57 [199, 124, 255], [149, 144, 255], [53, 162, 255], [0, 176, 246],
68 [0, 186, 224], [0, 191, 196], [0, 193, 163], [0, 191, 125],
index.htmlView
@@ -11,8 +11,13 @@
1111 <h2>Daily active users</h2>
1212 <img id=graph src=day.png alt="Graph of daily active feeds">
1313 </div>
1414
15 +<div id="day-info" style="float:right; text-align:right; visibility:hidden">
16 + <div><ins id="day"> </ins></div>
17 + <div><ins id="day-users"> </ins> users</div>
18 +</div>
19 +
1520 <div id="user-info" style="visibility:hidden">
1621 <div>User: <a id="user-link"><code id="user-id"> </code></a></div>
1722 </div>
1823
@@ -24,8 +29,11 @@
2429 var width, height
2530 var userInfo = document.getElementById('user-info')
2631 var userLink = document.getElementById('user-link')
2732 var userIdText = document.getElementById('user-id').firstChild
33 +var dayInfo = document.getElementById('day-info')
34 +var dayText = document.getElementById('day').firstChild
35 +var dayUsersText = document.getElementById('day-users').firstChild
2836
2937 var colors = {
3038 yellow: [255, 255, 0, 255],
3139 red: [255, 0, 0, 255],
@@ -135,8 +143,26 @@
135143 function pointEquals(a, b) {
136144 return a ? b && a[0] === b[0] && a[1] === b[1] : !b
137145 }
138146
147 +function dayStr(day) {
148 + return isNaN(day) ? '' :
149 + new Date(common.startTime + day * 86400000).toDateString()
150 +}
151 +
152 +var usersAtInterval = {}
153 +function countUsersAtInterval(x) {
154 + var count = usersAtInterval[x]
155 + if (typeof count !== 'undefined') return count
156 + count = 0
157 + for (var y = height-1; y > 0; y--) {
158 + var color = getPixel(x, y)
159 + if (colorEquals(color, colors.bg)) break
160 + count++
161 + }
162 + return usersAtInterval[x] = count
163 +}
164 +
139165 var hoverColor, hoverPoint
140166 var clickedColor, clickedPoint
141167
142168 function highlight(color, point) {
@@ -145,10 +171,20 @@
145171 if (hoverColor) replaceColor(hoverColor, hoverColor)
146172 ctx.putImageData(imgData, 0, 0)
147173 hoverColor = null
148174 userInfo.style.visibility = 'hidden'
175 + dayInfo.style.visibility = 'hidden'
149176 return
150177 }
178 +
179 + if (!point) {
180 + dayInfo.style.visibility = 'hidden'
181 + } else {
182 + dayInfo.style.visibility = 'visible'
183 + dayText.nodeValue = dayStr(point[0])
184 + dayUsersText.nodeValue = countUsersAtInterval(point[0])
185 + }
186 +
151187 if (colorEquals(color, colors.black)) return
152188 if (colorEquals(color, colors.bg)) return
153189 if (hoverColor) replaceColor(hoverColor, hoverColor)
154190 replaceColor(color, colors.highlight)
@@ -156,13 +192,14 @@
156192 ctx.putImageData(imgData, 0, 0)
157193 var id = idsByColor[color]
158194 if (!id) {
159195 userInfo.style.visibility = 'hidden'
160- return
196 + } else {
197 + userIdText.nodeValue = id
198 + userLink.href = feedBase + encodeURIComponent(id)
199 + userInfo.style.visibility = 'visible'
161200 }
162- userIdText.nodeValue = id
163- userLink.href = feedBase + encodeURIComponent(id)
164- userInfo.style.visibility = 'visible'
201 +
165202 }
166203
167204 function clearHoverPoint() {
168205 highlight(clickedColor, clickedPoint)
run.jsView
@@ -5,9 +5,9 @@
55 var Split = require('pull-split')
66 var PNG = require('pngjs').PNG
77 var common = require('./common')
88
9-var start = new Date('2015-08-05').getTime()
9 +var start = common.startTime
1010 var startDay = Math.floor(start / 86400000)
1111 var startWeek = Math.floor(start / 86400000 / 7)
1212 var startMonth = Math.floor(start / 86400000 / 30.43666666666666666666)
1313 var startT

Built with git-ssb-web