From 1839a4d28b0be1fa250f11aaf3cd7c9419f33987 Mon Sep 17 00:00:00 2001 From: Prajwal Adhikari Date: Mon, 9 Mar 2026 07:06:26 +0545 Subject: [PATCH] Cleaned --- astro_functions.php | 16 ++++--- css.css | 1 + index.php | 22 +++++---- js.js | 106 ++++++++++++++++++++++++++++---------------- 4 files changed, 91 insertions(+), 54 deletions(-) diff --git a/astro_functions.php b/astro_functions.php index 2b5f588..df7c6d9 100644 --- a/astro_functions.php +++ b/astro_functions.php @@ -86,19 +86,20 @@ function getNakshatraKeyFromLongitude(float $longitude): string function buildPlanetDataFromLongitude( string $planetKey, float $longitude, - int $segment, string $mode = NAME_MODE_MODERN ): array { - $signKey = getSignKeyFromLongitude($longitude); - $nakshatraKey = getNakshatraKeyFromLongitude($longitude); - $degreeWithinSign = getDegreeWithinSign($longitude); + $normalizedLongitude = normalizeLongitude($longitude); + $signKey = getSignKeyFromLongitude($normalizedLongitude); + $nakshatraKey = getNakshatraKeyFromLongitude($normalizedLongitude); + $degreeWithinSign = getDegreeWithinSign($normalizedLongitude); + $segment = getSegmentFromLongitude($normalizedLongitude); return [ 'key' => $planetKey, 'name' => getPlanetName($planetKey, $mode), 'short' => getPlanetShortName($planetKey), 'house' => $segment, - 'longitude' => normalizeLongitude($longitude), + 'longitude' => $normalizedLongitude, 'sign_key' => $signKey, 'sign' => getSignName($signKey, $mode), 'degree_value' => $degreeWithinSign, @@ -115,4 +116,9 @@ function sortPlanetsByLongitude(array $planets): array }); return $planets; +} +function getSegmentFromLongitude(float $longitude): int +{ + $longitude = normalizeLongitude($longitude); + return ((int) floor($longitude / 30)) + 1; } \ No newline at end of file diff --git a/css.css b/css.css index d3f1247..5cb8074 100644 --- a/css.css +++ b/css.css @@ -166,6 +166,7 @@ line-height:1; white-space:nowrap; box-shadow:0 4px 10px rgba(0,0,0,0.2); + z-index:5; } .table-box{ background: rgba(255,255,255,0.05); diff --git a/index.php b/index.php index 109af68..16a1147 100644 --- a/index.php +++ b/index.php @@ -86,23 +86,21 @@ if (!empty($date) && !empty($time) && !empty($location) && isset($locationMap[$l house = wheel segment number */ $samplePlanets = [ - buildPlanetDataFromLongitude('sun', 5.20, 1, $nameMode), - buildPlanetDataFromLongitude('moon', 72.13, 3, $nameMode), - buildPlanetDataFromLongitude('mars', 78.35, 3, $nameMode), - buildPlanetDataFromLongitude('mercury', 32.08, 2, $nameMode), - buildPlanetDataFromLongitude('venus', 41.30, 2, $nameMode), - buildPlanetDataFromLongitude('jupiter', 129.18, 5, $nameMode), - buildPlanetDataFromLongitude('saturn', 22.43, 1, $nameMode), - buildPlanetDataFromLongitude('rahu', 304.23, 11, $nameMode), - buildPlanetDataFromLongitude('ketu', 124.23, 7, $nameMode) + buildPlanetDataFromLongitude('sun', 5.20, $nameMode), + buildPlanetDataFromLongitude('moon', 72.13, $nameMode), + buildPlanetDataFromLongitude('mars', 78.35, $nameMode), + buildPlanetDataFromLongitude('mercury', 32.08, $nameMode), + buildPlanetDataFromLongitude('venus', 41.30, $nameMode), + buildPlanetDataFromLongitude('jupiter', 129.18, $nameMode), + buildPlanetDataFromLongitude('saturn', 22.43, $nameMode), + buildPlanetDataFromLongitude('rahu', 304.23, $nameMode), + buildPlanetDataFromLongitude('ketu', 124.23, $nameMode) ]; $planetsByHierarchy = $samplePlanets; $positionsInOrder = sortPlanetsByLongitude($samplePlanets); -usort($positionsInOrder, function ($a, $b) { - return $a['house'] <=> $b['house']; -}); + ?> diff --git a/js.js b/js.js index 3daa9f6..d3212cb 100644 --- a/js.js +++ b/js.js @@ -1,9 +1,9 @@ document.addEventListener("DOMContentLoaded", function () { const astroCircle = document.getElementById("astroCircle"); + if (!astroCircle) return; const segmentNumbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]; - const circleSize = astroCircle.offsetWidth; const centerX = circleSize / 2; const centerY = circleSize / 2; @@ -11,22 +11,26 @@ document.addEventListener("DOMContentLoaded", function () { const numberRadius = radius + (circleSize < 400 ? 18 : 28); const signRadius = radius * 0.84; - const planetRadius = radius * 0.66; + drawSegments(astroCircle, centerX, centerY, radius, segmentNumbers, signNames, numberRadius, signRadius); + + if (typeof samplePlanets !== "undefined" && Array.isArray(samplePlanets)) { + placePlanetsByLongitude(astroCircle, samplePlanets, centerX, centerY, radius); + } +}); + +function drawSegments(astroCircle, centerX, centerY, radius, segmentNumbers, signNames, numberRadius, signRadius) { for (let i = 0; i < 12; i++) { const angleDeg = i * 30; - // segment divider const line = document.createElement("div"); line.classList.add("segment-line"); line.style.transform = `translateX(-50%) rotate(${angleDeg}deg)`; astroCircle.appendChild(line); - // middle of segment const midAngle = angleDeg + 15; - const midRad = (midAngle - 90) * Math.PI / 180; + const midRad = degToRad(midAngle - 90); - // outside segment number const numberX = centerX + numberRadius * Math.cos(midRad); const numberY = centerY + numberRadius * Math.sin(midRad); @@ -37,7 +41,6 @@ document.addEventListener("DOMContentLoaded", function () { number.style.top = `${numberY}px`; astroCircle.appendChild(number); - // inside sign label const signX = centerX + signRadius * Math.cos(midRad); const signY = centerY + signRadius * Math.sin(midRad); @@ -48,44 +51,73 @@ document.addEventListener("DOMContentLoaded", function () { sign.style.top = `${signY}px`; astroCircle.appendChild(sign); } +} - if (typeof samplePlanets !== "undefined" && Array.isArray(samplePlanets)) { - placeSamplePlanets(astroCircle, samplePlanets, centerX, centerY, planetRadius); - } -}); - -function placeSamplePlanets(astroCircle, planets, centerX, centerY, planetRadius) { - const groupedByHouse = {}; - - planets.forEach(planet => { - if (!groupedByHouse[planet.house]) { - groupedByHouse[planet.house] = []; - } - groupedByHouse[planet.house].push(planet); +function placePlanetsByLongitude(astroCircle, planets, centerX, centerY, radius) { + const sortedPlanets = [...planets].sort((a, b) => { + return (a.longitude || 0) - (b.longitude || 0); }); - Object.keys(groupedByHouse).forEach(houseKey => { - const houseNumber = parseInt(houseKey, 10); - const housePlanets = groupedByHouse[houseNumber]; + const usedSlots = []; - const segmentStartAngle = (houseNumber - 1) * 30; - const segmentMidAngle = segmentStartAngle + 15; - const segmentMidRad = (segmentMidAngle - 90) * Math.PI / 180; + sortedPlanets.forEach((planet) => { + const longitude = normalizeLongitude(Number(planet.longitude || 0)); - const baseX = centerX + planetRadius * Math.cos(segmentMidRad); - const baseY = centerY + planetRadius * Math.sin(segmentMidRad); + // 0° Aries starts at top, so subtract 90° + const angleRad = degToRad(longitude - 90); - housePlanets.forEach((planet, index) => { - const planetEl = document.createElement("div"); - planetEl.classList.add("planet-tag"); - planetEl.innerText = planet.short; - planetEl.title = planet.name + " | Segment " + planet.house + " | " + planet.sign; + // base position inside circle + let ringRadius = radius * 0.67; - const verticalOffset = index * 24; - planetEl.style.left = `${baseX}px`; - planetEl.style.top = `${baseY + verticalOffset}px`; + // detect nearby planets and move slightly inward/outward + let closeCount = 0; + for (let i = 0; i < usedSlots.length; i++) { + const diff = smallestAngleDifference(longitude, usedSlots[i].longitude); + if (diff < 12) { + closeCount++; + } + } - astroCircle.appendChild(planetEl); + // alternate offsets for crowded areas + if (closeCount > 0) { + const offsetPattern = [0, -18, 18, -32, 32, -44, 44]; + const offset = offsetPattern[Math.min(closeCount, offsetPattern.length - 1)]; + ringRadius += offset; + } + + const x = centerX + ringRadius * Math.cos(angleRad); + const y = centerY + ringRadius * Math.sin(angleRad); + + const planetEl = document.createElement("div"); + planetEl.classList.add("planet-tag"); + planetEl.innerText = planet.short; + planetEl.title = + `${planet.name} | ${planet.sign} | ${planet.degree} | ${planet.nakshatra} | ${longitude.toFixed(2)}°`; + + planetEl.style.left = `${x}px`; + planetEl.style.top = `${y}px`; + + astroCircle.appendChild(planetEl); + + usedSlots.push({ + longitude: longitude, + x: x, + y: y }); }); +} + +function degToRad(deg) { + return deg * Math.PI / 180; +} + +function normalizeLongitude(value) { + let result = value % 360; + if (result < 0) result += 360; + return result; +} + +function smallestAngleDifference(a, b) { + let diff = Math.abs(a - b) % 360; + return diff > 180 ? 360 - diff : diff; } \ No newline at end of file