Spaces:
Running
Running
File size: 28,671 Bytes
c2ea5ed 738bb6b c2ea5ed 738bb6b c2ea5ed 738bb6b c2ea5ed 738bb6b c2ea5ed 738bb6b c2ea5ed 738bb6b c2ea5ed 738bb6b c2ea5ed 738bb6b c2ea5ed 738bb6b c2ea5ed 738bb6b c2ea5ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 |
import React, {
useState,
useEffect,
useCallback,
useMemo,
useRef,
} from "react";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Eye, EyeOff, Split, Layers } from "lucide-react";
import { LoadingSpinner } from "@/components/shared/LoadingSpinner";
import { api } from "@/lib/api";
import {
AvailableGraph,
GraphComparisonResults,
UniversalGraphData,
GraphDetailsResponse,
} from "@/types";
import { getGraphDataAdapter } from "@/lib/graph-data-adapters";
import { CytoscapeGraphCore } from "@/lib/cytoscape-graph-core";
import { createKnowledgeGraphConfig } from "@/lib/graph-config-factory";
import { GraphSelectionCallbacks } from "@/types/graph-visualization";
const truncateGraphName = (
name: string,
maxLength: number = 30
): string => {
if (!name) return "";
if (name.length <= maxLength) return name;
const start = name.substring(0, Math.floor(maxLength * 0.6));
const end = name.substring(name.length - Math.floor(maxLength * 0.3));
return `${start}...${end}`;
};
// Prefer human-friendly system name where available
const getGraphDisplayName = (graph?: AvailableGraph | null) => {
if (!graph) return "";
return graph.system_name && graph.system_name.trim().length > 0
? graph.system_name
: graph.filename;
};
interface VisualComparisonProps {
graph1: AvailableGraph;
graph2: AvailableGraph;
comparisonResults?: GraphComparisonResults | null;
}
interface MergedGraphData extends UniversalGraphData {
mergeStats: {
totalNodes: number;
totalLinks: number;
commonNodes: number;
commonLinks: number;
graph1UniqueNodes: number;
graph1UniqueLinks: number;
graph2UniqueNodes: number;
graph2UniqueLinks: number;
};
}
// Component wrapper for CytoscapeGraphCore
const CytoscapeWrapper: React.FC<{
data: UniversalGraphData;
width?: number;
height?: number;
}> = ({ data, width = 800, height = 600 }) => {
const containerRef = useRef<HTMLDivElement>(null);
const cytoscapeRef = useRef<CytoscapeGraphCore | null>(null);
const [isInitialized, setIsInitialized] = useState(false);
useEffect(() => {
const initializeVisualization = async () => {
if (!containerRef.current || !data || data.nodes.length === 0) return;
try {
// Wait for layout to settle
await new Promise((resolve) => setTimeout(resolve, 100));
const config = createKnowledgeGraphConfig({
width,
height,
showToolbar: false,
showSidebar: false,
showStats: false,
enableSearch: false,
enableZoom: true,
enablePan: true,
enableDrag: true,
enableSelection: true,
});
const selectionCallbacks: GraphSelectionCallbacks = {
onNodeSelect: (node) => {
console.log("Node selected:", node);
},
onLinkSelect: (link) => {
console.log("Link selected:", link);
},
onClearSelection: () => {
console.log("Selection cleared");
},
};
// Clean up existing instance
if (cytoscapeRef.current) {
cytoscapeRef.current.destroy();
cytoscapeRef.current = null;
}
cytoscapeRef.current = new CytoscapeGraphCore(
containerRef.current,
config,
selectionCallbacks
);
cytoscapeRef.current.updateGraph(data, true);
setIsInitialized(true);
} catch (err) {
console.error("Error initializing Cytoscape visualization:", err);
}
};
initializeVisualization();
return () => {
if (cytoscapeRef.current) {
cytoscapeRef.current.destroy();
cytoscapeRef.current = null;
}
setIsInitialized(false);
};
}, [data, width, height]);
return (
<div
ref={containerRef}
className="w-full h-full bg-white border rounded-lg relative overflow-hidden"
style={{ minHeight: `${height}px` }}
>
{!isInitialized && (
<div className="absolute inset-0 flex items-center justify-center">
<LoadingSpinner size="sm" />
</div>
)}
</div>
);
};
export const VisualComparison: React.FC<VisualComparisonProps> = ({
graph1,
graph2,
comparisonResults,
}) => {
const [graph1Data, setGraph1Data] = useState<UniversalGraphData | null>(null);
const [graph2Data, setGraph2Data] = useState<UniversalGraphData | null>(null);
const [mergedData, setMergedData] = useState<MergedGraphData | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [viewMode, setViewMode] = useState<"side-by-side" | "overlay">(
"side-by-side"
);
const [highlightMode, setHighlightMode] = useState<
"none" | "common" | "unique"
>("none");
// Function to merge two graphs for overlay visualization
const mergeGraphsForOverlay = useCallback(
(
graph1Data: UniversalGraphData,
graph2Data: UniversalGraphData
): MergedGraphData => {
const entityMap = new Map<string, any>();
const relationMap = new Map<string, any>();
// Add graph1 entities
graph1Data.nodes.forEach((entity) => {
const key = `${entity.type || "unknown"}:${
entity.label || entity.name || entity.id
}`.toLowerCase();
if (!entityMap.has(key)) {
entityMap.set(key, {
...entity,
id: `merged-${entity.id}`,
originalId: entity.id,
source: "graph1",
isCommon: false,
graphSource: "graph1",
});
}
});
// Add graph2 entities and mark common ones
graph2Data.nodes.forEach((entity) => {
const key = `${entity.type || "unknown"}:${
entity.label || entity.name || entity.id
}`.toLowerCase();
if (entityMap.has(key)) {
const existing = entityMap.get(key);
existing.isCommon = true;
existing.source = "common";
existing.graphSource = "common";
} else {
entityMap.set(key, {
...entity,
id: `merged-${entity.id}`,
originalId: entity.id,
source: "graph2",
isCommon: false,
graphSource: "graph2",
});
}
});
const allEntities = Array.from(entityMap.values());
// Create mapping from original IDs to merged entities
const originalToMergedMap = new Map<string, any>();
allEntities.forEach((entity) => {
originalToMergedMap.set(entity.originalId, entity);
});
// Add graph1 relations
graph1Data.links.forEach((relation) => {
const sourceId =
typeof relation.source === "string"
? relation.source
: relation.source.id;
const targetId =
typeof relation.target === "string"
? relation.target
: relation.target.id;
const sourceEntity = originalToMergedMap.get(sourceId);
const targetEntity = originalToMergedMap.get(targetId);
if (sourceEntity && targetEntity) {
const key = `${relation.type || relation.label || "unknown"}:${
sourceEntity.label
}:${targetEntity.label}`.toLowerCase();
if (!relationMap.has(key)) {
relationMap.set(key, {
...relation,
id: `merged-${relation.id}`,
originalId: relation.id,
source: sourceEntity.id,
target: targetEntity.id,
graphSource: "graph1",
isCommon: false,
});
}
}
});
// Add graph2 relations and mark common ones
graph2Data.links.forEach((relation) => {
const sourceId =
typeof relation.source === "string"
? relation.source
: relation.source.id;
const targetId =
typeof relation.target === "string"
? relation.target
: relation.target.id;
const sourceEntity = originalToMergedMap.get(sourceId);
const targetEntity = originalToMergedMap.get(targetId);
if (sourceEntity && targetEntity) {
const key = `${relation.type || relation.label || "unknown"}:${
sourceEntity.label
}:${targetEntity.label}`.toLowerCase();
if (relationMap.has(key)) {
const existing = relationMap.get(key);
existing.isCommon = true;
existing.graphSource = "common";
} else {
relationMap.set(key, {
...relation,
id: `merged-${relation.id}`,
originalId: relation.id,
source: sourceEntity.id,
target: targetEntity.id,
graphSource: "graph2",
isCommon: false,
});
}
}
});
const allRelations = Array.from(relationMap.values());
// Calculate statistics
const commonNodes = allEntities.filter((e) => e.isCommon).length;
const graph1UniqueNodes = allEntities.filter(
(e) => e.graphSource === "graph1"
).length;
const graph2UniqueNodes = allEntities.filter(
(e) => e.graphSource === "graph2"
).length;
const commonLinks = allRelations.filter((r) => r.isCommon).length;
const graph1UniqueLinks = allRelations.filter(
(r) => r.graphSource === "graph1"
).length;
const graph2UniqueLinks = allRelations.filter(
(r) => r.graphSource === "graph2"
).length;
return {
nodes: allEntities,
links: allRelations,
metadata: {
...graph1Data.metadata,
merged: true,
graph1Name: getGraphDisplayName(graph1),
graph2Name: getGraphDisplayName(graph2),
},
mergeStats: {
totalNodes: allEntities.length,
totalLinks: allRelations.length,
commonNodes,
commonLinks,
graph1UniqueNodes,
graph1UniqueLinks,
graph2UniqueNodes,
graph2UniqueLinks,
},
};
},
[graph1.filename, graph2.filename, graph1.system_name, graph2.system_name]
);
// Function to apply overlay coloring based on element source
const applyOverlayColoring = useCallback(
(data: MergedGraphData, mode: string): UniversalGraphData => {
return {
...data,
nodes: data.nodes.map((node) => ({
...node,
color: getOverlayNodeColor(node, mode),
})),
links: data.links.map((link) => ({
...link,
color: getOverlayLinkColor(link, mode),
})),
};
},
[]
);
const getOverlayNodeColor = (node: any, mode: string): string => {
if (mode === "none") return "#4f46e5"; // Default blue
if (node.isCommon) {
return mode === "common" ? "#22c55e" : "#94a3b8"; // Green for common, gray when highlighting unique
} else {
if (mode === "unique") {
return node.graphSource === "graph1" ? "#3b82f6" : "#f59e0b"; // Blue for graph1, orange for graph2
} else {
return "#94a3b8"; // Gray when highlighting common
}
}
};
const getOverlayLinkColor = (link: any, mode: string): string => {
if (mode === "none") return "#64748b"; // Default gray
if (link.isCommon) {
return mode === "common" ? "#22c55e" : "#94a3b8";
} else {
if (mode === "unique") {
return link.graphSource === "graph1" ? "#3b82f6" : "#f59e0b";
} else {
return "#94a3b8";
}
}
};
const loadGraphData = useCallback(async () => {
try {
setIsLoading(true);
setError(null);
const [data1, data2] = (await Promise.all([
api.graphComparison.getGraphDetails(graph1.id),
api.graphComparison.getGraphDetails(graph2.id),
])) as [GraphDetailsResponse, GraphDetailsResponse];
// Convert to UniversalGraphData format using auto-detecting adapters
const adapter1 = getGraphDataAdapter(undefined, data1);
const adapter2 = getGraphDataAdapter(undefined, data2);
const universalData1 = adapter1.adapt(data1);
const universalData2 = adapter2.adapt(data2);
console.log("VisualComparison: Graph data loaded successfully", {
graph1: {
nodes: universalData1.nodes.length,
links: universalData1.links.length,
},
graph2: {
nodes: universalData2.nodes.length,
links: universalData2.links.length,
},
});
setGraph1Data(universalData1);
setGraph2Data(universalData2);
// Create merged data for overlay
const merged = mergeGraphsForOverlay(universalData1, universalData2);
setMergedData(merged);
console.log("VisualComparison: Merged data created", {
totalNodes: merged.mergeStats.totalNodes,
totalLinks: merged.mergeStats.totalLinks,
commonNodes: merged.mergeStats.commonNodes,
commonLinks: merged.mergeStats.commonLinks,
});
} catch (err) {
setError(
err instanceof Error ? err.message : "Failed to load graph data"
);
} finally {
setIsLoading(false);
}
}, [graph1.id, graph2.id, mergeGraphsForOverlay]);
useEffect(() => {
// Add a small delay to ensure the layout has settled before loading data
const timer = setTimeout(loadGraphData, 100);
return () => clearTimeout(timer);
}, [loadGraphData]);
// Define getHighlightedData before using it in useMemo hooks
const getHighlightedData = useCallback(
(
originalData: UniversalGraphData,
otherData: UniversalGraphData,
mode: string
): UniversalGraphData => {
if (mode === "none") return originalData;
// Compare nodes by label (normalized)
const otherNodeLabels = new Set(
otherData.nodes.map((n) =>
(n.label || n.name || n.id || "").toLowerCase()
)
);
// Compare links by normalized source label, link label, and target label
const otherLinkKeys = new Set(
otherData.links.map((link) => {
const sourceId =
typeof link.source === "string" ? link.source : link.source.id;
const targetId =
typeof link.target === "string" ? link.target : link.target.id;
// Find the actual node labels for source and target
const sourceNode = otherData.nodes.find((n) => n.id === sourceId);
const targetNode = otherData.nodes.find((n) => n.id === targetId);
const sourceLabel = (
sourceNode?.label ||
sourceNode?.name ||
sourceId ||
""
).toLowerCase();
const targetLabel = (
targetNode?.label ||
targetNode?.name ||
targetId ||
""
).toLowerCase();
const linkLabel = (link.label || link.type || "").toLowerCase();
return `${sourceLabel}-${linkLabel}-${targetLabel}`;
})
);
return {
...originalData,
nodes: originalData.nodes.map((node) => {
const nodeLabel = (
node.label ||
node.name ||
node.id ||
""
).toLowerCase();
const isCommon = otherNodeLabels.has(nodeLabel);
return {
...node,
color:
mode === "common"
? isCommon
? "#22c55e"
: "#94a3b8"
: isCommon
? "#94a3b8"
: "#3b82f6",
};
}),
links: originalData.links.map((link) => {
const sourceId =
typeof link.source === "string" ? link.source : link.source.id;
const targetId =
typeof link.target === "string" ? link.target : link.target.id;
// Find the actual node labels for source and target
const sourceNode = originalData.nodes.find((n) => n.id === sourceId);
const targetNode = originalData.nodes.find((n) => n.id === targetId);
const sourceLabel = (
sourceNode?.label ||
sourceNode?.name ||
sourceId ||
""
).toLowerCase();
const targetLabel = (
targetNode?.label ||
targetNode?.name ||
targetId ||
""
).toLowerCase();
const linkLabel = (link.label || link.type || "").toLowerCase();
const linkKey = `${sourceLabel}-${linkLabel}-${targetLabel}`;
const isCommon = otherLinkKeys.has(linkKey);
return {
...link,
color:
mode === "common"
? isCommon
? "#22c55e"
: "#94a3b8"
: isCommon
? "#94a3b8"
: "#3b82f6",
};
}),
};
},
[]
);
// Memoize highlighted data to prevent unnecessary re-renders
const highlightedGraph1Data = useMemo(() => {
if (!graph1Data || !graph2Data) return graph1Data;
return getHighlightedData(graph1Data, graph2Data, highlightMode);
}, [graph1Data, graph2Data, highlightMode, getHighlightedData]);
const highlightedGraph2Data = useMemo(() => {
if (!graph1Data || !graph2Data) return graph2Data;
return getHighlightedData(graph2Data, graph1Data, highlightMode);
}, [graph1Data, graph2Data, highlightMode, getHighlightedData]);
const overlayData = useMemo(() => {
if (!mergedData) return null;
return applyOverlayColoring(mergedData, highlightMode);
}, [mergedData, highlightMode, applyOverlayColoring]);
if (isLoading) {
return (
<div className="flex items-center justify-center h-64">
<LoadingSpinner size="lg" />
</div>
);
}
if (error) {
return (
<Card className="m-4">
<CardContent className="p-8 text-center">
<p className="text-destructive">{error}</p>
<Button onClick={loadGraphData} className="mt-4">
Retry
</Button>
</CardContent>
</Card>
);
}
if (!graph1Data || !graph2Data) {
return (
<Card className="m-4">
<CardContent className="p-8 text-center">
<p className="text-muted-foreground">No graph data available</p>
</CardContent>
</Card>
);
}
return (
<div className="h-full flex flex-col">
{/* Controls */}
<div className="border-b p-4 bg-background">
<div className="flex items-center justify-between">
<div className="flex items-center gap-4">
<div className="flex items-center gap-2">
<span className="text-sm font-medium">View:</span>
<Button
variant={viewMode === "side-by-side" ? "default" : "outline"}
size="sm"
onClick={() => setViewMode("side-by-side")}
>
<Split className="h-4 w-4 mr-1" />
Side by Side
</Button>
<Button
variant={viewMode === "overlay" ? "default" : "outline"}
size="sm"
onClick={() => setViewMode("overlay")}
>
<Layers className="h-4 w-4 mr-1" />
Overlay
</Button>
</div>
<div className="flex items-center gap-2">
<span className="text-sm font-medium">Highlight:</span>
<Button
variant={highlightMode === "none" ? "default" : "outline"}
size="sm"
onClick={() => setHighlightMode("none")}
className="transition-all duration-200"
>
<EyeOff className="h-4 w-4 mr-1" />
None
</Button>
<Button
variant={highlightMode === "common" ? "default" : "outline"}
size="sm"
onClick={() => setHighlightMode("common")}
className="transition-all duration-200"
>
<Eye className="h-4 w-4 mr-1" />
Common
</Button>
<Button
variant={highlightMode === "unique" ? "default" : "outline"}
size="sm"
onClick={() => setHighlightMode("unique")}
className="transition-all duration-200"
>
<Eye className="h-4 w-4 mr-1" />
Unique
</Button>
</div>
</div>
{comparisonResults && comparisonResults.overall_metrics && (
<Badge variant="secondary">
{(
comparisonResults.overall_metrics.overall_similarity * 100
).toFixed(1)}
% Similar
</Badge>
)}
</div>
</div>
{/* Visualization */}
<div className="flex-1 overflow-hidden">
{viewMode === "side-by-side" ? (
<div className="h-full grid grid-cols-2 gap-4 p-4">
{/* Graph 1 */}
<Card className="h-full">
<CardHeader className="pb-2">
<CardTitle className="text-base flex items-start justify-between gap-2">
<span
title={getGraphDisplayName(graph1)}
className="min-w-0 flex-1 whitespace-normal break-words"
>
{getGraphDisplayName(graph1)}
</span>
<div className="flex gap-1 flex-shrink-0">
<Badge variant="outline" className="text-xs">
{graph1Data.nodes.length} nodes
</Badge>
<Badge variant="outline" className="text-xs">
{graph1Data.links.length} links
</Badge>
</div>
</CardTitle>
</CardHeader>
<CardContent className="h-full p-2">
<div className="h-full" style={{ minHeight: "650px" }}>
{highlightedGraph1Data && (
<CytoscapeWrapper
data={highlightedGraph1Data}
width={400} // Adjust width for side-by-side
height={650}
/>
)}
</div>
</CardContent>
</Card>
{/* Graph 2 */}
<Card className="h-full">
<CardHeader className="pb-2">
<CardTitle className="text-base flex items-start justify-between gap-2">
<span
title={getGraphDisplayName(graph2)}
className="min-w-0 flex-1 whitespace-normal break-words"
>
{getGraphDisplayName(graph2)}
</span>
<div className="flex gap-1 flex-shrink-0">
<Badge variant="outline" className="text-xs">
{graph2Data.nodes.length} nodes
</Badge>
<Badge variant="outline" className="text-xs">
{graph2Data.links.length} links
</Badge>
</div>
</CardTitle>
</CardHeader>
<CardContent className="h-full p-2">
<div className="h-full" style={{ minHeight: "650px" }}>
{highlightedGraph2Data && (
<CytoscapeWrapper
data={highlightedGraph2Data}
width={400} // Adjust width for side-by-side
height={650}
/>
)}
</div>
</CardContent>
</Card>
</div>
) : (
<div className="h-full p-2">
<Card className="h-full">
<CardHeader className="pb-2">
<CardTitle className="text-base flex items-start justify-between gap-2">
<span
title={`${getGraphDisplayName(graph1)} + ${getGraphDisplayName(graph2)}`}
className="min-w-0 flex-1 whitespace-normal break-words"
>
Overlay Comparison
</span>
{mergedData && (
<div className="flex gap-1 flex-shrink-0">
<Badge variant="outline" className="text-xs">
{mergedData.mergeStats.totalNodes} nodes
</Badge>
<Badge variant="outline" className="text-xs">
{mergedData.mergeStats.totalLinks} links
</Badge>
</div>
)}
</CardTitle>
</CardHeader>
<CardContent className="h-full p-1">
{overlayData ? (
<div className="h-full" style={{ minHeight: "750px" }}>
<CytoscapeWrapper
data={overlayData}
width={800} // Full width for overlay
height={750}
/>
</div>
) : (
<div className="flex items-center justify-center h-64">
<LoadingSpinner size="lg" />
</div>
)}
</CardContent>
</Card>
</div>
)}
</div>
{/* Legend */}
{highlightMode !== "none" && (
<div className="border-t p-4 bg-muted/50 transition-all duration-300">
<div className="flex items-center gap-6">
<span className="text-sm font-semibold">Legend:</span>
{viewMode === "overlay" ? (
// Overlay-specific legend
highlightMode === "common" ? (
<>
<div className="flex items-center gap-2">
<div className="w-4 h-4 rounded-full bg-green-500 shadow-sm"></div>
<span className="text-sm font-medium">Common elements</span>
</div>
<div className="flex items-center gap-2">
<div className="w-4 h-4 rounded-full bg-gray-400 shadow-sm"></div>
<span className="text-sm font-medium">Unique elements</span>
</div>
</>
) : (
<>
<div className="flex items-center gap-2">
<div className="w-4 h-4 rounded-full bg-blue-500 shadow-sm"></div>
<span className="text-sm font-medium">Graph 1 unique</span>
</div>
<div className="flex items-center gap-2">
<div className="w-4 h-4 rounded-full bg-orange-500 shadow-sm"></div>
<span className="text-sm font-medium">Graph 2 unique</span>
</div>
<div className="flex items-center gap-2">
<div className="w-4 h-4 rounded-full bg-gray-400 shadow-sm"></div>
<span className="text-sm font-medium">Common elements</span>
</div>
</>
)
) : // Side-by-side legend
highlightMode === "common" ? (
<>
<div className="flex items-center gap-2">
<div className="w-4 h-4 rounded-full bg-green-500 shadow-sm"></div>
<span className="text-sm font-medium">Common elements</span>
</div>
<div className="flex items-center gap-2">
<div className="w-4 h-4 rounded-full bg-gray-400 shadow-sm"></div>
<span className="text-sm font-medium">Unique elements</span>
</div>
</>
) : (
<>
<div className="flex items-center gap-2">
<div className="w-4 h-4 rounded-full bg-blue-500 shadow-sm"></div>
<span className="text-sm font-medium">Unique elements</span>
</div>
<div className="flex items-center gap-2">
<div className="w-4 h-4 rounded-full bg-gray-400 shadow-sm"></div>
<span className="text-sm font-medium">Common elements</span>
</div>
</>
)}
</div>
</div>
)}
</div>
);
};
|