kerykeion 4.26.1__py3-none-any.whl → 5.0.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of kerykeion might be problematic. Click here for more details.

Files changed (50) hide show
  1. kerykeion/__init__.py +8 -5
  2. kerykeion/aspects/aspects_utils.py +14 -8
  3. kerykeion/aspects/natal_aspects.py +26 -17
  4. kerykeion/aspects/synastry_aspects.py +32 -15
  5. kerykeion/aspects/transits_time_range.py +2 -2
  6. kerykeion/astrological_subject_factory.py +1132 -0
  7. kerykeion/charts/charts_utils.py +583 -85
  8. kerykeion/charts/draw_planets.py +9 -8
  9. kerykeion/charts/draw_planets_v2.py +639 -0
  10. kerykeion/charts/kerykeion_chart_svg.py +1289 -592
  11. kerykeion/charts/templates/chart.xml +178 -79
  12. kerykeion/charts/templates/wheel_only.xml +13 -12
  13. kerykeion/charts/themes/classic.css +91 -76
  14. kerykeion/charts/themes/dark-high-contrast.css +129 -107
  15. kerykeion/charts/themes/dark.css +130 -107
  16. kerykeion/charts/themes/light.css +130 -103
  17. kerykeion/charts/themes/strawberry.css +143 -0
  18. kerykeion/composite_subject_factory.py +26 -43
  19. kerykeion/ephemeris_data.py +6 -10
  20. kerykeion/house_comparison/__init__.py +3 -0
  21. kerykeion/house_comparison/house_comparison_factory.py +70 -0
  22. kerykeion/house_comparison/house_comparison_models.py +38 -0
  23. kerykeion/house_comparison/house_comparison_utils.py +98 -0
  24. kerykeion/kr_types/chart_types.py +9 -3
  25. kerykeion/kr_types/kr_literals.py +34 -6
  26. kerykeion/kr_types/kr_models.py +122 -160
  27. kerykeion/kr_types/settings_models.py +107 -143
  28. kerykeion/planetary_return_factory.py +299 -0
  29. kerykeion/relationship_score/relationship_score.py +3 -3
  30. kerykeion/relationship_score/relationship_score_factory.py +9 -12
  31. kerykeion/report.py +4 -4
  32. kerykeion/settings/config_constants.py +35 -6
  33. kerykeion/settings/kerykeion_settings.py +1 -0
  34. kerykeion/settings/kr.config.json +1301 -1255
  35. kerykeion/settings/legacy/__init__.py +0 -0
  36. kerykeion/settings/legacy/legacy_celestial_points_settings.py +299 -0
  37. kerykeion/settings/legacy/legacy_chart_aspects_settings.py +71 -0
  38. kerykeion/settings/legacy/legacy_color_settings.py +42 -0
  39. kerykeion/transits_time_range.py +13 -9
  40. kerykeion/utilities.py +228 -31
  41. {kerykeion-4.26.1.dist-info → kerykeion-5.0.0a1.dist-info}/METADATA +137 -10
  42. kerykeion-5.0.0a1.dist-info/RECORD +56 -0
  43. {kerykeion-4.26.1.dist-info → kerykeion-5.0.0a1.dist-info}/WHEEL +1 -1
  44. kerykeion/.DS_Store +0 -0
  45. kerykeion/astrological_subject.py +0 -841
  46. kerykeion/charts/.DS_Store +0 -0
  47. kerykeion-4.26.1.dist-info/LICENSE +0 -661
  48. kerykeion-4.26.1.dist-info/RECORD +0 -48
  49. /LICENSE → /kerykeion-5.0.0a1.dist-info/LICENSE +0 -0
  50. {kerykeion-4.26.1.dist-info → kerykeion-5.0.0a1.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,639 @@
1
+ from kerykeion.charts.charts_utils import degreeDiff, sliceToX, sliceToY, convert_decimal_to_degree_string
2
+ from kerykeion.kr_types import KerykeionException, ChartType, KerykeionPointModel
3
+ from kerykeion.kr_types.settings_models import KerykeionSettingsCelestialPointModel
4
+ from kerykeion.kr_types.kr_literals import Houses
5
+ import logging
6
+ from typing import Union, get_args
7
+
8
+
9
+ def draw_planets_v2(
10
+ radius: Union[int, float],
11
+ available_kerykeion_celestial_points: list[KerykeionPointModel],
12
+ available_planets_setting: list[KerykeionSettingsCelestialPointModel],
13
+ third_circle_radius: Union[int, float],
14
+ main_subject_first_house_degree_ut: Union[int, float],
15
+ main_subject_seventh_house_degree_ut: Union[int, float],
16
+ chart_type: ChartType,
17
+ second_subject_available_kerykeion_celestial_points: Union[list[KerykeionPointModel], None] = None,
18
+ ) -> str:
19
+ """
20
+ Draws the planets on an astrological chart based on the provided parameters.
21
+
22
+ This function calculates positions, handles overlap of celestial points, and draws SVG
23
+ elements for each planet/point on the chart. It supports different chart types including
24
+ natal charts, transits, synastry, and returns.
25
+
26
+ Args:
27
+ radius (Union[int, float]): The radius of the chart in pixels.
28
+ available_kerykeion_celestial_points (list[KerykeionPointModel]): List of celestial points for the main subject.
29
+ available_planets_setting (list[KerykeionSettingsCelestialPointModel]): Settings for the celestial points.
30
+ third_circle_radius (Union[int, float]): Radius of the third circle in the chart.
31
+ main_subject_first_house_degree_ut (Union[int, float]): Degree of the first house for the main subject.
32
+ main_subject_seventh_house_degree_ut (Union[int, float]): Degree of the seventh house for the main subject.
33
+ chart_type (ChartType): Type of the chart (e.g., "Transit", "Synastry", "Return", "ExternalNatal").
34
+ second_subject_available_kerykeion_celestial_points (Union[list[KerykeionPointModel], None], optional):
35
+ List of celestial points for the second subject, required for "Transit", "Synastry", or "Return" charts.
36
+ Defaults to None.
37
+
38
+ Raises:
39
+ KerykeionException: If secondary celestial points are required but not provided.
40
+
41
+ Returns:
42
+ str: SVG output for the chart with the planets drawn.
43
+ """
44
+ # Constants and initialization
45
+ PLANET_GROUPING_THRESHOLD = 3.4 # Distance threshold to consider planets as grouped
46
+ TRANSIT_RING_EXCLUDE_POINTS_NAMES = get_args(Houses)
47
+ output = ""
48
+
49
+ # -----------------------------------------------------------
50
+ # 1. Validate inputs and prepare data
51
+ # -----------------------------------------------------------
52
+ if chart_type == "Transit" and second_subject_available_kerykeion_celestial_points is None:
53
+ raise KerykeionException(f"Secondary celestial points are required for Transit charts")
54
+ elif chart_type == "Synastry" and second_subject_available_kerykeion_celestial_points is None:
55
+ raise KerykeionException(f"Secondary celestial points are required for Synastry charts")
56
+ elif chart_type == "Return" and second_subject_available_kerykeion_celestial_points is None:
57
+ raise KerykeionException(f"Secondary celestial points are required for Return charts")
58
+
59
+ # Extract absolute and relative positions for main celestial points
60
+ main_points_abs_positions = [planet.abs_pos for planet in available_kerykeion_celestial_points]
61
+ main_points_rel_positions = [planet.position for planet in available_kerykeion_celestial_points]
62
+
63
+ # Extract absolute and relative positions for secondary celestial points if needed
64
+ secondary_points_abs_positions = []
65
+ secondary_points_rel_positions = []
66
+ if chart_type == "Transit" or chart_type == "Synastry" or chart_type == "Return":
67
+ secondary_points_abs_positions = [
68
+ planet.abs_pos for planet in second_subject_available_kerykeion_celestial_points
69
+ ]
70
+ secondary_points_rel_positions = [
71
+ planet.position for planet in second_subject_available_kerykeion_celestial_points
72
+ ]
73
+
74
+ # -----------------------------------------------------------
75
+ # 2. Create position lookup dictionary for main celestial points
76
+ # -----------------------------------------------------------
77
+ # Map absolute degree to index in the settings array
78
+ position_index_map = {}
79
+ for i in range(len(available_planets_setting)):
80
+ position_index_map[main_points_abs_positions[i]] = i
81
+ logging.debug(f"Planet index: {i}, degree: {main_points_abs_positions[i]}")
82
+
83
+ # Sort positions for ordered processing
84
+ sorted_positions = sorted(position_index_map.keys())
85
+
86
+ # -----------------------------------------------------------
87
+ # 3. Identify groups of celestial points that are close to each other
88
+ # -----------------------------------------------------------
89
+ point_groups = []
90
+ current_group = []
91
+ is_group_open = False
92
+ planets_by_position = [None] * len(position_index_map)
93
+
94
+ # Process each celestial point to find groups
95
+ for position_idx, abs_position in enumerate(sorted_positions):
96
+ point_idx = position_index_map[abs_position]
97
+
98
+ # Find previous and next point positions for distance calculations
99
+ if position_idx == 0:
100
+ prev_position = main_points_abs_positions[position_index_map[sorted_positions[-1]]]
101
+ next_position = main_points_abs_positions[position_index_map[sorted_positions[1]]]
102
+ elif position_idx == len(sorted_positions) - 1:
103
+ prev_position = main_points_abs_positions[position_index_map[sorted_positions[position_idx - 1]]]
104
+ next_position = main_points_abs_positions[position_index_map[sorted_positions[0]]]
105
+ else:
106
+ prev_position = main_points_abs_positions[position_index_map[sorted_positions[position_idx - 1]]]
107
+ next_position = main_points_abs_positions[position_index_map[sorted_positions[position_idx + 1]]]
108
+
109
+ # Calculate distance to adjacent points
110
+ distance_to_prev = degreeDiff(prev_position, main_points_abs_positions[point_idx])
111
+ distance_to_next = degreeDiff(next_position, main_points_abs_positions[point_idx])
112
+
113
+ # Store position and distance information
114
+ planets_by_position[position_idx] = [point_idx, distance_to_prev, distance_to_next]
115
+
116
+ label = available_planets_setting[point_idx]["label"]
117
+ logging.debug(f"{label}, distance_to_prev: {distance_to_prev}, distance_to_next: {distance_to_next}")
118
+
119
+ # Group points that are close to each other
120
+ if distance_to_next < PLANET_GROUPING_THRESHOLD:
121
+ point_data = [position_idx, distance_to_prev, distance_to_next, label]
122
+ if is_group_open:
123
+ point_groups[-1].append(point_data)
124
+ else:
125
+ is_group_open = True
126
+ point_groups.append([point_data])
127
+ else:
128
+ if is_group_open:
129
+ point_data = [position_idx, distance_to_prev, distance_to_next, label]
130
+ point_groups[-1].append(point_data)
131
+ is_group_open = False
132
+
133
+ # -----------------------------------------------------------
134
+ # 4. Calculate position adjustments to avoid overlapping
135
+ # -----------------------------------------------------------
136
+ position_adjustments = [0] * len(available_planets_setting)
137
+
138
+ # Process each group to calculate position adjustments
139
+ for group in point_groups:
140
+ group_size = len(group)
141
+
142
+ # Handle groups of two celestial points
143
+ if group_size == 2:
144
+ handle_two_point_group(group, planets_by_position, position_adjustments, PLANET_GROUPING_THRESHOLD)
145
+
146
+ # Handle groups of three or more celestial points
147
+ elif group_size >= 3:
148
+ handle_multi_point_group(group, position_adjustments, PLANET_GROUPING_THRESHOLD)
149
+
150
+ # -----------------------------------------------------------
151
+ # 5. Draw main celestial points
152
+ # -----------------------------------------------------------
153
+ for position_idx, abs_position in enumerate(sorted_positions):
154
+ point_idx = position_index_map[abs_position]
155
+
156
+ # Determine radius based on chart type and point type
157
+ point_radius = determine_point_radius(point_idx, chart_type, bool(position_idx % 2))
158
+
159
+ # Calculate position offset for the point
160
+ adjusted_offset = calculate_point_offset(
161
+ main_subject_seventh_house_degree_ut,
162
+ main_points_abs_positions[point_idx],
163
+ position_adjustments[position_idx],
164
+ )
165
+
166
+ # Calculate true position without adjustment (used for connecting lines)
167
+ true_offset = calculate_point_offset(
168
+ main_subject_seventh_house_degree_ut,
169
+ main_points_abs_positions[point_idx],
170
+ 0
171
+ )
172
+
173
+ # Calculate point coordinates
174
+ point_x = sliceToX(0, radius - point_radius, adjusted_offset) + point_radius
175
+ point_y = sliceToY(0, radius - point_radius, adjusted_offset) + point_radius
176
+
177
+ # Determine scale factor based on chart type
178
+ scale_factor = 1.0
179
+ if chart_type == "Transit":
180
+ scale_factor = 0.8
181
+ elif chart_type == "Synastry":
182
+ scale_factor = 0.8
183
+ elif chart_type == "Return":
184
+ scale_factor = 0.8
185
+ elif chart_type == "ExternalNatal":
186
+ scale_factor = 0.8
187
+
188
+ # Draw connecting lines for ExternalNatal chart type
189
+ if chart_type == "ExternalNatal":
190
+ output = draw_external_natal_lines(
191
+ output,
192
+ radius,
193
+ third_circle_radius,
194
+ point_radius,
195
+ true_offset,
196
+ adjusted_offset,
197
+ available_planets_setting[point_idx]["color"],
198
+ )
199
+
200
+ # Draw the celestial point SVG element
201
+ point_details = available_kerykeion_celestial_points[point_idx]
202
+ output += generate_point_svg(
203
+ point_details, point_x, point_y, scale_factor, available_planets_setting[point_idx]["name"]
204
+ )
205
+
206
+ # -----------------------------------------------------------
207
+ # 6. Draw transit/secondary celestial points
208
+ # -----------------------------------------------------------
209
+ if chart_type == "Transit" or chart_type == "Synastry" or chart_type == "Return":
210
+ output = draw_secondary_points(
211
+ output,
212
+ radius,
213
+ main_subject_first_house_degree_ut,
214
+ main_subject_seventh_house_degree_ut,
215
+ secondary_points_abs_positions,
216
+ secondary_points_rel_positions,
217
+ available_planets_setting,
218
+ chart_type,
219
+ TRANSIT_RING_EXCLUDE_POINTS_NAMES,
220
+ adjusted_offset,
221
+ )
222
+
223
+ return output
224
+
225
+
226
+ def handle_two_point_group(
227
+ group: list, planets_by_position: list, position_adjustments: list, threshold: float
228
+ ) -> None:
229
+ """
230
+ Handle positioning for a group of two celestial points that are close to each other.
231
+
232
+ Adjusts positions to prevent overlapping by calculating appropriate offsets
233
+ based on available space around the points.
234
+
235
+ Args:
236
+ group (list): A list containing data about two closely positioned points.
237
+ planets_by_position (list): A list with data about all planets positions.
238
+ position_adjustments (list): The list to store calculated position adjustments.
239
+ threshold (float): The minimum distance threshold for considering points as grouped.
240
+ """
241
+ next_to_a = group[0][0] - 1
242
+ next_to_b = 0 if group[1][0] == (len(planets_by_position) - 1) else group[1][0] + 1
243
+
244
+ # If both points have room
245
+ if (group[0][1] > (2 * threshold)) and (group[1][2] > (2 * threshold)):
246
+ position_adjustments[group[0][0]] = -(threshold - group[0][2]) / 2
247
+ position_adjustments[group[1][0]] = +(threshold - group[0][2]) / 2
248
+
249
+ # If only first point has room
250
+ elif group[0][1] > (2 * threshold):
251
+ position_adjustments[group[0][0]] = -threshold
252
+
253
+ # If only second point has room
254
+ elif group[1][2] > (2 * threshold):
255
+ position_adjustments[group[1][0]] = +threshold
256
+
257
+ # If points adjacent to group have room
258
+ elif (planets_by_position[next_to_a][1] > (2.4 * threshold)) and (planets_by_position[next_to_b][2] > (2.4 * threshold)):
259
+ position_adjustments[next_to_a] = group[0][1] - threshold * 2
260
+ position_adjustments[group[0][0]] = -threshold * 0.5
261
+ position_adjustments[next_to_b] = -(group[1][2] - threshold * 2)
262
+ position_adjustments[group[1][0]] = +threshold * 0.5
263
+
264
+ # If only point adjacent to first has room
265
+ elif planets_by_position[next_to_a][1] > (2 * threshold):
266
+ position_adjustments[next_to_a] = group[0][1] - threshold * 2.5
267
+ position_adjustments[group[0][0]] = -threshold * 1.2
268
+
269
+ # If only point adjacent to second has room
270
+ elif planets_by_position[next_to_b][2] > (2 * threshold):
271
+ position_adjustments[next_to_b] = -(group[1][2] - threshold * 2.5)
272
+ position_adjustments[group[1][0]] = +threshold * 1.2
273
+
274
+
275
+ def handle_multi_point_group(group: list, position_adjustments: list, threshold: float) -> None:
276
+ """
277
+ Handle positioning for a group of three or more celestial points that are close to each other.
278
+
279
+ Distributes points evenly within the available space to prevent overlapping.
280
+
281
+ Args:
282
+ group (list): A list containing data about grouped points.
283
+ position_adjustments (list): The list to store calculated position adjustments.
284
+ threshold (float): The minimum distance threshold for considering points as grouped.
285
+ """
286
+ group_size = len(group)
287
+
288
+ # Calculate available space
289
+ available_space = group[0][1] # Distance before first point
290
+ for i in range(group_size):
291
+ available_space += group[i][2] # Add distance after each point
292
+
293
+ # Calculate needed space
294
+ needed_space = (3 * threshold) + (1.2 * (group_size - 1) * threshold)
295
+ leftover_space = available_space - needed_space
296
+
297
+ # Get spacing before first and after last point
298
+ space_before_first = group[0][1]
299
+ space_after_last = group[group_size - 1][2]
300
+
301
+ # Position points based on available space
302
+ if (space_before_first > (needed_space * 0.5)) and (space_after_last > (needed_space * 0.5)):
303
+ # Center the group
304
+ start_position = space_before_first - (needed_space * 0.5)
305
+ else:
306
+ # Distribute leftover space proportionally
307
+ start_position = (leftover_space / (space_before_first + space_after_last)) * space_before_first
308
+
309
+ # Apply positions if there's enough space
310
+ if available_space > needed_space:
311
+ position_adjustments[group[0][0]] = start_position - group[0][1] + (1.5 * threshold)
312
+
313
+ # Position each subsequent point relative to the previous one
314
+ for i in range(group_size - 1):
315
+ position_adjustments[group[i + 1][0]] = 1.2 * threshold + position_adjustments[group[i][0]] - group[i][2]
316
+
317
+
318
+ def determine_point_radius(
319
+ point_idx: int,
320
+ chart_type: str,
321
+ is_alternate_position: bool
322
+ ) -> int:
323
+ """
324
+ Determine the radius for placing a celestial point based on its type and chart type.
325
+
326
+ Args:
327
+ point_idx (int): Index of the celestial point.
328
+ chart_type (str): Type of the chart.
329
+ is_alternate_position (bool): Whether to use alternate positioning.
330
+
331
+ Returns:
332
+ int: Radius value for the point.
333
+ """
334
+ # Check if point is an angle of the chart (ASC, MC, DSC, IC)
335
+ is_chart_angle = 22 < point_idx < 27
336
+
337
+ if chart_type == "Transit":
338
+ if is_chart_angle:
339
+ return 76
340
+ else:
341
+ return 110 if is_alternate_position else 130
342
+ elif chart_type == "Synastry":
343
+ if is_chart_angle:
344
+ return 76
345
+ else:
346
+ return 110 if is_alternate_position else 130
347
+ elif chart_type == "Return":
348
+ if is_chart_angle:
349
+ return 76
350
+ else:
351
+ return 110 if is_alternate_position else 130
352
+ else:
353
+ # Default natal chart and ExternalNatal handling
354
+ # if 22 < point_idx < 27 it is asc,mc,dsc,ic (angles of chart)
355
+ amin, bmin, cmin = 0, 0, 0
356
+ if chart_type == "ExternalNatal":
357
+ amin = 74 - 10
358
+ bmin = 94 - 10
359
+ cmin = 40 - 10
360
+
361
+ if is_chart_angle:
362
+ return 40 - cmin
363
+ elif is_alternate_position:
364
+ return 74 - amin
365
+ else:
366
+ return 94 - bmin
367
+
368
+
369
+ def calculate_point_offset(
370
+ seventh_house_degree: Union[int, float], point_degree: Union[int, float], adjustment: Union[int, float]
371
+ ) -> float:
372
+ """
373
+ Calculate the offset position of a celestial point on the chart.
374
+
375
+ Args:
376
+ seventh_house_degree (Union[int, float]): Degree of the seventh house.
377
+ point_degree (Union[int, float]): Degree of the celestial point.
378
+ adjustment (Union[int, float]): Adjustment value to prevent overlapping.
379
+
380
+ Returns:
381
+ float: The calculated offset position.
382
+ """
383
+ return (int(seventh_house_degree) / -1) + int(point_degree + adjustment)
384
+
385
+
386
+ def draw_external_natal_lines(
387
+ output: str,
388
+ radius: Union[int, float],
389
+ third_circle_radius: Union[int, float],
390
+ point_radius: Union[int, float],
391
+ true_offset: Union[int, float],
392
+ adjusted_offset: Union[int, float],
393
+ color: str,
394
+ ) -> str:
395
+ """
396
+ Draw connecting lines for the ExternalNatal chart type.
397
+
398
+ Creates two line segments: one from the circle to the original position,
399
+ and another from the original position to the adjusted position.
400
+
401
+ Args:
402
+ output (str): The SVG output string to append to.
403
+ radius (Union[int, float]): Chart radius.
404
+ third_circle_radius (Union[int, float]): Radius of the third circle.
405
+ point_radius (Union[int, float]): Radius of the celestial point.
406
+ true_offset (Union[int, float]): True position offset.
407
+ adjusted_offset (Union[int, float]): Adjusted position offset.
408
+ color (str): Line color.
409
+
410
+ Returns:
411
+ str: Updated SVG output with added line elements.
412
+ """
413
+ # First line - from circle to outer position
414
+ x1 = sliceToX(0, radius - third_circle_radius, true_offset) + third_circle_radius
415
+ y1 = sliceToY(0, radius - third_circle_radius, true_offset) + third_circle_radius
416
+ x2 = sliceToX(0, radius - point_radius - 30, true_offset) + point_radius + 30
417
+ y2 = sliceToY(0, radius - point_radius - 30, true_offset) + point_radius + 30
418
+ output += f'<line x1="{x1}" y1="{y1}" x2="{x2}" y2="{y2}" style="stroke-width:1px;stroke:{color};stroke-opacity:.3;"/>\n'
419
+
420
+ # Second line - from outer position to adjusted position
421
+ x1 = x2
422
+ y1 = y2
423
+ x2 = sliceToX(0, radius - point_radius - 10, adjusted_offset) + point_radius + 10
424
+ y2 = sliceToY(0, radius - point_radius - 10, adjusted_offset) + point_radius + 10
425
+ output += f'<line x1="{x1}" y1="{y1}" x2="{x2}" y2="{y2}" style="stroke-width:1px;stroke:{color};stroke-opacity:.5;"/>\n'
426
+
427
+ return output
428
+
429
+
430
+ def generate_point_svg(point_details: KerykeionPointModel, x: float, y: float, scale: float, point_name: str) -> str:
431
+ """
432
+ Generate the SVG element for a celestial point.
433
+
434
+ Args:
435
+ point_details (KerykeionPointModel): Details about the celestial point.
436
+ x (float): X-coordinate for the point.
437
+ y (float): Y-coordinate for the point.
438
+ scale (float): Scale factor for the point.
439
+ point_name (str): Name of the celestial point.
440
+
441
+ Returns:
442
+ str: SVG element for the celestial point.
443
+ """
444
+ svg = f'<g kr:node="ChartPoint" kr:house="{point_details["house"]}" kr:sign="{point_details["sign"]}" '
445
+ svg += f'kr:slug="{point_details["name"]}" transform="translate(-{12 * scale},-{12 * scale}) scale({scale})">'
446
+ svg += f'<use x="{x * (1/scale)}" y="{y * (1/scale)}" xlink:href="#{point_name}" />'
447
+ svg += "</g>"
448
+ return svg
449
+
450
+
451
+ def draw_secondary_points(
452
+ output: str,
453
+ radius: Union[int, float],
454
+ first_house_degree: Union[int, float],
455
+ seventh_house_degree: Union[int, float],
456
+ points_abs_positions: list[Union[int, float]],
457
+ points_rel_positions: list[Union[int, float]],
458
+ points_settings: list[KerykeionSettingsCelestialPointModel],
459
+ chart_type: str,
460
+ exclude_points: list[str],
461
+ main_offset: float,
462
+ ) -> str:
463
+ """
464
+ Draw secondary celestial points (transit/synastry/return) on the chart.
465
+
466
+ Args:
467
+ output (str): Current SVG output to append to.
468
+ radius (Union[int, float]): Chart radius.
469
+ first_house_degree (Union[int, float]): Degree of the first house.
470
+ seventh_house_degree (Union[int, float]): Degree of the seventh house.
471
+ points_abs_positions (list[Union[int, float]]): Absolute positions of points.
472
+ points_rel_positions (list[Union[int, float]]): Relative positions of points.
473
+ points_settings (list[KerykeionSettingsCelestialPointModel]): Settings for points.
474
+ chart_type (str): Type of chart.
475
+ exclude_points (list[str]): List of point names to exclude.
476
+ main_offset (float): Offset position for the main point.
477
+
478
+ Returns:
479
+ str: Updated SVG output with added secondary points.
480
+ """
481
+ # Initialize position adjustments for grouped points
482
+ position_adjustments = {i: 0 for i in range(len(points_settings))}
483
+
484
+ # Map absolute position to point index
485
+ position_index_map = {}
486
+ for i in range(len(points_settings)):
487
+ if chart_type == "Transit" and points_settings[i]["name"] in exclude_points:
488
+ continue
489
+ position_index_map[points_abs_positions[i]] = i
490
+
491
+ # Sort positions
492
+ sorted_positions = sorted(position_index_map.keys())
493
+
494
+ # Find groups of points that are close to each other
495
+ point_groups = []
496
+ in_group = False
497
+
498
+ for pos_idx, abs_position in enumerate(sorted_positions):
499
+ point_a_idx = position_index_map[abs_position]
500
+
501
+ # Get next point
502
+ if pos_idx == len(sorted_positions) - 1:
503
+ point_b_idx = position_index_map[sorted_positions[0]]
504
+ else:
505
+ point_b_idx = position_index_map[sorted_positions[pos_idx + 1]]
506
+
507
+ # Check distance between points
508
+ position_a = points_abs_positions[point_a_idx]
509
+ position_b = points_abs_positions[point_b_idx]
510
+ distance = degreeDiff(position_a, position_b)
511
+
512
+ # Group points that are close
513
+ if distance <= 2.5:
514
+ if in_group:
515
+ point_groups[-1].append(point_b_idx)
516
+ else:
517
+ point_groups.append([point_a_idx])
518
+ point_groups[-1].append(point_b_idx)
519
+ in_group = True
520
+ else:
521
+ in_group = False
522
+
523
+ # Set position adjustments for grouped points
524
+ for group in point_groups:
525
+ if len(group) == 2:
526
+ position_adjustments[group[0]] = -1.0
527
+ position_adjustments[group[1]] = 1.0
528
+ elif len(group) == 3:
529
+ position_adjustments[group[0]] = -1.5
530
+ position_adjustments[group[1]] = 0
531
+ position_adjustments[group[2]] = 1.5
532
+ elif len(group) == 4:
533
+ position_adjustments[group[0]] = -2.0
534
+ position_adjustments[group[1]] = -1.0
535
+ position_adjustments[group[2]] = 1.0
536
+ position_adjustments[group[3]] = 2.0
537
+
538
+ # Draw each secondary point
539
+ alternate_position = False
540
+
541
+ for pos_idx, abs_position in enumerate(sorted_positions):
542
+ point_idx = position_index_map[abs_position]
543
+
544
+ if chart_type == "Transit" and points_settings[point_idx]["name"] in exclude_points:
545
+ continue
546
+
547
+ # Determine radius based on point type
548
+ if 22 < point_idx < 27: # Chart angles
549
+ point_radius = 9
550
+ elif alternate_position:
551
+ point_radius = 18
552
+ alternate_position = False
553
+ else:
554
+ point_radius = 26
555
+ alternate_position = True
556
+
557
+ # Calculate position
558
+ zero_point = 360 - seventh_house_degree
559
+ point_offset = zero_point + points_abs_positions[point_idx]
560
+ if point_offset > 360:
561
+ point_offset -= 360
562
+
563
+ # Draw point symbol
564
+ point_x = sliceToX(0, radius - point_radius, point_offset) + point_radius
565
+ point_y = sliceToY(0, radius - point_radius, point_offset) + point_radius
566
+ output += f'<g class="transit-planet-name" transform="translate(-6,-6)"><g transform="scale(0.5)">'
567
+ output += f'<use x="{point_x*2}" y="{point_y*2}" xlink:href="#{points_settings[point_idx]["name"]}" /></g></g>'
568
+
569
+ # Draw connecting line
570
+ x1 = sliceToX(0, radius + 3, point_offset) - 3
571
+ y1 = sliceToY(0, radius + 3, point_offset) - 3
572
+ x2 = sliceToX(0, radius - 3, point_offset) + 3
573
+ y2 = sliceToY(0, radius - 3, point_offset) + 3
574
+ output += f'<line class="transit-planet-line" x1="{x1}" y1="{y1}" x2="{x2}" y2="{y2}" '
575
+ output += f'style="stroke: {points_settings[point_idx]["color"]}; stroke-width: 1px; stroke-opacity:.8;"/>'
576
+
577
+ # Draw degree text with rotation
578
+ rotation = first_house_degree - points_abs_positions[point_idx]
579
+ text_anchor = "end"
580
+
581
+ # Adjust text rotation and anchor for readability
582
+ if -90 > rotation > -270:
583
+ rotation += 180.0
584
+ text_anchor = "start"
585
+ if 270 > rotation > 90:
586
+ rotation -= 180.0
587
+ text_anchor = "start"
588
+
589
+ # Position the degree text
590
+ x_offset = 1 if text_anchor == "end" else -1
591
+ adjusted_point_offset = point_offset + position_adjustments[point_idx]
592
+ text_radius = -3.0
593
+
594
+ deg_x = sliceToX(0, radius - text_radius, adjusted_point_offset + x_offset) + text_radius
595
+ deg_y = sliceToY(0, radius - text_radius, adjusted_point_offset + x_offset) + text_radius
596
+
597
+ # Format and output the degree text
598
+ degree_text = convert_decimal_to_degree_string(points_rel_positions[point_idx], format_type="1")
599
+ output += f'<g transform="translate({deg_x},{deg_y})">'
600
+ output += f'<text transform="rotate({rotation})" text-anchor="{text_anchor}" '
601
+ output += f'style="fill: {points_settings[point_idx]["color"]}; font-size: 10px;">{degree_text}</text></g>'
602
+
603
+ # Draw connecting lines for the main point
604
+ dropin = 0
605
+ if chart_type == "Transit":
606
+ dropin = 36
607
+ elif chart_type == "Synastry":
608
+ dropin = 36
609
+ elif chart_type == "Return":
610
+ dropin = 36
611
+
612
+ # First connecting line segment
613
+ x1 = sliceToX(0, radius - (dropin + 3), main_offset) + (dropin + 3)
614
+ y1 = sliceToY(0, radius - (dropin + 3), main_offset) + (dropin + 3)
615
+ x2 = sliceToX(0, radius - (dropin - 3), main_offset) + (dropin - 3)
616
+ y2 = sliceToY(0, radius - (dropin - 3), main_offset) + (dropin - 3)
617
+
618
+ point_color = points_settings[point_idx]["color"]
619
+ output += f'<line x1="{x1}" y1="{y1}" x2="{x2}" y2="{y2}" '
620
+ output += f'style="stroke: {point_color}; stroke-width: 2px; stroke-opacity:.6;"/>'
621
+
622
+ # Second connecting line segment
623
+ dropin = 120
624
+ if chart_type == "Transit":
625
+ dropin = 160
626
+ elif chart_type == "Synastry":
627
+ dropin = 160
628
+ elif chart_type == "Return":
629
+ dropin = 160
630
+
631
+ x1 = sliceToX(0, radius - dropin, main_offset) + dropin
632
+ y1 = sliceToY(0, radius - dropin, main_offset) + dropin
633
+ x2 = sliceToX(0, radius - (dropin - 3), main_offset) + (dropin - 3)
634
+ y2 = sliceToY(0, radius - (dropin - 3), main_offset) + (dropin - 3)
635
+
636
+ output += f'<line x1="{x1}" y1="{y1}" x2="{x2}" y2="{y2}" '
637
+ output += f'style="stroke: {point_color}; stroke-width: 2px; stroke-opacity:.6;"/>'
638
+
639
+ return output