Skip to content

Commit

Permalink
Tests for SVG tide charts, closes #44
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Apr 4, 2022
1 parent ad64409 commit efcf3a0
Show file tree
Hide file tree
Showing 7 changed files with 411 additions and 66 deletions.
1 change: 1 addition & 0 deletions pillarpointstewards/config/urls.py
Expand Up @@ -45,4 +45,5 @@ def trigger_error(request):
path("admin/", admin.site.urls),
path("sentry-debug/", trigger_error),
path("debug/tide-times/<str:date>/", tides.debug),
path("debug/tide-times-just-svg/<str:date>/", tides.debug_just_svg),
]
4 changes: 3 additions & 1 deletion pillarpointstewards/shifts/views.py
Expand Up @@ -32,7 +32,9 @@ def shift(request, shift_id):
"stewards": stewards,
"contact_details": Fragment.objects.get(slug="contact_details").fragment,
"forecast": Forecast.for_date(shift.shift_start.date()),
"tide_times_svg": tide_times_svg_context_for_date(shift.shift_start.date()),
"tide_times_svg": tide_times_svg_context_for_date(
shift.shift_start.replace(hour=0, minute=0, second=0)
),
},
)

Expand Down
31 changes: 31 additions & 0 deletions pillarpointstewards/templates/_tide_svg.html
@@ -0,0 +1,31 @@
{% if tide_times_svg.svg_points %}<div class="day-alone">
<div class="shift-view">
<div class="day-view" style="
background: linear-gradient(90deg,
#176AB8 0%,
#97bcdf {{ tide_times_svg.astral.dawn_pct }}%,
#d1e1f1 {{ tide_times_svg.astral.sunrise_pct }}%,
#FFFFFF {{ tide_times_svg.astral.noon_pct }}%,
#d1e1f1 {{ tide_times_svg.astral.sunset_pct }}%,
#97bcdf {{ tide_times_svg.astral.dusk_pct }}%,
#176AB8 100%
);
">
{% if tide_times_svg.shift %}
<div class="shift-window" style="left:{{ tide_times_svg.shift_start_pct }}%; width: {{ tide_times_svg.shift_width_pct }}%;">
<span class="start-time">{{ tide_times_svg.shift.shift_start|date:"g:iA"|lower }}</span>
<span class="end-time">{{ tide_times_svg.shift.shift_end|date:"g:iA"|lower }}</span>
</div>
{% endif %}
<svg style="width: 100%; height: 60px; opacity: 0.5" viewBox="0 -2 240 104" preserveAspectRatio="none">
<polyline fill="none" stroke="#176AB8" stroke-width="2" points="{{ tide_times_svg.svg_points }}"></polyline>
</svg>
{% if tide_times_svg.low_tide_time %}
<span class="minima" style="left: {{ tide_times_svg.low_tide_time_pct }}%">
<span class="time">{{ tide_times_svg.low_tide_time|date:"g:iA"|lower }}</span>
</span>
{% endif %}
</div>
</div>
</div>
{% endif %}
31 changes: 1 addition & 30 deletions pillarpointstewards/templates/shift.html
Expand Up @@ -73,36 +73,7 @@ <h2>Volunteers on this shift <em>({{ stewards|length }}{% if shift.target_stewar

{% if tide_times_svg %}
<h2>Tide on this day</h2>
<div class="day-alone">
<div class="shift-view">
<div class="day-view" style="
background: linear-gradient(90deg,
#176AB8 0%,
#97bcdf {{ tide_times_svg.astral.dawn_pct }}%,
#d1e1f1 {{ tide_times_svg.astral.sunrise_pct }}%,
#FFFFFF {{ tide_times_svg.astral.noon_pct }}%,
#d1e1f1 {{ tide_times_svg.astral.sunset_pct }}%,
#97bcdf {{ tide_times_svg.astral.dusk_pct }}%,
#176AB8 100%
);
">
{% if shift %}
<div class="shift-window" style="left:{{ tide_times_svg.shift_start_pct }}%; width: {{ tide_times_svg.shift_width_pct }}%;">
<span class="start-time">{{ shift.shift_start|date:"g:iA"|lower }}</span>
<span class="end-time">{{ shift.shift_end|date:"g:iA"|lower }}</span>
</div>
{% endif %}
<svg style="width: 100%; height: 60px; opacity: 0.5" viewBox="0 -2 240 104" preserveAspectRatio="none">
<polyline fill="none" stroke="#176AB8" stroke-width="2" points="{{ tide_times_svg.svg_points }}"></polyline>
</svg>
{% if tide_times_svg.low_tide_time %}
<span class="minima" style="left: {{ tide_times_svg.low_tide_time_pct }}%">
<span class="time">{{ tide_times_svg.low_tide_time|date:"g:iA"|lower }}</span>
</span>
{% endif %}
</div>
</div>
</div>
{% include "_tide_svg.html" %}
{% endif %}

{% if forecast %}
Expand Down
32 changes: 2 additions & 30 deletions pillarpointstewards/templates/tide-times-debug.html
Expand Up @@ -11,36 +11,8 @@ <h1 class="text"><span>Debug Tide Times Graphic: {{ date }}</span></h1>
</section>
<section class="content">
<div class="primary">
<div class="day-alone">
<div class="shift-view">
<div class="day-view" style="
background: linear-gradient(90deg,
#176AB8 0%,
#97bcdf {{ astral.dawn_pct }}%,
#d1e1f1 {{ astral.sunrise_pct }}%,
#FFFFFF {{ astral.noon_pct }}%,
#d1e1f1 {{ astral.sunset_pct }}%,
#97bcdf {{ astral.dusk_pct }}%,
#176AB8 100%
);
">
{% if shift %}
<div class="shift-window" style="left:{{ shift_start_pct }}%; width: {{ shift_width_pct }}%;">
<span class="start-time">{{ shift.shift_start|date:"g:iA"|lower }}</span>
<span class="end-time">{{ shift.shift_end|date:"g:iA"|lower }}</span>
</div>
{% endif %}
<svg style="width: 100%; height: 60px; opacity: 0.5" viewBox="0 -2 240 104" preserveAspectRatio="none">
<polyline fill="none" stroke="#176AB8" stroke-width="2" points="{{ svg_points }}"></polyline>
</svg>
{% if low_tide_time %}
<span class="minima" style="left: {{ low_tide_time_pct }}%">
<span class="time">{{ low_tide_time|date:"g:iA"|lower }}</span>
</span>
{% endif %}
</div>
</div>
</div>

{% include "_tide_svg.html" %}

<svg style="width: 100%; height: 60px; opacity: 0.5" viewBox="0 -2 240 104" preserveAspectRatio="none">
<polyline fill="none" stroke="#176AB8" stroke-width="2"
Expand Down

0 comments on commit efcf3a0

Please sign in to comment.