Hello, Alex, I think we are overdue to talk about what we can do to get your
improvements/modifications into the PHPlot releases, if that will work. I know
I usually seem unresponsive to patches or changes, but I do want to improve
PHPlot.
My goals for the project require that we:
Retain compatibility with existing plots, or have a really good reason to break things;
Documentation - the reference manual - must be kept up-to-date;
Changes need to be testable - test cases must be produced.
I'm not saying you (or anyone else) needs to do these things to get patches
accepted, but they do need to be done.
I'm going to take (another?) look at your version of PHPlot, with the goal of
incorporating as much as possible, and I hope I can count on your help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Feel free to use the email address listed on my weblink above. I won't type it
here because I already get enough spam from bots harvesting sourceforge :-(
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My "ideal" API, as a user, would be somehing like
$plot->DrawTextXY($x,$y,$text);
where $x and $y are "physical" coordinates (maybe one needs a
DrawTextLabelY($label,$y,$text) in the case $x is not a number? I don't know
:)
As far as i understand adoll's modifications would allow me to obtain the same
effect by using a dummy data set :P so I would really prefere the "clean
and dedicated API" solution...
Anyway, I will follow the discussion and see what happens (I have just
restored my sourceforge account)
Regards!
Luigi
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm wondering how one would sensibly position add-on text.
Terminology first:
PHPlot uses the terms Device Coordinates (which are the coordinate space
ofthe resulting image (0,0 in the upper left of the image, and units are
pixels), and World Coordinates (0,0 at the origin of the plotted data, and
in units of the data). By "physical units", are you referring to
Device Coordinates?
The difficulty is how to position the text in meaningful places, like relative
to the X axis, or make sure that text doesn't end up on top of something else.
An important issue is that PHPlot doesn't actually draw anything until you use
DrawGraph(). Implementing something like your DrawTextXY means storing up all
the text and coordinates until drawing time. (Tempting to consider using
callbacks instead.)
\> in the same spirit, it would be nice also to have an API to obtain the
\> pixel coordinates of a generic x,y point: this would allow users to use
GD
\> or similar to overlay stuff on the plot after it has been drawn
(For 'generic x,y', I assume 'world coordinates'.)
The functions $plot->xtr($x_world) and $plot->ytr($y_world) do this,
but
they are currently documented as "internal". (Doesn't mean you can't
use them, only that I won't apologize if they change some day and break your
code!) Maybe I need to wrap them in a public function, such as
I use randomly positioned text in two forms in my apps. First is the labels on
points (the modified code in my earlier examples). This is easiest done using
the existing 'label' column in the data series that is otherwise unused in
data-data plots.
A second example is a chart when I use a 'hidden series' to create a nomograph
with a second Y-axis (see , yes- this is 100% PHPlot using the code I've
posted). In this instance, I'm looking to position text at the last point of a
line showing the name of that series (the %filling), then I position a few
markers outside the right-hand boundary and put the bogus Y-2 axis labels on
them. This example would benefit from a more generic way of putting text at a
position specified in world units (kW and %speed in the second example).
If someone needs to position text in device coordinates, just return a GD
image that they can manipulate in PHP (Does $plot->DrawGraph() do that?
I've not tried it).
$myimg = $plot->DrawGraph(); // get a handle to the graph drawn by PHPlot
imagestring( $myimg, 1, 10,10 , "Figure 1: Something", $mycolour);
// title at the top-left of the PNG
imagepng( $myimg ); // send the annotated chart to the browser
No, there isn't a documented way to get the image back as a GD image resource.
If you use SetPrintImage(false), then DrawGraph() generates the image but does
nothing with it. Then you would have to reach inside and get $plot->img for
the image resource. Not 'supported'.
Nor is there a callback which is always called when the drawing is done, which
would be handy because callbacks include the image resource as the first
argument so you could do your stuff there. I should fix that.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, this is true, unless the call to DrawText is done after any call to
DrawGraph.
I wonder ....... how one would sensibly position add-on text.
For example I may have a dataset like "my quantity" vs
"time" and I want to mark that at time="15 Oct 2009"
something useful happened: for an example, try to search "php" in
google trends:
A,B,C are "comments" added in "World coordinates" I
guess....
Maybe I need to wrap them in a public function, such as devicexy....
Yes, this would be a good solution, but, as adoll said, one should be able to
access the resulting GD image.
Of course one can use "image.php" that takes the output of
"image_with_phplot.php" and then overlay something but it is not
nice (and you loose the World<=>Device coordinates conversion(s)
Just my cents
Luigi
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There are two tracks to this. adoll's changes for placing X data labels at the
data points is proving hard to adapt. Mostly because I'm not sure what to do
with multiple Y values for an X. Set aside for now.
The second track is better support for drawing on your graph. Soon to go into
CVS is a new callback (which it turns out is not really needed), and a
published method for mapping world to device coordinates:
The new callback will be called after drawing is complete. It isn't really
needed, because you can use SetPrintImage(False), and then do your drawing
after DrawGraph() returns. The thing to remember is you can't draw until
DrawGraph does its setup work. The GetDeviceXY() method will enforce this,
unlike the internal conversion methods xtr() and ytr(): you can only use it
from a 'draw' callback or after DrawGraph returns (with SetPrintImage(false)).
I need to write some documentation about drawing on your graph. This includes:
coordinates, colors, graphics, text. In most cases, I recommend using GD
functions and avoid PHPlot object internals. For example, use
imagecolorallocate() for the colors you want; use imagestring() or
imagettftext() to draw text.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all,
I am starting using PHPLOT, and yes, it is great!
One feature I am missing is the capability to add a text (like comment) in a
given X-Y position, where X-Y are physical coordinates (no pixels).
This would be useful to "annotate" some particular points.
Can you help me?
Thank you!
Luigi
Hi Luigi
I modified a local copy of PHPlot a while ago that may do what you need. You
can see example plots and download the code from here:
Be warned this is an old version of PHPlot that I modified.
http://www.agdconsulting.ca/webtools/phplot.php
Hi adoll,
it seems exactly what I was looking for :D
Do you which "major" features (if any) are missing from your
"old" version as compared with the "new" one? (GD2? PHP5?
etc etc)
Thank you!
Luigi
Hello, Alex, I think we are overdue to talk about what we can do to get your
improvements/modifications into the PHPlot releases, if that will work. I know
I usually seem unresponsive to patches or changes, but I do want to improve
PHPlot.
My goals for the project require that we:
I'm not saying you (or anyone else) needs to do these things to get patches
accepted, but they do need to be done.
I'm going to take (another?) look at your version of PHPlot, with the goal of
incorporating as much as possible, and I hope I can count on your help.
Awesome ! I'll offer whatever assistance you need.
In the source code, search for "AGD" in the comments. That will show
you the locations where I've made changes.
Good.
I don't think your code has changed since Apr 2007, correct? (Seems I
downloaded, looked it over, and then neglected to follow through on it back
then...)
Second question, preferred contact method for my questions on the code? (E.g.
this forum, your sourceforge.net email alias, or other?)
3rd: The original question from Luigi, sounds like he wants to draw
arbitrary text on the plot. I don't see that in your changes, or did I
overlook something, since he said it is exactly what he wanted?
I'm pretty sure this feature has been requested before.
It can be done with the callback feature, but it isn't
exactly intuitive. I have a test case that does it. But I just used
ImageString with absolute device coordinates in the callback. If anyone
wants to suggest an API for 'adding extra text to a plot', feel free.
Feel free to use the email address listed on my weblink above. I won't type it
here because I already get enough spam from bots harvesting sourceforge :-(
Hi all,
thank you for the interest :)
My "ideal" API, as a user, would be somehing like
$plot->DrawTextXY($x,$y,$text);
where $x and $y are "physical" coordinates (maybe one needs a
DrawTextLabelY($label,$y,$text) in the case $x is not a number? I don't know
:)
As far as i understand adoll's modifications would allow me to obtain the same
effect by using a dummy data set :P so I would really prefere the "clean
and dedicated API" solution...
Anyway, I will follow the discussion and see what happens (I have just
restored my sourceforge account)
Regards!
Luigi
no more requests I promise ;)
Luigi
I'm wondering how one would sensibly position add-on text.
Terminology first:
PHPlot uses the terms Device Coordinates (which are the coordinate space
ofthe resulting image (0,0 in the upper left of the image, and units are
pixels), and World Coordinates (0,0 at the origin of the plotted data, and
in units of the data). By "physical units", are you referring to
Device Coordinates?
The difficulty is how to position the text in meaningful places, like relative
to the X axis, or make sure that text doesn't end up on top of something else.
An important issue is that PHPlot doesn't actually draw anything until you use
DrawGraph(). Implementing something like your DrawTextXY means storing up all
the text and coordinates until drawing time. (Tempting to consider using
callbacks instead.)
\> in the same spirit, it would be nice also to have an API to obtain the
\> pixel coordinates of a generic x,y point: this would allow users to use
GD
\> or similar to overlay stuff on the plot after it has been drawn
(For 'generic x,y', I assume 'world coordinates'.)
The functions $plot->xtr($x_world) and $plot->ytr($y_world) do this,
but
they are currently documented as "internal". (Doesn't mean you can't
use them, only that I won't apologize if they change some day and break your
code!) Maybe I need to wrap them in a public function, such as
list($pixel_x, $pixel_y) = $plot->devicexy($world_x, $world_y)
I use randomly positioned text in two forms in my apps. First is the labels on
points (the modified code in my earlier examples). This is easiest done using
the existing 'label' column in the data series that is otherwise unused in
data-data plots.
A second example is a chart when I use a 'hidden series' to create a nomograph
with a second Y-axis (see , yes- this is 100% PHPlot using the code I've
posted). In this instance, I'm looking to position text at the last point of a
line showing the name of that series (the %filling), then I position a few
markers outside the right-hand boundary and put the bogus Y-2 axis labels on
them. This example would benefit from a more generic way of putting text at a
position specified in world units (kW and %speed in the second example).
If someone needs to position text in device coordinates, just return a GD
image that they can manipulate in PHP (Does $plot->DrawGraph() do that?
I've not tried it).
$myimg = $plot->DrawGraph(); // get a handle to the graph drawn by PHPlot
imagestring( $myimg, 1, 10,10 , "Figure 1: Something", $mycolour);
// title at the top-left of the PNG
http://www.agdconsulting.ca/webtools/tentdiag_chart.png
No, there isn't a documented way to get the image back as a GD image resource.
If you use SetPrintImage(false), then DrawGraph() generates the image but does
nothing with it. Then you would have to reach inside and get $plot->img for
the image resource. Not 'supported'.
Nor is there a callback which is always called when the drawing is done, which
would be handy because callbacks include the image resource as the first
argument so you could do your stuff there. I should fix that.
Hi all,
nice discussion! I have a couple of comments:
Implementing something like your
DrawTextXY means storing up all the
text and coordinates until drawing
time.
Yes, this is true, unless the call to DrawText is done after any call to
DrawGraph.
I wonder ....... how one would sensibly position add-on text.
For example I may have a dataset like "my quantity" vs
"time" and I want to mark that at time="15 Oct 2009"
something useful happened: for an example, try to search "php" in
google trends:
http://www.google.com/trends?q=php&ctab=0&geo=all&date=all&so
rt=0
A,B,C are "comments" added in "World coordinates" I
guess....
Maybe I need to wrap them in a public function, such as devicexy....
Yes, this would be a good solution, but, as adoll said, one should be able to
access the resulting GD image.
Of course one can use "image.php" that takes the output of
"image_with_phplot.php" and then overlay something but it is not
nice (and you loose the World<=>Device coordinates conversion(s)
Just my cents
Luigi
(any news?)
There are two tracks to this. adoll's changes for placing X data labels at the
data points is proving hard to adapt. Mostly because I'm not sure what to do
with multiple Y values for an X. Set aside for now.
The second track is better support for drawing on your graph. Soon to go into
CVS is a new callback (which it turns out is not really needed), and a
published method for mapping world to device coordinates:
list($x, $y) = $plot->GetDeviceXY($world_x, $world_y)
The new callback will be called after drawing is complete. It isn't really
needed, because you can use SetPrintImage(False), and then do your drawing
after DrawGraph() returns. The thing to remember is you can't draw until
DrawGraph does its setup work. The GetDeviceXY() method will enforce this,
unlike the internal conversion methods xtr() and ytr(): you can only use it
from a 'draw' callback or after DrawGraph returns (with SetPrintImage(false)).
I need to write some documentation about drawing on your graph. This includes:
coordinates, colors, graphics, text. In most cases, I recommend using GD
functions and avoid PHPlot object internals. For example, use
imagecolorallocate() for the colors you want; use imagestring() or
imagettftext() to draw text.