Skip to content

Commit

Permalink
Merge branch 'main' into eg-1567-social-empty-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-gade authored Sep 10, 2024
2 parents 9cbe32e + 081a0de commit 5d1b819
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 59 deletions.
97 changes: 45 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@
},
"devDependencies": {
"@axe-core/playwright": "^4.10.0",
"@playwright/test": "^1.46.1",
"@types/node": "^22.5.2",
"@playwright/test": "^1.47.0",
"@types/node": "^22.5.4",
"axe-core": "^4.10.0",
"chai": "^5.1.1",
"cypress": "^13.14.1",
"cypress": "^13.14.2",
"cypress-axe": "^1.5.0",
"cypress-plugin-tab": "^1.0.5",
"dayjs": "^1.11.13",
"eslint": "^8.57.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-cypress": "^3.5.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-import": "^2.30.0",
"jsdom": "^25.0.0",
"glob": "^11.0.0",
"jsdom-global": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion web/modules/weather_data/src/Service/NewRelicMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function sendMetric(
$type = "gauge",
$now = false,
) {
$now = $now ?? time();
$now = $now ?: time();

$attributes["applicationName"] = $this->applicationName;

Expand Down
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.

98 changes: 98 additions & 0 deletions web/themes/new_weather_theme/assets/js/charts/hourly-pops.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* global Chart ChartDataLabels */
(() => {
const styles = getComputedStyle(document.body);

const fontMono = styles.getPropertyValue("--font-family-mono");
const colors = {
base: styles.getPropertyValue("--color-base"),
baseLighter: styles.getPropertyValue("--color-base-lighter"),
baseLightest: styles.getPropertyValue("--color-base-lightest"),
primary: styles.getPropertyValue("--color-primary"),
primaryDark: styles.getPropertyValue("--color-primary-dark"),
primaryLight: styles.getPropertyValue("--color-primary-light"),
cyan50: styles.getPropertyValue("--color-cyan-50"),
};

Chart.register(ChartDataLabels);

// These are applied globally to all charts. Unclear if that's okay, or if
// what we really want is to set them per-chart, but this is what I've got
// for now.
Chart.defaults.font.family = fontMono;
Chart.defaults.font.size = 12;

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

for (const container of chartContainers) {
const times = JSON.parse(container.dataset.times);
const pops = JSON.parse(container.dataset.pops).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: colors.base,
},
grid: { display: false },
},
y: {
min: 0,
max: 100,
ticks: {
autoSkip: true,
color: colors.base,
maxTicksLimit: 6,
callback: (v) => `${v}%`,
},
},
},
},

data: {
labels: times.map((v) => (Number.parseInt(v, 10) % 2 === 0 ? v : "")),
datasets: [
{
label: "Chance of precipitation",
data: pops,
datalabels: {
align: "end",
anchor: "end",
color: colors.cyan50,
},
backgroundColor: colors.cyan50,
},
],
},
});
}
})();
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ body {
--color-primary: #{color("primary")};
--color-primary-dark: #{color("primary-dark")};
--color-primary-light: #{color("primary-light")};
--color-cyan-50: #{color("cyan-50")};
--font-family-mono: #{font-family("mono")};
}
6 changes: 6 additions & 0 deletions web/themes/new_weather_theme/new_weather_theme.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,9 @@ chart-hourly-temperature:
assets/js/charts/hourly-temperature.js:
attributes:
defer: true
chart-hourly-pops:
version: 2024-08-27
js:
assets/js/charts/hourly-pops.js:
attributes:
defer: true
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{{ attach_library('new_weather_theme/hourly-table') }}
{{ attach_library('new_weather_theme/chartjs') }}
{{ attach_library('new_weather_theme/chart-hourly-temperature') }}
{{ attach_library('new_weather_theme/chart-hourly-pops') }}

{% set times = hours | map(h => h.time) | json_encode %}
{% 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 %}

<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>
Expand All @@ -27,6 +29,14 @@
</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>
Expand Down

0 comments on commit 5d1b819

Please sign in to comment.