DDBS UI
dashboard

Route Map

A schematic SVG route map on a dotted grid: places as dots, the selected route bold (solid when approved, dotted when pending) and other routes faint.

npx shadcn@latest add https://ui.develop-better-solutions.com/r/dash-route-map.json
Fullscreen
HubPhiladelphiaWashingtonAtlanta
ApprovedPending approvalOther routes

Usage

dash-route-map-example.tsx
"use client";

import { useState } from "react";
import { DashRouteMap } from "@dbs/ui";
import { DashScope } from "./_store";

const NODES = [
  { id: "ny", label: "Hub", x: 0.82, y: 0.3, hub: true },
  { id: "bos", label: "Boston", x: 0.9, y: 0.12 },
  { id: "phl", label: "Philadelphia", x: 0.72, y: 0.42 },
  { id: "dc", label: "Washington", x: 0.62, y: 0.55 },
  { id: "chi", label: "Chicago", x: 0.2, y: 0.22 },
  { id: "atl", label: "Atlanta", x: 0.34, y: 0.86 },
];

const ROUTES = [
  { id: "r1", name: "North loop", stops: ["ny", "bos"], approved: true },
  { id: "r2", name: "Coast run", stops: ["ny", "phl", "dc", "atl"], approved: true },
  { id: "r3", name: "Midwest link", stops: ["ny", "chi"], approved: false },
];

export default function DashRouteMapExample() {
  const [sel, setSel] = useState("r2");
  return (
    <DashScope minHeight={0}>
      <div className="mb-3 flex flex-wrap gap-2">
        {ROUTES.map((r) => (
          <button key={r.id} type="button" aria-pressed={sel === r.id} onClick={() => setSel(r.id)} className={`rounded-full border px-4 py-1.5 text-[13px] ${sel === r.id ? "border-[var(--dash-bar)] bg-[var(--dash-green-soft)]" : "border-[var(--dash-line)]"}`}>
            {r.name}
          </button>
        ))}
      </div>
      <DashRouteMap nodes={NODES} routes={ROUTES} selectedId={sel} legend={{ approved: "Approved", pending: "Pending approval", other: "Other routes" }} />
    </DashScope>
  );
}