Merge pull request 'feat/pedigree-theme-visual' (#33) from feat/pedigree-theme-visual into master
Some checks failed
Build & Publish Docker Image / build-and-push (push) Has been cancelled

Reviewed-on: #33
This commit was merged in pull request #33.
This commit is contained in:
2026-03-09 22:47:09 -05:00
3 changed files with 305 additions and 193 deletions

View File

@@ -1,11 +1,17 @@
/* ─── Pedigree Tree Wrapper ──────────────────────────────────────── */
.pedigree-tree-wrapper {
position: relative;
width: 100%;
height: calc(100vh - 200px);
background: #f9fafb;
border-radius: 8px;
background: radial-gradient(
ellipse at 20% 50%,
rgba(194, 134, 42, 0.06) 0%,
var(--bg-primary) 60%
);
border-radius: var(--radius);
overflow: hidden;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
border: 1px solid var(--border);
box-shadow: var(--shadow-lg);
}
.tree-container {
@@ -13,117 +19,142 @@
height: 100%;
}
/* ─── SVG Link Paths ─────────────────────────────────────────────── */
.pedigree-tree-wrapper svg .rd3t-link {
stroke: var(--border-light) !important;
stroke-width: 1.5px !important;
stroke-opacity: 0.6;
}
/* ─── Controls ───────────────────────────────────────────────────── */
.pedigree-controls {
position: absolute;
top: 20px;
right: 20px;
top: 16px;
right: 16px;
z-index: 10;
display: flex;
gap: 1rem;
gap: 0.75rem;
align-items: center;
}
.control-group {
display: flex;
gap: 0.5rem;
background: white;
padding: 0.5rem;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
gap: 0.25rem;
background: var(--bg-elevated);
padding: 0.375rem;
border-radius: var(--radius-sm);
border: 1px solid var(--border);
box-shadow: var(--shadow);
backdrop-filter: blur(8px);
}
.control-btn {
background: white;
border: 1px solid #e5e7eb;
border-radius: 6px;
padding: 0.5rem;
background: transparent;
border: 1px solid transparent;
border-radius: var(--radius-sm);
padding: 0.4rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
color: var(--text-secondary);
transition: var(--transition);
}
.control-btn:hover {
background: #f3f4f6;
border-color: #d1d5db;
background: var(--bg-tertiary);
border-color: var(--border);
color: var(--primary-light);
}
.control-btn:active {
transform: scale(0.95);
transform: scale(0.93);
}
/* ─── COI Display ────────────────────────────────────────────────── */
.coi-display {
background: white;
padding: 0.75rem 1rem;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
background: var(--bg-elevated);
padding: 0.5rem 0.875rem;
border-radius: var(--radius-sm);
border: 1px solid var(--border);
box-shadow: var(--shadow);
display: flex;
align-items: center;
gap: 0.5rem;
backdrop-filter: blur(8px);
}
.coi-label {
font-weight: 600;
color: #6b7280;
font-size: 0.875rem;
color: var(--text-muted);
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.coi-value {
font-weight: 700;
font-size: 1.25rem;
font-size: 1.1rem;
letter-spacing: -0.02em;
}
.coi-value.low {
color: #10b981;
}
.coi-value.medium {
color: #f59e0b;
}
.coi-value.high {
color: #ef4444;
}
.coi-value.low { color: var(--success); }
.coi-value.medium { color: var(--warning); }
.coi-value.high { color: var(--danger); }
/* ─── Legend ─────────────────────────────────────────────────────── */
.pedigree-legend {
position: absolute;
bottom: 20px;
left: 20px;
bottom: 16px;
left: 16px;
z-index: 10;
background: white;
padding: 1rem;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
background: var(--bg-elevated);
padding: 0.625rem 1rem;
border-radius: var(--radius-sm);
border: 1px solid var(--border);
box-shadow: var(--shadow);
display: flex;
gap: 1.5rem;
gap: 1.25rem;
backdrop-filter: blur(8px);
}
.legend-item {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.875rem;
color: #6b7280;
gap: 0.4rem;
font-size: 0.8rem;
color: var(--text-secondary);
font-weight: 500;
}
.legend-color {
width: 20px;
height: 20px;
width: 14px;
height: 14px;
border-radius: 50%;
border: 2px solid white;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
border: 2px solid rgba(255,255,255,0.15);
box-shadow: 0 0 6px rgba(0,0,0,0.4);
}
.legend-color.male {
background: #3b82f6;
.legend-color.male { background: #3b82f6; box-shadow: 0 0 8px rgba(59,130,246,0.4); }
.legend-color.female { background: #ec4899; box-shadow: 0 0 8px rgba(236,72,153,0.4); }
/* ─── Zoom Indicator ─────────────────────────────────────────────── */
.zoom-indicator {
position: absolute;
bottom: 16px;
right: 16px;
z-index: 10;
background: var(--bg-elevated);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
padding: 0.3rem 0.6rem;
font-size: 0.7rem;
color: var(--text-muted);
font-variant-numeric: tabular-nums;
backdrop-filter: blur(8px);
}
.legend-color.female {
background: #ec4899;
}
/* Mobile responsive */
/* ─── Mobile ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
.pedigree-tree-wrapper {
height: calc(100vh - 150px);
@@ -133,52 +164,39 @@
top: 10px;
right: 10px;
flex-direction: column;
gap: 0.5rem;
gap: 0.4rem;
}
.coi-display {
padding: 0.5rem 0.75rem;
padding: 0.375rem 0.625rem;
}
.coi-label {
font-size: 0.75rem;
}
.coi-value {
font-size: 1rem;
}
.coi-label { font-size: 0.7rem; }
.coi-value { font-size: 0.95rem; }
.pedigree-legend {
bottom: 10px;
left: 10px;
padding: 0.75rem;
gap: 1rem;
padding: 0.5rem 0.75rem;
gap: 0.875rem;
}
.legend-item {
font-size: 0.75rem;
}
.legend-color {
width: 16px;
height: 16px;
}
.legend-item { font-size: 0.75rem; }
.legend-color { width: 12px; height: 12px; }
}
/* Print styles */
/* ─── Print ──────────────────────────────────────────────────────── */
@media print {
.pedigree-controls,
.pedigree-legend {
display: none;
}
.pedigree-legend,
.zoom-indicator { display: none; }
.pedigree-tree-wrapper {
height: 100vh;
box-shadow: none;
background: white;
border: none;
}
.tree-container {
page-break-inside: avoid;
}
.tree-container { page-break-inside: avoid; }
}

View File

@@ -1,6 +1,6 @@
import { useState, useCallback, useEffect } from 'react'
import Tree from 'react-d3-tree'
import { ZoomIn, ZoomOut, Maximize2, Download } from 'lucide-react'
import { ZoomIn, ZoomOut, Maximize2 } from 'lucide-react'
import './PedigreeTree.css'
const PedigreeTree = ({ dogId, pedigreeData, coi }) => {
@@ -12,90 +12,151 @@ const PedigreeTree = ({ dogId, pedigreeData, coi }) => {
const updateDimensions = () => {
const container = document.getElementById('tree-container')
if (container) {
setDimensions({
width: container.offsetWidth,
height: container.offsetHeight
})
setTranslate({
x: container.offsetWidth / 4,
y: container.offsetHeight / 2
})
setDimensions({ width: container.offsetWidth, height: container.offsetHeight })
setTranslate({ x: container.offsetWidth / 4, y: container.offsetHeight / 2 })
}
}
updateDimensions()
window.addEventListener('resize', updateDimensions)
return () => window.removeEventListener('resize', updateDimensions)
}, [])
const handleZoomIn = () => setZoom(z => Math.min(z + 0.2, 2))
const handleZoomIn = () => setZoom(z => Math.min(z + 0.2, 2))
const handleZoomOut = () => setZoom(z => Math.max(z - 0.2, 0.2))
const handleReset = () => {
const handleReset = () => {
setZoom(0.8)
setTranslate({
x: dimensions.width / 4,
y: dimensions.height / 2
})
setTranslate({ x: dimensions.width / 4, y: dimensions.height / 2 })
}
const renderCustomNode = ({ nodeDatum, toggleNode }) => {
const isMale = nodeDatum.attributes?.sex === 'male'
const nodeColor = isMale ? '#3b82f6' : '#ec4899'
const renderCustomNode = ({ nodeDatum }) => {
const isRoot = nodeDatum.attributes?.isRoot
const isMale = nodeDatum.attributes?.sex === 'male'
const hasId = !!nodeDatum.attributes?.id
const breed = nodeDatum.attributes?.breed
// Colour palette aligned to app theme
const maleColor = '#3b82f6'
const femaleColor = '#ec4899'
const rootGold = '#c2862a' // --primary
const rootAccent = '#9b3a10' // --accent
const nodeColor = isRoot ? rootGold : (isMale ? maleColor : femaleColor)
const glowColor = isRoot
? 'rgba(194,134,42,0.35)'
: (isMale ? 'rgba(59,130,246,0.3)' : 'rgba(236,72,153,0.3)')
const ringColor = isRoot ? rootAccent : nodeColor
const r = isRoot ? 34 : 28
return (
<g>
{/* Glow halo */}
<circle
r={30}
fill={nodeColor}
stroke="#fff"
strokeWidth={3}
opacity={0.9}
style={{ cursor: nodeDatum.attributes?.id ? 'pointer' : 'default' }}
r={r + 10}
fill={glowColor}
style={{ filter: 'blur(6px)' }}
/>
{/* Outer ring */}
<circle
r={r + 4}
fill="none"
stroke={ringColor}
strokeWidth={isRoot ? 2 : 1.5}
strokeOpacity={0.5}
/>
{/* Main node */}
<circle
r={r}
fill={isRoot
? `url(#rootGradient)`
: nodeColor}
stroke="rgba(255,255,255,0.15)"
strokeWidth={2}
style={{
cursor: hasId ? 'pointer' : 'default',
filter: isRoot ? 'drop-shadow(0 0 8px rgba(194,134,42,0.6))' : 'none'
}}
onClick={() => {
if (nodeDatum.attributes?.id) {
window.location.href = `/dogs/${nodeDatum.attributes.id}`
}
if (hasId) window.location.href = `/dogs/${nodeDatum.attributes.id}`
}}
/>
{/* SVG gradient definition for root node */}
{isRoot && (
<defs>
<radialGradient id="rootGradient" cx="35%" cy="35%">
<stop offset="0%" stopColor="#e0a84a" />
<stop offset="100%" stopColor="#9b3a10" />
</radialGradient>
</defs>
)}
{/* Gender / crown icon */}
<text
fill="#fff"
fontSize="24"
fill={isRoot ? '#fff' : '#fff'}
fontSize={isRoot ? 22 : 18}
textAnchor="middle"
dy="8"
style={{ pointerEvents: 'none' }}
dy="7"
style={{ pointerEvents: 'none', userSelect: 'none' }}
>
{isMale ? '♂' : '♀'}
{isRoot ? '👑' : (isMale ? '♂' : '♀')}
</text>
{/* Name label */}
<text
fill="#1f2937"
fontSize="14"
fontWeight="600"
fill="var(--text-primary, #f5f0e8)"
fontSize={isRoot ? 15 : 13}
fontWeight={isRoot ? '700' : '600'}
fontFamily="Inter, sans-serif"
textAnchor="middle"
x="0"
y="50"
y={r + 18}
style={{ pointerEvents: 'none' }}
>
{nodeDatum.name}
</text>
{nodeDatum.attributes?.registration && (
{/* Breed label (subtle) */}
{breed && (
<text
fill="#6b7280"
fontSize="11"
fill="var(--text-muted, #8c8472)"
fontSize="10"
fontFamily="Inter, sans-serif"
textAnchor="middle"
x="0"
y="65"
y={r + 31}
style={{ pointerEvents: 'none' }}
>
{breed}
</text>
)}
{/* Registration number */}
{nodeDatum.attributes?.registration && (
<text
fill="var(--text-muted, #8c8472)"
fontSize="10"
fontFamily="Inter, sans-serif"
textAnchor="middle"
x="0"
y={r + (breed ? 44 : 31)}
style={{ pointerEvents: 'none' }}
>
{nodeDatum.attributes.registration}
</text>
)}
{/* Birth year */}
{nodeDatum.attributes?.birth_year && (
<text
fill="#6b7280"
fontSize="11"
fill="var(--text-muted, #8c8472)"
fontSize="10"
fontFamily="Inter, sans-serif"
textAnchor="middle"
x="0"
y="78"
y={r + (breed ? 57 : (nodeDatum.attributes?.registration ? 44 : 31))}
style={{ pointerEvents: 'none' }}
>
({nodeDatum.attributes.birth_year})
@@ -107,21 +168,24 @@ const PedigreeTree = ({ dogId, pedigreeData, coi }) => {
return (
<div className="pedigree-tree-wrapper">
{/* Controls */}
<div className="pedigree-controls">
<div className="control-group">
<button onClick={handleZoomIn} className="control-btn" title="Zoom In">
<ZoomIn size={20} />
<button onClick={handleZoomIn} className="control-btn" title="Zoom In">
<ZoomIn size={18} />
</button>
<button onClick={handleZoomOut} className="control-btn" title="Zoom Out">
<ZoomOut size={20} />
<ZoomOut size={18} />
</button>
<button onClick={handleReset} className="control-btn" title="Reset View">
<Maximize2 size={20} />
<button onClick={handleReset} className="control-btn" title="Reset View">
<Maximize2 size={18} />
</button>
</div>
{coi !== null && coi !== undefined && (
<div className="coi-display">
<span className="coi-label">COI:</span>
<span className="coi-label">COI</span>
<span className={`coi-value ${coi > 10 ? 'high' : coi > 5 ? 'medium' : 'low'}`}>
{coi.toFixed(2)}%
</span>
@@ -129,31 +193,47 @@ const PedigreeTree = ({ dogId, pedigreeData, coi }) => {
)}
</div>
{/* Legend */}
<div className="pedigree-legend">
<div className="legend-item">
<div className="legend-color male"></div>
<span>Male</span>
<div className="legend-color male" />
<span>Sire</span>
</div>
<div className="legend-item">
<div className="legend-color female"></div>
<span>Female</span>
<div className="legend-color female" />
<span>Dam</span>
</div>
<div className="legend-item">
<div style={{
width: 14, height: 14, borderRadius: '50%',
background: 'linear-gradient(135deg, #e0a84a, #9b3a10)',
boxShadow: '0 0 8px rgba(194,134,42,0.5)',
border: '2px solid rgba(255,255,255,0.15)'
}} />
<span>Subject</span>
</div>
</div>
{/* Zoom indicator */}
<div className="zoom-indicator">
{Math.round(zoom * 100)}%
</div>
{/* Tree canvas */}
<div id="tree-container" className="tree-container">
{pedigreeData && dimensions.width > 0 && (
<Tree
data={pedigreeData}
translate={translate}
zoom={zoom}
onUpdate={({ zoom, translate }) => {
setZoom(zoom)
setTranslate(translate)
onUpdate={({ zoom: z, translate: t }) => {
setZoom(z)
setTranslate(t)
}}
orientation="horizontal"
pathFunc="step"
separation={{ siblings: 1.5, nonSiblings: 2 }}
nodeSize={{ x: 200, y: 150 }}
separation={{ siblings: 1.6, nonSiblings: 2.2 }}
nodeSize={{ x: 220, y: 160 }}
renderCustomNodeElement={renderCustomNode}
enableLegacyTransitions
transitionDuration={300}

View File

@@ -24,17 +24,13 @@ function PedigreeView() {
setError('')
try {
// Fetch pedigree tree data
const pedigreeRes = await axios.get(`/api/pedigree/${id}`)
const dogData = pedigreeRes.data
setDog(dogData)
// Transform data for react-d3-tree
const treeData = transformPedigreeData(dogData, generations)
setPedigreeData(treeData)
// Fetch COI calculation
try {
const coiRes = await axios.get(`/api/pedigree/${id}/coi`)
setCoiData(coiRes.data)
@@ -84,6 +80,9 @@ function PedigreeView() {
)
}
// Completeness bar colour — uses theme tokens
const barColor = completeness === 100 ? 'var(--success)' : 'var(--primary)'
return (
<div className="container">
{/* Header */}
@@ -99,7 +98,7 @@ function PedigreeView() {
<div style={{ flex: 1 }}>
<h1 style={{ margin: 0, display: 'flex', alignItems: 'center', gap: '0.75rem' }}>
<GitBranch size={32} />
<GitBranch size={32} style={{ color: 'var(--primary)' }} />
{dog?.name}'s Pedigree
</h1>
{dog?.registration_number && (
@@ -113,8 +112,10 @@ function PedigreeView() {
{/* Stats Bar */}
<div className="card" style={{ marginBottom: '1rem', padding: '1rem' }}>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: '1.5rem' }}>
{/* COI */}
<div>
<div style={{ fontSize: '0.875rem', color: 'var(--text-secondary)', marginBottom: '0.25rem' }}>
<div style={{ fontSize: '0.875rem', color: 'var(--text-muted)', marginBottom: '0.25rem', textTransform: 'uppercase', letterSpacing: '0.05em', fontWeight: 500 }}>
Coefficient of Inbreeding
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
@@ -133,37 +134,42 @@ function PedigreeView() {
{coiInfo.level}
</span>
</div>
<div style={{ fontSize: '0.75rem', color: 'var(--text-secondary)', marginTop: '0.25rem' }}>
<div style={{ fontSize: '0.75rem', color: 'var(--text-muted)', marginTop: '0.25rem' }}>
{coiInfo.description}
</div>
</div>
{/* Completeness */}
<div>
<div style={{ fontSize: '0.875rem', color: 'var(--text-secondary)', marginBottom: '0.25rem' }}>
<div style={{ fontSize: '0.875rem', color: 'var(--text-muted)', marginBottom: '0.25rem', textTransform: 'uppercase', letterSpacing: '0.05em', fontWeight: 500 }}>
Pedigree Completeness
</div>
<div style={{ fontSize: '1.5rem', fontWeight: '700' }}>
<div style={{ fontSize: '1.5rem', fontWeight: '700', color: 'var(--text-primary)' }}>
{completeness}%
</div>
<div style={{ marginTop: '0.5rem' }}>
<div style={{
height: '8px',
background: '#e5e7eb',
borderRadius: '4px',
overflow: 'hidden'
height: '6px',
background: 'var(--bg-tertiary)',
borderRadius: '3px',
overflow: 'hidden',
border: '1px solid var(--border)'
}}>
<div style={{
height: '100%',
width: `${completeness}%`,
background: completeness === 100 ? '#10b981' : '#3b82f6',
transition: 'width 0.3s ease'
background: barColor,
borderRadius: '3px',
transition: 'width 0.4s ease',
boxShadow: `0 0 6px ${barColor}`
}} />
</div>
</div>
</div>
{/* Generations */}
<div>
<div style={{ fontSize: '0.875rem', color: 'var(--text-secondary)', marginBottom: '0.25rem' }}>
<div style={{ fontSize: '0.875rem', color: 'var(--text-muted)', marginBottom: '0.25rem', textTransform: 'uppercase', letterSpacing: '0.05em', fontWeight: 500 }}>
Generations Displayed
</div>
<select
@@ -190,7 +196,7 @@ function PedigreeView() {
/>
) : (
<div style={{ textAlign: 'center', padding: '4rem' }}>
<GitBranch size={64} style={{ color: 'var(--text-secondary)', margin: '0 auto 1rem' }} />
<GitBranch size={64} style={{ color: 'var(--text-muted)', margin: '0 auto 1rem' }} />
<h3>No Pedigree Data Available</h3>
<p style={{ color: 'var(--text-secondary)' }}>
Add parent information to this dog to build the pedigree tree.
@@ -199,11 +205,19 @@ function PedigreeView() {
)}
</div>
{/* Help Text */}
<div className="card" style={{ marginTop: '1rem', background: '#eff6ff', border: '1px solid #bfdbfe' }}>
<div style={{ fontSize: '0.875rem', color: '#1e40af' }}>
<strong>💡 Tip:</strong> Click on any ancestor node to navigate to their profile.
Use the zoom controls to explore the tree, or drag to pan around.
{/* Tip */}
<div className="card" style={{
marginTop: '1rem',
background: 'var(--bg-elevated)',
border: '1px solid var(--border-light)'
}}>
<div style={{ fontSize: '0.875rem', color: 'var(--text-secondary)', display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
<span style={{ color: 'var(--primary)' }}>&#128161;</span>
<span>
<strong style={{ color: 'var(--text-primary)' }}>Tip:</strong>{' '}
Click any ancestor node to navigate to their profile.
Use the zoom controls or scroll to explore the tree, and drag to pan.
</span>
</div>
</div>
</div>