Cleaned
This commit is contained in:
@@ -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,
|
||||
@@ -116,3 +117,8 @@ function sortPlanetsByLongitude(array $planets): array
|
||||
|
||||
return $planets;
|
||||
}
|
||||
function getSegmentFromLongitude(float $longitude): int
|
||||
{
|
||||
$longitude = normalizeLongitude($longitude);
|
||||
return ((int) floor($longitude / 30)) + 1;
|
||||
}
|
||||
1
css.css
1
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);
|
||||
|
||||
22
index.php
22
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'];
|
||||
});
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
94
js.js
94
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 placePlanetsByLongitude(astroCircle, planets, centerX, centerY, radius) {
|
||||
const sortedPlanets = [...planets].sort((a, b) => {
|
||||
return (a.longitude || 0) - (b.longitude || 0);
|
||||
});
|
||||
|
||||
function placeSamplePlanets(astroCircle, planets, centerX, centerY, planetRadius) {
|
||||
const groupedByHouse = {};
|
||||
const usedSlots = [];
|
||||
|
||||
planets.forEach(planet => {
|
||||
if (!groupedByHouse[planet.house]) {
|
||||
groupedByHouse[planet.house] = [];
|
||||
sortedPlanets.forEach((planet) => {
|
||||
const longitude = normalizeLongitude(Number(planet.longitude || 0));
|
||||
|
||||
// 0° Aries starts at top, so subtract 90°
|
||||
const angleRad = degToRad(longitude - 90);
|
||||
|
||||
// base position inside circle
|
||||
let ringRadius = radius * 0.67;
|
||||
|
||||
// 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++;
|
||||
}
|
||||
}
|
||||
groupedByHouse[planet.house].push(planet);
|
||||
});
|
||||
|
||||
Object.keys(groupedByHouse).forEach(houseKey => {
|
||||
const houseNumber = parseInt(houseKey, 10);
|
||||
const housePlanets = groupedByHouse[houseNumber];
|
||||
// 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 segmentStartAngle = (houseNumber - 1) * 30;
|
||||
const segmentMidAngle = segmentStartAngle + 15;
|
||||
const segmentMidRad = (segmentMidAngle - 90) * Math.PI / 180;
|
||||
const x = centerX + ringRadius * Math.cos(angleRad);
|
||||
const y = centerY + ringRadius * Math.sin(angleRad);
|
||||
|
||||
const baseX = centerX + planetRadius * Math.cos(segmentMidRad);
|
||||
const baseY = centerY + planetRadius * Math.sin(segmentMidRad);
|
||||
|
||||
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;
|
||||
planetEl.title =
|
||||
`${planet.name} | ${planet.sign} | ${planet.degree} | ${planet.nakshatra} | ${longitude.toFixed(2)}°`;
|
||||
|
||||
const verticalOffset = index * 24;
|
||||
planetEl.style.left = `${baseX}px`;
|
||||
planetEl.style.top = `${baseY + verticalOffset}px`;
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user