/*
Here is a possible js code to render the north indian style horoscope chart from the given data with planets degrees and zodiac sign it is positioned in:
*/
// Define the zodiac signs and their symbols
const signs = ["Ari", "Tau", "Gem", "Can", "Leo", "Vir", "Lib", "Sco", "Sag", "Cap", "Aqu", "Pis"];
const symbols = ["♈", "♉", "♊", "♋", "♌", "♍", "♎", "♏", "♐", "♑", "♒", "♓"];
// Define the planets and their symbols
const planets = ["Sun", "Moon", "Merc", "Venu", "Mars", "Jupi", "Satu", "Uran", "Nept", "Plut"];
const planetSymbols = ["☉", "☽", "☿", "♀", "♂", "♃", "♄", "♅", "♆", "♇"];
// Define the data as an object with keys as planets and values as degrees
const data = {
Sun: 5.01,
Moon: 18.46,
Merc: 22.56,
Venu: 23.16,
Mars: 25.05,
Jupi: 29.49,
Satu: 19.19,
Uran: 16.52,
Nept: 5.18,
Plut: 7.54,
Nort: 21.28,
Asce: 28.27,
Midh: 13.58
};
// Define a function to convert degrees to sign and degree format
function toSignDegree(deg) {
// Find the sign index by dividing the degree by 30 and rounding down
let signIndex = Math.floor(deg / 30);
// Find the degree within the sign by subtracting the sign index times 30 from the degree
let degree = deg - (signIndex * 30);
// Return the sign symbol and the degree rounded to two decimals
return symbols[signIndex] + degree.toFixed(2);
}
// Define a function to create a horoscope chart as a nested array of strings
function createChart(data) {
// Initialize an empty array of size 12x12 let chart = [];
for (let i = 0; i < 12; i++) {
chart[i] = [];
for (let j = 0; j < 12; j++) {
chart[i][j] = "";
}
}
// Loop through the planets and place them in the chart according to their sign and degree
for (let planet of planets) {
// Get the sign index by dividing the degree by 30 and rounding down
let signIndex = Math.floor(data[planet] / 30);
// Get the row index by subtracting the sign index from the ascendant sign index and wrapping around...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.