Merge pull request #88 from gergelypolonkai/chart-moon-phase

Add Moon phase visualisation to the chart
This commit is contained in:
Gergely Polonkai 2014-09-24 13:03:29 +02:00
commit 447e1568a7
3 changed files with 98 additions and 5 deletions

View File

@ -1426,7 +1426,8 @@ ag_chart_create_svg(AgChart *chart,
GsweAspectData *aspect_data;
GEnumClass *planets_class,
*aspects_class,
*antiscia_class;
*antiscia_class,
*moon_phase_class;
gint save_length;
xsltStylesheetPtr xslt_proc;
locale_t current_locale;
@ -1437,6 +1438,8 @@ ag_chart_create_svg(AgChart *chart,
gboolean first;
guint dist;
gdouble first_pos;
GsweMoonPhaseData *moon_phase_data;
GEnumValue *enum_value;
root_node = xmlDocGetRootElement(doc);
@ -1527,7 +1530,6 @@ ag_chart_create_svg(AgChart *chart,
planet = g_list_next(planet)
) {
planet_data = planet->data;
GEnumValue *enum_value;
gdouble position;
if (
@ -1596,7 +1598,6 @@ ag_chart_create_svg(AgChart *chart,
aspect = g_list_next(aspect)
) {
GswePlanetData *planet_data;
GEnumValue *enum_value;
aspect_data = aspect->data;
@ -1641,7 +1642,6 @@ ag_chart_create_svg(AgChart *chart,
) {
GswePlanetData *planet_data;
GsweAntiscionData *antiscion_data = antiscion->data;
GEnumValue *enum_value;
if (gswe_antiscion_data_get_axis(
antiscion_data) == GSWE_ANTISCION_AXIS_NONE
@ -1672,6 +1672,24 @@ ag_chart_create_svg(AgChart *chart,
xmlNewProp(node, BAD_CAST "axis", BAD_CAST enum_value->value_nick);
}
g_debug("Getting Moon phase");
moon_phase_data = gswe_moment_get_moon_phase(GSWE_MOMENT(chart), NULL);
moon_phase_class = g_type_class_ref(GSWE_TYPE_MOON_PHASE);
enum_value = g_enum_get_value(G_ENUM_CLASS(moon_phase_class), gswe_moon_phase_data_get_phase(moon_phase_data));
value = g_malloc0(12);
g_ascii_dtostr(value, 12, gswe_moon_phase_data_get_illumination(moon_phase_data));
node = xmlNewChild(root_node, NULL, BAD_CAST "moonphase", NULL);
xmlNewProp(node, BAD_CAST "phase", BAD_CAST enum_value->value_nick);
xmlNewProp(node, BAD_CAST "illumination", BAD_CAST value);
g_free(value);
g_type_class_unref(moon_phase_class);
gswe_moon_phase_data_unref(moon_phase_data);
g_type_class_unref(planets_class);
// Now, doc contains the generated XML tree

View File

@ -138,3 +138,8 @@ line.antiscion {
#background {
fill: #ffffff;
}
#moon {
fill: #c0c0c0;
stroke-width: 0;
}

View File

@ -18,6 +18,7 @@
<xsl:variable name="image_size" select="800" />
<xsl:variable name="icon_size" select="30" />
<xsl:variable name="r_aspect" select="$image_size * 0.3" />
<xsl:variable name="r_moon" select="$image_size * 0.0625" />
<xsl:template name="planet-template">
<xsl:param name="planet_name"/>
@ -157,7 +158,7 @@
<xsl:attribute name="r"><xsl:value-of select="$image_size * 0.0875"/></xsl:attribute>
</circle>
<circle id="moon_circle" cx="0" cy="0" class="thick" style="fill:#00000;stroke:none">
<xsl:attribute name="r"><xsl:value-of select="$image_size * 0.0625"/></xsl:attribute>
<xsl:attribute name="r"><xsl:value-of select="$r_moon"/></xsl:attribute>
</circle>
<line id="aries_start" y1="0" y2="0" class="degree-thick">
@ -797,6 +798,75 @@
</xsl:for-each>
</g>
</g>
<g id="moon">
<xsl:variable name="moon_illum" select="/chartinfo/moonphase/@illumination"/>
<xsl:variable name="moon_orig_percent">
<xsl:choose>
<xsl:when test="$moon_illum &gt; 50">
<xsl:value-of select="100 - $moon_illum"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$moon_illum"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="moon_phase" select="/chartinfo/moonphase/@phase"/>
<xsl:variable name="moon_percent" select="$moon_orig_percent * 2 div 100"/>
<xsl:variable name="moon_x" select="$r_moon * (1 - $moon_percent)"/>
<xsl:variable name="moon_r2" select="$moon_x div (math:power(math:sin(math:atan($moon_x div $r_moon)), 2) * 2)"/>
<xsl:choose>
<xsl:when test="$moon_phase='full'">
<circle id="moon" cx="0" cy="0">
<xsl:attribute name="r"><xsl:value-of select="$r_moon"/></xsl:attribute>
</circle>
</xsl:when>
<xsl:when test="substring($moon_phase, 1, 2)='wa'">
<path id="moon">
<xsl:attribute name="d">
m 0,<xsl:value-of select="$r_moon"/>
<xsl:choose>
<xsl:when test="substring($moon_phase, 1, 3)='wan'">
a <xsl:value-of select="$r_moon"/>,<xsl:value-of select="$r_moon"/> 0 0,1 0,-<xsl:value-of select="2 * $r_moon"/>
<xsl:choose>
<xsl:when test="$moon_illum &lt; 50">
a <xsl:value-of select="$moon_r2"/>,<xsl:value-of select="$moon_r2"/> 0 0,0 0,<xsl:value-of select="2 * $r_moon"/>
</xsl:when>
<xsl:when test="$moon_illum = 50">
l 0,<xsl:value-of select="2 * $r_moon"/>
</xsl:when>
<xsl:when test="$moon_illum &gt; 50">
a <xsl:value-of select="$moon_r2"/>,<xsl:value-of select="$moon_r2"/> 0 0,1 0,<xsl:value-of select="2 * $r_moon"/>
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:when test="substring($moon_phase, 1, 3)='wax'">
a <xsl:value-of select="$r_moon"/>,<xsl:value-of select="$r_moon"/> 0 0,0 0,-<xsl:value-of select="2 * $r_moon"/>
<xsl:choose>
<xsl:when test="$moon_illum &lt; 50">
a <xsl:value-of select="$moon_r2"/>,<xsl:value-of select="$moon_r2"/> 0 0,1 0,<xsl:value-of select="2 * $r_moon"/>
</xsl:when>
<xsl:when test="$moon_illum = 50">
l 0,<xsl:value-of select="2 * $r_moon"/>
</xsl:when>
<xsl:when test="$moon_illum &gt; 50">
a <xsl:value-of select="$moon_r2"/>,<xsl:value-of select="$moon_r2"/> 0 0,0 0,<xsl:value-of select="2 * $r_moon"/>
</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
z
</xsl:attribute>
</path>
</xsl:when>
</xsl:choose>
</g>
</g>
</svg>
</xsl:template>