Helpers for syncing workspace selection with URL query parameters. Enables shareable URLs and browser back/forward navigation for workspace changes.
Utility helpers for lead time calculations and date comparisons. Centralizes logic for working with forecast target dates and lead times.
Generic formatting utilities for dates, numbers, and entity names. Provides consistent formatting across the application for display purposes.
Date parsing and formatting utilities for forecast dates. Handles various date formats used by the API and provides consistent parsing/formatting.
Common guard and helper functions shared across context providers. Reduces duplication and provides validation logic for method/workspace selections.
Color utilities for visualizing forecast values on maps and charts. Provides a color gradient from white -> cyan -> green -> yellow -> red based on normalized values.
Central TTL (Time-To-Live) presets for cached API requests. All values are in milliseconds. Adjust these if backend freshness requirements change.
Helpers to normalize varied API response shapes into predictable structures. The API may return data in different formats depending on the endpoint or version. These functions ensure consistent data structures for the UI layer.
Helpers for syncing workspace selection with URL query parameters. Enables shareable URLs and browser back/forward navigation for workspace changes.
stringfunctionstringReads the workspace key from the current URL query parameters.
Kind: static method of utils/urlWorkspaceUtils
Returns: string - Workspace key from URL, or empty string if not present
Example
// URL: /?workspace=demo
readWorkspaceFromUrl() // Returns: "demo"
Updates the URL query parameter with the selected workspace key. Uses pushState to update the URL without page reload.
Kind: static method of utils/urlWorkspaceUtils
| Param | Type | Description |
|---|---|---|
| next | string |
Workspace key to set, or empty/null to remove parameter |
Example
writeWorkspaceToUrl('demo') // Updates URL to: /?workspace=demo
writeWorkspaceToUrl(null) // Removes workspace parameter from URL
functionRegisters a handler for browser back/forward navigation to sync workspace changes.
Kind: static method of utils/urlWorkspaceUtils
Returns: function - Cleanup function to remove the event listener
| Param | Type | Description |
|---|---|---|
| handler | function |
Callback function that receives the workspace key from URL |
Example
const cleanup = onWorkspacePopState((workspaceKey) => {
console.log('Workspace changed via navigation:', workspaceKey);
setCurrentWorkspace(workspaceKey);
});
// Later, when component unmounts:
cleanup();
Utility helpers for lead time calculations and date comparisons. Centralizes logic for working with forecast target dates and lead times.
Array.<number>Sub-daily hour intervals for forecast resolution.
Kind: static constant of utils/targetDateUtils
stringCreates a stable YYYY-M-D key string for a date. Note: Month is 0-based as per JavaScript Date API.
Kind: static method of utils/targetDateUtils
Returns: string - Date key in format "YYYY-M-D", or empty string if invalid
| Param | Type | Description |
|---|---|---|
| date | Date |
Date object to convert to key |
Example
makeDayKey(new Date(2025, 10, 5)) // Returns: "2025-10-5"
DateParses a YYYY-M-D key string back to a Date object. Month is treated as 0-based (JavaScript Date convention).
Kind: static method of utils/targetDateUtils
Returns: Date - Date object, or Invalid Date if parsing fails
| Param | Type | Description |
|---|---|---|
| key | string |
Date key in format "YYYY-M-D" |
Example
parseDayKey("2025-10-5") // Returns: Date object for November 5, 2025
numberCompute lead hours given either a base date + target date (preferred) or fallback indices. Applies timezone offset adjustment when both dates are provided to keep consistent hour differences.
Kind: static method of utils/targetDateUtils
Returns: number - non-negative integer lead hours
| Param | Type |
|---|---|
| forecastBaseDate | Date | null |
| selectedTargetDate | Date | null |
| leadResolution | 'daily' | 'sub' |
| selectedLead | number |
| dailyLeads | Array.<{time_step:number, date:Date}> |
| subDailyLeads | Array.<{time_step:number, date:Date}> |
Compare two dates on calendar day only.
Kind: static method of utils/targetDateUtils
Strict timestamp equality (ms).
Kind: static method of utils/targetDateUtils
Determine if target date is present among leads given resolution.
Kind: static method of utils/targetDateUtils
Generic formatting utilities for dates, numbers, and entity names. Provides consistent formatting across the application for display purposes.
stringstringstringnumberstringstringFormat a Date or date-like value to DD.MM.YYYY format (e.g., 05.11.2025). Returns empty string on invalid input.
Kind: static method of utils/formattingUtils
Returns: string - Formatted date string or empty string if invalid
| Param | Type | Description |
|---|---|---|
| dateLike | Date | string | number |
Date object, timestamp, or date string |
Example
formatDateDDMMYYYY(new Date('2025-11-05')) // Returns: "05.11.2025"
formatDateDDMMYYYY('2025-11-05') // Returns: "05.11.2025"
formatDateDDMMYYYY(null) // Returns: ""
stringFormats precipitation value to string with one decimal place.
Kind: static method of utils/formattingUtils
Returns: string - Formatted string: number with 1 decimal, '0' for zero, '-' for null/undefined
| Param | Type | Description |
|---|---|---|
| value | number | string | null |
Precipitation value to format |
Example
formatPrecipitation(25.67) // Returns: "25.7"
formatPrecipitation(0) // Returns: "0"
formatPrecipitation(null) // Returns: "-"
stringFormats a criteria/score value to string with two decimal places.
Kind: static method of utils/formattingUtils
Returns: string - Formatted string with 2 decimals, or '-' for null/undefined
| Param | Type | Description |
|---|---|---|
| value | number | string | null |
Criteria value to format |
Example
formatCriteria(0.12345) // Returns: "0.12"
formatCriteria(null) // Returns: "-"
numberCompares two entity objects by name for sorting, case-insensitive. Falls back to comparing by id if name is not available.
Kind: static method of utils/formattingUtils
Returns: number - -1 if a < b, 1 if a > b, 0 if equal
| Param | Type | Description |
|---|---|---|
| a | Object |
First entity with name and/or id |
| b | Object |
Second entity with name and/or id |
Example
const entities = [{name: "Station B"}, {name: "Station A"}];
entities.sort(compareEntitiesByName);
// Results in: [{name: "Station A"}, {name: "Station B"}]
stringFormats a Date into a display label with optional time component. Includes time (HH:MM) only if hours or minutes are non-zero.
Kind: static method of utils/formattingUtils
Returns: string - Formatted string "DD.MM.YYYY" or "DD.MM.YYYY HH:MM"
| Param | Type | Description |
|---|---|---|
| date | Date | string | number |
Date object, timestamp, or date string |
Example
formatDateLabel(new Date('2025-11-05T00:00')) // Returns: "05.11.2025"
formatDateLabel(new Date('2025-11-05T14:30')) // Returns: "05.11.2025 14:30"
Date parsing and formatting utilities for forecast dates. Handles various date formats used by the API and provides consistent parsing/formatting.
Date | nullstring | nullDate | nullParses various forecast date string formats into a JavaScript Date object.
Supported formats:
Kind: static method of utils/forecastDateUtils
Returns: Date | null - Parsed Date object, or null if parsing fails
| Param | Type | Description |
|---|---|---|
| str | string |
Date string to parse |
Example
parseForecastDate("2023-01-15T12") // Returns: Date object for Jan 15, 2023 12:00
parseForecastDate("2023011512") // Returns: Date object for Jan 15, 2023 12:00
parseForecastDate("invalid") // Returns: null
string | nullFormats a Date object to a string format suitable for API requests. The output format is determined by examining a reference string format.
Output formats based on reference:
Kind: static method of utils/forecastDateUtils
Returns: string | null - Formatted date string, or null if invalid date
| Param | Type | Description |
|---|---|---|
| dateObj | Date |
Date object to format |
| [reference] | string |
Reference format string to match |
Example
formatForecastDateForApi(new Date('2023-01-15T12:00'), '2023-01-01T00')
// Returns: "2023-01-15T12"
formatForecastDateForApi(new Date('2023-01-15T12:00'), '2023-01-01')
// Returns: "2023-01-15 12:00"
Common guard and helper functions shared across context providers. Reduces duplication and provides validation logic for method/workspace selections.
booleanbooleanstring | number | nullstringstringstringbooleanValidates that a selected method/config belongs to the current workspace.
Kind: static method of utils/contextGuards
Returns: boolean - True if selection is valid for this workspace
| Param | Type | Description |
|---|---|---|
| selectedMethodConfig | Object |
The selected method and config object |
| workspace | string |
Current workspace key |
booleanChecks if a method ID exists in the method configuration tree.
Kind: static method of utils/contextGuards
Returns: boolean - True if method exists in tree
| Param | Type | Description |
|---|---|---|
| methodConfigTree | Array |
Array of method objects with id property |
| methodId | string | number |
Method ID to search for |
string | number | nullDerives a configuration ID from selected method, falling back to first config.
Kind: static method of utils/contextGuards
Returns: string | number | null - Configuration ID, or null if not found
| Param | Type | Description |
|---|---|---|
| selectedMethodConfig | Object |
Selected method and config object |
| methodConfigTree | Array |
Full method configuration tree |
stringComposes a cache key for entities data.
Kind: static method of utils/contextGuards
Returns: string - Composed cache key
| Param | Type | Description |
|---|---|---|
| workspace | string |
Workspace key |
| forecastDate | string |
Forecast date string |
| methodId | string | number |
Method ID |
| configId | string | number |
Configuration ID |
stringComposes a cache key for relevant entities data.
Kind: static method of utils/contextGuards
Returns: string - Composed cache key
| Param | Type | Description |
|---|---|---|
| workspace | string |
Workspace key |
| forecastDate | string |
Forecast date string |
| methodId | string | number |
Method ID |
| configId | string | number |
Configuration ID |
stringComposes a cache key for forecast values data.
Kind: static method of utils/contextGuards
Returns: string - Composed cache key
| Param | Type | Description |
|---|---|---|
| workspace | string |
Workspace key |
| forecastDate | string |
Forecast date string |
| methodId | string | number |
Method ID |
| configId | string | number |
Configuration ID (defaults to 'agg') |
| leadHours | number |
Lead time in hours |
| percentile | number |
Percentile value |
| normalizationRef | string |
Normalization reference (defaults to 'raw') |
Color utilities for visualizing forecast values on maps and charts. Provides a color gradient from white -> cyan -> green -> yellow -> red based on normalized values.
Array.<number>stringArray.<number>Converts a numeric value to an RGB color array based on a gradient scale.
Color scale:
Kind: static method of utils/colorUtils
Returns: Array.<number> - RGB color array [r, g, b] with values 0-255
| Param | Type | Description |
|---|---|---|
| value | number | null |
The value to convert to color |
| maxValue | number |
The maximum value for normalization |
Example
valueToColor(50, 100) // Returns [255, 255, 0] (yellow)
valueToColor(0, 100) // Returns [255, 255, 255] (white)
stringConverts a numeric value to a CSS rgb() color string. Convenience wrapper around valueToColor() that returns a CSS-ready string.
Kind: static method of utils/colorUtils
Returns: string - CSS rgb() color string, e.g., "rgb(255,128,0)"
| Param | Type | Description |
|---|---|---|
| value | number | null |
The value to convert to color |
| maxValue | number |
The maximum value for normalization |
Example
valueToColorCSS(75, 100) // Returns "rgb(255,191,0)"
Central TTL (Time-To-Live) presets for cached API requests. All values are in milliseconds. Adjust these if backend freshness requirements change.
numbernumbernumbernumberShort TTL for frequently changing data (2 minutes). Use for exploratory data with high churn rate like analog dates and lead times.
Kind: static constant of utils/cacheTTLs
numberDefault TTL for typical API data (5 minutes). Use for methods, entities, and synthesis data that changes moderately.
Kind: static constant of utils/cacheTTLs
numberLong TTL for very static data (15 minutes). Use for configuration and rarely-changing reference data.
Kind: static constant of utils/cacheTTLs
Helpers to normalize varied API response shapes into predictable structures. The API may return data in different formats depending on the endpoint or version. These functions ensure consistent data structures for the UI layer.
Array.<Object>Set.<(string|number)>Array.<Object>Array.<string>Object | Object | Object | booleanArray.<Object>Array.<Object>Normalizes entities response to a consistent array format.
Kind: static method of utils/apiNormalization
Returns: Array.<Object> - Array of entity objects with {id, name?, x?, y?}
| Param | Type | Description |
|---|---|---|
| resp | * |
Raw API response (can be array, object with entities property, or null) |
Example
// Returns [{id: 1, name: "Station A"}]
normalizeEntitiesResponse({entities: [{id: 1, name: "Station A"}]})
Set.<(string|number)>Extracts and normalizes relevant entity IDs from various response formats.
Kind: static method of utils/apiNormalization
Returns: Set.<(string|number)> - Set of entity IDs
| Param | Type | Description |
|---|---|---|
| resp | * |
Raw API response |
Example
normalizeRelevantEntityIds({entity_ids: [1, 2, 3]}) // Returns Set(1, 2, 3)
Array.<Object>Normalizes analog data from various response formats.
Kind: static method of utils/apiNormalization
Returns: Array.<Object> - Array of analog objects with {rank, date, value, criteria}
| Param | Type | Description |
|---|---|---|
| resp | * |
Raw API response containing analog data |
Example
normalizeAnalogsResponse({analogs: [{rank: 1, date: "2020-01-15", value: 25.3}]})
Array.<string>Extracts target dates array from various API response formats.
Kind: static method of utils/apiNormalization
Returns: Array.<string> - Array of target date strings, or empty array if not found
| Param | Type | Description |
|---|---|---|
| resp | * |
Raw API response (can be object, array, or nested structure) |
Example
extractTargetDatesArray({series_values: {target_dates: ['2023-01-15', '2023-01-16']}})
// Returns: ['2023-01-15', '2023-01-16']
Object | Object | Object | booleanNormalizes forecast values response into separate normalized and raw value maps.
Kind: static method of utils/apiNormalization
Returns: Object - Object with {norm: Object, raw: Object, unavailable: boolean}Object - returns.norm - Map of entity ID to normalized valueObject - returns.raw - Map of entity ID to raw valueboolean - returns.unavailable - True if data is missing or malformed
| Param | Type | Description |
|---|---|---|
| resp | Object |
Raw API response with entity_ids, values_normalized, and values arrays |
Example
normalizeForecastValuesResponse({
entity_ids: [1, 2],
values_normalized: [0.5, 0.8],
values: [25.5, 40.2]
})
// Returns: {
// norm: {1: 0.5, 2: 0.8},
// raw: {1: 25.5, 2: 40.2},
// unavailable: false
// }
Array.<Object>Normalizes methods and configurations response into a tree structure. Each method contains nested configuration objects.
Kind: static method of utils/apiNormalization
Returns: Array.<Object> - Array of method objects with nested children configs
| Param | Type | Description |
|---|---|---|
| resp | Object |
Raw API response with methods array |
Example
normalizeMethodsAndConfigs({
methods: [{id: 1, name: "Method A", configs: [{id: 10, name: "Config 1"}]}]
})
// Returns: [{id: 1, name: "Method A", children: [{id: 10, name: "Config 1"}]}]