SVG-Grid
view release on metacpan or search on metacpan
lib/SVG/Grid.pm view on Meta::CPAN
print sprintf("x_cell_count: %d. cell_width: %d. x_offset: %d. width: %d. \n",
$self -> x_cell_count, $self -> cell_width, $self -> x_offset, $self -> width);
print sprintf("y_cell_count: %d. cell_height: %d. y_offset: %d. height: %d. \n",
$self -> y_cell_count, $self -> cell_height, $self -> y_offset, $self -> height);
} # End of report.
# ----------------------------------------------
sub rectangle_link
{
my($self, %options) = @_;
my($defaults) = $self -> _get_defaults(%options);
my(%anchor_options) =
(
-href => $options{href},
id => "anchor_$options{x}_$options{y}", # Try to make it unique.
-show => $options{show} || 'new',
);
$anchor_options{-title} = $options{title} if ($options{title} && (length($options{title}) > 0) );
my($rectangle_id) = "rectangle_$options{x}_$options{y}"; # Try to make it unique.
$self -> svg -> anchor(%anchor_options) -> rectangle
(
fill => $$defaults{fill},
'fill-opacity' => $$defaults{fill_opacity} || 0.5, # We use 0.5 since the default is 0.
id => $rectangle_id,
stroke => $$defaults{stroke},
'stroke-width' => $$defaults{stroke_width},
width => $self -> cell_width,
height => $self -> cell_height,
x => $self -> x_offset + $self -> cell_width * $options{x},
y => $self -> y_offset + $self -> cell_height * $options{y},
);
return $rectangle_id;
} # End of rectangle_link.
# ----------------------------------------------
sub text
{
my($self, %options) = @_;
my($defaults) = $self -> _get_defaults(%options);
$self -> svg -> text
(
id => "note_$options{x}_$options{y}", # Try to make it unique.
x => $options{x},
y => $options{y},
style =>
{
%{$self -> style},
'fill-opacity' => $$defaults{fill_opacity},
'font-size' => $$defaults{font_size},
'font-weight' => $$defaults{font_weight},
stroke => $$defaults{stroke},
}
) -> cdata($options{text});
} # End of text.
# ----------------------------------------------
sub text_link
{
my($self, %options) = @_;
my($defaults) = $self -> _get_defaults(%options);
my($half_font) = int($$defaults{font_size} / 2);
my(%anchor_options) =
(
-href => $options{href},
id => "anchor_$options{x}_$options{y}", # Try to make it unique.
-show => $options{show} || 'new',
);
$anchor_options{-title} = $options{title} if ($options{title} && (length($options{title}) > 0) );
my($text_id) = "text_$options{x}_$options{y}"; # Try to make it unique.
$self -> svg -> anchor(%anchor_options) -> text
(
id => $text_id,
x => $self -> x_offset + $self -> cell_width * $options{x} + $$defaults{font_size} - $half_font,
y => $self -> y_offset + $self -> cell_height * $options{y} + $$defaults{font_size} + $half_font,
style =>
{
%{$self -> style},
'fill-opacity' => $$defaults{fill_opacity},
'font-size' => $$defaults{font_size},
'font-weight' => $$defaults{font_weight},
stroke => $$defaults{stroke},
'stroke-width' => $$defaults{stroke_width},
}
) -> cdata($options{text});
return $text_id;
} # End of text_link.
# ------------------------------------------------
sub write
{
my($self, %options) = @_;
my($file_name) = $options{output_file_name} || $self -> output_file_name;
write_text($file_name, $self -> svg -> xmlify);
} # End of write.
# ------------------------------------------------
1;
=pod
=encoding utf8
=head1 NAME
C<SVG::Grid> - Address SVG images using cells of $n1 x $n2 pixels
=head1 Synopsis
This is scripts/synopsis.pl:
#!/usr/bin/env perl
use strict;
use utf8;
use warnings;
use SVG::Grid;
# ------------
my($cell_width) = 40;
my($cell_height) = 40;
my($x_cell_count) = 3;
my($y_cell_count) = 3;
my($x_offset) = 40;
my($y_offset) = 40;
my($svg) = SVG::Grid -> new
(
cell_width => $cell_width,
cell_height => $cell_height,
x_cell_count => $x_cell_count,
y_cell_count => $y_cell_count,
x_offset => $x_offset,
y_offset => $y_offset,
);
$svg -> frame('stroke-width' => 3);
$svg -> text
( run in 0.986 second using v1.01-cache-2.11-cpan-2398b32b56e )