Skip to content

Commit 04f7d2e

Browse files
afuchereca-agent
andcommitted
fix(website): address Copilot review — factual errors and broken examples
- changelog: replace '— Current' header with real release dates (3.0.2: 2023-08-17, 3.0.1: 2023-07-20, 3.0.0: 2023-07-10) - changelog: remove false claim that AstroData/AspectData/Dignity are exported from the package entry point (only Chart, AspectCalculator, and Settings are) - changelog: add real 3.0.2 fix: SNode and Fortune symbol positions - changelog: correct ADD_CLICK_AREA entry — remove mention of the non-existent radix.on() event API - click-events: rewrite guide to use real DOM addEventListener pattern with predictable element IDs ({chartId}-radix-planets-{Name} / {chartId}-radix-cusps-{index}) instead of fictional radix.on() API - custom.css: rename .chart-demo selectors to .chart-demo-wrapper to match the class actually used by ChartDemo.astro (dead CSS fix) - vue.md: replace broken `import type { AstroData }` (not exported) with derived type: Parameters<InstanceType<typeof Chart>['radix']>[0] - ChartDemo.astro: fix package name in all 4 code snippets ('astrochart' → '@astrodraw/astrochart') - ChartDemo.astro: fix animate snippet — replace no-arg transit.animate() call with a valid call showing all required parameters 🤖 Generated with [eca](https://eca.dev) Co-Authored-By: eca <git@eca.dev>
1 parent 14c5e65 commit 04f7d2e

5 files changed

Lines changed: 121 additions & 57 deletions

File tree

website/src/components/ChartDemo.astro

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,30 @@ const {
2828
// Generate code snippet based on mode
2929
const getCodeSnippet = () => {
3030
if (mode === 'radix') {
31-
return `import { Chart } from 'astrochart'
31+
return `import { Chart } from '@astrodraw/astrochart'
3232
3333
const chart = new Chart('chart', 600, 600)
3434
chart.radix(data)`
3535
} else if (mode === 'transit') {
36-
return `import { Chart } from 'astrochart'
36+
return `import { Chart } from '@astrodraw/astrochart'
3737
3838
const chart = new Chart('chart', 600, 600)
3939
chart.radix(radixData).transit(transitData)`
4040
} else if (mode === 'aspects') {
41-
return `import { Chart } from 'astrochart'
41+
return `import { Chart } from '@astrodraw/astrochart'
4242
4343
const chart = new Chart('chart', 600, 600)
4444
chart.radix(data).aspects()`
4545
} else {
46-
return `import { Chart } from 'astrochart'
46+
return `import { Chart } from '@astrodraw/astrochart'
4747
4848
const chart = new Chart('chart', 600, 600)
4949
const transit = chart.radix(radixData).transit(transitData)
50-
transit.animate()`
50+
51+
// animate(targetData, durationSeconds, isReverse, onComplete)
52+
transit.animate(newTransitData, 2, false, () => {
53+
console.log('animation complete')
54+
})`
5155
}
5256
}
5357

website/src/content/docs/changelog.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,17 @@ This project adheres to [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1212
1313
---
1414

15-
## [3.0.2]Current
15+
## [3.0.2]2023-08-17
1616

1717
### Fixed
1818
- Corrected planet collision-avoidance logic when `SYMBOL_SCALE` is set to a value other than `1`
1919
- Resolved an edge case where `DIGNITIES_EXACT_EXALTATION_DEFAULT` positions were not applied when custom dignity data was provided
2020
- Minor SVG attribute type-coercion fixes for strict browser environments
21-
22-
### Changed
23-
- Improved TypeScript type exports — `AstroData`, `AspectData`, `Dignity`, and `Settings` interfaces are now all publicly exported from the package entry point
24-
- Internal SVG group IDs (`ID_*` settings) are now overridable without side-effects
21+
- Fixed `SNode` and `Fortune` symbol positions being rendered at incorrect ecliptic angles
2522

2623
---
2724

28-
## [3.0.1]
25+
## [3.0.1] — 2023-07-20
2926

3027
### Fixed
3128
- Transit chart rendering when cusps array contains boundary values at 0° or 360°
@@ -38,12 +35,12 @@ This project adheres to [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3835

3936
---
4037

41-
## [3.0.0]
38+
## [3.0.0] — 2023-07-10
4239

4340
### Added
4441
- Full TypeScript rewrite — all public APIs are typed; ships with `.d.ts` declaration files
4542
- `CUSTOM_SYMBOL_FN` setting for replacing any planet or sign symbol with a custom SVG element
46-
- `ADD_CLICK_AREA` setting plus `radix.on('click:planet', ...)` and `radix.on('click:cusp', ...)` event API
43+
- `ADD_CLICK_AREA` setting — adds transparent `<rect>` hit areas around planet and cusp symbols, enabling external DOM `click` event listeners
4744
- `STROKE_ONLY` rendering mode for monochrome / print output
4845
- `SHOW_DIGNITIES_TEXT` setting and configurable dignity label characters (`r`, `d`, `e`, `E`, `f`)
4946
- `ANIMATION_CUSPS_ROTATION_SPEED` setting for transit rotation animation
Lines changed: 102 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: Click Events
3-
description: Add interactivity to chart elements with click event handlers.
3+
description: Add interactivity to chart elements with click event listeners.
44
---
55

66
# Click Events
77

8-
AstroChart can fire events when a user clicks on a planet or cusp. You must opt-in by setting `ADD_CLICK_AREA: true` when constructing the chart — without this flag no click areas are added and no events will fire.
8+
AstroChart supports click interactivity via the `ADD_CLICK_AREA` setting. When enabled, transparent `<rect>` hit areas are rendered on top of each planet and cusp symbol. You attach standard DOM `click` listeners to those elements using their predictable `id` attributes.
99

1010
---
1111

@@ -16,39 +16,93 @@ Pass `ADD_CLICK_AREA: true` in your settings object:
1616
```javascript
1717
import { Chart } from '@astrodraw/astrochart'
1818

19-
const settings = {
20-
ADD_CLICK_AREA: true
21-
}
19+
const chart = new Chart('chart', 600, 600, { ADD_CLICK_AREA: true })
20+
chart.radix(data)
21+
```
22+
23+
Without this setting no `<rect>` elements are rendered and there are no click targets.
24+
25+
---
26+
27+
## How Click Areas Work
28+
29+
When `ADD_CLICK_AREA: true` is set, AstroChart injects a transparent `<rect>` element
30+
on top of each planet symbol and each cusp. These elements get predictable `id` attributes
31+
derived from the chart container `id` and the `ID_*` settings:
32+
33+
| Element | ID pattern | Example (chart id = `'chart'`) |
34+
|---|---|---|
35+
| Planet | `{chartId}-radix-planets-{PlanetName}` | `chart-radix-planets-Sun` |
36+
| Cusp | `{chartId}-radix-cusps-{index}` (0-based) | `chart-radix-cusps-0` (house 1) |
37+
38+
> If you override `ID_RADIX`, `ID_POINTS`, or `ID_CUSPS` in your settings, the IDs
39+
> change accordingly — update your selectors to match.
40+
41+
---
42+
43+
## Listening for a Single Planet Click
44+
45+
```javascript
46+
import { Chart } from '@astrodraw/astrochart'
47+
48+
const chart = new Chart('chart', 600, 600, { ADD_CLICK_AREA: true })
49+
chart.radix(data)
2250

23-
const chart = new Chart('chart', 600, 600, settings)
24-
const radix = chart.radix(data)
51+
document.getElementById('chart-radix-planets-Sun')
52+
?.addEventListener('click', (event) => {
53+
console.log('Sun clicked', event)
54+
})
2555
```
2656
2757
---
2858
29-
## Listening for Planet Clicks
59+
## Listening for All Planets via Event Delegation
3060
31-
Use `radix.on('click:planet', handler)` to respond when a planet symbol is clicked. The handler receives the planet name and the original DOM `MouseEvent`:
61+
Attach one listener to the SVG container and inspect the target `id` to determine which
62+
planet was clicked:
3263
3364
```javascript
34-
radix.on('click:planet', (name, event) => {
35-
console.log('Planet clicked:', name)
36-
console.log('DOM event:', event)
65+
import { Chart } from '@astrodraw/astrochart'
66+
67+
const chart = new Chart('chart', 600, 600, { ADD_CLICK_AREA: true })
68+
chart.radix(data)
69+
70+
document.getElementById('chart')?.addEventListener('click', (event) => {
71+
const id = (event.target as Element)?.id ?? ''
72+
const match = id.match(/^chart-radix-planets-(.+)$/)
73+
if (match) {
74+
const planetName = match[1]
75+
console.log('Planet clicked:', planetName)
76+
}
3777
})
3878
```
3979
40-
The `name` argument matches the planet key from your `AstroData` (e.g. `'Sun'`, `'Moon'`, `'Mars'`).
41-
4280
---
4381
4482
## Listening for Cusp Clicks
4583
46-
Use `radix.on('click:cusp', handler)` to respond when a house cusp is clicked. The handler receives the zero-based cusp index (0–11) and the `MouseEvent`:
84+
Cusp indices are zero-based — house 1 = index `0`, house 12 = index `11`.
4785
4886
```javascript
49-
radix.on('click:cusp', (index, event) => {
50-
const houseNumber = index + 1
51-
console.log('House clicked:', houseNumber)
87+
import { Chart } from '@astrodraw/astrochart'
88+
89+
const chart = new Chart('chart', 600, 600, { ADD_CLICK_AREA: true })
90+
chart.radix(data)
91+
92+
// House 1 (index 0)
93+
document.getElementById('chart-radix-cusps-0')
94+
?.addEventListener('click', (event) => {
95+
console.log('House 1 cusp clicked', event)
96+
})
97+
98+
// All cusps via delegation
99+
document.getElementById('chart')?.addEventListener('click', (event) => {
100+
const id = (event.target as Element)?.id ?? ''
101+
const match = id.match(/^chart-radix-cusps-(\d+)$/)
102+
if (match) {
103+
const houseNumber = Number(match[1]) + 1
104+
console.log('House clicked:', houseNumber)
105+
}
52106
})
53107
```
54108
@@ -61,28 +115,33 @@ import { Chart } from '@astrodraw/astrochart'
61115

62116
const data = {
63117
planets: {
64-
Sun: [120.5],
65-
Moon: [45.2],
66-
Mercury: [110.3],
67-
Venus: [98.7, -1], // retrograde
68-
Mars: [200.1],
118+
Sun: [120.5, 0],
119+
Moon: [45.2, 0],
120+
Mercury: [110.3, 0],
121+
Venus: [98.7, -1],
122+
Mars: [200.1, 0],
69123
},
70124
cusps: [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330]
71125
}
72126

73127
const chart = new Chart('chart', 600, 600, { ADD_CLICK_AREA: true })
74-
const radix = chart.radix(data)
75-
76-
// Planet click — show a tooltip or highlight
77-
radix.on('click:planet', (name, event) => {
78-
event.stopPropagation()
79-
alert(`You clicked: ${name}`)
80-
})
81-
82-
// Cusp click — display house info
83-
radix.on('click:cusp', (index, event) => {
84-
event.stopPropagation()
85-
console.log(`House ${index + 1} cusp starts at ${data.cusps[index]}°`)
128+
chart.radix(data)
129+
130+
// Event delegation — handles all planets and cusps with one listener
131+
document.getElementById('chart')?.addEventListener('click', (event) => {
132+
const id = (event.target as Element)?.id ?? ''
133+
134+
const planetMatch = id.match(/^chart-radix-planets-(.+)$/)
135+
if (planetMatch) {
136+
alert(`You clicked: ${planetMatch[1]}`)
137+
return
138+
}
139+
140+
const cuspMatch = id.match(/^chart-radix-cusps-(\d+)$/)
141+
if (cuspMatch) {
142+
const houseNumber = Number(cuspMatch[1]) + 1
143+
console.log(`House ${houseNumber} cusp starts at ${data.cusps[Number(cuspMatch[1])]}°`)
144+
}
86145
})
87146
```
88147
@@ -96,15 +155,18 @@ HTML:
96155
97156
## Notes
98157
99-
- **`ADD_CLICK_AREA: true` is required.** If this setting is omitted or set to `false`, no click areas are rendered and the `on()` handlers will never fire.
100-
- Events are standard DOM `MouseEvent` objects so you have access to `event.target`, `event.clientX`, `event.clientY`, etc.
101-
- The `click:planet` event fires for all planets present in your `AstroData.planets` map.
102-
- The `click:cusp` index is zero-based — house 1 is index `0`, house 12 is index `11`.
158+
- **`ADD_CLICK_AREA: true` is required.** Without it no transparent hit areas are rendered.
159+
- The click target is the `<rect>` element, not the planet symbol itself. Use the `id`
160+
attribute on `event.target` to identify which planet or cusp was clicked.
161+
- Events are standard DOM `MouseEvent` objects — `event.clientX`, `event.clientY`,
162+
`event.target`, etc. are all available.
163+
- If you customise `ID_RADIX`, `ID_POINTS`, or `ID_CUSPS` in your settings, the element
164+
IDs change. Adjust your regex patterns or selectors accordingly.
103165
104166
---
105167
106168
## Next Steps
107169
108170
- **[Custom Settings](./custom-settings)** — Configure `ADD_CLICK_AREA` and other options
109171
- **[Framework Integrations](./frameworks/react)** — Use click events with React, Vue, and Angular
110-
- **[API Reference](../api/chart)**See all chart methods
172+
- **[Settings API Reference](../api/settings)** — Full settings type documentation

website/src/content/docs/guides/frameworks/vue.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ Use a template ref and `onMounted`/`onUnmounted` to manage the chart lifecycle:
1717
<script setup lang="ts">
1818
import { ref, onMounted, onUnmounted, watch } from 'vue'
1919
import { Chart } from '@astrodraw/astrochart'
20-
import type { AstroData } from '@astrodraw/astrochart'
20+
21+
type AstroData = Parameters<InstanceType<typeof Chart>['radix']>[0]
2122
2223
interface Props {
2324
data: AstroData

website/src/styles/custom.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818

1919
/* Chart demo containers */
20-
.chart-demo {
20+
.chart-demo-wrapper {
2121
display: flex;
2222
justify-content: center;
2323
margin: 2rem 0;
@@ -28,13 +28,13 @@
2828
padding: 1.5rem;
2929
}
3030

31-
:root[data-theme="dark"] .chart-demo {
31+
:root[data-theme="dark"] .chart-demo-wrapper {
3232
background: hsl(240, 15%, 14%);
3333
border-color: hsl(240, 20%, 25%);
3434
box-shadow: 0 2px 16px 0 hsl(240, 40%, 5%, 0.6);
3535
}
3636

37-
.chart-demo svg {
37+
.chart-demo-wrapper svg {
3838
max-width: 100%;
3939
height: auto;
4040
}

0 commit comments

Comments
 (0)