@sybilion/uilib 1.2.24 → 1.3.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/dist/esm/components/ui/Chart/Chart.js +1 -0
- package/dist/esm/components/ui/Chart/components/BaseChartWrapper.js +7 -32
- package/dist/esm/components/ui/Chart/components/ChartEmptyState/ChartEmptyState.js +21 -0
- package/dist/esm/components/ui/Chart/components/ChartEmptyState/ChartEmptyState.styl.js +7 -0
- package/dist/esm/components/ui/Chart/tools/chartPlotGeometry.js +65 -0
- package/dist/esm/components/ui/ChartAreaInteractive/ChartAreaInteractive.helpers.js +37 -1
- package/dist/esm/components/ui/ChartAreaInteractive/ChartAreaInteractive.js +5 -2
- package/dist/esm/components/ui/ChartAreaInteractive/TimeRangeBrushLayer.js +205 -0
- package/dist/esm/components/ui/ChartAreaInteractive/TimeRangeBrushLayer.styl.js +7 -0
- package/dist/esm/components/ui/ChartAreaInteractive/TimeRangeBrushLayout.helpers.js +37 -0
- package/dist/esm/components/ui/ChartAreaInteractive/overlays/IntervalsOverlay/IntervalsOverlay.hooks.js +1 -0
- package/dist/esm/components/ui/ChartAreaInteractive/overlays/PinOverlay/PinOverlay.js +7 -60
- package/dist/esm/components/ui/ChartAreaInteractive/overlays/PinOverlay/PinOverlay.styl.js +2 -2
- package/dist/esm/components/ui/ChartAreaInteractive/overlays/ThresholdsOverlay/ThresholdsOverlay.hooks.js +1 -0
- package/dist/esm/components/ui/ChartAreaInteractive/overlays/useChartYRange.js +2 -4
- package/dist/esm/components/ui/Chat/ChatSheet/ChatSelector.js +1 -1
- package/dist/esm/components/ui/Chat/ChatSheet/ChatSelector.styl.js +1 -1
- package/dist/esm/components/ui/DropdownMenu/DropdownMenu.js +4 -4
- package/dist/esm/components/ui/TimeRangeControls/TimeRangeControls.js +7 -2
- package/dist/esm/components/ui/WorldMap/WorldMap.js +11 -0
- package/dist/esm/components/ui/WorldMap/WorldMap.styl.js +7 -0
- package/dist/esm/components/ui/WorldMap/map.svg.js +3 -0
- package/dist/esm/components/widgets/DriverCard/DriverCard.js +89 -0
- package/dist/esm/components/widgets/DriverCard/DriverCard.styl.js +7 -0
- package/dist/esm/components/widgets/DriverCard/DriverPerformanceChart.js +79 -0
- package/dist/esm/components/widgets/DriverCard/DriverPerformanceChart.styl.js +7 -0
- package/dist/esm/components/widgets/DriverCard/driverPerformanceChartData.js +50 -0
- package/dist/esm/components/widgets/DriverMap/DriverIcon/DriverIcon.constants.json.js +6 -0
- package/dist/esm/components/widgets/DriverMap/DriverIcon/DriverIcon.js +21 -0
- package/dist/esm/components/widgets/DriverMap/DriverIcon/DriverIcon.styl.js +7 -0
- package/dist/esm/components/widgets/DriverMap/DriverMap.helpers.js +107 -0
- package/dist/esm/components/widgets/DriverMap/DriverMap.js +129 -0
- package/dist/esm/components/widgets/DriverMap/DriverMap.styl.js +7 -0
- package/dist/esm/components/widgets/DriverMap/driverCategoryIcon.js +194 -0
- package/dist/esm/components/widgets/DriverMap/driverMapGeography.js +345 -0
- package/dist/esm/components/widgets/DriverMap/driverMapSelection.js +17 -0
- package/dist/esm/hooks/index.js +1 -0
- package/dist/esm/hooks/useEvent.js +0 -2
- package/dist/esm/index.js +7 -0
- package/dist/esm/types/src/components/ui/Chart/Chart.d.ts +1 -0
- package/dist/esm/types/src/components/ui/Chart/components/BaseChartWrapper.d.ts +2 -1
- package/dist/esm/types/src/components/ui/Chart/components/ChartEmptyState/ChartEmptyState.d.ts +14 -0
- package/dist/esm/types/src/components/ui/Chart/tools/chartPlotGeometry.d.ts +30 -0
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.d.ts +1 -1
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.helpers.d.ts +11 -2
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.types.d.ts +2 -2
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/TimeRangeBrushLayer.d.ts +15 -0
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/TimeRangeBrushLayout.helpers.d.ts +14 -0
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/overlays/PinOverlay/PinOverlay.d.ts +1 -1
- package/dist/esm/types/src/components/ui/DropdownMenu/DropdownMenu.d.ts +2 -2
- package/dist/esm/types/src/components/ui/Page/PageColumns/PageColumns.d.ts +1 -1
- package/dist/esm/types/src/components/ui/TimeRangeControls/TimeRangeControls.d.ts +5 -7
- package/dist/esm/types/src/components/ui/WorldMap/WorldMap.d.ts +4 -0
- package/dist/esm/types/src/components/ui/WorldMap/index.d.ts +2 -0
- package/dist/esm/types/src/components/widgets/DriverCard/DriverCard.d.ts +9 -0
- package/dist/esm/types/src/components/widgets/DriverCard/DriverPerformanceChart.d.ts +5 -0
- package/dist/esm/types/src/components/widgets/DriverCard/driverPerformanceChartData.d.ts +7 -0
- package/dist/esm/types/src/components/widgets/DriverCard/index.d.ts +1 -0
- package/dist/esm/types/src/components/widgets/DriverMap/DriverIcon/DriverIcon.d.ts +17 -0
- package/dist/esm/types/src/components/widgets/DriverMap/DriverMap.d.ts +8 -0
- package/dist/esm/types/src/components/widgets/DriverMap/DriverMap.helpers.d.ts +21 -0
- package/dist/esm/types/src/components/widgets/DriverMap/driverCategoryIcon.d.ts +1 -0
- package/dist/esm/types/src/components/widgets/DriverMap/driverMapGeography.d.ts +80 -0
- package/dist/esm/types/src/components/widgets/DriverMap/driverMapSelection.d.ts +3 -0
- package/dist/esm/types/src/components/widgets/DriverMap/index.d.ts +6 -0
- package/dist/esm/types/src/docs/pages/DriverMapPage.d.ts +1 -0
- package/dist/esm/types/src/docs/pages/PageColumnsPage.d.ts +1 -0
- package/dist/esm/types/src/docs/pages/WorldMapPage.d.ts +1 -0
- package/dist/esm/types/src/docs/registry.d.ts +1 -1
- package/dist/esm/types/src/hooks/index.d.ts +1 -0
- package/dist/esm/types/src/index.d.ts +3 -0
- package/package.json +1 -1
- package/src/components/ui/Chart/Chart.tsx +5 -0
- package/src/components/ui/Chart/components/BaseChartWrapper.tsx +8 -41
- package/src/components/ui/Chart/components/ChartEmptyState/ChartEmptyState.styl +60 -0
- package/src/components/ui/Chart/components/ChartEmptyState/ChartEmptyState.styl.d.ts +15 -0
- package/src/components/ui/Chart/components/ChartEmptyState/ChartEmptyState.tsx +66 -0
- package/src/components/ui/Chart/tools/chartPlotGeometry.ts +89 -0
- package/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.helpers.ts +44 -2
- package/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.tsx +14 -1
- package/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.types.ts +2 -3
- package/src/components/ui/ChartAreaInteractive/TimeRangeBrushLayer.styl +21 -0
- package/src/components/ui/ChartAreaInteractive/TimeRangeBrushLayer.styl.d.ts +9 -0
- package/src/components/ui/ChartAreaInteractive/TimeRangeBrushLayer.tsx +285 -0
- package/src/components/ui/ChartAreaInteractive/TimeRangeBrushLayout.helpers.ts +55 -0
- package/src/components/ui/ChartAreaInteractive/overlays/IntervalsOverlay/IntervalsOverlay.hooks.ts +1 -0
- package/src/components/ui/ChartAreaInteractive/overlays/PinOverlay/PinOverlay.styl +2 -7
- package/src/components/ui/ChartAreaInteractive/overlays/PinOverlay/PinOverlay.styl.d.ts +0 -1
- package/src/components/ui/ChartAreaInteractive/overlays/PinOverlay/PinOverlay.tsx +7 -71
- package/src/components/ui/ChartAreaInteractive/overlays/ThresholdsOverlay/ThresholdsOverlay.hooks.ts +1 -0
- package/src/components/ui/ChartAreaInteractive/overlays/useChartYRange.ts +2 -3
- package/src/components/ui/Chat/ChatSheet/ChatSelector.styl +3 -1
- package/src/components/ui/Chat/ChatSheet/ChatSelector.tsx +1 -1
- package/src/components/ui/DropdownMenu/DropdownMenu.tsx +4 -0
- package/src/components/ui/Page/PageColumns/PageColumns.tsx +1 -1
- package/src/components/ui/TimeRangeControls/TimeRangeControls.tsx +16 -17
- package/src/components/ui/WorldMap/WorldMap.styl +11 -0
- package/src/components/ui/WorldMap/WorldMap.styl.d.ts +7 -0
- package/src/components/ui/WorldMap/WorldMap.tsx +22 -0
- package/src/components/ui/WorldMap/index.ts +2 -0
- package/src/components/ui/WorldMap/map.svg +4337 -0
- package/src/components/ui/WorldMap/mapAspect.mixin.styl +3 -0
- package/src/components/ui/WorldMap/mapAspect.mixin.styl.d.ts +2 -0
- package/src/components/widgets/DriverCard/DriverCard.styl +169 -0
- package/src/components/widgets/DriverCard/DriverCard.styl.d.ts +40 -0
- package/src/components/widgets/DriverCard/DriverCard.tsx +219 -0
- package/src/components/widgets/DriverCard/DriverPerformanceChart.styl +43 -0
- package/src/components/widgets/DriverCard/DriverPerformanceChart.styl.d.ts +13 -0
- package/src/components/widgets/DriverCard/DriverPerformanceChart.tsx +150 -0
- package/src/components/widgets/DriverCard/driverPerformanceChartData.ts +64 -0
- package/src/components/widgets/DriverCard/index.ts +1 -0
- package/src/components/widgets/DriverMap/DriverIcon/DriverIcon.constants.json +3 -0
- package/src/components/widgets/DriverMap/DriverIcon/DriverIcon.styl +125 -0
- package/src/components/widgets/DriverMap/DriverIcon/DriverIcon.styl.d.ts +22 -0
- package/src/components/widgets/DriverMap/DriverIcon/DriverIcon.tsx +79 -0
- package/src/components/widgets/DriverMap/DriverMap.helpers.ts +164 -0
- package/src/components/widgets/DriverMap/DriverMap.styl +50 -0
- package/src/components/widgets/DriverMap/DriverMap.styl.d.ts +12 -0
- package/src/components/widgets/DriverMap/DriverMap.tsx +212 -0
- package/src/components/widgets/DriverMap/driverCategoryIcon.tsx +277 -0
- package/src/components/widgets/DriverMap/driverMapGeography.ts +478 -0
- package/src/components/widgets/DriverMap/driverMapSelection.ts +23 -0
- package/src/components/widgets/DriverMap/index.ts +16 -0
- package/src/docs/config/webpack.config.js +25 -9
- package/src/docs/pages/ChartAreaInteractivePage.tsx +2 -3
- package/src/docs/pages/DriverMapPage.tsx +268 -0
- package/src/docs/pages/PageColumnsPage.tsx +92 -0
- package/src/docs/pages/TimeRangeControlsPage.tsx +2 -3
- package/src/docs/pages/TooltipPage.tsx +14 -10
- package/src/docs/pages/WorldMapPage.styl +14 -0
- package/src/docs/pages/WorldMapPage.styl.d.ts +8 -0
- package/src/docs/pages/WorldMapPage.tsx +26 -0
- package/src/docs/registry.ts +18 -5
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useEvent.ts +0 -2
- package/src/index.ts +3 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import React__default, { useMemo } from 'react';
|
|
3
|
+
import { CoffeeIcon, TrendUpIcon, TrendDownIcon } from '@phosphor-icons/react';
|
|
4
|
+
import { Badge } from '../../ui/Badge/Badge.js';
|
|
5
|
+
import { Card, CardContent } from '../../ui/Card/Card.js';
|
|
6
|
+
import { LabelWithId } from '../../ui/LabelWithId/LabelWithId.js';
|
|
7
|
+
import { Skeleton } from '../../ui/Skeleton/Skeleton.js';
|
|
8
|
+
import { Tooltip, TooltipTrigger, TooltipContent } from '../../ui/Tooltip/Tooltip.js';
|
|
9
|
+
import { getCategoryIcon } from '../DriverMap/driverCategoryIcon.js';
|
|
10
|
+
import S from './DriverCard.styl.js';
|
|
11
|
+
import { DriverPerformanceChart } from './DriverPerformanceChart.js';
|
|
12
|
+
|
|
13
|
+
function DriverCard({ selectedDriver, isLoading, inQueue = false, driverSelector, }) {
|
|
14
|
+
const importanceDisplay = useMemo(() => {
|
|
15
|
+
if (!selectedDriver)
|
|
16
|
+
return '';
|
|
17
|
+
let importance = 0;
|
|
18
|
+
if (selectedDriver.rawImportance &&
|
|
19
|
+
typeof selectedDriver.rawImportance === 'object') {
|
|
20
|
+
const importanceObj = selectedDriver.rawImportance;
|
|
21
|
+
if (importanceObj.overall && typeof importanceObj.overall === 'object') {
|
|
22
|
+
const overall = importanceObj.overall;
|
|
23
|
+
if (typeof overall.mean === 'number') {
|
|
24
|
+
importance = Math.round(overall.mean);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return importance > 0
|
|
29
|
+
? `${importance}%`
|
|
30
|
+
: `${selectedDriver.importance.toFixed(1)}%`;
|
|
31
|
+
}, [selectedDriver]);
|
|
32
|
+
const regionDisplay = React__default.useMemo(() => {
|
|
33
|
+
if (!selectedDriver)
|
|
34
|
+
return '';
|
|
35
|
+
// Check for src_region and tgt_region properties first
|
|
36
|
+
const driver = selectedDriver;
|
|
37
|
+
const srcRegion = driver.src_region;
|
|
38
|
+
const tgtRegion = driver.tgt_region;
|
|
39
|
+
const srcName = srcRegion?.name;
|
|
40
|
+
const tgtName = tgtRegion?.name;
|
|
41
|
+
// If both src_region and tgt_region have valid names
|
|
42
|
+
if (srcName && tgtName) {
|
|
43
|
+
// If source and target are the same, just show one
|
|
44
|
+
if (srcName === tgtName) {
|
|
45
|
+
return srcName;
|
|
46
|
+
}
|
|
47
|
+
return `${srcName} → ${tgtName}`;
|
|
48
|
+
}
|
|
49
|
+
// If only src_region has a valid name
|
|
50
|
+
if (srcName) {
|
|
51
|
+
if (srcName === 'World') {
|
|
52
|
+
return 'World';
|
|
53
|
+
}
|
|
54
|
+
return `${srcName} → World`;
|
|
55
|
+
}
|
|
56
|
+
// If only tgt_region has a valid name
|
|
57
|
+
if (tgtName) {
|
|
58
|
+
if (tgtName === 'World') {
|
|
59
|
+
return 'World';
|
|
60
|
+
}
|
|
61
|
+
return `World → ${tgtName}`;
|
|
62
|
+
}
|
|
63
|
+
if (selectedDriver.region.length === 1)
|
|
64
|
+
return selectedDriver.region[0];
|
|
65
|
+
if (selectedDriver.region.length > 1) {
|
|
66
|
+
return (selectedDriver.region
|
|
67
|
+
// .filter(region => region !== 'World')
|
|
68
|
+
.join(' → '));
|
|
69
|
+
}
|
|
70
|
+
// Fallback to "World" when no region information is available
|
|
71
|
+
return 'World';
|
|
72
|
+
}, [selectedDriver]);
|
|
73
|
+
if (inQueue) {
|
|
74
|
+
return (jsx(Card, { className: S.root, children: jsx(CardContent, { centered: true, fullHeight: true, noScroll: true, children: jsxs("div", { className: S.queueMessage, children: [jsx(CoffeeIcon, { size: 24, weight: "regular" }), jsxs("div", { children: [jsx("p", { children: "Retrieving drivers data." }), jsx("p", { children: "This may take a while." })] })] }) }) }));
|
|
75
|
+
}
|
|
76
|
+
if (isLoading) {
|
|
77
|
+
return (jsx(Card, { className: S.root, children: jsx(CardContent, { noScroll: true, children: jsxs("div", { className: S.skeletonContainer, children: [jsx(Skeleton, { className: `${S.skeletonItem} ${S.hs} ${S.w75}` }), jsx(Skeleton, { className: `${S.skeletonItem} ${S.hm} ${S.w50}` }), jsx(Skeleton, { className: `${S.skeletonItem} ${S.hs} ${S.w33}` }), jsxs("div", { className: S.skeletonGroup, children: [jsx(Skeleton, { className: `${S.skeletonItem} ${S.hs} ${S.wFull}` }), jsx(Skeleton, { className: `${S.skeletonItem} ${S.hs} ${S.w75}` }), jsx(Skeleton, { className: `${S.skeletonItem} ${S.hs} ${S.w50}` })] }), jsx(Skeleton, { className: `${S.skeletonItem} ${S.hl} ${S.wFull}` }), jsxs("div", { className: S.skeletonGroup, children: [jsx(Skeleton, { className: `${S.skeletonItem} ${S.hs} ${S.wFull}` }), jsx(Skeleton, { className: `${S.skeletonItem} ${S.hs} ${S.w75}` })] })] }) }) }));
|
|
78
|
+
}
|
|
79
|
+
if (!selectedDriver) {
|
|
80
|
+
return (jsx(Card, { className: S.root, children: jsx(CardContent, { centered: true, fullHeight: true, noScroll: true, children: jsx("span", { className: S.noDriverSelected, children: "No driver selected" }) }) }));
|
|
81
|
+
}
|
|
82
|
+
const { id, name, category, direction, lag, summary } = selectedDriver;
|
|
83
|
+
const directionText = direction > 0 ? 'Positive' : 'Negative';
|
|
84
|
+
const DirectionIcon = direction > 0 ? TrendUpIcon : TrendDownIcon;
|
|
85
|
+
const nameElem = (jsx("h4", { className: `${S.driverTitle} ${S.truncated}`, children: name }));
|
|
86
|
+
return (jsx(Card, { className: S.root, paddingSize: "l", children: jsx(CardContent, { noScroll: true, children: jsxs("div", { className: S.cardContent, children: [jsx("div", { className: S.driverHeader, children: jsxs("div", { className: S.headerContent, children: [jsxs("div", { className: S.topHeader, children: [jsxs("p", { className: S.categoryInfo, children: [jsx("span", { className: S.categoryIcon, children: getCategoryIcon(category) }), jsx("span", { className: S.categoryText, children: category })] }), driverSelector] }), name.length > 60 ? (jsxs(Tooltip, { children: [jsx(LabelWithId, { id: id, label: jsx(TooltipTrigger, { asChild: true, children: nameElem }) }), jsx(TooltipContent, { side: "left", className: S.tooltipContent, children: jsx("div", { className: S.tooltipTitle, children: name }) })] })) : (jsx(LabelWithId, { id: id, label: nameElem })), jsx("p", { className: S.regionDisplay, children: regionDisplay })] }) }), jsx("div", { className: S.metricsSection, children: jsx("div", { className: S.importanceScore, children: importanceDisplay }) }), jsxs("div", { className: S.directionLagSection, children: [jsxs(Badge, { variant: direction > 0 ? 'green' : 'red', className: S.directionBadge, children: [jsx(DirectionIcon, { className: S.trendIcon }), directionText, " correlation"] }), jsxs("span", { className: S.lagInfo, children: ["Lag: ", lag] })] }), jsx(DriverPerformanceChart, { driver: selectedDriver }), jsx("p", { className: S.description, children: summary ?? '' })] }) }) }));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { DriverCard };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import styleInject from 'style-inject';
|
|
2
|
+
|
|
3
|
+
var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}.DriverCard_root__Kr5Xz{height:auto;min-height:500px;width:100%}@media (min-width:640px){.DriverCard_root__Kr5Xz{min-height:25rem}}@media (min-width:768px){.DriverCard_root__Kr5Xz{min-height:31.25rem}}.DriverCard_cardContent__zB8UV{display:flex;flex-direction:column;gap:.5rem}.DriverCard_noDriverSelected__-mVm-{color:var(--muted-foreground)}.DriverCard_driverHeader__0aeJ-{align-items:flex-start;display:flex;flex-direction:column;gap:.75rem;padding-bottom:.25rem}.DriverCard_headerContent__YNqtK{display:flex;flex-direction:column;flex-grow:1;gap:.5rem;width:100%}.DriverCard_topHeader__sUDUc{align-items:center;display:flex;justify-content:space-between;margin-top:-12px;min-height:36px}.DriverCard_categoryInfo__8Dhqn{align-items:center;color:var(--muted-foreground);display:flex;font-size:.75rem;gap:.25rem}.DriverCard_categoryIcon__lSIM8{color:var(--muted-foreground);height:.75rem;width:.75rem}.DriverCard_categoryText__DuifF{display:-webkit-box;-webkit-line-clamp:1;-webkit-box-orient:vertical;overflow:hidden;text-transform:lowercase}.DriverCard_categoryText__DuifF:first-letter{text-transform:uppercase}.DriverCard_driverTitle__tYQO1{color:var(--foreground);font-size:1.1rem;font-weight:500;line-height:1.4;-webkit-user-select:text;-moz-user-select:text;user-select:text}.DriverCard_driverTitle__tYQO1.DriverCard_truncated__RIn6f{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;cursor:help;overflow:hidden}.DriverCard_regionDisplay__QYVWx{color:var(--muted-foreground);font-size:.75rem}.DriverCard_metricsSection__uZViQ{margin-bottom:.5rem;text-align:left}.DriverCard_importanceScore__RGh5Y{align-items:center;color:var(--foreground);display:flex;font-size:2.25rem;font-weight:400;height:auto;line-height:1;-webkit-user-select:text;-moz-user-select:text;user-select:text}.DriverCard_directionLagSection__Mh-ep{align-items:center;display:flex;justify-content:space-between}.DriverCard_directionBadge__7EAHe{align-items:center;display:flex;gap:.5rem}.DriverCard_trendIcon__GtkDe{height:.75rem;width:.75rem}.DriverCard_lagInfo__enbxl{color:var(--muted-foreground);font-size:.75rem}.DriverCard_description__fNR4e{font-size:.875rem;line-height:1.625;-webkit-user-select:text;-moz-user-select:text;user-select:text}.DriverCard_skeletonContainer__AE9MP{display:flex;flex-direction:column;gap:1rem}.DriverCard_skeletonGroup__lQXls{display:flex;flex-direction:column;gap:.5rem}.DriverCard_skeletonItem__pmx4S.DriverCard_hxs__taJow{height:.75rem}.DriverCard_skeletonItem__pmx4S.DriverCard_hs__PlDPB{height:1rem}.DriverCard_skeletonItem__pmx4S.DriverCard_hm__oFwUK{height:2rem}.DriverCard_skeletonItem__pmx4S.DriverCard_hl__McKZn{height:8rem}.DriverCard_skeletonItem__pmx4S.DriverCard_w33__cI-vq{width:33.333333%}.DriverCard_skeletonItem__pmx4S.DriverCard_w50__DcUSo{width:50%}.DriverCard_skeletonItem__pmx4S.DriverCard_w75__To5oR{width:75%}.DriverCard_skeletonItem__pmx4S.DriverCard_w80__y8wQl{width:80%}.DriverCard_skeletonItem__pmx4S.DriverCard_wFull__TnaxF{width:100%}.DriverCard_tooltipContent__F6DUH{font-size:.75rem;max-width:20rem}.DriverCard_tooltipTitle__NieWB{font-family:var(--font-family-body);font-weight:400}.DriverCard_queueMessage__4hQxI{align-items:center;color:var(--muted-foreground);display:flex;flex-direction:column;font-size:.875rem;gap:var(--p-4);line-height:1.5;padding:var(--p-8) var(--p-4);text-align:center}.DriverCard_queueMessage__4hQxI svg{color:var(--muted-foreground);flex-shrink:0;opacity:.8}";
|
|
4
|
+
var S = {"root":"DriverCard_root__Kr5Xz","cardContent":"DriverCard_cardContent__zB8UV","noDriverSelected":"DriverCard_noDriverSelected__-mVm-","driverHeader":"DriverCard_driverHeader__0aeJ-","headerContent":"DriverCard_headerContent__YNqtK","topHeader":"DriverCard_topHeader__sUDUc","categoryInfo":"DriverCard_categoryInfo__8Dhqn","categoryIcon":"DriverCard_categoryIcon__lSIM8","categoryText":"DriverCard_categoryText__DuifF","driverTitle":"DriverCard_driverTitle__tYQO1","truncated":"DriverCard_truncated__RIn6f","regionDisplay":"DriverCard_regionDisplay__QYVWx","metricsSection":"DriverCard_metricsSection__uZViQ","importanceScore":"DriverCard_importanceScore__RGh5Y","directionLagSection":"DriverCard_directionLagSection__Mh-ep","directionBadge":"DriverCard_directionBadge__7EAHe","trendIcon":"DriverCard_trendIcon__GtkDe","lagInfo":"DriverCard_lagInfo__enbxl","description":"DriverCard_description__fNR4e","skeletonContainer":"DriverCard_skeletonContainer__AE9MP","skeletonGroup":"DriverCard_skeletonGroup__lQXls","skeletonItem":"DriverCard_skeletonItem__pmx4S","hxs":"DriverCard_hxs__taJow","hs":"DriverCard_hs__PlDPB","hm":"DriverCard_hm__oFwUK","hl":"DriverCard_hl__McKZn","w33":"DriverCard_w33__cI-vq","w50":"DriverCard_w50__DcUSo","w75":"DriverCard_w75__To5oR","w80":"DriverCard_w80__y8wQl","wFull":"DriverCard_wFull__TnaxF","tooltipContent":"DriverCard_tooltipContent__F6DUH","tooltipTitle":"DriverCard_tooltipTitle__NieWB","queueMessage":"DriverCard_queueMessage__4hQxI"};
|
|
5
|
+
styleInject(css_248z);
|
|
6
|
+
|
|
7
|
+
export { S as default };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { LineChart, CartesianGrid, XAxis, YAxis, Tooltip, Line } from 'recharts';
|
|
5
|
+
import '../../ui/Chart/components/BaseChartWrapper.js';
|
|
6
|
+
import { ChartContainer } from '../../ui/Chart/components/ChartContainer.js';
|
|
7
|
+
import '../../ui/Chart/Chart.context.js';
|
|
8
|
+
import '../../ui/Chart/Chart.styl.js';
|
|
9
|
+
import '../../ui/AnalysisLineIcon/AnalysisLineIcon.styl.js';
|
|
10
|
+
import '@radix-ui/react-slot';
|
|
11
|
+
import '../../ui/Badge/Badge.styl.js';
|
|
12
|
+
import '../../ui/LabelWithId/LabelWithId.styl.js';
|
|
13
|
+
import '@radix-ui/react-select';
|
|
14
|
+
import 'lucide-react';
|
|
15
|
+
import '../../ui/Select/Select.styl.js';
|
|
16
|
+
import '../../ui/TextShimmer/TextShimmer.js';
|
|
17
|
+
import '@phosphor-icons/react';
|
|
18
|
+
import '../../ui/AnalysesSelector/AnalysesSelector.styl.js';
|
|
19
|
+
import '../../ui/Chart/components/CustomChartLegend/CustomChartLegend.styl.js';
|
|
20
|
+
import { ChartEmptyState } from '../../ui/Chart/components/ChartEmptyState/ChartEmptyState.js';
|
|
21
|
+
import S from './DriverPerformanceChart.styl.js';
|
|
22
|
+
import { generateDriverChartData } from './driverPerformanceChartData.js';
|
|
23
|
+
|
|
24
|
+
const driverChartConfig = {
|
|
25
|
+
value: {
|
|
26
|
+
label: 'Performance',
|
|
27
|
+
color: 'var(--primary)',
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
function DriverPerformanceChart({ driver, }) {
|
|
31
|
+
const precision = useMemo(() => {
|
|
32
|
+
if (!driver.normalized_series)
|
|
33
|
+
return 7;
|
|
34
|
+
const values = Object.values(driver.normalized_series).filter((v) => typeof v === 'number' && v !== null);
|
|
35
|
+
if (values.length === 0)
|
|
36
|
+
return 7;
|
|
37
|
+
const absoluteValues = values.map(Math.abs).filter(v => v > 0);
|
|
38
|
+
if (absoluteValues.length === 0)
|
|
39
|
+
return 7;
|
|
40
|
+
const minAbs = Math.min(...absoluteValues);
|
|
41
|
+
if (minAbs < 0.0001)
|
|
42
|
+
return 7;
|
|
43
|
+
if (minAbs < 0.001)
|
|
44
|
+
return 6;
|
|
45
|
+
if (minAbs < 0.01)
|
|
46
|
+
return 5;
|
|
47
|
+
if (minAbs < 0.1)
|
|
48
|
+
return 4;
|
|
49
|
+
if (minAbs < 1)
|
|
50
|
+
return 3;
|
|
51
|
+
return 2;
|
|
52
|
+
}, [driver.normalized_series]);
|
|
53
|
+
const chartData = useMemo(() => generateDriverChartData(driver, precision), [driver, precision]);
|
|
54
|
+
const noSeriesData = useMemo(() => {
|
|
55
|
+
if (!driver.normalized_series)
|
|
56
|
+
return false;
|
|
57
|
+
return Object.values(driver.normalized_series).every(value => value === null);
|
|
58
|
+
}, [driver.normalized_series]);
|
|
59
|
+
const renderTooltipContent = ({ active, payload, }) => {
|
|
60
|
+
if (active && payload?.length) {
|
|
61
|
+
const dataPoint = payload[0];
|
|
62
|
+
const row = dataPoint?.payload;
|
|
63
|
+
const date = row?.date;
|
|
64
|
+
const value = dataPoint?.value;
|
|
65
|
+
return (jsxs("div", { className: S.chartTooltip, children: [jsx("div", { className: S.tooltipDate, children: date instanceof Date
|
|
66
|
+
? date.toLocaleDateString('en-US', {
|
|
67
|
+
month: 'long',
|
|
68
|
+
year: 'numeric',
|
|
69
|
+
})
|
|
70
|
+
: 'Unknown Date' }), jsxs("div", { className: S.tooltipPerformance, children: ["Performance:", ' ', typeof value === 'number'
|
|
71
|
+
? value.toFixed(precision)
|
|
72
|
+
: String(value ?? '')] })] }));
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
};
|
|
76
|
+
return (jsxs("div", { className: S.driverChartContainer, children: [jsx(ChartContainer, { config: driverChartConfig, className: cn(S.chartContainer, noSeriesData && S.chartContainerDisabled), children: jsxs(LineChart, { data: chartData, margin: { left: 8, right: 8, top: 8, bottom: -20 }, children: [jsx(CartesianGrid, { vertical: false }), jsx(XAxis, { dataKey: "date", tickLine: false, axisLine: false, tick: false, tickMargin: 0, minTickGap: 0 }), jsx(YAxis, { tickLine: false, axisLine: false, tick: false, tickMargin: 0, minTickGap: 0, width: 0, domain: ['dataMin', 'dataMax'] }), jsx(Tooltip, { cursor: false, content: renderTooltipContent }), jsx(Line, { dataKey: "value", type: "natural", stroke: "var(--color-value)" })] }) }), noSeriesData && (jsx(ChartEmptyState, { variant: "inline", align: "center", status: "No series data", className: S.noDataMessage }))] }));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { DriverPerformanceChart };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import styleInject from 'style-inject';
|
|
2
|
+
|
|
3
|
+
var css_248z = ".DriverPerformanceChart_driverChartContainer__27xZ-{position:relative;width:100%}.DriverPerformanceChart_driverChartContainer__27xZ- svg{overflow:visible}.DriverPerformanceChart_chartContainer__--rGL{height:214px;margin-left:-.5rem;padding:var(--p-4) 0;width:100%}.DriverPerformanceChart_chartContainerDisabled__ndtPZ{opacity:.1}.DriverPerformanceChart_noDataMessage__RO3u1{color:var(--foreground);font-size:.875rem;font-weight:500;left:50%;pointer-events:none;position:absolute;top:50%;transform:translate(-50%,-50%);z-index:10}.DriverPerformanceChart_chartTooltip__cpaQw{background-color:var(--popover);border:1px solid var(--border);border-radius:.5rem;box-shadow:0 10px 15px -3px rgba(0,0,0,.1);padding:.75rem}.DriverPerformanceChart_tooltipDate__B2aeP{color:var(--popover-foreground);font-size:.875rem;font-weight:500}.DriverPerformanceChart_tooltipPerformance__3hfgE{color:var(--muted-foreground);font-size:.875rem}";
|
|
4
|
+
var S = {"driverChartContainer":"DriverPerformanceChart_driverChartContainer__27xZ-","chartContainer":"DriverPerformanceChart_chartContainer__--rGL","chartContainerDisabled":"DriverPerformanceChart_chartContainerDisabled__ndtPZ","noDataMessage":"DriverPerformanceChart_noDataMessage__RO3u1","chartTooltip":"DriverPerformanceChart_chartTooltip__cpaQw","tooltipDate":"DriverPerformanceChart_tooltipDate__B2aeP","tooltipPerformance":"DriverPerformanceChart_tooltipPerformance__3hfgE"};
|
|
5
|
+
styleInject(css_248z);
|
|
6
|
+
|
|
7
|
+
export { S as default };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Last non-null points from `normalized_series`, or deterministic fallback sample. */
|
|
2
|
+
function generateDriverChartData(driver, precision = 7) {
|
|
3
|
+
if (driver.normalized_series) {
|
|
4
|
+
const entries = Object.entries(driver.normalized_series);
|
|
5
|
+
const seriesData = entries
|
|
6
|
+
.filter(([, value]) => value !== null)
|
|
7
|
+
.map(([date, value]) => {
|
|
8
|
+
let parsedDate;
|
|
9
|
+
try {
|
|
10
|
+
const dateStr = date.toString();
|
|
11
|
+
if (dateStr.includes('-')) {
|
|
12
|
+
parsedDate = new Date(`${dateStr}T00:00:00`);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
parsedDate = new Date(dateStr);
|
|
16
|
+
}
|
|
17
|
+
if (Number.isNaN(parsedDate.getTime())) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const numericValue = parseFloat(value.toFixed(precision));
|
|
25
|
+
return {
|
|
26
|
+
date: parsedDate,
|
|
27
|
+
value: numericValue,
|
|
28
|
+
};
|
|
29
|
+
})
|
|
30
|
+
.filter((item) => item !== null)
|
|
31
|
+
.sort((a, b) => a.date.getTime() - b.date.getTime())
|
|
32
|
+
.slice(-24);
|
|
33
|
+
if (seriesData.length > 0) {
|
|
34
|
+
return seriesData;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const data = [];
|
|
38
|
+
const baseValue = driver.importance / 100;
|
|
39
|
+
for (let i = 0; i < 12; i++) {
|
|
40
|
+
const randomVariation = (Math.random() - 0.5) * 0.2;
|
|
41
|
+
const value = Math.max(0, Math.min(1, baseValue + randomVariation));
|
|
42
|
+
data.push({
|
|
43
|
+
date: new Date(2023, i, 1),
|
|
44
|
+
value: parseFloat(value.toFixed(precision)),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { generateDriverChartData };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { Badge } from '../../../ui/Badge/Badge.js';
|
|
4
|
+
import { Tooltip, TooltipTrigger, TooltipContent } from '../../../ui/Tooltip/Tooltip.js';
|
|
5
|
+
import { getCategoryIcon } from '../driverCategoryIcon.js';
|
|
6
|
+
import S from './DriverIcon.styl.js';
|
|
7
|
+
|
|
8
|
+
const BADGE_SIZES = {
|
|
9
|
+
s: 's',
|
|
10
|
+
m: 'm',
|
|
11
|
+
l: 'l',
|
|
12
|
+
};
|
|
13
|
+
function DriverIcon({ driver, size, isSelected, onClick, isVisible, isLoading = false, }) {
|
|
14
|
+
return (jsxs(Tooltip, { children: [jsx(TooltipTrigger, { asChild: true, className: cn(S.root, S[`size-${size}`], isSelected && S.selected, isVisible ? S.visible : S.hidden, isLoading && S.loadingHidden), children: jsx("button", { type: "button", onClick: onClick, style: {
|
|
15
|
+
left: `${driver.coordinates.x}%`,
|
|
16
|
+
top: `${driver.coordinates.y}%`,
|
|
17
|
+
zIndex: isSelected ? 2 : '',
|
|
18
|
+
}, children: jsx(Badge, { className: S.badge, children: jsx("div", { className: S.icon, children: getCategoryIcon(driver.category) }) }) }) }), jsx(TooltipContent, { side: "top", className: S.tooltipContent, children: jsxs("div", { className: S.tooltipSpacing, children: [jsxs("div", { className: S.tooltipCategory, children: [jsx("span", { className: S.tooltipCategoryIcon, children: getCategoryIcon(driver.category) }), jsx("span", { className: S.tooltipCategoryText, children: driver.category })] }), jsx("div", { className: S.tooltipName, children: driver.name })] }) })] }));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { BADGE_SIZES, DriverIcon };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import styleInject from 'style-inject';
|
|
2
|
+
|
|
3
|
+
var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}.DriverIcon_root__LJkZV{cursor:pointer;outline:none;position:absolute;transform:translateX(-50%) translateY(-50%)}.DriverIcon_root__LJkZV:hover{transition:transform .3s ease-out}.DriverIcon_root__LJkZV:focus{outline:none}.DriverIcon_badge__gV6XC,.DriverIcon_loadingHidden__fm2N0{opacity:0;pointer-events:none}.DriverIcon_badge__gV6XC{padding:.25rem;transform:translateY(10px);transition:all .3s ease-out}.DriverIcon_badge__gV6XC svg{height:20px;width:20px}.DriverIcon_size-s__5oC0V,.DriverIcon_size-s__5oC0V .DriverIcon_badge__gV6XC{border-radius:10px;height:2rem;width:2rem}.DriverIcon_size-m__HoK4J,.DriverIcon_size-m__HoK4J .DriverIcon_badge__gV6XC{border-radius:12px;height:2.5rem;width:2.5rem}.DriverIcon_size-l__6solM,.DriverIcon_size-l__6solM .DriverIcon_badge__gV6XC{border-radius:14px;height:3rem;width:3rem}.DriverIcon_visible__HVfIl .DriverIcon_badge__gV6XC{opacity:1;transform:translateY(0);transition:.3s ease-out;transition-property:opacity,transform}.DriverIcon_visible__HVfIl .DriverIcon_badge__gV6XC span{transition:box-shadow 0s ease-out .1s}.DriverIcon_root__LJkZV:first-child .DriverIcon_badge__gV6XC{transition-delay:30ms}.DriverIcon_visible__HVfIl:first-child .DriverIcon_badge__gV6XC{transition-delay:60ms}.DriverIcon_hidden__udGUf:first-child .DriverIcon_badge__gV6XC{transition-duration:.27s}.DriverIcon_root__LJkZV:nth-child(2) .DriverIcon_badge__gV6XC{transition-delay:60ms}.DriverIcon_visible__HVfIl:nth-child(2) .DriverIcon_badge__gV6XC{transition-delay:.12s}.DriverIcon_hidden__udGUf:nth-child(2) .DriverIcon_badge__gV6XC{transition-duration:.24s}.DriverIcon_root__LJkZV:nth-child(3) .DriverIcon_badge__gV6XC{transition-delay:90ms}.DriverIcon_visible__HVfIl:nth-child(3) .DriverIcon_badge__gV6XC{transition-delay:.18s}.DriverIcon_hidden__udGUf:nth-child(3) .DriverIcon_badge__gV6XC{transition-duration:.21s}.DriverIcon_root__LJkZV:nth-child(4) .DriverIcon_badge__gV6XC{transition-delay:.12s}.DriverIcon_visible__HVfIl:nth-child(4) .DriverIcon_badge__gV6XC{transition-delay:.24s}.DriverIcon_hidden__udGUf:nth-child(4) .DriverIcon_badge__gV6XC{transition-duration:.18s}.DriverIcon_root__LJkZV:nth-child(5) .DriverIcon_badge__gV6XC{transition-delay:.15s}.DriverIcon_visible__HVfIl:nth-child(5) .DriverIcon_badge__gV6XC{transition-delay:.3s}.DriverIcon_hidden__udGUf:nth-child(5) .DriverIcon_badge__gV6XC{transition-duration:.15s}.DriverIcon_root__LJkZV:nth-child(6) .DriverIcon_badge__gV6XC{transition-delay:.18s}.DriverIcon_visible__HVfIl:nth-child(6) .DriverIcon_badge__gV6XC{transition-delay:.36s}.DriverIcon_hidden__udGUf:nth-child(6) .DriverIcon_badge__gV6XC{transition-duration:.12s}.DriverIcon_root__LJkZV:hover{z-index:10}.DriverIcon_root__LJkZV:hover .DriverIcon_badge__gV6XC{box-shadow:0 0 0 1px var(--background);transform:scale(1.1);transition-delay:0ms;transition-duration:.2s}.DriverIcon_selected__-yaRV .DriverIcon_badge__gV6XC,.DriverIcon_selected__-yaRV:hover .DriverIcon_badge__gV6XC{box-shadow:inset 0 0 0 3px var(--sb-cyan-400);transform:scale(1.1)}.dark .DriverIcon_selected__-yaRV .DriverIcon_badge__gV6XC,.dark .DriverIcon_selected__-yaRV:hover .DriverIcon_badge__gV6XC{box-shadow:inset 0 0 0 2px var(--sb-cyan-500)}.DriverIcon_root__LJkZV:not(.DriverIcon_selected__-yaRV):hover .DriverIcon_icon__1XnNP{transform:scale(1.05)}.DriverIcon_tooltipContent__a5p3p{background-color:var(--popover);border:1px solid var(--border);box-shadow:0 10px 15px -3px rgba(0,0,0,.1);color:var(--popover-foreground);font-family:var(--font-family-body);font-size:.75rem;max-width:20rem}.DriverIcon_tooltipCategory__k036X{align-items:center;color:var(--muted-foreground);display:flex;gap:.25rem}.DriverIcon_tooltipCategoryIcon__CKac6{color:var(--muted-foreground);height:.75rem;width:.75rem}.DriverIcon_tooltipCategoryText__YaHvf{display:-webkit-box;-webkit-line-clamp:1;-webkit-box-orient:vertical;overflow:hidden}.DriverIcon_tooltipName__3YJCB{font-weight:400}.DriverIcon_tooltipSpacing__p2MvJ{display:flex;flex-direction:column;gap:.25rem}";
|
|
4
|
+
var S = {"root":"DriverIcon_root__LJkZV","loadingHidden":"DriverIcon_loadingHidden__fm2N0","badge":"DriverIcon_badge__gV6XC","size-s":"DriverIcon_size-s__5oC0V","size-m":"DriverIcon_size-m__HoK4J","size-l":"DriverIcon_size-l__6solM","visible":"DriverIcon_visible__HVfIl","hidden":"DriverIcon_hidden__udGUf","selected":"DriverIcon_selected__-yaRV","icon":"DriverIcon_icon__1XnNP","tooltipContent":"DriverIcon_tooltipContent__a5p3p","tooltipCategory":"DriverIcon_tooltipCategory__k036X","tooltipCategoryIcon":"DriverIcon_tooltipCategoryIcon__CKac6","tooltipCategoryText":"DriverIcon_tooltipCategoryText__YaHvf","tooltipName":"DriverIcon_tooltipName__3YJCB","tooltipSpacing":"DriverIcon_tooltipSpacing__p2MvJ"};
|
|
5
|
+
styleInject(css_248z);
|
|
6
|
+
|
|
7
|
+
export { S as default };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { BADGE_SIZES } from './DriverIcon/DriverIcon.js';
|
|
2
|
+
import { geographicToSVG, svgToPercentage, getResponsiveCoordinates } from './driverMapGeography.js';
|
|
3
|
+
import { getDriverImportance } from './driverMapSelection.js';
|
|
4
|
+
|
|
5
|
+
// Calculate badge sizes for all drivers based on their importance
|
|
6
|
+
const calculateBadgeSizes = (drivers) => {
|
|
7
|
+
if (drivers.length === 0)
|
|
8
|
+
return {};
|
|
9
|
+
const importanceValues = drivers
|
|
10
|
+
.map(getDriverImportance)
|
|
11
|
+
.filter((val) => typeof val === 'number' && !isNaN(val) && val >= 0);
|
|
12
|
+
if (importanceValues.length === 0) {
|
|
13
|
+
return drivers.reduce((acc, driver) => {
|
|
14
|
+
acc[driver.id] = BADGE_SIZES.s;
|
|
15
|
+
return acc;
|
|
16
|
+
}, {});
|
|
17
|
+
}
|
|
18
|
+
const min = Math.min(...importanceValues);
|
|
19
|
+
const max = Math.max(...importanceValues);
|
|
20
|
+
const range = max - min;
|
|
21
|
+
if (range === 0) {
|
|
22
|
+
return drivers.reduce((acc, driver) => {
|
|
23
|
+
acc[driver.id] = BADGE_SIZES.s;
|
|
24
|
+
return acc;
|
|
25
|
+
}, {});
|
|
26
|
+
}
|
|
27
|
+
return drivers.reduce((acc, driver) => {
|
|
28
|
+
const importance = getDriverImportance(driver);
|
|
29
|
+
if (typeof importance !== 'number' ||
|
|
30
|
+
isNaN(importance) ||
|
|
31
|
+
importance < 0) {
|
|
32
|
+
acc[driver.id] = BADGE_SIZES.s;
|
|
33
|
+
return acc;
|
|
34
|
+
}
|
|
35
|
+
const normalized = (importance - min) / range;
|
|
36
|
+
acc[driver.id] =
|
|
37
|
+
normalized >= 0.66
|
|
38
|
+
? BADGE_SIZES.l
|
|
39
|
+
: normalized >= 0.33
|
|
40
|
+
? BADGE_SIZES.m
|
|
41
|
+
: BADGE_SIZES.s;
|
|
42
|
+
return acc;
|
|
43
|
+
}, {});
|
|
44
|
+
};
|
|
45
|
+
const hasValidCoords = (coords) => {
|
|
46
|
+
return (coords?.x != null &&
|
|
47
|
+
coords?.y != null &&
|
|
48
|
+
typeof coords.x === 'number' &&
|
|
49
|
+
typeof coords.y === 'number' &&
|
|
50
|
+
!isNaN(coords.x) &&
|
|
51
|
+
!isNaN(coords.y) &&
|
|
52
|
+
Math.abs(coords.x) > 0 &&
|
|
53
|
+
Math.abs(coords.y) > 0);
|
|
54
|
+
};
|
|
55
|
+
const findMostSpecificRegion = (driver) => {
|
|
56
|
+
if (driver.region?.length > 0) {
|
|
57
|
+
return {
|
|
58
|
+
name: driver.region[driver.region.length - 1],
|
|
59
|
+
coordinates: null,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const srcName = driver.src_region?.name;
|
|
63
|
+
const tgtName = driver.tgt_region?.name;
|
|
64
|
+
const srcCoords = driver.src_region?.coordinates;
|
|
65
|
+
const tgtCoords = driver.tgt_region?.coordinates;
|
|
66
|
+
const srcIsNonWorld = srcName && srcName !== 'World' && hasValidCoords(srcCoords);
|
|
67
|
+
const tgtIsNonWorld = tgtName && tgtName !== 'World' && hasValidCoords(tgtCoords);
|
|
68
|
+
if (tgtIsNonWorld) {
|
|
69
|
+
return {
|
|
70
|
+
name: tgtName,
|
|
71
|
+
coordinates: tgtCoords,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (srcIsNonWorld) {
|
|
75
|
+
return {
|
|
76
|
+
name: srcName,
|
|
77
|
+
coordinates: srcCoords,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return { name: null, coordinates: null };
|
|
81
|
+
};
|
|
82
|
+
const getDriverCoordinates = (driver, specificRegion, existingDrivers = []) => {
|
|
83
|
+
if (!specificRegion.name || specificRegion.name === 'World') {
|
|
84
|
+
return driver.coordinates;
|
|
85
|
+
}
|
|
86
|
+
if (specificRegion.coordinates) {
|
|
87
|
+
const isLatLng = Math.abs(specificRegion.coordinates.x) <= 180 &&
|
|
88
|
+
Math.abs(specificRegion.coordinates.y) <= 90;
|
|
89
|
+
if (isLatLng) {
|
|
90
|
+
const svgCoords = geographicToSVG(specificRegion.coordinates.y, specificRegion.coordinates.x);
|
|
91
|
+
const percentageCoords = svgToPercentage(svgCoords.x, svgCoords.y);
|
|
92
|
+
return {
|
|
93
|
+
x: Math.min(95, Math.max(5, percentageCoords.x)),
|
|
94
|
+
y: Math.min(95, Math.max(5, percentageCoords.y)),
|
|
95
|
+
continent: driver.coordinates?.continent || 'Global',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
x: specificRegion.coordinates.x,
|
|
100
|
+
y: specificRegion.coordinates.y,
|
|
101
|
+
continent: driver.coordinates?.continent || 'Global',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return getResponsiveCoordinates(specificRegion.name, existingDrivers);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export { calculateBadgeSizes, findMostSpecificRegion, getDriverCoordinates, hasValidCoords };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { useRef, useState, useMemo, useEffect, useCallback } from 'react';
|
|
4
|
+
import { WorldMap } from '../../ui/WorldMap/WorldMap.js';
|
|
5
|
+
import useEvent from '../../../hooks/useEvent.js';
|
|
6
|
+
import { Shimmer } from '@homecode/ui';
|
|
7
|
+
import { DriverIcon } from './DriverIcon/DriverIcon.js';
|
|
8
|
+
import constants from './DriverIcon/DriverIcon.constants.json.js';
|
|
9
|
+
import { findMostSpecificRegion, getDriverCoordinates, hasValidCoords, calculateBadgeSizes } from './DriverMap.helpers.js';
|
|
10
|
+
import S from './DriverMap.styl.js';
|
|
11
|
+
import { getHighestImportanceDriver } from './driverMapSelection.js';
|
|
12
|
+
|
|
13
|
+
const delay = (ms) => new Promise(r => setTimeout(r, ms));
|
|
14
|
+
const transitionDelay = () => delay(constants.FADE_DURATION);
|
|
15
|
+
function DriverMap({ drivers, isLoading, setSelectedDriver, selectedDriver, }) {
|
|
16
|
+
const visibleDriversRef = useRef([]);
|
|
17
|
+
const [showingDrivers, setShowingDrivers] = useState(drivers);
|
|
18
|
+
const [badgeSizes, setBadgeSizes] = useState({});
|
|
19
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
20
|
+
const [isTransitioning, setIsTransitioning] = useState(false);
|
|
21
|
+
const makeTransition = async (nextDrivers) => {
|
|
22
|
+
const hadDrivers = showingDrivers.length > 0;
|
|
23
|
+
setIsTransitioning(true);
|
|
24
|
+
if (hadDrivers) {
|
|
25
|
+
setIsVisible(false);
|
|
26
|
+
await transitionDelay();
|
|
27
|
+
}
|
|
28
|
+
if (nextDrivers.length > 0) {
|
|
29
|
+
setShowingDrivers(nextDrivers);
|
|
30
|
+
setIsVisible(false);
|
|
31
|
+
const sizes = calculateBadgeSizes(nextDrivers);
|
|
32
|
+
setBadgeSizes(sizes);
|
|
33
|
+
await delay(30);
|
|
34
|
+
setIsVisible(true);
|
|
35
|
+
await transitionDelay();
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
setShowingDrivers([]);
|
|
39
|
+
setBadgeSizes({});
|
|
40
|
+
setIsVisible(false);
|
|
41
|
+
}
|
|
42
|
+
setIsTransitioning(false);
|
|
43
|
+
};
|
|
44
|
+
const [worldDrivers, otherDrivers] = useMemo(() => {
|
|
45
|
+
const visibleDrivers = [];
|
|
46
|
+
const worldDriversList = [];
|
|
47
|
+
drivers.forEach(driver => {
|
|
48
|
+
let importance = driver.importance || 0;
|
|
49
|
+
if (importance === 0) {
|
|
50
|
+
const mean = driver?.rawImportance?.overall?.mean;
|
|
51
|
+
if (typeof mean === 'number') {
|
|
52
|
+
importance = Math.abs(mean) * 100;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const specificRegion = findMostSpecificRegion(driver);
|
|
56
|
+
const isEmptyRegion = driver.region?.length === 0;
|
|
57
|
+
const isWorldRegion = specificRegion.name === 'World' ||
|
|
58
|
+
driver.region?.slice(-1)[0] === 'World';
|
|
59
|
+
const coordinates = getDriverCoordinates(driver, specificRegion, visibleDrivers);
|
|
60
|
+
const driverToAdd = {
|
|
61
|
+
...driver,
|
|
62
|
+
coordinates,
|
|
63
|
+
};
|
|
64
|
+
const shouldGoToWorldDrivers = isWorldRegion ||
|
|
65
|
+
!hasValidCoords(driverToAdd.coordinates) ||
|
|
66
|
+
(isEmptyRegion && !specificRegion.name);
|
|
67
|
+
if (shouldGoToWorldDrivers && importance >= 0) {
|
|
68
|
+
worldDriversList.push(driver);
|
|
69
|
+
}
|
|
70
|
+
else if (hasValidCoords(driverToAdd.coordinates) && importance >= 0) {
|
|
71
|
+
visibleDrivers.push(driverToAdd);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return [
|
|
75
|
+
worldDriversList.sort((a, b) => b.importance - a.importance),
|
|
76
|
+
visibleDrivers,
|
|
77
|
+
];
|
|
78
|
+
}, [drivers]);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
void makeTransition(drivers);
|
|
81
|
+
if (drivers.length > 0) {
|
|
82
|
+
const idx = getHighestImportanceDriver(drivers);
|
|
83
|
+
if (idx !== null && idx >= 0) {
|
|
84
|
+
setSelectedDriver(drivers[idx]);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}, [drivers]);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
visibleDriversRef.current = otherDrivers;
|
|
90
|
+
}, [otherDrivers]);
|
|
91
|
+
const handleKeyDown = useCallback((e) => {
|
|
92
|
+
const items = visibleDriversRef.current;
|
|
93
|
+
if (!selectedDriver || items.length === 0 || e.metaKey || e.ctrlKey)
|
|
94
|
+
return;
|
|
95
|
+
const stop = () => {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
e.stopPropagation();
|
|
98
|
+
};
|
|
99
|
+
const currIndex = items.findIndex(d => d.id === selectedDriver.id);
|
|
100
|
+
if (e.key === 'ArrowLeft') {
|
|
101
|
+
const prevIndex = currIndex > 0 ? currIndex - 1 : items.length - 1;
|
|
102
|
+
setSelectedDriver(items[prevIndex]);
|
|
103
|
+
stop();
|
|
104
|
+
}
|
|
105
|
+
else if (e.key === 'ArrowRight') {
|
|
106
|
+
const nextIndex = currIndex < items.length - 1 ? currIndex + 1 : 0;
|
|
107
|
+
setSelectedDriver(items[nextIndex]);
|
|
108
|
+
stop();
|
|
109
|
+
}
|
|
110
|
+
}, [selectedDriver, setSelectedDriver]);
|
|
111
|
+
useEvent({
|
|
112
|
+
event: 'keydown',
|
|
113
|
+
callback: handleKeyDown,
|
|
114
|
+
isCapture: true,
|
|
115
|
+
});
|
|
116
|
+
return (jsxs("div", { className: cn(S.root, isTransitioning && S.inTransition), children: [jsxs("div", { className: S.mapInner, children: [jsx(WorldMap, { className: S.mapWorld }), isLoading && jsx(Shimmer, { className: S.shimmerOverlay, size: "l" }), otherDrivers.map(driver => (jsx(DriverIcon, { isLoading: isLoading, isVisible: isVisible, driver: driver, size: badgeSizes[driver.id] || 's', isSelected: selectedDriver?.id === driver.id, onClick: () => setSelectedDriver(driver) }, driver.id)))] }), jsx("div", { className: S.worldDrivers, children: worldDrivers.map(driver => {
|
|
117
|
+
const driverWithCoords = {
|
|
118
|
+
...driver,
|
|
119
|
+
coordinates: driver.coordinates || {
|
|
120
|
+
x: 0,
|
|
121
|
+
y: 0,
|
|
122
|
+
continent: 'Global',
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
return (jsx(DriverIcon, { isLoading: isLoading, isVisible: isVisible, driver: driverWithCoords, size: badgeSizes[driver.id] || 's', isSelected: selectedDriver?.id === driver.id, onClick: () => setSelectedDriver(driver) }, driver.id));
|
|
126
|
+
}) })] }));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { DriverMap };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import styleInject from 'style-inject';
|
|
2
|
+
|
|
3
|
+
var css_248z = "@media (max-width:768px){:root{--page-x-padding:var(--p-6);--page-y-padding:var(--p-6)}}.DriverMap_root__JszhG{aspect-ratio:623.2/341.276;max-width:100%;overflow:hidden;padding:0;position:relative;width:100%}@media (min-width:768px){.DriverMap_root__JszhG{flex:1;height:35rem;width:-moz-fit-content;width:fit-content}}.DriverMap_mapInner__E7rZR{aspect-ratio:623.2/341.276;border-radius:var(--p-4);margin:0 auto;max-height:100%;max-width:100%;overflow:hidden;position:relative}.DriverMap_mapWorld__vmPp-{box-sizing:border-box;inset:0;position:absolute}.DriverMap_shimmerOverlay__UH2qz{z-index:20}.DriverMap_inTransition__lvYwJ{pointer-events:none}.DriverMap_worldDrivers__sZOIW{align-items:center;bottom:0;display:flex;gap:.5rem;padding:.5rem;position:absolute}.DriverMap_worldDrivers__sZOIW button{position:static!important;transform:none!important}.DriverMap_worldDrivers__sZOIW button>span{opacity:1!important;transform:none!important}";
|
|
4
|
+
var S = {"root":"DriverMap_root__JszhG","mapInner":"DriverMap_mapInner__E7rZR","mapWorld":"DriverMap_mapWorld__vmPp-","shimmerOverlay":"DriverMap_shimmerOverlay__UH2qz","inTransition":"DriverMap_inTransition__lvYwJ","worldDrivers":"DriverMap_worldDrivers__sZOIW"};
|
|
5
|
+
styleInject(css_248z);
|
|
6
|
+
|
|
7
|
+
export { S as default };
|