CanvasPlot, createPlotAxis and createLinePlot

Good afternoon,

I’m trying to get a line plot (x-y coordinates with a line) up and
running on a Windows XP/Pro box.
I’m using references:

  1. The “Pick Axe” book
  2. “Mastering Perl/Tk”

The three classes or methods that will do everything I want, as shown in
ref 2, are:

  1. CanvasPlot
  2. createLinePlot
  3. createPlotAxis

What is the ‘require’ that is required to make these Class/Methods known
to a Ruby program…

Thanks,
Pat

Patrick L. wrote:

/ …

The three classes or methods that will do everything I want, as shown in
ref 2, are:

  1. CanvasPlot
  2. createLinePlot
  3. createPlotAxis

What is the ‘require’ that is required to make these Class/Methods known
to a Ruby program…

Most likely:

require ‘tk’

Paul L. wrote:

Patrick L. wrote:

/ …

The three classes or methods that will do everything I want, as shown in
ref 2, are:

  1. CanvasPlot
  2. createLinePlot
  3. createPlotAxis

What is the ‘require’ that is required to make these Class/Methods known
to a Ruby program…

Most likely:

require ‘tk’

I tried ‘tk’…but it doesn’t work…bummer…

On Sep 27, 2006, at 5:47 PM, Patrick L. wrote:

  1. createLinePlot
  2. createPlotAxis

What is the ‘require’ that is required to make these Class/Methods
known
to a Ruby program…

AFIK, TK::CanvasPlot is Perl only and is not available in the Ruby/Tk
libraries.

Regards, Morton

Morton G. wrote:

On Sep 27, 2006, at 5:47 PM, Patrick L. wrote:

  1. createLinePlot
  2. createPlotAxis

What is the ‘require’ that is required to make these Class/Methods
known
to a Ruby program…

AFIK, TK::CanvasPlot is Perl only and is not available in the Ruby/Tk
libraries.

Regards, Morton

Thanks Morton. Too bad, it does exactly what I need to do…what I’m
trying to do is to create a Line Plot with labeled x & y coordinates and
with tick marks on the coordinates…

I haven’t seen anything like this in the ‘Pick Axe’ book. I’ll check the
Tk classes…if you know of anything that I can use, please pass it on
to me…

Good day,
Pat

On Sep 28, 2006, at 6:34 AM, Patrick L. wrote:

I haven’t seen anything like this in the ‘Pick Axe’ book. I’ll
check the
Tk classes…if you know of anything that I can use, please pass it on
to me…

I’m afraid I can’t help you. I don’t do that kind of programming with
Ruby/Tk. When I need a line plot or any other kind of data plot, I
use Mathematica.

Discussions previously appearing on this ML indicate you can drive
GNUPlot from Ruby. You might look into that. Here a URL that could
get started:

  http://rgnuplot.sourceforge.net/

Regards, Morton

Hidetoshi NAGAI wrote:

From: Patrick L. [email protected]
Subject: Re: CanvasPlot, createPlotAxis and createLinePlot.
Date: Thu, 28 Sep 2006 19:34:06 +0900
Message-ID: [email protected]

  1. createLinePlot
  2. createPlotAxis

Those seem Perl’s simple subroutines.
It will be not difficult that you write such methods on Ruby/Tk.

If you want to create a line item “line” on the canvas “c”,

line = TkcLine.new(c, <…coords…>, <…options…>)

e.g. line = TkcLine.new(c, 0, 0, 10, 5, 20, 30, :fill=>‘red’)
or
line = TkcLine.new(c, [0, 0, 10, 5, 20, 30], :fill=>‘red’)
or
line = TkcLine.new(c, [0, 0], [10, 5], [20, 30], :fill=>‘red’)
or
line = TkcLine.new(c, [[0, 0], [10, 5], [20, 30]], :fill=>‘red’)

If you want an arc item, please use TkcArc class.

Hi,

I’ve done that…can you tell me how to add tick marks and coordinate
values and possibly even coordinate labels?

FYI

0----10----20----30----40—…
Label: this is the x-axis…

a similar thing for the y-axis…

THX

From: Patrick L. [email protected]
Subject: Re: CanvasPlot, createPlotAxis and createLinePlot.
Date: Fri, 29 Sep 2006 04:51:28 +0900
Message-ID: [email protected]

I’ve done that…can you tell me how to add tick marks and coordinate
values and possibly even coordinate labels?

FYI

0----10----20----30----40—…
Label: this is the x-axis…

a similar thing for the y-axis…

Do you want to use this from Ruby?
vvvv
http://perl.codefetch.com/example/da/mptk-code14/Tk/CanvasPlot.pm

It seems that the package is constructed with standard canvas items
only.
Why don’t you translate it to Ruby/Tk? :wink:
Anyway, translation is not so difficult, if you can read the Perl
source.
For example,
----<Perl/Tk>--------------------------------------------------
if ($y_axis) {
$self->createText(
$x1-$tl, $y2-$x, -text => $l,
%args, -fill => $tcolor,
-font => $lfont, -anchor => $an,
);
} else {
$self->createText(
$x+$x1, $y1+$tl, -text => $l,
%args, -fill => $tcolor,
-font => $tfont, -anchor => $an,
);
}

----<Ruby/Tk>--------------------------------------------------
if (y_axis) {
TkcText.new(self, x1-tl, y2-x,
args.merge(:text=>l, :fill=>tcolor,
:font=>lfont, :anchor=>an)
)
} else {
TkcText.new(self, x+x1, y1+tl,
args.merge(:text=>l, :fill=>tcolor,
:font=>tfont, :anchor=>an)
)
}

However, if you want to create beautiful graphs,
I recommend you to use BLT ( or Tcllib(Tklib) ) extension.
Current Ruby/Tk has a binding for BLT ( and Tcllib(Tklib) ).

Hidetoshi NAGAI wrote:

It seems that the package is constructed with standard canvas items
only.
Why don’t you translate it to Ruby/Tk? :wink:
Anyway, translation is not so difficult, if you can read the Perl
source.
For example,
----<Perl/Tk>--------------------------------------------------
if ($y_axis) {
$self->createText(
$x1-$tl, $y2-$x, -text => $l,
%args, -fill => $tcolor,
-font => $lfont, -anchor => $an,
);
} else {
$self->createText(
$x+$x1, $y1+$tl, -text => $l,
%args, -fill => $tcolor,
-font => $tfont, -anchor => $an,
);
}

----<Ruby/Tk>--------------------------------------------------
if (y_axis) {
TkcText.new(self, x1-tl, y2-x,
args.merge(:text=>l, :fill=>tcolor,
:font=>lfont, :anchor=>an)
)
} else {
TkcText.new(self, x+x1, y1+tl,
args.merge(:text=>l, :fill=>tcolor,
:font=>tfont, :anchor=>an)
)
}

However, if you want to create beautiful graphs,
I recommend you to use BLT ( or Tcllib(Tklib) ) extension.
Current Ruby/Tk has a binding for BLT ( and Tcllib(Tklib) ).

Hidetoshi,
Thank you, I shall try both techniques…
I’m developing a Quality Assurance Metrics package…so I will need do
do some beautiful graphs…
When its done, I will dedicate the graphics portion to you.
Ciao,
Pat

Patrick L. wrote:

Hidetoshi NAGAI wrote:

It seems that the package is constructed with standard canvas items
only.
Why don’t you translate it to Ruby/Tk? :wink:
Anyway, translation is not so difficult, if you can read the Perl
source.
For example,
----<Perl/Tk>--------------------------------------------------
if ($y_axis) {
$self->createText(
$x1-$tl, $y2-$x, -text => $l,
%args, -fill => $tcolor,
-font => $lfont, -anchor => $an,
);
} else {
$self->createText(
$x+$x1, $y1+$tl, -text => $l,
%args, -fill => $tcolor,
-font => $tfont, -anchor => $an,
);
}

----<Ruby/Tk>--------------------------------------------------
if (y_axis) {
TkcText.new(self, x1-tl, y2-x,
args.merge(:text=>l, :fill=>tcolor,
:font=>lfont, :anchor=>an)
)
} else {
TkcText.new(self, x+x1, y1+tl,
args.merge(:text=>l, :fill=>tcolor,
:font=>tfont, :anchor=>an)
)
}

However, if you want to create beautiful graphs,
I recommend you to use BLT ( or Tcllib(Tklib) ) extension.
Current Ruby/Tk has a binding for BLT ( and Tcllib(Tklib) ).

Hidetoshi,
Thank you, I shall try both techniques…
I’m developing a Quality Assurance Metrics package…so I will need do
do some beautiful graphs…
When its done, I will dedicate the graphics portion to you.
Ciao,
Pat

I finally got the Perl version of Tk::CanvasPlot up an running – see
the book “Mastering Perl/Tk” by Steve Lidie and Nancy Walsh…I now need
to convert this Perl Code to Ruby…

BTW, I tried to make ‘BLT’ known to one of my Ruby scripts but am unable
to do so…Will you please tell me how to do this…

Finally, if anyone is going to use Tk::CanvasPlot in the book mentioned
above, give me an email…there is one method that is not included in
the text…

Good day

From: Patrick L. [email protected]
Subject: Re: CanvasPlot, createPlotAxis and createLinePlot.
Date: Thu, 28 Sep 2006 19:34:06 +0900
Message-ID: [email protected]

  1. createLinePlot
  2. createPlotAxis

Those seem Perl’s simple subroutines.
It will be not difficult that you write such methods on Ruby/Tk.

If you want to create a line item “line” on the canvas “c”,

line = TkcLine.new(c, <…coords…>, <…options…>)

e.g. line = TkcLine.new(c, 0, 0, 10, 5, 20, 30, :fill=>‘red’)
or
line = TkcLine.new(c, [0, 0, 10, 5, 20, 30], :fill=>‘red’)
or
line = TkcLine.new(c, [0, 0], [10, 5], [20, 30], :fill=>‘red’)
or
line = TkcLine.new(c, [[0, 0], [10, 5], [20, 30]], :fill=>‘red’)

If you want an arc item, please use TkcArc class.