MCPcopy Create free account
hub / github.com/47ng/nuqs / CommitGraph

Function CommitGraph

packages/docs/src/components/commit-graph.tsx:571–724  ·  view source on GitHub ↗
({
  commits,
  truncateHash = 7,
  railWidth = 24,
  railColors,
  refColors,
  tagColors,
  className,
  ...props
}: CommitGraphProps)

Source from the content-addressed store, hash-verified

569// Main component
570
571function 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

Callers

nothing calls this directly

Calls 5

cnFunction · 0.90
computeLayoutFunction · 0.85
resolveRefColorFunction · 0.85
resolveTagColorFunction · 0.85
formatDateFunction · 0.70

Tested by

no test coverage detected