From 2d37193aecb41093b0b2685e629a34430c649283 Mon Sep 17 00:00:00 2001 From: Nathan Bergey Date: Sun, 20 Jan 2019 22:46:35 -0500 Subject: [PATCH] Shade sun, night, and twilight --- src/render.js | 19 +++++++++++++++++-- src/style.sass | 11 +++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/render.js b/src/render.js index ff7bdf2..934d6de 100644 --- a/src/render.js +++ b/src/render.js @@ -82,6 +82,15 @@ class Chart { .attr('x1', this.margin.left).attr('y1', this.yRange(value)) .attr('x2', this.width).attr('y2', this.yRange(value)) } + + draw_box(x1, x2, style) { + const x = this.xRange(x1) + const width = this.xRange(x2) - x + this.canvas.append('rect').attr('class', style) + .attr('x', x).attr('y', this.offset) + .attr('width', width) + .attr('height', this.height - this.offset - this.margin.bottom) + } } @@ -99,7 +108,7 @@ export function render_astronomy(canvas, height, offset, data) { chart.draw_yAxisTitle('Altitude') chart.set_yAxisTic( 0, '0°') - chart.set_yAxisTic(45 * (Math.PI/180), '45°') + chart.set_yAxisTic(26.6 * (Math.PI/180), '27°') chart.set_yAxisTic(75 * (Math.PI/180), '75°') const year = chart.beginTime.getFullYear() @@ -110,18 +119,24 @@ export function render_astronomy(canvas, height, offset, data) { const lon = -75.1696126 for (var day = chart.beginTime.getDate(); day <= chart.endTime.getDate(); day++) { const noon = new Date(year, month, day, 12, 0, 0) + const midnight = new Date(year, month, day, 0, 0, 0) chart.set_xAxisTic(noon, noon.toLocaleDateString('en-US', {weekday: 'long'})) chart.draw_yGrid(noon, 'noon') // Don't draw the first midnight line because that's also our yAxis line if (day != chart.beginTime.getDate()) { - const midnight = new Date(year, month, day, 0, 0, 0) chart.draw_yGrid(midnight, 'midnight') } // Solar Ephemeris let todaysSun = [] const sunEphem = SunCalc.getTimes(new Date(year, month, day, 1, 0, 0), lat, lon) + + chart.draw_box(midnight, sunEphem.nauticalDawn, 'night') + chart.draw_box(sunEphem.nauticalDawn, sunEphem.sunrise, 'twilight') + chart.draw_box(sunEphem.sunset, sunEphem.nauticalDusk, 'twilight') + chart.draw_box(sunEphem.nauticalDusk, new Date(year, month, day, 24, 0, 0), 'night') + todaysSun.push({ 'date': sunEphem.sunrise, 'alt': 0 diff --git a/src/style.sass b/src/style.sass index 2d1cd0b..986d1cc 100644 --- a/src/style.sass +++ b/src/style.sass @@ -49,7 +49,8 @@ path.data stroke-width: 2px path.sun - stroke: #ff0 + fill: #ffffce + stroke: #ffff64 stroke-width: 1px path.moon @@ -67,7 +68,7 @@ line.midnight line.noon stroke: #ddd stroke-width: 1px - stroke-dasharray: 4,8 + stroke-dasharray: 3,5 line.zero stroke: #25f @@ -86,5 +87,11 @@ line.axis stroke: #000 stroke-width: 1px +rect.night + fill: #ddddeb + +rect.twilight + fill: #ebebf7 + text.axis-label font: normal 10px sans-serif