Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit 53b0bdf

Browse files
Fix Chart colouring and javascript
1 parent a63e634 commit 53b0bdf

8 files changed

Lines changed: 73 additions & 87 deletions

File tree

static/js/scripts.js

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,13 @@ function toggleLoading(caller) {
2727
element.classList.toggle("is-loading");
2828
}
2929

30-
function toggleChartLoading(id) {
31-
const progress = document.getElementById(`${id}-loading`).parentElement;
32-
const chart = document.getElementById(id).parentElement;
33-
progress.hidden = !progress.hidden;
34-
chart.hidden = !chart.hidden;
35-
}
36-
3730
function resetForm(page) {
3831
window.location = page;
3932
}
4033

4134
function setTheme() {
42-
const darkCss = document.getElementById("dark-theme");
43-
const lightCss = document.getElementById("light-theme");
4435
const theme = getCookie("weatherdan_theme");
45-
46-
if (darkCss !== null && lightCss !== null) {
47-
darkCss.disabled = theme == "dark";
48-
lightCss.disabled = theme == "light";
49-
}
36+
document.documentElement.setAttribute("data-theme", theme === "dark" ? "villain" : "hero");
5037
}
5138

5239
function toggleTheme() {
@@ -57,7 +44,9 @@ function toggleTheme() {
5744
setTheme();
5845
}
5946

60-
ready(setTheme());
47+
ready(() => {
48+
setTheme();
49+
});
6150

6251
async function submitRequest(endpoint, method, body = {}) {
6352
try {
@@ -80,28 +69,37 @@ async function submitRequest(endpoint, method, body = {}) {
8069
}
8170
}
8271

83-
async function refreshData(endpoint) {
84-
const response = await submitRequest(endpoint, "PUT");
85-
if (response !== null && response.status != 208)
86-
window.location.reload();
72+
function getBulmaColour(name) {
73+
const tempElement = document.createElement("div");
74+
tempElement.className = `has-background-${name}`;
75+
document.body.appendChild(tempElement);
76+
const computedStyle = getComputedStyle(tempElement);
77+
const color = computedStyle.backgroundColor;
78+
document.body.removeChild(tempElement);
79+
return color;
8780
}
8881

89-
const backgroundColours = [
90-
"rgba(65,105,225,0.1)",
91-
"rgba(255,65,105,0.1)",
92-
"rgba(105,255,65,0.1)",
93-
];
82+
function setAlpha(rgb, alpha) {
83+
const rgbValues = rgb.match(/\d+/g).map(Number);
84+
return `rgba(${rgbValues[0]}, ${rgbValues[1]}, ${rgbValues[2]}, ${alpha})`;
85+
}
9486

95-
const borderColours = [
96-
"rgba(65,105,225,1)",
97-
"rgba(255,65,105,1)",
98-
"rgba(105,255,65,1)",
99-
];
87+
function getColours(alpha) {
88+
const colours = ["info", "danger", "success"];
89+
return colours.map(colour => setAlpha(getBulmaColour(colour), alpha));
90+
}
91+
92+
function toggleChartLoading(id) {
93+
const progress = document.getElementById(`${id}-loading`).parentElement;
94+
const chart = document.getElementById(id).parentElement;
95+
progress.hidden = !progress.hidden;
96+
chart.hidden = !chart.hidden;
97+
}
10098

10199
function createDataset(index, data, label, type, yAxisID = "y") {
102100
return {
103-
backgroundColor: backgroundColours[index],
104-
borderColor: borderColours[index],
101+
backgroundColor: getColours(0.5)[index],
102+
borderColor: getColours(1)[index],
105103
borderWidth: 2,
106104
borderSkipped: false,
107105
data: data,
@@ -124,7 +122,10 @@ function createGraph(elementId, labels, datasets, unit, unitLabel) {
124122
},
125123
plugins: {
126124
legend: {
127-
display: datasets.length > 1
125+
display: datasets.length > 1,
126+
labels: {
127+
color: getBulmaColour("text")
128+
}
128129
},
129130
tooltip: {
130131
callbacks: {
@@ -143,21 +144,42 @@ function createGraph(elementId, labels, datasets, unit, unitLabel) {
143144
title: {
144145
display: true,
145146
text: "Date",
147+
color: getBulmaColour("text")
146148
},
147149
position: "bottom",
150+
ticks: {
151+
color: getBulmaColour("text")
152+
},
153+
grid: {
154+
color: getBulmaColour("text-50")
155+
}
148156
},
149157
y: {
150158
title: {
151159
display: true,
152-
text: unitLabel
160+
text: unitLabel,
161+
color: getBulmaColour("text")
153162
},
154163
position: "left",
155164
beginAtZero: false,
165+
ticks: {
166+
color: getBulmaColour("text")
167+
},
168+
grid: {
169+
color: getBulmaColour("text-50")
170+
}
156171
}
157172
}
158173
}
159174
}
160175
new Chart(document.getElementById(elementId), config);
176+
toggleChartLoading(elementId);
177+
}
178+
179+
async function refreshData(endpoint) {
180+
const response = await submitRequest(endpoint, "PUT");
181+
if (response !== null && response.status != 208)
182+
window.location.reload();
161183
}
162184

163185
async function loadTotalStats(timeframe, graphId, endpoint, unit, unitLabel, maxEntries) {

templates/editor.html.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<div class="columns is-centered is-multiline">
2323
<div class="column is-one-quarter-tablet is-one-fifth-fullhd">
2424
<div class="box has-background-text-soft">
25-
<h5 class="title is-5 has-text-info-light">Graph Points</h5>
25+
<h4 class="title is-4 has-text-text-bold">Graph Points</h4>
2626
<form id="settings-form" onsubmit="return false;">
2727
{{ input_number(label="Max Entries", name="max-entries", value=max_entries) }}
2828
<div class="buttons is-centered">

templates/index.html.jinja

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@
6565
6666
if (results.some(x => x))
6767
window.location.reload();
68-
toggleChartLoading("rainfall-stats");
69-
toggleChartLoading("solar-stats");
70-
toggleChartLoading("uv-index-stats");
71-
toggleChartLoading("wind-stats");
7268
});
7369
</script>
7470
</body>

templates/rainfall.html.jinja

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,6 @@
7070
<script src="/static/js/scripts.js" type="text/javascript"></script>
7171
<script src="/static/js/bulma-navbar.js" type="text/javascript"></script>
7272
<script type="text/javascript">
73-
ready(() => {
74-
refreshData("/api/rainfall");
75-
{% if month %}
76-
toggleChartLoading("daily-stats");
77-
toggleChartLoading("weekly-stats");
78-
{% endif %}
79-
{% if year %}
80-
toggleChartLoading("monthly-stats");
81-
{% endif %}
82-
toggleChartLoading("yearly-stats");
83-
});
84-
8573
ready(() => {
8674
{% if month %}
8775
loadRainfallStats("Daily", "daily-stats", maxEntries=100);
@@ -92,6 +80,10 @@
9280
{% endif %}
9381
loadRainfallStats("Yearly", "yearly-stats", maxEntries=100);
9482
});
83+
84+
ready(() => {
85+
refreshData("/api/rainfall");
86+
});
9587
</script>
9688
</body>
9789
</html>

templates/solar.html.jinja

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,6 @@
7070
<script src="/static/js/scripts.js" type="text/javascript"></script>
7171
<script src="/static/js/bulma-navbar.js" type="text/javascript"></script>
7272
<script type="text/javascript">
73-
ready(() => {
74-
refreshData("/api/solar");
75-
{% if month %}
76-
toggleChartLoading("daily-stats");
77-
toggleChartLoading("weekly-stats");
78-
{% endif %}
79-
{% if year %}
80-
toggleChartLoading("monthly-stats");
81-
{% endif %}
82-
toggleChartLoading("yearly-stats");
83-
});
84-
8573
ready(() => {
8674
{% if month %}
8775
loadSolarStats("Daily", "daily-stats", maxEntries=100);
@@ -92,6 +80,10 @@
9280
{% endif %}
9381
loadSolarStats("Yearly", "yearly-stats", maxEntries=100);
9482
});
83+
84+
ready(() => {
85+
refreshData("/api/solar");
86+
});
9587
</script>
9688
</body>
9789
</html>

templates/uv-index.html.jinja

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,6 @@
7070
<script src="/static/js/scripts.js" type="text/javascript"></script>
7171
<script src="/static/js/bulma-navbar.js" type="text/javascript"></script>
7272
<script type="text/javascript">
73-
ready(() => {
74-
refreshData("/api/uv-index");
75-
{% if month %}
76-
toggleChartLoading("daily-stats");
77-
toggleChartLoading("weekly-stats");
78-
{% endif %}
79-
{% if year %}
80-
toggleChartLoading("monthly-stats");
81-
{% endif %}
82-
toggleChartLoading("yearly-stats");
83-
});
84-
8573
ready(() => {
8674
{% if month %}
8775
loadUVIndexStats("Daily", "daily-stats", maxEntries=100);
@@ -92,6 +80,10 @@
9280
{% endif %}
9381
loadUVIndexStats("Yearly", "yearly-stats", maxEntries=100);
9482
});
83+
84+
ready(() => {
85+
refreshData("/api/uv-index");
86+
});
9587
</script>
9688
</body>
9789
</html>

templates/wind.html.jinja

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,6 @@
7070
<script src="/static/js/scripts.js" type="text/javascript"></script>
7171
<script src="/static/js/bulma-navbar.js" type="text/javascript"></script>
7272
<script type="text/javascript">
73-
ready(() => {
74-
refreshData("/api/wind");
75-
{% if month %}
76-
toggleChartLoading("daily-stats");
77-
toggleChartLoading("weekly-stats");
78-
{% endif %}
79-
{% if year %}
80-
toggleChartLoading("monthly-stats");
81-
{% endif %}
82-
toggleChartLoading("yearly-stats");
83-
});
84-
8573
ready(() => {
8674
{% if month %}
8775
loadWindStats("Daily", "daily-stats", maxEntries=100);
@@ -92,6 +80,10 @@
9280
{% endif %}
9381
loadWindStats("Yearly", "yearly-stats", maxEntries=100);
9482
});
83+
84+
ready(() => {
85+
refreshData("/api/wind");
86+
});
9587
</script>
9688
</body>
9789
</html>

weatherdan/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from rich.theme import Theme
2121
from rich.traceback import install
2222

23-
__version__ = "0.6.2"
23+
__version__ = "0.6.3"
2424
CONSOLE = Console(
2525
theme=Theme(
2626
{

0 commit comments

Comments
 (0)