@opengeoweb/time-slider 17.0.0 → 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,3963 +0,0 @@
1
- import { Grid, useTheme, Box, Typography, Menu, MenuItem, CardHeader, FormControl, TextField, Select, Popper, Paper, Stack, InputAdornment, ClickAwayListener } from '@mui/material';
2
- import React, { useState, useRef, useEffect, createElement } from 'react';
3
- import { dateUtils, safelyInitI18nForTestsAndStories, CustomIconButton, CustomTooltip, CanvasComponent, renderCounter, CustomToggleButton } from '@opengeoweb/shared';
4
- import { debounce, throttle } from 'lodash';
5
- import { ChevronDown, ChevronUp, dragHandlePath, Edit, Animation, AutoUpdateActive, AutoUpdateInActive, StepForward, StepBackward, Now, Pause, Play, Speed, Clock, FastForward, Options, CalendarToday, ThemeWrapper, lightTheme, darkTheme } from '@opengeoweb/theme';
6
- import i18n from 'i18next';
7
- import { useTranslation, I18nextProvider } from 'react-i18next';
8
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
9
- import { Box as Box$1 } from '@mui/system';
10
- import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
11
- import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker';
12
- import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
13
- import { PickersDay } from '@mui/x-date-pickers/PickersDay';
14
-
15
- var en = {
16
- "timeslider-auto": "Auto",
17
- "timeslider-length": "length",
18
- "timeslider-animation": "Animation",
19
- "timeslider-auto-update-on": "Auto update on",
20
- "timeslider-auto-update-off": "Auto update off",
21
- "timeslider-backward": "Backward",
22
- "timeslider-forward": "Forward",
23
- "timeslider-hide": "Hide timeslider",
24
- "timeslider-show": "Show timeslider",
25
- "timeslider-now": "Now",
26
- "timeslider-animation-options": "Animation options",
27
- "timeslider-play": "Play",
28
- "timeslider-pause": "Pause",
29
- "timeslider-speed": "Speed",
30
- "timeslider-min": "min",
31
- "timeslider-hour": "h",
32
- "timeslider-day": "d",
33
- "timeslider-week": "week",
34
- "timeslider-weeks": "weeks",
35
- "timeslider-month": "month",
36
- "timeslider-months": "months",
37
- "timeslider-year": "year",
38
- "timeslider-years": "years",
39
- "timeslider-time-step": "Time step",
40
- "timeslider-time-span": "Time span",
41
- "timeslider-january": "Jan",
42
- "timeslider-february": "Feb",
43
- "timeslider-march": "Mar",
44
- "timeslider-april": "Apr",
45
- "timeslider-may": "May",
46
- "timeslider-june": "Jun",
47
- "timeslider-july": "Jul",
48
- "timeslider-august": "Aug",
49
- "timeslider-september": "Sep",
50
- "timeslider-october": "Oct",
51
- "timeslider-november": "Nov",
52
- "timeslider-december": "Dec",
53
- "timeslider-sunday": "Sun",
54
- "timeslider-monday": "Mon",
55
- "timeslider-tuesday": "Tue",
56
- "timeslider-wednesday": "Wed",
57
- "timeslider-thursday": "Thu",
58
- "timeslider-friday": "Fri",
59
- "timeslider-saturday": "Sat",
60
- "timeslider-edit": "Edit",
61
- "timeslider-span": "Span",
62
- "timeslider-marker": "Marker",
63
- "timeslider-marker-placement": "Marker placement",
64
- "timeslider-marker-label": "Select date and time"
65
- };
66
- var fi = {
67
- "timeslider-auto": "Auto",
68
- "timeslider-length": "pituus",
69
- "timeslider-animation": "Animaatio",
70
- "timeslider-auto-update-on": "Auto update päällä",
71
- "timeslider-auto-update-off": "Auto update pois päältä",
72
- "timeslider-backward": "Taaksepäin",
73
- "timeslider-forward": "Eteenpäin",
74
- "timeslider-hide": "Piilota Timeslider",
75
- "timeslider-show": "Näytä Timeslider",
76
- "timeslider-now": "Nyt",
77
- "timeslider-animation-options": "Animoinnin asetukset",
78
- "timeslider-play": "Toista",
79
- "timeslider-pause": "Tauko",
80
- "timeslider-speed": "Nopeus",
81
- "timeslider-min": "min",
82
- "timeslider-hour": "t",
83
- "timeslider-week": "viikko",
84
- "timeslider-weeks": "viikkoa",
85
- "timeslider-month": "kuukausi",
86
- "timeslider-months": "kuukautta",
87
- "timeslider-year": "vuosi",
88
- "timeslider-years": "vuotta",
89
- "timeslider-time-step": "Aika-askel",
90
- "timeslider-time-span": "Aikaväli",
91
- "timeslider-january": "Tammmi",
92
- "timeslider-february": "Helmi",
93
- "timeslider-march": "Maalis",
94
- "timeslider-april": "Huhti",
95
- "timeslider-may": "Touko",
96
- "timeslider-june": "Kesä",
97
- "timeslider-july": "Heinä",
98
- "timeslider-august": "Elo",
99
- "timeslider-september": "Syys",
100
- "timeslider-october": "Loka",
101
- "timeslider-november": "Marras",
102
- "timeslider-december": "Joulu",
103
- "timeslider-sunday": "Su",
104
- "timeslider-monday": "Ma",
105
- "timeslider-tuesday": "Ti",
106
- "timeslider-wednesday": "Ke",
107
- "timeslider-thursday": "To",
108
- "timeslider-friday": "Pe",
109
- "timeslider-saturday": "La",
110
- "timeslider-edit": "missing-translation",
111
- "timeslider-span": "missing-translation",
112
- "timeslider-marker": "Aikamerkki",
113
- "timeslider-marker-placement": "Aikamerkin siirto",
114
- "timeslider-marker-label": "Valitse päivämäärä ja kellonaika"
115
- };
116
- var no = {
117
- "timeslider-auto": "Auto",
118
- "timeslider-length": "lengde",
119
- "timeslider-animation": "Animasjon",
120
- "timeslider-auto-update-on": "Autooppdatering på",
121
- "timeslider-auto-update-off": "Autooppdatering av",
122
- "timeslider-backward": "Bakover",
123
- "timeslider-forward": "Forover",
124
- "timeslider-hide": "Skjul",
125
- "timeslider-show": "Vis",
126
- "timeslider-now": "Nå",
127
- "timeslider-animation-options": "Animasjonsinnstillinger",
128
- "timeslider-play": "Spill",
129
- "timeslider-pause": "Pause",
130
- "timeslider-speed": "Hurtighet",
131
- "timeslider-min": "min",
132
- "timeslider-hour": "t",
133
- "timeslider-week": "uke",
134
- "timeslider-weeks": "uker",
135
- "timeslider-month": "måned",
136
- "timeslider-months": "måneder",
137
- "timeslider-year": "år",
138
- "timeslider-years": "år",
139
- "timeslider-time-step": "Tidsintervall",
140
- "timeslider-time-span": "Tidsperiode",
141
- "timeslider-january": "Jan",
142
- "timeslider-february": "Feb",
143
- "timeslider-march": "Mar",
144
- "timeslider-april": "Apr",
145
- "timeslider-may": "Mai",
146
- "timeslider-june": "Jun",
147
- "timeslider-july": "Jul",
148
- "timeslider-august": "Aug",
149
- "timeslider-september": "Sep",
150
- "timeslider-october": "Okt",
151
- "timeslider-november": "Nov",
152
- "timeslider-december": "Des",
153
- "timeslider-sunday": "Søn",
154
- "timeslider-monday": "Man",
155
- "timeslider-tuesday": "Tir",
156
- "timeslider-wednesday": "Ons",
157
- "timeslider-thursday": "Tor",
158
- "timeslider-friday": "Fre",
159
- "timeslider-saturday": "Lør",
160
- "timeslider-edit": "Editer",
161
- "timeslider-span": "Periode",
162
- "timeslider-marker": "missing translation",
163
- "timeslider-marker-placement": "missing translation",
164
- "timeslider-marker-label": "missing translation"
165
- };
166
- var nl = {
167
- "timeslider-auto": "Auto",
168
- "timeslider-length": "lengte",
169
- "timeslider-animation": "Animatie",
170
- "timeslider-auto-update-on": "Auto update aan",
171
- "timeslider-auto-update-off": "Auto update uit",
172
- "timeslider-backward": "Achteruit",
173
- "timeslider-forward": "Vooruit",
174
- "timeslider-hide": "Timeslider verbergen",
175
- "timeslider-show": "Timeslider tonen",
176
- "timeslider-now": "Nu",
177
- "timeslider-animation-options": "Animatie opties",
178
- "timeslider-play": "Afspelen",
179
- "timeslider-pause": "Pauze",
180
- "timeslider-speed": "Snelheid",
181
- "timeslider-min": "min",
182
- "timeslider-hour": "u",
183
- "timeslider-week": "week",
184
- "timeslider-weeks": "weken",
185
- "timeslider-month": "maand",
186
- "timeslider-months": "maanden",
187
- "timeslider-year": "jaar",
188
- "timeslider-years": "jaren",
189
- "timeslider-time-step": "Tijdsinterval",
190
- "timeslider-time-span": "Tijdsperiode",
191
- "timeslider-january": "Jan",
192
- "timeslider-february": "Feb",
193
- "timeslider-march": "Maa",
194
- "timeslider-april": "Apr",
195
- "timeslider-may": "Mei",
196
- "timeslider-june": "Jun",
197
- "timeslider-july": "Jul",
198
- "timeslider-august": "Aug",
199
- "timeslider-september": "Sep",
200
- "timeslider-october": "Okt",
201
- "timeslider-november": "Nov",
202
- "timeslider-december": "Dec",
203
- "timeslider-sunday": "Zon",
204
- "timeslider-monday": "Maa",
205
- "timeslider-tuesday": "Din",
206
- "timeslider-wednesday": "Woe",
207
- "timeslider-thursday": "Don",
208
- "timeslider-friday": "Vri",
209
- "timeslider-saturday": "Zat",
210
- "timeslider-edit": "Bewerken",
211
- "timeslider-span": "Tijdsperiode",
212
- "timeslider-marker": "Kies tijdstip",
213
- "timeslider-marker-placement": "Tijd kiezen",
214
- "timeslider-marker-label": "Selecteer datum en tijd"
215
- };
216
- var timesliderTranslations = {
217
- en: en,
218
- fi: fi,
219
- no: no,
220
- nl: nl
221
- };
222
-
223
- function _arrayLikeToArray(r, a) {
224
- (null == a || a > r.length) && (a = r.length);
225
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
226
- return n;
227
- }
228
- function _createForOfIteratorHelperLoose(r, e) {
229
- var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
230
- if (t) return (t = t.call(r)).next.bind(t);
231
- if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
232
- t && (r = t);
233
- var o = 0;
234
- return function () {
235
- return o >= r.length ? {
236
- done: true
237
- } : {
238
- done: false,
239
- value: r[o++]
240
- };
241
- };
242
- }
243
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
244
- }
245
- function _objectWithoutPropertiesLoose(r, e) {
246
- if (null == r) return {};
247
- var t = {};
248
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
249
- if (-1 !== e.indexOf(n)) continue;
250
- t[n] = r[n];
251
- }
252
- return t;
253
- }
254
- function _unsupportedIterableToArray(r, a) {
255
- if (r) {
256
- if ("string" == typeof r) return _arrayLikeToArray(r, a);
257
- var t = {}.toString.call(r).slice(8, -1);
258
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
259
- }
260
- }
261
-
262
- var Scale = /*#__PURE__*/function (Scale) {
263
- Scale[Scale["Minutes5"] = 0] = "Minutes5";
264
- Scale[Scale["Hour"] = 1] = "Hour";
265
- Scale[Scale["Hours3"] = 2] = "Hours3";
266
- Scale[Scale["Hours6"] = 3] = "Hours6";
267
- Scale[Scale["Day"] = 4] = "Day";
268
- Scale[Scale["Week"] = 5] = "Week";
269
- Scale[Scale["Weeks2"] = 6] = "Weeks2";
270
- Scale[Scale["Month"] = 7] = "Month";
271
- Scale[Scale["Months3"] = 8] = "Months3";
272
- Scale[Scale["Year"] = 9] = "Year";
273
- return Scale;
274
- }({});
275
- var AnimationLength = /*#__PURE__*/function (AnimationLength) {
276
- AnimationLength[AnimationLength["Minutes15"] = 15] = "Minutes15";
277
- AnimationLength[AnimationLength["Minutes30"] = 30] = "Minutes30";
278
- AnimationLength[AnimationLength["Hours1"] = 60] = "Hours1";
279
- AnimationLength[AnimationLength["Hours2"] = 120] = "Hours2";
280
- AnimationLength[AnimationLength["Hours3"] = 180] = "Hours3";
281
- AnimationLength[AnimationLength["Hours6"] = 360] = "Hours6";
282
- AnimationLength[AnimationLength["Hours12"] = 720] = "Hours12";
283
- AnimationLength[AnimationLength["Hours24"] = 1440] = "Hours24";
284
- return AnimationLength;
285
- }({});
286
- /**
287
- * In this Map collection all fundamental scales
288
- * (Scale.Minutes5 ... Scale.Year) are mapped with their corresponding
289
- * secondsPerPx numbers.
290
- * @returns a Map including information explained above
291
- */
292
-
293
- var secondsPerPxToScale = new Map([[2.5, Scale.Minutes5], [30, Scale.Hour], [3 * 30, Scale.Hours3], [6 * 30, Scale.Hours6], [24 * 30, Scale.Day], [7 * 24 * 30, Scale.Week], [14 * 24 * 30, Scale.Weeks2], [30 * 24 * 30, Scale.Month], [90 * 24 * 30, Scale.Months3], [365 * 24 * 30, Scale.Year]]);
294
- var spanToScale = new Map([[5 * 60, Scale.Minutes5], [60 * 60, Scale.Hour], [3 * 60 * 60, Scale.Hours3], [6 * 60 * 60, Scale.Hours6], [24 * 60 * 60, Scale.Day], [7 * 24 * 60 * 60, Scale.Week], [14 * 24 * 60 * 60, Scale.Weeks2], [30 * 24 * 60 * 60, Scale.Month], [90 * 24 * 60 * 60, Scale.Months3], [365 * 24 * 60 * 60, Scale.Year]]);
295
-
296
- /**
297
- * Creates a reverse mapping of scales to their corresponding secondsPerPx
298
- * values to make it easier in some parts GeoWeb to fetch a secondsPerpx for
299
- * a certain fundamental scale (Scale.Minutes5 ... Scale.year)
300
- * @returns an Object, where names are fundamental scale values (0 - 7) and
301
- * values are their corresponding secondsPerPx numbers.
302
- */
303
-
304
- var scaleToSecondsPerPx = Object.fromEntries(Array.from(secondsPerPxToScale.entries()).map(function (_ref) {
305
- var key = _ref[0],
306
- value = _ref[1];
307
- return [value, key];
308
- }));
309
- var scalingCoefficient = function scalingCoefficient(end, start, width) {
310
- return width / (end - start);
311
- };
312
- var timestampToPixelEdges = function timestampToPixelEdges(timestamp, start, end, width) {
313
- return (timestamp - start) * scalingCoefficient(end, start, width);
314
- };
315
- var timestampToPixel = function timestampToPixel(timestamp, centerTime, widthPx, secondsPerPx) {
316
- return widthPx / 2 - (centerTime - timestamp) / secondsPerPx;
317
- };
318
- var pixelToTimestamp = function pixelToTimestamp(timePx, centerTime, widthPx, secondsPerPx) {
319
- return centerTime - (widthPx / 2 - timePx) * secondsPerPx;
320
- };
321
-
322
- /**
323
- * This function creates and returns an array where there is secondsPerPx
324
- * number of the data set added for a data scale (secondsPerPx)
325
- * to secondsPerPxToScale.
326
- * @param secondsPerPx
327
- * @returns an array containing secondsPerPx numbers.
328
- * The secondsPerPx number for a data scale is included
329
- * contrary to secondsPerPxToScale.
330
- */
331
-
332
- var secondsPerPxValues = function secondsPerPxValues(secondsPerPx) {
333
- var sortedSecondsPerPx = [].concat(secondsPerPxToScale).map(function (value) {
334
- return Number(value[0]);
335
- });
336
- var full = [].concat(sortedSecondsPerPx, [secondsPerPx]);
337
- return full;
338
- };
339
- var secondsPerPxFromCanvasWidth = function secondsPerPxFromCanvasWidth(canvasWidth, spanInSeconds) {
340
- if (canvasWidth <= 0 || spanInSeconds <= 0) {
341
- return undefined;
342
- }
343
- return spanInSeconds / canvasWidth;
344
- };
345
- var getNewCenterOfFixedPointZoom = function getNewCenterOfFixedPointZoom(fixedTimePoint, oldSecondsPerPx, newSecondsPerPx, oldCenterTime) {
346
- var centerToFixedPointPx = (fixedTimePoint - oldCenterTime) / oldSecondsPerPx;
347
- return fixedTimePoint - centerToFixedPointPx * newSecondsPerPx;
348
- };
349
-
350
- /**
351
- * Move the time slider such that a given time point (timePoint)
352
- * is at a given pixel width (timePointPx).
353
- * @returns a new center time for the resulting position
354
- */
355
- var moveRelativeToTimePoint = function moveRelativeToTimePoint(timePoint, timePointPx, secondsPerPx, canvasWidth) {
356
- return timePoint - secondsPerPx * (timePointPx - canvasWidth / 2);
357
- };
358
-
359
- /** This reusable custom hook tells whether given pointer event targets current canvas node.
360
- * Example:
361
- *
362
- * const [isAllowedCanvasNodePointed, nodeRef] = useCanvasTarget('mousedown', false);
363
- * ...
364
- * return isAllowedCanvasNodePointed ? (<CanvasComponent ref={nodeRef}>Component with ref</CanvasComponent>) : (<CanvasComponent>Component with NO ref</CanvasComponent>);
365
- * ...
366
- */
367
-
368
- var useCanvasTarget = function useCanvasTarget(eventType) {
369
- var nodeRef = React.useRef(null);
370
- var _React$useState = React.useState(false),
371
- isTargetNode = _React$useState[0],
372
- setIsTargetNode = _React$useState[1];
373
-
374
- // Check if pointer event targets current node element
375
- var pointerEventListener = React.useCallback(function (event) {
376
- setIsTargetNode(nodeRef.current.canvas ? nodeRef.current.canvas.isEqualNode(event.target) : false);
377
- }, [nodeRef]);
378
- React.useEffect(function () {
379
- document.addEventListener(eventType, pointerEventListener);
380
- return function () {
381
- return document.removeEventListener(eventType, pointerEventListener);
382
- };
383
- }, [eventType, pointerEventListener]); // Only add/remove event listener when listener really changes, that is, NOT necessarily between every re-render.
384
-
385
- return [isTargetNode, nodeRef];
386
- };
387
- var timeBoxGeom = {
388
- smallWidth: 126,
389
- largeWidth: 167,
390
- height: 24,
391
- cornerRadius: 5,
392
- lineWidth: 1,
393
- iconWidth: 25,
394
- calendarWidth: 20
395
- };
396
- var AUTO_MOVE_AREA_PADDING = 1;
397
- var getAutoMoveAreaWidth = function getAutoMoveAreaWidth(scale) {
398
- return (scale === Scale.Year ? timeBoxGeom.largeWidth + timeBoxGeom.iconWidth : timeBoxGeom.smallWidth + timeBoxGeom.iconWidth) / 2 + AUTO_MOVE_AREA_PADDING;
399
- };
400
- var TimeInMinutes = /*#__PURE__*/function (TimeInMinutes) {
401
- TimeInMinutes[TimeInMinutes["YEAR"] = 525600] = "YEAR";
402
- TimeInMinutes[TimeInMinutes["MONTH"] = 43200] = "MONTH";
403
- TimeInMinutes[TimeInMinutes["WEEK"] = 10080] = "WEEK";
404
- TimeInMinutes[TimeInMinutes["DAY"] = 1440] = "DAY";
405
- TimeInMinutes[TimeInMinutes["HOUR"] = 60] = "HOUR";
406
- TimeInMinutes[TimeInMinutes["MINUTE"] = 1] = "MINUTE";
407
- return TimeInMinutes;
408
- }({});
409
-
410
- /**
411
- *
412
- * @param minutes
413
- * @returns the two highest values in the format yr(s) mo(s) d h m
414
- */
415
- var minutesToDescribedDuration = function minutesToDescribedDuration(minutes) {
416
- var units = [{
417
- label: 'yr',
418
- value: TimeInMinutes.YEAR,
419
- plural: 's'
420
- }, {
421
- label: 'mo',
422
- value: TimeInMinutes.MONTH,
423
- plural: 's'
424
- }, {
425
- label: 'd',
426
- value: TimeInMinutes.DAY
427
- }, {
428
- label: 'h',
429
- value: TimeInMinutes.HOUR
430
- }, {
431
- label: 'm',
432
- value: TimeInMinutes.MINUTE
433
- }];
434
- var durations = units.reduce(function (units, duration) {
435
- var min = units.min,
436
- time = units.time,
437
- count = units.count;
438
- var label = duration.label,
439
- value = duration.value,
440
- _duration$plural = duration.plural,
441
- plural = _duration$plural === void 0 ? '' : _duration$plural;
442
- var unit = Math.floor(min / value);
443
- if (unit > 0 && count < 2) {
444
- return {
445
- time: "" + time + unit + label + (unit > 1 ? plural : '') + " ",
446
- min: min - unit * value,
447
- count: count + 1
448
- };
449
- }
450
- return {
451
- min: min,
452
- time: time,
453
- count: count
454
- };
455
- }, {
456
- min: minutes,
457
- time: '',
458
- count: 0
459
- });
460
- return durations.time.trim();
461
- };
462
-
463
- /**
464
- * Returns the largest timeunit value divisible by minuts
465
- * @param minutes
466
- * @returns
467
- */
468
- function getLargestTimeUnit(minutes) {
469
- var values = Object.values(TimeInMinutes).filter(function (value) {
470
- return typeof value === 'number';
471
- });
472
- for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) {
473
- var value = _step.value;
474
- if (minutes >= value) {
475
- return value;
476
- }
477
- }
478
- return TimeInMinutes.MINUTE;
479
- }
480
-
481
- // For a data scale an appropriate fundamental scale is chosen
482
- // depending on secondsPerPx of data. When a time range of
483
- // data is for example many months. the fundamental scale Scale.Year
484
- // is chosen here and the legend of the time slider is drawn in the
485
- // same as if otiginally a year scale would have been chose.
486
- //
487
- // If a time range of data is a few weeks, Scale.Month is chosen. So, all
488
- // the time range of data can be shown in the window.
489
-
490
- var getFundamentalScale = function getFundamentalScale(secondsPerPx) {
491
- if (secondsPerPx >= scaleToSecondsPerPx[Scale.Month]) {
492
- return Scale.Year;
493
- }
494
- if (secondsPerPx >= scaleToSecondsPerPx[Scale.Week]) {
495
- return Scale.Month;
496
- }
497
- if (secondsPerPx >= scaleToSecondsPerPx[Scale.Day]) {
498
- return Scale.Week;
499
- }
500
- if (secondsPerPx >= scaleToSecondsPerPx[Scale.Hours6]) {
501
- return Scale.Day;
502
- }
503
- if (secondsPerPx >= scaleToSecondsPerPx[Scale.Hours3]) {
504
- return Scale.Hours6;
505
- }
506
- if (secondsPerPx >= scaleToSecondsPerPx[Scale.Hour]) {
507
- return Scale.Hours3;
508
- }
509
- if (secondsPerPx >= scaleToSecondsPerPx[Scale.Minutes5]) {
510
- return Scale.Hour;
511
- }
512
- return Scale.Minutes5;
513
- };
514
- var getScaleFromSpan = function getScaleFromSpan(span) {
515
- var sortedScales = [].concat(spanToScale.entries()).sort(function (_ref2, _ref3) {
516
- var sa = _ref2[0];
517
- var sb = _ref3[0];
518
- return sb - sa;
519
- });
520
- for (var _iterator2 = _createForOfIteratorHelperLoose(sortedScales), _step2; !(_step2 = _iterator2()).done;) {
521
- var _step2$value = _step2.value,
522
- scaleSpan = _step2$value[0],
523
- scale = _step2$value[1];
524
- if (span >= scaleSpan) {
525
- return scale;
526
- }
527
- }
528
- return sortedScales[0][1];
529
- };
530
- var calculateMouseTimeAndCheckBounds = function calculateMouseTimeAndCheckBounds(x, startAnimationPosition, endAnimationPosition, DRAG_AREA_WIDTH, pixelsBetweenViewportAndTimesliderOnLeft, centerTime, canvasWidth, secondsPerPx, tooltipPosition) {
531
- var mousePosition = startAnimationPosition + x;
532
- var startAnimationMaxPosition = endAnimationPosition - DRAG_AREA_WIDTH * 2;
533
- var isDraggingWithinBounds = mousePosition >= startAnimationMaxPosition || mousePosition <= 0;
534
- if (isDraggingWithinBounds) {
535
- return undefined;
536
- }
537
-
538
- // eslint-disable-next-line no-param-reassign
539
- tooltipPosition.current = pixelsBetweenViewportAndTimesliderOnLeft && mousePosition + pixelsBetweenViewportAndTimesliderOnLeft;
540
- return pixelToTimestamp(mousePosition, centerTime, canvasWidth, secondsPerPx);
541
- };
542
-
543
- // default values
544
- var defaultAnimationDelayAtStart = 250;
545
- var defaultDelay = 1000; // [ms]
546
- var defaultTimeStep = 60;
547
- var defaultSecondsPerPx = 80;
548
- var defaultTimeSpan = 24 * 3600;
549
- var speedFactors = [0.1, 0.2, 0.5, 1, 2, 4, 8, 16]; // Declares available animation speed multipliers for default delay
550
-
551
- var roundWithTimeStep = function roundWithTimeStep(unixTime, timeStep, type) {
552
- var adjustedTimeStep = timeStep * 60;
553
- if (!type || type === 'round') {
554
- return Math.round(unixTime / adjustedTimeStep) * adjustedTimeStep;
555
- }
556
- if (type === 'floor') {
557
- return Math.floor(unixTime / adjustedTimeStep) * adjustedTimeStep;
558
- }
559
- if (type === 'ceil') {
560
- return Math.ceil(unixTime / adjustedTimeStep) * adjustedTimeStep;
561
- }
562
- return undefined;
563
- };
564
-
565
- /**
566
- * Returns speed delay for given speedFactor. For options, see defined above in "speedFactors"
567
- */
568
-
569
- var getSpeedDelay = function getSpeedDelay(speedFactor) {
570
- return defaultDelay / speedFactor;
571
- };
572
- var timeSliderLegendDefaultProps = {
573
- timeSliderWidth: 100,
574
- centerTime: dateUtils.unix(dateUtils.set(dateUtils.utc(), {
575
- hours: 12,
576
- minutes: 0,
577
- seconds: 0,
578
- milliseconds: 0
579
- })),
580
- secondsPerPx: defaultSecondsPerPx,
581
- selectedTime: dateUtils.unix(dateUtils.set(dateUtils.utc(), {
582
- hours: 12,
583
- minutes: 0,
584
- seconds: 0,
585
- milliseconds: 0
586
- }))
587
- };
588
-
589
- var timeSliderUtils = /*#__PURE__*/Object.freeze({
590
- __proto__: null,
591
- AUTO_MOVE_AREA_PADDING: AUTO_MOVE_AREA_PADDING,
592
- AnimationLength: AnimationLength,
593
- Scale: Scale,
594
- TimeInMinutes: TimeInMinutes,
595
- calculateMouseTimeAndCheckBounds: calculateMouseTimeAndCheckBounds,
596
- defaultAnimationDelayAtStart: defaultAnimationDelayAtStart,
597
- defaultDelay: defaultDelay,
598
- defaultSecondsPerPx: defaultSecondsPerPx,
599
- defaultTimeSpan: defaultTimeSpan,
600
- defaultTimeStep: defaultTimeStep,
601
- getAutoMoveAreaWidth: getAutoMoveAreaWidth,
602
- getFundamentalScale: getFundamentalScale,
603
- getLargestTimeUnit: getLargestTimeUnit,
604
- getNewCenterOfFixedPointZoom: getNewCenterOfFixedPointZoom,
605
- getScaleFromSpan: getScaleFromSpan,
606
- getSpeedDelay: getSpeedDelay,
607
- minutesToDescribedDuration: minutesToDescribedDuration,
608
- moveRelativeToTimePoint: moveRelativeToTimePoint,
609
- pixelToTimestamp: pixelToTimestamp,
610
- roundWithTimeStep: roundWithTimeStep,
611
- scaleToSecondsPerPx: scaleToSecondsPerPx,
612
- scalingCoefficient: scalingCoefficient,
613
- secondsPerPxFromCanvasWidth: secondsPerPxFromCanvasWidth,
614
- secondsPerPxToScale: secondsPerPxToScale,
615
- secondsPerPxValues: secondsPerPxValues,
616
- spanToScale: spanToScale,
617
- speedFactors: speedFactors,
618
- timeBoxGeom: timeBoxGeom,
619
- timeSliderLegendDefaultProps: timeSliderLegendDefaultProps,
620
- timestampToPixel: timestampToPixel,
621
- timestampToPixelEdges: timestampToPixelEdges,
622
- useCanvasTarget: useCanvasTarget
623
- });
624
-
625
- /* *
626
- * Licensed under the Apache License, Version 2.0 (the "License");
627
- * you may not use this file except in compliance with the License.
628
- * You may obtain a copy of the License at
629
- *
630
- * http://www.apache.org/licenses/LICENSE-2.0
631
- *
632
- * Unless required by applicable law or agreed to in writing, software
633
- * distributed under the License is distributed on an "AS IS" BASIS,
634
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
635
- * See the License for the specific language governing permissions and
636
- * limitations under the License.
637
- *
638
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
639
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
640
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
641
- * */
642
-
643
- var onsetNewDateDebounced = debounce(function (dateToSet, onSetNewDate) {
644
- onSetNewDate(dateToSet);
645
- }, 4, {
646
- maxWait: 40
647
- });
648
- var setPreviousTimeStep = function setPreviousTimeStep(timeStep, currentTime, dataStartTime, onSetNewDate) {
649
- // timeStep is in minutes, convert to seconds
650
- var timeStepInSeconds = timeStep * 60;
651
- var nextTime = currentTime - timeStepInSeconds;
652
- // Don't round - just step by the timestep amount from current position
653
- var newTime = Math.max(nextTime, dataStartTime || nextTime);
654
- var selectedTimeString = dateUtils.fromUnix(newTime).toISOString();
655
- onSetNewDate(selectedTimeString);
656
- };
657
- var setNextTimeStep = function setNextTimeStep(timeStep, currentTime, dataEndTime, onSetNewDate) {
658
- // timeStep is in minutes, convert to seconds
659
- var timeStepInSeconds = timeStep * 60;
660
- var nextTime = currentTime + timeStepInSeconds;
661
- // Don't round - just step by the timestep amount from current position
662
- var newTime = Math.min(nextTime, dataEndTime || nextTime);
663
- var selectedTimeString = dateUtils.fromUnix(newTime).toISOString();
664
- onSetNewDate(selectedTimeString);
665
- };
666
-
667
- /**
668
- * updates unfiltered selected time and moves selected time a given distance
669
- * in pixels. Unfiltered selected time can be outside data data limits, but
670
- * selected time cannot.
671
- */
672
- var moveSelectedTimePx = function moveSelectedTimePx(pixelsMoved, canvasWidth, centerTime, dataStartTime, dataEndTime, secondsPerPx, timeStep, unfilteredSelectedTime, setUnfilteredSelectedTime) {
673
- var unfilteredSelectedTimePx = timestampToPixel(unfilteredSelectedTime, centerTime, canvasWidth, secondsPerPx);
674
- var clickedUnfilteredSelectedTimePx = unfilteredSelectedTimePx + pixelsMoved;
675
- var newUnfilteredSelectedTime = pixelToTimestamp(clickedUnfilteredSelectedTimePx, centerTime, canvasWidth, secondsPerPx);
676
- setUnfilteredSelectedTime(newUnfilteredSelectedTime);
677
- };
678
- function getFilteredTime(unfilteredTime, timeStep, dataStartTime, dataEndTime) {
679
- if (!timeStep || !dataStartTime || !dataEndTime) {
680
- return unfilteredTime;
681
- }
682
- var roundedTime = roundWithTimeStep(unfilteredTime, timeStep);
683
- var maxTime = Math.max(roundedTime, dataStartTime);
684
- return Math.min(maxTime, dataEndTime);
685
- }
686
-
687
- /** Reusable business logic for how to handle events that set time to now (closest).
688
- * Used in NowButton and TimeSliderLegend.
689
- */
690
- var handleSetNowEvent = function handleSetNowEvent(timeStep, dataStartTime, dataEndTime, currentTime, onSetNewDate, onSetCenterTime) {
691
- if (dataStartTime < dataEndTime) {
692
- if (dataEndTime < currentTime) {
693
- onSetNewDate(dateUtils.fromUnix(dataEndTime).toISOString());
694
- onSetCenterTime(dataEndTime);
695
- } else if (dataStartTime > currentTime) {
696
- onSetNewDate(dateUtils.fromUnix(dataStartTime).toISOString());
697
- onSetCenterTime(dataStartTime);
698
- } else {
699
- var closestToCurrent = roundWithTimeStep(currentTime, timeStep);
700
- onSetNewDate(dateUtils.fromUnix(closestToCurrent).toISOString());
701
- onSetCenterTime(closestToCurrent);
702
- }
703
- }
704
- };
705
-
706
- /* *
707
- * Licensed under the Apache License, Version 2.0 (the "License");
708
- * you may not use this file except in compliance with the License.
709
- * You may obtain a copy of the License at
710
- *
711
- * http://www.apache.org/licenses/LICENSE-2.0
712
- *
713
- * Unless required by applicable law or agreed to in writing, software
714
- * distributed under the License is distributed on an "AS IS" BASIS,
715
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
716
- * See the License for the specific language governing permissions and
717
- * limitations under the License.
718
- *
719
- * Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
720
- * Copyright 2024 - Finnish Meteorological Institute (FMI)
721
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
722
- * */
723
-
724
- var useToggleTimesliderVisibility = function useToggleTimesliderVisibility(mapIsActive, isVisible, onToggleTimeSlider) {
725
- React.useEffect(function () {
726
- var handleKeyDown = function handleKeyDown(event) {
727
- var target = event.target;
728
- if (target.tagName !== 'INPUT' && target.tagName !== 'TEXTAREA' && (event.key === 't' || event.key === 'T') && mapIsActive) {
729
- onToggleTimeSlider(!isVisible);
730
- }
731
- };
732
- document.addEventListener('keydown', handleKeyDown);
733
- return function () {
734
- document.removeEventListener('keydown', handleKeyDown);
735
- };
736
- }, [mapIsActive, isVisible, onToggleTimeSlider]);
737
- };
738
- var useMoveTimeWithKeyboard = function useMoveTimeWithKeyboard(mapIsActive, timeStep, dataStartTime, dataEndTime, onSetNewDate, onSetCenterTime, selectedTime) {
739
- React.useEffect(function () {
740
- var handleKeyDown = function handleKeyDown(event) {
741
- if (event.key === 'Home' && mapIsActive) {
742
- handleSetNowEvent(timeStep, dataStartTime, dataEndTime, dateUtils.unix(dateUtils.utc()), onSetNewDate, onSetCenterTime);
743
- }
744
- var isMac = window.navigator.userAgent.includes(' Mac ');
745
- var isCorrectModifier = isMac && event.ctrlKey && event.shiftKey || !isMac && event.ctrlKey;
746
- if (isCorrectModifier && dataStartTime && dataEndTime && mapIsActive) {
747
- switch (event.code) {
748
- case 'ArrowLeft':
749
- setPreviousTimeStep(timeStep, selectedTime, dataStartTime, onSetNewDate);
750
- break;
751
- case 'ArrowRight':
752
- setNextTimeStep(timeStep, selectedTime, dataEndTime, onSetNewDate);
753
- break;
754
- }
755
- }
756
- };
757
- document.addEventListener('keydown', handleKeyDown);
758
- return function () {
759
- document.removeEventListener('keydown', handleKeyDown);
760
- };
761
- }, [dataEndTime, dataStartTime, mapIsActive, onSetCenterTime, onSetNewDate, selectedTime, timeStep]);
762
- };
763
-
764
- /* *
765
- * Licensed under the Apache License, Version 2.0 (the "License");
766
- * you may not use this file except in compliance with the License.
767
- * You may obtain a copy of the License at
768
- *
769
- * http://www.apache.org/licenses/LICENSE-2.0
770
- *
771
- * Unless required by applicable law or agreed to in writing, software
772
- * distributed under the License is distributed on an "AS IS" BASIS,
773
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
774
- * See the License for the specific language governing permissions and
775
- * limitations under the License.
776
- *
777
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
778
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
779
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
780
- * */
781
-
782
- var TIME_SLIDER_NAMESPACE = 'timeslider';
783
- var initTimesliderI18n = function initTimesliderI18n() {
784
- safelyInitI18nForTestsAndStories(i18n, TIME_SLIDER_NAMESPACE, [{
785
- ns: TIME_SLIDER_NAMESPACE,
786
- translations: timesliderTranslations
787
- }]);
788
- };
789
- var useTimesliderTranslation = function useTimesliderTranslation() {
790
- return useTranslation(TIME_SLIDER_NAMESPACE);
791
- };
792
-
793
- /* *
794
- * Licensed under the Apache License, Version 2.0 (the "License");
795
- * you may not use this file except in compliance with the License.
796
- * You may obtain a copy of the License at
797
- *
798
- * http://www.apache.org/licenses/LICENSE-2.0
799
- *
800
- * Unless required by applicable law or agreed to in writing, software
801
- * distributed under the License is distributed on an "AS IS" BASIS,
802
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
803
- * See the License for the specific language governing permissions and
804
- * limitations under the License.
805
- *
806
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
807
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
808
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
809
- * */
810
-
811
- var HideSliderButtonComponent = function HideSliderButtonComponent(_ref) {
812
- var isVisible = _ref.isVisible,
813
- toggleTimeSliderIsVisible = _ref.toggleTimeSliderIsVisible;
814
- var _useTimesliderTransla = useTimesliderTranslation(),
815
- t = _useTimesliderTransla.t;
816
- return /*#__PURE__*/jsx(CustomIconButton, {
817
- "data-testid": "hideTimeSliderButton",
818
- onClick: function onClick() {
819
- toggleTimeSliderIsVisible(!isVisible);
820
- },
821
- tooltipTitle: isVisible ? t('timeslider-hide') : t('timeslider-show'),
822
- variant: "tool",
823
- children: isVisible ? /*#__PURE__*/jsx(ChevronDown, {}) : /*#__PURE__*/jsx(ChevronUp, {})
824
- });
825
- };
826
- var HideSliderButton = /*#__PURE__*/React.memo(HideSliderButtonComponent);
827
-
828
- /* *
829
- * Licensed under the Apache License, Version 2.0 (the "License");
830
- * you may not use this file except in compliance with the License.
831
- * You may obtain a copy of the License at
832
- *
833
- * http://www.apache.org/licenses/LICENSE-2.0
834
- *
835
- * Unless required by applicable law or agreed to in writing, software
836
- * distributed under the License is distributed on an "AS IS" BASIS,
837
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
838
- * See the License for the specific language governing permissions and
839
- * limitations under the License.
840
- *
841
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
842
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
843
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
844
- * */
845
-
846
-
847
- /**
848
- * @param x The pin location
849
- * @param selectedTimePx The selected px
850
- * @param width The default width of a hoverable icon (usually 24px)
851
- * @returns
852
- */
853
- var isSelectedTimeIconArea = function isSelectedTimeIconArea(x, selectedTimePx, width) {
854
- return x >= selectedTimePx && x <= selectedTimePx + width / 2;
855
- };
856
- /**
857
- * @param x The pin location
858
- * @param selectedTimePx The selected px
859
- * @param width The default width of a hoverable icon (usually 24px)
860
- * @returns
861
- */
862
- var isRightAnimationIconArea = function isRightAnimationIconArea(x, rightMarkerPx, width) {
863
- return x >= rightMarkerPx - width && x <= rightMarkerPx;
864
- };
865
- var isInsideAnimationArea = function isInsideAnimationArea(x, leftMarkerPx, rightMarkerPx) {
866
- var isInsideOnLeftSide = x >= leftMarkerPx;
867
- var isInsideOnRightSide = x <= rightMarkerPx;
868
- return isInsideOnLeftSide && isInsideOnRightSide;
869
- };
870
- /**
871
- * @param x The pin location
872
- * @param selectedTimePx The selected px
873
- * @param width The default width of a hoverable icon (usually 24px)
874
- * @returns
875
- */
876
- var isLeftAnimationIconArea = function isLeftAnimationIconArea(x, leftMarkerPx, width) {
877
- return x >= leftMarkerPx && x <= leftMarkerPx + width;
878
- };
879
- function convertStringTimeToUnix(time) {
880
- return time ? dateUtils.unix(new Date(time)) : undefined;
881
- }
882
- var timeValues = [3600, 10800, 21600, 43200, 86400, 172800, 604800, 1209600, 2592000, 7776000, 31536000];
883
- var TIME_SLIDER_LEGEND_HEIGHT = 24;
884
- var DRAG_AREA_WIDTH = 24;
885
- var isDraggingStartWithinBounds = function isDraggingStartWithinBounds(endPos, mousePosition) {
886
- var startAnimationMaxPosition = endPos - DRAG_AREA_WIDTH * 2;
887
- return mousePosition >= startAnimationMaxPosition || mousePosition <= 0;
888
- };
889
- var isDraggingEndWithinBounds = function isDraggingEndWithinBounds(startPos, mousePosition, canvasWidth) {
890
- var endAnimationMinimumPosition = startPos + DRAG_AREA_WIDTH * 2;
891
- return endAnimationMinimumPosition >= mousePosition || mousePosition >= canvasWidth;
892
- };
893
- var getTimeSliderLegendId = function getTimeSliderLegendId(mapId) {
894
- return "timeSliderLegend_" + mapId;
895
- };
896
- var getTimeSliderLegendElement = function getTimeSliderLegendElement(mapId) {
897
- return document.querySelector(".timeSliderLegend_" + mapId);
898
- };
899
- var getPixelsBetweenViewportAndTimesliderOnLeft = function getPixelsBetweenViewportAndTimesliderOnLeft(mapId) {
900
- var timeSliderLegendElement = document.querySelector(".timeSliderLegend_" + mapId);
901
- return timeSliderLegendElement == null ? void 0 : timeSliderLegendElement.getBoundingClientRect()['left'];
902
- };
903
- function getPositions(width, unfilteredSelectedTime, centerTime, secondsPerPx, start, end) {
904
- var selectedTimePosition = timestampToPixel(unfilteredSelectedTime, centerTime, width, secondsPerPx);
905
- var endAnimationPosition = timestampToPixel(end, centerTime, width, secondsPerPx);
906
- var startAnimationPosition = timestampToPixel(start, centerTime, width, secondsPerPx);
907
- return {
908
- startAnimationPosition: startAnimationPosition,
909
- endAnimationPosition: endAnimationPosition,
910
- selectedTimePosition: selectedTimePosition
911
- };
912
- }
913
-
914
- /* *
915
- * Licensed under the Apache License, Version 2.0 (the "License");
916
- * you may not use this file except in compliance with the License.
917
- * You may obtain a copy of the License at
918
- *
919
- * http://www.apache.org/licenses/LICENSE-2.0
920
- *
921
- * Unless required by applicable law or agreed to in writing, software
922
- * distributed under the License is distributed on an "AS IS" BASIS,
923
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
924
- * See the License for the specific language governing permissions and
925
- * limitations under the License.
926
- *
927
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
928
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
929
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
930
- * */
931
-
932
- var TimeSlider = function TimeSlider(_ref) {
933
- var buttons = _ref.buttons,
934
- timeBox = _ref.timeBox,
935
- legend = _ref.legend,
936
- _ref$mapIsActive = _ref.mapIsActive,
937
- mapIsActive = _ref$mapIsActive === void 0 ? true : _ref$mapIsActive,
938
- _ref$isVisible = _ref.isVisible,
939
- isVisible = _ref$isVisible === void 0 ? true : _ref$isVisible,
940
- timeStep = _ref.timeStep,
941
- dataStartTime = _ref.dataStartTime,
942
- dataEndTime = _ref.dataEndTime,
943
- selectedTime = _ref.selectedTime,
944
- onSetNewDate = _ref.onSetNewDate,
945
- onSetCenterTime = _ref.onSetCenterTime,
946
- _ref$onToggleTimeSlid = _ref.onToggleTimeSlider,
947
- onToggleTimeSlider = _ref$onToggleTimeSlid === void 0 ? function () {} : _ref$onToggleTimeSlid;
948
- // set up visibility toggle
949
- useToggleTimesliderVisibility(mapIsActive, isVisible, onToggleTimeSlider);
950
-
951
- // set up movement with keyboard shortcuts
952
- useMoveTimeWithKeyboard(mapIsActive, timeStep, dataStartTime, dataEndTime, onSetNewDate, onSetCenterTime, selectedTime);
953
-
954
- // timeBox, buttons and legend are created in TimeSliderConnect.tsx
955
- // these components will always be created as TimeSlider never runs in isolation from the store
956
- return isVisible ? /*#__PURE__*/jsxs(Grid, {
957
- container: true,
958
- "data-testid": "timeSlider",
959
- sx: {
960
- display: 'grid',
961
- gridTemplateColumns: '175px 1fr 40px',
962
- gridTemplateRows: TIME_SLIDER_LEGEND_HEIGHT,
963
- gridTemplateAreas: "\". timebox .\"\n \"buttons timelegend toggle\"",
964
- alignItems: 'center',
965
- justifyContent: 'center',
966
- visibility: isVisible ? 'visible' : 'hidden',
967
- // Apply these styles only one mobile devices on landscape orientation
968
- '@media screen and (max-width: 1024px) and (orientation: landscape)': {
969
- paddingLeft: '5%',
970
- paddingRight: '5%'
971
- }
972
- },
973
- children: [/*#__PURE__*/jsx(Grid, {
974
- sx: {
975
- gridArea: 'timebox',
976
- zIndex: 99,
977
- position: 'relative',
978
- overflow: 'hidden'
979
- },
980
- children: timeBox
981
- }), /*#__PURE__*/jsx(Grid, {
982
- sx: {
983
- gridArea: 'buttons'
984
- },
985
- children: buttons
986
- }), /*#__PURE__*/jsx(Grid, {
987
- sx: {
988
- gridArea: 'timelegend'
989
- },
990
- children: legend
991
- }), /*#__PURE__*/jsx(Grid, {
992
- sx: {
993
- gridArea: 'toggle',
994
- paddingLeft: 1,
995
- lineHeight: 0
996
- },
997
- children: /*#__PURE__*/jsx(HideSliderButton, {
998
- isVisible: isVisible,
999
- toggleTimeSliderIsVisible: onToggleTimeSlider
1000
- })
1001
- })]
1002
- }) : /*#__PURE__*/jsx(Grid, {
1003
- container: true,
1004
- sx: {
1005
- paddingRight: 1,
1006
- alignItems: 'center',
1007
- justifyContent: 'flex-end'
1008
- },
1009
- children: /*#__PURE__*/jsx(HideSliderButton, {
1010
- isVisible: isVisible,
1011
- toggleTimeSliderIsVisible: onToggleTimeSlider
1012
- })
1013
- });
1014
- };
1015
-
1016
- var _scaleToUnitSeconds, _scaleToRoundableUnit;
1017
- var scaleToUnitSeconds = (_scaleToUnitSeconds = {}, _scaleToUnitSeconds[Scale.Minutes5] = 5 * 60, _scaleToUnitSeconds[Scale.Hour] = 60 * 60, _scaleToUnitSeconds[Scale.Hours3] = 3 * 60 * 60, _scaleToUnitSeconds[Scale.Hours6] = 6 * 60 * 60, _scaleToUnitSeconds[Scale.Day] = 24 * 60 * 60, _scaleToUnitSeconds[Scale.Week] = 7 * 24 * 60 * 60, _scaleToUnitSeconds[Scale.Weeks2] = 14 * 24 * 60 * 60, _scaleToUnitSeconds);
1018
- var TICK_MARK_HEIGHT_PRIMARY = 40;
1019
- var TICK_MARK_HEIGHT_SECONDARY = 10;
1020
- var TICK_MARK_HEIGHT_TERTIARY = 5;
1021
- var getStepPxLineHeight = function getStepPxLineHeight(scale, timestep) {
1022
- var scaleUnitSeconds = scaleToUnitSeconds[scale];
1023
- var rem = timestep % scaleUnitSeconds;
1024
- switch (scale) {
1025
- case Scale.Hour:
1026
- {
1027
- if (rem === 0) {
1028
- return TICK_MARK_HEIGHT_PRIMARY;
1029
- }
1030
- // 15 min subdivisions
1031
- if (rem % (15 * 60) === 0) {
1032
- return TICK_MARK_HEIGHT_SECONDARY;
1033
- }
1034
- return TICK_MARK_HEIGHT_TERTIARY;
1035
- }
1036
- case Scale.Hours3:
1037
- {
1038
- if (rem === 0) {
1039
- return TICK_MARK_HEIGHT_PRIMARY;
1040
- }
1041
- return TICK_MARK_HEIGHT_TERTIARY;
1042
- }
1043
- case Scale.Hours6:
1044
- {
1045
- if (rem === 0) {
1046
- return TICK_MARK_HEIGHT_PRIMARY;
1047
- }
1048
- // 3 hour subdivisions
1049
- if (rem % (3 * 60 * 60) === 0) {
1050
- return TICK_MARK_HEIGHT_SECONDARY;
1051
- }
1052
- return TICK_MARK_HEIGHT_TERTIARY;
1053
- }
1054
- case Scale.Day:
1055
- {
1056
- if (rem === 0) {
1057
- return TICK_MARK_HEIGHT_PRIMARY;
1058
- }
1059
- // 6 hour subdivisions
1060
- if (rem % (6 * 60 * 60) === 0) {
1061
- return TICK_MARK_HEIGHT_SECONDARY;
1062
- }
1063
- return TICK_MARK_HEIGHT_TERTIARY;
1064
- }
1065
- case Scale.Week:
1066
- case Scale.Weeks2:
1067
- {
1068
- var weekday = dateUtils.getDay(dateUtils.fromUnix(timestep));
1069
- // dateUtils days range from 0 (Sunday) to 6 (Saturday)
1070
- if (weekday === 1) {
1071
- return TICK_MARK_HEIGHT_PRIMARY;
1072
- }
1073
- return TICK_MARK_HEIGHT_TERTIARY;
1074
- }
1075
- case Scale.Year:
1076
- {
1077
- var month = dateUtils.getMonth(dateUtils.fromUnix(timestep));
1078
- // months are zero indexed
1079
- if (month === 0) {
1080
- return TICK_MARK_HEIGHT_PRIMARY;
1081
- }
1082
- if (month % 3 === 0) {
1083
- return TICK_MARK_HEIGHT_SECONDARY;
1084
- }
1085
- return TICK_MARK_HEIGHT_TERTIARY;
1086
- }
1087
- case Scale.Minutes5:
1088
- {
1089
- // add primary line on day change
1090
- if (timestep % (60 * 60 * 24) === 0) {
1091
- return TICK_MARK_HEIGHT_PRIMARY;
1092
- }
1093
- return TICK_MARK_HEIGHT_TERTIARY;
1094
- }
1095
- default:
1096
- // Scale.Month
1097
- return TICK_MARK_HEIGHT_TERTIARY;
1098
- }
1099
- };
1100
- var drawStepPxLine = function drawStepPxLine(ctx, theme, stepPx, height, fundamentalScale, timestep) {
1101
- var ctx2 = ctx;
1102
- ctx2.strokeStyle = theme.palette.geowebColors.timeSlider.timelineTimeScale.fill;
1103
- ctx2.lineWidth = 1;
1104
- var stepPxLineHeight = getStepPxLineHeight(fundamentalScale, timestep);
1105
- ctx2.beginPath();
1106
- ctx2.moveTo(stepPx, height - stepPxLineHeight);
1107
- ctx2.lineTo(stepPx, height);
1108
- ctx2.stroke();
1109
- };
1110
- var drawTimeText = function drawTimeText(ctx, theme, stepPx, height, timeText, scale) {
1111
- var ctx2 = ctx;
1112
- var _theme$palette$geoweb = theme.palette.geowebColors.timeSlider.timelineText,
1113
- fontSize = _theme$palette$geoweb.fontSize,
1114
- fontFamily = _theme$palette$geoweb.fontFamily,
1115
- color = _theme$palette$geoweb.color;
1116
- ctx2.fillStyle = color;
1117
- // time text has smaller font than other timeline text
1118
- ctx2.font = fontSize + "px " + fontFamily;
1119
- ctx2.textAlign = 'left';
1120
- if (scale === Scale.Year || scale === Scale.Months3 || scale === Scale.Month || scale === Scale.Weeks2 || scale === Scale.Week || scale === Scale.Day) {
1121
- ctx2.fillText(timeText, stepPx, height - 12);
1122
- } else {
1123
- ctx2.fillText(timeText, stepPx - 15, height - 12);
1124
- }
1125
- };
1126
- var drawYearScaleText = function drawYearScaleText(ctx, theme, newDate, stepPx, height) {
1127
- var ctx2 = ctx;
1128
- var _theme$palette$geoweb2 = theme.palette.geowebColors.timeSlider.timelineText,
1129
- fontSize = _theme$palette$geoweb2.fontSize,
1130
- fontFamily = _theme$palette$geoweb2.fontFamily,
1131
- color = _theme$palette$geoweb2.color;
1132
- ctx2.fillStyle = color;
1133
- ctx2.font = fontSize + "px " + fontFamily;
1134
- ctx2.textAlign = 'left';
1135
- ctx2.fillText(newDate, stepPx + 2, height - 10);
1136
- };
1137
- var drawLeftSideDateText = function drawLeftSideDateText(ctx, theme, newDate, height) {
1138
- var ctx2 = ctx;
1139
- var _theme$palette$geoweb3 = theme.palette.geowebColors.timeSlider.timelineText,
1140
- fontSize = _theme$palette$geoweb3.fontSize,
1141
- fontFamily = _theme$palette$geoweb3.fontFamily,
1142
- color = _theme$palette$geoweb3.color;
1143
- ctx2.fillStyle = color;
1144
- ctx2.font = fontSize + "px " + fontFamily;
1145
- ctx2.textAlign = 'left';
1146
- ctx2.fillText(newDate, 2, height - 30);
1147
- };
1148
- var getTimeFormat = function getTimeFormat(scale) {
1149
- switch (scale) {
1150
- case Scale.Year:
1151
- return 'y';
1152
- case Scale.Month:
1153
- case Scale.Months3:
1154
- return 'MMM';
1155
- case Scale.Week:
1156
- case Scale.Weeks2:
1157
- return 'dd MMM';
1158
- case Scale.Day:
1159
- return 'EEE dd';
1160
- default:
1161
- return dateUtils.DATE_FORMAT_HOURS;
1162
- }
1163
- };
1164
- var drawDateChangeLine = function drawDateChangeLine(ctx, theme, stepPx, height) {
1165
- var ctx2 = ctx;
1166
- ctx2.strokeStyle = theme.palette.geowebColors.timeSlider.timelineTimeScale.fill;
1167
- ctx2.lineWidth = 1;
1168
- ctx2.beginPath();
1169
- ctx2.moveTo(stepPx, height - 40);
1170
- ctx2.lineTo(stepPx, height);
1171
- ctx2.stroke();
1172
- };
1173
- var drawDashedMonthChangeLine = function drawDashedMonthChangeLine(ctx, theme, stepPx, height) {
1174
- var ctx2 = ctx;
1175
- ctx2.strokeStyle = theme.palette.geowebColors.timeSlider.timelineMonthChangeDash.rgba;
1176
- ctx2.lineWidth = 3;
1177
- ctx2.setLineDash([5, 5]);
1178
- ctx2.beginPath();
1179
- ctx2.moveTo(stepPx, 0);
1180
- ctx2.lineTo(stepPx, height);
1181
- ctx2.stroke();
1182
- ctx2.setLineDash([]);
1183
- };
1184
- var roundByUnitOfTime = function roundByUnitOfTime(timeUnix, unit, roundUp) {
1185
- if (roundUp === void 0) {
1186
- roundUp = false;
1187
- }
1188
- if (unit === 'hour') {
1189
- var _timeStartOfPassedUnit = dateUtils.startOfHourUTC(dateUtils.fromUnix(timeUnix));
1190
- if (roundUp) {
1191
- return dateUtils.unix(dateUtils.add(_timeStartOfPassedUnit, {
1192
- hours: 1
1193
- }));
1194
- }
1195
- return dateUtils.unix(_timeStartOfPassedUnit);
1196
- }
1197
- if (unit === 'day') {
1198
- var _timeStartOfPassedUnit2 = dateUtils.startOfDayUTC(dateUtils.fromUnix(timeUnix));
1199
- if (roundUp) {
1200
- return dateUtils.unix(dateUtils.add(_timeStartOfPassedUnit2, {
1201
- days: 1
1202
- }));
1203
- }
1204
- return dateUtils.unix(_timeStartOfPassedUnit2);
1205
- }
1206
- if (unit === 'week') {
1207
- var _timeStartOfPassedUnit3 = dateUtils.startOfWeekUTC(dateUtils.fromUnix(timeUnix));
1208
- if (roundUp) {
1209
- return dateUtils.unix(dateUtils.add(_timeStartOfPassedUnit3, {
1210
- weeks: 1
1211
- }));
1212
- }
1213
- return dateUtils.unix(_timeStartOfPassedUnit3);
1214
- }
1215
- if (unit === 'month') {
1216
- var _timeStartOfPassedUnit4 = dateUtils.startOfMonthUTC(dateUtils.fromUnix(timeUnix));
1217
- if (roundUp) {
1218
- return dateUtils.unix(dateUtils.add(_timeStartOfPassedUnit4, {
1219
- months: 1
1220
- }));
1221
- }
1222
- return dateUtils.unix(_timeStartOfPassedUnit4);
1223
- }
1224
-
1225
- // Default unit === 'year'
1226
- var timeStartOfPassedUnit = dateUtils.startOfYearUTC(dateUtils.fromUnix(timeUnix));
1227
- if (roundUp) {
1228
- return dateUtils.unix(dateUtils.add(timeStartOfPassedUnit, {
1229
- years: 1
1230
- }));
1231
- }
1232
- return dateUtils.unix(timeStartOfPassedUnit);
1233
- };
1234
- var roundToNearestMultiple = function roundToNearestMultiple(timeUnix, scale, roundUp) {
1235
- if (roundUp === void 0) {
1236
- roundUp = false;
1237
- }
1238
- var stepSeconds = scaleToUnitSeconds[scale];
1239
- var roundFn = roundUp ? Math.ceil : Math.floor;
1240
- return roundFn(timeUnix / stepSeconds) * stepSeconds;
1241
- };
1242
-
1243
- /**
1244
- * In this script starting and ending times of the time slider are rounded.
1245
- * Here it is defined what is a time unit to a start of which a rounding is
1246
- * done for each scale.
1247
- * @returns an object where there are rounding units of each scale
1248
- */
1249
-
1250
- var scaleToRoundableUnit = (_scaleToRoundableUnit = {}, _scaleToRoundableUnit[Scale.Hour] = 'hour', _scaleToRoundableUnit[Scale.Day] = 'day', _scaleToRoundableUnit[Scale.Week] = 'week', _scaleToRoundableUnit[Scale.Weeks2] = 'week', _scaleToRoundableUnit[Scale.Month] = 'week', _scaleToRoundableUnit[Scale.Months3] = 'week', _scaleToRoundableUnit[Scale.Year] = 'year', _scaleToRoundableUnit);
1251
- var getRoundedStartAndEnd = function getRoundedStartAndEnd(visibleTimeStart, visibleTimeEnd, scale) {
1252
- if (scale === Scale.Minutes5 || scale === Scale.Hours3 || scale === Scale.Hours6) {
1253
- return [roundToNearestMultiple(visibleTimeStart, scale, false), roundToNearestMultiple(visibleTimeEnd, scale, true)];
1254
- }
1255
- var unit = scaleToRoundableUnit[scale];
1256
- return [roundByUnitOfTime(visibleTimeStart, unit, false), roundByUnitOfTime(visibleTimeEnd, unit, true)];
1257
- };
1258
- var getCustomRoundedStartAndEndScale = function getCustomRoundedStartAndEndScale(scale) {
1259
- switch (scale) {
1260
- case Scale.Year:
1261
- return 'month';
1262
- case Scale.Month:
1263
- case Scale.Months3:
1264
- return 'week';
1265
- case Scale.Week:
1266
- case Scale.Weeks2:
1267
- return 'day';
1268
- default:
1269
- return 'day';
1270
- }
1271
- };
1272
- var getCustomRoundedStartAndEnd = function getCustomRoundedStartAndEnd(visibleTimeStart, visibleTimeEnd, unit) {
1273
- var scale = getCustomRoundedStartAndEndScale(unit);
1274
- return [roundByUnitOfTime(visibleTimeStart, scale, false), roundByUnitOfTime(visibleTimeEnd, scale, true)];
1275
- };
1276
- var incrementTimestep = function incrementTimestep(timeAtTimeStep, fundamentalScale) {
1277
- switch (fundamentalScale) {
1278
- case Scale.Minutes5:
1279
- return dateUtils.unix(dateUtils.add(dateUtils.fromUnix(timeAtTimeStep), {
1280
- minutes: 1
1281
- }));
1282
- case Scale.Hour:
1283
- return dateUtils.unix(dateUtils.add(dateUtils.fromUnix(timeAtTimeStep), {
1284
- minutes: 5
1285
- }));
1286
- case Scale.Hours3:
1287
- case Scale.Hours6:
1288
- return dateUtils.unix(dateUtils.add(dateUtils.fromUnix(timeAtTimeStep), {
1289
- hours: 1
1290
- }));
1291
- case Scale.Day:
1292
- return dateUtils.unix(dateUtils.add(dateUtils.fromUnix(timeAtTimeStep), {
1293
- hours: 3
1294
- }));
1295
- case Scale.Week:
1296
- case Scale.Weeks2:
1297
- return dateUtils.unix(dateUtils.add(dateUtils.fromUnix(timeAtTimeStep), {
1298
- days: 1
1299
- }));
1300
- case Scale.Month:
1301
- return dateUtils.unix(dateUtils.add(dateUtils.fromUnix(timeAtTimeStep), {
1302
- weeks: 1
1303
- }));
1304
- case Scale.Year:
1305
- case Scale.Months3:
1306
- return dateUtils.unix(dateUtils.add(dateUtils.fromUnix(timeAtTimeStep), {
1307
- months: 1
1308
- }));
1309
- default:
1310
- return dateUtils.unix(dateUtils.add(dateUtils.fromUnix(timeAtTimeStep), {
1311
- months: 1
1312
- }));
1313
- }
1314
- };
1315
- var getTimesteps = function getTimesteps(roundedStart, roundedEnd, fundamentalScaleType) {
1316
- var timesteps = [];
1317
- var timestep = roundedStart;
1318
- while (timestep <= roundedEnd) {
1319
- timesteps.push(timestep);
1320
- timestep = incrementTimestep(timestep, fundamentalScaleType);
1321
- }
1322
- return timesteps;
1323
- };
1324
- var getCustomTimesteps = function getCustomTimesteps(roundedStart, roundedEnd, increment) {
1325
- var timesteps = [];
1326
- var timestep = roundedStart;
1327
- while (timestep <= roundedEnd) {
1328
- var _dateUtils$add;
1329
- timesteps.push(timestep);
1330
- timestep = dateUtils.unix(dateUtils.add(dateUtils.fromUnix(timestep), (_dateUtils$add = {}, _dateUtils$add[increment] = 1, _dateUtils$add)));
1331
- }
1332
- return timesteps;
1333
- };
1334
- var getLeftSideDateText = function getLeftSideDateText(timestamp, fundamentalScale) {
1335
- var time = dateUtils.fromUnix(timestamp);
1336
- switch (fundamentalScale) {
1337
- case Scale.Minutes5:
1338
- case Scale.Hour:
1339
- case Scale.Hours3:
1340
- case Scale.Hours6:
1341
- return dateUtils.dateToString(time, 'y MMM EEE dd');
1342
- case Scale.Day:
1343
- case Scale.Week:
1344
- case Scale.Weeks2:
1345
- return dateUtils.dateToString(time, 'y MMM');
1346
- case Scale.Month:
1347
- case Scale.Months3:
1348
- return dateUtils.dateToString(time, 'y');
1349
- case Scale.Year:
1350
- return dateUtils.dateToString(time, 'y');
1351
- default:
1352
- return '';
1353
- }
1354
- };
1355
- var drawTimeScale = function drawTimeScale(context, theme, visibleTimeStart, visibleTimeEnd, canvasWidth, height, secondsPerPx) {
1356
- var fundamentalScale = getFundamentalScale(secondsPerPx);
1357
- var _getRoundedStartAndEn = getRoundedStartAndEnd(visibleTimeStart, visibleTimeEnd, fundamentalScale),
1358
- roundedStart = _getRoundedStartAndEn[0],
1359
- roundedEnd = _getRoundedStartAndEn[1];
1360
-
1361
- // draw regular tickmarks
1362
- var ctx = context;
1363
- getTimesteps(roundedStart, roundedEnd, fundamentalScale).forEach(function (timestep) {
1364
- var stepPx = timestampToPixelEdges(timestep, visibleTimeStart, visibleTimeEnd, canvasWidth);
1365
- // Move 1 pixel line by 0.5 pixels to prevent it from being shown as blurry: https://usefulangle.com/post/17/html5-canvas-drawing-1px-crisp-straight-lines
1366
- drawStepPxLine(ctx, theme, Math.floor(stepPx) + 0.5, height, fundamentalScale, timestep);
1367
-
1368
- // Draw the time step time as text
1369
- var timeFormat = getTimeFormat(fundamentalScale);
1370
- var timeText = dateUtils.dateToString(dateUtils.fromUnix(timestep), timeFormat);
1371
- if ([Scale.Minutes5, Scale.Hour, Scale.Hours3, Scale.Hours6, Scale.Day].includes(fundamentalScale) &&
1372
- // eslint-disable-next-line @typescript-eslint/no-confusing-non-null-assertion
1373
- timestep % scaleToUnitSeconds[fundamentalScale] === 0 || fundamentalScale === Scale.Week && dateUtils.getDay(dateUtils.fromUnix(timestep)) === 1) {
1374
- drawTimeText(ctx, theme, stepPx, height, timeText, fundamentalScale);
1375
- }
1376
- if (fundamentalScale === Scale.Year && dateUtils.getMonth(dateUtils.fromUnix(timestep)) === 0) {
1377
- drawYearScaleText(ctx, theme, timeText, stepPx, height);
1378
- }
1379
- });
1380
-
1381
- // draw month overlay lines
1382
- if (fundamentalScale === Scale.Week || fundamentalScale === Scale.Weeks2 || fundamentalScale === Scale.Month || fundamentalScale === Scale.Months3) {
1383
- var _getCustomRoundedStar = getCustomRoundedStartAndEnd(visibleTimeStart, visibleTimeEnd, Scale.Year),
1384
- _roundedStart = _getCustomRoundedStar[0],
1385
- _roundedEnd = _getCustomRoundedStar[1];
1386
- var monthTimesteps = getCustomTimesteps(_roundedStart, _roundedEnd, 'months');
1387
- monthTimesteps.forEach(function (timestep) {
1388
- var stepPx = timestampToPixelEdges(timestep, visibleTimeStart, visibleTimeEnd, canvasWidth);
1389
- if (fundamentalScale === Scale.Month || fundamentalScale === Scale.Months3) {
1390
- var month = dateUtils.dateToString(dateUtils.fromUnix(timestep), 'MMM');
1391
-
1392
- // Move 1 pixel line by 0.5 pixels to prevent it from being shown as blurry: https://usefulangle.com/post/17/html5-canvas-drawing-1px-crisp-straight-lines
1393
- drawDateChangeLine(ctx, theme, Math.floor(stepPx) + 0.5, height);
1394
- drawTimeText(ctx, theme, stepPx, height, month, fundamentalScale);
1395
- return;
1396
- }
1397
- // adding 0.5 to make line not so blurred
1398
- drawDashedMonthChangeLine(ctx, theme, Math.floor(stepPx) + 0.5, height);
1399
- });
1400
- }
1401
- // draw date change texts
1402
- if (fundamentalScale === Scale.Year) {
1403
- return;
1404
- }
1405
- var dateText = getLeftSideDateText(visibleTimeStart, fundamentalScale);
1406
- drawLeftSideDateText(ctx, theme, dateText, height);
1407
- };
1408
-
1409
- /* *
1410
- * Licensed under the Apache License, Version 2.0 (the "License");
1411
- * you may not use this file except in compliance with the License.
1412
- * You may obtain a copy of the License at
1413
- *
1414
- * http://www.apache.org/licenses/LICENSE-2.0
1415
- *
1416
- * Unless required by applicable law or agreed to in writing, software
1417
- * distributed under the License is distributed on an "AS IS" BASIS,
1418
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1419
- * See the License for the specific language governing permissions and
1420
- * limitations under the License.
1421
- *
1422
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1423
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
1424
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
1425
- * */
1426
-
1427
- var drawBackground = function drawBackground(context, theme, visibleTimeStart, visibleTimeEnd, animationStartPx, animationEndPx, canvasWidth, height, secondsPerPx, timeSliderSpan, dataStartPx, dataEndPx, currentTimePx) {
1428
- var ctx = context;
1429
- var _theme$palette$geoweb = theme.palette.geowebColors.timeSlider,
1430
- timelineNightTime = _theme$palette$geoweb.timelineNightTime,
1431
- ledgendObservedBackground = _theme$palette$geoweb.ledgendObservedBackground,
1432
- legendForecastBackground = _theme$palette$geoweb.legendForecastBackground,
1433
- legendNoDataBackground = _theme$palette$geoweb.legendNoDataBackground;
1434
-
1435
- // top spacing
1436
- var y = 0;
1437
- var scaleToUse = timeSliderSpan ? getScaleFromSpan(timeSliderSpan) : getFundamentalScale(secondsPerPx);
1438
- drawDefaultBackground();
1439
- drawObservedData();
1440
- drawForecastData();
1441
- drawNightOrAlternateTime();
1442
- drawAnimationArea();
1443
- drawDraggableIcons();
1444
- function drawDefaultBackground() {
1445
- ctx.fillStyle = legendNoDataBackground.rgba;
1446
- ctx.fillRect(0, y, canvasWidth, height);
1447
- }
1448
- function drawObservedData() {
1449
- if (dataStartPx < currentTimePx) {
1450
- ctx.fillStyle = ledgendObservedBackground.fill;
1451
- ctx.fillRect(Math.max(dataStartPx, y), y, Math.min(currentTimePx, dataEndPx) - Math.max(dataStartPx, y), height);
1452
- }
1453
- }
1454
- function drawForecastData() {
1455
- if (dataEndPx > currentTimePx) {
1456
- ctx.fillStyle = legendForecastBackground.fill;
1457
- ctx.fillRect(Math.max(currentTimePx, dataStartPx), y, Math.min(canvasWidth, dataEndPx) - Math.max(currentTimePx, dataStartPx), height);
1458
- }
1459
- }
1460
- function drawAnimationArea() {
1461
- ctx.fillStyle = theme.palette.geowebColors.timeSlider.timelineSelectionBackground.rgba;
1462
- ctx.strokeStyle = theme.palette.geowebColors.timeSlider.timelineSelectionOutline.rgba;
1463
- ctx.lineWidth = 3;
1464
- ctx.rect(animationStartPx, y, Math.max(animationEndPx - animationStartPx, y), height);
1465
- ctx.fill();
1466
- ctx.stroke();
1467
- }
1468
- function drawDraggableIcons() {
1469
- ctx.save();
1470
- var path = new Path2D(dragHandlePath);
1471
- ctx.translate(animationStartPx, y);
1472
- ctx.fillStyle = theme.palette.geowebColors.timeSlider.timelineTimeScale.fill;
1473
- ctx.fill(path);
1474
- ctx.restore();
1475
- ctx.save();
1476
- ctx.translate(animationEndPx - 24, y);
1477
- ctx.fillStyle = theme.palette.geowebColors.timeSlider.timelineTimeScale.fill;
1478
- ctx.fill(path);
1479
- ctx.restore();
1480
- }
1481
- function drawNightOrAlternateTime() {
1482
- var colorChangeTimesteps = getColorChangeTimesteps(scaleToUse, visibleTimeStart, visibleTimeEnd);
1483
- colorChangeTimesteps.forEach(function (timestep, i, arr) {
1484
- if (i === 0) {
1485
- return;
1486
- }
1487
- var _map = [arr[i - 1], timestep].map(function (timestep) {
1488
- return timestampToPixelEdges(timestep, visibleTimeStart, visibleTimeEnd, canvasWidth);
1489
- }),
1490
- prevPx = _map[0],
1491
- currPx = _map[1];
1492
- if (!isColorIntervalEven(scaleToUse, timestep)) {
1493
- ctx.fillStyle = timelineNightTime.rgba;
1494
- var TOP_OFFSET = 0;
1495
- ctx.fillRect(prevPx, TOP_OFFSET, currPx - prevPx, height);
1496
- }
1497
- });
1498
- }
1499
- };
1500
- var getColorChangeTimestepUnit = function getColorChangeTimestepUnit(scale) {
1501
- switch (scale) {
1502
- case Scale.Year:
1503
- return 'months';
1504
- case Scale.Month:
1505
- case Scale.Months3:
1506
- return 'weeks';
1507
- case Scale.Weeks2:
1508
- case Scale.Week:
1509
- return 'days';
1510
- default:
1511
- return 'days';
1512
- }
1513
- };
1514
- var isColorIntervalEven = function isColorIntervalEven(scale, timestep) {
1515
- var time = dateUtils.fromUnix(timestep);
1516
- switch (scale) {
1517
- case Scale.Year:
1518
- return dateUtils.getMonth(time) % 2 === 0;
1519
- case Scale.Month:
1520
- case Scale.Months3:
1521
- return dateUtils.getWeek(time) % 2 === 0;
1522
- case Scale.Week:
1523
- case Scale.Weeks2:
1524
- return dateUtils.getDayOfYear(time) % 2 === 0;
1525
- default:
1526
- {
1527
- return dateUtils.getDayOfYear(time) % 2 === 0;
1528
- }
1529
- }
1530
- };
1531
- function getColorChangeTimesteps(scale, visibleTimeStart, visibleTimeEnd) {
1532
- var _getCustomRoundedStar = getCustomRoundedStartAndEnd(visibleTimeStart, visibleTimeEnd, scale),
1533
- colorChangeStart = _getCustomRoundedStar[0],
1534
- colorChangeEnd = _getCustomRoundedStar[1];
1535
- var colorChangeUnit = getColorChangeTimestepUnit(scale);
1536
- var colorChangeTimesteps = getCustomTimesteps(colorChangeStart, colorChangeEnd, colorChangeUnit);
1537
- return colorChangeTimesteps;
1538
- }
1539
-
1540
- /* *
1541
- * Licensed under the Apache License, Version 2.0 (the "License");
1542
- * you may not use this file except in compliance with the License.
1543
- * You may obtain a copy of the License at
1544
- *
1545
- * http://www.apache.org/licenses/LICENSE-2.0
1546
- *
1547
- * Unless required by applicable law or agreed to in writing, software
1548
- * distributed under the License is distributed on an "AS IS" BASIS,
1549
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1550
- * See the License for the specific language governing permissions and
1551
- * limitations under the License.
1552
- *
1553
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1554
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
1555
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
1556
- * */
1557
-
1558
- var drawCurrentTime = function drawCurrentTime(context, theme, width, height, startTime, endTime, currentTime) {
1559
- var ctx = context;
1560
- var _theme$palette$geoweb = theme.palette.geowebColors.timeSlider,
1561
- playerNeedleTime = _theme$palette$geoweb.playerNeedleTime,
1562
- playerNeedleTimeTop = _theme$palette$geoweb.playerNeedleTimeTop;
1563
- var current = currentTime;
1564
- var currentPx = current ? timestampToPixelEdges(current, startTime, endTime, width) : 0;
1565
- // Draw a high vertical line (needle) indicating the current or selected time
1566
- ctx.beginPath();
1567
- // Move 1 pixel line by 0.5 pixels to prevent it from being shown as blurry: https://usefulangle.com/post/17/html5-canvas-drawing-1px-crisp-straight-lines
1568
- ctx.moveTo(Math.floor(currentPx) + 0.5, height - 24);
1569
- ctx.lineTo(Math.floor(currentPx) + 0.5, height);
1570
- ctx.lineWidth = 5;
1571
- ctx.strokeStyle = playerNeedleTime.rgba;
1572
- ctx.stroke();
1573
- ctx.lineWidth = 1;
1574
- ctx.strokeStyle = playerNeedleTimeTop.rgba;
1575
- ctx.stroke();
1576
- };
1577
-
1578
- /* *
1579
- * Licensed under the Apache License, Version 2.0 (the "License");
1580
- * you may not use this file except in compliance with the License.
1581
- * You may obtain a copy of the License at
1582
- *
1583
- * http://www.apache.org/licenses/LICENSE-2.0
1584
- *
1585
- * Unless required by applicable law or agreed to in writing, software
1586
- * distributed under the License is distributed on an "AS IS" BASIS,
1587
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1588
- * See the License for the specific language governing permissions and
1589
- * limitations under the License.
1590
- *
1591
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1592
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
1593
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
1594
- * */
1595
-
1596
- var drawNeedle = function drawNeedle(context, theme, width, height, startTime, endTime, selectedTime) {
1597
- if (!selectedTime) {
1598
- return;
1599
- }
1600
- var ctx = context;
1601
- var _theme$palette$geoweb = theme.palette.geowebColors.timeSlider,
1602
- playerNeedlePlayer = _theme$palette$geoweb.playerNeedlePlayer,
1603
- playerNeedlePlayerTop = _theme$palette$geoweb.playerNeedlePlayerTop,
1604
- playerTimeMarkers = _theme$palette$geoweb.playerTimeMarkers;
1605
- var selectedPx = timestampToPixelEdges(selectedTime, startTime, endTime, width);
1606
-
1607
- // Draw a high vertical line (needle) indicating the current or selected time
1608
- ctx.beginPath();
1609
- // Move 1 pixel line by 0.5 pixels to prevent it from being shown as blurry: https://usefulangle.com/post/17/html5-canvas-drawing-1px-crisp-straight-lines
1610
- ctx.moveTo(Math.floor(selectedPx) + 0.5, height - 50);
1611
- ctx.lineTo(Math.floor(selectedPx) + 0.5, height);
1612
- ctx.lineWidth = 5;
1613
- ctx.strokeStyle = playerNeedlePlayer.rgba;
1614
- ctx.stroke();
1615
- ctx.lineWidth = 1;
1616
- ctx.strokeStyle = playerNeedlePlayerTop.rgba;
1617
- ctx.stroke();
1618
-
1619
- // Triange connecting timebox.
1620
- ctx.beginPath();
1621
- ctx.moveTo(Math.floor(selectedPx) + 5, 0);
1622
- ctx.lineTo(Math.floor(selectedPx) + 0.5, 5);
1623
- ctx.lineTo(Math.floor(selectedPx) - 5, 0);
1624
- ctx.closePath();
1625
- ctx.fillStyle = playerTimeMarkers.fill;
1626
- ctx.fill();
1627
- };
1628
-
1629
- /* *
1630
- * Licensed under the Apache License, Version 2.0 (the "License");
1631
- * you may not use this file except in compliance with the License.
1632
- * You may obtain a copy of the License at
1633
- *
1634
- * http://www.apache.org/licenses/LICENSE-2.0
1635
- *
1636
- * Unless required by applicable law or agreed to in writing, software
1637
- * distributed under the License is distributed on an "AS IS" BASIS,
1638
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1639
- * See the License for the specific language governing permissions and
1640
- * limitations under the License.
1641
- *
1642
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1643
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
1644
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
1645
- * */
1646
-
1647
- var drawTimeSliderLegend = function drawTimeSliderLegend(context, theme, canvasWidth, height, centerTime, secondsPerPx, timeSliderSpan, selectedTimeUnix, currentTimeUnix, animationStartTime, animationEndTime, dataStartTime, dataEndTime) {
1648
- var ctx = context;
1649
- var _map = [0, canvasWidth].map(function (px) {
1650
- return pixelToTimestamp(px, centerTime, canvasWidth, secondsPerPx);
1651
- }),
1652
- visibleTimeStart = _map[0],
1653
- visibleTimeEnd = _map[1];
1654
- var _map2 = [animationStartTime, animationEndTime, dataStartTime, dataEndTime, currentTimeUnix].map(function (time) {
1655
- return timestampToPixel(time, centerTime, canvasWidth, secondsPerPx);
1656
- }),
1657
- animationStartPx = _map2[0],
1658
- animationEndPx = _map2[1],
1659
- dataStartPx = _map2[2],
1660
- dataEndPx = _map2[3],
1661
- currentTimePx = _map2[4];
1662
- ctx.clearRect(0, 0, canvasWidth, height);
1663
- drawBackground(ctx, theme, visibleTimeStart, visibleTimeEnd, animationStartPx, animationEndPx, canvasWidth, height, secondsPerPx, timeSliderSpan, dataStartPx, dataEndPx, currentTimePx);
1664
- drawTimeScale(ctx, theme, visibleTimeStart, visibleTimeEnd, canvasWidth, height, secondsPerPx);
1665
- drawCurrentTime(ctx, theme, canvasWidth, height, visibleTimeStart, visibleTimeEnd, currentTimeUnix);
1666
- drawNeedle(ctx, theme, canvasWidth, height, visibleTimeStart, visibleTimeEnd, selectedTimeUnix);
1667
- };
1668
-
1669
- /* *
1670
- * Licensed under the Apache License, Version 2.0 (the "License");
1671
- * you may not use this file except in compliance with the License.
1672
- * You may obtain a copy of the License at
1673
- *
1674
- * http://www.apache.org/licenses/LICENSE-2.0
1675
- *
1676
- * Unless required by applicable law or agreed to in writing, software
1677
- * distributed under the License is distributed on an "AS IS" BASIS,
1678
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1679
- * See the License for the specific language governing permissions and
1680
- * limitations under the License.
1681
- *
1682
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1683
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
1684
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
1685
- * */
1686
-
1687
- // Explanation of props can be found here:
1688
- // https://drive.google.com/file/d/1jqqNcciCH0UJiZ04HO-1vknmPPpT8fK5/view?usp=sharing
1689
-
1690
- var TimeSliderLegend = function TimeSliderLegend(_ref) {
1691
- var _node$current, _getTimeSliderLegendE;
1692
- var mapId = _ref.mapId,
1693
- isTimeScrollingEnabled = _ref.isTimeScrollingEnabled,
1694
- mapWindowRef = _ref.mapWindowRef,
1695
- centerTime = _ref.centerTime,
1696
- canvasWidth = _ref.timeSliderWidth,
1697
- _ref$secondsPerPx = _ref.secondsPerPx,
1698
- secondsPerPx = _ref$secondsPerPx === void 0 ? defaultSecondsPerPx : _ref$secondsPerPx,
1699
- currentTime = _ref.currentTime,
1700
- dataStartTime = _ref.dataStartTime,
1701
- dataEndTime = _ref.dataEndTime,
1702
- reduxAnimationStartTime = _ref.reduxAnimationStartTime,
1703
- reduxAnimationEndTime = _ref.reduxAnimationEndTime,
1704
- timeStep = _ref.timeStep,
1705
- unfilteredSelectedTime = _ref.unfilteredSelectedTime,
1706
- isDraggingStartAnimation = _ref.isDraggingStartAnimation,
1707
- isDraggingEndAnimation = _ref.isDraggingEndAnimation,
1708
- isTimeSliderHoverOn = _ref.isTimeSliderHoverOn,
1709
- timeSliderSpan = _ref.timeSliderSpan,
1710
- _ref$setUnfilteredSel = _ref.setUnfilteredSelectedTime,
1711
- setUnfilteredSelectedTime = _ref$setUnfilteredSel === void 0 ? function () {} : _ref$setUnfilteredSel,
1712
- _ref$onSetCenterTime = _ref.onSetCenterTime,
1713
- onSetCenterTime = _ref$onSetCenterTime === void 0 ? function () {} : _ref$onSetCenterTime,
1714
- _ref$onSetAnimationSt = _ref.onSetAnimationStartTime,
1715
- onSetAnimationStartTime = _ref$onSetAnimationSt === void 0 ? function () {} : _ref$onSetAnimationSt,
1716
- _ref$onSetAnimationEn = _ref.onSetAnimationEndTime,
1717
- onSetAnimationEndTime = _ref$onSetAnimationEn === void 0 ? function () {} : _ref$onSetAnimationEn,
1718
- _ref$updateCanvasWidt = _ref.updateCanvasWidth,
1719
- updateCanvasWidth = _ref$updateCanvasWidt === void 0 ? function () {} : _ref$updateCanvasWidt,
1720
- setIsDraggingStartAnimation = _ref.setIsDraggingStartAnimation,
1721
- setIsDraggingEndAnimation = _ref.setIsDraggingEndAnimation,
1722
- onStartTimeChange = _ref.onStartTimeChange,
1723
- onEndTimeChange = _ref.onEndTimeChange,
1724
- onSetTimeSliderSpan = _ref.onSetTimeSliderSpan,
1725
- _ref$adjustSelectedTi = _ref.adjustSelectedTimeOnWheel,
1726
- adjustSelectedTimeOnWheel = _ref$adjustSelectedTi === void 0 ? function () {} : _ref$adjustSelectedTi;
1727
- var _useCanvasTarget = useCanvasTarget('mousedown'),
1728
- node = _useCanvasTarget[1];
1729
- var theme = useTheme();
1730
- var _useState = useState(false),
1731
- isDraggingSelectedTime = _useState[0],
1732
- setIsDraggingSelectedTime = _useState[1];
1733
- var _useState2 = useState(false),
1734
- isDraggingLegend = _useState2[0],
1735
- setIsDraggingLegend = _useState2[1];
1736
- var xOffset = ((_node$current = node.current) == null || (_node$current = _node$current.canvas) == null ? void 0 : _node$current.getBoundingClientRect().x) || 0;
1737
- var _useState3 = useState(false),
1738
- isDraggingAnimationArea = _useState3[0],
1739
- setIsDraggingAnimationArea = _useState3[1];
1740
- var _useState4 = useState(false),
1741
- isMouseOverCanvas = _useState4[0],
1742
- setIsMouseOverCanvas = _useState4[1];
1743
- var _useState5 = useState('auto'),
1744
- cursorStyle = _useState5[0],
1745
- setCursorStyle = _useState5[1];
1746
- var _useState6 = useState(undefined),
1747
- showTooltip = _useState6[0],
1748
- setShowTooltip = _useState6[1];
1749
- var _useState7 = useState(),
1750
- lastHandledRoundedTime = _useState7[0],
1751
- setLastHandledRoundedTime = _useState7[1];
1752
-
1753
- // remove active drag. can happen outside canvas.
1754
- var _useState8 = useState(),
1755
- localAnimationStartTime = _useState8[0],
1756
- setLocalAnimationStartTime = _useState8[1];
1757
- var _useState9 = useState(),
1758
- localAnimationEndTime = _useState9[0],
1759
- setLocalAnimationEndTime = _useState9[1];
1760
- var _useState0 = useState(),
1761
- pointerTime = _useState0[0],
1762
- setPointerTime = _useState0[1];
1763
- var _useState1 = useState(false),
1764
- showPointerTimeTooltip = _useState1[0],
1765
- setShowPointerTimeTooltip = _useState1[1];
1766
- var debouncedSetShowPointerTimeTooltip = useRef(debounce(setShowPointerTimeTooltip, 500)).current;
1767
- var timeBetweenMouseAndStartAndEnd = useRef();
1768
- var pixelsMovedSinceStartDragging = useRef(0);
1769
- var isAnimationTimeModifiedSetRef = useRef(false);
1770
- var tooltipPosition = useRef();
1771
- var startDraggingPosition = useRef(0);
1772
- var popperRef = useRef(null);
1773
- var isClickOrDrag = useRef();
1774
-
1775
- // Display unfilteredSelectedTime (already snapped to available timestep)
1776
- var displayTime = unfilteredSelectedTime;
1777
- var start = localAnimationStartTime;
1778
- var end = localAnimationEndTime;
1779
- var pixelsBetweenViewportAndTimesliderOnTop = (_getTimeSliderLegendE = getTimeSliderLegendElement(mapId)) == null ? void 0 : _getTimeSliderLegendE.getBoundingClientRect()['top'];
1780
- var setTooltipPosition = function setTooltipPosition() {
1781
- var tooltipX = tooltipPosition.current;
1782
- var tooltipY = pixelsBetweenViewportAndTimesliderOnTop && pixelsBetweenViewportAndTimesliderOnTop - TIME_SLIDER_LEGEND_HEIGHT * 2.5;
1783
- return new DOMRect(tooltipX, tooltipY, 0, 0);
1784
- };
1785
- var getTooltipTime = function getTooltipTime() {
1786
- switch (showTooltip) {
1787
- case 'animationStart':
1788
- return localAnimationStartTime;
1789
- case 'animationEnd':
1790
- return localAnimationEndTime;
1791
- case 'mousePointer':
1792
- return pointerTime;
1793
- default:
1794
- return undefined;
1795
- }
1796
- };
1797
- var getTooltipText = function getTooltipText() {
1798
- var time = getTooltipTime();
1799
- if (!time) {
1800
- return undefined;
1801
- }
1802
- var roundedTooltipTime = showTooltip === 'mousePointer' ? time : roundWithTimeStep$1(time);
1803
- var tooltipText = dateUtils.dateToString(dateUtils.fromUnix(roundedTooltipTime), dateUtils.DATE_FORMAT_HOURS);
1804
- return tooltipText;
1805
- };
1806
- var roundWithTimeStep$1 = function roundWithTimeStep$1(time) {
1807
- return roundWithTimeStep(time, timeStep);
1808
- };
1809
- var currentIndex = timeValues.indexOf(timeSliderSpan);
1810
- var updateTimeSpan = function updateTimeSpan(deltaY) {
1811
- if (onSetTimeSliderSpan) {
1812
- // Don't do anything if we are already at the edges of the timespan options
1813
- if (deltaY < 0 && currentIndex === 0 || deltaY > 0 && currentIndex === timeValues.length - 1) {
1814
- return;
1815
- }
1816
- var newTimeSpan = deltaY < 0 ? timeValues[currentIndex - 1] : timeValues[currentIndex + 1];
1817
- onSetTimeSliderSpan(newTimeSpan, centerTime);
1818
- }
1819
- };
1820
- var throttledUpdateTimeSpan = throttle(updateTimeSpan, 200);
1821
- var debouncedAndThrottledUpdateTimeSpan = debounce(throttledUpdateTimeSpan, 20);
1822
- var handleAnimationDragging = React.useCallback(function (x, clientX) {
1823
- if (!localAnimationStartTime || !localAnimationEndTime) {
1824
- return;
1825
- }
1826
- var mousePosition = clientX - xOffset;
1827
- var startPos = timestampToPixel(localAnimationStartTime, centerTime, canvasWidth, secondsPerPx);
1828
- var endPos = timestampToPixel(localAnimationEndTime, centerTime, canvasWidth, secondsPerPx);
1829
- var mouseTimeUnix = pixelToTimestamp(mousePosition, centerTime, canvasWidth, secondsPerPx);
1830
- var startTime = roundWithTimeStep(mouseTimeUnix, timeStep);
1831
- var endTime = roundWithTimeStep(mouseTimeUnix, timeStep);
1832
- var pixelsBetweenOnLeft = getPixelsBetweenViewportAndTimesliderOnLeft(mapId);
1833
- if (isDraggingStartAnimation || isDraggingEndAnimation || isDraggingAnimationArea) {
1834
- if (!isAnimationTimeModifiedSetRef.current) {
1835
- isAnimationTimeModifiedSetRef.current = true;
1836
- }
1837
- }
1838
- if (isDraggingStartAnimation) {
1839
- if (isDraggingStartWithinBounds(endPos, mousePosition)) {
1840
- return;
1841
- }
1842
- setLocalAnimationStartTime(roundWithTimeStep(mouseTimeUnix, timeStep));
1843
- if (lastHandledRoundedTime !== startTime) {
1844
- setLastHandledRoundedTime(startTime);
1845
- setShowTooltip('animationStart');
1846
- onStartTimeChange == null || onStartTimeChange(startTime);
1847
- }
1848
- } else if (isDraggingEndAnimation && pixelsBetweenOnLeft) {
1849
- if (isDraggingEndWithinBounds(startPos, mousePosition, canvasWidth)) {
1850
- return;
1851
- }
1852
- setLocalAnimationEndTime(roundWithTimeStep(mouseTimeUnix, timeStep));
1853
- if (lastHandledRoundedTime !== endTime) {
1854
- setLastHandledRoundedTime(endTime);
1855
- setShowTooltip('animationEnd');
1856
- onEndTimeChange == null || onEndTimeChange(endTime);
1857
- }
1858
- }
1859
- if (isDraggingAnimationArea) {
1860
- if (timeBetweenMouseAndStartAndEnd.current === undefined) {
1861
- // to move the whole animation area we need to calculate the distance
1862
- // between the mouse position and the start and end position
1863
-
1864
- var _timeFromMouseToStart = mouseTimeUnix - start;
1865
- var _timeFromMouseToEnd = end - mouseTimeUnix;
1866
- timeBetweenMouseAndStartAndEnd.current = {
1867
- timeFromMouseToEnd: _timeFromMouseToEnd,
1868
- timeFromMouseToStart: _timeFromMouseToStart
1869
- };
1870
- return;
1871
- }
1872
- pixelsMovedSinceStartDragging.current += x;
1873
- var _timeBetweenMouseAndS = timeBetweenMouseAndStartAndEnd.current,
1874
- timeFromMouseToEnd = _timeBetweenMouseAndS.timeFromMouseToEnd,
1875
- timeFromMouseToStart = _timeBetweenMouseAndS.timeFromMouseToStart;
1876
- var newStartTime = mouseTimeUnix - timeFromMouseToStart;
1877
- var newEndTime = mouseTimeUnix + timeFromMouseToEnd;
1878
- var roundedNewStartTime = roundWithTimeStep(newStartTime, timeStep);
1879
- var roundedNewEndTime = roundWithTimeStep(newEndTime, timeStep);
1880
- setLocalAnimationStartTime(roundedNewStartTime);
1881
- setLocalAnimationEndTime(roundedNewEndTime);
1882
- }
1883
- }, [canvasWidth, centerTime, end, isDraggingAnimationArea, isDraggingEndAnimation, isDraggingStartAnimation, lastHandledRoundedTime, localAnimationEndTime, localAnimationStartTime, mapId, onEndTimeChange, onStartTimeChange, secondsPerPx, start, timeStep, xOffset]);
1884
- useEffect(function () {
1885
- var handleMouseUp = function handleMouseUp() {
1886
- pixelsMovedSinceStartDragging.current = 0;
1887
- timeBetweenMouseAndStartAndEnd.current = undefined;
1888
- };
1889
- document.addEventListener('mouseup', handleMouseUp);
1890
- return function () {
1891
- document.removeEventListener('mouseup', handleMouseUp);
1892
- };
1893
- }, []);
1894
- useEffect(function () {
1895
- var startTimestamp = convertStringTimeToUnix(reduxAnimationStartTime);
1896
- var endTimestamp = convertStringTimeToUnix(reduxAnimationEndTime);
1897
- setLocalAnimationStartTime(startTimestamp);
1898
- setLocalAnimationEndTime(endTimestamp);
1899
- }, [reduxAnimationStartTime, reduxAnimationEndTime, setLocalAnimationStartTime, setLocalAnimationEndTime]);
1900
- useEffect(function () {
1901
- var stoppedDragging = !isDraggingStartAnimation && !isDraggingEndAnimation && !isDraggingAnimationArea;
1902
- if (stoppedDragging && isAnimationTimeModifiedSetRef.current) {
1903
- if (start && start !== localAnimationStartTime) {
1904
- onSetAnimationStartTime(dateUtils.fromUnix(start).toISOString());
1905
- }
1906
- if (end && end !== localAnimationEndTime) {
1907
- onSetAnimationEndTime(dateUtils.fromUnix(end).toISOString());
1908
- }
1909
- isAnimationTimeModifiedSetRef.current = false;
1910
- }
1911
- }, [isDraggingStartAnimation, isDraggingEndAnimation, isDraggingAnimationArea, isAnimationTimeModifiedSetRef, localAnimationStartTime, localAnimationEndTime, onSetAnimationStartTime, onSetAnimationEndTime, start, end]);
1912
- useEffect(function () {
1913
- var handleMouseUp = function handleMouseUp() {
1914
- if (isDraggingAnimationArea) {
1915
- onStartTimeChange == null || onStartTimeChange(localAnimationStartTime);
1916
- onEndTimeChange == null || onEndTimeChange(localAnimationEndTime);
1917
- }
1918
- setCursorStyle('auto');
1919
- setIsDraggingSelectedTime(false);
1920
- setIsDraggingStartAnimation == null || setIsDraggingStartAnimation(false);
1921
- setIsDraggingEndAnimation == null || setIsDraggingEndAnimation(false);
1922
- setIsDraggingLegend(false);
1923
- setShowTooltip(undefined);
1924
- setIsDraggingAnimationArea(false);
1925
- startDraggingPosition.current = 0;
1926
- if (isAnimationTimeModifiedSetRef.current) {
1927
- isAnimationTimeModifiedSetRef.current = false;
1928
- }
1929
- };
1930
- document.addEventListener('mouseup', handleMouseUp);
1931
- return function () {
1932
- document.removeEventListener('mouseup', handleMouseUp);
1933
- };
1934
- }, [setIsDraggingStartAnimation, setIsDraggingEndAnimation, localAnimationStartTime, localAnimationEndTime, onStartTimeChange, onEndTimeChange, isDraggingAnimationArea]);
1935
- useEffect(function () {
1936
- var handleMouseActions = function handleMouseActions(event) {
1937
- if (event.movementX === 0) {
1938
- return;
1939
- }
1940
- if (isDraggingLegend) {
1941
- var dragDistanceTime = event.movementX * secondsPerPx;
1942
- var newCenterTime = centerTime - dragDistanceTime;
1943
- onSetCenterTime(newCenterTime);
1944
- } else if (isDraggingStartAnimation || isDraggingEndAnimation || isDraggingAnimationArea) {
1945
- handleAnimationDragging(event.movementX, event.clientX);
1946
- } else if (isDraggingSelectedTime) {
1947
- moveSelectedTimePx(event.movementX, canvasWidth, centerTime, dataStartTime, dataEndTime, secondsPerPx, timeStep, unfilteredSelectedTime, setUnfilteredSelectedTime);
1948
- }
1949
- if (isMouseOverCanvas && isTimeSliderHoverOn) {
1950
- moveSelectedTimePx(event.movementX, canvasWidth, centerTime, dataStartTime, dataEndTime, secondsPerPx, timeStep, unfilteredSelectedTime, setUnfilteredSelectedTime);
1951
- }
1952
- };
1953
- var handleMouseMove = function handleMouseMove(event) {
1954
- handleMouseActions(event);
1955
- };
1956
- document.addEventListener('mousemove', handleMouseMove);
1957
- return function () {
1958
- document.removeEventListener('mousemove', handleMouseMove);
1959
- };
1960
- }, [isDraggingLegend, isDraggingStartAnimation, isDraggingEndAnimation, isDraggingAnimationArea, isDraggingSelectedTime, canvasWidth, centerTime, dataStartTime, dataEndTime, secondsPerPx, timeStep, unfilteredSelectedTime, setUnfilteredSelectedTime, onSetCenterTime, isTimeSliderHoverOn, isMouseOverCanvas, handleAnimationDragging]);
1961
- useEffect(function () {
1962
- if (!showTooltip && pointerTime) {
1963
- if (showPointerTimeTooltip) {
1964
- setShowTooltip('mousePointer');
1965
- } else {
1966
- debouncedSetShowPointerTimeTooltip(true);
1967
- }
1968
- } else if (showTooltip === 'mousePointer' && !pointerTime) {
1969
- setShowTooltip(undefined);
1970
- debouncedSetShowPointerTimeTooltip(false);
1971
- debouncedSetShowPointerTimeTooltip.flush();
1972
- } else if (showTooltip !== 'mousePointer') {
1973
- debouncedSetShowPointerTimeTooltip(false);
1974
- debouncedSetShowPointerTimeTooltip.flush();
1975
- }
1976
- }, [debouncedSetShowPointerTimeTooltip, pointerTime, showPointerTimeTooltip, showTooltip]);
1977
- var onMouseDown = function onMouseDown(x, y, width) {
1978
- isClickOrDrag.current = 'click';
1979
- startDraggingPosition.current = x;
1980
- var _getPositions = getPositions(width, unfilteredSelectedTime, centerTime, secondsPerPx, start, end),
1981
- startAnimationPosition = _getPositions.startAnimationPosition,
1982
- endAnimationPosition = _getPositions.endAnimationPosition,
1983
- selectedTimePosition = _getPositions.selectedTimePosition;
1984
-
1985
- // start dragging selected time.
1986
- if (isSelectedTimeIconArea(x, selectedTimePosition, DRAG_AREA_WIDTH)) {
1987
- setCursorStyle('grabbing');
1988
- setIsDraggingSelectedTime(true);
1989
- return;
1990
- }
1991
- if (reduxAnimationStartTime && reduxAnimationEndTime) {
1992
- var pixelsBetweenOnLeft = getPixelsBetweenViewportAndTimesliderOnLeft(mapId);
1993
- tooltipPosition.current = pixelsBetweenOnLeft ? x + pixelsBetweenOnLeft : x;
1994
-
1995
- // start dragging either marker
1996
- if (isLeftAnimationIconArea(x, startAnimationPosition, DRAG_AREA_WIDTH)) {
1997
- setCursorStyle('grabbing');
1998
- setIsDraggingStartAnimation == null || setIsDraggingStartAnimation(true);
1999
- setShowTooltip('animationStart');
2000
- return;
2001
- }
2002
- if (isRightAnimationIconArea(x, endAnimationPosition, DRAG_AREA_WIDTH)) {
2003
- setCursorStyle('grabbing');
2004
- setIsDraggingEndAnimation == null || setIsDraggingEndAnimation(true);
2005
- setShowTooltip('animationEnd');
2006
- return;
2007
- }
2008
- if (isInsideAnimationArea(x, startAnimationPosition, endAnimationPosition)) {
2009
- setCursorStyle('grabbing');
2010
- setIsDraggingAnimationArea(true);
2011
- return;
2012
- }
2013
- }
2014
- // clicking the timeslider
2015
- setIsDraggingLegend(true);
2016
- };
2017
- var onMouseUp = function onMouseUp(x) {
2018
- if (isClickOrDrag.current === 'click') {
2019
- var unfilteredSelectedTimePx = timestampToPixel(unfilteredSelectedTime, centerTime, canvasWidth, secondsPerPx);
2020
- moveSelectedTimePx(x - unfilteredSelectedTimePx, canvasWidth, centerTime, dataStartTime, dataEndTime, secondsPerPx, timeStep, unfilteredSelectedTime, setUnfilteredSelectedTime);
2021
- }
2022
- isClickOrDrag.current = undefined;
2023
- };
2024
- var onMouseMove = function onMouseMove(x, y, event, width) {
2025
- var mousePosition = x;
2026
- setPointerTime(pixelToTimestamp(mousePosition, centerTime, canvasWidth, secondsPerPx));
2027
- var pixelsBetweenOnLeft = getPixelsBetweenViewportAndTimesliderOnLeft(mapId);
2028
- tooltipPosition.current = pixelsBetweenOnLeft && mousePosition + pixelsBetweenOnLeft;
2029
- if (isClickOrDrag.current === 'click') {
2030
- isClickOrDrag.current = 'drag';
2031
- }
2032
- if (isDraggingSelectedTime || isDraggingStartAnimation || isDraggingEndAnimation || isDraggingAnimationArea) {
2033
- return;
2034
- }
2035
- var _getPositions2 = getPositions(width, unfilteredSelectedTime, centerTime, secondsPerPx, start, end),
2036
- startAnimationPosition = _getPositions2.startAnimationPosition,
2037
- endAnimationPosition = _getPositions2.endAnimationPosition,
2038
- selectedTimePosition = _getPositions2.selectedTimePosition;
2039
-
2040
- // Adjust mouse cursor while hovering draggable areas
2041
- var leftAnimationIconArea = isLeftAnimationIconArea(x, startAnimationPosition, DRAG_AREA_WIDTH);
2042
- var rightAnimationIconArea = isRightAnimationIconArea(x, endAnimationPosition, DRAG_AREA_WIDTH);
2043
- var selectedTimeArea = isSelectedTimeIconArea(x, selectedTimePosition, DRAG_AREA_WIDTH);
2044
- var insideAnimationArea = isInsideAnimationArea(x, startAnimationPosition, endAnimationPosition);
2045
- var hoveringLegendHandles = leftAnimationIconArea || rightAnimationIconArea || selectedTimeArea || isDraggingLegend;
2046
- if (hoveringLegendHandles) {
2047
- setCursorStyle('ew-resize');
2048
- } else if (insideAnimationArea && !isDraggingAnimationArea) {
2049
- setCursorStyle('grab');
2050
- } else if (insideAnimationArea && isDraggingAnimationArea) {
2051
- setCursorStyle('grabbing');
2052
- } else {
2053
- setCursorStyle('auto');
2054
- }
2055
- };
2056
- var onWheel = React.useCallback(function (_ref2) {
2057
- var event = _ref2.event,
2058
- deltaY = _ref2.deltaY;
2059
- event.preventDefault();
2060
- if (event.ctrlKey || event.metaKey) {
2061
- debouncedAndThrottledUpdateTimeSpan(deltaY);
2062
- }
2063
- }, [debouncedAndThrottledUpdateTimeSpan]);
2064
- var onWheelOverCanvas = React.useCallback(function (props) {
2065
- onWheel(props);
2066
- adjustSelectedTimeOnWheel(props);
2067
- }, [adjustSelectedTimeOnWheel, onWheel]);
2068
- React.useEffect(function () {
2069
- if (isTimeScrollingEnabled && mapWindowRef != null && mapWindowRef.current) {
2070
- var handleWheel = function handleWheel(event) {
2071
- event.preventDefault();
2072
- onWheel({
2073
- event: event,
2074
- deltaY: event.deltaY
2075
- });
2076
- };
2077
- var element = mapWindowRef.current;
2078
- element.addEventListener('wheel', handleWheel);
2079
- return function () {
2080
- element.removeEventListener('wheel', handleWheel);
2081
- };
2082
- }
2083
- return undefined;
2084
- }, [isTimeScrollingEnabled, mapWindowRef, onWheel]);
2085
- return /*#__PURE__*/jsxs(Box, {
2086
- sx: {
2087
- position: 'relative',
2088
- height: TIME_SLIDER_LEGEND_HEIGHT + "px"
2089
- },
2090
- children: [/*#__PURE__*/jsx(CustomTooltip, {
2091
- open: Boolean(showTooltip),
2092
- slotProps: {
2093
- popper: {
2094
- popperRef: popperRef,
2095
- anchorEl: {
2096
- getBoundingClientRect: setTooltipPosition
2097
- }
2098
- }
2099
- },
2100
- title: getTooltipText(),
2101
- children: /*#__PURE__*/jsx(Box, {
2102
- className: getTimeSliderLegendId(mapId),
2103
- "data-testid": "timeSliderLegend",
2104
- onMouseLeave: function onMouseLeave() {
2105
- setPointerTime(undefined);
2106
- },
2107
- sx: {
2108
- height: TIME_SLIDER_LEGEND_HEIGHT + "px",
2109
- borderRadius: '4.5px',
2110
- overflow: 'hidden',
2111
- cursor: cursorStyle
2112
- },
2113
- children: /*#__PURE__*/jsx(CanvasComponent, {
2114
- onMouseDown: onMouseDown,
2115
- onMouseMove: onMouseMove,
2116
- onMouseUp: onMouseUp,
2117
- onRenderCanvas: function onRenderCanvas(ctx, width, height) {
2118
- updateCanvasWidth(canvasWidth, width);
2119
- drawTimeSliderLegend(ctx, theme, width, height, centerTime, secondsPerPx, timeSliderSpan, displayTime, currentTime, start, end, dataStartTime, dataEndTime);
2120
- },
2121
- onWheel: onWheelOverCanvas,
2122
- ref: node
2123
- })
2124
- })
2125
- }), !!isTimeSliderHoverOn && /*#__PURE__*/jsx(Box, {
2126
- "data-testid": "customCanvasMouseOverContainer",
2127
- onMouseLeave: function onMouseLeave() {
2128
- return setIsMouseOverCanvas(false);
2129
- },
2130
- onMouseOver: function onMouseOver() {
2131
- return setIsMouseOverCanvas(true);
2132
- },
2133
- sx: {
2134
- position: 'absolute',
2135
- top: '-40px',
2136
- left: 0,
2137
- right: 0,
2138
- bottom: 0,
2139
- height: TIME_SLIDER_LEGEND_HEIGHT + " + 40px",
2140
- zIndex: isMouseOverCanvas ? 100 : 0
2141
- }
2142
- })]
2143
- });
2144
- };
2145
-
2146
- /* *
2147
- * Licensed under the Apache License, Version 2.0 (the "License");
2148
- * you may not use this file except in compliance with the License.
2149
- * You may obtain a copy of the License at
2150
- *
2151
- * http://www.apache.org/licenses/LICENSE-2.0
2152
- *
2153
- * Unless required by applicable law or agreed to in writing, software
2154
- * distributed under the License is distributed on an "AS IS" BASIS,
2155
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2156
- * See the License for the specific language governing permissions and
2157
- * limitations under the License.
2158
- *
2159
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2160
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
2161
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2162
- * */
2163
-
2164
- var THROTTLE_WAIT_TIME = 300; // [ms]
2165
- var THROTTLE_OPTIONS = {
2166
- trailing: false // Invoke function when called, but not more than once every <THROTTLE_WAIT_TIME>.
2167
- };
2168
- var TimeSliderMenu = function TimeSliderMenu(_ref) {
2169
- var marks = _ref.marks,
2170
- value = _ref.value,
2171
- allOptionsDisabled = _ref.allOptionsDisabled,
2172
- isAutoDisabled = _ref.isAutoDisabled,
2173
- handleAutoClick = _ref.handleAutoClick,
2174
- isAutoSelected = _ref.isAutoSelected,
2175
- title = _ref.title,
2176
- icon = _ref.icon,
2177
- _ref$onChangeSliderVa = _ref.onChangeSliderValue,
2178
- onChangeSliderValue = _ref$onChangeSliderVa === void 0 ? function () {} : _ref$onChangeSliderVa,
2179
- displayCurrentLength = _ref.displayCurrentLength,
2180
- _ref$disbleUserSetDur = _ref.disbleUserSetDuration,
2181
- disbleUserSetDuration = _ref$disbleUserSetDur === void 0 ? true : _ref$disbleUserSetDur,
2182
- customLengthSelector = _ref.customLengthSelector,
2183
- _ref$setOpen = _ref.setOpen,
2184
- setOpen = _ref$setOpen === void 0 ? function () {} : _ref$setOpen,
2185
- _ref$customFieldHeade = _ref.customFieldHeader,
2186
- customFieldHeader = _ref$customFieldHeade === void 0 ? 'timeslider-length' : _ref$customFieldHeade,
2187
- open = _ref.open;
2188
- var currentMarkIndex = marks.findIndex(function (mark) {
2189
- return mark.value === value;
2190
- });
2191
- var currentMark = marks[currentMarkIndex];
2192
- var _React$useState = React.useState(null),
2193
- anchorRef = _React$useState[0],
2194
- setAnchorRef = _React$useState[1];
2195
- var _useTimesliderTransla = useTimesliderTranslation(),
2196
- t = _useTimesliderTransla.t;
2197
- var _useState = useState(false),
2198
- displayLengthInputField = _useState[0],
2199
- setDisplayLengthInputField = _useState[1];
2200
- React.useEffect(function () {
2201
- if (!open && displayLengthInputField) {
2202
- setDisplayLengthInputField(false);
2203
- }
2204
- }, [displayLengthInputField, open]);
2205
- var buttonText = function buttonText(value, displayCurrentLength, currentMark) {
2206
- if (displayCurrentLength) {
2207
- return minutesToDescribedDuration(value);
2208
- }
2209
- if (currentMark) {
2210
- var parts = t(currentMark.label).split(' ');
2211
- if (parts.length > 1) {
2212
- return parts[0] + parts.slice(1).join(' ');
2213
- }
2214
- return parts.join('');
2215
- }
2216
- return '';
2217
- };
2218
-
2219
- // eslint-disable-next-line react-hooks/exhaustive-deps
2220
- var throttledScroll = React.useCallback(throttle(function (newValue) {
2221
- onChangeSliderValue(newValue);
2222
- }, THROTTLE_WAIT_TIME, THROTTLE_OPTIONS), []);
2223
- var onWheel = React.useCallback(function (event) {
2224
- var direction = event.deltaY < 0 ? 1 : -1;
2225
- var newValue = marks[Math.min(Math.max(currentMarkIndex - direction, 0), marks.length - 1)];
2226
- throttledScroll(newValue.value);
2227
- }, [currentMarkIndex, marks, throttledScroll]);
2228
- return /*#__PURE__*/jsxs(Box, {
2229
- onKeyDown: function onKeyDown(event) {
2230
- event.stopPropagation();
2231
- },
2232
- children: [/*#__PURE__*/jsxs(CustomIconButton, {
2233
- isSelected: true,
2234
- onClick: function onClick() {
2235
- setOpen(true);
2236
- },
2237
- onWheel: onWheel,
2238
- ref: setAnchorRef,
2239
- sx: {
2240
- padding: '0px',
2241
- paddingRight: '12px',
2242
- width: '100%!important',
2243
- minWidth: '64px',
2244
- justifyContent: 'space-between'
2245
- },
2246
- tooltipTitle: title,
2247
- variant: "tool",
2248
- children: [icon, /*#__PURE__*/jsx(Typography, {
2249
- sx: {
2250
- fontSize: 12,
2251
- fontWeight: 400,
2252
- textTransform: 'none'
2253
- },
2254
- children: buttonText(value, displayCurrentLength, currentMark)
2255
- })]
2256
- }), !!anchorRef && /*#__PURE__*/jsxs(Menu, {
2257
- anchorEl: anchorRef,
2258
- anchorOrigin: {
2259
- vertical: -15,
2260
- horizontal: 'center'
2261
- },
2262
- onClose: function onClose() {
2263
- return setOpen(false);
2264
- },
2265
- open: open,
2266
- slotProps: {
2267
- backdrop: {
2268
- sx: {
2269
- backgroundColor: 'transparent'
2270
- }
2271
- }
2272
- },
2273
- transformOrigin: {
2274
- vertical: 'bottom',
2275
- horizontal: 'center'
2276
- },
2277
- children: [/*#__PURE__*/jsx(MenuItem, {
2278
- disabled: true,
2279
- sx: {
2280
- fontSize: '12px',
2281
- opacity: 0.67,
2282
- padding: '0px 12px',
2283
- '&.MuiMenuItem-root': {
2284
- minHeight: '30px!important',
2285
- minWidth: 150
2286
- }
2287
- },
2288
- children: title
2289
- }), marks.map(function (mark) {
2290
- var isSelected = (currentMark == null ? void 0 : currentMark.value) === mark.value && !isAutoSelected;
2291
- return /*#__PURE__*/jsx(MenuItem, {
2292
- disabled: allOptionsDisabled,
2293
- onClick: function onClick() {
2294
- if (!isSelected) {
2295
- onChangeSliderValue(mark.value);
2296
- }
2297
- setOpen(false);
2298
- },
2299
- selected: !!isSelected && !displayLengthInputField,
2300
- children: mark.label || mark.text
2301
- }, mark.value);
2302
- }), !!handleAutoClick && /*#__PURE__*/jsx(MenuItem, {
2303
- disabled: allOptionsDisabled || isAutoDisabled,
2304
- onClick: function onClick() {
2305
- handleAutoClick();
2306
- setOpen(false);
2307
- },
2308
- selected: isAutoSelected,
2309
- children: t('timeslider-auto')
2310
- }), !!displayCurrentLength && /*#__PURE__*/jsxs(MenuItem, {
2311
- disabled: disbleUserSetDuration,
2312
- onClick: function onClick() {
2313
- return setDisplayLengthInputField(true);
2314
- },
2315
- sx: {
2316
- maxWidth: '175px'
2317
- },
2318
- children: [!!displayLengthInputField && customLengthSelector, !displayLengthInputField && /*#__PURE__*/jsxs(Box, {
2319
- sx: {
2320
- flexDirection: 'column',
2321
- display: 'flex',
2322
- flexGrow: 1
2323
- },
2324
- children: [/*#__PURE__*/jsx(CardHeader, {
2325
- slotProps: {
2326
- title: {
2327
- fontSize: 12
2328
- }
2329
- },
2330
- sx: {
2331
- height: 2,
2332
- padding: 0,
2333
- color: 'geowebColors.greys.accessible'
2334
- },
2335
- title: t(customFieldHeader)
2336
- }), /*#__PURE__*/jsxs(Box, {
2337
- sx: {
2338
- flexDirection: 'row',
2339
- display: 'flex',
2340
- justifyContent: 'space-between',
2341
- flexGrow: 1,
2342
- paddingTop: 0.5
2343
- },
2344
- children: [/*#__PURE__*/jsx(Typography, {
2345
- sx: {
2346
- fontSize: 14,
2347
- textTransform: 'none',
2348
- lineHeight: 2
2349
- },
2350
- children: minutesToDescribedDuration(value)
2351
- }), /*#__PURE__*/jsx(CustomTooltip, {
2352
- title: t('timeslider-edit'),
2353
- children: /*#__PURE__*/jsx("span", {
2354
- children: /*#__PURE__*/jsx(CustomIconButton, {
2355
- "aria-label": "edit animation option",
2356
- "data-testid": "editAnimationOption",
2357
- children: /*#__PURE__*/jsx(Edit, {})
2358
- })
2359
- })
2360
- })]
2361
- })]
2362
- })]
2363
- })]
2364
- })]
2365
- });
2366
- };
2367
-
2368
- /* *
2369
- * Licensed under the Apache License, Version 2.0 (the "License");
2370
- * you may not use this file except in compliance with the License.
2371
- * You may obtain a copy of the License at
2372
- *
2373
- * http://www.apache.org/licenses/LICENSE-2.0
2374
- *
2375
- * Unless required by applicable law or agreed to in writing, software
2376
- * distributed under the License is distributed on an "AS IS" BASIS,
2377
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2378
- * See the License for the specific language governing permissions and
2379
- * limitations under the License.
2380
- *
2381
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2382
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
2383
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2384
- * */
2385
-
2386
- var marks$2 = [{
2387
- value: AnimationLength.Minutes15,
2388
- text: 'timeslider-min',
2389
- count: 15
2390
- }, {
2391
- value: AnimationLength.Minutes30,
2392
- text: 'timeslider-min',
2393
- count: 30
2394
- }, {
2395
- value: AnimationLength.Hours1,
2396
- text: 'timeslider-hour',
2397
- count: 1
2398
- }, {
2399
- value: AnimationLength.Hours2,
2400
- text: 'timeslider-hour',
2401
- count: 2
2402
- }, {
2403
- value: AnimationLength.Hours3,
2404
- text: 'timeslider-hour',
2405
- count: 3
2406
- }, {
2407
- value: AnimationLength.Hours6,
2408
- text: 'timeslider-hour',
2409
- count: 6
2410
- }, {
2411
- value: AnimationLength.Hours12,
2412
- text: 'timeslider-hour',
2413
- count: 12
2414
- }, {
2415
- value: AnimationLength.Hours24,
2416
- text: 'timeslider-hour',
2417
- count: 24
2418
- }].sort(function (ta, tb) {
2419
- return tb.value - ta.value;
2420
- });
2421
- var AnimationLengthButton = function AnimationLengthButton(_ref) {
2422
- var _ref$disabled = _ref.disabled,
2423
- disabled = _ref$disabled === void 0 ? false : _ref$disabled,
2424
- _ref$animationLength = _ref.animationLength,
2425
- animationLength = _ref$animationLength === void 0 ? AnimationLength.Hours1 : _ref$animationLength,
2426
- _ref$isAuto = _ref.isAuto,
2427
- isAuto = _ref$isAuto === void 0 ? false : _ref$isAuto,
2428
- layerHasTimeStep = _ref.layerHasTimeStep,
2429
- onChangeAnimationLength = _ref.onChangeAnimationLength,
2430
- toggleAnimationLengthAuto = _ref.toggleAnimationLengthAuto;
2431
- var _useTimesliderTransla = useTimesliderTranslation(),
2432
- t = _useTimesliderTransla.t;
2433
- var translatedMarks = marks$2.map(function (mark) {
2434
- return Object.assign({}, mark, {
2435
- label: mark.count + " " + t(mark.text)
2436
- });
2437
- });
2438
- var onChangeSliderValue = function onChangeSliderValue(newSliderValue) {
2439
- var newLength = newSliderValue ? Math.round(newSliderValue) : 0;
2440
- onChangeAnimationLength == null || onChangeAnimationLength(newLength);
2441
- };
2442
- var _useState = useState(false),
2443
- open = _useState[0],
2444
- setOpen = _useState[1];
2445
- return /*#__PURE__*/jsx(TimeSliderMenu, {
2446
- allOptionsDisabled: disabled,
2447
- displayCurrentLength: true,
2448
- handleAutoClick: toggleAnimationLengthAuto,
2449
- icon: /*#__PURE__*/jsx(Animation, {
2450
- "data-testid": "animationLengthButton"
2451
- }),
2452
- isAutoDisabled: !layerHasTimeStep,
2453
- isAutoSelected: isAuto,
2454
- marks: translatedMarks,
2455
- onChangeSliderValue: onChangeSliderValue,
2456
- open: open,
2457
- setOpen: setOpen,
2458
- title: t('timeslider-animation'),
2459
- value: animationLength
2460
- });
2461
- };
2462
-
2463
- /* *
2464
- * Licensed under the Apache License, Version 2.0 (the "License");
2465
- * you may not use this file except in compliance with the License.
2466
- * You may obtain a copy of the License at
2467
- *
2468
- * http://www.apache.org/licenses/LICENSE-2.0
2469
- *
2470
- * Unless required by applicable law or agreed to in writing, software
2471
- * distributed under the License is distributed on an "AS IS" BASIS,
2472
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2473
- * See the License for the specific language governing permissions and
2474
- * limitations under the License.
2475
- *
2476
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2477
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
2478
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2479
- * */
2480
-
2481
- var AutoUpdateButton = function AutoUpdateButton(_ref) {
2482
- var _ref$toggleAutoUpdate = _ref.toggleAutoUpdate,
2483
- toggleAutoUpdate = _ref$toggleAutoUpdate === void 0 ? function () {} : _ref$toggleAutoUpdate,
2484
- _ref$isAutoUpdating = _ref.isAutoUpdating,
2485
- isAutoUpdating = _ref$isAutoUpdating === void 0 ? false : _ref$isAutoUpdating,
2486
- _ref$disabled = _ref.disabled,
2487
- disabled = _ref$disabled === void 0 ? false : _ref$disabled;
2488
- var _useTimesliderTransla = useTimesliderTranslation(),
2489
- t = _useTimesliderTransla.t;
2490
- return /*#__PURE__*/jsx(CustomIconButton, {
2491
- "data-testid": "autoUpdateButton",
2492
- disabled: disabled,
2493
- isSelected: isAutoUpdating,
2494
- onClick: function onClick() {
2495
- return toggleAutoUpdate();
2496
- },
2497
- tooltipTitle: isAutoUpdating ? t('timeslider-auto-update-on') : t('timeslider-auto-update-off'),
2498
- variant: "tool",
2499
- children: isAutoUpdating ? /*#__PURE__*/jsx(AutoUpdateActive, {
2500
- "data-testid": "auto-update-svg-on"
2501
- }) : /*#__PURE__*/jsx(AutoUpdateInActive, {
2502
- "data-testid": "auto-update-svg-off"
2503
- })
2504
- });
2505
- };
2506
-
2507
- /* *
2508
- * Licensed under the Apache License, Version 2.0 (the "License");
2509
- * you may not use this file except in compliance with the License.
2510
- * You may obtain a copy of the License at
2511
- *
2512
- * http://www.apache.org/licenses/LICENSE-2.0
2513
- *
2514
- * Unless required by applicable law or agreed to in writing, software
2515
- * distributed under the License is distributed on an "AS IS" BASIS,
2516
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2517
- * See the License for the specific language governing permissions and
2518
- * limitations under the License.
2519
- *
2520
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2521
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
2522
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2523
- * */
2524
-
2525
- var BackwardForwardStepButton = function BackwardForwardStepButton(_ref) {
2526
- var isForwardStep = _ref.isForwardStep,
2527
- isDisabled = _ref.isDisabled,
2528
- _ref$onClickBFButton = _ref.onClickBFButton,
2529
- onClickBFButton = _ref$onClickBFButton === void 0 ? function () {} : _ref$onClickBFButton;
2530
- // Added renderCounter for testing and performance purposes
2531
- renderCounter.count(BackwardForwardStepButton.name);
2532
- var _useTimesliderTransla = useTimesliderTranslation(),
2533
- t = _useTimesliderTransla.t;
2534
- return /*#__PURE__*/jsx(CustomIconButton, {
2535
- "aria-label": isForwardStep ? 'forward' : 'backward',
2536
- "data-testid": isForwardStep ? 'stepForwardButton' : 'stepBackwardButton',
2537
- disabled: isDisabled,
2538
- onClick: onClickBFButton,
2539
- tooltipTitle: isForwardStep ? t('timeslider-forward') : t('timeslider-backward'),
2540
- variant: "tool",
2541
- children: isForwardStep ? /*#__PURE__*/jsx(StepForward, {
2542
- "data-testid": "step-forward-svg-path"
2543
- }) : /*#__PURE__*/jsx(StepBackward, {
2544
- "data-testid": "step-backward-svg-path"
2545
- })
2546
- });
2547
- };
2548
-
2549
- /* *
2550
- * Licensed under the Apache License, Version 2.0 (the "License");
2551
- * you may not use this file except in compliance with the License.
2552
- * You may obtain a copy of the License at
2553
- *
2554
- * http://www.apache.org/licenses/LICENSE-2.0
2555
- *
2556
- * Unless required by applicable law or agreed to in writing, software
2557
- * distributed under the License is distributed on an "AS IS" BASIS,
2558
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2559
- * See the License for the specific language governing permissions and
2560
- * limitations under the License.
2561
- *
2562
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2563
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
2564
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2565
- * */
2566
-
2567
- var NowButton = function NowButton(_ref) {
2568
- var _ref$onSetNow = _ref.onSetNow,
2569
- onSetNow = _ref$onSetNow === void 0 ? function () {} : _ref$onSetNow,
2570
- _ref$disabled = _ref.disabled,
2571
- disabled = _ref$disabled === void 0 ? false : _ref$disabled;
2572
- var _useTimesliderTransla = useTimesliderTranslation(),
2573
- t = _useTimesliderTransla.t;
2574
- return /*#__PURE__*/jsx(CustomIconButton, {
2575
- "aria-label": "now",
2576
- "data-testid": "nowButtonTooltip",
2577
- disabled: disabled,
2578
- onClick: function onClick() {
2579
- return onSetNow();
2580
- },
2581
- tooltipTitle: t('timeslider-now'),
2582
- variant: "tool",
2583
- children: /*#__PURE__*/jsx(Now, {
2584
- "data-testid": "now-svg"
2585
- })
2586
- });
2587
- };
2588
-
2589
- /* *
2590
- * Licensed under the Apache License, Version 2.0 (the "License");
2591
- * you may not use this file except in compliance with the License.
2592
- * You may obtain a copy of the License at
2593
- *
2594
- * http://www.apache.org/licenses/LICENSE-2.0
2595
- *
2596
- * Unless required by applicable law or agreed to in writing, software
2597
- * distributed under the License is distributed on an "AS IS" BASIS,
2598
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2599
- * See the License for the specific language governing permissions and
2600
- * limitations under the License.
2601
- *
2602
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2603
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
2604
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2605
- * */
2606
-
2607
- var PlayButton = function PlayButton(_ref) {
2608
- var isAnimating = _ref.isAnimating,
2609
- isDisabled = _ref.isDisabled,
2610
- _ref$onTogglePlayButt = _ref.onTogglePlayButton,
2611
- onTogglePlayButton = _ref$onTogglePlayButt === void 0 ? function () {} : _ref$onTogglePlayButt;
2612
- var onTogglePlay = function onTogglePlay() {
2613
- onTogglePlayButton();
2614
- };
2615
- var _useTimesliderTransla = useTimesliderTranslation(),
2616
- t = _useTimesliderTransla.t;
2617
- return /*#__PURE__*/jsx(CustomIconButton, {
2618
- "data-testid": "playButton",
2619
- disabled: isDisabled,
2620
- isSelected: isAnimating,
2621
- onClick: onTogglePlay,
2622
- tooltipTitle: isAnimating ? t('timeslider-pause') : t('timeslider-play'),
2623
- variant: "tool",
2624
- children: isAnimating ? /*#__PURE__*/jsx(Pause, {
2625
- "data-testid": "pause-svg-path"
2626
- }) : /*#__PURE__*/jsx(Play, {
2627
- "data-testid": "play-svg-path"
2628
- })
2629
- });
2630
- };
2631
-
2632
- /* *
2633
- * Licensed under the Apache License, Version 2.0 (the "License");
2634
- * you may not use this file except in compliance with the License.
2635
- * You may obtain a copy of the License at
2636
- *
2637
- * http://www.apache.org/licenses/LICENSE-2.0
2638
- *
2639
- * Unless required by applicable law or agreed to in writing, software
2640
- * distributed under the License is distributed on an "AS IS" BASIS,
2641
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2642
- * See the License for the specific language governing permissions and
2643
- * limitations under the License.
2644
- *
2645
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2646
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
2647
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2648
- * */
2649
-
2650
- var ControlButtons = function ControlButtons(_ref) {
2651
- var backwardBtn = _ref.backwardBtn,
2652
- forwardBtn = _ref.forwardBtn,
2653
- playBtn = _ref.playBtn,
2654
- nowBtn = _ref.nowBtn,
2655
- autoUpdateBtn = _ref.autoUpdateBtn;
2656
- return /*#__PURE__*/jsxs(Fragment, {
2657
- children: [/*#__PURE__*/jsx(Grid, {
2658
- children: backwardBtn || /*#__PURE__*/jsx(BackwardForwardStepButton, {
2659
- isForwardStep: false
2660
- })
2661
- }), /*#__PURE__*/jsx(Grid, {
2662
- children: forwardBtn || /*#__PURE__*/jsx(BackwardForwardStepButton, {
2663
- isForwardStep: true
2664
- })
2665
- }), /*#__PURE__*/jsx(Grid, {
2666
- children: playBtn || /*#__PURE__*/jsx(PlayButton, {})
2667
- }), /*#__PURE__*/jsx(Grid, {
2668
- children: nowBtn || /*#__PURE__*/jsx(NowButton, {})
2669
- }), /*#__PURE__*/jsx(Grid, {
2670
- children: autoUpdateBtn || /*#__PURE__*/jsx(AutoUpdateButton, {})
2671
- })]
2672
- });
2673
- };
2674
-
2675
- /* *
2676
- * Licensed under the Apache License, Version 2.0 (the "License");
2677
- * you may not use this file except in compliance with the License.
2678
- * You may obtain a copy of the License at
2679
- *
2680
- * http://www.apache.org/licenses/LICENSE-2.0
2681
- *
2682
- * Unless required by applicable law or agreed to in writing, software
2683
- * distributed under the License is distributed on an "AS IS" BASIS,
2684
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2685
- * See the License for the specific language governing permissions and
2686
- * limitations under the License.
2687
- *
2688
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2689
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
2690
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2691
- * */
2692
-
2693
- var SpeedButton = function SpeedButton(_ref) {
2694
- var animationDelay = _ref.animationDelay,
2695
- setMapAnimationDelay = _ref.setMapAnimationDelay;
2696
- var sorted = [].concat(speedFactors).sort(function (sa, sb) {
2697
- return sb - sa;
2698
- });
2699
- var marks = sorted.map(function (speedFactor) {
2700
- return {
2701
- value: getSpeedDelay(speedFactor),
2702
- text: "x" + speedFactor,
2703
- label: "x" + speedFactor
2704
- };
2705
- });
2706
- var _useTimesliderTransla = useTimesliderTranslation(),
2707
- t = _useTimesliderTransla.t;
2708
- var _useState = useState(false),
2709
- open = _useState[0],
2710
- setOpen = _useState[1];
2711
- return /*#__PURE__*/jsx(TimeSliderMenu, {
2712
- icon: /*#__PURE__*/jsx(Speed, {}),
2713
- marks: marks,
2714
- onChangeSliderValue: function onChangeSliderValue(markValue) {
2715
- setMapAnimationDelay(markValue);
2716
- },
2717
- open: open,
2718
- setOpen: setOpen,
2719
- title: t('timeslider-speed'),
2720
- value: animationDelay
2721
- });
2722
- };
2723
-
2724
- /* *
2725
- * Licensed under the Apache License, Version 2.0 (the "License");
2726
- * you may not use this file except in compliance with the License.
2727
- * You may obtain a copy of the License at
2728
- *
2729
- * http://www.apache.org/licenses/LICENSE-2.0
2730
- *
2731
- * Unless required by applicable law or agreed to in writing, software
2732
- * distributed under the License is distributed on an "AS IS" BASIS,
2733
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2734
- * See the License for the specific language governing permissions and
2735
- * limitations under the License.
2736
- *
2737
- * Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2738
- * Copyright 2024 - Finnish Meteorological Institute (FMI)
2739
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2740
- * */
2741
-
2742
- var TimeSpanButtonCustomSelect = function TimeSpanButtonCustomSelect(_ref) {
2743
- var timeSliderSpan = _ref.timeSliderSpan,
2744
- setOpen = _ref.setOpen,
2745
- onChangeSliderValue = _ref.onChangeSliderValue;
2746
- var _useTimesliderTransla = useTimesliderTranslation(),
2747
- t = _useTimesliderTransla.t;
2748
- var _React$useState = React.useState(timeSliderSpan / getLargestTimeUnit(timeSliderSpan)),
2749
- selectedTimeValue = _React$useState[0],
2750
- setSelectedTimeValue = _React$useState[1];
2751
- var _React$useState2 = React.useState(getLargestTimeUnit(timeSliderSpan).toString()),
2752
- selectedTimeResolution = _React$useState2[0],
2753
- setSelectedTimeResolution = _React$useState2[1];
2754
- var _React$useState3 = React.useState(true),
2755
- isANumber = _React$useState3[0],
2756
- setIsANumber = _React$useState3[1];
2757
- return /*#__PURE__*/jsx(Box, {
2758
- children: /*#__PURE__*/jsxs(FormControl, {
2759
- onKeyDown: function onKeyDown(event) {
2760
- event.stopPropagation();
2761
- },
2762
- size: "small",
2763
- sx: {
2764
- flexDirection: 'row',
2765
- display: 'flex'
2766
- },
2767
- variant: "standard",
2768
- children: [/*#__PURE__*/jsx(TextField, {
2769
- autoFocus: true,
2770
- color: isANumber ? 'primary' : 'warning',
2771
- label: t('timeslider-span'),
2772
- onBlur: function onBlur() {
2773
- onChangeSliderValue(selectedTimeValue * Number(selectedTimeResolution));
2774
- },
2775
- onChange: function onChange(e) {
2776
- if (!isNaN(+e.target.value)) {
2777
- setIsANumber(true);
2778
- setSelectedTimeValue(Number(e.target.value));
2779
- } else {
2780
- setIsANumber(false);
2781
- }
2782
- },
2783
- onKeyDown: function onKeyDown(e) {
2784
- if (e.key === 'Enter' || e.key === 'Escape') {
2785
- onChangeSliderValue(selectedTimeValue * Number(selectedTimeResolution));
2786
- setOpen(false);
2787
- }
2788
- },
2789
- size: "small",
2790
- slotProps: {
2791
- htmlInput: {
2792
- maxLength: 4,
2793
- 'aria-label': 'custom-input'
2794
- }
2795
- },
2796
- value: Math.round(selectedTimeValue * 100) / 100,
2797
- variant: "standard"
2798
- }), /*#__PURE__*/jsx(Box, {
2799
- sx: {
2800
- alignContent: 'end'
2801
- },
2802
- children: /*#__PURE__*/jsxs(Select, {
2803
- "aria-label": "time-resolution-selector",
2804
- defaultValue: "h",
2805
- onChange: function onChange(e) {
2806
- setSelectedTimeResolution(e.target.value);
2807
- onChangeSliderValue(selectedTimeValue * Number(e.target.value));
2808
- setOpen(false);
2809
- },
2810
- size: "small",
2811
- tabIndex: -1,
2812
- value: selectedTimeResolution,
2813
- children: [/*#__PURE__*/jsx(MenuItem, {
2814
- value: TimeInMinutes.YEAR,
2815
- children: t('years')
2816
- }), /*#__PURE__*/jsx(MenuItem, {
2817
- value: TimeInMinutes.MONTH,
2818
- children: t('months')
2819
- }), /*#__PURE__*/jsx(MenuItem, {
2820
- value: TimeInMinutes.WEEK,
2821
- children: t('weeks')
2822
- }), /*#__PURE__*/jsx(MenuItem, {
2823
- value: TimeInMinutes.DAY,
2824
- children: t('days')
2825
- }), /*#__PURE__*/jsx(MenuItem, {
2826
- value: TimeInMinutes.HOUR,
2827
- children: t('hours')
2828
- }), /*#__PURE__*/jsx(MenuItem, {
2829
- value: TimeInMinutes.MINUTE,
2830
- children: t('minutes')
2831
- })]
2832
- })
2833
- })]
2834
- })
2835
- });
2836
- };
2837
-
2838
- /* *
2839
- * Licensed under the Apache License, Version 2.0 (the "License");
2840
- * you may not use this file except in compliance with the License.
2841
- * You may obtain a copy of the License at
2842
- *
2843
- * http://www.apache.org/licenses/LICENSE-2.0
2844
- *
2845
- * Unless required by applicable law or agreed to in writing, software
2846
- * distributed under the License is distributed on an "AS IS" BASIS,
2847
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2848
- * See the License for the specific language governing permissions and
2849
- * limitations under the License.
2850
- *
2851
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2852
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
2853
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2854
- * */
2855
-
2856
- var marks$1 = [{
2857
- value: 60,
2858
- text: 'timeslider-hour',
2859
- count: 1
2860
- }, {
2861
- value: 3 * 60,
2862
- text: 'timeslider-hour',
2863
- count: 3
2864
- }, {
2865
- value: 6 * 60,
2866
- text: 'timeslider-hour',
2867
- count: 6
2868
- }, {
2869
- value: 12 * 60,
2870
- text: 'timeslider-hour',
2871
- count: 12
2872
- }, {
2873
- value: 24 * 60,
2874
- text: 'timeslider-hour',
2875
- count: 24
2876
- }, {
2877
- value: 2 * 24 * 60,
2878
- text: 'timeslider-hour',
2879
- count: 48
2880
- }, {
2881
- value: 7 * 24 * 60,
2882
- text: 'timeslider-week',
2883
- count: 1
2884
- }, {
2885
- value: 2 * 7 * 24 * 60,
2886
- text: 'timeslider-weeks',
2887
- count: 2
2888
- }, {
2889
- value: 30 * 24 * 60,
2890
- text: 'timeslider-month',
2891
- count: 1
2892
- }, {
2893
- value: 3 * 30 * 24 * 60,
2894
- text: 'timeslider-months',
2895
- count: 3
2896
- }, {
2897
- value: 365 * 24 * 60,
2898
- text: 'timeslider-year',
2899
- count: 1
2900
- }].sort(function (ta, tb) {
2901
- return tb.value - ta.value;
2902
- });
2903
- var TimeSpanButton = function TimeSpanButton(_ref) {
2904
- var _ref$timeSliderSpan = _ref.timeSliderSpan,
2905
- timeSliderSpan = _ref$timeSliderSpan === void 0 ? defaultTimeSpan : _ref$timeSliderSpan,
2906
- _ref$disabled = _ref.disabled,
2907
- disabled = _ref$disabled === void 0 ? false : _ref$disabled,
2908
- _ref$onChangeSliderVa = _ref.onChangeSliderValue,
2909
- onChangeSliderValue = _ref$onChangeSliderVa === void 0 ? function () {} : _ref$onChangeSliderVa,
2910
- onToggleTimeSpan = _ref.onToggleTimeSpan,
2911
- isTimeSpanAuto = _ref.isTimeSpanAuto,
2912
- _ref$isOpenByDefault = _ref.isOpenByDefault,
2913
- isOpenByDefault = _ref$isOpenByDefault === void 0 ? false : _ref$isOpenByDefault,
2914
- _ref$layerHasTimeStep = _ref.layerHasTimeStep,
2915
- layerHasTimeStep = _ref$layerHasTimeStep === void 0 ? false : _ref$layerHasTimeStep;
2916
- var _useTimesliderTransla = useTimesliderTranslation(),
2917
- t = _useTimesliderTransla.t;
2918
- var translatedMarks = marks$1.map(function (mark) {
2919
- return Object.assign({}, mark, {
2920
- label: mark.count + " " + t(mark.text)
2921
- });
2922
- });
2923
- var _useState = useState(isOpenByDefault),
2924
- open = _useState[0],
2925
- setOpen = _useState[1];
2926
- return /*#__PURE__*/jsx(TimeSliderMenu, {
2927
- allOptionsDisabled: disabled,
2928
- customFieldHeader: t('timeslider-span'),
2929
- customLengthSelector: /*#__PURE__*/jsx(TimeSpanButtonCustomSelect, {
2930
- onChangeSliderValue: onChangeSliderValue,
2931
- setOpen: setOpen,
2932
- timeSliderSpan: timeSliderSpan
2933
- }),
2934
- disbleUserSetDuration: false,
2935
- displayCurrentLength: true,
2936
- handleAutoClick: onToggleTimeSpan,
2937
- icon: /*#__PURE__*/jsx(Clock, {}),
2938
- isAutoDisabled: !layerHasTimeStep,
2939
- isAutoSelected: isTimeSpanAuto,
2940
- marks: translatedMarks,
2941
- onChangeSliderValue: onChangeSliderValue,
2942
- open: open,
2943
- setOpen: setOpen,
2944
- title: t('timeslider-time-span'),
2945
- value: timeSliderSpan
2946
- });
2947
- };
2948
-
2949
- /* *
2950
- * Licensed under the Apache License, Version 2.0 (the "License");
2951
- * you may not use this file except in compliance with the License.
2952
- * You may obtain a copy of the License at
2953
- *
2954
- * http://www.apache.org/licenses/LICENSE-2.0
2955
- *
2956
- * Unless required by applicable law or agreed to in writing, software
2957
- * distributed under the License is distributed on an "AS IS" BASIS,
2958
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2959
- * See the License for the specific language governing permissions and
2960
- * limitations under the License.
2961
- *
2962
- * Copyright 2020 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
2963
- * Copyright 2020 - Finnish Meteorological Institute (FMI)
2964
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
2965
- * */
2966
-
2967
- var marks = [{
2968
- value: 1,
2969
- text: 'timeslider-min',
2970
- count: 1
2971
- }, {
2972
- value: 2,
2973
- text: 'timeslider-min',
2974
- count: 2
2975
- }, {
2976
- value: 5,
2977
- text: 'timeslider-min',
2978
- count: 5
2979
- }, {
2980
- value: 10,
2981
- text: 'timeslider-min',
2982
- count: 10
2983
- }, {
2984
- value: 15,
2985
- text: 'timeslider-min',
2986
- count: 15
2987
- }, {
2988
- value: 30,
2989
- text: 'timeslider-min',
2990
- count: 30
2991
- }, {
2992
- value: 60,
2993
- text: 'timeslider-hour',
2994
- count: 1
2995
- }, {
2996
- value: 120,
2997
- text: 'timeslider-hour',
2998
- count: 2
2999
- }, {
3000
- value: 180,
3001
- text: 'timeslider-hour',
3002
- count: 3
3003
- }, {
3004
- value: 360,
3005
- text: 'timeslider-hour',
3006
- count: 6
3007
- }, {
3008
- value: 720,
3009
- text: 'timeslider-hour',
3010
- count: 12
3011
- }, {
3012
- value: 1440,
3013
- text: 'timeslider-hour',
3014
- count: 24
3015
- }, {
3016
- value: 2880,
3017
- text: 'timeslider-hour',
3018
- count: 48
3019
- }, {
3020
- value: 4320,
3021
- text: 'timeslider-hour',
3022
- count: 72
3023
- }, {
3024
- value: 10080,
3025
- text: 'timeslider-week',
3026
- count: 1
3027
- }, {
3028
- value: 20160,
3029
- text: 'timeslider-weeks',
3030
- count: 2
3031
- }, {
3032
- value: 43200,
3033
- text: 'timeslider-month',
3034
- count: 1
3035
- }, {
3036
- value: 87600,
3037
- text: 'timeslider-months',
3038
- count: 2
3039
- }, {
3040
- value: 262800,
3041
- text: 'timeslider-months',
3042
- count: 6
3043
- }, {
3044
- value: 525600,
3045
- text: 'timeslider-year',
3046
- count: 1
3047
- }, {
3048
- value: 5256000,
3049
- text: 'timeslider-years',
3050
- count: 10
3051
- }].sort(function (ta, tb) {
3052
- return tb.value - ta.value;
3053
- });
3054
- var TimeStepButton = function TimeStepButton(_ref) {
3055
- var _ref$timeStep = _ref.timeStep,
3056
- timeStep = _ref$timeStep === void 0 ? marks[0].value : _ref$timeStep,
3057
- _ref$disabled = _ref.disabled,
3058
- disabled = _ref$disabled === void 0 ? false : _ref$disabled,
3059
- _ref$isTimestepAuto = _ref.isTimestepAuto,
3060
- isTimestepAuto = _ref$isTimestepAuto === void 0 ? false : _ref$isTimestepAuto,
3061
- onChangeTimeStep = _ref.onChangeTimeStep,
3062
- _ref$onToggleTimestep = _ref.onToggleTimestepAuto,
3063
- onToggleTimestepAuto = _ref$onToggleTimestep === void 0 ? function () {} : _ref$onToggleTimestep,
3064
- _ref$isOpenByDefault = _ref.isOpenByDefault,
3065
- isOpenByDefault = _ref$isOpenByDefault === void 0 ? false : _ref$isOpenByDefault,
3066
- timeStepFromLayer = _ref.timeStepFromLayer;
3067
- var _useTimesliderTransla = useTimesliderTranslation(),
3068
- t = _useTimesliderTransla.t;
3069
- var translatedMarks = marks.map(function (mark) {
3070
- return Object.assign({}, mark, {
3071
- label: mark.count + " " + t(mark.text)
3072
- });
3073
- });
3074
- var onMenuItemClick = function onMenuItemClick(markValue) {
3075
- if (isTimestepAuto) {
3076
- onToggleTimestepAuto();
3077
- }
3078
- onChangeTimeStep(markValue);
3079
- };
3080
- var handleToggleTimeStep = function handleToggleTimeStep() {
3081
- if (isTimestepAuto) {
3082
- return;
3083
- }
3084
- onToggleTimestepAuto();
3085
- timeStepFromLayer && onChangeTimeStep(timeStepFromLayer);
3086
- };
3087
- var layerHasTimeStep = Boolean(timeStepFromLayer);
3088
- renderCounter.count(TimeStepButton.name);
3089
- var _useState = useState(isOpenByDefault),
3090
- open = _useState[0],
3091
- setOpen = _useState[1];
3092
- return /*#__PURE__*/jsx(TimeSliderMenu, {
3093
- allOptionsDisabled: disabled,
3094
- displayCurrentLength: true,
3095
- handleAutoClick: handleToggleTimeStep,
3096
- icon: /*#__PURE__*/jsx(FastForward, {
3097
- "data-testid": "timeStepButton"
3098
- }),
3099
- isAutoDisabled: !layerHasTimeStep,
3100
- isAutoSelected: isTimestepAuto,
3101
- marks: translatedMarks,
3102
- onChangeSliderValue: onMenuItemClick,
3103
- open: open,
3104
- setOpen: setOpen,
3105
- title: t('timeslider-time-step'),
3106
- value: timeStep || translatedMarks[0].value
3107
- });
3108
- };
3109
-
3110
- /* *
3111
- * Licensed under the Apache License, Version 2.0 (the "License");
3112
- * you may not use this file except in compliance with the License.
3113
- * You may obtain a copy of the License at
3114
- *
3115
- * http://www.apache.org/licenses/LICENSE-2.0
3116
- *
3117
- * Unless required by applicable law or agreed to in writing, software
3118
- * distributed under the License is distributed on an "AS IS" BASIS,
3119
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3120
- * See the License for the specific language governing permissions and
3121
- * limitations under the License.
3122
- *
3123
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3124
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
3125
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
3126
- * */
3127
-
3128
- var OptionsMenu = function OptionsMenu(_ref) {
3129
- var speedBtn = _ref.speedBtn,
3130
- timeSpanBtn = _ref.timeSpanBtn,
3131
- timeStepBtn = _ref.timeStepBtn,
3132
- animationLengthBtn = _ref.animationLengthBtn;
3133
- return /*#__PURE__*/jsxs(Fragment, {
3134
- children: [/*#__PURE__*/jsx(Grid, {
3135
- size: {
3136
- xs: 'auto'
3137
- },
3138
- children: timeSpanBtn || /*#__PURE__*/jsx(TimeSpanButton, {
3139
- disabled: false,
3140
- isTimeSpanAuto: false,
3141
- layerHasTimeStep: false,
3142
- onChangeSliderValue: function onChangeSliderValue() {},
3143
- onToggleTimeSpan: function onToggleTimeSpan() {},
3144
- timeSliderSpan: 0
3145
- })
3146
- }), /*#__PURE__*/jsx(Grid, {
3147
- size: {
3148
- xs: 'auto'
3149
- },
3150
- children: animationLengthBtn || /*#__PURE__*/jsx(AnimationLengthButton, {
3151
- onChangeAnimationLength: function onChangeAnimationLength() {},
3152
- toggleAnimationLengthAuto: function toggleAnimationLengthAuto() {}
3153
- })
3154
- }), /*#__PURE__*/jsx(Grid, {
3155
- size: {
3156
- xs: 'auto'
3157
- },
3158
- children: timeStepBtn || /*#__PURE__*/jsx(TimeStepButton, {
3159
- isTimestepAuto: false,
3160
- onChangeTimeStep: function onChangeTimeStep() {}
3161
- })
3162
- }), /*#__PURE__*/jsx(Grid, {
3163
- size: {
3164
- xs: 'auto'
3165
- },
3166
- children: speedBtn || /*#__PURE__*/jsx(SpeedButton, {
3167
- animationDelay: defaultAnimationDelayAtStart,
3168
- setMapAnimationDelay: function setMapAnimationDelay() {}
3169
- })
3170
- })]
3171
- });
3172
- };
3173
-
3174
- /* *
3175
- * Licensed under the Apache License, Version 2.0 (the "License");
3176
- * you may not use this file except in compliance with the License.
3177
- * You may obtain a copy of the License at
3178
- *
3179
- * http://www.apache.org/licenses/LICENSE-2.0
3180
- *
3181
- * Unless required by applicable law or agreed to in writing, software
3182
- * distributed under the License is distributed on an "AS IS" BASIS,
3183
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3184
- * See the License for the specific language governing permissions and
3185
- * limitations under the License.
3186
- *
3187
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3188
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
3189
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
3190
- * */
3191
-
3192
- var OptionsMenuButton = function OptionsMenuButton(_ref) {
3193
- var speedBtn = _ref.speedBtn,
3194
- timeStepBtn = _ref.timeStepBtn,
3195
- timeSpanBtn = _ref.timeSpanBtn,
3196
- animationLengthBtn = _ref.animationLengthBtn,
3197
- _ref$isOpenByDefault = _ref.isOpenByDefault,
3198
- isOpenByDefault = _ref$isOpenByDefault === void 0 ? false : _ref$isOpenByDefault;
3199
- var _useState = useState(null),
3200
- anchorEl = _useState[0],
3201
- setAnchorEl = _useState[1];
3202
- var _useState2 = useState(false),
3203
- open = _useState2[0],
3204
- setOpen = _useState2[1];
3205
- var _useTimesliderTransla = useTimesliderTranslation(),
3206
- t = _useTimesliderTransla.t;
3207
- useEffect(function () {
3208
- if (anchorEl && isOpenByDefault) {
3209
- setOpen(true);
3210
- }
3211
- }, [anchorEl, isOpenByDefault]);
3212
- return /*#__PURE__*/jsxs("div", {
3213
- children: [/*#__PURE__*/jsx(CustomIconButton, {
3214
- "aria-label": "animation options",
3215
- "data-testid": "optionsMenuButton",
3216
- isSelected: open,
3217
- onClick: function onClick() {
3218
- setOpen(!open);
3219
- },
3220
- ref: function ref(_ref2) {
3221
- setAnchorEl(_ref2);
3222
- },
3223
- tooltipProps: {
3224
- title: t('timeslider-animation-options'),
3225
- placement: 'bottom'
3226
- },
3227
- variant: "tool",
3228
- children: /*#__PURE__*/jsx(Options, {})
3229
- }), /*#__PURE__*/jsx(Popper, {
3230
- anchorEl: anchorEl,
3231
- "data-testid": "optionsMenuPopOver",
3232
- open: open,
3233
- placement: "top-start",
3234
- sx: {
3235
- zIndex: 10
3236
- },
3237
- children: /*#__PURE__*/jsx(Paper, {
3238
- elevation: 3,
3239
- sx: {
3240
- position: 'relative',
3241
- top: '-2rem'
3242
- },
3243
- children: /*#__PURE__*/jsx(Grid, {
3244
- container: true,
3245
- spacing: 1,
3246
- sx: {
3247
- padding: '10px'
3248
- },
3249
- children: /*#__PURE__*/jsx(OptionsMenu, {
3250
- animationLengthBtn: animationLengthBtn,
3251
- speedBtn: speedBtn,
3252
- timeSpanBtn: timeSpanBtn,
3253
- timeStepBtn: timeStepBtn
3254
- })
3255
- })
3256
- })
3257
- })]
3258
- });
3259
- };
3260
-
3261
- /* *
3262
- * Licensed under the Apache License, Version 2.0 (the "License");
3263
- * you may not use this file except in compliance with the License.
3264
- * You may obtain a copy of the License at
3265
- *
3266
- * http://www.apache.org/licenses/LICENSE-2.0
3267
- *
3268
- * Unless required by applicable law or agreed to in writing, software
3269
- * distributed under the License is distributed on an "AS IS" BASIS,
3270
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3271
- * See the License for the specific language governing permissions and
3272
- * limitations under the License.
3273
- *
3274
- * Copyright 2020 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3275
- * Copyright 2020 - Finnish Meteorological Institute (FMI)
3276
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
3277
- * */
3278
-
3279
- var TimeSliderButtons = function TimeSliderButtons(_ref) {
3280
- var optionsMenuBtn = _ref.optionsMenuBtn,
3281
- playBtn = _ref.playBtn,
3282
- backwardBtn = _ref.backwardBtn,
3283
- forwardBtn = _ref.forwardBtn,
3284
- nowBtn = _ref.nowBtn,
3285
- autoUpdateBtn = _ref.autoUpdateBtn;
3286
- return /*#__PURE__*/jsx(Box, {
3287
- "data-testid": "timeSliderButtons",
3288
- sx: {
3289
- height: 24
3290
- },
3291
- children: /*#__PURE__*/jsxs(Grid, {
3292
- container: true,
3293
- spacing: 0.5,
3294
- sx: {
3295
- alignItems: 'center',
3296
- justifyContent: 'center'
3297
- },
3298
- children: [/*#__PURE__*/jsx(Grid, {
3299
- children: optionsMenuBtn || /*#__PURE__*/jsx(OptionsMenuButton, {})
3300
- }), /*#__PURE__*/jsx(ControlButtons, {
3301
- autoUpdateBtn: autoUpdateBtn,
3302
- backwardBtn: backwardBtn,
3303
- forwardBtn: forwardBtn,
3304
- nowBtn: nowBtn,
3305
- playBtn: playBtn
3306
- })]
3307
- })
3308
- });
3309
- };
3310
-
3311
- /* *
3312
- * Licensed under the Apache License, Version 2.0 (the "License");
3313
- * you may not use this file except in compliance with the License.
3314
- * You may obtain a copy of the License at
3315
- *
3316
- * http://www.apache.org/licenses/LICENSE-2.0
3317
- *
3318
- * Unless required by applicable law or agreed to in writing, software
3319
- * distributed under the License is distributed on an "AS IS" BASIS,
3320
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3321
- * See the License for the specific language governing permissions and
3322
- * limitations under the License.
3323
- *
3324
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3325
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
3326
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
3327
- * */
3328
-
3329
- var onMouseMove = function onMouseMove(x, width, selectedTime, centerTime, secondsPerPx, mouseDownInTimeBox, isTimeBoxArea, setCursorStyle) {
3330
- if (!selectedTime || mouseDownInTimeBox) {
3331
- return;
3332
- }
3333
- var selectedTimePx = timestampToPixel(selectedTime, centerTime, width, secondsPerPx);
3334
- if (isTimeBoxArea(x, selectedTimePx)) {
3335
- setCursorStyle('grab');
3336
- } else {
3337
- setCursorStyle('auto');
3338
- }
3339
- };
3340
- var onMouseDown = function onMouseDown(x, width, selectedTime, centerTime, secondsPerPx, isTimeBoxArea, setCursorStyle, setMouseDownInTimeBox) {
3341
- if (!selectedTime) {
3342
- return;
3343
- }
3344
- var selectedTimePx = timestampToPixel(selectedTime, centerTime, width, secondsPerPx);
3345
- if (isTimeBoxArea(x, selectedTimePx)) {
3346
- setCursorStyle('grabbing');
3347
- }
3348
- setMouseDownInTimeBox(true);
3349
- };
3350
-
3351
- /* *
3352
- * Licensed under the Apache License, Version 2.0 (the "License");
3353
- * you may not use this file except in compliance with the License.
3354
- * You may obtain a copy of the License at
3355
- *
3356
- * http://www.apache.org/licenses/LICENSE-2.0
3357
- *
3358
- * Unless required by applicable law or agreed to in writing, software
3359
- * distributed under the License is distributed on an "AS IS" BASIS,
3360
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3361
- * See the License for the specific language governing permissions and
3362
- * limitations under the License.
3363
- *
3364
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3365
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
3366
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
3367
- * */
3368
-
3369
- var secondsInYear = 365 * 24 * 3600;
3370
- var drawRoundedRectangle = function drawRoundedRectangle(ctx, x, y, width, height, cornerRadius, theme) {
3371
- ctx.save();
3372
- ctx.translate(x, y);
3373
- var playerTimeMarkers = theme.palette.geowebColors.timeSlider.playerTimeMarkers;
3374
- ctx.beginPath();
3375
- ctx.strokeStyle = playerTimeMarkers.fill;
3376
- ctx.fillStyle = playerTimeMarkers.fill;
3377
- ctx.lineWidth = timeBoxGeom.lineWidth;
3378
- var halfLineWidth = timeBoxGeom.lineWidth / 2;
3379
-
3380
- // Top left corner
3381
- ctx.moveTo(halfLineWidth, height / 2);
3382
- ctx.arcTo(halfLineWidth, halfLineWidth, width / 2, halfLineWidth, cornerRadius);
3383
-
3384
- // Top right corner
3385
- ctx.arcTo(width - halfLineWidth, halfLineWidth, width - halfLineWidth, height / 2, cornerRadius);
3386
-
3387
- // Bottom right corner
3388
- ctx.arcTo(width - halfLineWidth, height - halfLineWidth, width / 2, height - halfLineWidth, cornerRadius);
3389
- // Bottom left corner
3390
- ctx.arcTo(halfLineWidth, height - halfLineWidth, halfLineWidth, height / 2, cornerRadius);
3391
- ctx.lineTo(halfLineWidth, height / 2);
3392
- ctx.fill();
3393
- ctx.stroke();
3394
- ctx.restore();
3395
- };
3396
- var drawAutoUpdateIcon = function drawAutoUpdateIcon(ctx, x, y, theme, isAutoUpdating) {
3397
- ctx.save();
3398
- ctx.translate(x, y);
3399
- var playerTimeText = theme.palette.geowebColors.timeSlider.playerTimeText;
3400
- ctx.fillStyle = isAutoUpdating ? '#7BACFF' : '#B4B4B4';
3401
- var path = new Path2D('M12.385 3.295l5 3-5 3V7.723l-.085.014c-3.08.548-5.418 3.24-5.418 6.479 0 3.634 2.945 6.58 6.577 6.58 2.914 0 5.385-1.896 6.248-4.523l2.815-1.626c-.225 4.814-4.197 8.648-9.063 8.648-5.012 0-9.074-4.065-9.074-9.08 0-4.65 3.495-8.484 8-9.015V3.295z');
3402
- ctx.translate(7, -8);
3403
- ctx.rotate(13.295);
3404
- ctx.fill(path);
3405
- ctx.restore();
3406
- var text = 'Auto';
3407
- ctx.save();
3408
- ctx.translate(x, y);
3409
- ctx.fillStyle = isAutoUpdating ? '#7BACFF' : '#B4B4B4'; // ON
3410
-
3411
- ctx.font = "7px " + playerTimeText.fontFamily;
3412
- ctx.fillText(text, 5, 14);
3413
- ctx.restore();
3414
- };
3415
- var drawTextAnnotation = function drawTextAnnotation(ctx, x, y, text, theme) {
3416
- var playerTimeText = theme.palette.geowebColors.timeSlider.playerTimeText;
3417
- ctx.save();
3418
- ctx.translate(x, y);
3419
- ctx.fillStyle = playerTimeText.color;
3420
- ctx.font = playerTimeText.fontSize + "px " + playerTimeText.fontFamily;
3421
- var textMetrics = ctx.measureText(text);
3422
- var actualTextWidth = textMetrics.actualBoundingBoxRight - textMetrics.actualBoundingBoxLeft;
3423
- var actualTextHeight = ctx.measureText('O').width;
3424
- ctx.fillText(text, -actualTextWidth / 2, actualTextHeight / 2);
3425
- ctx.restore();
3426
- };
3427
- var drawNewCurrentTimeBox = function drawNewCurrentTimeBox(ctx, selectedTime, selectedPx, span, theme, isAutoUpdating) {
3428
- var smallWidth = timeBoxGeom.smallWidth,
3429
- largeWidth = timeBoxGeom.largeWidth,
3430
- height = timeBoxGeom.height,
3431
- iconWidth = timeBoxGeom.iconWidth,
3432
- calendarWidth = timeBoxGeom.calendarWidth;
3433
- var boxWidth = span >= secondsInYear ? largeWidth : smallWidth;
3434
- var needleX = selectedPx - boxWidth / 2;
3435
- var needleY = timeBoxGeom.lineWidth;
3436
- drawRoundedRectangle(ctx, needleX - iconWidth / 2 - calendarWidth / 2, needleY, boxWidth + iconWidth + calendarWidth, height, timeBoxGeom.cornerRadius, theme);
3437
- var timeFormat = span >= secondsInYear ? "y " + dateUtils.DATE_FORMAT_NAME_OF_DAY_MONTH : dateUtils.DATE_FORMAT_NAME_OF_DAY_MONTH;
3438
- var timeText = dateUtils.dateToString(dateUtils.fromUnix(selectedTime), timeFormat) || '';
3439
- drawTextAnnotation(ctx, needleX + boxWidth / 2 - iconWidth / 2 + calendarWidth / 2, needleY + height / 2, timeText, theme);
3440
- drawAutoUpdateIcon(ctx, needleX + boxWidth + calendarWidth - iconWidth / 2 - calendarWidth / 2, needleY, theme, isAutoUpdating);
3441
- };
3442
- var renderTimeSliderCurrentTimeBox = function renderTimeSliderCurrentTimeBox(ctx, theme, width, height, centerTime, selected, secondsPerPx, span, isAutoUpdating) {
3443
- // map unix timestamps to pixel values
3444
- var _map = [selected].map(function (t) {
3445
- return timestampToPixel(t, centerTime, width, secondsPerPx);
3446
- }),
3447
- selectedPx = _map[0];
3448
- ctx.clearRect(0, 0, width, height);
3449
- drawNewCurrentTimeBox(ctx, selected, selectedPx, span, theme, isAutoUpdating);
3450
- };
3451
-
3452
- var _excluded = ["day", "today", "outsideCurrentMonth"];
3453
- var getTimezoneOffsetS = function getTimezoneOffsetS(value) {
3454
- return value.getTimezoneOffset() * 60;
3455
- };
3456
- var toLocalTime = function toLocalTime(dateTime) {
3457
- return dateUtils.fromUnix(dateTime + getTimezoneOffsetS(dateUtils.fromUnix(dateTime)));
3458
- };
3459
- var toUTCTime = function toUTCTime(dateTime) {
3460
- return dateUtils.unix(dateTime) - getTimezoneOffsetS(dateTime);
3461
- };
3462
- var OpenPicker = function OpenPicker() {
3463
- return /*#__PURE__*/jsx(CalendarToday, {});
3464
- };
3465
- var enabledAndSelectedButtonStyle = {
3466
- borderWidth: '6px',
3467
- borderBottomStyle: 'solid',
3468
- borderRadius: 0,
3469
- borderColor: 'rgb(170, 210, 240)',
3470
- backgroundColor: 'rgba(170, 210, 240, 0.3)'
3471
- };
3472
- var enabledButUnSelectedButtonStyle = Object.assign({}, enabledAndSelectedButtonStyle, {
3473
- backgroundColor: 'transparent'
3474
- });
3475
- var disabledButtonStyle = Object.assign({}, enabledAndSelectedButtonStyle, {
3476
- borderColor: 'transparent',
3477
- backgroundColor: 'transparent'
3478
- });
3479
- var AvailableDayByTimeRange = function AvailableDayByTimeRange(props, isDisabledStyle) {
3480
- var day = props.day,
3481
- today = props.today,
3482
- outsideCurrentMonth = props.outsideCurrentMonth,
3483
- other = _objectWithoutPropertiesLoose(props, _excluded);
3484
- var _React$useState = React.useState({}),
3485
- calendarDayStyle = _React$useState[0],
3486
- setCalendarDayStyle = _React$useState[1];
3487
- React.useEffect(function () {
3488
- if (outsideCurrentMonth || isDisabledStyle) {
3489
- setCalendarDayStyle(disabledButtonStyle);
3490
- } else if (today) {
3491
- setCalendarDayStyle(enabledAndSelectedButtonStyle);
3492
- } else {
3493
- setCalendarDayStyle(enabledButUnSelectedButtonStyle);
3494
- }
3495
- }, [day, today, outsideCurrentMonth, isDisabledStyle]);
3496
- return /*#__PURE__*/createElement(PickersDay, Object.assign({}, other, {
3497
- day: day,
3498
- disableHighlightToday: true,
3499
- disableMargin: true,
3500
- key: day.toString(),
3501
- outsideCurrentMonth: outsideCurrentMonth,
3502
- sx: Object.assign({}, calendarDayStyle)
3503
- }));
3504
- };
3505
- var MarkerTimeSelector = function MarkerTimeSelector(_ref) {
3506
- var value = _ref.value,
3507
- _ref$format = _ref.format,
3508
- format = _ref$format === void 0 ? dateUtils.DATE_FORMAT_DATEPICKER : _ref$format,
3509
- dataStartTime = _ref.dataStartTime,
3510
- dataEndTime = _ref.dataEndTime,
3511
- _ref$onSelect = _ref.onSelect,
3512
- onSelect = _ref$onSelect === void 0 ? function () {} : _ref$onSelect,
3513
- _ref$onCancel = _ref.onCancel,
3514
- onCancel = _ref$onCancel === void 0 ? function () {} : _ref$onCancel;
3515
- var _useTimesliderTransla = useTimesliderTranslation(),
3516
- t = _useTimesliderTransla.t;
3517
- var _React$useState2 = React.useState(value ? toLocalTime(value) : null),
3518
- localTimeValue = _React$useState2[0],
3519
- setLocalTimeValue = _React$useState2[1];
3520
- var _React$useState3 = React.useState(!dataStartTime || !dataEndTime || dataStartTime > dataEndTime),
3521
- isUndefinedDateRange = _React$useState3[0],
3522
- setIsUndefinedDateRange = _React$useState3[1];
3523
- var isDateRangeDisabled = React.useCallback(function (date) {
3524
- if (dataStartTime === undefined || dataEndTime === undefined || dataStartTime > dataEndTime) {
3525
- return true;
3526
- }
3527
- var startOfFirstDay = dateUtils.fromUnix(dataStartTime);
3528
- startOfFirstDay.setHours(0, 0, 0);
3529
- var endOfLastDay = dateUtils.fromUnix(dataEndTime);
3530
- var day = dateUtils.unix(date);
3531
- return day < dateUtils.unix(startOfFirstDay) || day > dateUtils.unix(endOfLastDay);
3532
- }, [dataStartTime, dataEndTime]);
3533
- var _React$useState4 = React.useState(isDateRangeDisabled(localTimeValue)),
3534
- isDisabledRange = _React$useState4[0],
3535
- setIsDisabledRange = _React$useState4[1];
3536
- var handleSelect = function handleSelect() {
3537
- if (localTimeValue) {
3538
- onSelect(toUTCTime(localTimeValue));
3539
- }
3540
- };
3541
- var handleKeyDown = function handleKeyDown(event) {
3542
- if (event.key === 'Enter') {
3543
- handleSelect();
3544
- } else if (event.key === 'Escape') {
3545
- onCancel();
3546
- }
3547
- };
3548
- var isDisabledDateWithSomeAvailableData = function isDisabledDateWithSomeAvailableData() {
3549
- return isUndefinedDateRange ? false : isDisabledRange;
3550
- };
3551
- var handleDateChange = function handleDateChange(value) {
3552
- if (value instanceof Date || value === null || isDisabledDateWithSomeAvailableData()) {
3553
- setLocalTimeValue(value);
3554
- }
3555
- };
3556
- var AvailableDay = function AvailableDay(props) {
3557
- return AvailableDayByTimeRange(props, isDateRangeDisabled(props.day));
3558
- };
3559
- React.useEffect(function () {
3560
- setIsUndefinedDateRange(!dataStartTime || !dataEndTime || dataStartTime > dataEndTime);
3561
- setIsDisabledRange(isDateRangeDisabled(localTimeValue));
3562
- }, [dataStartTime, dataEndTime, localTimeValue, isDateRangeDisabled]);
3563
- return /*#__PURE__*/jsx(Paper, {
3564
- sx: {
3565
- borderRadius: '0px',
3566
- width: '240px'
3567
- },
3568
- children: /*#__PURE__*/jsxs(Stack, {
3569
- "data-testid": "markerTimeSelector",
3570
- children: [/*#__PURE__*/jsx(Paper, {
3571
- sx: {
3572
- height: '24px',
3573
- align: 'center',
3574
- display: 'flex',
3575
- justifyContent: 'center',
3576
- alignItems: 'center',
3577
- borderRadius: '0px'
3578
- },
3579
- children: /*#__PURE__*/jsx(Paper, {
3580
- sx: {
3581
- variant: 'subtitle',
3582
- textAlign: 'center',
3583
- display: 'flex',
3584
- justifyContent: 'center',
3585
- alignItems: 'center',
3586
- font: {
3587
- fontWeight: 'medium',
3588
- fontFamily: 'Roboto',
3589
- fontSize: '12px'
3590
- },
3591
- borderRadius: '0px',
3592
- boxShadow: 'none'
3593
- },
3594
- children: t('timeslider-marker')
3595
- })
3596
- }), /*#__PURE__*/jsx(LocalizationProvider, {
3597
- dateAdapter: AdapterDateFns,
3598
- children: /*#__PURE__*/jsx(DateTimePicker, {
3599
- ampm: false,
3600
- autoFocus: true,
3601
- closeOnSelect: false,
3602
- desktopModeMediaQuery: "@media (min-width: 720px)",
3603
- disableIgnoringDatePartForTimeValidation: true,
3604
- format: format,
3605
- label: t('timeslider-marker-label'),
3606
- maxDateTime: isUndefinedDateRange ? undefined : toLocalTime(dataEndTime),
3607
- minDateTime: isUndefinedDateRange ? undefined : toLocalTime(dataStartTime),
3608
- onChange: handleDateChange,
3609
- onClose: handleSelect,
3610
- shouldDisableDate: isDisabledDateWithSomeAvailableData,
3611
- slotProps: {
3612
- textField: {
3613
- variant: 'filled',
3614
- InputProps: {
3615
- onKeyDownCapture: handleKeyDown,
3616
- endAdornment: /*#__PURE__*/jsx(InputAdornment, {
3617
- position: "end",
3618
- sx: {
3619
- paddingTop: '16px'
3620
- },
3621
- children: "UTC"
3622
- })
3623
- }
3624
- },
3625
- field: {
3626
- openPickerButtonPosition: 'start'
3627
- },
3628
- openPickerButton: {
3629
- size: 'small',
3630
- sx: {
3631
- padding: 0
3632
- }
3633
- }
3634
- },
3635
- slots: {
3636
- openPickerIcon: OpenPicker,
3637
- day: AvailableDay
3638
- },
3639
- sx: {
3640
- marginTop: '8px',
3641
- marginBottom: '8px',
3642
- marginLeft: '8px',
3643
- marginRight: '8px',
3644
- borderRadius: '0px'
3645
- },
3646
- timeSteps: {
3647
- minutes: 1
3648
- },
3649
- value: localTimeValue
3650
- })
3651
- })]
3652
- })
3653
- });
3654
- };
3655
-
3656
- /* *
3657
- * Licensed under the Apache License, Version 2.0 (the "License");
3658
- * you may not use this file except in compliance with the License.
3659
- * You may obtain a copy of the License at
3660
- *
3661
- * http://www.apache.org/licenses/LICENSE-2.0
3662
- *
3663
- * Unless required by applicable law or agreed to in writing, software
3664
- * distributed under the License is distributed on an "AS IS" BASIS,
3665
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3666
- * See the License for the specific language governing permissions and
3667
- * limitations under the License.
3668
- *
3669
- * Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3670
- * Copyright 2024 - Finnish Meteorological Institute (FMI)
3671
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
3672
- * */
3673
-
3674
- var style = {
3675
- '&.MuiToggleButton-root': {
3676
- color: '#B4B4B4',
3677
- '&:hover': {
3678
- color: '#F8F9F9 !important',
3679
- backgroundColor: 'rgba(255,255,225, 0.3)'
3680
- },
3681
- '&.Mui-selected': {
3682
- color: '#7BACFF !important',
3683
- '&:hover': {
3684
- backgroundColor: 'rgba(255,255,225, 0.3)'
3685
- }
3686
- }
3687
- },
3688
- width: '26px',
3689
- height: '24px!important'
3690
- };
3691
- var CalendarButton = function CalendarButton(_ref) {
3692
- var calendarIconPx = _ref.calendarIconPx,
3693
- dataStartTime = _ref.dataStartTime,
3694
- dataEndTime = _ref.dataEndTime,
3695
- selectedTime = _ref.selectedTime,
3696
- _ref$onSelect = _ref.onSelect,
3697
- _onSelect = _ref$onSelect === void 0 ? function () {} : _ref$onSelect;
3698
- var _React$useState = React.useState(null),
3699
- anchorEl = _React$useState[0],
3700
- setAnchorEl = _React$useState[1];
3701
- var _React$useState2 = React.useState(false),
3702
- open = _React$useState2[0],
3703
- setOpen = _React$useState2[1];
3704
- var _useTimesliderTransla = useTimesliderTranslation(),
3705
- t = _useTimesliderTransla.t;
3706
- return /*#__PURE__*/jsx(ClickAwayListener, {
3707
- mouseEvent: "onMouseDown",
3708
- onClickAway: function onClickAway() {
3709
- return setOpen(false);
3710
- },
3711
- children: /*#__PURE__*/jsxs("div", {
3712
- style: {
3713
- position: 'absolute',
3714
- top: '-2px',
3715
- left: calendarIconPx + "px"
3716
- },
3717
- children: [/*#__PURE__*/jsx(CustomTooltip, {
3718
- slotProps: {
3719
- transition: {
3720
- exit: false
3721
- }
3722
- },
3723
- title: !open && t('timeslider-marker-placement'),
3724
- children: /*#__PURE__*/jsx(CustomToggleButton, {
3725
- onClick: function onClick() {
3726
- return setOpen(!open);
3727
- },
3728
- ref: function ref(_ref2) {
3729
- setAnchorEl(_ref2);
3730
- },
3731
- selected: open,
3732
- sx: style,
3733
- variant: "flat",
3734
- children: /*#__PURE__*/jsx(CalendarToday, {
3735
- style: {
3736
- marginRight: '0px'
3737
- }
3738
- })
3739
- })
3740
- }), /*#__PURE__*/jsx(Popper, {
3741
- anchorEl: anchorEl,
3742
- "data-testid": "dateTimePickerPopOver",
3743
- open: open,
3744
- placement: "top-start",
3745
- sx: {
3746
- zIndex: 10
3747
- },
3748
- children: /*#__PURE__*/jsx(MarkerTimeSelector, {
3749
- dataEndTime: dataEndTime,
3750
- dataStartTime: dataStartTime,
3751
- onCancel: function onCancel() {
3752
- return setOpen(false);
3753
- },
3754
- onSelect: function onSelect(newTime) {
3755
- setOpen(false);
3756
- _onSelect(newTime);
3757
- },
3758
- value: selectedTime
3759
- })
3760
- })]
3761
- })
3762
- });
3763
- };
3764
-
3765
- /* *
3766
- * Licensed under the Apache License, Version 2.0 (the "License");
3767
- * you may not use this file except in compliance with the License.
3768
- * You may obtain a copy of the License at
3769
- *
3770
- * http://www.apache.org/licenses/LICENSE-2.0
3771
- *
3772
- * Unless required by applicable law or agreed to in writing, software
3773
- * distributed under the License is distributed on an "AS IS" BASIS,
3774
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3775
- * See the License for the specific language governing permissions and
3776
- * limitations under the License.
3777
- *
3778
- * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3779
- * Copyright 2022 - Finnish Meteorological Institute (FMI)
3780
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
3781
- * */
3782
-
3783
- var getTimeBoxWidth = function getTimeBoxWidth(span) {
3784
- var smallWidth = timeBoxGeom.smallWidth,
3785
- largeWidth = timeBoxGeom.largeWidth,
3786
- iconWidth = timeBoxGeom.iconWidth,
3787
- calendarWidth = timeBoxGeom.calendarWidth;
3788
- var mainWidth = span >= secondsInYear ? largeWidth : smallWidth;
3789
- return mainWidth + iconWidth + calendarWidth;
3790
- };
3791
- var CALENDAR_ICON_LEFT_SPACING = 1;
3792
- var DEFAULT_PX_TO_MOVE_TIMESLIDER_CENTER = 25; // When the timeslider centertime is reaching the end of the canvas, move the timeslider center a bit
3793
-
3794
- var TimeSliderCurrentTimeBox = function TimeSliderCurrentTimeBox(_ref) {
3795
- var centerTime = _ref.centerTime,
3796
- _ref$secondsPerPx = _ref.secondsPerPx,
3797
- secondsPerPx = _ref$secondsPerPx === void 0 ? 50 : _ref$secondsPerPx,
3798
- _ref$span = _ref.span,
3799
- span = _ref$span === void 0 ? defaultTimeSpan : _ref$span;
3800
- _ref.timeStep;
3801
- var dataStartTime = _ref.dataStartTime,
3802
- dataEndTime = _ref.dataEndTime,
3803
- unfilteredSelectedTime = _ref.unfilteredSelectedTime,
3804
- linkedMapAnimationInfo = _ref.linkedMapAnimationInfo,
3805
- isAutoUpdating = _ref.isAutoUpdating,
3806
- setUnfilteredSelectedTime = _ref.setUnfilteredSelectedTime,
3807
- onCalendarSelect = _ref.onCalendarSelect,
3808
- onSetCenterTime = _ref.onSetCenterTime;
3809
- var timeBoxWidth = getTimeBoxWidth(span);
3810
- var theme = useTheme();
3811
- var _useCanvasTarget = useCanvasTarget('mousedown'),
3812
- node = _useCanvasTarget[1];
3813
- var _React$useState = React.useState('auto'),
3814
- cursorStyle = _React$useState[0],
3815
- setCursorStyle = _React$useState[1];
3816
- var _React$useState2 = React.useState(false),
3817
- mouseDownInTimeBox = _React$useState2[0],
3818
- setMouseDownInTimeBox = _React$useState2[1];
3819
- var _React$useState3 = React.useState(0),
3820
- canvasWidth = _React$useState3[0],
3821
- setCanvasWidth = _React$useState3[1];
3822
- var isAnimating = linkedMapAnimationInfo == null ? void 0 : linkedMapAnimationInfo.isAnimating;
3823
-
3824
- // Move TimeBox back to view if it goes out of bounds
3825
- useEffect(function () {
3826
- if (!(onSetCenterTime && canvasWidth && !mouseDownInTimeBox)) {
3827
- return;
3828
- }
3829
- var receivedTimePx = timestampToPixel(unfilteredSelectedTime, centerTime, canvasWidth, secondsPerPx);
3830
- var moveWidth = isAnimating ? DEFAULT_PX_TO_MOVE_TIMESLIDER_CENTER : getAutoMoveAreaWidth(getFundamentalScale(secondsPerPx));
3831
- if (moveWidth > canvasWidth / 2 || canvasWidth < 100) {
3832
- // don't move if the moveWidth is larger than half the canvaswidth or canvaswidth is very small
3833
- return;
3834
- }
3835
- if (receivedTimePx < moveWidth) {
3836
- onSetCenterTime(pixelToTimestamp(canvasWidth / 2 - (moveWidth - receivedTimePx), centerTime, canvasWidth, secondsPerPx));
3837
- } else if (receivedTimePx > canvasWidth - moveWidth) {
3838
- onSetCenterTime(pixelToTimestamp(canvasWidth / 2 + (receivedTimePx - (canvasWidth - moveWidth)), centerTime, canvasWidth, secondsPerPx));
3839
- }
3840
- // eslint-disable-next-line react-hooks/exhaustive-deps
3841
- }, [unfilteredSelectedTime, isAnimating]);
3842
- var isTimeBoxArea = function isTimeBoxArea(x, selectedTimePx) {
3843
- return x > selectedTimePx - timeBoxWidth / 2 && x < selectedTimePx + timeBoxWidth / 2;
3844
- };
3845
- var mouseDownX = useRef(0);
3846
- var unfilteredSelectedTimePxAtMouseDown = useRef(0);
3847
- React.useEffect(function () {
3848
- var handleMouseUp = function handleMouseUp() {
3849
- mouseDownInTimeBox ? setCursorStyle('grab') : setCursorStyle('auto');
3850
- setMouseDownInTimeBox(false);
3851
- };
3852
- var handleMouseDown = function handleMouseDown(event) {
3853
- mouseDownX.current = event.clientX;
3854
- unfilteredSelectedTimePxAtMouseDown.current = timestampToPixel(unfilteredSelectedTime, centerTime, canvasWidth, secondsPerPx);
3855
- };
3856
- var handleMouseMove = function handleMouseMove(event) {
3857
- if (mouseDownInTimeBox) {
3858
- if (mouseDownX.current) {
3859
- var pixelsMoved = event.clientX - mouseDownX.current;
3860
- var clickedUnfilteredSelectedTimePx = unfilteredSelectedTimePxAtMouseDown.current + pixelsMoved;
3861
- var newUnfilteredSelectedTime = pixelToTimestamp(clickedUnfilteredSelectedTimePx, centerTime, canvasWidth, secondsPerPx);
3862
- setUnfilteredSelectedTime(newUnfilteredSelectedTime);
3863
- }
3864
- }
3865
- };
3866
- document.addEventListener('mouseup', handleMouseUp);
3867
- document.addEventListener('mousemove', handleMouseMove);
3868
- document.addEventListener('mousedown', handleMouseDown);
3869
- return function () {
3870
- document.removeEventListener('mousemove', handleMouseMove);
3871
- document.removeEventListener('mousedown', handleMouseDown);
3872
- document.removeEventListener('mouseup', handleMouseUp);
3873
- };
3874
- }, [canvasWidth, centerTime, mouseDownInTimeBox, secondsPerPx, setUnfilteredSelectedTime, unfilteredSelectedTime]);
3875
-
3876
- // Display unfilteredSelectedTime (already snapped to available timestep)
3877
- var displayTime = unfilteredSelectedTime;
3878
- var timePx = timestampToPixel(displayTime, centerTime, canvasWidth, secondsPerPx);
3879
- var currentTimeBoxWidth = getTimeBoxWidth(span);
3880
- var calendarIconPx = timePx - currentTimeBoxWidth / 2 + CALENDAR_ICON_LEFT_SPACING;
3881
- return /*#__PURE__*/jsxs(Box$1, {
3882
- className: "timeSliderTimeBox",
3883
- "data-testid": "timeSliderTimeBox",
3884
- sx: {
3885
- height: '24px',
3886
- cursor: cursorStyle
3887
- },
3888
- children: [/*#__PURE__*/jsx(CanvasComponent, {
3889
- onMouseDown: function onMouseDown$1(x, y, width) {
3890
- if (!unfilteredSelectedTime) {
3891
- return;
3892
- }
3893
- onMouseDown(x, width, unfilteredSelectedTime, centerTime, secondsPerPx, isTimeBoxArea, setCursorStyle, setMouseDownInTimeBox);
3894
- },
3895
- onMouseMove: function onMouseMove$1(x, y, event, width) {
3896
- if (!unfilteredSelectedTime) {
3897
- return;
3898
- }
3899
- onMouseMove(x, width, unfilteredSelectedTime, centerTime, secondsPerPx, mouseDownInTimeBox, isTimeBoxArea, setCursorStyle);
3900
- },
3901
- onRenderCanvas: function onRenderCanvas(ctx, width, height) {
3902
- setCanvasWidth(width);
3903
- // Use the actual selected time without rounding to timestep
3904
- renderTimeSliderCurrentTimeBox(ctx, theme, width, height, centerTime, unfilteredSelectedTime, secondsPerPx, span, isAutoUpdating);
3905
- },
3906
- ref: node
3907
- }), /*#__PURE__*/jsx(CalendarButton, {
3908
- calendarIconPx: calendarIconPx,
3909
- dataEndTime: dataEndTime,
3910
- dataStartTime: dataStartTime,
3911
- onSelect: function onSelect(newSelectedTime) {
3912
- if (newSelectedTime) {
3913
- onCalendarSelect(newSelectedTime);
3914
- if (onSetCenterTime) {
3915
- onSetCenterTime(newSelectedTime - displayTime + centerTime);
3916
- }
3917
- }
3918
- },
3919
- selectedTime: displayTime
3920
- })]
3921
- });
3922
- };
3923
-
3924
- /* *
3925
- * Licensed under the Apache License, Version 2.0 (the "License");
3926
- * you may not use this file except in compliance with the License.
3927
- * You may obtain a copy of the License at
3928
- *
3929
- * http://www.apache.org/licenses/LICENSE-2.0
3930
- *
3931
- * Unless required by applicable law or agreed to in writing, software
3932
- * distributed under the License is distributed on an "AS IS" BASIS,
3933
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3934
- * See the License for the specific language governing permissions and
3935
- * limitations under the License.
3936
- *
3937
- * Copyright 2023 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3938
- * Copyright 2023 - Finnish Meteorological Institute (FMI)
3939
- * Copyright 2024 - The Norwegian Meteorological Institute (MET Norway)
3940
- * */
3941
-
3942
- var TimesliderI18nProvider = function TimesliderI18nProvider(_ref) {
3943
- var children = _ref.children;
3944
- initTimesliderI18n();
3945
- return /*#__PURE__*/jsx(I18nextProvider, {
3946
- i18n: i18n,
3947
- children: children
3948
- });
3949
- };
3950
- var DemoWrapper = function DemoWrapper(_ref2) {
3951
- var children = _ref2.children,
3952
- _ref2$theme = _ref2.theme,
3953
- theme = _ref2$theme === void 0 ? 'light' : _ref2$theme;
3954
- var themeToApply = theme === 'light' ? lightTheme : darkTheme;
3955
- return /*#__PURE__*/jsx(TimesliderI18nProvider, {
3956
- children: /*#__PURE__*/jsx(ThemeWrapper, {
3957
- theme: themeToApply,
3958
- children: children
3959
- })
3960
- });
3961
- };
3962
-
3963
- export { AUTO_MOVE_AREA_PADDING, AnimationLength, AnimationLengthButton, AutoUpdateButton, BackwardForwardStepButton, ControlButtons, DRAG_AREA_WIDTH, DemoWrapper, HideSliderButton, NowButton, OptionsMenu, OptionsMenuButton, PlayButton, Scale, SpeedButton, TIME_SLIDER_LEGEND_HEIGHT, TIME_SLIDER_NAMESPACE, TimeInMinutes, TimeSlider, TimeSliderButtons, TimeSliderCurrentTimeBox, TimeSliderLegend, TimeSliderMenu, TimeSpanButton, TimeStepButton, calculateMouseTimeAndCheckBounds, convertStringTimeToUnix, defaultAnimationDelayAtStart, defaultDelay, defaultSecondsPerPx, defaultTimeSpan, defaultTimeStep, getAutoMoveAreaWidth, getFilteredTime, getFundamentalScale, getLargestTimeUnit, getNewCenterOfFixedPointZoom, getPixelsBetweenViewportAndTimesliderOnLeft, getPositions, getScaleFromSpan, getSpeedDelay, getTimeBoxWidth, getTimeSliderLegendElement, getTimeSliderLegendId, handleSetNowEvent, isDraggingEndWithinBounds, isDraggingStartWithinBounds, isInsideAnimationArea, isLeftAnimationIconArea, isRightAnimationIconArea, isSelectedTimeIconArea, marks$1 as marks, minutesToDescribedDuration, moveRelativeToTimePoint, moveSelectedTimePx, onsetNewDateDebounced, pixelToTimestamp, roundWithTimeStep, scaleToSecondsPerPx, scalingCoefficient, secondsPerPxFromCanvasWidth, secondsPerPxToScale, secondsPerPxValues, setNextTimeStep, setPreviousTimeStep, spanToScale, speedFactors, timeBoxGeom, timeSliderLegendDefaultProps, timeSliderUtils, timeValues, timesliderTranslations, timestampToPixel, timestampToPixelEdges, useCanvasTarget };