({
commits,
truncateHash = 7,
railWidth = 24,
railColors,
refColors,
tagColors,
className,
...props
}: CommitGraphProps)
| 569 | // Main component |
| 570 | |
| 571 | function CommitGraph({ |
| 572 | commits, |
| 573 | truncateHash = 7, |
| 574 | railWidth = 24, |
| 575 | railColors, |
| 576 | refColors, |
| 577 | tagColors, |
| 578 | className, |
| 579 | ...props |
| 580 | }: CommitGraphProps) { |
| 581 | const resolveColor = (rail: number) => railColors?.[rail] ?? color(rail) |
| 582 | const resolveRefColor = (rail: number, ref: string) => |
| 583 | refColors?.[ref] ?? resolveColor(rail) |
| 584 | const resolveTagColor = (rail: number, tag: string) => |
| 585 | tagColors?.[tag] ?? resolveColor(rail) |
| 586 | |
| 587 | // Simple mode: if no commit has parents, infer a linear topology |
| 588 | const hasTopology = commits.some(c => c.parents && c.parents.length > 0) |
| 589 | const resolvedCommits = hasTopology |
| 590 | ? commits |
| 591 | : commits.map((c, i) => ({ |
| 592 | ...c, |
| 593 | parents: i < commits.length - 1 ? [commits[i + 1].hash] : [] |
| 594 | })) |
| 595 | |
| 596 | if (resolvedCommits.length === 0) { |
| 597 | return ( |
| 598 | <div |
| 599 | data-slot="commit-graph" |
| 600 | className={cn( |
| 601 | 'border-border/60 bg-card text-muted-foreground flex items-center justify-center rounded-xl border py-10 text-sm shadow-sm', |
| 602 | className |
| 603 | )} |
| 604 | {...props} |
| 605 | > |
| 606 | No commits. |
| 607 | </div> |
| 608 | ) |
| 609 | } |
| 610 | |
| 611 | const rows = computeLayout(resolvedCommits) |
| 612 | const maxRails = Math.max( |
| 613 | ...rows.map(r => |
| 614 | Math.max( |
| 615 | r.rail + 1, |
| 616 | r.rails.length, |
| 617 | ...r.edges.map(e => Math.max(e.fromRail, e.toRail) + 1) |
| 618 | ) |
| 619 | ) |
| 620 | ) |
| 621 | const svgWidth = maxRails * railWidth |
| 622 | |
| 623 | return ( |
| 624 | <div |
| 625 | data-slot="commit-graph" |
| 626 | className={cn( |
| 627 | 'border-border/60 bg-card overflow-hidden rounded-xl border shadow-sm', |
| 628 | className |
nothing calls this directly
no test coverage detected