Guides

Extending the astrolabe

Hanging your own analysis rules off a chart — the extension point in each of the three programming languages.

For: developers

A chart is data; how it is interpreted is each school's own business. Zi Wei has many schools and predicate rules vary from reader to reader, so cramming them all into the core is neither possible nor desirable. What x-iztro does instead is let you attach your own rules to the astrolabe as methods, called with the same syntax as the built-in ones.

The extension point in each programming language

Each language uses the mechanism most natural to it; they are not forced into one shape:

Programming languageMechanismCheckedScope
RustExtension traitCompile timeVisible where the trait is used
PythonAttaching methods to the classRun timeProcess-wide
GoStruct embeddingCompile timeOnly your own type

All three do the same thing: you call chart.my_method() and have the astrolabe's full built-in capability available. Exact syntax and runnable examples are on the respective pages.

Shared conventions

An example

The same plugin in all three programming languages: take the Soul palace's major stars (borrowing from the opposite palace when it is empty).

trait MyAnalysis {
    fn major_star(&self) -> String;
}

impl MyAnalysis for Astrolabe {
    fn major_star(&self) -> String {
        let soul = self.palace(Palace::Soul).expect("the Soul palace always exists");
        let source = if soul.is_empty() { soul.opposite_palace() } else { soul };
        source.major_stars.iter()
            .filter(|s| s.star_type == StarType::Major)
            .map(|s| translate_star(s.key, self.language))
            .collect::<Vec<_>>().join(",")
    }
}

chart.major_star()   // emperor

All three return emperor on an English chart of this birthday, and 紫微 on a Simplified Chinese one — the same star, written differently.

On this page