Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the SVG-TT-Graph CPAN distribution.

Report information
The Basics
Id: 48096
Status: open
Priority: 0/
Queue: SVG-TT-Graph

People
Owner: Nobody in particular
Requestors: MOLECULES [...] cpan.org
Cc: IANRODDIS [...] cpan.org
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



CC: IANRODDIS [...] cpan.org
Subject: Patches uploaded to support basic data point symbols (i.e. diamond, triangle, square, plus sign).
Everyone, If you would like to add support for basic data point symbols for Line graphs, feel free to use the patches I'm uploading. There is also a minor patch for Graph.pm to make this work. Also added is the ability to display these symbols without the data line, if desired. Also uploaded is a test that the introduced functionality. Thanks, Christopher Bottoms p.s. I wasn't sure what to do with the "version" number in Graph.pm, so I set it to "0.120_001".
Subject: 04_line.t
#!/usr/bin/perl -w use lib qw( ./blib/lib ../blib/lib ); # Check we can create objects and adding data works # as well as clearing data. use Test::More qw(no_plan); BEGIN { use_ok( 'SVG::TT::Graph::Line' ); } my @fields = qw(Jan Feb Mar); my @data_sales_02 = qw(12 45 21); my @data_sales_03 = qw(24 55 61); # Might as well test them all, even though they're # the same under the hood! - just in case my @types = qw(Line Bar BarHorizontal Pie BarLine); my $module = "SVG::TT::Graph::Line"; eval { my $gr = $module->new({ }); }; ok($@,'Croak ok as no fields supplied'); my $graph = $module->new({ 'fields' => \@fields, }); isa_ok($graph,$module); # Check we croak if no data eval { $graph->burn(); }; ok($@, 'Burn method croaked as expected - no data has been set'); $graph->add_data({ 'data' => \@data_sales_02, }); is(scalar(@{$graph->{data}}),1,'Data set 1 added'); is($graph->{data}->[0]->{title}, undef,'Data set 1 - title default is undefined ok'); is($graph->{data}->[0]->{data}->{Feb}, 45,'Data set 1 - data set ok'); is($graph->{data}->[0]->{symbol_type}, 'circle','Data set 1 - symbol type ok'); is($graph->{data}->[0]->{symbol_fill}, 1,'Data set 1 - symbol fill ok'); $graph->add_data({ 'data' => \@data_sales_03, 'title' => 'Sales 2003', 'symbol_type'=>'triangle', 'symbol_fill'=>0, }); is(scalar(@{$graph->{data}}),2,'Data set 2 added'); is($graph->{data}->[1]->{title}, 'Sales 2003','Data set 2 - title set ok'); is($graph->{data}->[1]->{data}->{Mar}, 61,'Data set 2 - data set ok'); is($graph->{data}->[1]->{symbol_type}, 'triangle','Data set 2 - symbol type ok'); is($graph->{data}->[1]->{symbol_fill}, 0,'Data set 2 - symbol fill ok'); $graph->clear_data(); is(scalar(@{$graph->{data}}),0,'Data cleared ok');
Subject: Graph.patch
--- Graph.pm.orig 2009-02-16 11:01:37.000000000 -0600 +++ Graph.pm 2009-07-22 15:28:02.000000000 -0500 @@ -6,7 +6,7 @@ use Template; use POSIX; -$VERSION = '0.12'; +$VERSION = '0.120_001'; # set up TT object my %config = ( @@ -156,6 +156,18 @@ 'data' => \%new_data, ); $store{'title'} = $conf->{'title'} if defined $conf->{'title'}; + if($self->isa("SVG::TT::Graph::Line")){ + if (defined $conf->{'symbol_type'}){ + $store{'symbol_type'} = $conf->{'symbol_type'}; + }else{ + $store{'symbol_type'} = 'circle'; + } + if (defined $conf->{'symbol_fill'}){ + $store{'symbol_fill'} = $conf->{'symbol_fill'}; + }else{ + $store{'symbol_fill'} = 1; + } + } push (@{$self->{'data'}},\%store); return 1; }
Subject: Line.patch
66a67 > 'show_data_lines' => 1, 109a111,112 > 'symbol_type' => 'circle', > 'symbol_fill' => 1, 114a118,135 > Possible symbol types: 'circle' (default), 'diamond', > 'triangle', 'plus', 'square'. > > If 'symbol_fill' is set to 1 (default), the symbols for > this data set will be filled. If it is set to 0, the > symbols will be outlines only. > > To show the symbols without the data lines, be sure to > set 'show_data_lines' to '0' when creating the Line > object: > > SVG::TT::Graph::Line->new( > 'height' => '500', > 'width' => '300', > 'fields' => \@fields, > 'show_data_lines' => 0, > ); > 330a352 > 'show_data_lines' => 1, 590a613,673 > /* empty symbol styles */ > .empty1{ > fill: none; > stroke: #ff0000; > stroke-width: 1px; > } > .empty2{ > fill: none; > stroke: #0000ff; > stroke-width: 1px; > } > .empty3{ > fill: none; > stroke: #00ff00; > stroke-width: 1px; > } > .empty4{ > fill: none; > stroke: #ffcc00; > stroke-width: 1px; > } > .empty5{ > fill: none; > stroke: #00ccff; > stroke-width: 1px; > } > .empty6{ > fill: none; > stroke: #ff00ff; > stroke-width: 1px; > } > .empty7{ > fill: none; > stroke: #00ffff; > stroke-width: 1px; > } > .empty8{ > fill: none; > stroke: #ffff00; > stroke-width: 1px; > } > .empty9{ > fill: none; > stroke: #cc6666; > stroke-width: 1px; > } > .empty10{ > fill: none; > stroke: #663399; > stroke-width: 1px; > } > .empty11{ > fill: none; > stroke: #339900; > stroke-width: 1px; > } > .empty12{ > fill: none; > stroke: #9966FF; > stroke-width: 1px; > } 891a975 > [% IF config.show_data_lines %] 898a983 > [% END %] 903a989,993 > [% IF dataset.symbol_fill == 1 %] > [% symbol_fill = 'fill' %] > [% ELSE %] > [% symbol_fill = 'empty' %] > [% END %] 905c995,1011 < <circle cx="[% (dw * xcount) + x %]" cy="[% base_line - ((dataset.data.$field - min_scale_value) * divider) %]" r="2.5" class="fill[% line %]"/> --- > [% translate_x = ((dw * xcount) + x) %] > [% translate_y = (base_line - ((dataset.data.$field - min_scale_value) * divider)) %] > [% transform_text = "transform=\"translate($translate_x,$translate_y)\"" %] > [% class_text = "class=\"" _ symbol_fill _ line _ "\""%] > [% SWITCH dataset.symbol_type %] > [% CASE 'circle' %] > <circle cx="0" cy="0" r="2.5" [% transform_text %] [% class_text %]/> > [% CASE 'triangle' %] > <polygon points="-2.6,2.25 0,-2.25 2.6,2.25" [% transform_text %] [% class_text %]/> > [% CASE 'square' %] > <polygon points="-2.5,-2.5 -2.5,2.5 2.5,2.5 2.5,-2.5" [% transform_text %] [% class_text %]/> > [% CASE 'diamond' %] > <polygon points="-2.5,0 0,-2.5 2.5,0 0,2.5" [% transform_text %] [% class_text %]/> > [% CASE 'plus' %] > <line x1="0" y1="-2.5" x2="0" y2="2.5" [% transform_text %] [% class_text %]/> > <line x1="-2.5" y1="0" x2="2.5" y2="0" [% transform_text %] [% class_text %]/> > [% END %]
04_line.t explicitly added the number of tests. Graph.patch same Line.patch used "diff -u" this time. Sorry I forgot "-u" last time.
#!/usr/bin/perl -w use lib qw( ./blib/lib ../blib/lib ); # Check we can create objects and adding data works # as well as clearing data. use Test::More tests=>15; BEGIN { use_ok( 'SVG::TT::Graph::Line' ); } my @fields = qw(Jan Feb Mar); my @data_sales_02 = qw(12 45 21); my @data_sales_03 = qw(24 55 61); # Might as well test them all, even though they're # the same under the hood! - just in case my @types = qw(Line Bar BarHorizontal Pie BarLine); my $module = "SVG::TT::Graph::Line"; eval { my $gr = $module->new({ }); }; ok($@,'Croak ok as no fields supplied'); my $graph = $module->new({ 'fields' => \@fields, }); isa_ok($graph,$module); # Check we croak if no data eval { $graph->burn(); }; ok($@, 'Burn method croaked as expected - no data has been set'); $graph->add_data({ 'data' => \@data_sales_02, }); is(scalar(@{$graph->{data}}),1,'Data set 1 added'); is($graph->{data}->[0]->{title}, undef,'Data set 1 - title default is undefined ok'); is($graph->{data}->[0]->{data}->{Feb}, 45,'Data set 1 - data set ok'); is($graph->{data}->[0]->{symbol_type}, 'circle','Data set 1 - symbol type ok'); is($graph->{data}->[0]->{symbol_fill}, 1,'Data set 1 - symbol fill ok'); $graph->add_data({ 'data' => \@data_sales_03, 'title' => 'Sales 2003', 'symbol_type'=>'triangle', 'symbol_fill'=>0, }); is(scalar(@{$graph->{data}}),2,'Data set 2 added'); is($graph->{data}->[1]->{title}, 'Sales 2003','Data set 2 - title set ok'); is($graph->{data}->[1]->{data}->{Mar}, 61,'Data set 2 - data set ok'); is($graph->{data}->[1]->{symbol_type}, 'triangle','Data set 2 - symbol type ok'); is($graph->{data}->[1]->{symbol_fill}, 0,'Data set 2 - symbol fill ok'); $graph->clear_data(); is(scalar(@{$graph->{data}}),0,'Data cleared ok');
--- Graph.pm.orig 2009-02-16 11:01:37.000000000 -0600 +++ Graph.pm 2009-07-22 15:28:02.000000000 -0500 @@ -6,7 +6,7 @@ use Template; use POSIX; -$VERSION = '0.12'; +$VERSION = '0.120_001'; # set up TT object my %config = ( @@ -156,6 +156,18 @@ 'data' => \%new_data, ); $store{'title'} = $conf->{'title'} if defined $conf->{'title'}; + if($self->isa("SVG::TT::Graph::Line")){ + if (defined $conf->{'symbol_type'}){ + $store{'symbol_type'} = $conf->{'symbol_type'}; + }else{ + $store{'symbol_type'} = 'circle'; + } + if (defined $conf->{'symbol_fill'}){ + $store{'symbol_fill'} = $conf->{'symbol_fill'}; + }else{ + $store{'symbol_fill'} = 1; + } + } push (@{$self->{'data'}},\%store); return 1; }
--- Line.pm.orig 2008-04-28 15:04:26.000000000 -0500 +++ Line.pm 2009-07-22 15:10:33.000000000 -0500 @@ -64,6 +64,7 @@ # Optional - defaults shown 'height' => '500', 'width' => '300', + 'show_data_lines' => 1, 'show_data_points' => 1, 'show_data_values' => 1, 'stacked' => 0, @@ -107,11 +108,31 @@ $graph->add_data({ 'data' => \@data_sales_02, 'title' => 'Sales 2002', + 'symbol_type' => 'circle', + 'symbol_fill' => 1, }); This method allows you to add data to the graph object. It can be called several times to add more data sets in. +Possible symbol types: 'circle' (default), 'diamond', +'triangle', 'plus', 'square'. + +If 'symbol_fill' is set to 1 (default), the symbols for +this data set will be filled. If it is set to 0, the +symbols will be outlines only. + +To show the symbols without the data lines, be sure to +set 'show_data_lines' to '0' when creating the Line +object: + +SVG::TT::Graph::Line->new( + 'height' => '500', + 'width' => '300', + 'fields' => \@fields, + 'show_data_lines' => 0, +); + =head2 clear_data() my $graph->clear_data(); @@ -328,6 +349,7 @@ 'width' => '500', 'height' => '300', 'style_sheet' => '', + 'show_data_lines' => 1, 'show_data_points' => 1, 'show_data_values' => 1, 'stacked' => 0, @@ -588,6 +610,67 @@ stroke: none; stroke-width: 1px; } +/* empty symbol styles */ +.empty1{ + fill: none; + stroke: #ff0000; + stroke-width: 1px; +} +.empty2{ + fill: none; + stroke: #0000ff; + stroke-width: 1px; +} +.empty3{ + fill: none; + stroke: #00ff00; + stroke-width: 1px; +} +.empty4{ + fill: none; + stroke: #ffcc00; + stroke-width: 1px; +} +.empty5{ + fill: none; + stroke: #00ccff; + stroke-width: 1px; +} +.empty6{ + fill: none; + stroke: #ff00ff; + stroke-width: 1px; +} +.empty7{ + fill: none; + stroke: #00ffff; + stroke-width: 1px; +} +.empty8{ + fill: none; + stroke: #ffff00; + stroke-width: 1px; +} +.empty9{ + fill: none; + stroke: #cc6666; + stroke-width: 1px; +} +.empty10{ + fill: none; + stroke: #663399; + stroke-width: 1px; +} +.empty11{ + fill: none; + stroke: #339900; + stroke-width: 1px; +} +.empty12{ + fill: none; + stroke: #9966FF; + stroke-width: 1px; +} .keyText{ fill: #000000; text-anchor:start; @@ -889,6 +972,7 @@ [% END %] <!--- create line --> + [% IF config.show_data_lines %] <path d="M [% xcount = 0 %] [% FOREACH field = config.fields %] @@ -896,13 +980,35 @@ [% (dw * xcount) + x %] [% base_line - ((dataset.data.$field - min_scale_value) * divider) %] [% xcount = xcount + 1 %] [% END %]" class="line[% line %]"/> + [% END %] [% IF config.show_data_points || config.show_data_values%] [% xcount = 0 %] [% FOREACH field = config.fields %] [% IF config.show_data_points %] + [% IF dataset.symbol_fill == 1 %] + [% symbol_fill = 'fill' %] + [% ELSE %] + [% symbol_fill = 'empty' %] + [% END %] <!-- datapoint shown --> - <circle cx="[% (dw * xcount) + x %]" cy="[% base_line - ((dataset.data.$field - min_scale_value) * divider) %]" r="2.5" class="fill[% line %]"/> + [% translate_x = ((dw * xcount) + x) %] + [% translate_y = (base_line - ((dataset.data.$field - min_scale_value) * divider)) %] + [% transform_text = "transform=\"translate($translate_x,$translate_y)\"" %] + [% class_text = "class=\"" _ symbol_fill _ line _ "\""%] + [% SWITCH dataset.symbol_type %] + [% CASE 'circle' %] + <circle cx="0" cy="0" r="2.5" [% transform_text %] [% class_text %]/> + [% CASE 'triangle' %] + <polygon points="-2.6,2.25 0,-2.25 2.6,2.25" [% transform_text %] [% class_text %]/> + [% CASE 'square' %] + <polygon points="-2.5,-2.5 -2.5,2.5 2.5,2.5 2.5,-2.5" [% transform_text %] [% class_text %]/> + [% CASE 'diamond' %] + <polygon points="-2.5,0 0,-2.5 2.5,0 0,2.5" [% transform_text %] [% class_text %]/> + [% CASE 'plus' %] + <line x1="0" y1="-2.5" x2="0" y2="2.5" [% transform_text %] [% class_text %]/> + <line x1="-2.5" y1="0" x2="2.5" y2="0" [% transform_text %] [% class_text %]/> + [% END %] [% END %] [% IF config.show_data_values %]
Cleaned up 04_line.t to reduce redundancy with 02_basic.t.
#!/usr/bin/perl -w use lib qw( ./blib/lib ../blib/lib ); use Test::More tests=>7; BEGIN { use_ok( 'SVG::TT::Graph::Line' ); } my @fields = qw(Jan Feb Mar); my @data_sales_02 = qw(12 45 21); my @data_sales_03 = qw(24 55 61); my $module = "SVG::TT::Graph::Line"; my $graph = $module->new({ 'fields' => \@fields, }); isa_ok($graph,$module); $graph->add_data({ 'data' => \@data_sales_02, }); is($graph->{data}->[0]->{title}, undef,'Data set 1 - title default is undefined ok'); is($graph->{data}->[0]->{symbol_type}, 'circle','Data set 1 - symbol type (default) ok'); is($graph->{data}->[0]->{symbol_fill}, 1,'Data set 1 - symbol fill (default) ok'); $graph->add_data({ 'data' => \@data_sales_03, 'title' => 'Sales 2003', 'symbol_type'=>'triangle', 'symbol_fill'=>0, }); is($graph->{data}->[1]->{symbol_type}, 'triangle','Data set 2 - symbol type ok'); is($graph->{data}->[1]->{symbol_fill}, 0,'Data set 2 - symbol fill ok');
If you would like svn access and are interested in helping maintain SVG::TT::Graph please let me know. Thanks Leo
Yes, I am interested. Thanks, Christopher Bottoms University of Missouri On Thu Jul 23 07:10:34 2009, LLAP wrote: Show quoted text
> If you would like svn access and are interested in helping maintain > SVG::TT::Graph please let me know. > > Thanks > > Leo
Please send me your google email address as your CPAN email does not seem to work/be public. Email me llap@cuckoo.org Cheers Leo On Mon Jul 27 13:07:35 2009, MOLECULES wrote: Show quoted text
> Yes, I am interested. > Thanks, > Christopher Bottoms > University of Missouri > > On Thu Jul 23 07:10:34 2009, LLAP wrote:
> > If you would like svn access and are interested in helping maintain > > SVG::TT::Graph please let me know. > > > > Thanks > > > > Leo
>