Skip to content

Commit 19c9c25

Browse files
Copilotankurrera
andcommitted
refactor: Address code review feedback
- Use squared distance comparison in RadarChart to avoid expensive sqrt - Extract MAX_DISPLAYED_CONTRIBUTIONS constant in SkillCard Co-authored-by: ankurrera <186232326+ankurrera@users.noreply.github.com>
1 parent ab5e48b commit 19c9c25

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/components/skills/SkillCard.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ interface SkillCardProps {
1515
skill: Skill;
1616
}
1717

18+
/** Maximum number of metric contributions to display inline on a skill card */
19+
const MAX_DISPLAYED_CONTRIBUTIONS = 3;
20+
1821
const SkillCard = ({ skill }: SkillCardProps) => {
1922
const { updateSkill, deleteSkill } = useSkills();
2023
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false);
@@ -123,7 +126,7 @@ const SkillCard = ({ skill }: SkillCardProps) => {
123126
<TooltipProvider>
124127
<div className="flex items-center gap-1 text-xs flex-wrap">
125128
<Target className="w-3 h-3 text-muted-foreground" />
126-
{metricContributions.slice(0, 3).map((contribution) => (
129+
{metricContributions.slice(0, MAX_DISPLAYED_CONTRIBUTIONS).map((contribution) => (
127130
<Tooltip key={contribution.metricName}>
128131
<TooltipTrigger asChild>
129132
<span className="text-muted-foreground bg-muted/50 px-1.5 py-0.5 rounded cursor-help">
@@ -137,9 +140,9 @@ const SkillCard = ({ skill }: SkillCardProps) => {
137140
</TooltipContent>
138141
</Tooltip>
139142
))}
140-
{metricContributions.length > 3 && (
143+
{metricContributions.length > MAX_DISPLAYED_CONTRIBUTIONS && (
141144
<span className="text-muted-foreground">
142-
+{metricContributions.length - 3} more
145+
+{metricContributions.length - MAX_DISPLAYED_CONTRIBUTIONS} more
143146
</span>
144147
)}
145148
</div>

src/components/system/RadarChart.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,13 @@ const RadarChart = () => {
125125
const dx = x - centerX;
126126
const dy = y - centerY;
127127
const clickAngle = Math.atan2(dy, dx);
128-
const distance = Math.sqrt(dx * dx + dy * dy);
128+
129+
// Use squared distance comparison to avoid expensive square root operation
130+
const distanceSquared = dx * dx + dy * dy;
131+
const maxDistanceSquared = (radius + 50) * (radius + 50);
129132

130133
// Only respond to clicks near the chart area
131-
if (distance > radius + 50) return;
134+
if (distanceSquared > maxDistanceSquared) return;
132135

133136
// Find the closest axis
134137
let closestAxisIndex = 0;

0 commit comments

Comments
 (0)