# HG changeset patch # User paulo # Date 1474096301 25200 # Node ID a0fdf2cf1d53df877f9385b903f87b2dfc1192d4 # Parent 03c6971ed0236cb8bab07ededaabc6c95f86e740 add "selection" feature to life_calendar; fix minor typos in deer_crash diff -r 03c6971ed023 -r a0fdf2cf1d53 deer_crash/index.html --- a/deer_crash/index.html Sat Jul 23 15:25:44 2016 -0600 +++ b/deer_crash/index.html Sat Sep 17 00:11:41 2016 -0700 @@ -134,7 +134,7 @@ Seeing my CBR500R laid down also made me sad. I got it almost brand new about 4 months before and have put less than 4000 miles on it at that time. Those aren't a lot of miles for a motorcycle, but those were a lot of miles for me in such a short amount of time, because I've been having so much fun riding it. I was expecting the worst. I've heard stories of how fragile the plastic fairings are on a sportsbike, how prone they are to shattering from even the mildest drops of the bike; from this crash, at a decent speed against a decent-sized object on the road, I was imagining the bike to be a total loss.
-I thought of how expensive it was going to be to fix everything that I may just have to buy a new motorcycle to replace it-- but then I'm having doubts whether that would be worth the money if some stupid deer is just going to decide to crash into it again. I was dreading the idea of spending even more money just to get me back to where I was; that of not being to justify the extra expenses; and, finally, of losing the ability to experience the sublime joys of motorcycle riding itself. +I thought of how expensive it was going to be to fix everything that I may just have to buy a new motorcycle to replace it-- but then I'm having doubts whether that would be worth the money if some stupid deer is just going to decide to crash into it again. I was dreading the idea of spending even more money just to get me back to where I was; that of not being able to justify the extra expenses; and, finally, of losing the ability to experience the sublime joys of motorcycle riding itself.
But first, I had to bring the bike back upright right away. It was not exactly because I wanted to inspect the damage I couldn't see yet, or that I had to get it out of the way of other vehicles, or some other purely logical reason like that; it was more of an instinct of somehow preventing more damage to the motorcycle by getting it off the ground and onto its own wheels as soon as possible. This actually makes a lot of sense: it could be leaking fluids, or it could be unstable and shift weight and damage another part if left on the ground. But I wasn't thinking of those at the moment. I just felt as if the bike was an injured animal itself; that it must be helped back to its feet as if it might've felt pain and needed assistance. @@ -158,7 +158,7 @@ A park ranger was there within minutes, asking me if I was okay. Again, I said I felt fine, except for the soreness on my left foot.
-For a while, a new dangerous situation took place. Cars were stopping or slowing down suddenly when they went around that curve and saw the accident scene. Whether they were gawking at the dead deer, gawking at me or bike, asking me if I needed help, or just really not seeing what's going on in front of them until the last second, a half dozen or so cars almost rear-ended each other and almost caused another crash. +For a while, a new dangerous situation took place. Cars were stopping or slowing down suddenly when they went around that curve and saw the accident scene. Whether they were gawking at the dead deer, gawking at me or the bike, asking me if I needed help, or just really not seeing what's going on in front of them until the last second, a half dozen or so cars almost rear-ended each other and almost caused another crash.
Throughout this time, I was pacing around to inspect the damage to me and the bike. Amazingly, we were both almost completely fine. @@ -191,7 +191,7 @@
-(Damage to leather jacket. The decorative piping is torn up, but the leather on the sleeve itself does not rip. I also only took a picture of the left sleeve, because I thought that's the side I fell and slid on and thought the damage is limited there, but later on I'd notice similar scuffs on the right sleeve. Weird.) +(Damage to leather jacket. The decorative piping is torn up, but the leather on the sleeve itself did not rip. I also only took a picture of the left sleeve, because I thought that's the side I fell and slid on and thought the damage is limited there, but later on I'd notice similar scuffs on the right sleeve. Weird.)
diff -r 03c6971ed023 -r a0fdf2cf1d53 life_calendar/index.html --- a/life_calendar/index.html Sat Jul 23 15:25:44 2016 -0600 +++ b/life_calendar/index.html Sat Sep 17 00:11:41 2016 -0700 @@ -79,6 +79,12 @@ margin: 1px; } + div#tooltip h3 { + color: #333333; + font-size: 0.8em; + margin: 2px; + } + td { border-color: #FFFFFF; } @@ -133,6 +139,10 @@ var remainderWeeks; var restOfYearWeeks; + var selecting = false; + var start_wyc = null; + var end_wyc = null; + function validateBirthday(birthday) { var birthdayPattern = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/; return birthdayPattern.test( $("#birthday").val()); @@ -192,14 +202,18 @@ break; } } - var cal = getCalendar(birthdayDate, week, year); return { week: week, year: year, - cal: cal, + cal: getCalendar(birthdayDate, week, year), + weeks: nWeeks*year + week, } } + function inSpan(x, s, e) { + return x >= s && x <= e; + } + function loop(x, f) { for (var i = 0; i < x; f(i++)); } @@ -212,6 +226,41 @@ return ret; } + function setStyle(e) { + var styles = []; + + if (e["_fill_color"] != undefined) { + styles.push("background-color: " + e._fill_color); + } + if (e["_border_color"] != undefined) { + styles.push("border-color: " + e._border_color); + } + + if (styles.length == 0) { + e.setAttribute("style", undefined); + } else { + e.setAttribute("style", styles.join('; ')); + } + } + + function highlightDistance(e0, e1_wyc, e2_wyc) { + var calParent = e0.parentNode.parentNode; + var min_wyc = (e1_wyc.weeks <= e2_wyc.weeks) ? e1_wyc : e2_wyc; + var max_wyc = (e2_wyc == min_wyc) ? e1_wyc : e2_wyc; + for (var year = 0; year < lifespan; year++) { + for (var week = 0; week < nWeeks; week++) { + w = nWeeks*year + week; + e = calParent.childNodes[year].childNodes[week] + if (inSpan(w, min_wyc.weeks, max_wyc.weeks)) { + e._border_color = "black"; + } else { + e._border_color = undefined; + } + setStyle(e); + } + } + } + function cycleColors(e) { var colors = [ undefined, @@ -225,11 +274,7 @@ var i = 0; for (; i < colors.length, colors[i] != e._fill_color; i++); e._fill_color = colors[(i + 1) % colors.length]; - if (e._fill_color != undefined) { - e.setAttribute("style", "background-color: " + e._fill_color); - } else { - e.setAttribute("style", undefined); - } + setStyle(e); } function _createElement(tagName, className) { @@ -262,10 +307,40 @@ var calYear = wyc.cal.getFullYear(); var calMonth = wyc.cal.getMonth() + 1; var calDay = wyc.cal.getDate(); - createTooltip(evt, calYear + '-' + calMonth + '-' + calDay, "(Week: " + wyc.week + ", Year: " + wyc.year + ")"); + var title = calYear + '-' + calMonth + '-' + calDay; + var text = "(Week: " + wyc.week + ", Year: " + wyc.year + ")"; + var subtext = null; + if (selecting) { + end_wyc = wyc; + highlightDistance(e, start_wyc, end_wyc); + } + if (start_wyc && end_wyc) { + var min_wyc = (start_wyc.weeks <= end_wyc.weeks) ? start_wyc : end_wyc; + var max_wyc = (end_wyc == min_wyc) ? start_wyc : end_wyc; + if (inSpan(wyc.weeks, min_wyc.weeks, max_wyc.weeks)) { + var sel_weeks = max_wyc.weeks - min_wyc.weeks; + var sel_years = sel_weeks/nWeeks; + subtext = "[Selected: weeks: " + sel_weeks + " years: " + sel_years.toFixed(2) + "]"; + } + } + createTooltip(evt, title, text, subtext); }); e.addEventListener("click", function() { - cycleColors(e); + var wyc = getWeekYearCal(e, i); + highlightDistance(e, wyc, wyc); + if (start_wyc && end_wyc) { + start_wyc = null; + end_wyc = null; + } else { + cycleColors(e); + } + }); + e.addEventListener("mousedown", function() { + selecting = true; + start_wyc = getWeekYearCal(e, i); + }); + e.addEventListener("mouseup", function() { + selecting = false; }); } diff -r 03c6971ed023 -r a0fdf2cf1d53 life_calendar/tooltip.js --- a/life_calendar/tooltip.js Sat Jul 23 15:25:44 2016 -0600 +++ b/life_calendar/tooltip.js Sat Sep 17 00:11:41 2016 -0700 @@ -9,7 +9,7 @@ return document.querySelector("#" + _tt_options.tooltipId); } -function adjustTooltip(evt, tooltipElm, title, text) { +function adjustTooltip(evt, tooltipElm, title, text, subtext) { var offset = _tt_options.offsetDefault; var scrollY = window.scrollY || window.pageYOffset; var scrollX = window.scrollX || window.pageXOffset; @@ -22,37 +22,41 @@ tooltipElm.style.top = tooltipTop + "px"; tooltipElm.style.left = tooltipLeft + "px"; - setTooltipText(tooltipElm, title, text); + setTooltipText(tooltipElm, title, text, subtext); } function removeTooltip() { document.querySelector("body").removeChild(getTooltipElm()); } -function createTooltip(evt, title, text) { +function createTooltip(evt, title, text, subtext) { var tooltipElm = getTooltipElm(); if (!tooltipElm) { tooltipElm = document.createElement("div"); tooltipElm.appendChild(document.createElement("h1")); tooltipElm.appendChild(document.createElement("h2")); + tooltipElm.appendChild(document.createElement("h3")); - tooltipElm.style.position = "absolute"; - tooltipElm.setAttribute("id", _tt_options.tooltipId); + tooltipElm.style.position = "absolute"; tooltipElm.setAttribute("id", _tt_options.tooltipId); document.querySelector("body").appendChild(tooltipElm); } - adjustTooltip(evt, tooltipElm, title, text); + adjustTooltip(evt, tooltipElm, title, text, subtext); } -function setTooltipText(tooltipElm, title, text) { +function setTooltipText(tooltipElm, title, text, subtext) { var eTitle = tooltipElm.children[0]; var eText = tooltipElm.children[1]; + var eSubText = tooltipElm.children[2]; if (eTitle && title) { eTitle.textContent = title; } if (eText && text) { eText.textContent = text; } + if (eSubText) { + eSubText.textContent = subtext; + } }