From: Rich D. <dr...@in...> - 2005-09-09 19:06:38
|
Hello, I have a number of curve() connectors, and I'd like to put a small text label next to each. Is there some automated way to have PyX place my text at a reasonable location next to each curve? I could try to place the text manually, but since I don't know exactly where the curve is going to be placed that seems like a lot of work, and if I change my curve parameters I would have to place the text again. Do I need to somehow extract the coordinates of the curve and use some transform operation to place the text? I see that axes can take "title=" variables, but curves don't seem to. I did see a post on the user mailing list about laying text out along a curve, which would be OK, though a bit more than I need, and used more advanced TeX-Fu than I understood, but the example code did not work for me (PyX 0.8.1). Otherwise, none of the PyX example programs seem to do what I want, which seems odd, since this must be something people want to do fairly often. Thanks to PyX developers! Rich |
From: Andre W. <wo...@us...> - 2005-09-12 07:08:13
|
Hi, On 09.09.05, Rich Drewes wrote: > I have a number of curve() connectors, and I'd like to put a small text > label next to each. Is there some automated way to have PyX place my text > at a reasonable location next to each curve? I could try to place the > text manually, but since I don't know exactly where the curve is going to > be placed that seems like a lot of work, and if I change my curve > parameters I would have to place the text again. Do I need to somehow > extract the coordinates of the curve and use some transform operation to > place the text? > > I see that axes can take "title=" variables, but curves don't seem to. > > I did see a post on the user mailing list about laying text out along a > curve, which would be OK, though a bit more than I need, and used more > advanced TeX-Fu than I understood, but the example code did not work for > me (PyX 0.8.1). Otherwise, none of the PyX example programs seem to do > what I want, which seems odd, since this must be something people want to > do fairly often. Right. And we have the concept of decorators for that. We just not yet implemented a text decorator. But it's quite easy to do so, and we only need to add such a thing to the PyX core, which I'll do right now along the lines of the following, basic but useful implementation: import math from pyx import * class textdeco(deco.deco, attr.attr): def __init__(self, text, textattrs=[text.halign.center, text.vshift.mathaxis], angle=0, textdist=0.2, relarcpos=0.5, texrunner=text.defaulttexrunner): self.text = text self.textattrs = textattrs self.angle = angle self.textdist = textdist self.relarcpos = relarcpos self.texrunner = texrunner def decorate(self, dp): x, y = dp.path.at(self.relarcpos * dp.path.arclen()) t = self.texrunner.text(x, y, self.text, self.textattrs) t.linealign(self.textdist, math.cos(self.angle*math.pi/180), math.sin(self.angle*math.pi/180)) dp.ornaments.insert(t) return dp c = canvas.canvas() c.stroke(path.curve(0, 0, 3, 0, 2, 5, 5, 5), [textdeco("Hello, world!")]) c.writeEPSfile("textdeco") HTH, André -- by _ _ _ Dr. André Wobst / \ \ / ) wo...@us..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript and PDF figures (_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/ |
From: Rich D. <dr...@in...> - 2005-09-12 15:54:05
|
That works great. Thanks! Rich On Mon, 12 Sep 2005, Andre Wobst wrote: > Right. And we have the concept of decorators for that. We just not yet > implemented a text decorator. But it's quite easy to do so, and we > only need to add such a thing to the PyX core, which I'll do right now > along the lines of the following, basic but useful implementation: > . . . |
From: Andre W. <wo...@us...> - 2005-09-14 11:16:23
|
Hi, On 13.09.05, Rich Drewes wrote: > The "angle" argument doesn't seem to result in rotations of the placed > text. Is it supposed to? No, it's the direction used for alignment. We could (and even should at least have an option to) do this perpendicular to the path. To come back to your original question, you should add a rotation to the textattrs. Unfortunately you'll overwrite the text.halign.center and text.vshift.mathaxis by that. The PyX-way would be to merge those attributes the the additional attributes. So the code would look like: class textdeco(deco.deco, attr.attr): def __init__(self, text, textattrs=[], angle=0, textdist=0.2, relarcpos=0.5, texrunner=text.defaulttexrunner): self.text = text self.textattrs = textattrs self.angle = angle self.textdist = textdist self.relarcpos = relarcpos self.texrunner = texrunner def decorate(self, dp): x, y = dp.path.at(self.relarcpos * dp.path.arclen()) textattrs = attr.mergeattrs([text.halign.center, text.vshift.mathaxis] + self.textattrs) t = self.texrunner.text(x, y, self.text, textattrs) t.linealign(self.textdist, math.cos(self.angle*math.pi/180), math.sin(self.angle*math.pi/180)) dp.ornaments.insert(t) return dp c = canvas.canvas() c.stroke(path.curve(0, 0, 3, 0, 2, 5, 5, 5), [textdeco("Hello, world!", textattrs=[trafo.rotate(45)])]) c.writeEPSfile("textdeco") André -- by _ _ _ Dr. André Wobst / \ \ / ) wo...@us..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript and PDF figures (_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/ |