git ssb

0+

cel / ssb-activity



Commit c05ef3d7a163d0205ee54329f8a7a0fba176ad0a

Higlight day column

cel committed on 11/17/2019, 11:40:07 PM
Parent: ba8080319c06284e2f8fe71cddad735d3897657a

Files changed

index.htmlchanged
index.htmlView
@@ -139,8 +139,16 @@
139139 }
140140 }
141141 }
142142
143 +function highlightColumn(x, amount) {
144 + for (var y = 0; y < height; y++) {
145 + var p = getPixel(x, y)
146 + if (p[3] === 0) p[0] = p[1] = p[2] = 255
147 + setPixel(x, y, common.interpolate(p, colors.grey, amount))
148 + }
149 +}
150 +
143151 function pointEquals(a, b) {
144152 return a ? b && a[0] === b[0] && a[1] === b[1] : !b
145153 }
146154
@@ -164,17 +172,24 @@
164172
165173 var hoverColor, hoverPoint
166174 var clickedColor, clickedPoint
167175
168-function highlight(color, point) {
169- if (colorEquals(color, hoverColor)) return
170- if (!color) {
176 +function highlight(point) {
177 + if (pointEquals(point, hoverPoint)) return
178 + if (hoverPoint) highlightColumn(hoverPoint[0], 0)
179 + if (point) highlightColumn(point[0], 0.7)
180 + hoverPoint = point
181 +
182 + var color = point && getPixel(point[0], point[1])
183 + if (colorEquals(color, colors.bg)) {
171184 if (hoverColor) replaceColor(hoverColor, hoverColor)
172- ctx.putImageData(imgData, 0, 0)
173185 hoverColor = null
174186 userInfo.style.visibility = 'hidden'
175187 dayInfo.style.visibility = 'hidden'
176- return
188 + } else if (!colorEquals(color, hoverColor)) {
189 + if (hoverColor) replaceColor(hoverColor, hoverColor)
190 + replaceColor(color, colors.highlight)
191 + hoverColor = color
177192 }
178193
179194 if (!point) {
180195 dayInfo.style.visibility = 'hidden'
@@ -183,14 +198,8 @@
183198 dayText.nodeValue = dayStr(point[0])
184199 dayUsersText.nodeValue = countUsersAtInterval(point[0])
185200 }
186201
187- if (colorEquals(color, colors.black)) return
188- if (colorEquals(color, colors.bg)) return
189- if (hoverColor) replaceColor(hoverColor, hoverColor)
190- replaceColor(color, colors.highlight)
191- hoverColor = color
192- ctx.putImageData(imgData, 0, 0)
193202 var id = idsByColor[color]
194203 if (!id) {
195204 userInfo.style.visibility = 'hidden'
196205 } else {
@@ -198,22 +207,17 @@
198207 userLink.href = feedBase + encodeURIComponent(id)
199208 userInfo.style.visibility = 'visible'
200209 }
201210
211 + ctx.putImageData(imgData, 0, 0)
202212 }
203213
204-function clearHoverPoint() {
205- highlight(clickedColor, clickedPoint)
206-}
214 +canvas.addEventListener('mousemove', function (e) {
215 + highlight(getPoint(e))
216 +}, false)
207217
208-function setHoverPoint(point) {
209- if (pointEquals(point, hoverPoint)) return
210- hoverPoint = point
211- var color = getPixel(point[0], point[1])
212- highlight(color, point)
213-}
214-
215-function setClickedPoint(point) {
218 +canvas.addEventListener('mousedown', function (e) {
219 + var point = getPoint(e)
216220 if (pointEquals(point, clickedPoint)) return
217221 var color
218222 if (point) {
219223 color = getPixel(point[0], point[1])
@@ -223,22 +227,13 @@
223227 }
224228 }
225229 clickedPoint = point
226230 clickedColor = color
227- highlight(color, point)
228-}
229-
230-canvas.addEventListener('mousemove', function (e) {
231- setHoverPoint(getPoint(e))
231 + highlight(point)
232232 }, false)
233233
234-
235-canvas.addEventListener('mousedown', function (e) {
236- setClickedPoint(getPoint(e))
237-}, false)
238-
239234 canvas.addEventListener('mouseout', function (e) {
240- clearHoverPoint()
235 + highlight(clickedPoint)
241236 }, false)
242237
243238 </script>
244239 </body>

Built with git-ssb-web