Skip to content

Commit

Permalink
Merge pull request #1763 from weather-gov/ik/humidity-hourly-chart
Browse files Browse the repository at this point in the history
Add humidity hourly chart
  • Loading branch information
partly-igor authored Sep 12, 2024
2 parents 21e5c81 + d67489e commit cc0b24e
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 31 deletions.
2 changes: 1 addition & 1 deletion web/themes/new_weather_theme/assets/css/styles.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/themes/new_weather_theme/assets/css/styles.css.map

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions web/themes/new_weather_theme/assets/js/charts/hourly-humidity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* global Chart ChartDataLabels */

import styles from "../styles.js";

Chart.register(ChartDataLabels);

const chartContainers = Array.from(
document.querySelectorAll(".wx-hourly-humidity-chart-container"),
);

for (const container of chartContainers) {
const times = JSON.parse(container.dataset.times);
const humidity = JSON.parse(container.dataset.humidity).map((v) =>
Number.parseInt(v, 10),
);

// We don't need to keep a reference to the chart object. We only need the
// side-effects of creating it. This is not ideal, but it's how Chart.js
// works, so it's what we've got.
// eslint-disable-next-line no-new
new Chart(container.querySelector("canvas"), {
type: "bar",
plugins: [ChartDataLabels],

options: {
animation: false,
responsive: true,
maintainAspectRatio: false,
interaction: {
intersect: false,
mode: "index",
},

plugins: {
legend: {
display: false,
},
tooltip: {
xAlign: "center",
yAlign: "bottom",
},
},
scales: {
x: {
ticks: {
maxRotation: 0,
color: styles.colors.base,
},
grid: { display: false },
},
y: {
min: 0,
max: 100,
ticks: {
autoSkip: true,
color: styles.colors.base,
maxTicksLimit: 6,
callback: (v) => `${v}%`,
},
},
},
},

data: {
labels: times.map((v) => (Number.parseInt(v, 10) % 2 === 0 ? v : "")),
datasets: [
{
label: "Humidity",
data: humidity,
datalabels: {
align: "end",
anchor: "end",
color: styles.colors.accentCoolDark,
},
backgroundColor: styles.colors.accentCoolDark,
},
],
},
});
}
1 change: 1 addition & 0 deletions web/themes/new_weather_theme/assets/js/point.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ import("./components/combo-box-location.js");
import("./components/alertMap.js");
import("./charts/hourly-temperature.js");
import("./charts/hourly-pops.js");
import("./charts/hourly-humidity.js");
1 change: 1 addition & 0 deletions web/themes/new_weather_theme/assets/js/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const colors = {
primaryDark: styles.getPropertyValue("--color-primary-dark"),
primaryLight: styles.getPropertyValue("--color-primary-light"),
cyan50: styles.getPropertyValue("--color-cyan-50"),
accentCoolDark: styles.getPropertyValue("--color-accent-cool-dark"),
};

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ body {
--color-primary-dark: #{color("primary-dark")};
--color-primary-light: #{color("primary-light")};
--color-cyan-50: #{color("cyan-50")};
--color-accent-cool-dark: #{color("accent-cool-dark")};
--font-family-mono: #{font-family("mono")};
}
4 changes: 2 additions & 2 deletions web/themes/new_weather_theme/new_weather_theme.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ uswds-init:
minified: true

uswds-customized:
version: 2024-08-29
version: 2024-09-12
css:
theme:
assets/css/styles.css: {}
Expand All @@ -25,7 +25,7 @@ front-page:
defer: true

point-page:
version: 2024-09-03
version: 2024-09-12
js:
assets/js/point.page.js:
attributes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,11 @@
{% set temps = hours | map(h => h.temperature) | json_encode %}
{% set feelsLike = hours | map(h => h.apparentTemperature) | json_encode %}
{% set pops = hours | map(h => h.probabilityOfPrecipitation) | json_encode %}
{% set relativeHumidity = hours | map(h => h.relativeHumidity) | json_encode %}

<wx-hourly-table class="display-block position-relative margin-top-2 bg-white">
<h5 class="wx-visual-h3 font-heading-md text-normal text-primary-darker margin-top-0 margin-bottom-205">Hourly forecast</h5>

<div class="margin-bottom-205">
<span class="font-family-mono text-primary-dark">Temperature</span>
<div class="wx-hourly-temp-chart-container margin-y-105 position-relative grid-col-12" data-times="{{ times }}" data-temps="{{ temps }}" data-feels-like="{{ feelsLike }}">
<canvas>
</canvas>
</div>
<div class="display-flex flex-align-center font-mono-xs text-base">
<div class="width-3 border-bottom-2px border-primary-dark height-0 margin-right-1">
<div class="bg-primary-dark margin-left-1 radius-pill width-1 height-1" style="margin-top: -3px;"></div>
</div>
Temperature
<div class="margin-left-3 width-3 border-bottom-2px border-top-0 border-left-0 border-right-0 border-dotted border-primary-light height-0 margin-right-1">
<div class="bg-primary-light margin-left-1 radius-pill width-1 height-1" style="margin-top: -3px;"></div>
</div>
Feels like
</div>
</div>

<div class="margin-bottom-205">
<span class="font-family-mono text-primary-dark">Chance of precipitation</span>
<div class="wx-hourly-pops-chart-container margin-y-205 position-relative grid-col-12" data-times="{{ times }}" data-pops="{{ pops }}">
<canvas>
</canvas>
</div>
</div>


<div class="display-flex flex-justify">
<div>
<button class="wx-scroll-button bg-gray-30 circle-5 border-0 text-white display-flex flex-align-center flex-justify-center padding-y-1px padding-x-05" data-direction="left" type="button" role="button">
Expand Down Expand Up @@ -190,4 +164,40 @@
</tbody>
</table>
</div>

<div class="margin-bottom-3">
<span class="font-family-mono text-primary-dark">Temperature</span>
<div class="wx-hourly-temp-chart-container margin-y-105 position-relative grid-col-12" data-times="{{ times }}" data-temps="{{ temps }}" data-feels-like="{{ feelsLike }}">
<canvas>
</canvas>
</div>
<div class="display-flex flex-align-center font-mono-xs text-base">
<div class="width-3 border-bottom-2px border-primary-dark height-0 margin-right-1">
<div class="bg-primary-dark margin-left-1 radius-pill width-1 height-1" style="margin-top: -3px;"></div>
</div>
Temperature
<div class="margin-left-3 width-3 border-bottom-2px border-top-0 border-left-0 border-right-0 border-dotted border-primary-light height-0 margin-right-1">
<div class="bg-primary-light margin-left-1 radius-pill width-1 height-1" style="margin-top: -3px;"></div>
</div>
Feels like
</div>
</div>

<div class="margin-bottom-205">
<span class="font-family-mono text-primary-dark">Humidity</span>
<div class="wx-hourly-humidity-chart-container margin-y-205 position-relative grid-col-12" data-times="{{ times }}" data-humidity="{{ relativeHumidity }}">
<canvas>
</canvas>
</div>
</div>

<div class="margin-bottom-205">
<span class="font-family-mono text-primary-dark">Chance of precipitation</span>
<div class="wx-hourly-pops-chart-container margin-y-205 position-relative grid-col-12" data-times="{{ times }}" data-pops="{{ pops }}">
<canvas>
</canvas>
</div>
</div>


</wx-hourly-table>

0 comments on commit cc0b24e

Please sign in to comment.