diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 6cc64e4..e647700 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -38,7 +38,7 @@ Staging currently exercises the PostgreSQL → API → frontend path with synthe - Queries the backend using the same origin in production builds. - Provides Stations, City Analysis, Faktiskā, Latvia overview, Database, HARMONIE, and LVGMC forecast workspaces. A separate Ūdens temperatūra production workspace is planned. - Uses HTML canvas for broadcast maps and PNG export. -- Uses the bundled `ltv_meteo.otf` font for weather symbols; the glyphs are font characters, not emoji. +- Uses normalized transparent PNG assets for weather symbols; the internal letter codes remain stable identifiers and are not rendered as text or emoji. ### PostgreSQL @@ -72,15 +72,15 @@ The operator can add title/source overlays and export the rendered canvas. Faktiskā has a fixed 13-position station configuration. On page entry the frontend calls `/api/query/latest-temperatures/`. The backend selects the newest row per requested city and returns `tempAvg`, the station name, and its observation timestamp. The UI highlights missing or older observations and permits an explicit manual override without changing the stored observation. -Weather-font glyphs and wind values remain manual editorial inputs. One glyph can be applied to all fixed stations and exceptions changed individually. The browser composes these values on the fixed wind-template canvas and exports exactly 3840×1440 pixels. The production master images define the required output geometry; final Monda pixel-level comparison remains pending. +Weather symbols and wind values remain manual editorial inputs. One symbol can be applied to all fixed stations and exceptions changed individually. The browser composes these values on the fixed wind-template canvas and exports exactly 3840×1440 pixels. The production master images define the required output geometry; final Monda pixel-level comparison remains pending. -The glyph renderer measures each finished temperature badge, attaches the selected Daira glyph automatically, then applies a fixed optical correction shared by the Faktiskā template. The configuration also permits per-station offsets when later production comparison requires them. Operator input selects the symbol but never controls its coordinates. +The renderer attaches each normalized 256×256 weather image to the measured edge of its temperature badge. All assets share one canvas, center, and scale, so placement does not depend on font bearings or baselines. The configuration permits per-station offsets when later production comparison requires them. Operator input selects the symbol but never controls its coordinates. ### Ūdens temperatūra Ūdens temperatūra is an independent fixed-template renderer. Its six ranges are currently manual editorial inputs rather than station-query results. A Latvian-named field configuration maps each water area to locked canvas coordinates. The workflow produces explicit 1920×1080 and 3840×1440 canvases and filenames; each size still requires comparison against newsroom output. -Monda Regular and Bold are bundled locally and used by the interface and generated text. Daira remains a separate font used only for weather-symbol glyphs. +Monda Regular and Bold are bundled locally and used by the interface and generated text. Weather symbols are bundled as independent transparent PNG assets. ## What the repository does not provide by itself diff --git a/docs/DEVELOPMENT_AND_STAGING.md b/docs/DEVELOPMENT_AND_STAGING.md index e9d7451..31fe6c1 100644 --- a/docs/DEVELOPMENT_AND_STAGING.md +++ b/docs/DEVELOPMENT_AND_STAGING.md @@ -97,7 +97,7 @@ At minimum, verify: 4. City Analysis can query synthetic observations. 5. Each map resolution renders and downloads. 6. Faktiskā automatically loads the latest fixed-station temperatures, allows overrides, assigns font symbols, supports exceptions, and downloads a 3840×1440 PNG. -7. Faktiskā symbols remain automatically attached to their corresponding temperature badges when several different Daira glyphs are tested. +7. Faktiskā symbols remain automatically attached to their corresponding temperature badges when several different image assets are tested. 8. Browser developer tools show no new runtime errors. Known limitation: direct browser refreshes on newer client-side routes such as `/faktiska` can return 404 because the backend static-route list does not yet provide a general SPA fallback. Navigate from the home page until that backend behavior is fixed. diff --git a/docs/PRODUCT_WORKFLOWS.md b/docs/PRODUCT_WORKFLOWS.md index 152da31..4d64629 100644 --- a/docs/PRODUCT_WORKFLOWS.md +++ b/docs/PRODUCT_WORKFLOWS.md @@ -38,7 +38,7 @@ The production template contains: - the fixed title/source nameplate already present in the production artwork; - the latest available temperature for each fixed station; -- weather conditions represented by the bundled weather-font glyphs; +- weather conditions represented by normalized transparent image assets; - manually entered wind direction, speed, and gust values; - a fixed 3840×1440 PNG output. @@ -48,7 +48,7 @@ Current operator flow: 2. Review the observation timestamp, missing/stale indicators, and temperatures. 3. Override any temperature manually when editorial correction is required; reset restores the fetched value. 4. Enter wind values manually. -5. Select a weather glyph, apply it to all stations where appropriate, and adjust exceptions. +5. Select a weather symbol, apply it to all stations where appropriate, and adjust exceptions. 6. Review and download `faktiska-3840x1440.png`. Fixed positions: @@ -71,7 +71,7 @@ Fixed positions: The weather symbols are not automatically derived from the historical temperature query. They remain editorial/manual inputs until a reliable phenomena-data mapping is designed and validated. -Symbol selection is manual, but placement is automatic. Each Faktiskā position owns a fixed marker layout that attaches the selected font glyph to the actual rendered edge of its temperature badge. Operators do not position symbols for each export; per-station offsets can be refined centrally against the production master. +Symbol selection is manual, but placement is automatic. Each Faktiskā position owns a fixed marker layout that attaches the selected normalized image to the actual rendered edge of its temperature badge. Operators do not position symbols for each export; per-station offsets can be refined centrally against the production master. Completed Faktiskā checkpoint: @@ -79,8 +79,8 @@ Completed Faktiskā checkpoint: - automatic latest-temperature loading with observation time and stale/missing states; - manual temperature correction and reset to the fetched value; - manual wind direction, speed, and gust values; -- manual Daira weather-glyph selection with apply-to-all and station exceptions; -- automatic badge-relative glyph placement with shared optical correction; +- manual weather-symbol selection with apply-to-all and station exceptions; +- automatic badge-relative image placement using consistent 256×256 asset geometry; - guarded 3840×1440 export using the fixed wind production artwork. Valmiera is included in the development seed so all 13 fixed positions can be exercised. Confirmed Monda Regular/Bold files are now bundled and used. The export dimensions are locked, but final pixel-level placement must still be compared against the production masters after the font change. @@ -138,5 +138,4 @@ Development limitation: representative forecast CSV fixtures are not currently i - Whether Stende and Zīlāni remain the production feeds after users test real provider data. - Confirm how Valmiera is named and sourced when authorized provider data is available. - Final pixel-level Monda export comparison against the production masters. -- Replace Daira font-glyph rendering with a normalized SVG weather-symbol set after the design assets are supplied. - Required authentication and role separation for analytical, production, and administrative workspaces. diff --git a/docs/README.md b/docs/README.md index 48d351d..194c971 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,9 +10,9 @@ This directory contains the working documentation for the WeatherTool modernizat - Scheduled external-provider jobs are disabled in development and staging. - PostgreSQL is private to the project Compose network; only the Scala application publishes a host port. - UI modernization is in progress. City Analysis retains custom analytical map outputs, while Faktiskā is a fixed 13-position, latest-temperature newsroom workflow with a locked 3840×1440 export. -- Faktiskā symbol placement is automatic after manual glyph selection and is anchored to each rendered temperature badge. +- Faktiskā symbol placement is automatic after manual image selection and is anchored to each rendered temperature badge. - The first **Ūdens temperatūra** workspace is implemented with manual Latvian-named fields and required 1920×1080 and 3840×1440 exports; visual calibration remains in progress. -- Confirmed local Monda Regular/Bold files now provide interface and generated-graphic typography; Daira remains reserved for weather symbols. +- Confirmed local Monda Regular/Bold files provide interface and generated-graphic typography; weather symbols use normalized transparent image assets. - This is not yet approved or hardened for workplace production. ## Documents diff --git a/docs/THIRD_PARTY_NOTICES.md b/docs/THIRD_PARTY_NOTICES.md index dca4d54..3ed5264 100644 --- a/docs/THIRD_PARTY_NOTICES.md +++ b/docs/THIRD_PARTY_NOTICES.md @@ -18,6 +18,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI The locally bundled Monda Regular and Monda Bold font files are distributed under the SIL Open Font License 1.1. The complete license text is stored at `Monda/OFL.txt`. -## Planned weather-symbol SVG handoff +## Weather-symbol image assets -The production designer will export the authorized Daira weather symbols as outlined SVG artwork for use in the web renderer. Each file should use the same transparent 256×256 artboard, contain no embedded font or raster image, use a tight but optically consistent visible scale, preserve the production stroke appearance, and have a descriptive stable filename. Licensing/authorization for those workplace graphical assets must be confirmed before external distribution. +The production designer supplied normalized 256×256 transparent PNG renderings of the authorized Daira weather symbols. WeatherTool uses these independent images instead of loading or rendering the original font. Licensing/authorization for these workplace graphical assets must be confirmed before external distribution. diff --git a/docs/UPDATE_ROADMAP.md b/docs/UPDATE_ROADMAP.md index 3ee154b..a97c011 100644 --- a/docs/UPDATE_ROADMAP.md +++ b/docs/UPDATE_ROADMAP.md @@ -120,7 +120,7 @@ Status: pending - [x] Add an explicit PNG download workflow for broadcast map assets. - [x] Implement the fixed Faktiskā station set, latest-temperature loading, manual overrides, and locked 3840×1440 export. - [x] Make Faktiskā weather-symbol selection manual while keeping placement automatic and badge-relative. -- [ ] Replace Daira font glyphs in the web renderer with normalized SVG assets supplied from the production design workflow. +- [x] Replace Daira font glyphs with normalized 256×256 transparent image assets across the editor and canvas renderers. - [x] Add a separate Latvian-named Ūdens temperatūra workspace with fixed manual fields. - [ ] Validate independent Ūdens temperatūra exports at 1920×1080 and 3840×1440 against the production specification. - [x] Bundle the confirmed Monda Regular/Bold files and replace temporary Rubik rendering. diff --git a/web/src/App.tsx b/web/src/App.tsx index 4486cba..e736681 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -7,7 +7,6 @@ import { Cities } from './pages/cities/Cities'; import { Database } from './pages/database/Database'; import { Station } from './pages/station/Station'; import { apiHost } from './consts'; -import { WeatherIconStub } from './components/weatherIcons/WeatherIconStub'; import { Harmonie } from './pages/harmonie/Harmonie' import { LvgmcForecast } from './pages/lvgmc-forecast/LvgmcForecast' import { Home } from './pages/home/Home' @@ -47,7 +46,6 @@ const AppLayout: ParentComponent = (props) => { }) return (
-
WWeatherToolWeather data workspace diff --git a/web/src/assets/ltv_meteo.otf b/web/src/assets/ltv_meteo.otf deleted file mode 100644 index 4da2337..0000000 Binary files a/web/src/assets/ltv_meteo.otf and /dev/null differ diff --git a/web/src/assets/weather-icons/A.png b/web/src/assets/weather-icons/A.png new file mode 100644 index 0000000..e47081d Binary files /dev/null and b/web/src/assets/weather-icons/A.png differ diff --git a/web/src/assets/weather-icons/B.png b/web/src/assets/weather-icons/B.png new file mode 100644 index 0000000..0f54491 Binary files /dev/null and b/web/src/assets/weather-icons/B.png differ diff --git a/web/src/assets/weather-icons/C.png b/web/src/assets/weather-icons/C.png new file mode 100644 index 0000000..5e62834 Binary files /dev/null and b/web/src/assets/weather-icons/C.png differ diff --git a/web/src/assets/weather-icons/D.png b/web/src/assets/weather-icons/D.png new file mode 100644 index 0000000..45e40fe Binary files /dev/null and b/web/src/assets/weather-icons/D.png differ diff --git a/web/src/assets/weather-icons/E.png b/web/src/assets/weather-icons/E.png new file mode 100644 index 0000000..46fb5c4 Binary files /dev/null and b/web/src/assets/weather-icons/E.png differ diff --git a/web/src/assets/weather-icons/F.png b/web/src/assets/weather-icons/F.png new file mode 100644 index 0000000..df5a974 Binary files /dev/null and b/web/src/assets/weather-icons/F.png differ diff --git a/web/src/assets/weather-icons/G.png b/web/src/assets/weather-icons/G.png new file mode 100644 index 0000000..2f18a7d Binary files /dev/null and b/web/src/assets/weather-icons/G.png differ diff --git a/web/src/assets/weather-icons/H.png b/web/src/assets/weather-icons/H.png new file mode 100644 index 0000000..43a5d2f Binary files /dev/null and b/web/src/assets/weather-icons/H.png differ diff --git a/web/src/assets/weather-icons/I.png b/web/src/assets/weather-icons/I.png new file mode 100644 index 0000000..f7439e1 Binary files /dev/null and b/web/src/assets/weather-icons/I.png differ diff --git a/web/src/assets/weather-icons/J.png b/web/src/assets/weather-icons/J.png new file mode 100644 index 0000000..2bb8605 Binary files /dev/null and b/web/src/assets/weather-icons/J.png differ diff --git a/web/src/assets/weather-icons/K.png b/web/src/assets/weather-icons/K.png new file mode 100644 index 0000000..fd556b0 Binary files /dev/null and b/web/src/assets/weather-icons/K.png differ diff --git a/web/src/assets/weather-icons/L.png b/web/src/assets/weather-icons/L.png new file mode 100644 index 0000000..0124bb8 Binary files /dev/null and b/web/src/assets/weather-icons/L.png differ diff --git a/web/src/assets/weather-icons/M.png b/web/src/assets/weather-icons/M.png new file mode 100644 index 0000000..5736bd9 Binary files /dev/null and b/web/src/assets/weather-icons/M.png differ diff --git a/web/src/assets/weather-icons/N.png b/web/src/assets/weather-icons/N.png new file mode 100644 index 0000000..7d99a27 Binary files /dev/null and b/web/src/assets/weather-icons/N.png differ diff --git a/web/src/assets/weather-icons/O.png b/web/src/assets/weather-icons/O.png new file mode 100644 index 0000000..372c33b Binary files /dev/null and b/web/src/assets/weather-icons/O.png differ diff --git a/web/src/assets/weather-icons/P.png b/web/src/assets/weather-icons/P.png new file mode 100644 index 0000000..8859aaf Binary files /dev/null and b/web/src/assets/weather-icons/P.png differ diff --git a/web/src/assets/weather-icons/Q.png b/web/src/assets/weather-icons/Q.png new file mode 100644 index 0000000..f3e1966 Binary files /dev/null and b/web/src/assets/weather-icons/Q.png differ diff --git a/web/src/assets/weather-icons/R.png b/web/src/assets/weather-icons/R.png new file mode 100644 index 0000000..ff20cdc Binary files /dev/null and b/web/src/assets/weather-icons/R.png differ diff --git a/web/src/assets/weather-icons/S.png b/web/src/assets/weather-icons/S.png new file mode 100644 index 0000000..d2b8dfa Binary files /dev/null and b/web/src/assets/weather-icons/S.png differ diff --git a/web/src/assets/weather-icons/T.png b/web/src/assets/weather-icons/T.png new file mode 100644 index 0000000..b5ade1c Binary files /dev/null and b/web/src/assets/weather-icons/T.png differ diff --git a/web/src/assets/weather-icons/U.png b/web/src/assets/weather-icons/U.png new file mode 100644 index 0000000..576c39c Binary files /dev/null and b/web/src/assets/weather-icons/U.png differ diff --git a/web/src/assets/weather-icons/V.png b/web/src/assets/weather-icons/V.png new file mode 100644 index 0000000..41b3685 Binary files /dev/null and b/web/src/assets/weather-icons/V.png differ diff --git a/web/src/assets/weather-icons/W.png b/web/src/assets/weather-icons/W.png new file mode 100644 index 0000000..9d16e3a Binary files /dev/null and b/web/src/assets/weather-icons/W.png differ diff --git a/web/src/assets/weather-icons/X.png b/web/src/assets/weather-icons/X.png new file mode 100644 index 0000000..8487954 Binary files /dev/null and b/web/src/assets/weather-icons/X.png differ diff --git a/web/src/assets/weather-icons/Y.png b/web/src/assets/weather-icons/Y.png new file mode 100644 index 0000000..29607f6 Binary files /dev/null and b/web/src/assets/weather-icons/Y.png differ diff --git a/web/src/assets/weather-icons/Z.png b/web/src/assets/weather-icons/Z.png new file mode 100644 index 0000000..ae976d9 Binary files /dev/null and b/web/src/assets/weather-icons/Z.png differ diff --git a/web/src/assets/weather-icons/aa.png b/web/src/assets/weather-icons/aa.png new file mode 100644 index 0000000..8e4a860 Binary files /dev/null and b/web/src/assets/weather-icons/aa.png differ diff --git a/web/src/assets/weather-icons/bb.png b/web/src/assets/weather-icons/bb.png new file mode 100644 index 0000000..45ae73b Binary files /dev/null and b/web/src/assets/weather-icons/bb.png differ diff --git a/web/src/assets/weather-icons/cc.png b/web/src/assets/weather-icons/cc.png new file mode 100644 index 0000000..7d29508 Binary files /dev/null and b/web/src/assets/weather-icons/cc.png differ diff --git a/web/src/assets/weather-icons/dd.png b/web/src/assets/weather-icons/dd.png new file mode 100644 index 0000000..c32f58f Binary files /dev/null and b/web/src/assets/weather-icons/dd.png differ diff --git a/web/src/assets/weather-icons/ee.png b/web/src/assets/weather-icons/ee.png new file mode 100644 index 0000000..e87dbf5 Binary files /dev/null and b/web/src/assets/weather-icons/ee.png differ diff --git a/web/src/assets/weather-icons/ff.png b/web/src/assets/weather-icons/ff.png new file mode 100644 index 0000000..8641ffd Binary files /dev/null and b/web/src/assets/weather-icons/ff.png differ diff --git a/web/src/assets/weather-icons/gg.png b/web/src/assets/weather-icons/gg.png new file mode 100644 index 0000000..a851eab Binary files /dev/null and b/web/src/assets/weather-icons/gg.png differ diff --git a/web/src/assets/weather-icons/hh.png b/web/src/assets/weather-icons/hh.png new file mode 100644 index 0000000..7bba7e1 Binary files /dev/null and b/web/src/assets/weather-icons/hh.png differ diff --git a/web/src/assets/weather-icons/ii.png b/web/src/assets/weather-icons/ii.png new file mode 100644 index 0000000..d09a0db Binary files /dev/null and b/web/src/assets/weather-icons/ii.png differ diff --git a/web/src/components/map/MapView.tsx b/web/src/components/map/MapView.tsx index 657ef90..279a8f3 100644 --- a/web/src/components/map/MapView.tsx +++ b/web/src/components/map/MapView.tsx @@ -8,12 +8,14 @@ import { cityCoords } from "../cityCoords"; import { MapResolution, resolutionProps, windProps, WindProps } from "./mapConsts"; import { CityData, drawOnMap } from "./canvasDraw"; import { IconInputs } from "../weatherIcons/IconInputs"; +import { preloadWeatherIcons } from "../weatherIcons/weatherIconAssets"; import { download } from '../../helpers/download' export const MapView: Component<{ type: MapResolution, data: () => ResultKeyVal[], mode?: "temperature" | "faktiska", productionTemplate?: boolean }> = ({ type, data, mode = "temperature", productionTemplate = false }) => { const [getCanvas, setCanvas] = createSignal(); const [getImg, setImg] = createSignal(new Image()); const [fontReady, setFontReady] = createSignal(false); + const [iconsReady, setIconsReady] = createSignal(mode !== "faktiska"); const weatherIconsSignal = createSignal<{[key: string]: string;}>({}); const [getWeatherIcons] = weatherIconsSignal; const [getTitle, setTitle] = createSignal(""); @@ -44,6 +46,7 @@ export const MapView: Component<{ type: MapResolution, data: () => ResultKeyVal[ onMount(() => { void document.fonts.load(`700 ${props.fontSize}px Monda`).then(() => setFontReady(true)); + if (mode === "faktiska") void preloadWeatherIcons().then(() => setIconsReady(true)); const ctx = getCanvas()!.getContext("2d")!; const img = new Image(); img.onload = () => { @@ -63,6 +66,7 @@ export const MapView: Component<{ type: MapResolution, data: () => ResultKeyVal[ createEffect(() => { fontReady(); + iconsReady(); const ctx = getCanvas()!.getContext("2d")!; const weatherIcons = getWeatherIcons(); const coordsAndData: CityData[] = data() diff --git a/web/src/components/map/canvasDraw.ts b/web/src/components/map/canvasDraw.ts index 9c92f90..aed6305 100644 --- a/web/src/components/map/canvasDraw.ts +++ b/web/src/components/map/canvasDraw.ts @@ -1,6 +1,7 @@ import { ResolutionPropsValue, WindProps, windProps } from "./mapConsts"; import { drawRotatedImage, getAngleFromString } from "./windAngles"; import { faktiskaMarkerLayout, FaktiskaStation } from "../../pages/map-graphics/faktiskaConfig"; +import { getLoadedWeatherIcon } from "../weatherIcons/weatherIconAssets"; // cityName, {x, y}, weatherValue, icon export type CityData = [cityName: string, {x: number, y: number }, weatherValue: number, icon: string | undefined] @@ -48,11 +49,10 @@ export function drawOnMap( ctx.fillText(stringValue, localX, localY); if (icon) { - ctx.fillStyle = "#FFFFFF"; - ctx.font = `normal ${props.fontSize * (productionTemplate ? 4.2 : 5)}px Daira by LTV grafika`; - const iconMetrics = ctx.measureText(icon); - const glyphWidth = iconMetrics.actualBoundingBoxLeft + iconMetrics.actualBoundingBoxRight; - const badgeWidth = getBadgeWidth(ctx, stringValue, props, true); + const iconImage = getLoadedWeatherIcon(icon); + if (!iconImage) return; + const iconSize = productionTemplate ? 190 : props.boxSize * 1.35; + const badgeWidth = getBadgeWidth(ctx, stringValue, props); if (productionTemplate) { const layout = faktiskaMarkerLayout[city as FaktiskaStation]; @@ -61,11 +61,11 @@ export function drawOnMap( const offsetX = layout?.iconOffsetX ?? 0; const offsetY = layout?.iconOffsetY ?? 0; const iconCenterX = side === "right" - ? localX + badgeWidth / 2 + gap + glyphWidth / 2 + offsetX - : localX - badgeWidth / 2 - gap - glyphWidth / 2 + offsetX; - drawOpticallyCenteredGlyph(ctx, icon, iconCenterX, localY + offsetY); + ? localX + badgeWidth / 2 + gap + iconSize / 2 + offsetX + : localX - badgeWidth / 2 - gap - iconSize / 2 + offsetX; + drawWeatherIcon(ctx, iconImage, iconCenterX, localY + offsetY, iconSize); } else { - drawOpticallyCenteredGlyph(ctx, icon, localX + props.boxSize / 2 + 10 + iconMetrics.width / 2, localY); + drawWeatherIcon(ctx, iconImage, localX + badgeWidth / 2 + 10 + iconSize / 2, localY, iconSize); } } }); @@ -98,20 +98,13 @@ export function drawOnMap( ctx.fillText("M/S", windProp.offsetX + boxMiddleX + gustsWidth / 2 - 22, (windProp.offsetY + 805)*windProp.scaleY); } -function getBadgeWidth(ctx: CanvasRenderingContext2D, value: string, props: ResolutionPropsValue, restoreValueFont = false): number { - if (restoreValueFont) ctx.font = `bold ${props.fontSize}px Monda`; - const width = Math.max(props.boxSize, Math.ceil(ctx.measureText(value).width + props.fontSize * 0.8)); - if (restoreValueFont) ctx.font = `normal ${props.fontSize * 4.2}px Daira by LTV grafika`; - return width; +function getBadgeWidth(ctx: CanvasRenderingContext2D, value: string, props: ResolutionPropsValue): number { + ctx.font = `bold ${props.fontSize}px Monda`; + return Math.max(props.boxSize, Math.ceil(ctx.measureText(value).width + props.fontSize * 0.8)); } -function drawOpticallyCenteredGlyph(ctx: CanvasRenderingContext2D, glyph: string, centerX: number, centerY: number): void { - const metrics = ctx.measureText(glyph); - ctx.textAlign = "left"; - ctx.textBaseline = "alphabetic"; - const x = centerX + (metrics.actualBoundingBoxLeft - metrics.actualBoundingBoxRight) / 2; - const y = centerY + (metrics.actualBoundingBoxAscent - metrics.actualBoundingBoxDescent) / 2; - ctx.fillText(glyph, x, y); +export function drawWeatherIcon(ctx: CanvasRenderingContext2D, image: HTMLImageElement, centerX: number, centerY: number, size: number): void { + ctx.drawImage(image, centerX - size / 2, centerY - size / 2, size, size); } function drawTitleOverlay(ctx: CanvasRenderingContext2D, title: string, source: string, canvasWidth: number): void { diff --git a/web/src/components/table/TableFour.tsx b/web/src/components/table/TableFour.tsx index 20cbbfb..5d78cb3 100644 --- a/web/src/components/table/TableFour.tsx +++ b/web/src/components/table/TableFour.tsx @@ -3,6 +3,8 @@ import { codeToIcon } from '../weatherIcons/iconConsts' import rigaBgUrl from '../../assets/bg-riga.webp' import arrowUrl from '../../assets/arrow.webp' import { drawRotatedImage, getAngleFromString } from '../map/windAngles' +import { getLoadedWeatherIcon, preloadWeatherIcons } from '../weatherIcons/weatherIconAssets' +import { drawWeatherIcon } from '../map/canvasDraw' type TableWeather = { hour: string, @@ -44,7 +46,7 @@ export const TableFour: Component<{ return { hour, temperature, windDirection, windSpeed, icon } }) - drawTable(canvas!, rigaBg, arrowImg, data, weekDayLV) + void preloadWeatherIcons(data.map(item => item.icon)).then(() => drawTable(canvas!, rigaBg, arrowImg, data, weekDayLV)) }) return <> @@ -82,8 +84,8 @@ function drawTable( ctx.fillStyle = '#FFFFFF' ctx.fillText(weather.hour, midX, rigaBg.height * 0.2) - ctx.font = `normal 240px Daira by LTV grafika` - ctx.fillText(weather.icon, midX, rigaBg.height * 0.5) + const iconImage = getLoadedWeatherIcon(weather.icon) + if (iconImage) drawWeatherIcon(ctx, iconImage, midX, rigaBg.height * 0.5, 220) ctx.font = 'normal 50px Monda' ctx.fillText(weather.temperature, midX, rigaBg.height * 0.75) diff --git a/web/src/components/table/TableTwo.tsx b/web/src/components/table/TableTwo.tsx index 7a60af5..c17cce2 100644 --- a/web/src/components/table/TableTwo.tsx +++ b/web/src/components/table/TableTwo.tsx @@ -3,6 +3,8 @@ import { codeToIcon } from '../weatherIcons/iconConsts' import table2BgUrl from '../../assets/bg-table2-left.webp' import arrowUrl from '../../assets/arrow.webp' import { drawRotatedImage, getAngleFromString } from '../map/windAngles' +import { getLoadedWeatherIcon, preloadWeatherIcons } from '../weatherIcons/weatherIconAssets' +import { drawWeatherIcon } from '../map/canvasDraw' type TableWeather = { temperature: string, @@ -50,7 +52,7 @@ export const TableTwo: Component<{ }, ] - drawTable(canvas!, table2Bg, arrowImg, data, weekDayLV) + void preloadWeatherIcons(data.map(item => item.icon)).then(() => drawTable(canvas!, table2Bg, arrowImg, data, weekDayLV)) }) return <> @@ -86,8 +88,8 @@ function drawTable( ctx.textAlign = 'center' ctx.fillStyle = '#FFFFFF' - ctx.font = `normal 240px Daira by LTV grafika` - ctx.fillText(weather.icon, midX, rigaBg.height * 0.4) + const iconImage = getLoadedWeatherIcon(weather.icon) + if (iconImage) drawWeatherIcon(ctx, iconImage, midX, rigaBg.height * 0.4, 220) ctx.font = 'normal 50px Monda' ctx.fillText(weather.temperature, midX, rigaBg.height * 0.7) diff --git a/web/src/components/weatherIcons/IconInputs.tsx b/web/src/components/weatherIcons/IconInputs.tsx index b71ef28..dc8fef9 100644 --- a/web/src/components/weatherIcons/IconInputs.tsx +++ b/web/src/components/weatherIcons/IconInputs.tsx @@ -1,7 +1,7 @@ import { Component, createSignal, For, Show, Signal } from "solid-js"; import { weatherIcons } from "./iconConsts"; import "../../css/weatherIcons.css"; -import { WeatherGlyph } from "./WeatherGlyph"; +import { WeatherIcon } from "./WeatherIcon"; export const IconInputs: Component<{cities: string[]; weatherIconsSignal: Signal>}> = (props) => { const [icons, setIcons] = props.weatherIconsSignal; @@ -11,9 +11,9 @@ export const IconInputs: Component<{cities: string[]; weatherIconsSignal: Signal const applyAll = () => setIcons(Object.fromEntries(props.cities.map(city => [city, selected()]))); return
-
Weather symbols

Choose one symbol, apply it broadly, then update the exceptions below.

-
{icon => }
+
Weather symbols

Choose one symbol, apply it broadly, then update the exceptions below.

+
{icon => }
City assignmentsUse the selected symbol for each exception.
-
{city =>
{city}{icon => }
}
+
{city =>
{city}{icon => }
}
; }; diff --git a/web/src/components/weatherIcons/WeatherGlyph.tsx b/web/src/components/weatherIcons/WeatherGlyph.tsx deleted file mode 100644 index 6cea938..0000000 --- a/web/src/components/weatherIcons/WeatherGlyph.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { Component, createEffect, onMount } from "solid-js"; - -export const WeatherGlyph: Component<{glyph: string; size?: number; tone?: "default" | "inverse"}> = (props) => { - let canvas!: HTMLCanvasElement; - const boxSize = () => props.size ?? 40; - const draw = async () => { - const size = boxSize(); - await document.fonts.load(`${Math.round(size * 0.82)}px "Daira by LTV grafika"`); - canvas.width = size; canvas.height = size; - const ctx = canvas.getContext("2d")!; - ctx.clearRect(0, 0, size, size); - ctx.font = `normal ${Math.round(size * 0.82)}px "Daira by LTV grafika"`; - ctx.fillStyle = props.tone === "inverse" ? "#ffffff" : "#17212d"; - ctx.textAlign = "left"; ctx.textBaseline = "alphabetic"; - const metrics = ctx.measureText(props.glyph); - const x = size / 2 + (metrics.actualBoundingBoxLeft - metrics.actualBoundingBoxRight) / 2; - const y = size / 2 + (metrics.actualBoundingBoxAscent - metrics.actualBoundingBoxDescent) / 2; - ctx.fillText(props.glyph, x, y); - }; - onMount(draw); - createEffect(() => { props.glyph; props.tone; boxSize(); if (canvas) void draw(); }); - return