lytx 0.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/.env.example +37 -0
- package/README.md +486 -0
- package/alchemy.run.ts +155 -0
- package/cli/bootstrap-admin.ts +284 -0
- package/cli/deploy-staging.ts +692 -0
- package/cli/import-events.ts +628 -0
- package/cli/import-sites.ts +518 -0
- package/cli/index.ts +609 -0
- package/cli/init-db.ts +269 -0
- package/cli/migrate-to-durable-objects.ts +564 -0
- package/cli/migration-worker.ts +300 -0
- package/cli/performance-test.ts +588 -0
- package/cli/pg/client.ts +4 -0
- package/cli/pg/new-site.ts +153 -0
- package/cli/rollback-durable-objects.ts +622 -0
- package/cli/seed-data.ts +459 -0
- package/cli/setup.js +18 -0
- package/cli/setup.ts +463 -0
- package/cli/validate-migration.ts +200 -0
- package/cli/wrangler-migration.jsonc +28 -0
- package/db/adapter.ts +166 -0
- package/db/analytics_engine/client.ts +0 -0
- package/db/analytics_engine/sites.ts +0 -0
- package/db/client.ts +16 -0
- package/db/d1/client.ts +8 -0
- package/db/d1/drizzle.config.ts +35 -0
- package/db/d1/migrations/0000_true_maelstrom.sql +165 -0
- package/db/d1/migrations/0001_wonderful_bloodaxe.sql +12 -0
- package/db/d1/migrations/0002_late_frightful_four.sql +1 -0
- package/db/d1/migrations/0003_cuddly_obadiah_stane.sql +16 -0
- package/db/d1/migrations/0004_mute_stardust.sql +1 -0
- package/db/d1/migrations/0005_awesome_silvermane.sql +3 -0
- package/db/d1/migrations/0006_volatile_shriek.sql +2 -0
- package/db/d1/migrations/0007_superb_lila_cheney.sql +1 -0
- package/db/d1/migrations/0008_bitter_longshot.sql +17 -0
- package/db/d1/migrations/0009_wonderful_madame_masque.sql +28 -0
- package/db/d1/migrations/meta/0000_snapshot.json +1112 -0
- package/db/d1/migrations/meta/0001_snapshot.json +1187 -0
- package/db/d1/migrations/meta/0002_snapshot.json +1194 -0
- package/db/d1/migrations/meta/0003_snapshot.json +1296 -0
- package/db/d1/migrations/meta/0004_snapshot.json +1303 -0
- package/db/d1/migrations/meta/0005_snapshot.json +1325 -0
- package/db/d1/migrations/meta/0006_snapshot.json +1339 -0
- package/db/d1/migrations/meta/0007_snapshot.json +1347 -0
- package/db/d1/migrations/meta/0008_snapshot.json +1464 -0
- package/db/d1/migrations/meta/0009_snapshot.json +1648 -0
- package/db/d1/migrations/meta/_journal.json +76 -0
- package/db/d1/schema.ts +407 -0
- package/db/d1/sites.ts +374 -0
- package/db/d1/teamAiUsage.ts +101 -0
- package/db/d1/teams.ts +127 -0
- package/db/durable/drizzle.config.ts +8 -0
- package/db/durable/durableObjectClient.ts +480 -0
- package/db/durable/events.ts +100 -0
- package/db/durable/migrations/0000_fair_bucky.sql +38 -0
- package/db/durable/migrations/meta/0000_snapshot.json +278 -0
- package/db/durable/migrations/meta/_journal.json +13 -0
- package/db/durable/migrations/migrations.js +10 -0
- package/db/durable/schema.ts +5 -0
- package/db/durable/siteDurableObject.ts +1352 -0
- package/db/durable/types.ts +53 -0
- package/db/postgres/client.ts +13 -0
- package/db/postgres/drizzle.config.ts +12 -0
- package/db/postgres/migrations/0000_brainy_sprite.sql +116 -0
- package/db/postgres/migrations/meta/0000_snapshot.json +681 -0
- package/db/postgres/migrations/meta/_journal.json +13 -0
- package/db/postgres/schema.ts +145 -0
- package/db/postgres/sites.ts +118 -0
- package/db/tranformReports.ts +595 -0
- package/db/types.ts +55 -0
- package/endpoints/api_worker.tsx +1854 -0
- package/endpoints/site_do_worker.ts +11 -0
- package/index.d.ts +63 -0
- package/index.ts +83 -0
- package/lib/auth.ts +279 -0
- package/lib/geojson/world_countries.json +45307 -0
- package/lib/random_name.ts +41 -0
- package/lib/sendMail.ts +252 -0
- package/package.json +142 -0
- package/public/favicon.ico +0 -0
- package/public/images/android-chrome-192x192.png +0 -0
- package/public/images/android-chrome-512x512.png +0 -0
- package/public/images/apple-touch-icon.png +0 -0
- package/public/images/favicon-16x16.png +0 -0
- package/public/images/favicon-32x32.png +0 -0
- package/public/images/lytx_dark_dashboard.png +0 -0
- package/public/images/lytx_light_dashboard.png +0 -0
- package/public/images/safari-pinned-tab.svg +4 -0
- package/public/logo.png +0 -0
- package/public/site.webmanifest +26 -0
- package/public/sw.js +107 -0
- package/src/Document.tsx +86 -0
- package/src/api/ai_api.ts +1156 -0
- package/src/api/authMiddleware.ts +45 -0
- package/src/api/auth_api.ts +465 -0
- package/src/api/event_labels_api.ts +193 -0
- package/src/api/events_api.ts +210 -0
- package/src/api/queueWorker.ts +303 -0
- package/src/api/reports_api.ts +278 -0
- package/src/api/seed_api.ts +288 -0
- package/src/api/sites_api.ts +904 -0
- package/src/api/tag_api.ts +458 -0
- package/src/api/tag_api_v2.ts +289 -0
- package/src/api/team_api.ts +456 -0
- package/src/app/Dashboard.tsx +1339 -0
- package/src/app/Events.tsx +974 -0
- package/src/app/Explore.tsx +312 -0
- package/src/app/Layout.tsx +58 -0
- package/src/app/Settings.tsx +1302 -0
- package/src/app/components/DashboardCard.tsx +118 -0
- package/src/app/components/EditableCell.tsx +123 -0
- package/src/app/components/EventForm.tsx +93 -0
- package/src/app/components/MarketingFooter.tsx +49 -0
- package/src/app/components/MarketingNav.tsx +150 -0
- package/src/app/components/Nav.tsx +755 -0
- package/src/app/components/NewSiteSetup.tsx +298 -0
- package/src/app/components/SQLEditor.tsx +740 -0
- package/src/app/components/SiteSelector.tsx +126 -0
- package/src/app/components/SiteTag.tsx +42 -0
- package/src/app/components/SiteTagInstallCard.tsx +241 -0
- package/src/app/components/WorldMapCard.tsx +337 -0
- package/src/app/components/charts/ChartComponents.tsx +1481 -0
- package/src/app/components/charts/EventFunnel.tsx +45 -0
- package/src/app/components/charts/EventSummary.tsx +194 -0
- package/src/app/components/charts/SankeyFlows.tsx +72 -0
- package/src/app/components/marketing/CheckIcon.tsx +16 -0
- package/src/app/components/marketing/MarketingLayout.tsx +23 -0
- package/src/app/components/marketing/SectionHeading.tsx +35 -0
- package/src/app/components/reports/AskAiWorkspace.tsx +371 -0
- package/src/app/components/reports/CreateReportStarter.tsx +74 -0
- package/src/app/components/reports/DashboardRouteFiltersContext.tsx +14 -0
- package/src/app/components/reports/DashboardToolbar.tsx +154 -0
- package/src/app/components/reports/DashboardWorkspaceLayout.tsx +63 -0
- package/src/app/components/reports/DashboardWorkspaceShell.tsx +118 -0
- package/src/app/components/reports/ReportBuilderWorkspace.tsx +76 -0
- package/src/app/components/reports/custom/CustomReportBuilderPage.tsx +1667 -0
- package/src/app/components/reports/custom/ReportWidgetChart.tsx +297 -0
- package/src/app/components/reports/custom/buildWidgetSql.ts +151 -0
- package/src/app/components/reports/custom/chartPalettes.ts +18 -0
- package/src/app/components/reports/custom/types.ts +50 -0
- package/src/app/components/reports/reportBuilderMenuItems.ts +17 -0
- package/src/app/components/reports/useDashboardToolbarControls.tsx +235 -0
- package/src/app/components/ui/AlertBanner.tsx +101 -0
- package/src/app/components/ui/Button.tsx +55 -0
- package/src/app/components/ui/Card.tsx +80 -0
- package/src/app/components/ui/Input.tsx +72 -0
- package/src/app/components/ui/Link.tsx +23 -0
- package/src/app/components/ui/ReportBuilderMenu.tsx +246 -0
- package/src/app/components/ui/ThemeToggle.tsx +54 -0
- package/src/app/constants.ts +6 -0
- package/src/app/headers.ts +33 -0
- package/src/app/providers/AuthProvider.tsx +189 -0
- package/src/app/providers/ClientProviders.tsx +18 -0
- package/src/app/providers/QueryProvider.tsx +23 -0
- package/src/app/providers/ThemeProvider.tsx +88 -0
- package/src/app/utils/chartThemes.ts +146 -0
- package/src/app/utils/keybinds.ts +96 -0
- package/src/app/utils/media.tsx +24 -0
- package/src/client.tsx +114 -0
- package/src/config/createLytxAppConfig.ts +252 -0
- package/src/config/resourceNames.ts +88 -0
- package/src/db/index.ts +67 -0
- package/src/index.css +285 -0
- package/src/lib/featureFlags.ts +69 -0
- package/src/pages/GetStarted.tsx +290 -0
- package/src/pages/Home.tsx +268 -0
- package/src/pages/Login.tsx +283 -0
- package/src/pages/PrivacyPolicy.tsx +120 -0
- package/src/pages/Signup.tsx +267 -0
- package/src/pages/TermsOfService.tsx +126 -0
- package/src/pages/VerifyEmail.tsx +56 -0
- package/src/session/durableObject.ts +7 -0
- package/src/session/siteSchema.ts +86 -0
- package/src/session/types.ts +36 -0
- package/src/templates/README.md +80 -0
- package/src/templates/cleanFunctions.js +44 -0
- package/src/templates/embedFunctions.js +52 -0
- package/src/templates/lytx-shared.ts +662 -0
- package/src/templates/lytxpixel-core.ts +144 -0
- package/src/templates/lytxpixel.ts +267 -0
- package/src/templates/lytxpixelBrowser.js +634 -0
- package/src/templates/lytxpixelBrowser.mjs +634 -0
- package/src/templates/parseData.js +12 -0
- package/src/templates/script.ts +31 -0
- package/src/templates/template.tsx +50 -0
- package/src/templates/test.js +3 -0
- package/src/templates/trackWebEvents.ts +177 -0
- package/src/templates/vendors/clickcease.ts +8 -0
- package/src/templates/vendors/google.ts +174 -0
- package/src/templates/vendors/linkedin.ts +23 -0
- package/src/templates/vendors/meta.ts +56 -0
- package/src/templates/vendors/quantcast.ts +22 -0
- package/src/templates/vendors/simplfi.ts +7 -0
- package/src/types/app-context.ts +16 -0
- package/src/utilities/dashboardParams.ts +188 -0
- package/src/utilities/dashboardQueries.ts +537 -0
- package/src/utilities/dashboardTransforms.ts +167 -0
- package/src/utilities/dataValidation.ts +414 -0
- package/src/utilities/detector.ts +73 -0
- package/src/utilities/encrypt.ts +103 -0
- package/src/utilities/index.ts +13 -0
- package/src/utilities/parser.ts +117 -0
- package/src/utilities/performanceMonitoring.ts +570 -0
- package/src/utilities/route_interuptors.ts +24 -0
- package/src/worker.tsx +675 -0
- package/tsconfig.json +78 -0
- package/types/env.d.ts +16 -0
- package/types/rw.d.ts +7 -0
- package/types/shims.d.ts +53 -0
- package/types/vite.d.ts +19 -0
- package/vite/vite-plugin-pixel-bundle.ts +126 -0
- package/vite.config.ts +53 -0
- package/worker-configuration.d.ts +8401 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
4
|
+
import {
|
|
5
|
+
ComposableMap,
|
|
6
|
+
Geographies,
|
|
7
|
+
Geography,
|
|
8
|
+
Marker,
|
|
9
|
+
ZoomableGroup,
|
|
10
|
+
} from "react-simple-maps";
|
|
11
|
+
import { DashboardCard } from "@components/DashboardCard";
|
|
12
|
+
|
|
13
|
+
// [lng, lat] centroids for countries keyed by ISO-2 code
|
|
14
|
+
const COUNTRY_CENTROIDS: Record<string, [number, number]> = {
|
|
15
|
+
AF: [67.7, 33.9], AL: [20.2, 41.2], DZ: [3.0, 28.0], AO: [17.5, -12.3],
|
|
16
|
+
AR: [-63.6, -38.4], AM: [45.0, 40.1], AU: [133.8, -25.3], AT: [14.6, 47.5],
|
|
17
|
+
AZ: [47.6, 40.1], BD: [90.4, 23.7], BY: [27.9, 53.7], BE: [4.5, 50.5],
|
|
18
|
+
BZ: [-88.5, 17.2], BJ: [2.3, 9.3], BT: [90.4, 27.5], BO: [-65.0, -17.0],
|
|
19
|
+
BA: [17.7, 43.9], BW: [24.7, -22.3], BR: [-51.9, -14.2], BN: [114.7, 4.9],
|
|
20
|
+
BG: [25.5, 42.7], BF: [-1.6, 12.4], BI: [29.9, -3.4], KH: [105.0, 12.6],
|
|
21
|
+
CM: [12.4, 5.9], CA: [-106.3, 56.1], CF: [21.0, 6.6], TD: [18.7, 15.5],
|
|
22
|
+
CL: [-71.5, -35.7], CN: [104.2, 35.9], CO: [-74.3, 4.6], CR: [-84.0, 10.0],
|
|
23
|
+
HR: [15.2, 45.1], CU: [-77.8, 21.5], CY: [33.4, 35.1], CZ: [15.5, 49.8],
|
|
24
|
+
CD: [21.8, -4.0], DK: [9.5, 56.3], DJ: [42.6, 11.8], DO: [-70.2, 18.7],
|
|
25
|
+
EC: [-78.2, -1.8], EG: [30.8, 26.8], SV: [-88.9, 13.8], GQ: [10.3, 1.6],
|
|
26
|
+
ER: [39.8, 15.2], EE: [25.0, 58.6], ET: [40.5, 9.1], FI: [25.7, 61.9],
|
|
27
|
+
FR: [2.2, 46.2], GA: [11.6, -0.8], GM: [-15.3, 13.4], GE: [43.4, 42.3],
|
|
28
|
+
DE: [10.5, 51.2], GH: [-1.0, 7.9], GR: [21.8, 39.1], GL: [-42.6, 71.7],
|
|
29
|
+
GT: [-90.2, 15.8], GN: [-9.7, 9.9], GW: [-15.2, 12.0], GY: [-58.9, 5.0],
|
|
30
|
+
HT: [-72.3, 19.1], HN: [-86.2, 15.2], HU: [19.5, 47.2], IS: [-19.0, 65.0],
|
|
31
|
+
IN: [79.0, 21.0], ID: [114.0, -0.8], IR: [53.7, 32.4], IQ: [43.7, 33.2],
|
|
32
|
+
IE: [-8.2, 53.4], IL: [34.9, 31.0], IT: [12.6, 41.9], CI: [-5.5, 7.5],
|
|
33
|
+
JM: [-77.3, 18.1], JP: [138.3, 36.2], JO: [36.2, 30.6], KZ: [66.9, 48.0],
|
|
34
|
+
KE: [37.9, 0.0], KW: [47.5, 29.3], KG: [74.8, 41.2], LA: [102.5, 19.9],
|
|
35
|
+
LV: [24.6, 56.9], LB: [35.9, 33.9], LS: [28.2, -29.6], LR: [-9.4, 6.4],
|
|
36
|
+
LY: [17.2, 26.3], LT: [23.9, 55.2], LU: [6.1, 49.8], MK: [21.7, 41.5],
|
|
37
|
+
MG: [46.9, -18.8], MW: [34.3, -13.3], MY: [101.7, 4.2], ML: [-4.0, 17.6],
|
|
38
|
+
MR: [-10.9, 21.0], MX: [-102.6, 23.6], MD: [28.4, 47.4], MN: [103.8, 46.9],
|
|
39
|
+
ME: [19.4, 42.7], MA: [-7.1, 31.8], MZ: [35.5, -18.7], MM: [96.0, 19.8],
|
|
40
|
+
NA: [18.5, -22.0], NP: [84.1, 28.4], NL: [5.3, 52.1], NZ: [174.9, -40.9],
|
|
41
|
+
NI: [-85.2, 12.9], NE: [8.1, 17.6], NG: [8.7, 9.1], NO: [8.5, 60.5],
|
|
42
|
+
OM: [55.9, 21.5], PK: [69.3, 30.4], PA: [-80.8, 8.5], PG: [143.9, -6.3],
|
|
43
|
+
PY: [-58.4, -23.4], PE: [-75.0, -9.2], PH: [121.8, 12.9], PL: [19.1, 51.9],
|
|
44
|
+
PT: [-8.2, 39.4], QA: [51.2, 25.4], RO: [24.9, 45.9], RU: [105.3, 61.5],
|
|
45
|
+
RW: [29.9, -1.9], SA: [45.1, 23.9], SN: [-14.5, 14.5], RS: [21.0, 44.0],
|
|
46
|
+
SL: [-11.8, 8.5], SK: [19.7, 48.7], SI: [14.6, 46.2], SO: [46.2, 5.2],
|
|
47
|
+
ZA: [22.9, -30.6], KR: [128.0, 35.9], SS: [31.3, 6.9], ES: [-3.7, 40.5],
|
|
48
|
+
LK: [80.8, 7.9], SD: [30.2, 12.9], SR: [-56.0, 4.0], SZ: [31.5, -26.5],
|
|
49
|
+
SE: [18.6, 60.1], CH: [8.2, 46.8], SY: [38.0, 35.0], TW: [121.0, 23.7],
|
|
50
|
+
TJ: [71.3, 38.9], TZ: [34.9, -6.4], TH: [100.5, 15.9], TG: [1.2, 8.6],
|
|
51
|
+
TT: [-61.2, 10.7], TN: [9.5, 33.9], TR: [35.2, 38.9], TM: [58.4, 38.0],
|
|
52
|
+
UG: [32.3, 1.4], UA: [31.2, 48.4], AE: [53.8, 23.4], GB: [-3.4, 55.4],
|
|
53
|
+
US: [-95.7, 37.1], UY: [-55.8, -32.5], UZ: [64.6, 41.4], VE: [-66.6, 6.4],
|
|
54
|
+
VN: [108.3, 14.1], YE: [48.5, 15.6], ZM: [27.8, -13.1], ZW: [29.2, -19.0],
|
|
55
|
+
XK: [21.0, 42.6], PS: [35.2, 31.9],
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const ISO2_TO_GEOJSON_NAME: Record<string, string> = {
|
|
59
|
+
US: "USA", GB: "UK", KR: "Korea", KP: "Korea", CI: "Ivory Coast",
|
|
60
|
+
BS: "The Bahamas", SZ: "Swaziland", MK: "Macedonia", TL: "East Timor",
|
|
61
|
+
FK: "Falkland Islands", NC: "New Caledonia", PG: "Papua New Guinea",
|
|
62
|
+
SB: "Solomon Islands", GQ: "Equatorial Guinea", GW: "Guinea Bissau",
|
|
63
|
+
BA: "Bosnia and Herzegovina", TT: "Trinidad and Tobago",
|
|
64
|
+
CF: "Central African Republic", CD: "Democratic Republic of the Congo",
|
|
65
|
+
CG: "Republic of the Congo", AE: "United Arab Emirates", SA: "Saudi Arabia",
|
|
66
|
+
SS: "South Sudan", ZA: "South Africa", SL: "Sierra Leone", BF: "Burkina Faso",
|
|
67
|
+
LK: "Sri Lanka", DO: "Dominican Republic", SV: "El Salvador", CR: "Costa Rica",
|
|
68
|
+
WS: "Western Sahara", PS: "West Bank", NZ: "New Zealand",
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const regionNames = (() => {
|
|
72
|
+
try {
|
|
73
|
+
return new Intl.DisplayNames(["en"], { type: "region" });
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
})();
|
|
78
|
+
|
|
79
|
+
function iso2ToDisplayName(code: string): string {
|
|
80
|
+
const upper = code.trim().toUpperCase();
|
|
81
|
+
return regionNames?.of(upper) ?? ISO2_TO_GEOJSON_NAME[upper] ?? upper;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface TooltipState {
|
|
85
|
+
x: number;
|
|
86
|
+
y: number;
|
|
87
|
+
name: string;
|
|
88
|
+
value: number;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface BubbleDatum {
|
|
92
|
+
iso2: string;
|
|
93
|
+
name: string;
|
|
94
|
+
coordinates: [number, number];
|
|
95
|
+
value: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const WorldMapCard = React.memo(function WorldMapCard({
|
|
99
|
+
aggregatedCountries,
|
|
100
|
+
isDark,
|
|
101
|
+
metricLabel = "visitors",
|
|
102
|
+
height = 380,
|
|
103
|
+
embedded = false,
|
|
104
|
+
}: {
|
|
105
|
+
aggregatedCountries: Array<[string, number]>;
|
|
106
|
+
isDark: boolean;
|
|
107
|
+
metricLabel?: string;
|
|
108
|
+
height?: number;
|
|
109
|
+
embedded?: boolean;
|
|
110
|
+
}) {
|
|
111
|
+
const [geoData, setGeoData] = useState<any>(null);
|
|
112
|
+
const [zoom, setZoom] = useState(1);
|
|
113
|
+
const [center, setCenter] = useState<[number, number]>([0, 0]);
|
|
114
|
+
const [tooltip, setTooltip] = useState<TooltipState | null>(null);
|
|
115
|
+
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
import("@lib/geojson/world_countries.json").then((mod) => {
|
|
118
|
+
setGeoData(mod.default || mod);
|
|
119
|
+
});
|
|
120
|
+
}, []);
|
|
121
|
+
|
|
122
|
+
const bubbles = useMemo<BubbleDatum[]>(() => {
|
|
123
|
+
return aggregatedCountries
|
|
124
|
+
.map(([iso2, count]) => {
|
|
125
|
+
const upper = iso2.trim().toUpperCase();
|
|
126
|
+
const coords = COUNTRY_CENTROIDS[upper];
|
|
127
|
+
if (!coords || count <= 0) return null;
|
|
128
|
+
return {
|
|
129
|
+
iso2: upper,
|
|
130
|
+
name: iso2ToDisplayName(upper),
|
|
131
|
+
coordinates: coords,
|
|
132
|
+
value: count,
|
|
133
|
+
};
|
|
134
|
+
})
|
|
135
|
+
.filter((d): d is BubbleDatum => d !== null)
|
|
136
|
+
.toSorted((a, b) => b.value - a.value);
|
|
137
|
+
}, [aggregatedCountries]);
|
|
138
|
+
|
|
139
|
+
const maxValue = useMemo(() => {
|
|
140
|
+
if (!bubbles.length) return 1;
|
|
141
|
+
return Math.max(...bubbles.map((b) => b.value));
|
|
142
|
+
}, [bubbles]);
|
|
143
|
+
|
|
144
|
+
const getRadius = useCallback(
|
|
145
|
+
(value: number) => {
|
|
146
|
+
const minR = 4;
|
|
147
|
+
const maxR = 24;
|
|
148
|
+
return minR + (maxR - minR) * Math.sqrt(value / maxValue);
|
|
149
|
+
},
|
|
150
|
+
[maxValue],
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const handleZoomIn = useCallback(() => {
|
|
154
|
+
setZoom((z) => Math.min(z * 1.5, 8));
|
|
155
|
+
}, []);
|
|
156
|
+
|
|
157
|
+
const handleZoomOut = useCallback(() => {
|
|
158
|
+
setZoom((z) => Math.max(z / 1.5, 1));
|
|
159
|
+
}, []);
|
|
160
|
+
|
|
161
|
+
const handleReset = useCallback(() => {
|
|
162
|
+
setZoom(1);
|
|
163
|
+
setCenter([0, 0]);
|
|
164
|
+
}, []);
|
|
165
|
+
|
|
166
|
+
if (!geoData) {
|
|
167
|
+
if (embedded) {
|
|
168
|
+
return (
|
|
169
|
+
<div
|
|
170
|
+
style={{ height: `${height}px` }}
|
|
171
|
+
className="w-full rounded-md bg-[var(--theme-bg-secondary)] animate-pulse"
|
|
172
|
+
/>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<DashboardCard title="Visitor Map" titleAs="h3">
|
|
178
|
+
<div
|
|
179
|
+
style={{ height: `${height}px` }}
|
|
180
|
+
className="w-full rounded-md bg-[var(--theme-bg-secondary)] animate-pulse"
|
|
181
|
+
/>
|
|
182
|
+
</DashboardCard>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const baseFill = isDark ? "rgba(55,65,81,0.5)" : "rgba(229,231,235,0.8)";
|
|
187
|
+
const borderColor = isDark ? "rgba(255,255,255,0.1)" : "rgba(0,0,0,0.08)";
|
|
188
|
+
const bubbleFill = isDark ? "rgba(249,115,22,0.55)" : "rgba(249,115,22,0.45)";
|
|
189
|
+
const bubbleStroke = isDark ? "rgba(253,186,116,0.8)" : "rgba(234,88,12,0.6)";
|
|
190
|
+
|
|
191
|
+
const mapCanvas = (
|
|
192
|
+
<div className="relative overflow-hidden rounded-md" style={{ height: `${height}px` }}>
|
|
193
|
+
<div className="absolute top-2 right-2 z-10 flex flex-col gap-1">
|
|
194
|
+
<button
|
|
195
|
+
type="button"
|
|
196
|
+
onClick={handleZoomIn}
|
|
197
|
+
className="w-7 h-7 flex items-center justify-center rounded bg-[var(--theme-card-bg)] border border-[var(--theme-card-border)] text-[var(--theme-text-primary)] hover:bg-[var(--theme-bg-secondary)] transition-colors text-sm font-bold"
|
|
198
|
+
aria-label="Zoom in"
|
|
199
|
+
>
|
|
200
|
+
+
|
|
201
|
+
</button>
|
|
202
|
+
<button
|
|
203
|
+
type="button"
|
|
204
|
+
onClick={handleZoomOut}
|
|
205
|
+
className="w-7 h-7 flex items-center justify-center rounded bg-[var(--theme-card-bg)] border border-[var(--theme-card-border)] text-[var(--theme-text-primary)] hover:bg-[var(--theme-bg-secondary)] transition-colors text-sm font-bold"
|
|
206
|
+
aria-label="Zoom out"
|
|
207
|
+
>
|
|
208
|
+
−
|
|
209
|
+
</button>
|
|
210
|
+
{zoom > 1 && (
|
|
211
|
+
<button
|
|
212
|
+
type="button"
|
|
213
|
+
onClick={handleReset}
|
|
214
|
+
className="w-7 h-7 flex items-center justify-center rounded bg-[var(--theme-card-bg)] border border-[var(--theme-card-border)] text-[var(--theme-text-secondary)] hover:bg-[var(--theme-bg-secondary)] transition-colors text-[10px] font-semibold"
|
|
215
|
+
aria-label="Reset zoom"
|
|
216
|
+
>
|
|
217
|
+
↺
|
|
218
|
+
</button>
|
|
219
|
+
)}
|
|
220
|
+
</div>
|
|
221
|
+
|
|
222
|
+
{tooltip && (
|
|
223
|
+
<div
|
|
224
|
+
className="pointer-events-none absolute z-20"
|
|
225
|
+
style={{
|
|
226
|
+
left: tooltip.x,
|
|
227
|
+
top: tooltip.y,
|
|
228
|
+
transform: "translate(-50%, -110%)",
|
|
229
|
+
}}
|
|
230
|
+
>
|
|
231
|
+
<div
|
|
232
|
+
style={{
|
|
233
|
+
padding: "5px 10px",
|
|
234
|
+
background: isDark ? "#484743" : "#fff",
|
|
235
|
+
color: isDark ? "#fff" : "#111827",
|
|
236
|
+
border: `1px solid ${isDark ? "#575353" : "#E5E7EB"}`,
|
|
237
|
+
borderRadius: "6px",
|
|
238
|
+
fontSize: "12px",
|
|
239
|
+
fontWeight: 600,
|
|
240
|
+
whiteSpace: "nowrap",
|
|
241
|
+
}}
|
|
242
|
+
>
|
|
243
|
+
{tooltip.name}: {tooltip.value.toLocaleString()} {metricLabel}
|
|
244
|
+
</div>
|
|
245
|
+
</div>
|
|
246
|
+
)}
|
|
247
|
+
|
|
248
|
+
<ComposableMap
|
|
249
|
+
projection="geoEqualEarth"
|
|
250
|
+
projectionConfig={{ scale: 160 }}
|
|
251
|
+
width={800}
|
|
252
|
+
height={height}
|
|
253
|
+
style={{ width: "100%", height: "100%" }}
|
|
254
|
+
>
|
|
255
|
+
<ZoomableGroup
|
|
256
|
+
zoom={zoom}
|
|
257
|
+
center={center}
|
|
258
|
+
onMoveEnd={({ zoom: z, coordinates }: { zoom: number; coordinates: [number, number] | number[] }) => {
|
|
259
|
+
setZoom(z);
|
|
260
|
+
if (Array.isArray(coordinates) && coordinates.length === 2) {
|
|
261
|
+
setCenter([coordinates[0], coordinates[1]]);
|
|
262
|
+
}
|
|
263
|
+
}}
|
|
264
|
+
maxZoom={8}
|
|
265
|
+
>
|
|
266
|
+
<Geographies geography={geoData}>
|
|
267
|
+
{({ geographies }: { geographies: Array<{ rsmKey: string }> }) =>
|
|
268
|
+
geographies.map((geo: { rsmKey: string }) => (
|
|
269
|
+
<Geography
|
|
270
|
+
key={geo.rsmKey}
|
|
271
|
+
geography={geo}
|
|
272
|
+
fill={baseFill}
|
|
273
|
+
stroke={borderColor}
|
|
274
|
+
strokeWidth={0.4}
|
|
275
|
+
style={{
|
|
276
|
+
default: { outline: "none" },
|
|
277
|
+
hover: { outline: "none", fill: baseFill },
|
|
278
|
+
pressed: { outline: "none" },
|
|
279
|
+
}}
|
|
280
|
+
/>
|
|
281
|
+
))
|
|
282
|
+
}
|
|
283
|
+
</Geographies>
|
|
284
|
+
|
|
285
|
+
{bubbles.map((bubble) => (
|
|
286
|
+
<Marker key={bubble.iso2} coordinates={bubble.coordinates}>
|
|
287
|
+
<circle
|
|
288
|
+
r={getRadius(bubble.value) / zoom}
|
|
289
|
+
fill={bubbleFill}
|
|
290
|
+
stroke={bubbleStroke}
|
|
291
|
+
strokeWidth={1 / zoom}
|
|
292
|
+
onMouseEnter={(evt) => {
|
|
293
|
+
const svg = (evt.target as SVGElement).closest("svg");
|
|
294
|
+
if (!svg) return;
|
|
295
|
+
const rect = svg.getBoundingClientRect();
|
|
296
|
+
setTooltip({
|
|
297
|
+
x: evt.clientX - rect.left,
|
|
298
|
+
y: evt.clientY - rect.top,
|
|
299
|
+
name: bubble.name,
|
|
300
|
+
value: bubble.value,
|
|
301
|
+
});
|
|
302
|
+
}}
|
|
303
|
+
onMouseMove={(evt) => {
|
|
304
|
+
const svg = (evt.target as SVGElement).closest("svg");
|
|
305
|
+
if (!svg) return;
|
|
306
|
+
const rect = svg.getBoundingClientRect();
|
|
307
|
+
setTooltip({
|
|
308
|
+
x: evt.clientX - rect.left,
|
|
309
|
+
y: evt.clientY - rect.top,
|
|
310
|
+
name: bubble.name,
|
|
311
|
+
value: bubble.value,
|
|
312
|
+
});
|
|
313
|
+
}}
|
|
314
|
+
onMouseLeave={() => setTooltip(null)}
|
|
315
|
+
style={{ cursor: "pointer" }}
|
|
316
|
+
/>
|
|
317
|
+
</Marker>
|
|
318
|
+
))}
|
|
319
|
+
</ZoomableGroup>
|
|
320
|
+
</ComposableMap>
|
|
321
|
+
</div>
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
if (embedded) {
|
|
325
|
+
return mapCanvas;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return (
|
|
329
|
+
<DashboardCard
|
|
330
|
+
title="Visitor Map"
|
|
331
|
+
titleAs="h3"
|
|
332
|
+
empty={bubbles.length === 0}
|
|
333
|
+
>
|
|
334
|
+
{mapCanvas}
|
|
335
|
+
</DashboardCard>
|
|
336
|
+
);
|
|
337
|
+
});
|