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 %]