@opengeoweb/time-slider-lite 17.0.1 → 17.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.esm.js DELETED
@@ -1,2899 +0,0 @@
1
- import { Card, Typography, IconButton, CardContent, Select, MenuItem, Grid, RadioGroup, FormControlLabel, Radio, Box, ToggleButtonGroup, ToggleButton, Divider, useTheme, ButtonGroup, Tooltip } from '@mui/material';
2
- import React, { useState, useEffect, useLayoutEffect, useRef, createElement } from 'react';
3
- import { Close, ChevronDown, ChevronUp, Options, Pause, Play, StepForward, StepBackward } from '@opengeoweb/theme';
4
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
5
- import { usePrevious, safelyInitI18nForTestsAndStories } from '@opengeoweb/shared';
6
- import { speedFactors, defaultAnimationDelayAtStart } from '@opengeoweb/time-slider';
7
- import i18n from 'i18next';
8
- import { I18nextProvider, useTranslation } from 'react-i18next';
9
- import { CORE_NAMESPACE, coreTranslations } from '@opengeoweb/core';
10
- import { useDispatch, useSelector } from 'react-redux';
11
- import { mapActions, mapEnums, mapSelectors, genericActions } from '@opengeoweb/store';
12
- import { handleDateUtilsISOString } from '@opengeoweb/webmap';
13
- import Draggable from 'react-draggable';
14
-
15
- var en = {
16
- common: {
17
- "default": "Default",
18
- custom: "Custom",
19
- observed: "Observed",
20
- forecast: "Forecast"
21
- },
22
- units: {
23
- days: "days",
24
- hours: "hours",
25
- minutes: "min"
26
- },
27
- menu: {
28
- title: "Animation options",
29
- timeRange: {
30
- title: "Time range",
31
- description: "Time range from current time",
32
- button: "Time range"
33
- },
34
- timeStep: {
35
- title: "Time step",
36
- button: "Time step"
37
- },
38
- speed: {
39
- title: "Animation speed",
40
- button: "Speed"
41
- },
42
- updateInterval: {
43
- title: "Update interval",
44
- button: "Update interval"
45
- },
46
- LT: "LT",
47
- UTC: "UTC"
48
- },
49
- controlButtons: {
50
- play: "Play",
51
- pause: "Pause",
52
- forward: "Forward",
53
- backward: "Backward",
54
- hide: "Hide",
55
- show: "Show"
56
- }
57
- };
58
- var fi = {
59
- common: {
60
- "default": "Oletus",
61
- custom: "Valitse",
62
- observed: "Havainto",
63
- forecast: "Ennuste"
64
- },
65
- units: {
66
- days: "vrk",
67
- hours: "h",
68
- minutes: "min"
69
- },
70
- menu: {
71
- title: "Aikajana-asetukset",
72
- timeRange: {
73
- title: "Aikaväli",
74
- description: "Valittu aika nykyhetkestä",
75
- button: "Aikaväli"
76
- },
77
- timeStep: {
78
- title: "Aika-askel",
79
- button: "Aika-askel"
80
- },
81
- speed: {
82
- title: "Animointinopeus",
83
- button: "Animointinopeus"
84
- },
85
- updateInterval: {
86
- title: "Päivitysväli",
87
- button: "Päivitysväli"
88
- },
89
- LT: "PA",
90
- UTC: "UTC"
91
- },
92
- controlButtons: {
93
- play: "Toista",
94
- pause: "Pysäytä",
95
- forward: "Eteenpäin",
96
- backward: "Taaksepäin",
97
- hide: "Piilota aikajana",
98
- show: "Näytä aikajana"
99
- }
100
- };
101
- var translations = {
102
- en: en,
103
- "sv-FI": {
104
- common: {
105
- "default": "Standard",
106
- custom: "Välj",
107
- observed: "Observation",
108
- forecast: "Prognos"
109
- },
110
- units: {
111
- days: "dygn",
112
- hours: "h",
113
- minutes: "min"
114
- },
115
- menu: {
116
- title: "Tidslinjeinställningar",
117
- timeRange: {
118
- title: "Tidsintervall",
119
- description: "Vald tid från nu",
120
- button: "Tidsintervall"
121
- },
122
- timeStep: {
123
- title: "Tidssteg",
124
- button: "Tidssteg"
125
- },
126
- speed: {
127
- title: "Animationshastighet",
128
- button: "Hastighet"
129
- },
130
- updateInterval: {
131
- title: "Uppdateringsintervall",
132
- button: "Uppdateringsintervall"
133
- },
134
- LT: "LT",
135
- UTC: "UTC"
136
- },
137
- controlButtons: {
138
- play: "Spela",
139
- pause: "Paus",
140
- forward: "Framåt",
141
- backward: "Bakåt",
142
- hide: "Dölj tidslinje",
143
- show: "Visa tidslinje"
144
- }
145
- },
146
- fi: fi
147
- };
148
-
149
- function _objectWithoutPropertiesLoose(r, e) {
150
- if (null == r) return {};
151
- var t = {};
152
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
153
- if (-1 !== e.indexOf(n)) continue;
154
- t[n] = r[n];
155
- }
156
- return t;
157
- }
158
-
159
- var _excluded$4 = ["children", "closeButtonIcon", "sx", "setSubmenu", "title"];
160
- var SubmenuWrapper = function SubmenuWrapper(_ref) {
161
- var children = _ref.children,
162
- closeButtonIcon = _ref.closeButtonIcon,
163
- sx = _ref.sx,
164
- setSubmenu = _ref.setSubmenu,
165
- title = _ref.title,
166
- props = _objectWithoutPropertiesLoose(_ref, _excluded$4);
167
- return /*#__PURE__*/jsxs(Card, Object.assign({}, props, {
168
- sx: Object.assign({
169
- position: 'relative'
170
- }, Array.isArray(sx) ? Object.assign.apply(Object, [{}].concat(sx)) : sx),
171
- children: [/*#__PURE__*/jsx(Typography, {
172
- sx: {
173
- fontWeight: '500',
174
- padding: '16px',
175
- paddingBottom: '0px'
176
- },
177
- children: title
178
- }), /*#__PURE__*/jsx(IconButton, {
179
- "data-testid": "TimeSliderLite-submenuWrapper-closeButton",
180
- onClick: function onClick() {
181
- return setSubmenu == null ? void 0 : setSubmenu(null);
182
- },
183
- size: "small",
184
- sx: {
185
- position: 'absolute',
186
- top: 4,
187
- right: 4
188
- },
189
- children: closeButtonIcon != null ? closeButtonIcon : /*#__PURE__*/jsx(Close, {
190
- "data-testid": "TimeSliderLite-submenuWrapper-defaultCloseIcon"
191
- })
192
- }), children]
193
- }));
194
- };
195
-
196
- /* *
197
- * Licensed under the Apache License, Version 2.0 (the "License");
198
- * you may not use this file except in compliance with the License.
199
- * You may obtain a copy of the License at
200
- *
201
- * http://www.apache.org/licenses/LICENSE-2.0
202
- *
203
- * Unless required by applicable law or agreed to in writing, software
204
- * distributed under the License is distributed on an "AS IS" BASIS,
205
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
206
- * See the License for the specific language governing permissions and
207
- * limitations under the License.
208
- *
209
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
210
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
211
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
212
- * */
213
-
214
- var DAY_TO_MILLISECOND = 24 * 60 * 60 * 1000;
215
- var DAY_TO_SECOND = 86400;
216
- var HOUR_TO_SECOND = 3600;
217
- var HOUR_TO_MINUTE = 60;
218
- var MILLISECOND_TO_DAY = 1 / 86400000;
219
- var MILLISECOND_TO_SECOND = 1 / 1000;
220
- var MILLISECOND_TO_MINUTE = 1 / 60000;
221
- var MINUTE_TO_SECOND = 60;
222
- var MINUTE_TO_MILLISECOND = 60000;
223
- var SECOND_TO_DAY = 1 / 86400;
224
- var SECOND_TO_HOUR = 1 / 3600;
225
- var SECOND_TO_MILLISECOND = 1000;
226
- var SEVEN_DAYS_IN_SECONDS = 7 * 24 * 60 * 60;
227
- var ONE_DAY_IN_SECONDS = DAY_TO_SECOND;
228
- /**
229
- * Default behaviour for time slider lite to update
230
- * - Update current time
231
- * - Update time range
232
- *
233
- * Layers are updated using the native auto update functionality implemented in ReactMapView.tsx
234
- *
235
- * @param mapId
236
- * @param options
237
- */
238
- var defaultTimeSliderLiteUpdate = function defaultTimeSliderLiteUpdate(options) {
239
- if (document.visibilityState !== 'visible') {
240
- return;
241
- }
242
- var setCurrentTime = options.setCurrentTime,
243
- timeRange = options.timeRange,
244
- currentTime = options.currentTime,
245
- setTimeRange = options.setTimeRange;
246
- var newCurrentTime = Math.floor(Date.now() * MILLISECOND_TO_SECOND);
247
- var delta = newCurrentTime - currentTime;
248
-
249
- // Update current time and trigger update in useDefaultTimeRange hook
250
- setCurrentTime(currentTime + delta);
251
- if (timeRange && setTimeRange) {
252
- setTimeRange([timeRange[0] + delta, timeRange[1] + delta]);
253
- }
254
- };
255
-
256
- /**
257
- * Connected hook for updating time range and current time every 10 seconds
258
- * @param updateInterval Update interval in minutes
259
- * @param timeRange [startTime, endTime] in seconds
260
- * @param setTimeRange Sets the time range
261
- * @param options Options
262
- */
263
- var useAutoUpdate = function useAutoUpdate(timeRange, setTimeRange, options) {
264
- var _useState = useState(Math.floor(Date.now() * MILLISECOND_TO_SECOND)),
265
- currentTime = _useState[0],
266
- setCurrentTime = _useState[1];
267
- useEffect(function () {
268
- var intervalCallback = function intervalCallback() {
269
- var _options$handleUpdate;
270
- return ((_options$handleUpdate = options == null ? void 0 : options.handleUpdate) != null ? _options$handleUpdate : defaultTimeSliderLiteUpdate)({
271
- setCurrentTime: setCurrentTime,
272
- currentTime: currentTime,
273
- timeRange: timeRange,
274
- setTimeRange: setTimeRange
275
- });
276
- };
277
- var interval = setInterval(intervalCallback, 10 * SECOND_TO_MILLISECOND);
278
- document.addEventListener('visibilitychange', intervalCallback);
279
- return function () {
280
- clearInterval(interval);
281
- document.removeEventListener('visibilitychange', intervalCallback);
282
- };
283
- }, [timeRange, setTimeRange, options == null ? void 0 : options.handleUpdate, currentTime, setCurrentTime]);
284
- return {
285
- currentTime: currentTime
286
- };
287
- };
288
-
289
- /**
290
- * Reformats a date that has capitalized first letter and colon separator for time
291
- * @param dateString Date string from Date.toLocaleDateString
292
- * @returns Reformatted date string
293
- */
294
- var reformatFinnishDateString = function reformatFinnishDateString(dateString) {
295
- var charPositionOfTimestamp = -4;
296
- return dateString.charAt(0).toUpperCase() + dateString.slice(1, charPositionOfTimestamp) + dateString.slice(charPositionOfTimestamp).replace('.', ':');
297
- };
298
-
299
- /**
300
- * Marks UTC time with Z after hh:mm or hh.mm or appends UTC to the end of the date string
301
- * If two matches of time are found, the second one is marked
302
- */
303
- var shortUTCTime = function shortUTCTime(dateString) {
304
- var timeRegex = /(\d[:.]\d{2})/g;
305
- var match = dateString.match(timeRegex);
306
- if (!match) {
307
- return dateString + " UTC";
308
- }
309
- var first = match[0],
310
- second = match[1];
311
- if (second) {
312
- var secondIndex = dateString.lastIndexOf(second);
313
- return "" + dateString.substring(0, secondIndex) + second + "Z" + dateString.substring(secondIndex + second.length);
314
- }
315
- return dateString.replace(first, first + "Z");
316
- };
317
- var getMonthChanges = function getMonthChanges(startDate, endDate) {
318
- var result = [];
319
- var currentDate = new Date(startDate.getTime());
320
- var lastDate = new Date(endDate.getTime());
321
- currentDate.setDate(1);
322
- currentDate.setHours(0, 0, 0, 0);
323
- while (currentDate <= lastDate) {
324
- result.push(currentDate.getTime() * MILLISECOND_TO_SECOND);
325
- currentDate.setMonth(currentDate.getMonth() + 1);
326
- }
327
- return result;
328
- };
329
- var isWithinRange = function isWithinRange(time, target, range) {
330
- return Math.abs(time - target) <= range;
331
- };
332
- var getSelectedTimePx = function getSelectedTimePx(startTime, endTime, selectedTime, width) {
333
- var startDate = new Date(startTime * SECOND_TO_MILLISECOND);
334
- var startDateX = startDate.getTime() * MILLISECOND_TO_SECOND;
335
- var selectedTimeX = selectedTime - startDateX;
336
- var needleX = Math.floor(selectedTimeX / (endTime - startTime) * width);
337
- return needleX;
338
- };
339
- var boundedValue = function boundedValue(value, bounds) {
340
- var min = bounds[0],
341
- max = bounds[1];
342
- return Math.max(min, Math.min(max, value));
343
- };
344
- var getSelectedTimeFromPx = function getSelectedTimeFromPx(startTime, endTime, selectedTimePx, width) {
345
- var startDate = new Date(startTime * SECOND_TO_MILLISECOND);
346
- var startDateX = startDate.getTime() * MILLISECOND_TO_SECOND;
347
- var selectedTimeX = Math.floor(selectedTimePx / width * (endTime - startTime));
348
- var selectedTime = selectedTimeX + startDateX;
349
- return selectedTime;
350
- };
351
- var getNearestSelectableTime = function getNearestSelectableTime(timeStep, startTime, endTime, x, width, currentTime, disableForecast, timeZoneOffsetSeconds) {
352
- var observedTimeStepSeconds = timeStep[0];
353
- var forecastTimeStepSeconds = timeStep[1];
354
- var hoveredTime = getSelectedTimeFromPx(startTime, endTime, x, width);
355
- var lastObservedTime = floorLocalSeconds(currentTime, observedTimeStepSeconds, timeZoneOffsetSeconds);
356
- if (disableForecast && hoveredTime >= lastObservedTime) {
357
- return lastObservedTime;
358
- }
359
- var timeStepSeconds = hoveredTime >= currentTime ? forecastTimeStepSeconds : observedTimeStepSeconds;
360
- var firstForecastTime = floorLocalSeconds(currentTime, forecastTimeStepSeconds, timeZoneOffsetSeconds) + forecastTimeStepSeconds;
361
- var isBetweenObservedAndForecast = hoveredTime >= lastObservedTime && hoveredTime < firstForecastTime;
362
- var roundedCurrentTime = hoveredTime >= (lastObservedTime + firstForecastTime) / 2 ? firstForecastTime : lastObservedTime;
363
- var result = isBetweenObservedAndForecast ? roundedCurrentTime : floorLocalSeconds(hoveredTime + timeStepSeconds / 2, timeStepSeconds, timeZoneOffsetSeconds);
364
- return result;
365
- };
366
- var floorLocalMinutes = function floorLocalMinutes(selectedTimeMinutes, timeStepMinutes, timeZoneOffsetMinutes) {
367
- var localTimeZoneOffset = timeZoneOffsetMinutes != null ? timeZoneOffsetMinutes : new Date().getTimezoneOffset();
368
- var unFlooredTimeSteps = (selectedTimeMinutes - localTimeZoneOffset) / timeStepMinutes;
369
- return Math.floor(unFlooredTimeSteps) * timeStepMinutes + localTimeZoneOffset;
370
- };
371
- var floorLocalSeconds = function floorLocalSeconds(selectedTimeSeconds, timeStepSeconds, timeZoneOffsetSeconds) {
372
- if (timeZoneOffsetSeconds === 0) {
373
- return Math.floor(selectedTimeSeconds / timeStepSeconds) * timeStepSeconds;
374
- }
375
- var localTimeZoneOffset = timeZoneOffsetSeconds != null ? timeZoneOffsetSeconds : new Date().getTimezoneOffset() * 60;
376
- var unFlooredTimeSteps = (selectedTimeSeconds - localTimeZoneOffset) / timeStepSeconds;
377
- return Math.floor(unFlooredTimeSteps) * timeStepSeconds + localTimeZoneOffset;
378
- };
379
- var secondsToDaysAndHours = function secondsToDaysAndHours(seconds) {
380
- var days = Math.floor(seconds * SECOND_TO_DAY);
381
- var hours = Math.round(seconds % DAY_TO_SECOND * SECOND_TO_HOUR);
382
- if (hours === 24) {
383
- return {
384
- days: days + 1,
385
- hours: 0
386
- };
387
- }
388
- return {
389
- days: days,
390
- hours: hours
391
- };
392
- };
393
- var hoursAndDaysToSeconds = function hoursAndDaysToSeconds(hours, days) {
394
- return hours * HOUR_TO_SECOND + days * DAY_TO_SECOND;
395
- };
396
- var TIME_SLIDER_LITE_DEFAULT_MAX_FORECAST_RANGE = 2 * SEVEN_DAYS_IN_SECONDS;
397
- var TIME_SLIDER_LITE_DEFAULT_MAX_OBSERVED_RANGE = SEVEN_DAYS_IN_SECONDS;
398
-
399
- /**
400
- * Checks which layers have observed/forecasted data and returns a default time range
401
- * @param layers layerTypes.ReduxLayer[] Map layers
402
- * @param currentTime Current time in seconds
403
- * @param overrideDefaultTimeRange [observedTimeRange, forecastTime] in seconds from current time
404
- * @returns [startTime, endTime] in seconds
405
- */
406
- var defaultTimeRange = function defaultTimeRange(layers, currentTime, overrideDefaultTimeRange) {
407
- if (currentTime === void 0) {
408
- currentTime = Math.floor(Date.now() * MILLISECOND_TO_SECOND);
409
- }
410
- var defaultBounds = [currentTime - TIME_SLIDER_LITE_DEFAULT_MAX_OBSERVED_RANGE, currentTime + TIME_SLIDER_LITE_DEFAULT_MAX_FORECAST_RANGE];
411
- var bounds = overrideDefaultTimeRange ? [currentTime - overrideDefaultTimeRange[0], currentTime + overrideDefaultTimeRange[1]] : defaultBounds;
412
- var timeDimensions = [];
413
- layers.forEach(function (layer) {
414
- var _layer$dimensions;
415
- var timeDimension = (_layer$dimensions = layer.dimensions) == null ? void 0 : _layer$dimensions.find(function (dimension) {
416
- return dimension.name === 'time';
417
- });
418
- if (timeDimension != null && timeDimension.minValue && timeDimension != null && timeDimension.maxValue) {
419
- timeDimensions.push(timeDimension);
420
- }
421
- });
422
- if (timeDimensions.length === 0) {
423
- return bounds;
424
- }
425
- var minMinValue = Math.min.apply(Math, timeDimensions.map(function (dimension) {
426
- return new Date(dimension.minValue).valueOf() * MILLISECOND_TO_SECOND;
427
- }));
428
- var maxMaxValue = Math.max.apply(Math, timeDimensions.map(function (dimension) {
429
- return new Date(dimension.maxValue).valueOf() * MILLISECOND_TO_SECOND;
430
- }));
431
- return [Math.max(bounds[0], minMinValue), Math.min(bounds[1], maxMaxValue)];
432
- };
433
- var useDefaultTimeRange = function useDefaultTimeRange(layers, updateThreshold, currentTime) {
434
- if (currentTime === void 0) {
435
- currentTime = Math.floor(Date.now() * MILLISECOND_TO_SECOND);
436
- }
437
- var _useState2 = useState([0, 0]),
438
- _useState2$ = _useState2[0],
439
- defaultStartTime = _useState2$[0],
440
- defaultEndTime = _useState2$[1],
441
- setDefaultTimeRange = _useState2[1];
442
- var updateThresholdInMinutes = updateThreshold * MINUTE_TO_SECOND;
443
- var updateDefaultTimeRange = function updateDefaultTimeRange() {
444
- var newTimeRange = defaultTimeRange(layers, currentTime);
445
- var defaultStartTimeChanged = Math.abs(newTimeRange[0] - defaultStartTime) > updateThresholdInMinutes;
446
- var defaultEndTimeChanged = Math.abs(newTimeRange[1] - defaultEndTime) > updateThresholdInMinutes;
447
- if (defaultStartTimeChanged || defaultEndTimeChanged) {
448
- setDefaultTimeRange(newTimeRange);
449
- }
450
- };
451
- useEffect(function () {
452
- updateDefaultTimeRange();
453
- // eslint-disable-next-line react-hooks/exhaustive-deps
454
- }, [layers, currentTime]);
455
- return [defaultStartTime, defaultEndTime];
456
- };
457
- var generateCustomTimeList = function generateCustomTimeList(currentTime, startTime, endTime, timeStep, timeZoneOffsetSeconds) {
458
- var localTimeZoneOffset = timeZoneOffsetSeconds !== undefined ? timeZoneOffsetSeconds : new Date().getTimezoneOffset() * MINUTE_TO_SECOND;
459
- var observedTimeStep = timeStep[0] * MINUTE_TO_SECOND;
460
- var forecastTimeStep = timeStep[1] * MINUTE_TO_SECOND;
461
- var firstObservedTimeStep = floorLocalSeconds(startTime, observedTimeStep, localTimeZoneOffset);
462
- if (firstObservedTimeStep < startTime) {
463
- firstObservedTimeStep += observedTimeStep;
464
- }
465
- var lastObservedTimeStep = floorLocalSeconds(currentTime, observedTimeStep, localTimeZoneOffset);
466
- var truncatePassingHour = currentTime - startTime < 0;
467
- var firstForecastTimeStep = truncatePassingHour ? floorLocalSeconds(currentTime + HOUR_TO_SECOND, HOUR_TO_SECOND, localTimeZoneOffset) - 1 : floorLocalSeconds(currentTime, forecastTimeStep, localTimeZoneOffset);
468
- var lastForecastTimeStep = floorLocalSeconds(endTime, forecastTimeStep, localTimeZoneOffset);
469
- var observedTimeList = [];
470
- var forecastTimeList = [];
471
- var time = firstObservedTimeStep;
472
- while (time <= lastObservedTimeStep) {
473
- var observedTimeListItem = {
474
- name: 'time',
475
- value: new Date(time * SECOND_TO_MILLISECOND).toISOString()
476
- };
477
- observedTimeList.push(observedTimeListItem);
478
- time += observedTimeStep;
479
- }
480
- time = lastForecastTimeStep;
481
- while (time > firstForecastTimeStep) {
482
- var forecastTimeListItem = {
483
- name: 'time',
484
- value: new Date(time * SECOND_TO_MILLISECOND).toISOString()
485
- };
486
- forecastTimeList.push(forecastTimeListItem);
487
- time -= forecastTimeStep;
488
- }
489
- forecastTimeList.reverse();
490
- return [].concat(observedTimeList, forecastTimeList);
491
- };
492
- var TickMode = /*#__PURE__*/function (TickMode) {
493
- TickMode[TickMode["DAY"] = 1] = "DAY";
494
- TickMode[TickMode["HALF_A_DAY"] = 2] = "HALF_A_DAY";
495
- TickMode[TickMode["SIX_HOURS"] = 4] = "SIX_HOURS";
496
- TickMode[TickMode["THREE_HOURS"] = 8] = "THREE_HOURS";
497
- TickMode[TickMode["ONE_HOUR"] = 24] = "ONE_HOUR";
498
- TickMode[TickMode["HALF_AN_HOUR"] = 48] = "HALF_AN_HOUR";
499
- TickMode[TickMode["FIFTEEN_MINUTES"] = 96] = "FIFTEEN_MINUTES";
500
- return TickMode;
501
- }(TickMode || {});
502
- var subTicksPerDay = function subTicksPerDay(dayWidthInPixels) {
503
- if (dayWidthInPixels < 40) {
504
- return TickMode.DAY;
505
- }
506
- if (dayWidthInPixels < 75) {
507
- return TickMode.HALF_A_DAY;
508
- }
509
- if (dayWidthInPixels < 400) {
510
- return TickMode.SIX_HOURS;
511
- }
512
- if (dayWidthInPixels < 800) {
513
- return TickMode.THREE_HOURS;
514
- }
515
- if (dayWidthInPixels < 1600) {
516
- return TickMode.ONE_HOUR;
517
- }
518
- if (dayWidthInPixels < 3200) {
519
- return TickMode.HALF_AN_HOUR;
520
- }
521
- return TickMode.FIFTEEN_MINUTES;
522
- };
523
- var maxSubTicksPerDay = function maxSubTicksPerDay(dayWidthInPixels, timeStep) {
524
- return Math.min(subTicksPerDay(dayWidthInPixels), Math.floor(ONE_DAY_IN_SECONDS / timeStep));
525
- };
526
- var getRemainingHours = function getRemainingHours(maxHours, days) {
527
- var hourDifference = maxHours && maxHours - days * 24;
528
- var result = maxHours && hourDifference && hourDifference > 0 ? hourDifference : 0;
529
- return result;
530
- };
531
- var secondsSinceLocalMidnight = function secondsSinceLocalMidnight(currentTimeInSeconds) {
532
- return new Date(currentTimeInSeconds * 1000).getHours() * HOUR_TO_SECOND + new Date(currentTimeInSeconds * 1000).getMinutes() * MINUTE_TO_SECOND + new Date(currentTimeInSeconds * 1000).getSeconds();
533
- };
534
- var getTimeScaleDescription = function getTimeScaleDescription(timeScale) {
535
- if (timeScale !== 1 && timeScale < HOUR_TO_SECOND) {
536
- return Math.round(timeScale / MINUTE_TO_SECOND) + " minutes is ~1 second";
537
- }
538
- if (timeScale > 60) {
539
- var hours = Math.floor(timeScale / HOUR_TO_SECOND);
540
- var mins = Math.round((timeScale - hours * HOUR_TO_SECOND) / MINUTE_TO_SECOND);
541
- return hours + " h " + mins + " min is ~1 second";
542
- }
543
- return 'Real-time';
544
- };
545
- /**
546
- * Keeps selected time in sync with default time
547
- * @returns True if selected time sync to default time is enabled
548
- */
549
- var useAutoUpdateSelectedTime = function useAutoUpdateSelectedTime(defaultTime, selectedTime, setSelectedTime) {
550
- var defaultTimeBeforeChange = usePrevious(defaultTime);
551
- var _useState3 = useState(defaultTime),
552
- previousDefaultTime = _useState3[0],
553
- setPreviousDefaultTime = _useState3[1];
554
- useEffect(function () {
555
- if (defaultTime !== defaultTimeBeforeChange) {
556
- setPreviousDefaultTime(defaultTimeBeforeChange);
557
- }
558
- // eslint-disable-next-line react-hooks/exhaustive-deps
559
- }, [defaultTime]);
560
- useEffect(function () {
561
- if (previousDefaultTime === selectedTime) {
562
- setSelectedTime(defaultTime);
563
- }
564
- // eslint-disable-next-line react-hooks/exhaustive-deps
565
- }, [previousDefaultTime]);
566
- return defaultTime === selectedTime;
567
- };
568
-
569
- var timeSliderLiteUtils = /*#__PURE__*/Object.freeze({
570
- __proto__: null,
571
- DAY_TO_MILLISECOND: DAY_TO_MILLISECOND,
572
- DAY_TO_SECOND: DAY_TO_SECOND,
573
- HOUR_TO_MINUTE: HOUR_TO_MINUTE,
574
- HOUR_TO_SECOND: HOUR_TO_SECOND,
575
- MILLISECOND_TO_DAY: MILLISECOND_TO_DAY,
576
- MILLISECOND_TO_MINUTE: MILLISECOND_TO_MINUTE,
577
- MILLISECOND_TO_SECOND: MILLISECOND_TO_SECOND,
578
- MINUTE_TO_MILLISECOND: MINUTE_TO_MILLISECOND,
579
- MINUTE_TO_SECOND: MINUTE_TO_SECOND,
580
- SECOND_TO_DAY: SECOND_TO_DAY,
581
- SECOND_TO_HOUR: SECOND_TO_HOUR,
582
- SECOND_TO_MILLISECOND: SECOND_TO_MILLISECOND,
583
- SEVEN_DAYS_IN_SECONDS: SEVEN_DAYS_IN_SECONDS,
584
- TIME_SLIDER_LITE_DEFAULT_MAX_FORECAST_RANGE: TIME_SLIDER_LITE_DEFAULT_MAX_FORECAST_RANGE,
585
- TIME_SLIDER_LITE_DEFAULT_MAX_OBSERVED_RANGE: TIME_SLIDER_LITE_DEFAULT_MAX_OBSERVED_RANGE,
586
- boundedValue: boundedValue,
587
- defaultTimeRange: defaultTimeRange,
588
- defaultTimeSliderLiteUpdate: defaultTimeSliderLiteUpdate,
589
- floorLocalMinutes: floorLocalMinutes,
590
- floorLocalSeconds: floorLocalSeconds,
591
- generateCustomTimeList: generateCustomTimeList,
592
- getMonthChanges: getMonthChanges,
593
- getNearestSelectableTime: getNearestSelectableTime,
594
- getRemainingHours: getRemainingHours,
595
- getSelectedTimeFromPx: getSelectedTimeFromPx,
596
- getSelectedTimePx: getSelectedTimePx,
597
- getTimeScaleDescription: getTimeScaleDescription,
598
- hoursAndDaysToSeconds: hoursAndDaysToSeconds,
599
- isWithinRange: isWithinRange,
600
- maxSubTicksPerDay: maxSubTicksPerDay,
601
- reformatFinnishDateString: reformatFinnishDateString,
602
- secondsSinceLocalMidnight: secondsSinceLocalMidnight,
603
- secondsToDaysAndHours: secondsToDaysAndHours,
604
- shortUTCTime: shortUTCTime,
605
- subTicksPerDay: subTicksPerDay,
606
- useAutoUpdate: useAutoUpdate,
607
- useAutoUpdateSelectedTime: useAutoUpdateSelectedTime,
608
- useDefaultTimeRange: useDefaultTimeRange
609
- });
610
-
611
- /* *
612
- * Licensed under the Apache License, Version 2.0 (the "License");
613
- * you may not use this file except in compliance with the License.
614
- * You may obtain a copy of the License at
615
- *
616
- * http://www.apache.org/licenses/LICENSE-2.0
617
- *
618
- * Unless required by applicable law or agreed to in writing, software
619
- * distributed under the License is distributed on an "AS IS" BASIS,
620
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
621
- * See the License for the specific language governing permissions and
622
- * limitations under the License.
623
- *
624
- * Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
625
- * Copyright 2024 - Finnish Meteorological Institute (FMI)
626
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
627
- * */
628
- var TIME_SLIDER_LITE_NAMESPACE = 'timesliderlite';
629
- var initTimeSliderLiteI18n = function initTimeSliderLiteI18n(language, i18nInstance) {
630
- var i18nInst = i18nInstance != null ? i18nInstance : i18n;
631
- safelyInitI18nForTestsAndStories(i18nInst, TIME_SLIDER_LITE_NAMESPACE, [], language);
632
- // load all translations here that are needed for tests and stories
633
- i18nInst.addResourceBundle('en', TIME_SLIDER_LITE_NAMESPACE, translations['en']);
634
- i18nInst.addResourceBundle('en', CORE_NAMESPACE, coreTranslations['en']);
635
- i18nInst.addResourceBundle('fi', TIME_SLIDER_LITE_NAMESPACE, translations['fi']);
636
- i18nInst.addResourceBundle('fi', CORE_NAMESPACE, coreTranslations['fi']);
637
- i18nInst.addResourceBundle('sv-FI', TIME_SLIDER_LITE_NAMESPACE, translations['sv-FI']);
638
- };
639
- /**
640
- * This provider is limited to TimeSliderLite translations.
641
- *
642
- * If you need more translations, install i18next and react-i18next packages and create your own I18nextProvider as multiple providers are not supported.
643
- *
644
- * You can then import TIME_SLIDER_LITE_NAMESPACE and timeSliderLiteTranslations and use it to build your own provider.
645
- * @language TimeSliderLiteLanguage - optional - default 'en'
646
- * @returns I18nextProvider
647
- */
648
- var TimeSliderLiteI18nProvider = function TimeSliderLiteI18nProvider(_ref) {
649
- var children = _ref.children,
650
- language = _ref.language,
651
- i18nInstance = _ref.i18nInstance;
652
- initTimeSliderLiteI18n(language, i18nInstance);
653
- return /*#__PURE__*/jsx(I18nextProvider, {
654
- i18n: i18nInstance != null ? i18nInstance : i18n,
655
- children: children
656
- });
657
- };
658
- var useTimesliderLiteTranslation = function useTimesliderLiteTranslation() {
659
- return useTranslation(TIME_SLIDER_LITE_NAMESPACE);
660
- };
661
-
662
- /* *
663
- * Licensed under the Apache License, Version 2.0 (the "License");
664
- * you may not use this file except in compliance with the License.
665
- * You may obtain a copy of the License at
666
- *
667
- * http://www.apache.org/licenses/LICENSE-2.0
668
- *
669
- * Unless required by applicable law or agreed to in writing, software
670
- * distributed under the License is distributed on an "AS IS" BASIS,
671
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
672
- * See the License for the specific language governing permissions and
673
- * limitations under the License.
674
- *
675
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
676
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
677
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
678
- * */
679
-
680
- var AnimationSpeedOptions = function AnimationSpeedOptions(_ref) {
681
- var _useAnimationSpeed$;
682
- var dropdownButtonIcon = _ref.dropdownButtonIcon,
683
- _ref$speedOptions = _ref.speedOptions,
684
- speedOptions = _ref$speedOptions === void 0 ? speedFactors.sort(function (speedA, speedB) {
685
- return speedB - speedA;
686
- }) : _ref$speedOptions,
687
- _ref$speedOptionItemP = _ref.speedOptionItemPrefix,
688
- speedOptionItemPrefix = _ref$speedOptionItemP === void 0 ? 'x ' : _ref$speedOptionItemP,
689
- _ref$speedOptionItemP2 = _ref.speedOptionItemPostfix,
690
- speedOptionItemPostfix = _ref$speedOptionItemP2 === void 0 ? '' : _ref$speedOptionItemP2,
691
- defaultSpeedOptionPostfix = _ref.defaultSpeedOptionPostfix,
692
- _ref$defaultSpeedFact = _ref.defaultSpeedFactor,
693
- defaultSpeedFactor = _ref$defaultSpeedFact === void 0 ? speedFactors[2] : _ref$defaultSpeedFact,
694
- useAnimationSpeed = _ref.useAnimationSpeed;
695
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
696
- t = _useTimesliderLiteTra.t;
697
- var translatedSpeedOptionPostfix = defaultSpeedOptionPostfix != null ? defaultSpeedOptionPostfix : " (" + t('common.default').toLocaleLowerCase() + ")";
698
- var animationSpeed = (_useAnimationSpeed$ = useAnimationSpeed == null ? void 0 : useAnimationSpeed[0]) != null ? _useAnimationSpeed$ : defaultSpeedFactor;
699
- var setAnimationSpeed = useAnimationSpeed == null ? void 0 : useAnimationSpeed[1];
700
- var readOnly = !setAnimationSpeed || speedOptions.length < 2;
701
- return /*#__PURE__*/jsx(CardContent, {
702
- className: "TimeSliderLite-animationSpeedOptions",
703
- "data-testid": "TimeSliderLite-animationSpeedOptions",
704
- sx: {
705
- paddingTop: '12px',
706
- marginBottom: '-8px',
707
- minWidth: '200px'
708
- },
709
- children: /*#__PURE__*/jsx(Select, {
710
- IconComponent: dropdownButtonIcon,
711
- className: "TimeSliderLite-animationSpeedSelect",
712
- "data-testid": "TimeSliderLite-animationSpeedSelect",
713
- disabled: readOnly,
714
- inputProps: {
715
- 'data-testid': 'TimeSliderLite-animationSpeedSelect-input'
716
- },
717
- onChange: function onChange(event) {
718
- var _event$target;
719
- var newValue = Number(event == null || (_event$target = event.target) == null ? void 0 : _event$target.value);
720
- setAnimationSpeed == null || setAnimationSpeed(newValue);
721
- },
722
- sx: {
723
- height: '40px'
724
- },
725
- value: String(animationSpeed),
726
- children: speedOptions.map(function (option) {
727
- var postfix = option === defaultSpeedFactor ? translatedSpeedOptionPostfix : speedOptionItemPostfix;
728
- var label = speedOptionItemPrefix + option + postfix;
729
- return /*#__PURE__*/jsx(MenuItem, {
730
- value: String(option),
731
- children: label
732
- }, String(option));
733
- })
734
- })
735
- });
736
- };
737
-
738
- /* *
739
- * Licensed under the Apache License, Version 2.0 (the "License");
740
- * you may not use this file except in compliance with the License.
741
- * You may obtain a copy of the License at
742
- *
743
- * http://www.apache.org/licenses/LICENSE-2.0
744
- *
745
- * Unless required by applicable law or agreed to in writing, software
746
- * distributed under the License is distributed on an "AS IS" BASIS,
747
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
748
- * See the License for the specific language governing permissions and
749
- * limitations under the License.
750
- *
751
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
752
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
753
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
754
- * */
755
-
756
- var SubmenuSelectLabel = function SubmenuSelectLabel(_ref) {
757
- var children = _ref.children,
758
- isDisabled = _ref.isDisabled;
759
- return /*#__PURE__*/jsx(Typography, {
760
- sx: {
761
- opacity: isDisabled ? 0.5 : 1,
762
- fontWeight: '400',
763
- paddingTop: '10px'
764
- },
765
- children: children
766
- });
767
- };
768
-
769
- var _excluded$3 = ["amountOfOptions", "dropdownButtonIcon", "itemPostFix", "value", "setValue"];
770
- var CustomSelect = function CustomSelect(_ref) {
771
- var amountOfOptions = _ref.amountOfOptions,
772
- dropdownButtonIcon = _ref.dropdownButtonIcon,
773
- itemPostFix = _ref.itemPostFix,
774
- value = _ref.value,
775
- setValue = _ref.setValue,
776
- props = _objectWithoutPropertiesLoose(_ref, _excluded$3);
777
- var availableOptions = Array.from(Array(amountOfOptions).keys());
778
- return /*#__PURE__*/jsx(Select, Object.assign({}, props, {
779
- IconComponent: dropdownButtonIcon,
780
- autoWidth: false,
781
- "data-testid": "TimeSliderLite-customSelect-" + itemPostFix,
782
- inputProps: {
783
- 'data-testid': "TimeSliderLite-customSelect-" + itemPostFix + "-input"
784
- },
785
- onChange: function onChange(event) {
786
- var _event$target;
787
- var newValue = Number(event == null || (_event$target = event.target) == null ? void 0 : _event$target.value);
788
- if (availableOptions.includes(newValue)) {
789
- setValue(newValue);
790
- }
791
- },
792
- sx: {
793
- height: '40px',
794
- width: '100%'
795
- },
796
- value: String(availableOptions.includes(value) ? value : availableOptions[availableOptions.length - 1]),
797
- children: availableOptions.map(function (option) {
798
- return /*#__PURE__*/jsxs(MenuItem, {
799
- value: String(option),
800
- children: [option, " ", itemPostFix]
801
- }, option);
802
- })
803
- }));
804
- };
805
- var DayHourSelector = function DayHourSelector(_ref2) {
806
- var isDisabled = _ref2.isDisabled,
807
- dropdownButtonIcon = _ref2.dropdownButtonIcon,
808
- label = _ref2.label,
809
- maxHours = _ref2.maxHours,
810
- sx = _ref2.sx,
811
- useDays = _ref2.useDays,
812
- useHours = _ref2.useHours;
813
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
814
- t = _useTimesliderLiteTra.t;
815
- var days = useDays[0],
816
- setDays = useDays[1];
817
- var hours = useHours[0],
818
- setHours = useHours[1];
819
- var remainingHours = getRemainingHours(maxHours, days);
820
- var amountOfDayOptions = maxHours ? Math.floor(maxHours / 24) + 1 : 1;
821
- var amountOfHourOptions = maxHours ? Math.min(24, remainingHours + 1) : 1;
822
- return /*#__PURE__*/jsxs(Grid, {
823
- container: true,
824
- sx: sx,
825
- children: [/*#__PURE__*/jsx(Grid, {
826
- size: {
827
- xs: 3
828
- },
829
- children: /*#__PURE__*/jsx(SubmenuSelectLabel, {
830
- isDisabled: isDisabled || amountOfDayOptions === 1 && amountOfHourOptions === 1,
831
- children: label
832
- })
833
- }), /*#__PURE__*/jsx(Grid, {
834
- paddingX: "4px",
835
- size: {
836
- xs: 4.5
837
- },
838
- children: /*#__PURE__*/jsx(CustomSelect, {
839
- amountOfOptions: amountOfDayOptions,
840
- disabled: isDisabled || amountOfDayOptions === 1,
841
- dropdownButtonIcon: dropdownButtonIcon,
842
- itemPostFix: t('units.days'),
843
- setValue: setDays,
844
- value: days
845
- })
846
- }), /*#__PURE__*/jsx(Grid, {
847
- paddingLeft: "4px",
848
- size: {
849
- xs: 4.5
850
- },
851
- children: /*#__PURE__*/jsx(CustomSelect, {
852
- amountOfOptions: amountOfHourOptions,
853
- disabled: isDisabled || amountOfHourOptions === 1,
854
- dropdownButtonIcon: dropdownButtonIcon,
855
- itemPostFix: t('units.hours'),
856
- setValue: setHours,
857
- value: hours
858
- })
859
- })]
860
- });
861
- };
862
-
863
- /* *
864
- * Licensed under the Apache License, Version 2.0 (the "License");
865
- * you may not use this file except in compliance with the License.
866
- * You may obtain a copy of the License at
867
- *
868
- * http://www.apache.org/licenses/LICENSE-2.0
869
- *
870
- * Unless required by applicable law or agreed to in writing, software
871
- * distributed under the License is distributed on an "AS IS" BASIS,
872
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
873
- * See the License for the specific language governing permissions and
874
- * limitations under the License.
875
- *
876
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
877
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
878
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
879
- * */
880
-
881
- var TIME_SELECTOR_MIN_WIDTH = '21em';
882
- var TimeRangeOptions = function TimeRangeOptions(_ref) {
883
- var _ref$currentTime = _ref.currentTime,
884
- currentTime = _ref$currentTime === void 0 ? Date.now().valueOf() * MILLISECOND_TO_SECOND : _ref$currentTime,
885
- useTimeRange = _ref.useTimeRange,
886
- defaultTimeRange = _ref.defaultTimeRange,
887
- dropdownButtonIcon = _ref.dropdownButtonIcon;
888
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
889
- t = _useTimesliderLiteTra.t;
890
- var isReadOnly = useTimeRange === undefined;
891
- var isDefault = (useTimeRange == null ? void 0 : useTimeRange[0]) === null;
892
- var handleIsDefaultChange = function handleIsDefaultChange(event) {
893
- if (event.target.value === 'default' && useTimeRange != null && useTimeRange[1]) {
894
- useTimeRange[1](null);
895
- }
896
- if (event.target.value === 'custom' && useTimeRange != null && useTimeRange[1]) {
897
- useTimeRange[1](defaultTimeRange);
898
- }
899
- };
900
- var _React$useState = React.useState(0),
901
- forecastDays = _React$useState[0],
902
- setForecastDays = _React$useState[1];
903
- var _React$useState2 = React.useState(0),
904
- forecastHours = _React$useState2[0],
905
- setForecastHours = _React$useState2[1];
906
- var _React$useState3 = React.useState(0),
907
- observedDays = _React$useState3[0],
908
- setObservedDays = _React$useState3[1];
909
- var _React$useState4 = React.useState(0),
910
- observedHours = _React$useState4[0],
911
- setObservedHours = _React$useState4[1];
912
- useEffect(function () {
913
- if (!isDefault && !isReadOnly) {
914
- var observedSeconds = Math.min(hoursAndDaysToSeconds(observedHours, observedDays), currentTime - defaultTimeRange[0]);
915
- var forecastSeconds = Math.min(hoursAndDaysToSeconds(forecastHours, forecastDays), defaultTimeRange[1] - currentTime);
916
- if (useTimeRange != null && useTimeRange[1]) {
917
- useTimeRange[1]([currentTime - observedSeconds, currentTime + forecastSeconds]);
918
- }
919
- }
920
- // eslint-disable-next-line react-hooks/exhaustive-deps
921
- }, [forecastDays, forecastHours, observedDays, observedHours]);
922
- useLayoutEffect(function () {
923
- if (useTimeRange) {
924
- var timeRange = useTimeRange[0];
925
- var _ref2 = timeRange || defaultTimeRange,
926
- timeStart = _ref2[0],
927
- timeEnd = _ref2[1];
928
- var timeToEndSeconds = timeEnd - currentTime > 0 ? timeEnd - currentTime : 0;
929
- var timeToStartSeconds = currentTime - timeStart > 0 ? currentTime - timeStart : 0;
930
- var _secondsToDaysAndHour = secondsToDaysAndHours(timeToEndSeconds),
931
- _forecastDays = _secondsToDaysAndHour.days,
932
- _forecastHours = _secondsToDaysAndHour.hours;
933
- var _secondsToDaysAndHour2 = secondsToDaysAndHours(timeToStartSeconds),
934
- _observedDays = _secondsToDaysAndHour2.days,
935
- _observedHours = _secondsToDaysAndHour2.hours;
936
- setForecastDays(_forecastDays);
937
- setForecastHours(_forecastHours);
938
- setObservedDays(_observedDays);
939
- setObservedHours(_observedHours);
940
- }
941
- // eslint-disable-next-line react-hooks/exhaustive-deps
942
- }, [isDefault]);
943
- var customTimeRange = (useTimeRange == null ? void 0 : useTimeRange[0]) || defaultTimeRange;
944
- var minStartTime = Math.min(defaultTimeRange[0], customTimeRange[0]);
945
- var observedHoursToCurrentTime = (currentTime - minStartTime) * SECOND_TO_HOUR;
946
- var maxObservedHours = observedHoursToCurrentTime > 0 ? Math.floor(observedHoursToCurrentTime) : 0;
947
- var maxEndTime = Math.max(defaultTimeRange[1], customTimeRange[1]);
948
- var forecastHoursToCurrentTime = (maxEndTime - currentTime) * SECOND_TO_HOUR;
949
- var maxForecastHours = forecastHoursToCurrentTime > 0 ? Math.floor(forecastHoursToCurrentTime) : 0;
950
- return /*#__PURE__*/jsxs(CardContent, {
951
- className: "TimeSliderLite-timeRangeOptions",
952
- "data-testid": "TimeSliderLite-timeRangeOptions",
953
- sx: {
954
- paddingTop: '4px',
955
- '& label': {
956
- height: '36px'
957
- },
958
- '&:last-child': {
959
- paddingBottom: '16px'
960
- }
961
- },
962
- children: [t('menu.timeRange.description'), /*#__PURE__*/jsxs(RadioGroup, {
963
- defaultValue: isDefault ? 'default' : 'custom',
964
- name: "time-range-radio-button-group",
965
- onChange: handleIsDefaultChange,
966
- row: true,
967
- sx: {
968
- marginTop: 1
969
- },
970
- value: isDefault ? 'default' : 'custom',
971
- children: [/*#__PURE__*/jsx(FormControlLabel, {
972
- control: /*#__PURE__*/jsx(Radio, {}),
973
- disabled: isReadOnly,
974
- label: t('common.default'),
975
- value: "default"
976
- }), /*#__PURE__*/jsx(FormControlLabel, {
977
- control: /*#__PURE__*/jsx(Radio, {}),
978
- disabled: isReadOnly,
979
- label: t('common.custom'),
980
- value: "custom"
981
- })]
982
- }), /*#__PURE__*/jsxs(Box, {
983
- minWidth: TIME_SELECTOR_MIN_WIDTH,
984
- children: [/*#__PURE__*/jsx(DayHourSelector, {
985
- dropdownButtonIcon: dropdownButtonIcon,
986
- isDisabled: isDefault,
987
- label: t('common.observed'),
988
- maxHours: maxObservedHours,
989
- sx: {
990
- marginY: 1
991
- },
992
- useDays: [observedDays, setObservedDays],
993
- useHours: [observedHours, setObservedHours]
994
- }), /*#__PURE__*/jsx(DayHourSelector, {
995
- dropdownButtonIcon: dropdownButtonIcon,
996
- isDisabled: isDefault,
997
- label: t('common.forecast'),
998
- maxHours: maxForecastHours,
999
- useDays: [forecastDays, setForecastDays],
1000
- useHours: [forecastHours, setForecastHours]
1001
- })]
1002
- })]
1003
- });
1004
- };
1005
-
1006
- var _excluded$2 = ["dropdownButtonIcon", "value", "setValue", "defaultTimeStep", "timeStepOptions"];
1007
- var TimeStepSelector = function TimeStepSelector(_ref) {
1008
- var dropdownButtonIcon = _ref.dropdownButtonIcon,
1009
- value = _ref.value,
1010
- setValue = _ref.setValue,
1011
- defaultTimeStep = _ref.defaultTimeStep,
1012
- timeStepOptions = _ref.timeStepOptions,
1013
- props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
1014
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
1015
- t = _useTimesliderLiteTra.t;
1016
- var defaultTimeStepOptions = {
1017
- 5: "5 " + t('units.minutes'),
1018
- 15: "15 " + t('units.minutes'),
1019
- 30: "30 " + t('units.minutes'),
1020
- 60: "1 " + t('units.hours'),
1021
- 180: "3 " + t('units.hours'),
1022
- 360: "6 " + t('units.hours'),
1023
- 720: "12 " + t('units.hours')
1024
- };
1025
- var options = timeStepOptions != null ? timeStepOptions : defaultTimeStepOptions;
1026
- var allOptionsKeys = Object.keys(options);
1027
- var availableOptionKeys = allOptionsKeys.filter(function (option) {
1028
- return Number(option) >= defaultTimeStep;
1029
- });
1030
- return /*#__PURE__*/jsx(Select, Object.assign({}, props, {
1031
- IconComponent: dropdownButtonIcon,
1032
- className: "TimeSliderLite-timeStepSelect",
1033
- "data-testid": "TimeSliderLite-timeStepSelect",
1034
- inputProps: {
1035
- 'data-testid': 'TimeSliderLite-timeStepSelect-input'
1036
- },
1037
- onChange: function onChange(event) {
1038
- var _event$target;
1039
- var newValue = Number(event == null || (_event$target = event.target) == null ? void 0 : _event$target.value);
1040
- setValue(newValue);
1041
- },
1042
- sx: {
1043
- height: '40px',
1044
- width: '100%'
1045
- },
1046
- value: String(availableOptionKeys.includes(String(value)) ? value : availableOptionKeys[availableOptionKeys.length - 1]),
1047
- children: availableOptionKeys.map(function (option) {
1048
- return /*#__PURE__*/jsx(MenuItem, {
1049
- value: String(option),
1050
- children: options[option]
1051
- }, String(option));
1052
- })
1053
- }));
1054
- };
1055
-
1056
- /* *
1057
- * Licensed under the Apache License, Version 2.0 (the "License");
1058
- * you may not use this file except in compliance with the License.
1059
- * You may obtain a copy of the License at
1060
- *
1061
- * http://www.apache.org/licenses/LICENSE-2.0
1062
- *
1063
- * Unless required by applicable law or agreed to in writing, software
1064
- * distributed under the License is distributed on an "AS IS" BASIS,
1065
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1066
- * See the License for the specific language governing permissions and
1067
- * limitations under the License.
1068
- *
1069
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1070
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
1071
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
1072
- * */
1073
-
1074
- var TimeStepOptions = function TimeStepOptions(_ref) {
1075
- var useTimeStep = _ref.useTimeStep,
1076
- _ref$defaultTimeStep = _ref.defaultTimeStep,
1077
- defaultTimeStep = _ref$defaultTimeStep === void 0 ? [5, 15] : _ref$defaultTimeStep,
1078
- timeStepOptions = _ref.timeStepOptions,
1079
- dropdownButtonIcon = _ref.dropdownButtonIcon;
1080
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
1081
- t = _useTimesliderLiteTra.t;
1082
- var isReadOnly = useTimeStep === undefined;
1083
- var timeStep = useTimeStep == null ? void 0 : useTimeStep[0];
1084
- var setTimeStep = useTimeStep == null ? void 0 : useTimeStep[1];
1085
- var observedTimeStepProp = timeStep == null ? void 0 : timeStep[0];
1086
- var forecastTimeStepProp = timeStep == null ? void 0 : timeStep[1];
1087
- var isDefault = !useTimeStep || timeStep === null;
1088
- var defaultObservedTimeStep = defaultTimeStep[0];
1089
- var defaultForecastTimeStep = defaultTimeStep[1];
1090
- var _React$useState = React.useState(observedTimeStepProp != null ? observedTimeStepProp : defaultObservedTimeStep),
1091
- observedTimeStep = _React$useState[0],
1092
- setObservedTimeStep = _React$useState[1];
1093
- var _React$useState2 = React.useState(forecastTimeStepProp != null ? forecastTimeStepProp : defaultForecastTimeStep),
1094
- forecastTimeStep = _React$useState2[0],
1095
- setForecastTimeStep = _React$useState2[1];
1096
- useEffect(function () {
1097
- if (!isDefault && setTimeStep) {
1098
- setTimeStep([observedTimeStep, forecastTimeStep]);
1099
- }
1100
- // eslint-disable-next-line react-hooks/exhaustive-deps
1101
- }, [observedTimeStep, forecastTimeStep]);
1102
- var handleIsDefaultChange = function handleIsDefaultChange(event) {
1103
- if (event.target.value === 'default') {
1104
- setTimeStep == null || setTimeStep(null);
1105
- setObservedTimeStep(defaultTimeStep[0]);
1106
- setForecastTimeStep(defaultTimeStep[1]);
1107
- }
1108
- if (event.target.value === 'custom' && setTimeStep) {
1109
- setTimeStep(defaultTimeStep);
1110
- }
1111
- };
1112
- return /*#__PURE__*/jsxs(CardContent, {
1113
- "data-testid": "TimeSliderLite-timeStepOptions",
1114
- sx: {
1115
- paddingTop: '4px',
1116
- '& label': {
1117
- height: '36px'
1118
- },
1119
- '&:last-child': {
1120
- paddingBottom: '16px'
1121
- }
1122
- },
1123
- children: [/*#__PURE__*/jsxs(RadioGroup, {
1124
- defaultValue: isDefault ? 'default' : 'custom',
1125
- name: "time-range-radio-button-group",
1126
- onChange: handleIsDefaultChange,
1127
- row: true,
1128
- sx: {
1129
- marginTop: 1
1130
- },
1131
- value: isDefault ? 'default' : 'custom',
1132
- children: [/*#__PURE__*/jsx(FormControlLabel, {
1133
- control: /*#__PURE__*/jsx(Radio, {}),
1134
- disabled: isReadOnly,
1135
- label: t('common.default'),
1136
- value: "default"
1137
- }), /*#__PURE__*/jsx(FormControlLabel, {
1138
- control: /*#__PURE__*/jsx(Radio, {}),
1139
- disabled: isReadOnly,
1140
- label: t('common.custom'),
1141
- value: "custom"
1142
- })]
1143
- }), /*#__PURE__*/jsxs(Grid, {
1144
- container: true,
1145
- width: 250,
1146
- children: [/*#__PURE__*/jsx(Grid, {
1147
- size: {
1148
- xs: 4
1149
- },
1150
- sx: {
1151
- marginY: 1
1152
- },
1153
- children: /*#__PURE__*/jsx(SubmenuSelectLabel, {
1154
- isDisabled: isDefault,
1155
- children: t('common.observed')
1156
- })
1157
- }), /*#__PURE__*/jsx(Grid, {
1158
- paddingX: "4px",
1159
- size: {
1160
- xs: 8
1161
- },
1162
- sx: {
1163
- marginY: 1
1164
- },
1165
- children: /*#__PURE__*/jsx(TimeStepSelector, {
1166
- defaultTimeStep: defaultTimeStep[0],
1167
- disabled: isDefault,
1168
- dropdownButtonIcon: dropdownButtonIcon,
1169
- setValue: setObservedTimeStep,
1170
- timeStepOptions: timeStepOptions,
1171
- value: observedTimeStep
1172
- })
1173
- }), /*#__PURE__*/jsx(Grid, {
1174
- size: {
1175
- xs: 4
1176
- },
1177
- children: /*#__PURE__*/jsx(SubmenuSelectLabel, {
1178
- isDisabled: isDefault,
1179
- children: t('common.forecast')
1180
- })
1181
- }), /*#__PURE__*/jsx(Grid, {
1182
- paddingX: "4px",
1183
- size: {
1184
- xs: 8
1185
- },
1186
- children: /*#__PURE__*/jsx(TimeStepSelector, {
1187
- defaultTimeStep: defaultTimeStep[1],
1188
- disabled: isDefault,
1189
- dropdownButtonIcon: dropdownButtonIcon,
1190
- setValue: setForecastTimeStep,
1191
- timeStepOptions: timeStepOptions,
1192
- value: forecastTimeStep
1193
- })
1194
- })]
1195
- })]
1196
- });
1197
- };
1198
-
1199
- /* *
1200
- * Licensed under the Apache License, Version 2.0 (the "License");
1201
- * you may not use this file except in compliance with the License.
1202
- * You may obtain a copy of the License at
1203
- *
1204
- * http://www.apache.org/licenses/LICENSE-2.0
1205
- *
1206
- * Unless required by applicable law or agreed to in writing, software
1207
- * distributed under the License is distributed on an "AS IS" BASIS,
1208
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1209
- * See the License for the specific language governing permissions and
1210
- * limitations under the License.
1211
- *
1212
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1213
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
1214
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
1215
- * */
1216
-
1217
- var availableTimeZones = ['LT', 'UTC'];
1218
- var styles$3 = {
1219
- root: {
1220
- marginY: 0.5,
1221
- marginRight: 1,
1222
- '> button': {
1223
- borderRadius: 10,
1224
- height: '36px',
1225
- textTransform: 'none'
1226
- },
1227
- '> button:first-of-type': {
1228
- paddingRight: 1
1229
- },
1230
- '> button:last-of-type': {
1231
- paddingLeft: 1
1232
- }
1233
- }
1234
- };
1235
- var TimeZoneSwitch = function TimeZoneSwitch(_ref) {
1236
- var _ref$useTimeZone = _ref.useTimeZone,
1237
- _ref$useTimeZone2 = _ref$useTimeZone === void 0 ? ['LT', undefined] : _ref$useTimeZone,
1238
- timeZone = _ref$useTimeZone2[0],
1239
- setTimeZone = _ref$useTimeZone2[1];
1240
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
1241
- t = _useTimesliderLiteTra.t;
1242
- return /*#__PURE__*/jsx(ToggleButtonGroup, {
1243
- className: "TimeSliderLite-timeZoneSwitch",
1244
- "data-testid": "TimeSliderLite-timeZoneSwitch",
1245
- disabled: !setTimeZone,
1246
- exclusive: true,
1247
- onChange: function onChange(_event, newZone) {
1248
- if (newZone && setTimeZone) {
1249
- setTimeZone(newZone);
1250
- }
1251
- },
1252
- sx: styles$3.root,
1253
- value: timeZone != null ? timeZone : 'LT',
1254
- children: availableTimeZones.map(function (zone) {
1255
- return /*#__PURE__*/jsx(ToggleButton, {
1256
- value: zone,
1257
- children: t("menu." + zone)
1258
- }, zone);
1259
- })
1260
- });
1261
- };
1262
-
1263
- /* *
1264
- * Licensed under the Apache License, Version 2.0 (the "License");
1265
- * you may not use this file except in compliance with the License.
1266
- * You may obtain a copy of the License at
1267
- *
1268
- * http://www.apache.org/licenses/LICENSE-2.0
1269
- *
1270
- * Unless required by applicable law or agreed to in writing, software
1271
- * distributed under the License is distributed on an "AS IS" BASIS,
1272
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1273
- * See the License for the specific language governing permissions and
1274
- * limitations under the License.
1275
- *
1276
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1277
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
1278
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
1279
- * */
1280
-
1281
- var defaultUpdateIntervalOptions = [1, 2, 5, 10, 15, 30, 60];
1282
- var UpdateIntervalOptions = function UpdateIntervalOptions(_ref) {
1283
- var _useUpdateInterval$, _updateIntervalOption;
1284
- var _ref$defaultUpdateInt = _ref.defaultUpdateInterval,
1285
- defaultUpdateInterval = _ref$defaultUpdateInt === void 0 ? 1 : _ref$defaultUpdateInt,
1286
- dropdownButtonIcon = _ref.dropdownButtonIcon,
1287
- _ref$intervalOptionPr = _ref.intervalOptionPrefix,
1288
- intervalOptionPrefix = _ref$intervalOptionPr === void 0 ? '' : _ref$intervalOptionPr,
1289
- intervalOptionPostfix = _ref.intervalOptionPostfix,
1290
- defaultOptionPostfix = _ref.defaultOptionPostfix,
1291
- _ref$updateIntervalOp = _ref.updateIntervalOptions,
1292
- updateIntervalOptions = _ref$updateIntervalOp === void 0 ? defaultUpdateIntervalOptions.sort(function (optionA, optionB) {
1293
- return optionA - optionB;
1294
- }) : _ref$updateIntervalOp,
1295
- useUpdateInterval = _ref.useUpdateInterval;
1296
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
1297
- t = _useTimesliderLiteTra.t;
1298
- var translatedIntervalOptionPostfix = intervalOptionPostfix != null ? intervalOptionPostfix : " " + t('units.minutes');
1299
- var translatedDefaultOptionPostfix = defaultOptionPostfix != null ? defaultOptionPostfix : " " + t('units.minutes') + " (" + t('common.default').toLowerCase() + ")";
1300
- var updateInterval = (_useUpdateInterval$ = useUpdateInterval == null ? void 0 : useUpdateInterval[0]) != null ? _useUpdateInterval$ : defaultUpdateInterval;
1301
- var setUpdateInterval = useUpdateInterval == null ? void 0 : useUpdateInterval[1];
1302
- var readOnly = !setUpdateInterval || updateIntervalOptions.length < 2;
1303
- var defaultValue = (_updateIntervalOption = updateIntervalOptions.find(function (option) {
1304
- return option === defaultUpdateInterval;
1305
- })) != null ? _updateIntervalOption : Math.min.apply(Math, updateIntervalOptions);
1306
- return /*#__PURE__*/jsx(CardContent, {
1307
- className: "TimeSliderLite-updateIntervalOptions",
1308
- "data-testid": "TimeSliderLite-updateIntervalOptions",
1309
- sx: {
1310
- paddingTop: '12px',
1311
- marginBottom: '-8px',
1312
- minWidth: '200px'
1313
- },
1314
- children: /*#__PURE__*/jsx(Select, {
1315
- IconComponent: dropdownButtonIcon,
1316
- className: "TimeSliderLite-updateIntervalSelect",
1317
- "data-testid": "TimeSliderLite-updateIntervalSelect",
1318
- disabled: readOnly,
1319
- inputProps: {
1320
- 'data-testid': 'TimeSliderLite-updateIntervalSelect-input'
1321
- },
1322
- onChange: function onChange(event) {
1323
- var _event$target;
1324
- var newValue = Number(event == null || (_event$target = event.target) == null ? void 0 : _event$target.value);
1325
- setUpdateInterval == null || setUpdateInterval(newValue === defaultValue ? null : newValue);
1326
- },
1327
- sx: {
1328
- height: '40px'
1329
- },
1330
- value: String(updateInterval != null ? updateInterval : defaultValue),
1331
- children: updateIntervalOptions.map(function (option) {
1332
- var label = option === defaultValue ? "" + intervalOptionPrefix + option + translatedDefaultOptionPostfix : "" + intervalOptionPrefix + option + translatedIntervalOptionPostfix;
1333
- return /*#__PURE__*/jsx(MenuItem, {
1334
- value: String(option),
1335
- children: label
1336
- }, String(option));
1337
- })
1338
- })
1339
- });
1340
- };
1341
-
1342
- /* *
1343
- * Licensed under the Apache License, Version 2.0 (the "License");
1344
- * you may not use this file except in compliance with the License.
1345
- * You may obtain a copy of the License at
1346
- *
1347
- * http://www.apache.org/licenses/LICENSE-2.0
1348
- *
1349
- * Unless required by applicable law or agreed to in writing, software
1350
- * distributed under the License is distributed on an "AS IS" BASIS,
1351
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1352
- * See the License for the specific language governing permissions and
1353
- * limitations under the License.
1354
- *
1355
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1356
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
1357
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
1358
- * */
1359
-
1360
- var styles$2 = {
1361
- button: {
1362
- height: '36px',
1363
- lineHeight: '1em',
1364
- border: 'none',
1365
- textTransform: 'none',
1366
- borderRadius: '2px !important',
1367
- color: 'geowebColors.typographyAndIcons.text',
1368
- '&.Mui-selected': {
1369
- backgroundColor: 'geowebColors.timeSliderLite.selected.backgroundColor'
1370
- },
1371
- '&:disabled': {
1372
- border: 'none'
1373
- }
1374
- }
1375
- };
1376
-
1377
- // TODO: Add translations
1378
- var SubmenuTitleTranslations = /*#__PURE__*/function (SubmenuTitleTranslations) {
1379
- SubmenuTitleTranslations["TIME_RANGE"] = "menu.timeRange";
1380
- SubmenuTitleTranslations["TIME_STEP"] = "menu.timeStep";
1381
- SubmenuTitleTranslations["SPEED"] = "menu.speed";
1382
- SubmenuTitleTranslations["UPDATE_INTERVAL"] = "menu.updateInterval";
1383
- return SubmenuTitleTranslations;
1384
- }({});
1385
- var TimeSliderLiteOptionsMenu = function TimeSliderLiteOptionsMenu(_ref) {
1386
- var closeButtonIcon = _ref.closeButtonIcon,
1387
- _ref$currentTime = _ref.currentTime,
1388
- currentTime = _ref$currentTime === void 0 ? Date.now().valueOf() * MILLISECOND_TO_SECOND : _ref$currentTime,
1389
- defaultTimeRange = _ref.defaultTimeRange,
1390
- defaultTimeStep = _ref.defaultTimeStep,
1391
- defaultSpeedFactor = _ref.defaultSpeedFactor,
1392
- defaultUpdateInterval = _ref.defaultUpdateInterval,
1393
- dropdownButtonIcon = _ref.dropdownButtonIcon,
1394
- menuOpen = _ref.menuOpen,
1395
- setMenuOpen = _ref.setMenuOpen,
1396
- speedOptionItemPostfix = _ref.speedOptionItemPostfix,
1397
- speedOptionItemPrefix = _ref.speedOptionItemPrefix,
1398
- speedOptions = _ref.speedOptions,
1399
- updateIntervalOptions = _ref.updateIntervalOptions,
1400
- subMenuSx = _ref.subMenuSx,
1401
- sx = _ref.sx,
1402
- _ref$TimeZoneSwitch = _ref.TimeZoneSwitch,
1403
- TimeZoneSwitch$1 = _ref$TimeZoneSwitch === void 0 ? TimeZoneSwitch : _ref$TimeZoneSwitch,
1404
- timeStepOptions = _ref.timeStepOptions,
1405
- useAnimationSpeed = _ref.useAnimationSpeed,
1406
- useTimeRange = _ref.useTimeRange,
1407
- useTimeStep = _ref.useTimeStep,
1408
- useTimeZone = _ref.useTimeZone,
1409
- useUpdateInterval = _ref.useUpdateInterval;
1410
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
1411
- t = _useTimesliderLiteTra.t;
1412
- var _React$useState = React.useState(null),
1413
- submenu = _React$useState[0],
1414
- setSubmenu = _React$useState[1];
1415
- var _React$useState2 = React.useState(0),
1416
- submenuLeft = _React$useState2[0],
1417
- setSubmenuLeft = _React$useState2[1];
1418
- return /*#__PURE__*/jsxs(Fragment, {
1419
- children: [!!submenu && /*#__PURE__*/jsxs(SubmenuWrapper, {
1420
- closeButtonIcon: closeButtonIcon,
1421
- setSubmenu: setSubmenu,
1422
- sx: Object.assign({
1423
- left: submenuLeft,
1424
- marginLeft: '-12px'
1425
- }, Array.isArray(subMenuSx) ? Object.assign.apply(Object, [{}].concat(subMenuSx)) : subMenuSx),
1426
- title: t(submenu + ".title"),
1427
- children: [submenu === SubmenuTitleTranslations.TIME_RANGE && /*#__PURE__*/jsx(TimeRangeOptions, {
1428
- currentTime: currentTime,
1429
- defaultTimeRange: defaultTimeRange,
1430
- dropdownButtonIcon: dropdownButtonIcon,
1431
- useTimeRange: useTimeRange
1432
- }), submenu === SubmenuTitleTranslations.TIME_STEP && /*#__PURE__*/jsx(TimeStepOptions, {
1433
- defaultTimeStep: defaultTimeStep,
1434
- dropdownButtonIcon: dropdownButtonIcon,
1435
- timeStepOptions: timeStepOptions,
1436
- useTimeStep: useTimeStep
1437
- }), submenu === SubmenuTitleTranslations.SPEED && /*#__PURE__*/jsx(AnimationSpeedOptions, {
1438
- defaultSpeedFactor: defaultSpeedFactor,
1439
- dropdownButtonIcon: dropdownButtonIcon,
1440
- speedOptionItemPostfix: speedOptionItemPostfix,
1441
- speedOptionItemPrefix: speedOptionItemPrefix,
1442
- speedOptions: speedOptions,
1443
- useAnimationSpeed: useAnimationSpeed
1444
- }), submenu === SubmenuTitleTranslations.UPDATE_INTERVAL && /*#__PURE__*/jsx(UpdateIntervalOptions, {
1445
- defaultUpdateInterval: defaultUpdateInterval,
1446
- dropdownButtonIcon: dropdownButtonIcon,
1447
- updateIntervalOptions: updateIntervalOptions,
1448
- useUpdateInterval: useUpdateInterval
1449
- })]
1450
- }), /*#__PURE__*/jsxs(Box, {
1451
- sx: Object.assign({
1452
- backgroundColor: 'geowebColors.background.surface',
1453
- borderRadius: 1,
1454
- display: 'flex',
1455
- flexDirection: 'row',
1456
- marginY: 1,
1457
- visibility: menuOpen ? 'visible' : 'hidden'
1458
- }, Array.isArray(sx) ? Object.assign.apply(Object, [{}].concat(sx)) : sx),
1459
- children: [/*#__PURE__*/jsx(ToggleButtonGroup, {
1460
- "data-testid": "TimeSliderLite-optionsMenu",
1461
- exclusive: true,
1462
- onChange: function onChange(event, newOption) {
1463
- setSubmenu(newOption);
1464
- var button = event.currentTarget;
1465
- var buttonPosition = button.getBoundingClientRect();
1466
- setSubmenuLeft(buttonPosition.x);
1467
- },
1468
- sx: {
1469
- padding: 0.5,
1470
- gap: 0.5
1471
- },
1472
- value: submenu,
1473
- children: Object.values(SubmenuTitleTranslations).map(function (value) {
1474
- return /*#__PURE__*/jsx(ToggleButton, {
1475
- sx: styles$2.button,
1476
- value: value,
1477
- children: t(value + ".button")
1478
- }, value);
1479
- })
1480
- }), /*#__PURE__*/jsx(TimeZoneSwitch$1, {
1481
- useTimeZone: useTimeZone != null ? useTimeZone : ['LT']
1482
- }), /*#__PURE__*/jsx(Divider, {
1483
- flexItem: true,
1484
- orientation: "vertical"
1485
- }), /*#__PURE__*/jsx(IconButton, {
1486
- "data-testid": "TimeSliderLite-optionsMenu-closeButton",
1487
- onClick: function onClick() {
1488
- return setMenuOpen == null ? void 0 : setMenuOpen(false);
1489
- },
1490
- size: "small",
1491
- sx: {
1492
- margin: 0.5
1493
- },
1494
- children: closeButtonIcon != null ? closeButtonIcon : /*#__PURE__*/jsx(Close, {})
1495
- })]
1496
- })]
1497
- });
1498
- };
1499
-
1500
- /* *
1501
- * Licensed under the Apache License, Version 2.0 (the "License");
1502
- * you may not use this file except in compliance with the License.
1503
- * You may obtain a copy of the License at
1504
- *
1505
- * http://www.apache.org/licenses/LICENSE-2.0
1506
- *
1507
- * Unless required by applicable law or agreed to in writing, software
1508
- * distributed under the License is distributed on an "AS IS" BASIS,
1509
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1510
- * See the License for the specific language governing permissions and
1511
- * limitations under the License.
1512
- *
1513
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1514
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
1515
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
1516
- * */
1517
- var DRAG_AREA_WIDTH = 10;
1518
- var NEEDLE_WIDTH = 5;
1519
- var SHADOW_SPREAD = 2;
1520
- var NeedleShadow = function NeedleShadow(_ref) {
1521
- var x = _ref.x,
1522
- stroke = _ref.stroke,
1523
- height = _ref.height,
1524
- width = _ref.width;
1525
- return /*#__PURE__*/jsx("line", {
1526
- "data-testid": "TimeSliderLite-NeedleShadow",
1527
- filter: "blur(0.5px)",
1528
- stroke: stroke,
1529
- strokeLinecap: "round",
1530
- strokeWidth: width + SHADOW_SPREAD,
1531
- x1: x,
1532
- x2: x,
1533
- y1: height - (height - SHADOW_SPREAD / 2),
1534
- y2: height - SHADOW_SPREAD / 2
1535
- });
1536
- };
1537
- var NeedleLine = function NeedleLine(_ref2) {
1538
- var x = _ref2.x,
1539
- stroke = _ref2.stroke,
1540
- height = _ref2.height,
1541
- width = _ref2.width;
1542
- return /*#__PURE__*/jsx("line", {
1543
- "data-testid": "TimeSliderLite-NeedleLine",
1544
- stroke: stroke,
1545
- strokeLinecap: "round",
1546
- strokeWidth: width,
1547
- x1: x,
1548
- x2: x,
1549
- y1: width / 2,
1550
- y2: height - width / 2
1551
- });
1552
- };
1553
- var TimeSliderDraggableNeedle = function TimeSliderDraggableNeedle(_ref3) {
1554
- var draggableLabel = _ref3.draggableLabel,
1555
- width = _ref3.width,
1556
- height = _ref3.height,
1557
- _ref3$timeZone = _ref3.timeZone,
1558
- timeZone = _ref3$timeZone === void 0 ? 'LT' : _ref3$timeZone,
1559
- _ref3$currentTime = _ref3.currentTime,
1560
- currentTime = _ref3$currentTime === void 0 ? Date.now() * MILLISECOND_TO_SECOND : _ref3$currentTime,
1561
- currentTimeSelected = _ref3.currentTimeSelected,
1562
- startTime = _ref3.startTime,
1563
- endTime = _ref3.endTime,
1564
- disableForecast = _ref3.disableForecast,
1565
- _ref3$needleDragAreaW = _ref3.needleDragAreaWidth,
1566
- needleDragAreaWidth = _ref3$needleDragAreaW === void 0 ? DRAG_AREA_WIDTH : _ref3$needleDragAreaW,
1567
- needleLabelZIndex = _ref3.needleLabelZIndex,
1568
- _ref3$needleLabelOffs = _ref3.needleLabelOffset,
1569
- needleLabelOffset = _ref3$needleLabelOffs === void 0 ? [0, -5] : _ref3$needleLabelOffs,
1570
- _ref3$needleWidth = _ref3.needleWidth,
1571
- needleWidth = _ref3$needleWidth === void 0 ? NEEDLE_WIDTH : _ref3$needleWidth,
1572
- timeStep = _ref3.timeStep,
1573
- selectedTime = _ref3.selectedTime,
1574
- setSelectedTime = _ref3.setSelectedTime,
1575
- style = _ref3.style,
1576
- onDoubleClick = _ref3.onDoubleClick;
1577
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
1578
- i18n = _useTimesliderLiteTra.i18n;
1579
- var language = i18n.language;
1580
- var draggableRef = useRef(null);
1581
- var _useTheme = useTheme(),
1582
- timeSliderLite = _useTheme.palette.geowebColors.timeSliderLite;
1583
- var timeZoneOffset = timeZone === 'UTC' ? 0 : undefined;
1584
- var observedTimeStepSeconds = timeStep[0];
1585
- var forecastTimeStepSeconds = timeStep[1];
1586
- var timeStepSeconds = selectedTime >= currentTime ? forecastTimeStepSeconds : observedTimeStepSeconds;
1587
- var lastObservedTime = floorLocalSeconds(currentTime, observedTimeStepSeconds, timeZoneOffset);
1588
- var firstForecastTime = floorLocalSeconds(currentTime, forecastTimeStepSeconds, timeZoneOffset) + forecastTimeStepSeconds;
1589
- var selectedTimePx = getSelectedTimePx(startTime, endTime, selectedTime, width);
1590
- var x = selectedTimePx > 0 ? selectedTimePx - needleDragAreaWidth / 2 : -needleDragAreaWidth / 2;
1591
- var isBetweenObservedAndForecast = selectedTime >= lastObservedTime && selectedTime < firstForecastTime;
1592
- var roundedSelectedTime = isBetweenObservedAndForecast ? lastObservedTime : floorLocalSeconds(selectedTime, timeStepSeconds, timeZoneOffset);
1593
- var dateString = new Date(roundedSelectedTime * 1000).toLocaleDateString(language, {
1594
- weekday: 'short',
1595
- month: 'numeric',
1596
- day: 'numeric',
1597
- hour: 'numeric',
1598
- minute: 'numeric',
1599
- timeZone: timeZone === 'UTC' ? 'UTC' : undefined
1600
- });
1601
- var localLabel = language === 'fi' || language === 'sv-FI' ? reformatFinnishDateString(dateString) : dateString;
1602
- var label = timeZone === 'UTC' ? shortUTCTime(localLabel) : localLabel;
1603
- return /*#__PURE__*/jsx(Draggable, {
1604
- axis: "x",
1605
- bounds: {
1606
- left: -needleDragAreaWidth / 2,
1607
- right: width - needleDragAreaWidth / 2
1608
- },
1609
- handle: ".TimeSliderLite-DraggableNeedle",
1610
- nodeRef: draggableRef,
1611
- onDrag: function onDrag(_, position) {
1612
- var positionOffsetToCompensateFlooring = 0.5;
1613
- var needleCenterPosition = position.x + needleDragAreaWidth / 2 + positionOffsetToCompensateFlooring;
1614
- var newSelectedTime = getSelectedTimeFromPx(startTime, endTime, needleCenterPosition, width);
1615
- if (disableForecast && newSelectedTime >= lastObservedTime) {
1616
- setSelectedTime(lastObservedTime);
1617
- }
1618
- setSelectedTime(newSelectedTime);
1619
- },
1620
- onStop: function onStop(_, position) {
1621
- var positionOffsetToCompensateFlooring = 0.5;
1622
- var needleCenterPosition = position.x + needleDragAreaWidth / 2 + positionOffsetToCompensateFlooring;
1623
- var newSelectedTime = getSelectedTimeFromPx(startTime, endTime, needleCenterPosition, width);
1624
- var isLastObservedTime = newSelectedTime >= lastObservedTime && newSelectedTime < firstForecastTime || newSelectedTime >= lastObservedTime && disableForecast;
1625
- var roundedSelectedTime = isLastObservedTime ? lastObservedTime : floorLocalSeconds(newSelectedTime, timeStepSeconds, timeZoneOffset);
1626
- setSelectedTime(roundedSelectedTime);
1627
- },
1628
- position: {
1629
- x: x,
1630
- y: 0
1631
- },
1632
- children: /*#__PURE__*/jsxs(Box, {
1633
- className: "TimeSliderLite-DraggableNeedle",
1634
- "data-testid": "TimeSliderLite-DraggableNeedle",
1635
- onDoubleClick: onDoubleClick,
1636
- ref: draggableRef,
1637
- sx: {
1638
- overflow: 'visible'
1639
- },
1640
- children: [/*#__PURE__*/jsxs("svg", {
1641
- cursor: "ew-resize",
1642
- "data-testid": "TimeSliderLite-NeedleSvg",
1643
- height: height,
1644
- style: style,
1645
- width: needleDragAreaWidth,
1646
- children: [/*#__PURE__*/jsx(NeedleShadow, {
1647
- height: height,
1648
- stroke: timeSliderLite.needleShadow.stroke,
1649
- width: needleWidth,
1650
- x: needleDragAreaWidth / 2
1651
- }), /*#__PURE__*/jsx(NeedleLine, {
1652
- height: height,
1653
- stroke: currentTimeSelected ? timeSliderLite.needleDefault.stroke : timeSliderLite.needle.stroke,
1654
- width: needleWidth,
1655
- x: needleDragAreaWidth / 2
1656
- })]
1657
- }), /*#__PURE__*/jsxs(Box, {
1658
- bottom: "-1px",
1659
- className: "TimeSliderLite-timeStamp",
1660
- position: "absolute",
1661
- sx: {
1662
- backgroundColor: timeSliderLite.needleLabel.backgroundColor,
1663
- border: "1px solid " + timeSliderLite.needleLabel.borderColor,
1664
- borderRadius: '4px',
1665
- className: draggableLabel ? 'TimeSliderLite-DraggableNeedle' : '',
1666
- color: timeSliderLite.needleLabel.color,
1667
- cursor: draggableLabel ? 'ew-resize' : null,
1668
- fontSize: '12px',
1669
- padding: '0px 4px 0px 4px',
1670
- pointerEvents: draggableLabel ? null : 'none',
1671
- transform: "translate(calc(-50% + " + needleWidth + "px + " + needleLabelOffset[0] + "px), " + needleLabelOffset[1] + "px)",
1672
- zIndex: needleLabelZIndex != null ? needleLabelZIndex : null
1673
- },
1674
- children: [label, /*#__PURE__*/jsx(Box, {
1675
- bottom: "-4px",
1676
- className: "TimeSliderLite-timeStamp-tail",
1677
- height: "10px",
1678
- position: "absolute",
1679
- sx: {
1680
- backgroundColor: timeSliderLite.needleLabel.backgroundColor,
1681
- transform: 'rotate(45deg)',
1682
- left: "calc(50% - 5px - " + needleLabelOffset[0] + "px)",
1683
- zIndex: -1
1684
- },
1685
- width: "10px"
1686
- })]
1687
- })]
1688
- })
1689
- });
1690
- };
1691
-
1692
- /* *
1693
- * Licensed under the Apache License, Version 2.0 (the "License");
1694
- * you may not use this file except in compliance with the License.
1695
- * You may obtain a copy of the License at
1696
- *
1697
- * http://www.apache.org/licenses/LICENSE-2.0
1698
- *
1699
- * Unless required by applicable law or agreed to in writing, software
1700
- * distributed under the License is distributed on an "AS IS" BASIS,
1701
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1702
- * See the License for the specific language governing permissions and
1703
- * limitations under the License.
1704
- *
1705
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1706
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
1707
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
1708
- * */
1709
-
1710
- var OBSERVED_PADDING_DAYS = 1;
1711
- var FORECAST_PADDING_DAYS = OBSERVED_PADDING_DAYS + 2;
1712
- var TICK_HEIGHT = 6;
1713
- var HOUR_LABEL_OFFSET = 1.5;
1714
- var MONTH_LABEL_BREAKPOINT = 65;
1715
- var HOUR_LABEL_BREAKPOINT = 800;
1716
- var HOUR_LABEL_EVERY_THIRD_HOUR_BREAKPOINT = 1600;
1717
- var TIME_SLIDER_LITE_PADDING_RIGHT = 1;
1718
- var TimeSliderLiteBackgroundSvg = function TimeSliderLiteBackgroundSvg(_ref) {
1719
- var width = _ref.width,
1720
- height = _ref.height,
1721
- startTime = _ref.startTime,
1722
- endTime = _ref.endTime,
1723
- disableForecast = _ref.disableForecast,
1724
- _ref$currentTime = _ref.currentTime,
1725
- currentTime = _ref$currentTime === void 0 ? Date.now() * MILLISECOND_TO_SECOND : _ref$currentTime,
1726
- timeStep = _ref.timeStep,
1727
- style = _ref.style,
1728
- _ref$timeZone = _ref.timeZone,
1729
- timeZone = _ref$timeZone === void 0 ? 'LT' : _ref$timeZone;
1730
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
1731
- i18n = _useTimesliderLiteTra.i18n;
1732
- var language = i18n.language;
1733
- var _useTheme = useTheme(),
1734
- timeSliderLite = _useTheme.palette.geowebColors.timeSliderLite;
1735
- if (!width) {
1736
- return /*#__PURE__*/jsx("svg", {
1737
- height: height,
1738
- style: style
1739
- });
1740
- }
1741
-
1742
- // Convert start and end time from Unix timestamp to JavaScript Date object
1743
- var startDate = new Date(startTime * SECOND_TO_MILLISECOND);
1744
- var endDate = new Date(endTime * SECOND_TO_MILLISECOND);
1745
- var totalDays = (endDate.getTime() - startDate.getTime()) * MILLISECOND_TO_DAY;
1746
- var utcOffset = timeZone === 'UTC' ? new Date().getTimezoneOffset() * 60 * SECOND_TO_DAY : 0;
1747
- var tickSpacing = width / totalDays;
1748
- if (tickSpacing === Infinity || tickSpacing === -Infinity || isNaN(tickSpacing)) {
1749
- return null;
1750
- }
1751
- var startTimeDayOffset = secondsSinceLocalMidnight(startTime) * SECOND_TO_DAY + utcOffset;
1752
- var tickOffset = startTimeDayOffset * tickSpacing;
1753
- var showMonthLabel = tickSpacing < MONTH_LABEL_BREAKPOINT;
1754
- var maxTimeStep = timeStep ? Math.max.apply(Math, timeStep) : null;
1755
- var hideHourLabels = maxTimeStep && maxTimeStep > 60 * 60 * 3;
1756
- var showHourLabel = !hideHourLabels && tickSpacing > HOUR_LABEL_BREAKPOINT;
1757
- var limitHourLabelsToEveryThirdHour = maxTimeStep && maxTimeStep > 60 * 60;
1758
- var showHourLabelEveryThirdHour = limitHourLabelsToEveryThirdHour || tickSpacing < HOUR_LABEL_EVERY_THIRD_HOUR_BREAKPOINT;
1759
-
1760
- // Set up variables for date labels and background colors
1761
- var dayLabels = [];
1762
- var dayLabelDate = new Date(startTime * SECOND_TO_MILLISECOND - OBSERVED_PADDING_DAYS * DAY_TO_MILLISECOND);
1763
- var lastDayLabelDate = new Date(endDate.getTime() + FORECAST_PADDING_DAYS * DAY_TO_MILLISECOND);
1764
- while (dayLabelDate < lastDayLabelDate) {
1765
- var dateString = dayLabelDate.toLocaleDateString(language, {
1766
- weekday: 'short',
1767
- month: 'numeric',
1768
- day: 'numeric'
1769
- });
1770
- var label = dateString.charAt(0).toUpperCase() + dateString.slice(1);
1771
- dayLabels.push(label);
1772
- dayLabelDate.setDate(dayLabelDate.getDate() + 1);
1773
- }
1774
- var monthChanges = getMonthChanges(startDate, endDate);
1775
- var monthLabels = showMonthLabel ? monthChanges.map(function (monthChange) {
1776
- var x = getSelectedTimePx(startTime, endTime, monthChange, width) + 4;
1777
- var dateString = new Date(monthChange * 1000).toLocaleDateString(language, {
1778
- weekday: 'short',
1779
- month: 'numeric',
1780
- day: 'numeric'
1781
- });
1782
- var label = dateString.charAt(0).toUpperCase() + dateString.slice(1);
1783
- return /*#__PURE__*/jsx("text", {
1784
- fill: timeSliderLite.timeline.fill,
1785
- fontSize: "12px",
1786
- style: {
1787
- userSelect: 'none'
1788
- },
1789
- textAnchor: "left",
1790
- x: x,
1791
- y: 14,
1792
- children: label
1793
- }, monthChange + "-month-change-text");
1794
- }) : null;
1795
- var currentDayIndex = (currentTime - startTime) * SECOND_TO_DAY + startTimeDayOffset + OBSERVED_PADDING_DAYS;
1796
- var backgroundRectangles = dayLabels.map(function (label, index) {
1797
- var observedColor = index % 2 === 0 ? timeSliderLite.timelineBackgroundObserved.fill : timeSliderLite.timelineBackgroundObservedAlternative.fill;
1798
- var enabledForecastColor = index % 2 === 0 ? timeSliderLite.timelineBackgroundAlternative.fill : timeSliderLite.timelineBackground.fill;
1799
- var disabledForecastColor = index % 2 === 0 ? timeSliderLite.timelineBackgroundDisabled.fill : timeSliderLite.timelineBackgroundDisabledAlternative.fill;
1800
- var forecastColor = disableForecast ? disabledForecastColor : enabledForecastColor;
1801
- var defaultProps = {
1802
- x: Math.floor((index - OBSERVED_PADDING_DAYS) * tickSpacing - tickOffset),
1803
- y: 0,
1804
- height: height
1805
- };
1806
- var isObserved = index + 1 < currentDayIndex;
1807
- var baseRectangle = /*#__PURE__*/createElement("rect", Object.assign({}, defaultProps, {
1808
- "data-testid": "TimeSliderLite-BackgroundRectangle-" + (isObserved ? 'Observed' : 'Forecast'),
1809
- fill: isObserved ? observedColor : forecastColor,
1810
- key: label + "-color",
1811
- width: Math.ceil(tickSpacing)
1812
- }));
1813
- var localDayOffset = secondsSinceLocalMidnight(currentTime) * SECOND_TO_DAY + utcOffset;
1814
- var isCurrentDay = index === Math.floor(currentDayIndex);
1815
- if (isCurrentDay) {
1816
- var partialRectangle = /*#__PURE__*/createElement("rect", Object.assign({}, defaultProps, {
1817
- fill: observedColor,
1818
- key: label + "-partial-color",
1819
- width: tickSpacing * localDayOffset
1820
- }));
1821
- return [baseRectangle, partialRectangle];
1822
- }
1823
- return baseRectangle;
1824
- }).flat();
1825
- var dailyLabels = !showMonthLabel ? dayLabels.map(function (label, index) {
1826
- return /*#__PURE__*/jsx("text", {
1827
- fill: timeSliderLite.timeline.fill,
1828
- fontSize: "12px",
1829
- style: {
1830
- userSelect: 'none'
1831
- },
1832
- textAnchor: "left",
1833
- x: (index - OBSERVED_PADDING_DAYS) * tickSpacing + 8 - tickOffset,
1834
- y: 14,
1835
- children: dayLabels[index]
1836
- }, label + "-text");
1837
- }) : null;
1838
- var hourLabelsPerDay = 24;
1839
- var hourLabels = showHourLabel ? dayLabels.map(function (label, index) {
1840
- return Array.from({
1841
- length: hourLabelsPerDay
1842
- }, function (_, value) {
1843
- var defaultProps = {
1844
- x: (index - OBSERVED_PADDING_DAYS) * tickSpacing + value * (tickSpacing / hourLabelsPerDay) - tickOffset - HOUR_LABEL_OFFSET,
1845
- y: height - 10,
1846
- visibility: showHourLabelEveryThirdHour && value % 3 !== 0 ? 'hidden' : 'visible',
1847
- fill: timeSliderLite.timeline.fill,
1848
- fontSize: '12px'
1849
- };
1850
- return /*#__PURE__*/jsxs("g", {
1851
- children: [/*#__PURE__*/jsx("text", Object.assign({}, defaultProps, {
1852
- style: {
1853
- userSelect: 'none'
1854
- },
1855
- textAnchor: "end",
1856
- children: value
1857
- })), /*#__PURE__*/jsx("text", Object.assign({}, defaultProps, {
1858
- style: {
1859
- userSelect: 'none'
1860
- },
1861
- textAnchor: "start",
1862
- children: ":00"
1863
- })), ","]
1864
- }, label + "-" + value + "-hourLabel");
1865
- });
1866
- }).flat() : null;
1867
- var tickMarks = dayLabels.map(function (label, index) {
1868
- var defaultProps = {
1869
- y1: height,
1870
- y2: Math.floor(height - TICK_HEIGHT),
1871
- stroke: timeSliderLite.timeline.stroke
1872
- };
1873
- var ticksPerDay = timeStep ? maxSubTicksPerDay(tickSpacing, index > currentDayIndex ? timeStep[1] : timeStep[0]) : subTicksPerDay(tickSpacing);
1874
- var isCurrentDay = index === Math.floor(currentDayIndex);
1875
- if (isCurrentDay && timeStep) {
1876
- var observedTicksPerDay = maxSubTicksPerDay(tickSpacing, timeStep[0]);
1877
- var forecastTicksPerDay = maxSubTicksPerDay(tickSpacing, timeStep[1]);
1878
- var observedTickMarksFromStartOfDay = Array.from({
1879
- length: Math.floor(observedTicksPerDay * (currentDayIndex - index)) + 1
1880
- }, function (_, value) {
1881
- return /*#__PURE__*/createElement("line", Object.assign({}, defaultProps, {
1882
- key: label + "-" + value + "-observed-tick",
1883
- x1: (index - OBSERVED_PADDING_DAYS) * tickSpacing + value * (tickSpacing / observedTicksPerDay) - tickOffset,
1884
- x2: (index - OBSERVED_PADDING_DAYS) * tickSpacing + value * (tickSpacing / observedTicksPerDay) - tickOffset
1885
- }));
1886
- });
1887
- var forecastTickMarksFromEndOfDay = Array.from({
1888
- length: Math.floor(forecastTicksPerDay * (1 - (currentDayIndex - index))) + 1
1889
- }, function (_, value) {
1890
- return /*#__PURE__*/createElement("line", Object.assign({}, defaultProps, {
1891
- key: label + "-" + value + "-forecast-tick",
1892
- x1: (index + 1 - OBSERVED_PADDING_DAYS) * tickSpacing - value * (tickSpacing / forecastTicksPerDay) - tickOffset,
1893
- x2: (index + 1 - OBSERVED_PADDING_DAYS) * tickSpacing - value * (tickSpacing / forecastTicksPerDay) - tickOffset
1894
- }));
1895
- });
1896
- return [].concat(observedTickMarksFromStartOfDay, forecastTickMarksFromEndOfDay);
1897
- }
1898
- return Array.from({
1899
- length: ticksPerDay + 1
1900
- }, function (_, value) {
1901
- return /*#__PURE__*/createElement("line", Object.assign({}, defaultProps, {
1902
- key: label + "-" + value + "-tick",
1903
- x1: (index - OBSERVED_PADDING_DAYS) * tickSpacing + value * (tickSpacing / ticksPerDay) - tickOffset,
1904
- x2: (index - OBSERVED_PADDING_DAYS) * tickSpacing + value * (tickSpacing / ticksPerDay) - tickOffset
1905
- }));
1906
- });
1907
- }).flat();
1908
- return /*#__PURE__*/jsxs("svg", {
1909
- height: height,
1910
- style: style,
1911
- width: width + TIME_SLIDER_LITE_PADDING_RIGHT,
1912
- children: [backgroundRectangles, tickMarks, monthLabels, dailyLabels, hourLabels]
1913
- });
1914
- };
1915
-
1916
- /* *
1917
- * Licensed under the Apache License, Version 2.0 (the "License");
1918
- * you may not use this file except in compliance with the License.
1919
- * You may obtain a copy of the License at
1920
- *
1921
- * http://www.apache.org/licenses/LICENSE-2.0
1922
- *
1923
- * Unless required by applicable law or agreed to in writing, software
1924
- * distributed under the License is distributed on an "AS IS" BASIS,
1925
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1926
- * See the License for the specific language governing permissions and
1927
- * limitations under the License.
1928
- *
1929
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1930
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
1931
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
1932
- * */
1933
-
1934
- var HOVER_NEEDLE_WIDTH = 1;
1935
- var DEFAULT_OPACITY = 0.5;
1936
- var TimeSliderClickableTimeline = function TimeSliderClickableTimeline(_ref) {
1937
- var _ref$currentTime = _ref.currentTime,
1938
- currentTime = _ref$currentTime === void 0 ? Date.now() * MILLISECOND_TO_SECOND : _ref$currentTime,
1939
- endTime = _ref.endTime,
1940
- disableForecast = _ref.disableForecast,
1941
- _ref$opacity = _ref.opacity,
1942
- opacity = _ref$opacity === void 0 ? DEFAULT_OPACITY : _ref$opacity,
1943
- setSelectedTime = _ref.setSelectedTime,
1944
- startTime = _ref.startTime,
1945
- timeStep = _ref.timeStep,
1946
- width = _ref.width,
1947
- timeZone = _ref.timeZone;
1948
- var _React$useState = React.useState(false),
1949
- isShown = _React$useState[0],
1950
- setIsShown = _React$useState[1];
1951
- var _React$useState2 = React.useState(0),
1952
- mouseX = _React$useState2[0],
1953
- setMouseX = _React$useState2[1];
1954
- var _useTheme = useTheme(),
1955
- timeSliderLite = _useTheme.palette.geowebColors.timeSliderLite;
1956
- var needleSuggestion = getNearestSelectableTime(timeStep, startTime, endTime, mouseX, width, currentTime, disableForecast, timeZone === 'UTC' ? 0 : undefined);
1957
- var x = getSelectedTimePx(startTime, endTime, needleSuggestion, width);
1958
- if (isNaN(x)) {
1959
- return null;
1960
- }
1961
- return /*#__PURE__*/jsx("svg", {
1962
- "data-testid": "TimeSliderLite-clickableTimeline",
1963
- onClick: function onClick() {
1964
- return setSelectedTime(needleSuggestion);
1965
- },
1966
- onMouseEnter: function onMouseEnter() {
1967
- return setIsShown(true);
1968
- },
1969
- onMouseLeave: function onMouseLeave() {
1970
- return setIsShown(false);
1971
- },
1972
- onMouseMove: function onMouseMove(event) {
1973
- isShown && setMouseX(event.nativeEvent.offsetX);
1974
- },
1975
- style: {
1976
- position: 'absolute',
1977
- width: '100%',
1978
- height: '100%',
1979
- cursor: 'pointer'
1980
- },
1981
- children: /*#__PURE__*/jsx("line", {
1982
- opacity: isShown ? opacity : 0,
1983
- stroke: timeSliderLite.timeline.stroke,
1984
- strokeWidth: HOVER_NEEDLE_WIDTH,
1985
- style: {
1986
- transition: 'opacity 0.2s ease-in-out'
1987
- },
1988
- x1: x,
1989
- x2: x,
1990
- y1: "0",
1991
- y2: "100%"
1992
- })
1993
- });
1994
- };
1995
-
1996
- /* *
1997
- * Licensed under the Apache License, Version 2.0 (the "License");
1998
- * you may not use this file except in compliance with the License.
1999
- * You may obtain a copy of the License at
2000
- *
2001
- * http://www.apache.org/licenses/LICENSE-2.0
2002
- *
2003
- * Unless required by applicable law or agreed to in writing, software
2004
- * distributed under the License is distributed on an "AS IS" BASIS,
2005
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2006
- * See the License for the specific language governing permissions and
2007
- * limitations under the License.
2008
- *
2009
- * Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2010
- * Copyright 2024 - Finnish Meteorological Institute (FMI)
2011
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2012
- * */
2013
- var styles$1 = {
2014
- centeredBox: {
2015
- borderRadius: '4px',
2016
- bottom: 'calc(50% - 0.5rem - 2px)',
2017
- left: '50%',
2018
- padding: '0px 3px 0px 3px',
2019
- position: 'absolute',
2020
- transform: 'translateX(-50%)'
2021
- }
2022
- };
2023
- var TimeSliderZeroTimestamp = function TimeSliderZeroTimestamp(_ref) {
2024
- var _ref$timeZone = _ref.timeZone,
2025
- timeZone = _ref$timeZone === void 0 ? 'LT' : _ref$timeZone,
2026
- _ref$currentTime = _ref.currentTime,
2027
- currentTime = _ref$currentTime === void 0 ? Date.now() * MILLISECOND_TO_SECOND : _ref$currentTime,
2028
- timeStep = _ref.timeStep,
2029
- timestampZIndex = _ref.timestampZIndex;
2030
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
2031
- i18n = _useTimesliderLiteTra.i18n;
2032
- var language = i18n.language;
2033
- var _useTheme = useTheme(),
2034
- timeSliderLite = _useTheme.palette.geowebColors.timeSliderLite;
2035
- var observedTimeStepSeconds = timeStep[0];
2036
- var lastObservedTime = floorLocalSeconds(currentTime, observedTimeStepSeconds);
2037
- var dateString = new Date(lastObservedTime * 1000).toLocaleDateString(language, {
2038
- weekday: 'short',
2039
- month: 'numeric',
2040
- day: 'numeric',
2041
- hour: 'numeric',
2042
- minute: 'numeric',
2043
- timeZone: timeZone === 'UTC' ? 'UTC' : undefined
2044
- });
2045
- var localLabel = language === 'fi' || language === 'sv-FI' ? reformatFinnishDateString(dateString) : dateString;
2046
- var label = timeZone === 'UTC' ? shortUTCTime(localLabel) : localLabel;
2047
- return /*#__PURE__*/jsx(Box, {
2048
- className: "TimeSliderLite-zeroTimeStamp",
2049
- sx: Object.assign({}, styles$1.centeredBox, timeSliderLite.needleLabel, {
2050
- fontSize: '13px',
2051
- opacity: 0.6,
2052
- pointerEvents: null,
2053
- zIndex: timestampZIndex != null ? timestampZIndex : null
2054
- }),
2055
- children: label
2056
- });
2057
- };
2058
-
2059
- /* *
2060
- * Licensed under the Apache License, Version 2.0 (the "License");
2061
- * you may not use this file except in compliance with the License.
2062
- * You may obtain a copy of the License at
2063
- *
2064
- * http://www.apache.org/licenses/LICENSE-2.0
2065
- *
2066
- * Unless required by applicable law or agreed to in writing, software
2067
- * distributed under the License is distributed on an "AS IS" BASIS,
2068
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2069
- * See the License for the specific language governing permissions and
2070
- * limitations under the License.
2071
- *
2072
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2073
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
2074
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2075
- * */
2076
-
2077
- var TimeSliderLiteBackground = function TimeSliderLiteBackground(_ref) {
2078
- var height = _ref.height,
2079
- draggableTimeStamp = _ref.draggableTimeStamp,
2080
- _ref$timeZone = _ref.timeZone,
2081
- timeZone = _ref$timeZone === void 0 ? 'LT' : _ref$timeZone,
2082
- startTime = _ref.startTime,
2083
- endTime = _ref.endTime,
2084
- disableForecast = _ref.disableForecast,
2085
- _ref$currentTime = _ref.currentTime,
2086
- currentTime = _ref$currentTime === void 0 ? Date.now() * MILLISECOND_TO_SECOND : _ref$currentTime,
2087
- currentTimeSelected = _ref.currentTimeSelected,
2088
- mouseHoverNeedleOpacity = _ref.mouseHoverNeedleOpacity,
2089
- needleWidth = _ref.needleWidth,
2090
- needleDragAreaWidth = _ref.needleDragAreaWidth,
2091
- needleLabelZIndex = _ref.needleLabelZIndex,
2092
- needleLabelOffset = _ref.needleLabelOffset,
2093
- timeStep = _ref.timeStep,
2094
- selectedTime = _ref.selectedTime,
2095
- setSelectedTime = _ref.setSelectedTime,
2096
- resetSelectedTime = _ref.resetSelectedTime,
2097
- zerorange = _ref.zerorange;
2098
- var _useTheme = useTheme(),
2099
- timeSliderLite = _useTheme.palette.geowebColors.timeSliderLite;
2100
- var sliderAreaRef = useRef(null);
2101
- var _React$useState = React.useState(0),
2102
- areaWidth = _React$useState[0],
2103
- setAreaWidth = _React$useState[1];
2104
- var drawNeedle = selectedTime && areaWidth && startTime <= endTime;
2105
- useLayoutEffect(function () {
2106
- var sliderArea = sliderAreaRef.current;
2107
- setAreaWidth(sliderArea.clientWidth - TIME_SLIDER_LITE_PADDING_RIGHT);
2108
- var observer = new ResizeObserver(function () {
2109
- setAreaWidth(sliderArea.clientWidth - TIME_SLIDER_LITE_PADDING_RIGHT);
2110
- });
2111
- observer.observe(sliderArea);
2112
- return function () {
2113
- observer.disconnect();
2114
- };
2115
- }, [sliderAreaRef]);
2116
- return /*#__PURE__*/jsxs(Box, {
2117
- "data-testid": "TimeSliderLite-Background",
2118
- ref: sliderAreaRef,
2119
- sx: {
2120
- position: 'relative',
2121
- height: height + "px",
2122
- overflow: 'visible',
2123
- width: '100%',
2124
- backgroundColor: timeSliderLite.timelineBackgroundObserved.fill
2125
- },
2126
- children: [/*#__PURE__*/jsx(TimeSliderLiteBackgroundSvg, {
2127
- currentTime: currentTime,
2128
- disableForecast: disableForecast,
2129
- endTime: endTime,
2130
- height: height,
2131
- startTime: startTime,
2132
- style: {
2133
- position: 'absolute',
2134
- top: 0
2135
- },
2136
- timeStep: timeStep,
2137
- timeZone: timeZone,
2138
- width: areaWidth
2139
- }), /*#__PURE__*/jsx(TimeSliderClickableTimeline, {
2140
- currentTime: currentTime,
2141
- disableForecast: disableForecast,
2142
- endTime: endTime,
2143
- opacity: mouseHoverNeedleOpacity,
2144
- setSelectedTime: setSelectedTime,
2145
- startTime: startTime,
2146
- timeStep: timeStep,
2147
- timeZone: timeZone,
2148
- width: areaWidth
2149
- }), !!drawNeedle && (!zerorange ? /*#__PURE__*/jsx(TimeSliderDraggableNeedle, {
2150
- currentTime: currentTime,
2151
- currentTimeSelected: currentTimeSelected,
2152
- disableForecast: disableForecast,
2153
- draggableLabel: draggableTimeStamp,
2154
- endTime: endTime,
2155
- height: height,
2156
- needleDragAreaWidth: needleDragAreaWidth,
2157
- needleLabelOffset: needleLabelOffset,
2158
- needleLabelZIndex: needleLabelZIndex,
2159
- needleWidth: needleWidth,
2160
- onDoubleClick: resetSelectedTime,
2161
- selectedTime: selectedTime,
2162
- setSelectedTime: setSelectedTime,
2163
- startTime: startTime,
2164
- style: {
2165
- position: 'absolute',
2166
- top: 0
2167
- },
2168
- timeStep: timeStep,
2169
- timeZone: timeZone,
2170
- width: areaWidth
2171
- }) : /*#__PURE__*/jsx(TimeSliderZeroTimestamp, {
2172
- currentTime: currentTime,
2173
- timeStep: timeStep,
2174
- timeZone: timeZone,
2175
- timestampZIndex: needleLabelZIndex
2176
- }))]
2177
- });
2178
- };
2179
-
2180
- var _excluded$1 = ["children", "right", "left"];
2181
- var ControlButtonGroup = function ControlButtonGroup(_ref) {
2182
- var children = _ref.children,
2183
- right = _ref.right,
2184
- left = _ref.left,
2185
- props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
2186
- return /*#__PURE__*/jsx(ButtonGroup, Object.assign({
2187
- fullWidth: true,
2188
- orientation: "horizontal"
2189
- }, props, {
2190
- sx: Object.assign({}, right && {
2191
- borderTopLeftRadius: 0,
2192
- borderBottomLeftRadius: 0
2193
- }, left && {
2194
- borderTopRightRadius: 0,
2195
- borderBottomRightRadius: 0
2196
- }, {
2197
- backgroundColor: 'geowebColors.background.surface',
2198
- height: '100%',
2199
- alignItems: 'center',
2200
- justifyContent: 'center',
2201
- padding: '4px',
2202
- gap: '2px'
2203
- }, Array.isArray(props.sx) ? Object.assign.apply(Object, [{}].concat(props.sx)) : props.sx),
2204
- children: children
2205
- }));
2206
- };
2207
-
2208
- /* *
2209
- * Licensed under the Apache License, Version 2.0 (the "License");
2210
- * you may not use this file except in compliance with the License.
2211
- * You may obtain a copy of the License at
2212
- *
2213
- * http://www.apache.org/licenses/LICENSE-2.0
2214
- *
2215
- * Unless required by applicable law or agreed to in writing, software
2216
- * distributed under the License is distributed on an "AS IS" BASIS,
2217
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2218
- * See the License for the specific language governing permissions and
2219
- * limitations under the License.
2220
- *
2221
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2222
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
2223
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2224
- * */
2225
-
2226
- var timeSliderLiteButtonDefaultProps = {
2227
- sx: {
2228
- width: '36px',
2229
- height: '36px'
2230
- }
2231
- };
2232
-
2233
- /* *
2234
- * Licensed under the Apache License, Version 2.0 (the "License");
2235
- * you may not use this file except in compliance with the License.
2236
- * You may obtain a copy of the License at
2237
- *
2238
- * http://www.apache.org/licenses/LICENSE-2.0
2239
- *
2240
- * Unless required by applicable law or agreed to in writing, software
2241
- * distributed under the License is distributed on an "AS IS" BASIS,
2242
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2243
- * See the License for the specific language governing permissions and
2244
- * limitations under the License.
2245
- *
2246
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2247
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
2248
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2249
- * */
2250
-
2251
- var HideButton = function HideButton(_ref) {
2252
- var _settings$icon$hide, _settings$icon, _settings$icon$show, _settings$icon2;
2253
- var isVisible = _ref.isVisible,
2254
- settings = _ref.settings,
2255
- onClick = _ref.onClick;
2256
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
2257
- t = _useTimesliderLiteTra.t;
2258
- var hideIcon = (_settings$icon$hide = settings == null || (_settings$icon = settings.icon) == null ? void 0 : _settings$icon.hide) != null ? _settings$icon$hide : /*#__PURE__*/jsx(ChevronDown, {});
2259
- var showIcon = (_settings$icon$show = settings == null || (_settings$icon2 = settings.icon) == null ? void 0 : _settings$icon2.show) != null ? _settings$icon$show : /*#__PURE__*/jsx(ChevronUp, {});
2260
- return /*#__PURE__*/jsx(Tooltip, {
2261
- placement: "top-end",
2262
- title: isVisible ? t('controlButtons.hide') : t('controlButtons.show'),
2263
- children: /*#__PURE__*/jsx(IconButton, Object.assign({}, timeSliderLiteButtonDefaultProps, {
2264
- "aria-selected": !isVisible,
2265
- "data-testid": "TimeSliderLite-HideButton",
2266
- onClick: onClick,
2267
- children: isVisible ? hideIcon : showIcon
2268
- }))
2269
- });
2270
- };
2271
-
2272
- /* *
2273
- * Licensed under the Apache License, Version 2.0 (the "License");
2274
- * you may not use this file except in compliance with the License.
2275
- * You may obtain a copy of the License at
2276
- *
2277
- * http://www.apache.org/licenses/LICENSE-2.0
2278
- *
2279
- * Unless required by applicable law or agreed to in writing, software
2280
- * distributed under the License is distributed on an "AS IS" BASIS,
2281
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2282
- * See the License for the specific language governing permissions and
2283
- * limitations under the License.
2284
- *
2285
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2286
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
2287
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2288
- * */
2289
-
2290
- var MenuButton = function MenuButton(_ref) {
2291
- var _settings$icon;
2292
- var menuOpen = _ref.menuOpen,
2293
- onClick = _ref.onClick,
2294
- settings = _ref.settings;
2295
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
2296
- t = _useTimesliderLiteTra.t;
2297
- var icon = (_settings$icon = settings == null ? void 0 : settings.icon) != null ? _settings$icon : /*#__PURE__*/jsx(Options, {});
2298
- var Button = /*#__PURE__*/jsx(IconButton, Object.assign({}, timeSliderLiteButtonDefaultProps, {
2299
- "aria-selected": menuOpen,
2300
- "data-testid": "TimeSliderLite-MenuButton",
2301
- onClick: onClick,
2302
- sx: Object.assign({}, menuOpen && {
2303
- backgroundColor: 'geowebColors.timeSliderLite.selected.backgroundColor'
2304
- }, Array.isArray(timeSliderLiteButtonDefaultProps.sx) ? Object.assign.apply(Object, [{}].concat(timeSliderLiteButtonDefaultProps.sx)) : timeSliderLiteButtonDefaultProps.sx),
2305
- children: icon
2306
- }));
2307
- if (menuOpen) {
2308
- return Button;
2309
- }
2310
- return /*#__PURE__*/jsx(Tooltip, {
2311
- placement: "top-start",
2312
- title: t('menu.title'),
2313
- children: Button
2314
- });
2315
- };
2316
-
2317
- /* *
2318
- * Licensed under the Apache License, Version 2.0 (the "License");
2319
- * you may not use this file except in compliance with the License.
2320
- * You may obtain a copy of the License at
2321
- *
2322
- * http://www.apache.org/licenses/LICENSE-2.0
2323
- *
2324
- * Unless required by applicable law or agreed to in writing, software
2325
- * distributed under the License is distributed on an "AS IS" BASIS,
2326
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2327
- * See the License for the specific language governing permissions and
2328
- * limitations under the License.
2329
- *
2330
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2331
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
2332
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2333
- * */
2334
-
2335
- var PlayButton = function PlayButton(_ref) {
2336
- var _settings$icon$pause, _settings$icon, _settings$icon$play, _settings$icon2;
2337
- var isAnimating = _ref.isAnimating,
2338
- isDisabled = _ref.isDisabled,
2339
- onTogglePlayButton = _ref.onTogglePlayButton,
2340
- settings = _ref.settings,
2341
- tooltipDelay = _ref.tooltipDelay;
2342
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
2343
- t = _useTimesliderLiteTra.t;
2344
- var pauseIcon = (_settings$icon$pause = settings == null || (_settings$icon = settings.icon) == null ? void 0 : _settings$icon.pause) != null ? _settings$icon$pause : /*#__PURE__*/jsx(Pause, {});
2345
- var playIcon = (_settings$icon$play = settings == null || (_settings$icon2 = settings.icon) == null ? void 0 : _settings$icon2.play) != null ? _settings$icon$play : /*#__PURE__*/jsx(Play, {});
2346
- return /*#__PURE__*/jsx(Tooltip, {
2347
- enterDelay: tooltipDelay,
2348
- enterNextDelay: tooltipDelay,
2349
- placement: "top",
2350
- title: isAnimating ? t('controlButtons.pause') : t('controlButtons.play'),
2351
- children: /*#__PURE__*/jsx("span", {
2352
- children: /*#__PURE__*/jsx(IconButton, Object.assign({}, timeSliderLiteButtonDefaultProps, {
2353
- "data-testid": "TimeSliderLite-PlayButton",
2354
- disabled: isDisabled,
2355
- onClick: function onClick() {
2356
- onTogglePlayButton();
2357
- },
2358
- sx: Object.assign({}, isAnimating && {
2359
- backgroundColor: 'geowebColors.timeSliderLite.selected.backgroundColor'
2360
- }, Array.isArray(timeSliderLiteButtonDefaultProps.sx) ? Object.assign.apply(Object, [{}].concat(timeSliderLiteButtonDefaultProps.sx)) : timeSliderLiteButtonDefaultProps.sx),
2361
- children: isAnimating ? pauseIcon : playIcon
2362
- }))
2363
- })
2364
- });
2365
- };
2366
-
2367
- /* *
2368
- * Licensed under the Apache License, Version 2.0 (the "License");
2369
- * you may not use this file except in compliance with the License.
2370
- * You may obtain a copy of the License at
2371
- *
2372
- * http://www.apache.org/licenses/LICENSE-2.0
2373
- *
2374
- * Unless required by applicable law or agreed to in writing, software
2375
- * distributed under the License is distributed on an "AS IS" BASIS,
2376
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2377
- * See the License for the specific language governing permissions and
2378
- * limitations under the License.
2379
- *
2380
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2381
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
2382
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2383
- * */
2384
-
2385
- var StepButton = function StepButton(_ref) {
2386
- var _settings$icon$forwar, _settings$icon, _settings$icon$backwa, _settings$icon2;
2387
- var forward = _ref.forward,
2388
- isDisabled = _ref.isDisabled,
2389
- _ref$onClick = _ref.onClick,
2390
- onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
2391
- settings = _ref.settings,
2392
- tooltipDelay = _ref.tooltipDelay;
2393
- var _useTimesliderLiteTra = useTimesliderLiteTranslation(),
2394
- t = _useTimesliderLiteTra.t;
2395
- var forwardTitle = t('controlButtons.forward');
2396
- var backwardTitle = t('controlButtons.backward');
2397
- var forwardIcon = (_settings$icon$forwar = settings == null || (_settings$icon = settings.icon) == null ? void 0 : _settings$icon.forward) != null ? _settings$icon$forwar : /*#__PURE__*/jsx(StepForward, {
2398
- "data-testid": "step-forward-svg-path"
2399
- });
2400
- var backwardIcon = (_settings$icon$backwa = settings == null || (_settings$icon2 = settings.icon) == null ? void 0 : _settings$icon2.backward) != null ? _settings$icon$backwa : /*#__PURE__*/jsx(StepBackward, {
2401
- "data-testid": "step-backward-svg-path"
2402
- });
2403
- return /*#__PURE__*/jsx(Tooltip, {
2404
- enterDelay: tooltipDelay,
2405
- enterNextDelay: tooltipDelay,
2406
- placement: "top",
2407
- title: forward ? forwardTitle : backwardTitle,
2408
- children: /*#__PURE__*/jsx("span", {
2409
- children: /*#__PURE__*/jsx(IconButton, Object.assign({}, timeSliderLiteButtonDefaultProps, {
2410
- "aria-label": forward ? forwardTitle : backwardTitle,
2411
- "data-testid": "TimeSliderLite-StepButton" + (forward ? 'Forward' : 'Backward'),
2412
- disabled: isDisabled,
2413
- onClick: onClick,
2414
- children: forward ? forwardIcon : backwardIcon
2415
- }))
2416
- })
2417
- });
2418
- };
2419
-
2420
- /* *
2421
- * Licensed under the Apache License, Version 2.0 (the "License");
2422
- * you may not use this file except in compliance with the License.
2423
- * You may obtain a copy of the License at
2424
- *
2425
- * http://www.apache.org/licenses/LICENSE-2.0
2426
- *
2427
- * Unless required by applicable law or agreed to in writing, software
2428
- * distributed under the License is distributed on an "AS IS" BASIS,
2429
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2430
- * See the License for the specific language governing permissions and
2431
- * limitations under the License.
2432
- *
2433
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2434
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
2435
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2436
- * */
2437
-
2438
- var TIME_SLIDER_LITE_DEFAULT_HEIGHT = 40;
2439
- var TIME_SLIDER_LITE_DEFAULT_TIME_STEP = 5;
2440
- var TIME_SLIDER_LITE_TOOLTIP_DELAY = 3000;
2441
- var styles = {
2442
- container: {
2443
- display: 'grid',
2444
- alignItems: 'center',
2445
- justifyContent: 'center',
2446
- borderRadius: '4px',
2447
- width: '100%'
2448
- }
2449
- };
2450
- var TimeSliderLite = function TimeSliderLite(_ref) {
2451
- var controlButtons = _ref.controlButtons,
2452
- _ref$currentTime = _ref.currentTime,
2453
- currentTime = _ref$currentTime === void 0 ? Date.now() * MILLISECOND_TO_SECOND : _ref$currentTime,
2454
- endTime = _ref.endTime,
2455
- _ref$height = _ref.height,
2456
- height = _ref$height === void 0 ? TIME_SLIDER_LITE_DEFAULT_HEIGHT : _ref$height,
2457
- hideButton = _ref.hideButton,
2458
- hideMenuButton = _ref.hideMenuButton,
2459
- hideStepButtons = _ref.hideStepButtons,
2460
- hidePlayButton = _ref.hidePlayButton,
2461
- isAnimating = _ref.isAnimating,
2462
- isVisible = _ref.isVisible,
2463
- mapId = _ref.mapId,
2464
- menuOpen = _ref.menuOpen,
2465
- mouseHoverNeedleOpacity = _ref.mouseHoverNeedleOpacity,
2466
- overrideAnimation = _ref.overrideAnimation,
2467
- onToggleAnimation = _ref.onToggleAnimation,
2468
- onToggleMenu = _ref.onToggleMenu,
2469
- onToggleTimeSlider = _ref.onToggleTimeSlider,
2470
- needleWidth = _ref.needleWidth,
2471
- needleDragAreaWidth = _ref.needleDragAreaWidth,
2472
- needleLabelZIndex = _ref.needleLabelZIndex,
2473
- needleLabelOffset = _ref.needleLabelOffset,
2474
- draggableTimeStamp = _ref.draggableTimeStamp,
2475
- selectedTime = _ref.selectedTime,
2476
- setSelectedTime = _ref.setSelectedTime,
2477
- settings = _ref.settings,
2478
- startTime = _ref.startTime,
2479
- sx = _ref.sx,
2480
- needleDisabled = _ref.needleDisabled,
2481
- _ref$timeStep = _ref.timeStep,
2482
- timeStep = _ref$timeStep === void 0 ? [TIME_SLIDER_LITE_DEFAULT_TIME_STEP, TIME_SLIDER_LITE_DEFAULT_TIME_STEP] : _ref$timeStep,
2483
- _ref$timeZone = _ref.timeZone,
2484
- timeZone = _ref$timeZone === void 0 ? 'LT' : _ref$timeZone,
2485
- _ref$animationSpeed = _ref.animationSpeed,
2486
- animationSpeed = _ref$animationSpeed === void 0 ? 1 : _ref$animationSpeed;
2487
- var observedTimeStep = timeStep[0],
2488
- forecastTimeStep = timeStep[1];
2489
- var timeZoneOffset = timeZone === 'UTC' ? 0 : undefined;
2490
- var _useState = useState(currentTime),
2491
- rawSelectedTime = _useState[0],
2492
- setRawSelectedTime = _useState[1];
2493
- var forecastTimeStepSeconds = forecastTimeStep * MINUTE_TO_SECOND;
2494
- var observedTimeStepSeconds = observedTimeStep * MINUTE_TO_SECOND;
2495
- var lastObservedTime = floorLocalSeconds(currentTime, observedTimeStepSeconds, timeZoneOffset);
2496
- var firstForecastTime = floorLocalSeconds(currentTime, forecastTimeStepSeconds, timeZoneOffset) + forecastTimeStepSeconds;
2497
- var timeStepSeconds = rawSelectedTime >= currentTime ? forecastTimeStepSeconds : observedTimeStepSeconds;
2498
- var roundedStartTime = floorLocalSeconds(startTime + Math.max(forecastTimeStepSeconds, observedTimeStepSeconds, HOUR_TO_SECOND), HOUR_TO_SECOND, timeZoneOffset);
2499
- var isObservedTimeRange = endTime - currentTime < HOUR_TO_SECOND;
2500
- var roundedEndTime = floorLocalSeconds(endTime + HOUR_TO_SECOND, HOUR_TO_SECOND, timeZoneOffset);
2501
- var autoUpdateSelectedTime = useAutoUpdateSelectedTime(lastObservedTime, selectedTime, setRawSelectedTime);
2502
- var runningExternalAnimation = overrideAnimation && isAnimating;
2503
- var runningInternalAnimation = !overrideAnimation && isAnimating;
2504
- useEffect(function () {
2505
- if (needleDisabled && selectedTime !== lastObservedTime) {
2506
- setRawSelectedTime(lastObservedTime);
2507
- setSelectedTime(lastObservedTime);
2508
- }
2509
- // eslint-disable-next-line react-hooks/exhaustive-deps
2510
- }, [selectedTime, needleDisabled, lastObservedTime]);
2511
- useEffect(function () {
2512
- if (!runningExternalAnimation) {
2513
- var roundedSelectedTime = floorLocalSeconds(rawSelectedTime, timeStepSeconds, timeZoneOffset);
2514
- setSelectedTime(roundedSelectedTime);
2515
- }
2516
- // eslint-disable-next-line react-hooks/exhaustive-deps
2517
- }, [rawSelectedTime, timeStepSeconds, runningExternalAnimation]);
2518
- useEffect(function () {
2519
- if (runningInternalAnimation) {
2520
- var interval = setInterval(function () {
2521
- handleTimeStep(timeStepSeconds, true);
2522
- }, SECOND_TO_MILLISECOND / animationSpeed);
2523
- return function () {
2524
- return clearInterval(interval);
2525
- };
2526
- }
2527
- if (runningExternalAnimation) {
2528
- setRawSelectedTime(selectedTime);
2529
- }
2530
- return function () {};
2531
- // eslint-disable-next-line react-hooks/exhaustive-deps
2532
- }, [runningInternalAnimation, runningExternalAnimation, selectedTime]);
2533
- var handleTimeStep = function handleTimeStep(stepSeconds, asAnimation) {
2534
- var newSteppedTime = stepSeconds >= 0 ? floorLocalSeconds(rawSelectedTime, timeStepSeconds, timeZoneOffset) + stepSeconds : floorLocalSeconds(rawSelectedTime - 1, timeStepSeconds, timeZoneOffset);
2535
- if (asAnimation && newSteppedTime > roundedEndTime + 1) {
2536
- setRawSelectedTime(roundedStartTime);
2537
- return;
2538
- }
2539
-
2540
- // Handle stepping over current time
2541
- if (newSteppedTime >= currentTime && currentTime > rawSelectedTime && !isObservedTimeRange) {
2542
- setRawSelectedTime(firstForecastTime);
2543
- } else if (newSteppedTime < currentTime && currentTime <= rawSelectedTime && newSteppedTime >= roundedStartTime) {
2544
- setRawSelectedTime(lastObservedTime);
2545
- } else {
2546
- // Handle normal stepping
2547
- setRawSelectedTime(boundedValue(newSteppedTime, [roundedStartTime, isObservedTimeRange ? lastObservedTime : roundedEndTime]));
2548
- }
2549
- if (!asAnimation && isAnimating && onToggleAnimation) {
2550
- onToggleAnimation();
2551
- }
2552
- };
2553
- var handleTimeSelect = function handleTimeSelect(value) {
2554
- setRawSelectedTime(boundedValue(value, [roundedStartTime, roundedEndTime]));
2555
- if (isAnimating && onToggleAnimation) {
2556
- onToggleAnimation();
2557
- }
2558
- };
2559
-
2560
- // Handle time range selection
2561
- useEffect(function () {
2562
- var userDraggingNeedle = rawSelectedTime !== selectedTime || rawSelectedTime === roundedEndTime;
2563
- if (!userDraggingNeedle) {
2564
- var newRawSelectedTime = isObservedTimeRange ? lastObservedTime : roundedEndTime;
2565
- var isValid = newRawSelectedTime >= roundedStartTime;
2566
- setRawSelectedTime(boundedValue(selectedTime, [roundedStartTime, isValid ? newRawSelectedTime : roundedStartTime]));
2567
- }
2568
- if (needleDisabled) {
2569
- setRawSelectedTime(selectedTime);
2570
- }
2571
- // eslint-disable-next-line react-hooks/exhaustive-deps
2572
- }, [startTime, endTime, needleDisabled, timeStep]);
2573
- var tooltipDelay = menuOpen ? TIME_SLIDER_LITE_TOOLTIP_DELAY : undefined;
2574
- return /*#__PURE__*/jsxs(Grid, {
2575
- container: true,
2576
- "data-testid": "timeSliderLite-" + mapId,
2577
- sx: Object.assign({}, styles.container, Array.isArray(sx) ? Object.assign.apply(Object, [{}].concat(sx)) : sx, {
2578
- gridTemplateColumns: isVisible ? 'auto 1fr auto' : "1fr auto",
2579
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2580
- boxShadow: isVisible ? sx == null ? void 0 : sx.boxShadow : undefined
2581
- }),
2582
- children: [isVisible ? /*#__PURE__*/jsxs(Fragment, {
2583
- children: [/*#__PURE__*/jsx(Grid, {
2584
- sx: {
2585
- height: height + "px"
2586
- },
2587
- children: controlButtons || /*#__PURE__*/jsxs(ControlButtonGroup, {
2588
- left: true,
2589
- children: [!hideMenuButton && /*#__PURE__*/jsxs(Fragment, {
2590
- children: [/*#__PURE__*/jsx(MenuButton, {
2591
- menuOpen: menuOpen,
2592
- onClick: onToggleMenu,
2593
- settings: settings == null ? void 0 : settings.menuButton
2594
- }), /*#__PURE__*/jsx(Divider, {
2595
- orientation: "vertical",
2596
- sx: {
2597
- height: height + "px",
2598
- margin: '2px'
2599
- }
2600
- })]
2601
- }), !hidePlayButton && /*#__PURE__*/jsx(PlayButton, {
2602
- isAnimating: isAnimating,
2603
- isDisabled: needleDisabled,
2604
- onTogglePlayButton: onToggleAnimation,
2605
- settings: settings == null ? void 0 : settings.playButton,
2606
- tooltipDelay: tooltipDelay
2607
- }), !hideStepButtons && /*#__PURE__*/jsxs(Fragment, {
2608
- children: [/*#__PURE__*/jsx(StepButton, {
2609
- isDisabled: needleDisabled,
2610
- onClick: function onClick() {
2611
- return handleTimeStep(-timeStepSeconds);
2612
- },
2613
- settings: settings == null ? void 0 : settings.stepButton,
2614
- tooltipDelay: tooltipDelay
2615
- }), /*#__PURE__*/jsx(StepButton, {
2616
- forward: true,
2617
- isDisabled: needleDisabled,
2618
- onClick: function onClick() {
2619
- return handleTimeStep(timeStepSeconds);
2620
- },
2621
- settings: settings == null ? void 0 : settings.stepButton,
2622
- tooltipDelay: tooltipDelay
2623
- })]
2624
- })]
2625
- })
2626
- }), /*#__PURE__*/jsx(Grid, {
2627
- children: /*#__PURE__*/jsx(TimeSliderLiteBackground, {
2628
- currentTime: currentTime,
2629
- currentTimeSelected: !!autoUpdateSelectedTime && !isAnimating,
2630
- disableForecast: isObservedTimeRange,
2631
- draggableTimeStamp: draggableTimeStamp,
2632
- endTime: roundedEndTime,
2633
- height: height,
2634
- mouseHoverNeedleOpacity: mouseHoverNeedleOpacity,
2635
- needleDragAreaWidth: needleDragAreaWidth,
2636
- needleLabelOffset: needleLabelOffset,
2637
- needleLabelZIndex: needleLabelZIndex,
2638
- needleWidth: needleWidth,
2639
- resetSelectedTime: function resetSelectedTime() {
2640
- return setRawSelectedTime(lastObservedTime);
2641
- },
2642
- selectedTime: runningExternalAnimation ? selectedTime : rawSelectedTime,
2643
- setSelectedTime: handleTimeSelect,
2644
- startTime: roundedStartTime,
2645
- timeStep: [observedTimeStepSeconds, forecastTimeStepSeconds],
2646
- timeZone: timeZone,
2647
- zerorange: needleDisabled
2648
- })
2649
- })]
2650
- }) : /*#__PURE__*/jsx(Grid, {}), /*#__PURE__*/jsx(Grid, {
2651
- sx: {
2652
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2653
- boxShadow: isVisible ? 'none' : sx == null ? void 0 : sx.boxShadow,
2654
- borderRadius: isVisible ? 'none' : '4px',
2655
- height: height + "px"
2656
- },
2657
- children: hideButton || /*#__PURE__*/jsx(ControlButtonGroup, {
2658
- className: "timeSliderLite-hideButtonGroup-" + (isVisible ? 'hide' : 'show'),
2659
- right: isVisible,
2660
- children: /*#__PURE__*/jsx(HideButton, {
2661
- isVisible: isVisible,
2662
- onClick: onToggleTimeSlider,
2663
- settings: settings == null ? void 0 : settings.hideButton
2664
- })
2665
- })
2666
- })]
2667
- });
2668
- };
2669
-
2670
- /* *
2671
- * Licensed under the Apache License, Version 2.0 (the "License");
2672
- * you may not use this file except in compliance with the License.
2673
- * You may obtain a copy of the License at
2674
- *
2675
- * http://www.apache.org/licenses/LICENSE-2.0
2676
- *
2677
- * Unless required by applicable law or agreed to in writing, software
2678
- * distributed under the License is distributed on an "AS IS" BASIS,
2679
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2680
- * See the License for the specific language governing permissions and
2681
- * limitations under the License.
2682
- *
2683
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2684
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
2685
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2686
- * */
2687
-
2688
- var useOnToggleAnimation = function useOnToggleAnimation(dispatch, mapId, selectedTime, timeStep, defaultTimeStep, startTime, endTime, isAnimating, timeSliderProps) {
2689
- var startMapAnimation = function startMapAnimation() {
2690
- var _timeStep$, _timeStep$2, _timeSliderProps$curr, _timeSliderProps$curr2;
2691
- var observedTimeStep = (_timeStep$ = timeStep == null ? void 0 : timeStep[0]) != null ? _timeStep$ : defaultTimeStep[0];
2692
- var forecastTimeStep = (_timeStep$2 = timeStep == null ? void 0 : timeStep[1]) != null ? _timeStep$2 : defaultTimeStep[1];
2693
- var floorCorrectedTimeStart = floorLocalSeconds(startTime + HOUR_TO_SECOND, HOUR_TO_SECOND);
2694
- var floorCorrectedEndTime = floorLocalSeconds(endTime + HOUR_TO_SECOND, HOUR_TO_SECOND);
2695
- var currentTime = (_timeSliderProps$curr = timeSliderProps.currentTime) != null ? _timeSliderProps$curr : Date.now() * MILLISECOND_TO_SECOND;
2696
- var observedOnly = floorCorrectedEndTime - currentTime < HOUR_TO_SECOND;
2697
- var timeList = generateCustomTimeList((_timeSliderProps$curr2 = timeSliderProps.currentTime) != null ? _timeSliderProps$curr2 : Date.now() * MILLISECOND_TO_SECOND, floorCorrectedTimeStart, observedOnly ? currentTime : floorCorrectedEndTime, [observedTimeStep, forecastTimeStep], timeSliderProps.timeZone === 'UTC' ? 0 : undefined);
2698
- dispatch(mapActions.mapStartAnimation({
2699
- mapId: mapId,
2700
- initialTime: new Date(selectedTime * SECOND_TO_MILLISECOND).toISOString(),
2701
- timeList: timeList,
2702
- origin: mapEnums.MapActionOrigin.map
2703
- }));
2704
- };
2705
- var onToggleAnimation = function onToggleAnimation(forceStart) {
2706
- if (isAnimating && !forceStart) {
2707
- dispatch(mapActions.mapStopAnimation({
2708
- mapId: mapId,
2709
- origin: mapEnums.MapActionOrigin.map
2710
- }));
2711
- } else {
2712
- startMapAnimation();
2713
- }
2714
- };
2715
- React.useEffect(function () {
2716
- var hasTimeRange = startTime && endTime && selectedTime;
2717
- var isInvalidAnimation = selectedTime < startTime || selectedTime > endTime;
2718
- if (hasTimeRange && isInvalidAnimation && isAnimating) {
2719
- startMapAnimation();
2720
- }
2721
- // eslint-disable-next-line react-hooks/exhaustive-deps
2722
- }, [selectedTime, startTime, endTime]);
2723
- return onToggleAnimation;
2724
- };
2725
-
2726
- var _excluded = ["overrideUseTimeRange", "overrideUseTimeStep", "overrideUseTimeZone", "overrideUseUpdateInterval", "overrideHandleAutoUpdate", "preTimeDimensionSelect", "sourceId", "mapId", "isAlwaysVisible", "TimeSliderLiteOptionsMenuProps"];
2727
- var TimeSliderLiteConnect = function TimeSliderLiteConnect(_ref) {
2728
- var _TimeSliderLiteOption, _timeSliderProps$sett, _timeSliderProps$sett2, _timeSliderProps$sett3;
2729
- var overrideUseTimeRange = _ref.overrideUseTimeRange,
2730
- overrideUseTimeStep = _ref.overrideUseTimeStep,
2731
- overrideUseTimeZone = _ref.overrideUseTimeZone,
2732
- overrideUseUpdateInterval = _ref.overrideUseUpdateInterval,
2733
- overrideHandleAutoUpdate = _ref.overrideHandleAutoUpdate,
2734
- _ref$preTimeDimension = _ref.preTimeDimensionSelect,
2735
- preTimeDimensionSelect = _ref$preTimeDimension === void 0 ? function (_, selectedTime) {
2736
- return new Date(selectedTime * SECOND_TO_MILLISECOND).toISOString();
2737
- } : _ref$preTimeDimension,
2738
- sourceId = _ref.sourceId,
2739
- mapId = _ref.mapId,
2740
- _ref$isAlwaysVisible = _ref.isAlwaysVisible,
2741
- isAlwaysVisible = _ref$isAlwaysVisible === void 0 ? false : _ref$isAlwaysVisible,
2742
- TimeSliderLiteOptionsMenuProps = _ref.TimeSliderLiteOptionsMenuProps,
2743
- timeSliderProps = _objectWithoutPropertiesLoose(_ref, _excluded);
2744
- var _React$useState = React.useState(false),
2745
- menuOpen = _React$useState[0],
2746
- setMenuOpen = _React$useState[1];
2747
- // eslint-disable-next-line react/hook-use-state
2748
- var useTimeRange = React.useState(null);
2749
- var _ref2 = overrideUseTimeRange || useTimeRange,
2750
- timeRange = _ref2[0],
2751
- setTimeRange = _ref2[1];
2752
- // eslint-disable-next-line react/hook-use-state
2753
- var useTimeStep = React.useState(null);
2754
- var _ref3 = overrideUseTimeStep || useTimeStep,
2755
- timeStep = _ref3[0],
2756
- setTimeStep = _ref3[1];
2757
- // eslint-disable-next-line react/hook-use-state
2758
- var useTimeZone = React.useState('LT');
2759
- var _ref4 = overrideUseTimeZone || useTimeZone,
2760
- timeZone = _ref4[0],
2761
- setTimeZone = _ref4[1];
2762
-
2763
- // eslint-disable-next-line react/hook-use-state
2764
- var useUpdateInterval = React.useState(null);
2765
- var _ref5 = overrideUseUpdateInterval || useUpdateInterval,
2766
- updateInterval = _ref5[0],
2767
- setUpdateInterval = _ref5[1];
2768
- var dispatch = useDispatch();
2769
- var _useAutoUpdate = useAutoUpdate(timeRange, setTimeRange, Object.assign({}, TimeSliderLiteOptionsMenuProps, {
2770
- handleUpdate: overrideHandleAutoUpdate
2771
- })),
2772
- currentTime = _useAutoUpdate.currentTime;
2773
- var isTimeSliderVisible = useSelector(function (store) {
2774
- return mapSelectors.isTimeSliderVisible(store, mapId);
2775
- });
2776
- var isVisible = isAlwaysVisible || isTimeSliderVisible;
2777
- var onToggleTimeSliderVisibility = function onToggleTimeSliderVisibility() {
2778
- dispatch(mapActions.toggleTimeSliderIsVisible({
2779
- mapId: mapId,
2780
- isTimeSliderVisible: !isVisible,
2781
- origin: mapEnums.MapActionOrigin.map
2782
- }));
2783
- };
2784
- var animationDelay = useSelector(function (store) {
2785
- return mapSelectors.getMapAnimationDelay(store, mapId);
2786
- });
2787
- var animationSpeed = animationDelay ? SECOND_TO_MILLISECOND / animationDelay : defaultAnimationDelayAtStart;
2788
- var handleAnimationSpeedChange = function handleAnimationSpeedChange(animationSpeed) {
2789
- var animationDelay = SECOND_TO_MILLISECOND / animationSpeed;
2790
- dispatch(mapActions.setAnimationDelay({
2791
- mapId: mapId,
2792
- animationDelay: animationDelay,
2793
- origin: mapEnums.MapActionOrigin.map
2794
- }));
2795
- };
2796
- var defaultTimeStep = (_TimeSliderLiteOption = TimeSliderLiteOptionsMenuProps == null ? void 0 : TimeSliderLiteOptionsMenuProps.defaultTimeStep) != null ? _TimeSliderLiteOption : [5, 15];
2797
- var layers = useSelector(function (store) {
2798
- return mapSelectors.getMapLayers(store, mapId);
2799
- });
2800
- var _useDefaultTimeRange = useDefaultTimeRange(layers, HOUR_TO_MINUTE, currentTime),
2801
- defaultStartTime = _useDefaultTimeRange[0],
2802
- defaultEndTime = _useDefaultTimeRange[1];
2803
- var _ref6 = timeRange || [defaultStartTime, defaultEndTime],
2804
- startTime = _ref6[0],
2805
- endTime = _ref6[1];
2806
- var zeroRange = isWithinRange(startTime, endTime, 30 * MINUTE_TO_SECOND);
2807
- var isAnimating = useSelector(function (store) {
2808
- return mapSelectors.isAnimating(store, mapId);
2809
- });
2810
- useEffect(function () {
2811
- if (zeroRange) {
2812
- dispatch(mapActions.mapStopAnimation({
2813
- mapId: mapId
2814
- }));
2815
- }
2816
- }, [dispatch, mapId, zeroRange]);
2817
- var selectedTime = useSelector(function (store) {
2818
- return mapSelectors.getSelectedTime(store, mapId);
2819
- });
2820
- var onToggleAnimation = useOnToggleAnimation(dispatch, mapId, selectedTime, timeStep, defaultTimeStep, startTime, endTime, isAnimating, Object.assign({}, timeSliderProps, {
2821
- timeZone: timeZone
2822
- }));
2823
-
2824
- // Restart animation if auto updated
2825
- useEffect(function () {
2826
- if (isAnimating) {
2827
- onToggleAnimation(true);
2828
- }
2829
- // eslint-disable-next-line react-hooks/exhaustive-deps
2830
- }, [currentTime]);
2831
- var handleTimeRangeChange = function handleTimeRangeChange(newTimeRange) {
2832
- if (isAnimating && newTimeRange) {
2833
- dispatch(mapActions.mapStopAnimation({
2834
- mapId: mapId
2835
- }));
2836
- }
2837
- setTimeRange(newTimeRange);
2838
- };
2839
- var handleTimeStepChange = function handleTimeStepChange(newTimeStep) {
2840
- if (isAnimating) {
2841
- dispatch(mapActions.mapStopAnimation({
2842
- mapId: mapId
2843
- }));
2844
- }
2845
- setTimeStep(newTimeStep);
2846
- };
2847
- return /*#__PURE__*/jsxs(Fragment, {
2848
- children: [!!isVisible && !!menuOpen && /*#__PURE__*/jsx(TimeSliderLiteOptionsMenu, Object.assign({
2849
- TimeZoneSwitch: timeSliderProps == null || (_timeSliderProps$sett = timeSliderProps.settings) == null ? void 0 : _timeSliderProps$sett.TimeZoneSwitch,
2850
- closeButtonIcon: (_timeSliderProps$sett2 = timeSliderProps.settings) == null || (_timeSliderProps$sett2 = _timeSliderProps$sett2.closeButton) == null ? void 0 : _timeSliderProps$sett2.icon,
2851
- defaultTimeRange: [defaultStartTime, defaultEndTime],
2852
- defaultTimeStep: defaultTimeStep // TODO: Calculate from layers
2853
- ,
2854
- dropdownButtonIcon: (_timeSliderProps$sett3 = timeSliderProps.settings) == null || (_timeSliderProps$sett3 = _timeSliderProps$sett3.dropdownButton) == null ? void 0 : _timeSliderProps$sett3.icon,
2855
- menuOpen: menuOpen,
2856
- setMenuOpen: setMenuOpen,
2857
- useAnimationSpeed: [animationSpeed, handleAnimationSpeedChange],
2858
- useTimeRange: [timeRange, handleTimeRangeChange],
2859
- useTimeStep: [timeStep, handleTimeStepChange],
2860
- useTimeZone: [timeZone, setTimeZone],
2861
- useUpdateInterval: [updateInterval, setUpdateInterval]
2862
- }, TimeSliderLiteOptionsMenuProps)), /*#__PURE__*/jsx(TimeSliderLite, Object.assign({
2863
- currentTime: currentTime,
2864
- endTime: endTime,
2865
- isAnimating: !!isAnimating,
2866
- isVisible: isVisible,
2867
- mapId: mapId,
2868
- menuOpen: menuOpen,
2869
- needleDisabled: zeroRange,
2870
- onToggleAnimation: onToggleAnimation,
2871
- onToggleMenu: function onToggleMenu() {
2872
- return setMenuOpen(!menuOpen);
2873
- },
2874
- onToggleTimeSlider: onToggleTimeSliderVisibility,
2875
- overrideAnimation: true,
2876
- selectedTime: selectedTime,
2877
- setSelectedTime: function setSelectedTime(newSelectedTime) {
2878
- var newDate = preTimeDimensionSelect(mapId, newSelectedTime);
2879
- if (isAnimating) {
2880
- dispatch(mapActions.mapStopAnimation({
2881
- mapId: mapId
2882
- }));
2883
- }
2884
- dispatch(genericActions.setTime({
2885
- sourceId: sourceId,
2886
- value: {
2887
- currentTime: handleDateUtilsISOString(newDate)
2888
- },
2889
- origin: mapEnums.MapActionOrigin.map
2890
- }));
2891
- },
2892
- startTime: startTime,
2893
- timeStep: timeStep != null ? timeStep : defaultTimeStep,
2894
- timeZone: timeZone
2895
- }, timeSliderProps))]
2896
- });
2897
- };
2898
-
2899
- export { TIME_SLIDER_LITE_NAMESPACE, TimeSliderLite, TimeSliderLiteConnect, TimeSliderLiteI18nProvider, TimeSliderLiteOptionsMenu, timeSliderLiteUtils as TimeSliderLiteUtils, initTimeSliderLiteI18n, translations as timeSliderLiteTranslations, translations as timesliderliteTranslations, useTimesliderLiteTranslation };