parashari

package module
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

README

Go Vedic Astro Charts

A Go library for generating Vedic astrology charts in different styles: North Indian and South Indian.

Features

  • Generates charts in two different styles:
    • South Indian: Fixed rashi positions (1-12 always in same positions), planets placed based on their rashi
    • North Indian: Fixed rashi positions with rotating house system based on Lagna
  • Supports all 9 planets (Sun, Moon, Mars, Mercury, Jupiter, Venus, Saturn, Rahu, Ketu)
  • Supports upagrahas (Upaketu, Mandi, Gulika, etc.)
  • Handles retrograde (R) and combust (C) indicators
  • Custom display names for planets/upagrahas
  • Center text support for South Indian charts
  • House/rashi highlights for illustrating specific positions (e.g., for blog posts)
  • Aspect lines to visualize planetary drishti between houses
  • Returns base64-encoded PNG images

Installation

go get github.com/tejzpr/go-vedic-astro-charts

Usage

package main

import (
    "encoding/base64"
    "fmt"
    "os"
    "github.com/tejzpr/go-vedic-astro-charts"
)

func main() {
    input := parashari.ChartInput{
        ChartType: parashari.ChartTypeSouth, // or ChartTypeNorth
        Lagna: &parashari.Planet{
            Rashi: "leo", // Lagna rashi (ascendant sign)
        },
        Planets: map[string]*parashari.Planet{
            "sun": {
                Rashi:        "taurus",
                IsRetrograde: false,
                IsCombust:    false,
            },
            "jupiter": {
                Rashi:        "taurus",
                IsRetrograde: true,
                IsCombust:    false,
            },
            "moon": {
                Rashi:        "gemini",
                IsRetrograde: false,
                IsCombust:    false,
            },
            "upaketu": {
                Rashi:      "scorpio",
                IsUpagraha: true,
            },
        },
        CenterText: "Custom Text\nLine 2", // Optional: for South Indian charts only
    }

    // Generate chart
    base64Image, err := parashari.GenerateChart(input)
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }

    // Decode and save
    imageData, _ := base64.StdEncoding.DecodeString(base64Image)
    os.WriteFile("chart.png", imageData, 0644)
}

Input Format

The input requires:

  • chart_type: One of "north" or "south"
  • lagna: (Optional) Lagna (Ascendant) planet object with:
    • rashi: Zodiac sign name where Lagna is located
    • Note: Lagna is never retrograde or combust (it's a point, not a planet)
  • planets: A map of planet names to planet data, where each planet has:
    • rashi: Zodiac sign name (e.g., "aries", "taurus", "gemini", etc.)
    • is_retrograde: Boolean indicating retrograde status (adds "R" suffix)
    • is_combust: Boolean indicating combust status (adds "C" suffix)
    • upagraha: (Optional) Boolean indicating if this is an upagraha
    • display: (Optional) Custom display name (overrides default abbreviation)
  • center_text: (Optional) Multi-line text to display in center of South Indian chart
  • highlight_rashis: (Optional) List of houses/rashis to visually highlight (see Highlights)
  • aspects: (Optional) List of aspect lines to draw between houses (see Highlights)
Supported Planet Names
  • "sun", "moon", "mars", "mercury", "jupiter", "venus", "saturn", "rahu", "ketu"
  • "lagna" (for ascendant, displayed as "Asc" in saffron color)
Supported Upagraha Names
  • "upaketu" (displayed as "Up"), "mandi" (displayed as "Mn"), "gulika" (displayed as "Gu")
  • "yamaghantaka" (Ya), "ardhaprahara" (Ar), "kala" (Ka), "dhuma" (Dh)
  • "vyatipata" (Vy), "parivesha" (Pa), "indrachapa" (In)
Supported Rashi Names
  • "aries", "taurus", "gemini", "cancer", "leo", "virgo", "libra", "scorpio", "sagittarius", "capricorn", "aquarius", "pisces"

Chart Types

South Indian Chart
  • Fixed rashi positions: Rashi numbers (1-12) are always in the same positions
    • Position 1 = Aries, Position 2 = Taurus, ..., Position 12 = Pisces
  • Planets are placed in the box corresponding to their rashi number
  • Lagna (Ascendant) is displayed as "Asc" in saffron color in the box of its rashi
  • Lagna indicator: Two parallel diagonal lines at bottom-left corner of the lagna rashi box
  • Center text: Optional multi-line text can be displayed in the center (4 empty squares)
  • Perimeter layout: 12 boxes around the perimeter, center 4 squares are empty

South Indian Chart Example

North Indian Chart
  • Fixed rashi positions with rotating house system
  • Diamond-shaped layout with inner and outer rotated squares
  • Lagna rashi number appears at the top-right of the 45-degree rotated inner square
  • Rashi numbers rotate counter-clockwise from lagna position
  • Planets are displayed near their respective rashi numbers
  • Lagna (Ascendant) is displayed as "Asc" in saffron color

North Indian Chart Example

Highlights and Aspects

For creating illustrative charts for astrology blogs, tutorials, or teaching material, you can highlight specific houses/rashis and draw aspect lines between houses.

Highlighting Houses or Rashis

Highlight a house (relative to Lagna) or a specific rashi (by name). Each highlight accepts an optional hex color and opacity.

input := parashari.ChartInput{
    ChartType: parashari.ChartTypeNorth,
    Lagna:     &parashari.Planet{Rashi: "aries"},
    Planets:   map[string]*parashari.Planet{ /* ... */ },
    HighlightRashis: []parashari.RashiHighlight{
        {House: 1, Color: "#FFE4B5", Opacity: 0.5},    // Highlight 1st house (lagna house)
        {Rashi: "cancer", Color: "#B0E0E6", Opacity: 0.4}, // Highlight Cancer rashi
        {House: 7, Color: "#F08080", Opacity: 0.3},    // Highlight 7th house
    },
}

Each RashiHighlight:

  • house (1-12) or rashi (rashi name) — specify one, not both
  • color — hex string like "#FFE4B5" (defaults to warm yellow)
  • opacity — 0.0 to 1.0 (defaults to 0.4)
Drawing Aspect Lines

Draw an aspect line from one house to another. Lines are drawn with an arrow head at the target and colored by the source planet's conventional color.

input := parashari.ChartInput{
    ChartType: parashari.ChartTypeNorth,
    Lagna:     &parashari.Planet{Rashi: "aries"},
    Planets: map[string]*parashari.Planet{
        "jupiter": {Rashi: "aries"},
        "saturn":  {Rashi: "cancer"},
    },
    Aspects: []parashari.Aspect{
        // Jupiter in house 1 aspects Saturn in house 4
        {FromPlanet: "jupiter", FromHouse: 1, ToPlanet: "saturn", ToHouse: 4},
        // Jupiter in house 1 also aspects house 9 (no target planet)
        {FromPlanet: "jupiter", FromHouse: 1, ToHouse: 9},
        // Override color explicitly
        {FromHouse: 5, ToHouse: 11, Color: "#6A5ACD"},
    },
}

Each Aspect:

  • from_house (1-12, required) — source house
  • to_house (1-12, required) — target house
  • from_planet — optional planet name (e.g., "jupiter"), used for line color
  • to_planet — optional planet name for documentation/consistency (not rendered)
  • color — optional hex color override (defaults to the source planet's conventional color)

Default planet colors for aspect lines:

Planet Color
Sun Saffron (#D95A0D)
Moon Silver-gray
Mars Red (#CC2626)
Mercury Green
Jupiter Gold (#D9A61A)
Venus Pink
Saturn Deep blue
Rahu Purple
Ketu Brown
Full Example (blog illustration)
input := parashari.ChartInput{
    ChartType: parashari.ChartTypeNorth,
    Lagna:     &parashari.Planet{Rashi: "aries"},
    Planets: map[string]*parashari.Planet{
        "jupiter": {Rashi: "aries"},   // 1st house
        "saturn":  {Rashi: "cancer"},  // 4th house
        "mars":    {Rashi: "leo"},     // 5th house
        "venus":   {Rashi: "libra"},   // 7th house
    },
    HighlightRashis: []parashari.RashiHighlight{
        {House: 1, Color: "#FFE4B5"},
        {House: 4, Color: "#B0E0E6"},
        {House: 7, Color: "#F08080", Opacity: 0.3},
    },
    Aspects: []parashari.Aspect{
        {FromPlanet: "jupiter", FromHouse: 1, ToPlanet: "saturn", ToHouse: 4},
        {FromPlanet: "mars", FromHouse: 5, ToPlanet: "venus", ToHouse: 7},
        {FromPlanet: "jupiter", FromHouse: 1, ToHouse: 9},
    },
}

House vs. Rashi

  • In the North chart, positions are fixed to houses relative to the Lagna — house 1 is always the top kite.
  • In the South chart, positions are fixed to rashis — Aries is always position 1. Specifying a House in a highlight/aspect is resolved using the Lagna, so the visual output stays consistent across chart types.

Planet Display

  • Planets: Displayed with abbreviations (Su, Mo, Ma, Me, Ju, Ve, Sa, Ra, Ke)
  • Lagna: Displayed as "Asc" in saffron color (RGB: 1.0, 0.6, 0.2)
  • Upagrahas: Displayed by their names/abbreviations (Up, Mn, Gu, etc.)
  • Retrograde: Adds "R" suffix (e.g., "JuR")
  • Combust: Adds "C" suffix (e.g., "VeC")
  • Custom Display: Use display field to override default abbreviation

Output

The library returns a base64-encoded PNG string that can be:

  • Decoded and saved as a PNG file
  • Embedded in HTML as a data URI
  • Sent over HTTP as an image response

Dependencies

  • github.com/fogleman/gg - Graphics library for drawing
  • golang.org/x/image - Image processing and fonts

Fonts

The library uses the Matangi font family for rendering:

  • Matangi-Regular.ttf for rashi numbers
  • Matangi-Bold.ttf for planet names
  • Falls back to basic font if Matangi fonts cannot be loaded

Font Embedding: Fonts are automatically embedded into the binary using Go's go:embed directive. When you build your application, the font files are included in the compiled binary, so you don't need to distribute font files separately. The fonts are loaded from embedded data at runtime.

Font files are located at: fonts/matangi/fonts/ttf/ in the source code, but are embedded during compilation.

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Copyright (c) 2024 Tejus Pratap tejzpr@gmail.com

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateChart

func GenerateChart(input ChartInput) (string, error)

GenerateChart generates a chart image and returns it as a base64-encoded PNG string

func GenerateNorthChart

func GenerateNorthChart(input ChartInput) ([]byte, error)

GenerateNorthChart generates a North Indian style chart Fixed zodiac signs, houses move based on lagna (counter-clockwise)

func GenerateSouthChart

func GenerateSouthChart(input ChartInput) ([]byte, error)

GenerateSouthChart generates a South Indian style chart Houses are fixed, rashis rotate based on Lagna

func GetPlanetAbbreviation

func GetPlanetAbbreviation(planetName string) string

GetPlanetAbbreviation returns the abbreviation for a planet or upagraha

func GetPlanetDisplayName

func GetPlanetDisplayName(planetName string, planet *Planet) string

GetPlanetDisplayName returns the display name for a planet If Display field is set, it uses that, otherwise uses the abbreviation

func IsSpecialLagnaAbbrev added in v1.0.1

func IsSpecialLagnaAbbrev(abbrev string, input ChartInput) bool

IsSpecialLagnaAbbrev checks if an abbreviation corresponds to a special lagna by looking through the input.Planets map

func NumberToRashi

func NumberToRashi(num int) string

NumberToRashi converts rashi number to name

func RashiToNumber

func RashiToNumber(rashi string) int

RashiToNumber converts rashi name to number (1-12)

Types

type Aspect added in v1.0.6

type Aspect struct {
	FromPlanet string `json:"from_planet,omitempty"`
	FromHouse  int    `json:"from_house"`
	ToPlanet   string `json:"to_planet,omitempty"`
	ToHouse    int    `json:"to_house"`
	Color      string `json:"color,omitempty"` // Optional hex color override (defaults to FromPlanet's conventional color)
}

Aspect specifies an aspect line between two houses. FromPlanet/ToPlanet are labels for coloring; FromHouse/ToHouse (1-12) determine the line endpoints.

type ChartInput

type ChartInput struct {
	ChartType       ChartType          `json:"chart_type"`
	Planets         map[string]*Planet `json:"planets"`
	Lagna           *Planet            `json:"lagna,omitempty"`
	CenterText      string             `json:"center_text,omitempty"`      // Text to display in center of chart
	HighlightRashis []RashiHighlight   `json:"highlight_rashis,omitempty"` // Houses/rashis to visually highlight
	Aspects         []Aspect           `json:"aspects,omitempty"`          // Aspect lines to draw between houses
}

ChartInput contains all the data needed to generate a chart

type ChartType

type ChartType string

ChartType represents the type of chart to generate

const (
	ChartTypeNorth ChartType = "north"
	ChartTypeSouth ChartType = "south"
	ChartTypeEast  ChartType = "east"
	ChartTypeWest  ChartType = "west"
)

type Planet

type Planet struct {
	Rashi          string `json:"rashi"`
	IsRetrograde   bool   `json:"is_retrograde"`
	IsCombust      bool   `json:"is_combust"`
	IsUpagraha     bool   `json:"upagraha,omitempty"`
	Display        string `json:"display,omitempty"` // Custom display name
	IsSpecialLagna bool   `json:"is_special_lagna,omitempty"`
}

Planet represents a planet in the chart

type RashiHighlight added in v1.0.6

type RashiHighlight struct {
	Rashi   string  `json:"rashi,omitempty"`   // Rashi name (mutually exclusive with House)
	House   int     `json:"house,omitempty"`   // House number 1-12 (mutually exclusive with Rashi)
	Color   string  `json:"color,omitempty"`   // Hex color e.g. "#FFE4B5"; defaults to warm yellow
	Opacity float64 `json:"opacity,omitempty"` // 0.0-1.0; defaults to 0.4
}

RashiHighlight specifies a rashi (or house) to highlight with a custom fill color. Either Rashi (by name, e.g., "leo") or House (1-12) may be used.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL