SVGraph

 view release on metacpan or  search on metacpan

lib/SVGraph/Core.pm  view on Meta::CPAN

		}
		$self->{'colors_used'}{$self->{'columns'}{$_}->{'ENV'}{'color'}}=1;
	}
 
	
	# color assigning to columns which have not assigned any color
	
	foreach (@{$self->{columnsA}})
	{
		next if $self->{columns}{$_}->{ENV}{color};
		reass:
		foreach my $color(@SVGraph::colors::table_C)
		{
			next if $self->{colors_used}{$color};
			$self->{colors_used}{$color}=1;
			$self->{columns}{$_}->{ENV}{color}=$color;
			last;
		}
		if (!$self->{columns}{$_}->{ENV}{color})
		{
			# color table reassing;
			delete $self->{colors_used};
			goto reass;
		}
	}
	
}





# TITLE
sub prepare_title
{
	my $self=shift;
	
	my $font_size=calc_fontsize(
		$self->{block_up},
		s_from => 10,
		s_to => 100,
		o_from => 6,
		o_to => 25
	);
	
	main::_log("title: $self->{block_up} = $font_size");
	
	$self->{SVG}->text
	(
		x=>$self->{block_left},
		y=>int(($self->{block_up}*0.33)+($font_size/2)),
        	style => {
			'font-family'	=> 'Verdana',
			'font-size'	=> $font_size.'px',
			'font-weight'=> "900",
			'fill'		=> $self->{'ENV'}{'title.color'} || "black",
#			'fill-opacity'=>(0.5+0.5*rand()),
#			'fill'=>"$colour_map[$index]",
#			'stroke'=>"#808080"
		},	
	)->cdata($self->{ENV}{title}) if $self->{ENV}{title};

	return 1;
}





sub prepare_legend
{
	my $self=shift; 
	
	return undef unless $self->{ENV}{show_legend};
 
	my $count;
	foreach (keys %{$self->{columns}}){$count++};
 
=cut
 my $block=$self->{SVG}->polyline(
	points	=>	
		($self->{ENV}{x}).",".$self->{block_up}." ".
		($self->{block_right}+10).",".$self->{block_up}." ".
		($self->{block_right}+10).",".($self->{block_up}+(20*$count))." ".
		($self->{ENV}{x}).",".($self->{block_up}+(20*$count))." ",
	'stroke-width'	=>"0.5pt" ,
	'stroke'		=>"rgb(150,150,150)",
	'fill'			=>"rgb(240,240,240)",
	'fill-opacity'	=>"0.7",
	'stroke-linecap'	=>"round",
	'stroke-linejoin'	=>"round",
 ); 
=cut

	my $count;
	my $freq=20;
 #foreach (keys %{$self->{columns}})
 #@{$self->{columnsA}} = reverse @{$self->{columnsA}};
 
 
	if ($self->{ENV}{show_legend_reverse})
	{
		@{$self->{columnsA}} = reverse @{$self->{columnsA}};
	}
 
	foreach (@{$self->{columnsA}})
	{
		my $color=$self->{columns}->{$_}{ENV}{color};
		my %colors=%{$SVGraph::colors::table{$color}};  
		$count++;
 
		my $width=(($self->{ENV}{x}-$self->{block_right})*0.07);
		#my $height=int(($self->{ENV}{x}-$self->{block_right})*0.05);
		my $height=($self->{ENV}{y}*0.03);
		my $x=($self->{block_right}+(($self->{ENV}{x}-$self->{block_right})*0.15));
 
		$self->{SVG}->rect(
			x=>int($x),
			y=>int($self->{block_up}+($count*($height*1.7)-$height)),
			rx=>"2pt",
			ry=>"2pt",
			width=>$width,
			height=>$height,
			'stroke-width'	=>"1pt" ,
			'stroke'       =>"rgb(0,0,0)",
			'fill'         =>"rgb(".$colors{N0}.")",
			'stroke-linecap'	=>"round",
			'stroke-linejoin'	=>"round",
		);
		
		
		my $font_size=calc_fontsize(
			$self->{ENV}{y},
			s_from => 100,
			s_to => 500,
			o_from => 6,
			o_to => 13
		);
		
		$self->{SVG}->text
		(
			x=>int($x+($width*1.5)),
			y=>int($self->{block_up}+($count*($height*1.7)-$height)+($font_size/2)+($height/4)),
			style =>
			{
				'text-anchor'	=>	'start',
				'font-family'	=> 'Verdana',
				'font-size'	=> $font_size.'px',
				'font-weight'	=> "600",
				'fill'		=> "black",
			},
		)->cdata($_);
	
	}
 
 
	if ($self->{ENV}{show_legend_reverse})
	{
		@{$self->{columnsA}} = reverse @{$self->{columnsA}};
	}
 
	return 1;
}







#
# adding columns to the graph
#
sub addColumn
{
	my ($self,%env)=@_; 

	return undef if $self->{columns}{$env{title}};	

	$self->{columns}{$env{title}}=new SVGraph::columns(%env);
	push @{$self->{columnsA}},$env{title};

	return ($self->{columns}{$env{title}});
}










#
# CALCULATION OF THE RANGE
#


sub CalculateMinMax
{
	my($self,$minimal,$maximal,$div_min,$div_max)=@_;
	my $log=0;
	my $scale=$maximal-$minimal;
	# my $div_min=9;
	# my $div_max=15;
	# my $minimal=0;
	# my $maximal=849;
	my $what; # min/max;
	
	print "<=$minimal $maximal ($scale)\n" if $log;
	



( run in 0.660 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )