easy way of rotating text?

24 views
Skip to first unread message

Dan Kortschak

unread,
Jun 5, 2013, 5:50:44 PM6/5/13
to plotinum...@googlegroups.com
I'm looking at how to rotate text for axes/point labels and so far I
think that what I need to do is translate the canvas, rotate and then
reverse the original translation. Is there an easier way?

thanks
Dan

Ethan Burns

unread,
Jun 5, 2013, 7:22:33 PM6/5/13
to plotinum...@googlegroups.com
Hi Dan,

It isn't supported. See this issue: https://code.google.com/p/plotinum/issues/detail?id=51. I couldn't figure out a great way to add support for it, so I just gave up. I'll re-open the issue and maybe I'll eventually think of something.


Ethan

Dan Kortschak

unread,
Jun 5, 2013, 7:41:18 PM6/5/13
to Ethan Burns, plotinum...@googlegroups.com
I'm thinking of a more general question; is it possible to do rotated
text at all?

Ethan Burns

unread,
Jun 5, 2013, 7:59:04 PM6/5/13
to Dan Kortschak, plotinum...@googlegroups.com

Vg supports arbitrary text rotation, so it should be easy to use rotation for many things (labels plotter, axis labels), but, for various reasons, it is not easy to support general rotation for all text in Plotinum (tick labels)-- at least I didn't think it was easy when I closed that ticket.

Ethan

Dan Kortschak

unread,
Jun 5, 2013, 8:06:37 PM6/5/13
to Ethan Burns, plotinum...@googlegroups.com
On Wed, 2013-06-05 at 19:59 -0400, Ethan Burns wrote:
> Vg supports arbitrary text rotation, so it should be easy to use
> rotation for many things (labels plotter, axis labels), but, for
> various reasons, it is not easy to support general rotation for all
> text in Plotinum (tick labels)-- at least I didn't think it was easy
> when I closed that ticket.

Ahh, OK. So how is the arbitrary text rotation performed? I can't see an
obvious way except what I originally posted.

thanks
Dan

Ethan Burns

unread,
Jun 5, 2013, 8:13:05 PM6/5/13
to Dan Kortschak, plotinum...@googlegroups.com

Yeah, what you originally posted should work if you want to modify the plot package code.

Ethan

Dan Kortschak

unread,
Jun 24, 2013, 1:01:27 AM6/24/13
to Ethan Burns, plotinum...@googlegroups.com
Following up this thread.

I'm having a great deal of difficulty trying to sort out a way of doing
this without having to introduce new code to calculate polar offsets; I
don't think I should need to do this, but maybe I do.

I have variations on the following code:

da.Push()
da.Translate(-x, -y)
da.Rotate(angle)
da.FillText(
plot.TextStyle{Color: color.Gray16{0}, Font: f},
x, y, -0.5, -0.5, "Test LABEL",
)
da.Pop()

The intention is to translate the canvas so that rotation is around the
point (x, y), rotate and draw.

I can find no combination of translations, and FillText locations that
do not result in the text's location also being rotated around the
origin. Ideally I just want some function that will perform the semantic
equivalent of RotateAround(pt plot.Point, angle float64) - I just can't
figure out how to get it.

Any help would be greatly appreciated.

Dan

Dan Kortschak

unread,
Jun 24, 2013, 1:15:29 AM6/24/13
to Ethan Burns, plotinum...@googlegroups.com
Reading the svg reference has given the clue needed. The following
works:

da.Push()
da.Translate(x, y)
da.Rotate(angle)
da.Translate(-x, -y)

Ethan Burns

unread,
Jun 24, 2013, 9:30:23 AM6/24/13
to Dan Kortschak, plotinum...@googlegroups.com
Hi Dan,

I am glad to see that you figured it out!

At one point I was considering adding rotation to the text style so
that no one would have to do the really ugly push, translate, rotate,
translate back, draw, pop stuff. I still think that it should be in
there, but if I recall correctly, it gets messy because now the
TextStyle.Width and .Height methods no longer say the actual width and
height of the bounding box of the text. There would need to be a
separate method to get the bbox size. This isn't a problem on its
own, but actually figuring out which calls to .Height and .Width
should really call this new method instead would be a pain and fairly
error prone.

In fact, there seems to be an issue for text rotation if you wanted to
follow it: https://code.google.com/p/plotinum/issues/detail?id=51.


Ethan
> --
> You received this message because you are subscribed to a topic in the Google Groups "plotinum-discuss" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/plotinum-discuss/g2N2FVXSkKw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to plotinum-discu...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Dan Kortschak

unread,
Jun 24, 2013, 9:08:49 PM6/24/13
to Ethan Burns, plotinum...@googlegroups.com
On Mon, 2013-06-24 at 09:30 -0400, Ethan Burns wrote:
> At one point I was considering adding rotation to the text style so
> that no one would have to do the really ugly push, translate, rotate,
> translate back, draw, pop stuff. I still think that it should be in
> there, but if I recall correctly, it gets messy because now the
> TextStyle.Width and .Height methods no longer say the actual width and
> height of the bounding box of the text.

I had a look at that issue and figured it was too difficult to do
correctly given my limited knowledge of how fonts work and so left it to
the client. Width seems to work OK, but height is not quite correct. I
just allow the client to pass in Xadjust and Yadjust to their heart's
content.

> There would need to be a separate method to get the bbox size. This
> isn't a problem on its own, but actually figuring out which calls
> to .Height and .Width should really call this new method instead would
> be a pain and fairly error prone.

Yes.

> In fact, there seems to be an issue for text rotation if you wanted to
> follow it: https://code.google.com/p/plotinum/issues/detail?id=51.

Yeah I saw that.

The labelling code is at [1].

I'd like to add that the work you have put into vg makes life very much
easier for people wanting to have a cross-platform (in the image
universe) method of generating vector graphics. It's a great boon.

thanks
Dan

[1]http://code.google.com/p/biogo/source/browse/rings/labels.go?repo=graphics&name=feature%2Frings


Reply all
Reply to author
Forward
0 new messages