aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-rw-r--r--widgets/details.lua2
-rw-r--r--widgets/hourly.lua23
-rw-r--r--widgets/now.lua10
-rw-r--r--widgets/sky.lua6
-rw-r--r--widgets/week.lua10
5 files changed, 25 insertions, 26 deletions
diff --git a/widgets/details.lua b/widgets/details.lua
index a1063a4..8b107a9 100644
--- a/widgets/details.lua
+++ b/widgets/details.lua
@@ -20,7 +20,7 @@ local function draw_compass(cr, x, y, w, h, colors, deg, S)
cairo_arc(cr, cx, cy, r, 0, math.pi * 2)
cairo_stroke(cr)
- local size = math.max(9, r * 0.2)
+ local size = math.min(r * 0.2, S * 0.32)
card.font(cr, card.FONT_MONO, size, false)
card.rgba(cr, colors.label)
for i, p in ipairs({ 'N', 'E', 'S', 'W' }) do
diff --git a/widgets/hourly.lua b/widgets/hourly.lua
index 9566823..82f7585 100644
--- a/widgets/hourly.lua
+++ b/widgets/hourly.lua
@@ -12,8 +12,8 @@ local M = {}
-- The band, top to bottom: glyph line, temperature line, curve, hour line.
-- Every third hour is labelled; all 24 shape the curve.
local function draw_curve(cr, x, y, w, h, colors, hours, S)
- local n = #hours
- local label = math.max(9, math.min(S * 0.30, h * 0.11))
+ local n = math.min(#hours, 24)
+ local label = math.max(9, math.min(h * 0.11, w / 8 * 0.22))
local glyph = label * 1.5
local slot = w / n
local function px(i) return x + (i - 0.5) * slot end
@@ -22,7 +22,8 @@ local function draw_curve(cr, x, y, w, h, colors, hours, S)
if base - top < label * 2 then return end -- no room: no curve beats a broken one
local lo, hi = math.huge, -math.huge
- for _, hr in ipairs(hours) do
+ for i = 1, n do
+ local hr = hours[i]
if hr.temp then lo, hi = math.min(lo, hr.temp), math.max(hi, hr.temp) end
end
if lo > hi then return end
@@ -31,10 +32,11 @@ local function draw_curve(cr, x, y, w, h, colors, hours, S)
local function py(t) return base - (base - top) * (0.15 + 0.7 * (t - lo) / span) end
-- Rain chance as bars rising from the baseline, under the curve.
- card.rgba(cr, colors.rule, 0.5)
- for i, hr in ipairs(hours) do
- if hr.precip and hr.precip > 0 then
- local bh = (base - top) * 0.5 * hr.precip / 100
+ card.rgba(cr, colors.value, 0.3)
+ for i = 1, n do
+ local p = math.min(hours[i].precip or 0, 100)
+ if p > 0 then
+ local bh = (base - top) * 0.5 * p / 100
cairo_rectangle(cr, px(i) - slot * 0.3, base - bh, slot * 0.6, bh)
end
end
@@ -50,7 +52,8 @@ local function draw_curve(cr, x, y, w, h, colors, hours, S)
card.rgba(cr, colors.highlight)
cairo_set_line_width(cr, math.max(1.5, label * 0.15))
local pen = false
- for i, hr in ipairs(hours) do
+ for i = 1, n do
+ local hr = hours[i]
if hr.temp then
if pen then cairo_line_to(cr, px(i), py(hr.temp))
else cairo_move_to(cr, px(i), py(hr.temp)) end
@@ -71,7 +74,7 @@ local function draw_curve(cr, x, y, w, h, colors, hours, S)
card.text_centre(cr, px(i), y + glyph + label * 1.3, weather.deg(hr.temp))
card.rgba(cr, colors.label)
card.text_centre(cr, px(i), y + h - label * 0.2,
- hr.t and os.date('%H', hr.t) or '--')
+ weather.clock(hr.t, '%H'))
end
end
@@ -85,7 +88,7 @@ function M.draw(cr, rect, colors)
-- hours[1] is the current hour, so the big value is the one after it.
local y, S = card.standard(cr, inner, colors, {
icon = card.ICON.hourly, title = 'NEXT 24H',
- big = weather.deg((w.hours[2] or {}).temp), share = 0.3,
+ big = weather.deg((w.hours[2] or {}).temp), share = 0.4,
})
draw_curve(cr, inner.x, y, inner.w, inner.y + inner.h - y, colors, w.hours, S)
end
diff --git a/widgets/now.lua b/widgets/now.lua
index 8fc6843..1b797ae 100644
--- a/widgets/now.lua
+++ b/widgets/now.lua
@@ -14,15 +14,7 @@ function M.draw(cr, rect, colors)
local inner = card.card(cr, rect, colors)
local w = weather.parse(data.slurp(weather.CACHE))
if not w then
- -- Closed explicitly: this branch reruns every frame until a fetch lands,
- -- so an unclosed handle would accumulate one per draw.
- local envf = io.open((os.getenv('HOME') or '') .. '/.config/udt/weather.env', 'r')
- local hint = 'set ~/.config/udt/weather.env'
- if envf then
- envf:close()
- hint = 'bin/weather-fetch.sh'
- end
- card.notice(cr, inner, colors, 'WEATHER', 'no weather data', hint)
+ card.notice(cr, inner, colors, 'WEATHER', 'no weather data', 'bin/weather-fetch.sh')
return
end
diff --git a/widgets/sky.lua b/widgets/sky.lua
index aa0ad43..7dbc399 100644
--- a/widgets/sky.lua
+++ b/widgets/sky.lua
@@ -38,7 +38,7 @@ local function draw_arc(cr, x, y, w, h, colors, rise, set, now)
cairo_curve_to(cr, c1[1], c1[2], c2[1], c2[2], p3[1], p3[2])
cairo_stroke(cr)
- local t = weather.sun_t(now, rise, set) or 0
+ local t = weather.sun_t(now, rise, set)
local function bez(a, b, c, d)
local u = 1 - t
return u * u * u * a + 3 * u * u * t * b + 3 * u * t * t * c + t * t * t * d
@@ -64,8 +64,8 @@ function M.draw(cr, rect, colors)
local rise, set = w.sun.rise, w.sun.set
local phase, lit = weather.moon(now)
local rows = {
- { 'SUNRISE', os.date('%H:%M', rise) },
- { 'SUNSET', os.date('%H:%M', set) },
+ { 'SUNRISE', weather.clock(rise) },
+ { 'SUNSET', weather.clock(set) },
{ 'DAYLIGHT', weather.duration(set - rise) },
{ 'MOON', weather.num(lit * 100, '%') },
}
diff --git a/widgets/week.lua b/widgets/week.lua
index 262121f..3cf34d1 100644
--- a/widgets/week.lua
+++ b/widgets/week.lua
@@ -19,8 +19,9 @@ local function draw_days(cr, x, y, w, h, colors, days, S)
local lo, hi = math.huge, -math.huge
for _, d in ipairs(days) do
- if d.min then lo = math.min(lo, d.min) end
- if d.max then hi = math.max(hi, d.max) end
+ if d.min and d.max then
+ lo, hi = math.min(lo, d.min, d.max), math.max(hi, d.min, d.max)
+ end
end
local span = (hi > lo) and (hi - lo) or 1
-- Columns as fractions of the width: day | glyph | min | bar | max.
@@ -33,10 +34,13 @@ local function draw_days(cr, x, y, w, h, colors, days, S)
local by = y + step * (i - 0.5) + size * 0.35 -- baseline, centred in the row
card.font(cr, card.FONT_MONO, size, false)
card.rgba(cr, colors.label)
+ local name = weather.clock(d.t, '%a')
card.text(cr, x, by, i == 1 and 'TODAY'
- or (d.t and os.date('%a', d.t):upper() or '--'))
+ or (name == '--' and name or name:upper()))
card.rgba(cr, colors.highlight)
+ card.font(cr, card.FONT_MONO, size * 1.4, false)
card.text(cr, gx, by, weather.icon(d.code, true))
+ card.font(cr, card.FONT_MONO, size, false)
card.rgba(cr, colors.value)
card.text_right(cr, minx, by, weather.deg(d.min))
card.text_right(cr, x + w, by, weather.deg(d.max))