Circular Natal Horoscope JS

repository·master·Indexed 18 days ago

https://github.com/0xstarcat/circularnatalhoroscopejs

A JavaScript library for calculating astrological birth charts (natal charts). It provides precise astronomical calculations for planetary positions, house cusps, and aspects, returning data compatible with frontend circular chart rendering. Version 1.1.0 supports multiple house systems (e.g., Placidus, Koch, Whole-sign), tropical and sidereal zodiacs, and localized labels.

Tokens
6.1K
Snippets
19
Records
22
Agent score
63%

What's inside circular-natal-horoscope-js

  1. Interpret ChartPosition for chart rendering

    master

    The ChartPosition class is returned for house cusps, zodiac cusps, and bodies. It provides coordinates for two different circles used in circular natal charts:

    1. Horizon: Typically the inner circle. The Ascendant is at 0 degrees on this circle.
    2. Ecliptic: Typically the outer circle. The start of Aries is at 0 degrees on this circle.

    Each position includes ArcDegrees (as an object with degrees, minutes, seconds), ArcDegreesFormatted, ArcDegreesFormatted30, and DecimalDegrees.

    // Example ChartPosition for mercury
    const mercury = {
      ...,
      ChartPosition: {
        Horizon: {
          ArcDegrees: {degrees: 0, minutes: 0, seconds: 0},
          ArcDegreesFormatted: "0° 0' 0''",
          ArcDegreesFormatted30: "0° 0' 0''",
          DecimalDegrees: 0
        },
        Ecliptic: {
          ArcDegrees: {degrees: 180, minutes: 38, seconds: 2},
          ArcDegreesFormatted: "180° 38' 2''",
          ArcDegreesFormatted30: "0° 38' 2''",
          DecimalDegrees: 180.634
        }
      }
    }
  2. Add new languages for localized labels

    master

    To add support for a new language, you must implement the tokens in src/utilities/language.js. Copy the existing English or Spanish tokens and add them to a new key matching the desired ISO language code.

    When generating the horoscope, pass the language code to the constructor to receive localized labels in the .label keys of Sign, Aspect, Planet, and House objects.

    // Example usage with Spanish
    new Horoscope({ language: "es" });
  3. Set custom orb degrees for aspects

    master

    You can override the default orb degrees used for aspect calculations by passing a customOrbs object to the Horoscope constructor. Keys should match the aspect type names.

    import { Origin, Horoscope } from "circular-natal-horoscope-js";
    
    const customOrbs = {
      conjunction: 8,
      opposition: 8,
      trine: 8,
      square: 7,
      sextile: 6,
      quincunx: 5,
      quintile: 1,
      septile: 1,
      "semi-square": 1,
      "semi-sextile": 1,
    };
    
    const horoscope = new Horoscope({
      origin: new Origin({...}),
      houseSystem: "whole-sign",
      zodiac: "tropical",
      aspectPoints: ['bodies', 'points', 'angles'],
      aspectWithPoints: ['bodies', 'points', 'angles'],
      aspectTypes: ["major", "minor"],
      customOrbs: customOrbs,
      language: 'en'
    });
  4. Configure and create a Horoscope

    master

    The Horoscope class performs the astrological calculations. It requires an Origin instance and can be configured with various systems and aspect settings.

    Configuration Options:

    • origin: Origin instance.
    • houseSystem: string - One of ['placidus', 'koch', 'campanus', 'whole-sign', 'equal-house', 'regiomontanus', 'topocentric'].
    • zodiac: string - Either 'sidereal' or 'tropical'.
    • aspectPoints: array - Starting points for aspects (e.g., ['bodies', 'points', 'angles'] or specific strings like ['sun']).
    • aspectWithPoints: array - Ending points for aspects.
    • aspectTypes: array - Types of aspects to calculate (e.g., ['major', 'minor']).
    • customOrbs: object - Overrides default orb degrees for aspect calculation.
    • language: string - ISO language code (e.g., 'en', 'es') for localized labels.
    import { Origin, Horoscope } from "circular-natal-horoscope-js";
    
    const horoscope = new Horoscope({
      origin: new Origin({
        year: 2020,
        month: 11,
        date: 1,
        hour: 16,
        minute: 30,
        latitude: 40.0,
        longitude: -70.0,
      }),
      houseSystem: "whole-sign",
      zodiac: "tropical",
      aspectPoints: ['bodies', 'points', 'angles'],
      aspectWithPoints: ['bodies', 'points', 'angles'],
      aspectTypes: ["major", "minor"],
      customOrbs: {},
      language: 'en'
    });
  5. Initialize an Origin

    master

    The Origin class derives the local timezone from latitude/longitude and calculates UTC time, accounting for historical daylight savings. It only supports C.E. dates (> 0).

    Parameters:

    • year: int (>= 0)
    • month: int (0 = January, 11 = December)
    • date: int (1-31)
    • hour: int (0-23)
    • minute: int (0-59)
    • latitude: float (-90.00 to 90.00)
    • longitude: float (-180.00 to 180.00)
    import { Origin } from "circular-natal-horoscope-js";
    
    const origin = new Origin({
      year: 2020,
      month: 11, // 0 = January, 11 = December!
      date: 1,
      hour: 16,
      minute: 30,
      latitude: 40.0,
      longitude: -70.0,
    });
  6. Configure Webpack for the demo environment

    master

    The project uses Webpack to bundle the demo application. The configuration defines an entry point at ./demo/script.js and outputs a UMD (Universal Module Definition) library named demoScript.js into the demo/dist directory. It also uses HtmlWebpackPlugin to generate demo.html from the ./demo/demo.html template.

    var HtmlWebpackPlugin = require("html-webpack-plugin");
    const path = require("path");
    
    module.exports = {
      entry: {
        index: "./demo/script.js",
      },
      output: {
        filename: "demoScript.js",
        path: path.resolve(__dirname, "demo", "dist"),
        library: "[name].js",
        libraryTarget: "umd",
      },
      plugins: [
        new HtmlWebpackPlugin({
          filename: "demo.html",
          template: "./demo/demo.html",
        }),
      ],
    };
  7. Access horoscope calculation results

    master

    Once a Horoscope instance is created, you can access the computed data through several properties:

    • Angles: Contains all, ascendant, and midheaven info.
    • Ascendant: Specific info for the ascendant.
    • Midheaven: Specific info for the midheaven.
    • Aspects: Contains all, points (organized by point), and types (organized by aspect type).
    • CelestialBodies: Contains all and individual planets/asteroids (e.g., sun, moon, mercury, etc.).
    • CelestialPoints: Contains all and lunar nodes/lilith (e.g., northnode, southnode, lilith).
    • Houses: An array of the 12 house cusps.
    • SunSign: Info about the zodiac sign the sun is in.
    • ZodiacCusps: An array of the 12 zodiac cusps.
  8. Access Sign properties and dates

    master

    Once a Sign instance is created, you can access several properties and getters to retrieve astrological data specific to the chosen zodiac system.

    Properties and Getters:

    • key: The unique identifier of the sign.
    • label: The localized name of the sign in the specified language.
    • zodiac: The active zodiac system (e.g., 'tropical').
    • StartDate: Returns the start date for the sign within the current zodiac system.
    • EndDate: Returns the end date for the sign within the current zodiac system.
    • ZodiacStart: Returns the starting degree of the sign in the 360° circle (calculated via modulo(this.zodiacStart, 360)).
    • ZodiacEnd: Returns the ending degree of the sign in the 360° circle (calculated via modulo(this.zodiacEnd, 360)).
    const sign = new Sign({ key: 'aries', zodiac: 'tropical' });
    
    console.log(sign.label);       // e.g., "Aries"
    console.log(sign.StartDate);   // Start date for Aries in tropical system
    console.log(sign.ZodiacStart); // Starting degree (e.g., 0.0)
  9. Instantiate the Origin class

    master

    The Origin class serves as the base data component required for chart casting. It encapsulates the location and time for astronomical calculations. When instantiated, it automatically derives the local timezone from the provided latitude and longitude coordinates and calculates the corresponding UTC time, accounting for historical daylight savings time.

    Note: This class only supports C.E. dates (year > 0).

    import { Origin } from './Origin';
    
    const origin = new Origin({
      year: 2023,
      month: 6, // 0 = January, 11 = December
      date: 15,
      hour: 14,
      minute: 30,
      second: 0,
      latitude: 34.0522,
      longitude: -118.2437
    });
  10. Access calculated time and location data from Origin

    master

    Once an Origin instance is created, it provides several derived properties used for astronomical calculations:

    • timezone: The timezone object derived from the latitude and longitude.
    • localTime: A moment-timezone object representing the local time.
    • localTimeFormatted: A string representation of the local time.
    • utcTime: A moment-timezone object representing the UTC time.
    • utcTimeFormatted: A string representation of the UTC time.
    • julianDate: The calculated Julian Date based on the UTC time.
    • localSiderealTime: The calculated Local Sidereal Time based on the Julian Date and longitude.