Skip to content

fix: distribute clock markers around face (fixes stacking bug)#2

Open
isupersid wants to merge 11 commits into001-world-clockfrom
002-fix-clock-markers
Open

fix: distribute clock markers around face (fixes stacking bug)#2
isupersid wants to merge 11 commits into001-world-clockfrom
002-fix-clock-markers

Conversation

@isupersid
Copy link
Owner

Summary

Fixes bug where all 12 hour markers on analog clock faces were stacked at the 12 o'clock position instead of being evenly distributed around the clock face perimeter at 30-degree intervals.

Problem

The original implementation had markers positioned without proper vertical positioning (top property) and incorrect transform-origin, causing all markers to stack at a single point rather than distribute around the clock face.

Solution

Corrected the CSS positioning and transform-origin calculation:

  1. CSS Positioning (src/styles/main.css):

    • Added top: 0 to position markers at top edge of clock face
    • Added left: 50% to center markers horizontally
    • Set transform-origin: center calc(var(--clock-size) / 2 - 4px) to make rotation happen around clock center
  2. Bold Marker Selector (src/styles/main.css):

    • Changed from :nth-child(3n) to :nth-child(3n+1) to correctly select 12, 3, 6, 9 o'clock positions
  3. JavaScript Transform (src/components/Clock.ts):

    • Used translateX(-50%) rotate(${i * 30}deg) to center marker then rotate around transform-origin point

Key Insight

The transform-origin property must point from the marker's position to the clock center. With markers at top: 0, the origin calculation center calc(var(--clock-size) / 2 - 4px) positions the rotation point at the clock center, allowing markers to rotate around that point while staying at the perimeter.

Files Changed

  • src/components/Clock.ts - Updated marker transform logic and added clarifying comment
  • src/styles/main.css - Fixed marker positioning, transform-origin, and bold marker selector
  • tests/unit/Clock.test.ts - Added unit tests for marker creation and transforms (TDD)
  • tests/integration/ClockGrid.test.ts - Added integration tests for visual distribution (TDD)

Testing Performed

  • ✅ Unit tests verify correct rotation angles (0°, 30°, 60°, ..., 330°)
  • ✅ Integration tests verify markers not stacked and properly distributed
  • ✅ Visual verification across desktop, tablet, and mobile viewports
  • ✅ Cross-browser testing in Chrome, Firefox, and Edge
  • ✅ Multiple clock instances display correctly
  • ✅ No regression in clock hands positioning or animation
  • ✅ No performance degradation
  • ✅ Build succeeds with no errors

Checklist

  • Tests written first and verified to fail (TDD red phase)
  • Implementation makes tests pass (TDD green phase)
  • Visual verification complete
  • Cross-browser tested
  • No regressions
  • Code comments added
  • Documentation updated
  • Build succeeds
  • Follows constitution principles (test-first, simplicity, documentation)

Visual Result

All 12 hour markers now properly distributed around clock face at 30-degree intervals with bold markers correctly positioned at 12, 3, 6, 9 o'clock positions.

Siddharth Singh and others added 11 commits January 16, 2026 00:16
- Add unit tests for marker creation and transform validation
- Add integration tests for visual marker distribution
- Tests verify markers should be distributed at 30-degree intervals
- Current implementation has all markers stacked at 12 o'clock position
- Update CSS: Add 'top: 0' to .clock-marker to position markers at top edge
- Update JavaScript: Change transform to 'translate(-50%, 0) rotate(${i * 30}deg)'
- Add inline comment explaining the transform logic
- Fix test type issues to match City interface

The fix distributes all 12 hour markers evenly around the clock face
at 30-degree intervals instead of stacking them all at 12 o'clock.

TDD Green Phase: Implementation complete
Previous approach had markers starting at top with bottom rotation,
which didn't work correctly.

New approach:
- CSS: Position markers at center (top: 50%, left: 50%)
- CSS: Rotate from center top (transform-origin: center top)
- JS: Center, offset to edge, then rotate around clock center
- JS: Use translateX(-50%) translateY(-50%) translateY(-45%) rotate()

This properly distributes all 12 markers around the clock face.
The key is transform order matters:
1. rotate(angle) - rotate around clock center first
2. translateY(-45%) - move outward to clock edge
3. translateX(-50%) - center the marker horizontally

This approach ensures markers rotate around the clock center point
before being moved to their positions on the edge, creating proper
circular distribution.
Set markers at top edge (12 o'clock) and use transform-origin pointing
to clock center. Rotation now happens around the clock center while
markers remain at the perimeter edge, creating proper circular distribution.

CSS changes:
- top: 5px (positions at top edge)
- transform-origin: center calc(var(--clock-size) / 2 - 5px) (points to clock center)

JS changes:
- translateX(-50%) rotate(${i * 30}deg) (center horizontally, then rotate)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…lignment

Changed top from 5px to 0 and transform-origin to calc(var(--clock-size) / 2 - 4px)
to ensure markers touch the clock face edge without gaps and bold markers (every 3rd)
align correctly at 12, 3, 6, 9 o'clock positions.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Changed nth-child selector from (3n) to (3n+1) to select markers at
positions 1, 4, 7, 10 which correspond to 12, 3, 6, 9 o'clock positions.
Previously (3n) was selecting positions 3, 6, 9, 12 which made bold
markers appear one position counter-clockwise from where they should be.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant