### Serve the project with Python's HTTP server Source: https://deepwiki.com/Jermen592/hk-dashboard/1.1-getting-started-and-project-setup Start a local HTTP server on port 8080 using Python 3. Required to satisfy browser security requirements like Service Worker registration and CORS. ```bash python3 -m http.server 8080 ``` -------------------------------- ### GET /opendata.php?dataType=CLMTEMP Source: https://deepwiki.com/Jermen592/hk-dashboard/6.1-government-open-data-apis-%28data.gov.hk-and-hko%29 Retrieves historical daily mean temperatures for a given month. Used by Climate.fetchMonthData() in climate.js. ```APIDOC ## GET /opendata.php?dataType=CLMTEMP ### Description Retrieves historical daily mean temperatures for a given month. ### Method GET ### Endpoint https://data.weather.gov.hk/weatherAPI/opendata/opendata.php?dataType=CLMTEMP&year={YYYY}&month={MM} ### Parameters #### Path Parameters - **YYYY** (integer) - Required - Year (e.g., 2025). - **MM** (integer) - Required - Month (1-12). ### Response #### Success Response (200) - **data** (array) - Array of daily mean temperature values. #### Response Example { "data": [ 18.5, 19.0, 20.1, ... ] } ``` -------------------------------- ### GET /weather.php?dataType=fnd Source: https://deepwiki.com/Jermen592/hk-dashboard/6.1-government-open-data-apis-%28data.gov.hk-and-hko%29 Retrieves the 9-day weather forecast including daily max/min temperatures, humidity, and weather icons. Used by fetchForecast() in weather.js. ```APIDOC ## GET /weather.php?dataType=fnd ### Description Retrieves the 9-day weather forecast including daily max/min temperatures, humidity, and weather icons. ### Method GET ### Endpoint https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=fnd&lang=tc ### Parameters #### Query Parameters - **dataType** (string) - Required - Set to 'fnd' for 9-day forecast. - **lang** (string) - Optional - Language code, e.g., 'tc' for Traditional Chinese. ### Response #### Success Response (200) - **forecast** (array) - Array of daily forecast objects. - **forecastDate** (string) - Date of forecast. - **forecastMaxtemp** (number) - Maximum temperature. - **forecastMintemp** (number) - Minimum temperature. - **forecastMaxrh** (number) - Maximum relative humidity. - **forecastMinrh** (number) - Minimum relative humidity. - **ForecastIcon** (number) - Weather icon code. #### Response Example { "forecast": [ { "forecastDate": "20250301", "forecastMaxtemp": 25, "forecastMintemp": 20, "forecastMaxrh": 90, "forecastMinrh": 70, "ForecastIcon": 60 } ] } ``` -------------------------------- ### GET /opendata.php?dataType=HHOT Source: https://deepwiki.com/Jermen592/hk-dashboard/6.1-government-open-data-apis-%28data.gov.hk-and-hko%29 Retrieves hourly tide heights for a specified station and month. Used by Tides.fetchTideData() in tides.js. ```APIDOC ## GET /opendata.php?dataType=HHOT ### Description Retrieves hourly tide heights for a specified station and month. ### Method GET ### Endpoint https://data.weather.gov.hk/weatherAPI/opendata/opendata.php?dataType=HHOT&station={STATION}&year={YYYY}&month={MM} ### Parameters #### Path Parameters - **STATION** (string) - Required - Station code (e.g., 'Tuen Mun', 'Quarry Bay'). - **YYYY** (integer) - Required - Year (e.g., 2025). - **MM** (integer) - Required - Month (1-12). ### Response #### Success Response (200) - **data** (array) - Nested array of tide height values. #### Response Example { "data": [ [0.5, 0.6, 0.7, ...] ] } ``` -------------------------------- ### GET /weather.php?dataType=rhrread Source: https://deepwiki.com/Jermen592/hk-dashboard/6.1-government-open-data-apis-%28data.gov.hk-and-hko%29 Retrieves current weather data including air temperature, humidity, rainfall, UV index, and active weather warnings. Used by fetchCurrentWeather() in weather.js. ```APIDOC ## GET /weather.php?dataType=rhrread ### Description Retrieves current weather data including air temperature, humidity, rainfall, UV index, and active weather warnings. ### Method GET ### Endpoint https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=rhrread&lang=tc ### Parameters #### Query Parameters - **dataType** (string) - Required - Set to 'rhrread' for current weather. - **lang** (string) - Optional - Language code, e.g., 'tc' for Traditional Chinese. ### Response #### Success Response (200) - **temperature** (object) - Contains temperature readings from various stations. - **humidity** (object) - Humidity readings. - **rainfall** (object) - Rainfall data per district. - **uvindex** (object) - UV index data. - **warningMessage** (string) - Active weather warnings. #### Response Example { "temperature": { "data": [ { "place": "香港天文台", "value": "28", "unit": "C" } ] }, "humidity": { "data": [ { "place": "香港天文台", "value": "80", "unit": "%" } ] }, "rainfall": { "data": [ { "place": "中西區", "max": 0.5, "main": 0.2 } ] }, "uvindex": { "data": [ { "place": "京士柏", "value": 6, "desc": "高" } ] }, "warningMessage": "" } ``` -------------------------------- ### Serve the project with Node's npx serve Source: https://deepwiki.com/Jermen592/hk-dashboard/1.1-getting-started-and-project-setup Alternative way to serve the project locally using the npx serve command. Like Python, it provides HTTP access needed for the Service Worker and API fetches. ```bash npx serve . ``` -------------------------------- ### Clone the repository Source: https://deepwiki.com/Jermen592/hk-dashboard/1.1-getting-started-and-project-setup Clone the project from GitHub and enter its directory. Required before local development. ```bash git clone https://github.com/badboyhong/hk-dashboard.git cd hk-dashboard ``` -------------------------------- ### System Bootstrapping Sequence Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/1.1-getting-started-and-project-setup Mermaid sequence diagram showing the initialization flow: browser loads core.js and app.js, app.js initializes theme and navigation, initializes modules like Weather, and loads all data. Includes an auto-refresh lifecycle with tiered timers. ```mermaid sequenceDiagram participant B as Browser participant A as app.js participant C as core.js participant M as Modules (weather.js, etc.) B->>C: Load core.js (Theme/Clock) B->>A: Load app.js (DOM Content Loaded) A->>C: initTheme() & initNavigation() A->>M: Initialize Modules (e.g., Weather.init()) A->>A: loadAllData() loop Auto-Refresh Lifecycle A->>M: Module.refresh() (Tiered Timers) end ``` -------------------------------- ### Bootstrapping and Module Registration Sequence Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/2.2-app-orchestrator-and-data-refresh-lifecycle-%28app.js%29 Mermaid sequence diagram showing the bootstrapping flow: app.js calls showPage('home'), then loadAllData() triggers parallel refresh() calls on Weather, Transport, and Health modules, followed by initBusPresets() and startAutoRefresh(). ```mermaid sequenceDiagram participant App as "app.js (Orchestrator)" participant Core as "core.js (showPage)" participant W as "Weather.js" participant T as "Transport.js" participant B as "Bus.js" App->>Core: showPage("home") Note over App: Parallel Execution via loadAllData() par Weather App->>W: Weather.refresh() and Transport App->>T: Transport.refresh() and Health App->>App: safeRun("Health", Health.refresh) end App->>B: initBusPresets() App->>App: startAutoRefresh() ``` -------------------------------- ### CCTV Loading Logic Sequence Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/6.2-transport-and-third-party-apis Mermaid sequence diagram illustrating the dual-loading strategy for CCTV images: direct fetch attempt with cache-buster, fallback to AllOrigins proxy if direct fetch is blocked or errors. ```mermaid sequenceDiagram participant UI as cctv.js (loadCCTV) participant Proxy as AllOrigins Proxy participant TD as TD CCTV Server UI->>TD: Attempt Direct Fetch (with cache-buster) alt Direct Success TD-->>UI: Image Data else Direct Blocked/Error UI->>Proxy: Request via https://api.allorigins.win/raw?url=... Proxy->>TD: Server-side Fetch TD-->>Proxy: Image Bytes Proxy-->>UI: Proxied Image Bytes end ``` -------------------------------- ### System Data Flow Diagram (Mermaid) Source: https://deepwiki.com/Jermen592/hk-dashboard/6.1-government-open-data-apis-%28data.gov.hk-and-hko%29 Shows how `app.js` orchestrates feature modules (`weather.js`, `environment.js`, `parking.js`, `holidays.js`, `tides.js`) to fetch from government servers and update the UI via `core.js` helpers. ```mermaid graph TD subgraph "Government Servers" HKO["data.weather.gov.hk"] DGH["api.data.gov.hk"] OGCIO["1823 / OGCIO Assets"] end subgraph "Dashboard Core" APP["app.js (Orchestrator)"] CORE["core.js (UI Helpers)"] end subgraph "Feature Modules" WX["weather.js"] ENV["environment.js"] PK["parking.js"] HL["holidays.js"] TD["tides.js"] end APP -- "loadAllData()" --> WX APP -- "loadAllData()" --> ENV APP -- "loadAllData()" --> PK WX -- "fetch(rhrread)" --> HKO ENV -- "fetch(aqhi-forecast)" --> DGH PK -- "fetch(carpark-info-vacancy)" --> DGH HL -- "fetch(vcal)" --> OGCIO TD -- "fetch(HHOT)" --> HKO WX -- "setEl()" --> CORE PK -- "renderParks()" --> CORE ``` -------------------------------- ### UI Interaction to Function Mapping (Mermaid Diagram) Source: https://deepwiki.com/Jermen592/hk-dashboard/3.3-tides-earthquakes-and-forecast-text-%28tides.js%29 Mermaid diagram showing how UI actions (station select dropdown, initial page load) map to tides.js functions (Tides.refresh, Tides.changeStation, fetchTideData, fetchEarthquake, fetchForecastText). ```mermaid graph LR subgraph "UI Interaction" BTN["Station Select Dropdown"] LOAD["Initial Page Load"] end subgraph "tides.js Functions" REF["Tides.refresh()"] CS["Tides.changeStation(code)"] FET["fetchTideData()"] FEQ["fetchEarthquake()"] FFT["fetchForecastText()"] end BTN -- "onclick" --> CS CS -- "calls" --> REF LOAD -- "app.js calls" --> REF REF --> FET REF --> FEQ REF --> FFT ``` -------------------------------- ### AQHI Data-to-Style Flow (Mermaid) Source: https://deepwiki.com/Jermen592/hk-dashboard/2.3-design-system%3A-css-tokens-and-base-layout Mermaid diagram showing how AQHI API values are mapped to CSS tag classes via RISK_MAP and riskClass() in environment.js, then applied to .tag-green, .tag-yellow, and .tag-red in base.css. ```mermaid graph LR subgraph "Data Space (environment.js)" API["AQHI API Value"] Map["RISK_MAP"] Fn["riskClass()"] end subgraph "Visual Space (base.css)" Green[".tag-green"] Yellow[".tag-yellow"] Red[".tag-red"] end API --> Map Map --> Fn Fn -- "1-3" --> Green Fn -- "4-6" --> Yellow Fn -- "7+" --> Red ``` -------------------------------- ### CCTV Card Lifecycle Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/4.4-cctv-traffic-camera-module-%28cctv.js%29 A Mermaid diagram illustrating the state transitions of a CCTV camera card from initialization through image loading to maintenance. ```mermaid graph TD subgraph "Initialization" A["loadCCTV(key, label)"] --> B{"loadedKeys.has(key)?"} B -- "Yes" --> C["refreshCCTV(key)"] B -- "No" --> D["Create Card Element"] end subgraph "Image Loading" D --> E["Apply Skeleton Loader"] E --> F["cctvImgSrc(key)"] F --> G["Set img.src = proxy"] G --> H{"Image Status"} H -- "onload" --> I["Remove Skeleton & Show Image"] H -- "onerror" --> J["Retry with direct URL"] J -- "onerror" --> K["Display Error Placeholder"] end subgraph "Maintenance" I --> L["60s Auto-Refresh"] L --> C I --> M["removeCCTV(key)"] M --> N["loadedKeys.delete(key)"] end ``` -------------------------------- ### UI Rendering Lifecycle Sequence Source: https://deepwiki.com/Jermen592/hk-dashboard/3-dashboard-modules-weather-and-environment A sequence diagram illustrating the interaction between the application, module logic, and the DOM during data refresh and rendering. ```mermaid sequenceDiagram participant App as app.js participant Mod as Module (e.g., weather.js) participant DOM as index.html App->>Mod: refresh() Mod->>API: fetch(url) API-->>Mod: JSON Data Mod->>Mod: parse & normalize Mod->>DOM: renderHomeView() -> update #h-weather Mod->>DOM: renderFullView() -> update #w-page ``` -------------------------------- ### showPage Hook Flow (Mermaid Diagram) Source: https://deepwiki.com/Jermen592/hk-dashboard/2.2-app-orchestrator-and-data-refresh-lifecycle-%28app.js%29 Illustrates the data flow for page changes, showing how showPage in core.js triggers the app.js hook, which conditionally refreshes Weather and Transport immediately, and checks the _parkingLoaded flag before refreshing Parking. ```mermaid graph TD subgraph "core.js" A["showPage(name)"] end subgraph "app.js Hooks" B{"Switch(name)"} C["Weather.refresh()"] D["Transport.refresh()"] E{"_parkingLoaded?"} F["Parking.refresh()"] end A --> B B -- "weather" --> C B -- "transport" --> D B -- "parking" --> E E -- "false" --> F E -- "true" --> G["Display Cached View"] ``` -------------------------------- ### MapView data integration diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/5-dashboard-modules-health-community-and-lifestyle Mermaid diagram showing how MapView's loadLayer(type) routes to external data sources (parking, AQHI, beach) and how createMap(container) checks the document theme. ```mermaid graph LR subgraph "js/map.js (MapView)" ML["loadLayer(type)"] MC["createMap(container)"] end subgraph "External Integration" ML -- "type: 'parking'" --> P_DATA["api.data.gov.hk/.../carpark"] ML -- "type: 'aqhi'" --> A_DATA["AQHI_STATIONS constant"] ML -- "type: 'beach'" --> B_DATA["Beach.BEACHES (beach.js)"] end MC -- "Theme Check" --> THEME["document.documentElement (data-theme)"] ``` -------------------------------- ### MapView Layer Switching Sequence Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/5.6-interactive-map-module-%28map.js%29 Sequence diagram illustrating the interaction between the UI tabs, MapView module, Leaflet engine, and the government API when switching layers. Shows the flow from switchLayer('parking') through loadLayer, layer removal, data fetch, merging, and adding circle markers for each carpark. ```mermaid sequenceDiagram participant UI as "User Interface (Tabs)" participant MV as "MapView Module" participant L as "Leaflet Engine" participant API as "Government API" UI->>MV: switchLayer('parking') activate MV MV->>MV: loadLayer('parking') MV->>L: removeLayer(current) MV->>API: fetch(parking-vacancy) API-->>MV: JSON Data MV->>MV: Merge Vacancy + Info loop Each Carpark MV->>L: L.circleMarker().addTo(map) end deactivate MV ``` -------------------------------- ### Module Architecture Overview (Mermaid diagram) Source: https://deepwiki.com/Jermen592/hk-dashboard/5-dashboard-modules-health-community-and-lifestyle Mermaid diagram illustrating the relationships between UI components, logic modules, and external data sources for the health, beach, finance, holidays, and map modules. ```mermaid graph TD subgraph "UI Layer (index.html)" AED_UI["#h-aed-full (AED Waiting Times)"] BEACH_UI["#beach-list (Beach Quality)"] FIN_UI["#fin-hsi (Finance/HSI)"] HOL_UI["#holidays-list (Holidays)"] MAP_UI["#map-container (Interactive Map)"] end subgraph "Logic Layer" H_MOD["Health (health.js)"] B_MOD["Beach (beach.js)"] F_MOD["Finance (finance.js)"] HO_MOD["Holidays (holidays.js)"] M_MOD["MapView (map.js)"] end H_MOD --> AED_UI B_MOD --> BEACH_UI F_MOD --> FIN_UI HO_MOD --> HOL_UI M_MOD --> MAP_UI subgraph "External Data Sources" HA_API["HA A&E JSON"] EPD_DATA["EPD Static/Manual"] Y_FIN["Yahoo Finance"] GOV_1823["1823 iCal API"] end HA_API -.-> H_MOD EPD_DATA -.-> B_MOD Y_FIN -.-> F_MOD GOV_1823 -.-> HO_MOD ``` -------------------------------- ### Climate Module Class Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/3.4-climate-module-historical-data-and-visualizations-%28climate.js%29 A Mermaid class diagram illustrating the relationships between the ClimateModule, DataFetchers, and Renderers components. ```mermaid classDiagram class ClimateModule { +CLIMATE_FACTS Array +NORMALS_1991_2020 Array +init() +refresh() } class DataFetchers { +fetchYearlyData() +HKO_BASE String } class Renderers { +renderFacts() +renderNormals() +renderMonthlyBarChart() +renderTempChart() +buildSparkline() } ClimateModule -- DataFetchers : orchestrates ClimateModule -- Renderers : updates UI Renderers -- buildSparkline : uses for SVG ``` -------------------------------- ### Core Orchestration Flow Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/2-core-architecture Mermaid diagram illustrating how the core files (index.html, core.js, app.js, sw.js) interact to bootstrap the application and manage data updates, including module refresh intervals. ```mermaid graph TD subgraph "Entry Point" Index["index.html"] end subgraph "Infrastructure Layer" Core["js/core.js"] App["js/app.js"] SW["sw.js"] end subgraph "Module Layer" Weather["Weather.refresh()"] Transport["Transport.refresh()"] Bus["Bus.refresh()"] Others["Other Modules..."] end Index -- "Loads" --> Core Index -- "Loads" --> App Index -- "Registers" --> SW App -- "Initial Boot" --> LoadAll["loadAllData()"] App -- "Orchestrates" --> StartAuto["startAutoRefresh()"] LoadAll --> Weather LoadAll --> Transport StartAuto -- "10s Interval" --> Transport StartAuto -- "45s Interval" --> Bus StartAuto -- "60s Interval" --> Weather Core -- "UI Control" --> ShowPage["showPage()"] ShowPage -- "Intercepts" --> AppHook["_origShowPage Hook"] AppHook -- "Lazy Refresh" --> Others ``` -------------------------------- ### Station Configuration Array (STATIONS) Source: https://deepwiki.com/Jermen592/hk-dashboard/3.3-tides-earthquakes-and-forecast-text-%28tides.js%29 Defines the list of monitoring stations with their codes and names. Used to populate the station select dropdown. ```javascript const STATIONS = [ { code:'CCH', name:'鰂魚涌 Quarry Bay' }, { code:'CLK', name:'赤鱲角 Chek Lap Kok' }, { code:'KCT', name:'昂船洲 Stonecutters Is.' }, { code:'MWC', name:'馬灣 Ma Wan' }, { code:'TBT', name:'大埔滘 Tai Po Kau' }, { code:'TPK', name:'塔門 Tap Mun' }, { code:'TMW', name:'屯門 Tuen Mun' }, ]; ``` -------------------------------- ### Mermaid class diagram: API to code entity mapping Source: https://deepwiki.com/Jermen592/hk-dashboard/6.1-government-open-data-apis-%28data.gov.hk-and-hko%29 Shows the relationships between HKO and data.gov.hk API endpoints and the internal JavaScript classes (WeatherModule, TidesModule, ParkingModule) that consume them. The diagram uses Mermaid syntax and is intended for rendering in a Markdown viewer. ```mermaid classDiagram class HKO_API { <> rhrread fnd HHOT CLMTEMP } class DataGovHK_API { <> aqhi-forecast carpark-vacancy 1823-holidays } class WeatherModule { +fetchCurrentWeather() +renderRainfall() +WX_DESC } class TidesModule { +fetchTideData() +parseTideToday() +STATIONS } class ParkingModule { +fetchAllParking() +applyFilter() +DISTRICTS } HKO_API --|> WeatherModule : rhrread/fnd HKO_API --|> TidesModule : HHOT DataGovHK_API --|> ParkingModule : vacancy/info ``` -------------------------------- ### Holidays Module Architecture Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/5.4-holidays-and-solar-terms-module-%28holidays.js%29 A Mermaid diagram illustrating the data flow from external APIs and static sources through the normalization engine to the UI components. ```mermaid graph TD subgraph "Data Acquisition" API["1823 iCal JSON API"] STATIC["STATIC_HOLIDAYS (2024-2026)"] SOLAR["SOLAR_TERMS Registry"] end subgraph "Normalization Engine" FETCH["Holidays.refresh()"] PARSE_D["parseDtstart()"] PARSE_S["parseSummary()"] FMT["fmtDate()"] end subgraph "UI Components" BANNER["Today Holiday Banner"] COUNT["Countdown Widget"] LIST["Upcoming List (Top 5)"] YEAR_VIEW["Yearly Calendar View"] end API --> FETCH STATIC --> FETCH FETCH --> PARSE_D FETCH --> PARSE_S PARSE_D --> FMT FMT --> BANNER FMT --> COUNT FMT --> LIST SOLAR --> YEAR_VIEW FMT --> YEAR_VIEW ``` -------------------------------- ### Visual Component Hierarchy Mermaid Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/3.2-environment-module-aqhi-%28environment.js%29 A visual representation of the environment module functions and their relationship with CSS design tokens. ```mermaid graph TD subgraph "environment.js Functions" ENV_OBJ["window.Environment"] REFRESH["refresh()"] RENDER_C["renderAQHICard(r)"] RENDER_M["renderAQHIMini(r)"] end subgraph "CSS Design Tokens (tokens.css)" SUCCESS["--success / --success-bg"] WARNING["--warning / --warning-bg"] ERROR["--error / --error-bg"] end ENV_OBJ --> REFRESH REFRESH --> RENDER_C REFRESH --> RENDER_M RENDER_C -- "n <= 3" --> SUCCESS RENDER_C -- "3 < n <= 6" --> WARNING RENDER_C -- "n > 6" --> ERROR ``` -------------------------------- ### Logic Flow: Filter and Render Mermaid Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/5.2-beach-water-quality-module-%28beach.js%29 A diagram illustrating how user interactions with UI components flow through the Beach API to update the DOM. ```mermaid graph TD subgraph "UI Layer" SearchInput["#beach-search"] RegionButtons["Region Filter Buttons"] BeachList["#beach-list"] Summary["#beach-summary"] end subgraph "Logic (beach.js)" FS["Beach.filterSearch()"] SR["Beach.setRegion()"] RB["renderBeaches()"] RS["renderSummary()"] State["_selectedRegion (Variable)"] end subgraph "Data Space" B_DATA["BEACHES Array"] S_DATA["TYPICAL_SPRING Map"] end SearchInput -- "oninput" --> FS RegionButtons -- "onclick" --> SR FS --> RB SR --> State State --> RB RB --> B_DATA RB --> S_DATA RB --> BeachList RS --> Summary ``` -------------------------------- ### Data Entity Mapping Mermaid Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/5.2-beach-water-quality-module-%28beach.js%29 A diagram mapping natural language concepts of beach monitoring to specific code entities within beach.js. ```mermaid graph LR subgraph "Natural Language Space" Location["42 Statutory Beaches"] Area["Geographic Regions"] Safety["Water Quality Grade"] Status["Bacteriological Info"] end subgraph "Code Entity Space (beach.js)" BEACHES["BEACHES (Array of Objects)"] GRADES["GRADES (Lookup Object)"] TYPICAL_SPRING["TYPICAL_SPRING (Static Map)"] getRegions["getRegions() (Utility)"] end Location --> BEACHES Area --> getRegions Safety --> GRADES Status --> TYPICAL_SPRING ``` -------------------------------- ### Climate Data Flow Diagram (Mermaid) Source: https://deepwiki.com/Jermen592/hk-dashboard/3.4-climate-module-historical-data-and-visualizations-%28climate.js%29 Mermaid diagram showing the relationship between the HKO API, the climate module's internal functions, and the visual engines. It illustrates the data flow from Climate.init() to refresh, which triggers fetchYearlyData, renderFacts, and renderNormals, and then to the monthly and temperature charts. ```mermaid graph TD subgraph "HKO API" CLMTEMP["CLMTEMP Endpoint"] end subgraph "Climate Module (climate.js)" init["Climate.init()"] refresh["Climate.refresh()"] fetchYearly["fetchYearlyData()"] renderFacts["renderFacts()"] renderNormals["renderNormals()"] renderMonthly["renderMonthlyBarChart()"] renderTemp["renderTempChart()"] end subgraph "Visual Engines" sparkline["buildSparkline()"] colorInt["RGB Interpolation"] end init --> refresh refresh --> fetchYearly refresh --> renderFacts refresh --> renderNormals fetchYearly --> CLMTEMP CLMTEMP -- "12 Monthly JSONs" --> fetchYearly fetchYearly --> renderMonthly fetchYearly --> renderTemp renderTemp --> sparkline renderTemp --> colorInt ``` -------------------------------- ### Issue to Code Entity Mapping Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/1.2-contributing-and-issue-reporting A Mermaid diagram illustrating the workflow from GitHub issue templates to specific project code modules. ```mermaid graph TD subgraph "Natural Language Space (GitHub Issues)" A["[BUG] Template"] -- "Labels: bug" --> B["Bug Report"] C["[FEATURE] Template"] -- "Labels: enhancement" --> D["Feature Request"] end subgraph "Code Entity Space (Project Implementation)" B --> E["Logic Debugging (JS Modules)"] B --> F["Layout Fixes (CSS Tokens/Base)"] D --> G["API Integration (New .js Module)"] D --> H["Navigation Entry (index.html)"] end E -.-> I["weather.js, transport.js, etc."] F -.-> J["tokens.css, base.css"] G -.-> K["New Data Fetcher"] H -.-> L["showPage() in core.js"] ``` -------------------------------- ### Contribution Data Flow Sequence Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/1.2-contributing-and-issue-reporting A Mermaid sequence diagram illustrating the interaction between contributors, the GitHub issue tracker, and maintainers during the contribution lifecycle. ```mermaid sequenceDiagram participant C as Contributor participant G as GitHub Issue Tracker participant M as Maintainer participant L as LICENSE (MIT) C->>G: Submit bug_report.md (Include Device/Steps) C->>G: Submit feature_request.md (Include data.gov.hk API) G->>M: Review Label (bug/enhancement) M->>C: Request PR or Additional Context C->>L: Agree to MIT License terms M->>G: Close Issue / Merge PR ``` -------------------------------- ### Visual to Code Mapping Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/7-glossary A Mermaid diagram illustrating the relationship between UI components, CSS classes in base.css, and JavaScript logic in core.js or weather.js. ```mermaid graph LR subgraph "Visual UI" V1["Temperature Badge"] V2["Loading State"] V3["Warning Banner"] V4["Navigation Tab"] end subgraph "CSS Classes (base.css)" C1[".tag-blue"] C2[".skel"] C3[".warn-strip"] C4[".nav-tab.active"] end subgraph "JS Logic (core.js / weather.js)" J1["aqhiClass(val)"] J2["window.skelHtml()"] J3["renderCurrentWeather()"] J4["showPage(name)"] end V1 --- C1 --- J1 V2 --- C2 --- J2 V3 --- C3 --- J3 V4 --- C4 --- J4 ``` -------------------------------- ### Warning Banner Logic Flow Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/3.1-weather-module-%28weather.js%29 Mermaid diagram illustrating the logic flow for the warning banner. It shows how fetchWarnings() fetches the warnsum API, checks for active warnings, and either hides the banner or fetches warningInfo API to loop through warning statements, map codes to CSS classes, and update the DOM. ```mermaid graph TD Start["fetchWarnings()"] --> Summary["Fetch warnsum API"] Summary --> CheckActive{"Any Active Warnings?"} CheckActive -- "No" --> Hide["Hide warning-banner element"] CheckActive -- "Yes" --> Details["Fetch warningInfo API"] Details --> Loop["Loop through warningStatement"] Loop --> MapStyle["Map code to CSS (warn-red/orange/yellow)"] MapStyle --> BuildHTML["Generate banner-item chips"] BuildHTML --> Inject["Update DOM #warning-banner"] ``` -------------------------------- ### Data Lifecycle Diagram (Mermaid) Source: https://deepwiki.com/Jermen592/hk-dashboard/7-glossary Mermaid diagram showing the data flow from triggers (DOMContentLoaded, setInterval, showPage) through loadAllData(), safeRun(), module refresh, fetch, renderData, setEl, and finally to the DOM element div#w-temp. ```mermaid graph TD subgraph "Trigger Space" A["DOMContentLoaded Event"] --> B["loadAllData()"] C["setInterval (10s/60s/300s)"] --> B D["showPage(name)"] --> E["Module.refresh()"] end subgraph "Code Entity Space (app.js)" B --> F["safeRun(label, fn)"] F --> E end subgraph "Module Logic (e.g., weather.js)" E --> G["fetch(API_URL)"] G --> H["renderData(json)"] H --> I["setEl(id, val)"] end subgraph "DOM Space (index.html)" I --> J["div#w-temp"] end ``` -------------------------------- ### Collection Status Logic Flow (Mermaid diagram) Source: https://deepwiki.com/Jermen592/hk-dashboard/5.5-waste-and-recycling-module-%28waste.js%29 Mermaid diagram illustrating the logic of getCollectionStatus() and renderCollectionStatus(). Shows decision branches for day of week and hour, and how status updates the DOM with CSS variables. ```mermaid graph TD subgraph "Logic Engine: getCollectionStatus()" A["new Date()"] --> B{"Day of Week?"} B -- "1-6 (Mon-Sat)" --> C{"Hour 07-18?"} B -- "0 (Sun)" --> D["Status: Sunday Rest"] C -- "Yes" --> E["Status: Ongoing"] C -- "No" --> F["Status: Pending/Finished"] end subgraph "UI Rendering: renderCollectionStatus()" E --> G["Update #waste-collection-status"] F --> G D --> G end G --> H["Apply CSS Variables (e.g., --success, --text-muted)"] ``` -------------------------------- ### System Connectivity Diagram (Mermaid) Source: https://deepwiki.com/Jermen592/hk-dashboard/6-external-api-reference Mermaid graph showing the high-level data flow from external REST API providers to internal JavaScript modules. It maps each provider to its consuming module and indicates the API endpoints used. ```mermaid graph TD subgraph "External Providers (REST APIs)" HKO["data.weather.gov.hk"] DGH["api.data.gov.hk"] MTR["rt.data.gov.hk"] KMB["data.etabus.gov.hk"] HA["ha.org.hk"] YF["query1.finance.yahoo.com"] end subgraph "Dashboard Core (js/)" Weather["weather.js"] Transport["transport.js"] Bus["bus.js"] Health["health.js"] Finance["finance.js"] Parking["parking.js"] end HKO -->|"rhrread / fnd"| Weather DGH -->|"carpark-info-vacancy"| Parking MTR -->|"mtr/getSchedule"| Transport KMB -->|"kmb/eta"| Bus HA -->|"aedwtdata2-tc.json"| Health YF -->|"v8/finance/chart"| Finance Weather -.->|"relativeTime()"| Health Parking -.->|"park_Id merge"| MapView["map.js"] ``` -------------------------------- ### CCTV Code Entity Mapping Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/4.4-cctv-traffic-camera-module-%28cctv.js%29 A Mermaid diagram illustrating the relationship between UI components and the corresponding functions and data structures in cctv.js. ```mermaid graph LR subgraph "User Interface" BTN_ALL["'Load All' Button"] BTN_SINGLE["Camera Area Button"] BTN_REF["'↻' Button"] BTN_REM["'✕' Button"] INP_CODE["Manual Code Input"] end subgraph "Logic (js/cctv.js)" F_ALL["loadAllCCTV()"] F_LOAD["loadCCTV()"] F_REF["refreshCCTV()"] F_REM["removeCCTV()"] F_INP["loadCCTVInput()"] REGISTRY["CCTV_CAMERAS"] S_KEYS["loadedKeys (Set)"] end BTN_ALL --> F_ALL F_ALL -- "loops" --> REGISTRY F_ALL -- "calls" --> F_LOAD BTN_SINGLE --> F_LOAD BTN_REF --> F_REF BTN_REM --> F_REM INP_CODE --> F_INP F_INP --> F_LOAD F_LOAD -- "updates" --> S_KEYS F_REM -- "cleans" --> S_KEYS ``` -------------------------------- ### Navigation Event Flow Diagram (Mermaid) Source: https://deepwiki.com/Jermen592/hk-dashboard/2.1-application-shell-and-page-navigation-%28index.html-%2B-core.js%29 Mermaid diagram illustrating the navigation event flow between the HTML navigation triggers (top nav tabs, bottom nav items, and logo) and the core.js showPage() logic, including the visual state changes. ```mermaid graph TD subgraph "DOM (index.html)" A["nav-tab (Top Nav)"] -- "onclick" --> SP["showPage(name)"] B["bottom-nav-item"] -- "onclick" --> SP C["topnav-logo"] -- "onclick" --> SP end subgraph "Logic (core.js)" SP --> D["Remove .active from all .page"] SP --> E["Add .active to page-ID"] SP --> F["Update window._currentPage"] SP --> G["scrollIntoView (Active Tab)"] end subgraph "Visual State" E --> H["CSS: display: block"] D --> I["CSS: display: none"] end ``` -------------------------------- ### Weather & Environment Entity Map Mermaid Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/3-dashboard-modules-weather-and-environment A visual representation mapping functional requirements to JavaScript modules, specific fetch functions, and their corresponding API endpoints. ```mermaid graph TD subgraph "Natural Language Space" A["Real-time Weather"] B["Air Quality (AQHI)"] C["Tide Charts"] D["Historical Climate"] end subgraph "Code Entity Space (JavaScript)" A --> WX["weather.js"] B --> ENV["environment.js"] C --> TIDE["tides.js"] D --> CLIM["climate.js"] WX --> F1["fetchCurrentWeather()"] WX --> F2["fetchForecast()"] ENV --> F3["fetchAQHI()"] TIDE --> F4["fetchTides()"] CLIM --> F5["fetchClimateData()"] end subgraph "Data Layer (API)" F1 -- "rhrread" --> HKO["HKO Weather API"] F2 -- "fnd" --> HKO F3 -- "aqhi-forecast.json" --> EPD["EPD Data"] F4 -- "HHOT" --> HKO F5 -- "CLMTEMP" --> HKO end ``` -------------------------------- ### Transport System Mapping Diagram Source: https://deepwiki.com/Jermen592/hk-dashboard/6.2-transport-and-third-party-apis Mermaid diagram mapping transport system concepts to code implementations and external API endpoints. Shows relationships between natural language entities, code functions, and API URLs. ```mermaid graph TD subgraph "Natural Language Space" MTR["MTR Heavy Rail"] LRT["Light Rail"] Bus["Franchised Bus"] Ferry["NLB Ferry"] end subgraph "Code Entity Space (transport.js / bus.js / ferry.js)" MTR_F["fetchMTR()"] LRT_F["fetchLRT()"] Bus_P["Bus.loadPreset()"] Bus_S["BusSearch.loadStopEta()"] Ferry_R["Ferry.refresh()"] end subgraph "External API Space" MTR_API["rt.data.gov.hk/v1/transport/mtr"] LRT_API["rt.data.gov.hk/v1/transport/mtr/lrt"] KMB_API["data.etabus.gov.hk"] CTB_API["rt.data.gov.hk/v2/transport/citybus"] NLB_API["rt.data.gov.hk/v1/transport/nlb"] end MTR --> MTR_F LRT --> LRT_F Bus --> Bus_P Bus --> Bus_S Ferry --> Ferry_R MTR_F --> MTR_API LRT_F --> LRT_API Bus_P --> KMB_API Bus_P --> CTB_API Bus_S --> KMB_API Ferry_R --> NLB_API ``` -------------------------------- ### Data Refresh Hierarchy (Mermaid diagram) Source: https://deepwiki.com/Jermen592/hk-dashboard/2-core-architecture Mermaid diagram showing the data refresh hierarchy: high-frequency (10-45s) for Transport and Bus, standard (60s) for Weather, Health, Environment, and on-demand/lazy for Parking, Ferry, Climate. App.js triggers refresh, core.js showPage triggers app, and app triggers parking if page active. ```mermaid graph LR subgraph "High Frequency (10-45s)" T["Transport.refresh()"] B["Bus.refresh()"] end subgraph "Standard Frequency (60s)" W["Weather.refresh()"] H["Health.refresh()"] E["Environment.refresh()"] end subgraph "On-Demand / Lazy" P["Parking.refresh()"] F["Ferry.refresh()"] C["Climate.refresh()"] end App["js/app.js"] --> T App --> B App --> W Core["js/core.js::showPage"] -- "Trigger" --> App App -- "If Page Active" --> P ``` -------------------------------- ### Transport Data Mapping (Mermaid) Source: https://deepwiki.com/Jermen592/hk-dashboard/6-external-api-reference Mermaid graph mapping transport API endpoints (MTR, LRT, KMB, CTB) to their consuming JavaScript functions. It shows which functions fetch data from which endpoints. ```mermaid graph LR subgraph "API Endpoints" MTR_ETA["rt.data.gov.hk/.../getSchedule.php"] LRT_ETA["rt.data.gov.hk/.../lrt/getSchedule"] KMB_ETA["data.etabus.gov.hk/.../kmb/eta"] CTB_ETA["rt.data.gov.hk/.../citybus/eta"] end subgraph "JS Consumption" fetchMTR["fetchMTR()"] fetchLRT["fetchLRT()"] loadPreset["loadPreset()"] end MTR_ETA --> fetchMTR LRT_ETA --> fetchLRT KMB_ETA --> loadPreset CTB_ETA --> loadPreset ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.