You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Mark <ma...@inomial.com> on 2001/09/16 17:28:51 UTC

OT(?): transcendental functions in XSLT

Hi folks,

sorry for this slightly off topic post but i was hoping someone could
help me.

I thought i should be able to produce a very simple xml schema for
generating pie charts. the idea was that I could use XSLT to transform
from the pie-chart schema to SVG (and then to import the SVG into FOP). 

It would be preferable to express the size of the pie chart segments as
percentages, but the SVG Path object requires coordinates on the
circumferance of a circle.

The problem is that there don't seem to be any functions in XSLT or
XPath that let me find the sin() or cosine() of an angle. Am I missing
something? I thought I could possibly use a transform but I can't seem
to perform a transform in the middle of a Path.

I finally decided that maybe if I created a table of degree-to-sin/cos
mappings I could somehow use the document() function to import this into
the stylesheet and use an index to search it (ergh) but that doesn't
seem to work either.

There's little point in having a pie-chart schema if you have to do the
calculations yourself anyway.

So if anyone has any suggestions .. ? I'd certainly be pleased to share
a pie-chart-XSLT transform if I can get it going.

As an aside, does anyone know why SVG paths are so (IMHO) brain dead? I
can't believe that the elements in a path aren't XML elements, it seems
very strange. (Generating the paths in XSLT is going to be a bit
painful, even if I can get the sin() of an angle. I dont really see how
"M300,200 h-150 a150,150 0 1,0 150,-150 z" qualifies as XML).

Cheers
Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org


Re: OT(?): transcendental functions in XSLT

Posted by "David S. Dixon" <dd...@leastsquares.com>.
Mark,

Correction and clarification on my previous response:

By small angles, I meant small angle DIFFERENCES -- the series expansions work
best for small angles.  The sine expansion to 3 terms is good within 1% up to
pi/2, as is the cosine expansion to 4 terms (the first term is always 1, so
it's equivalent to sine to 3 terms).  Then you find yourself doing if-then
ladders for the four quadrants, i.e. sin(pi/2 < x < pi) = sin(pi - x), sin(pi
< x < 2pi) = - sin(x - pi), and so on. I haven't thought about how do to this
in fop, so this may or may not help.

-dd

"David S. Dixon" wrote:

> Mark,
>
> Well, you could do what most implementations of sine and cosine would do,
> series expansion:
>
> sin(x) = x - x^3/3! + x^5/5! - x^7/7! ...
>
> cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! ...
>
> I haven't tried it, but if you avoid small angles (not a bad idea with pie
> charts, anyway) the expansion shouldn't have to include more than three
> terms, I suspect.
>
> -dd
>
> Mark wrote:
>
> > Hi folks,
> >
> > sorry for this slightly off topic post but i was hoping someone could
> > help me.
> >
> > I thought i should be able to produce a very simple xml schema for
> > generating pie charts. the idea was that I could use XSLT to transform
> > from the pie-chart schema to SVG (and then to import the SVG into FOP).
> >
> > It would be preferable to express the size of the pie chart segments as
> > percentages, but the SVG Path object requires coordinates on the
> > circumferance of a circle.
> >
> > The problem is that there don't seem to be any functions in XSLT or
> > XPath that let me find the sin() or cosine() of an angle. Am I missing
> > something? I thought I could possibly use a transform but I can't seem
> > to perform a transform in the middle of a Path.
> >
> > I finally decided that maybe if I created a table of degree-to-sin/cos
> > mappings I could somehow use the document() function to import this into
> > the stylesheet and use an index to search it (ergh) but that doesn't
> > seem to work either.
> >
> > There's little point in having a pie-chart schema if you have to do the
> > calculations yourself anyway.
> >
> > So if anyone has any suggestions .. ? I'd certainly be pleased to share
> > a pie-chart-XSLT transform if I can get it going.
> >
> > As an aside, does anyone know why SVG paths are so (IMHO) brain dead? I
> > can't believe that the elements in a path aren't XML elements, it seems
> > very strange. (Generating the paths in XSLT is going to be a bit
> > painful, even if I can get the sin() of an angle. I dont really see how
> > "M300,200 h-150 a150,150 0 1,0 150,-150 z" qualifies as XML).
> >
> > Cheers
> > Mark
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
> > For additional commands, email: fop-dev-help@xml.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
> For additional commands, email: fop-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org


Re: OT(?): transcendental functions in XSLT

Posted by "David S. Dixon" <dd...@leastsquares.com>.
Mark,

Well, you could do what most implementations of sine and cosine would do,
series expansion:

sin(x) = x - x^3/3! + x^5/5! - x^7/7! ...

cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! ...

I haven't tried it, but if you avoid small angles (not a bad idea with pie
charts, anyway) the expansion shouldn't have to include more than three
terms, I suspect.

-dd

Mark wrote:

> Hi folks,
>
> sorry for this slightly off topic post but i was hoping someone could
> help me.
>
> I thought i should be able to produce a very simple xml schema for
> generating pie charts. the idea was that I could use XSLT to transform
> from the pie-chart schema to SVG (and then to import the SVG into FOP).
>
> It would be preferable to express the size of the pie chart segments as
> percentages, but the SVG Path object requires coordinates on the
> circumferance of a circle.
>
> The problem is that there don't seem to be any functions in XSLT or
> XPath that let me find the sin() or cosine() of an angle. Am I missing
> something? I thought I could possibly use a transform but I can't seem
> to perform a transform in the middle of a Path.
>
> I finally decided that maybe if I created a table of degree-to-sin/cos
> mappings I could somehow use the document() function to import this into
> the stylesheet and use an index to search it (ergh) but that doesn't
> seem to work either.
>
> There's little point in having a pie-chart schema if you have to do the
> calculations yourself anyway.
>
> So if anyone has any suggestions .. ? I'd certainly be pleased to share
> a pie-chart-XSLT transform if I can get it going.
>
> As an aside, does anyone know why SVG paths are so (IMHO) brain dead? I
> can't believe that the elements in a path aren't XML elements, it seems
> very strange. (Generating the paths in XSLT is going to be a bit
> painful, even if I can get the sin() of an angle. I dont really see how
> "M300,200 h-150 a150,150 0 1,0 150,-150 z" qualifies as XML).
>
> Cheers
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
> For additional commands, email: fop-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org


Re: OT(?): transcendental functions in XSLT

Posted by Mark Lillywhite <ma...@inomial.com>.
Howdy transformers,

Thanks to those that helped me out. I tried the developerworks article
that Trevor mentioned; the article was for an older version of xalan,
but once I knew where to look I was able to bind to the java.lang.Math
class and now I have transcendentals coming out my ears :)

Anyway I got one wedge of pie to draw now, and a second one draws OK for
areas < 50%, so I'm on my way, I'll put the scripts on my web site if I
get them working satisfactorally.

Cheers
Mark



On Tue, 2001-09-18 at 01:40, Wim Beliën wrote:
> If you are using xalan, you can add the
> xmlns:math="xalan://java.lang.Math namespace
> to your xsl document. Then you can use all
> methods out of the java.lang.Math object.
> like
> 
> <line x1="{math:log(myTag)}" y1="0" x2="{math:log(myTag)}" y2="0"/>
> 
> Although I haven't tried, I think this should also be possible in a  svg
> path construction like
> 
> <path d="M275,175 v-150 a150,150 0 0,0 -{150 * math:sin(myTag)},{150 -
> math:sin(myTag)}z"
>  fill="yellow" stroke="blue" stroke-width="5" />
> 
> Please keep me posted of your results.
> 
> ++++++++++++++++++++++++++++++++++
> Wim Beliën
> Netherlands Institute of Applied Geoscience TNO
> Delft, the Netherlands
> tel     : +31 15 2696824
> email : w.belien@nitg.tno.nl
> ++++++++++++++++++++++++++++++++++
> 
> ----- Original Message -----
> From: "Mark" <ma...@inomial.com>
> To: <fo...@xml.apache.org>
> Sent: Sunday, September 16, 2001 5:28 PM
> Subject: OT(?): transcendental functions in XSLT
> 
> > Hi folks,
> >
> > sorry for this slightly off topic post but i was hoping someone could
> > help me.
> >
> > I thought i should be able to produce a very simple xml schema for
> > generating pie charts. the idea was that I could use XSLT to transform
> > from the pie-chart schema to SVG (and then to import the SVG into FOP).
> >
> > It would be preferable to express the size of the pie chart segments as
> > percentages, but the SVG Path object requires coordinates on the
> > circumferance of a circle.
> >
> > The problem is that there don't seem to be any functions in XSLT or
> > XPath that let me find the sin() or cosine() of an angle. Am I missing
> > something? I thought I could possibly use a transform but I can't seem
> > to perform a transform in the middle of a Path.
> >
> > I finally decided that maybe if I created a table of degree-to-sin/cos
> > mappings I could somehow use the document() function to import this into
> > the stylesheet and use an index to search it (ergh) but that doesn't
> > seem to work either.
> >
> > There's little point in having a pie-chart schema if you have to do the
> > calculations yourself anyway.
> >
> > So if anyone has any suggestions .. ? I'd certainly be pleased to share
> > a pie-chart-XSLT transform if I can get it going.
> >
> > As an aside, does anyone know why SVG paths are so (IMHO) brain dead? I
> > can't believe that the elements in a path aren't XML elements, it seems
> > very strange. (Generating the paths in XSLT is going to be a bit
> > painful, even if I can get the sin() of an angle. I dont really see how
> > "M300,200 h-150 a150,150 0 1,0 150,-150 z" qualifies as XML).
> >
> > Cheers
> > Mark
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
> > For additional commands, email: fop-dev-help@xml.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
> For additional commands, email: fop-dev-help@xml.apache.org
> 


Re: OT(?): transcendental functions in XSLT

Posted by Wim Beliën <w....@nitg.tno.nl>.
If you are using xalan, you can add the
xmlns:math="xalan://java.lang.Math namespace
to your xsl document. Then you can use all
methods out of the java.lang.Math object.
like

<line x1="{math:log(myTag)}" y1="0" x2="{math:log(myTag)}" y2="0"/>

Although I haven't tried, I think this should also be possible in a  svg
path construction like

<path d="M275,175 v-150 a150,150 0 0,0 -{150 * math:sin(myTag)},{150 -
math:sin(myTag)}z"
 fill="yellow" stroke="blue" stroke-width="5" />

Please keep me posted of your results.

++++++++++++++++++++++++++++++++++
Wim Beliën
Netherlands Institute of Applied Geoscience TNO
Delft, the Netherlands
tel     : +31 15 2696824
email : w.belien@nitg.tno.nl
++++++++++++++++++++++++++++++++++

----- Original Message -----
From: "Mark" <ma...@inomial.com>
To: <fo...@xml.apache.org>
Sent: Sunday, September 16, 2001 5:28 PM
Subject: OT(?): transcendental functions in XSLT

> Hi folks,
>
> sorry for this slightly off topic post but i was hoping someone could
> help me.
>
> I thought i should be able to produce a very simple xml schema for
> generating pie charts. the idea was that I could use XSLT to transform
> from the pie-chart schema to SVG (and then to import the SVG into FOP).
>
> It would be preferable to express the size of the pie chart segments as
> percentages, but the SVG Path object requires coordinates on the
> circumferance of a circle.
>
> The problem is that there don't seem to be any functions in XSLT or
> XPath that let me find the sin() or cosine() of an angle. Am I missing
> something? I thought I could possibly use a transform but I can't seem
> to perform a transform in the middle of a Path.
>
> I finally decided that maybe if I created a table of degree-to-sin/cos
> mappings I could somehow use the document() function to import this into
> the stylesheet and use an index to search it (ergh) but that doesn't
> seem to work either.
>
> There's little point in having a pie-chart schema if you have to do the
> calculations yourself anyway.
>
> So if anyone has any suggestions .. ? I'd certainly be pleased to share
> a pie-chart-XSLT transform if I can get it going.
>
> As an aside, does anyone know why SVG paths are so (IMHO) brain dead? I
> can't believe that the elements in a path aren't XML elements, it seems
> very strange. (Generating the paths in XSLT is going to be a bit
> painful, even if I can get the sin() of an angle. I dont really see how
> "M300,200 h-150 a150,150 0 1,0 150,-150 z" qualifies as XML).
>
> Cheers
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
> For additional commands, email: fop-dev-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org