This commit is contained in:
2026-03-09 07:06:26 +05:45
parent f5a41a3546
commit 1839a4d28b
4 changed files with 91 additions and 54 deletions

View File

@@ -86,19 +86,20 @@ function getNakshatraKeyFromLongitude(float $longitude): string
function buildPlanetDataFromLongitude( function buildPlanetDataFromLongitude(
string $planetKey, string $planetKey,
float $longitude, float $longitude,
int $segment,
string $mode = NAME_MODE_MODERN string $mode = NAME_MODE_MODERN
): array { ): array {
$signKey = getSignKeyFromLongitude($longitude); $normalizedLongitude = normalizeLongitude($longitude);
$nakshatraKey = getNakshatraKeyFromLongitude($longitude); $signKey = getSignKeyFromLongitude($normalizedLongitude);
$degreeWithinSign = getDegreeWithinSign($longitude); $nakshatraKey = getNakshatraKeyFromLongitude($normalizedLongitude);
$degreeWithinSign = getDegreeWithinSign($normalizedLongitude);
$segment = getSegmentFromLongitude($normalizedLongitude);
return [ return [
'key' => $planetKey, 'key' => $planetKey,
'name' => getPlanetName($planetKey, $mode), 'name' => getPlanetName($planetKey, $mode),
'short' => getPlanetShortName($planetKey), 'short' => getPlanetShortName($planetKey),
'house' => $segment, 'house' => $segment,
'longitude' => normalizeLongitude($longitude), 'longitude' => $normalizedLongitude,
'sign_key' => $signKey, 'sign_key' => $signKey,
'sign' => getSignName($signKey, $mode), 'sign' => getSignName($signKey, $mode),
'degree_value' => $degreeWithinSign, 'degree_value' => $degreeWithinSign,
@@ -115,4 +116,9 @@ function sortPlanetsByLongitude(array $planets): array
}); });
return $planets; return $planets;
}
function getSegmentFromLongitude(float $longitude): int
{
$longitude = normalizeLongitude($longitude);
return ((int) floor($longitude / 30)) + 1;
} }

View File

@@ -166,6 +166,7 @@
line-height:1; line-height:1;
white-space:nowrap; white-space:nowrap;
box-shadow:0 4px 10px rgba(0,0,0,0.2); box-shadow:0 4px 10px rgba(0,0,0,0.2);
z-index:5;
} }
.table-box{ .table-box{
background: rgba(255,255,255,0.05); background: rgba(255,255,255,0.05);

View File

@@ -86,23 +86,21 @@ if (!empty($date) && !empty($time) && !empty($location) && isset($locationMap[$l
house = wheel segment number house = wheel segment number
*/ */
$samplePlanets = [ $samplePlanets = [
buildPlanetDataFromLongitude('sun', 5.20, 1, $nameMode), buildPlanetDataFromLongitude('sun', 5.20, $nameMode),
buildPlanetDataFromLongitude('moon', 72.13, 3, $nameMode), buildPlanetDataFromLongitude('moon', 72.13, $nameMode),
buildPlanetDataFromLongitude('mars', 78.35, 3, $nameMode), buildPlanetDataFromLongitude('mars', 78.35, $nameMode),
buildPlanetDataFromLongitude('mercury', 32.08, 2, $nameMode), buildPlanetDataFromLongitude('mercury', 32.08, $nameMode),
buildPlanetDataFromLongitude('venus', 41.30, 2, $nameMode), buildPlanetDataFromLongitude('venus', 41.30, $nameMode),
buildPlanetDataFromLongitude('jupiter', 129.18, 5, $nameMode), buildPlanetDataFromLongitude('jupiter', 129.18, $nameMode),
buildPlanetDataFromLongitude('saturn', 22.43, 1, $nameMode), buildPlanetDataFromLongitude('saturn', 22.43, $nameMode),
buildPlanetDataFromLongitude('rahu', 304.23, 11, $nameMode), buildPlanetDataFromLongitude('rahu', 304.23, $nameMode),
buildPlanetDataFromLongitude('ketu', 124.23, 7, $nameMode) buildPlanetDataFromLongitude('ketu', 124.23, $nameMode)
]; ];
$planetsByHierarchy = $samplePlanets; $planetsByHierarchy = $samplePlanets;
$positionsInOrder = sortPlanetsByLongitude($samplePlanets); $positionsInOrder = sortPlanetsByLongitude($samplePlanets);
usort($positionsInOrder, function ($a, $b) {
return $a['house'] <=> $b['house'];
});
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">

106
js.js
View File

@@ -1,9 +1,9 @@
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
const astroCircle = document.getElementById("astroCircle"); const astroCircle = document.getElementById("astroCircle");
if (!astroCircle) return;
const segmentNumbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]; const segmentNumbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
const circleSize = astroCircle.offsetWidth; const circleSize = astroCircle.offsetWidth;
const centerX = circleSize / 2; const centerX = circleSize / 2;
const centerY = circleSize / 2; const centerY = circleSize / 2;
@@ -11,22 +11,26 @@ document.addEventListener("DOMContentLoaded", function () {
const numberRadius = radius + (circleSize < 400 ? 18 : 28); const numberRadius = radius + (circleSize < 400 ? 18 : 28);
const signRadius = radius * 0.84; 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++) { for (let i = 0; i < 12; i++) {
const angleDeg = i * 30; const angleDeg = i * 30;
// segment divider
const line = document.createElement("div"); const line = document.createElement("div");
line.classList.add("segment-line"); line.classList.add("segment-line");
line.style.transform = `translateX(-50%) rotate(${angleDeg}deg)`; line.style.transform = `translateX(-50%) rotate(${angleDeg}deg)`;
astroCircle.appendChild(line); astroCircle.appendChild(line);
// middle of segment
const midAngle = angleDeg + 15; 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 numberX = centerX + numberRadius * Math.cos(midRad);
const numberY = centerY + numberRadius * Math.sin(midRad); const numberY = centerY + numberRadius * Math.sin(midRad);
@@ -37,7 +41,6 @@ document.addEventListener("DOMContentLoaded", function () {
number.style.top = `${numberY}px`; number.style.top = `${numberY}px`;
astroCircle.appendChild(number); astroCircle.appendChild(number);
// inside sign label
const signX = centerX + signRadius * Math.cos(midRad); const signX = centerX + signRadius * Math.cos(midRad);
const signY = centerY + signRadius * Math.sin(midRad); const signY = centerY + signRadius * Math.sin(midRad);
@@ -48,44 +51,73 @@ document.addEventListener("DOMContentLoaded", function () {
sign.style.top = `${signY}px`; sign.style.top = `${signY}px`;
astroCircle.appendChild(sign); astroCircle.appendChild(sign);
} }
}
if (typeof samplePlanets !== "undefined" && Array.isArray(samplePlanets)) { function placePlanetsByLongitude(astroCircle, planets, centerX, centerY, radius) {
placeSamplePlanets(astroCircle, samplePlanets, centerX, centerY, planetRadius); const sortedPlanets = [...planets].sort((a, b) => {
} return (a.longitude || 0) - (b.longitude || 0);
});
function placeSamplePlanets(astroCircle, planets, centerX, centerY, planetRadius) {
const groupedByHouse = {};
planets.forEach(planet => {
if (!groupedByHouse[planet.house]) {
groupedByHouse[planet.house] = [];
}
groupedByHouse[planet.house].push(planet);
}); });
Object.keys(groupedByHouse).forEach(houseKey => { const usedSlots = [];
const houseNumber = parseInt(houseKey, 10);
const housePlanets = groupedByHouse[houseNumber];
const segmentStartAngle = (houseNumber - 1) * 30; sortedPlanets.forEach((planet) => {
const segmentMidAngle = segmentStartAngle + 15; const longitude = normalizeLongitude(Number(planet.longitude || 0));
const segmentMidRad = (segmentMidAngle - 90) * Math.PI / 180;
const baseX = centerX + planetRadius * Math.cos(segmentMidRad); // 0° Aries starts at top, so subtract 90°
const baseY = centerY + planetRadius * Math.sin(segmentMidRad); const angleRad = degToRad(longitude - 90);
housePlanets.forEach((planet, index) => { // base position inside circle
const planetEl = document.createElement("div"); let ringRadius = radius * 0.67;
planetEl.classList.add("planet-tag");
planetEl.innerText = planet.short;
planetEl.title = planet.name + " | Segment " + planet.house + " | " + planet.sign;
const verticalOffset = index * 24; // detect nearby planets and move slightly inward/outward
planetEl.style.left = `${baseX}px`; let closeCount = 0;
planetEl.style.top = `${baseY + verticalOffset}px`; 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;
} }