SVG::Grid - Address SVG images using cells of $n1 x $n2 pixels
SVG::Grid
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 ( 'font-size' => 20, 'font-weight' => '400', text => 'Front Garden', x => $svg -> x_offset, # Pixel co-ord. y => $svg -> y_offset / 2, # Pixel co-ord. ); $svg -> text ( 'font-size' => 14, 'font-weight' => '400', text => '--> N', x => $svg -> width - 2 * $svg -> cell_width, # Pixel co-ord. y => $svg -> y_offset / 2, # Pixel co-ord. ); $svg -> grid(stroke => 'blue'); $svg -> image_link ( href => 'http://savage.net.au/Flowers/Chorizema.cordatum.html', image => 'http://savage.net.au/Flowers/images/Chorizema.cordatum.0.jpg', show => 'new', title => 'MouseOver® an image', x => 1, # Cell co-ord. y => 2, # Cell co-ord. ); $svg -> rectangle_link ( href => 'http://savage.net.au/Flowers/Alyogyne.huegelii.html', show => 'new', title => 'MouseOver™ a rectangle', x => 2, # Cell co-ord. y => 3, # Cell co-ord. ); $svg -> text_link ( href => 'http://savage.net.au/Flowers/Aquilegia.McKana.html', stroke => 'rgb(255, 0, 0)', show => 'new', text => '3,1', title => 'MouseOvér some text', x => 3, # Cell co-ord. y => 1, # Cell co-ord. ); $svg -> write(output_file_name => 'data/synopsis.svg');
Output: http://savage.net.au/assets/images/articles/synopsis.svg
See also scripts/*.pl.
SVG::Grid allows you to mostly use cell co-ordinates (like a spreadsheet) to place items on an SVG image. These co-ordinates are in the form (x, y) = (integer, integer), where x and y refer to the position of a cell within a row and a column. You define these rows and columns when you call the "new(%options)" method. Cell co-ordinates are numbered 1 .. N.
Here, mostly means all method calls except adding text via the "text(%options)]" method. With text(), you use pixels locations so that the text can be placed anywhere. Pixel co-ordinates are numbered 0 .. N.
text()
Note: Objects of type SVG::Grid are not daughters of SVG. They are stand-alone objects.
This module is available as a Unix-style distro (*.tgz).
See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing distros.
Install SVG::Grid as you would any Perl module:
Perl
Run:
cpanm SVG::Grid
or run:
sudo cpan SVG::Grid
And then:
perl Makefile.PL make (or dmake or nmake) make test make install
new() is called as my($svg) = SVG::Grid -> new(k1 => v1, k2 => v2, ...).
new()
my($svg) = SVG::Grid -> new(k1 => v1, k2 => v2, ...)
It returns a new object of type SVG::Grid.
Key-value pairs accepted in the parameter list (see corresponding methods for details [e.g. "text(%options)"]:
The height of each cell, in pixels.
Default: 40.
The width of each cell, in pixels.
The set of default colors, so you don't have to provide a color parameter to various methods.
color
It also means you can refer to colors by their names, rather than the awkward 'rgb($R, $G, $B)' structures that the SVG module uses.
'rgb($R, $G, $B)'
Default:
$self -> colors ({ black => 'rgb( 0, 0, 0)', blue => 'rgb( 0, 0, 255)', dimgray => 'rgb(105, 105, 105)', indianred => 'rgb(205, 92, 92)', red => 'rgb(255, 0, 0)', silver => 'rgb(192, 192, 192)', white => 'rgb(255, 255, 255)', });
The name of the SVG file to write, if the "write(%options)" method is called.
Default: ''.
The default style to use, so you don't have to provide a style parameter to various methods.
style
$self -> style ({ 'fill-opacity' => 0, font => 'Arial', 'font-size' => 14, 'font-weight' => 'normal', stroke => 'rgb(0, 0, 0)', 'stroke-width' => 1, });
The number of cells aross the SVG.
Each cell will be cell_width pixels wide.
cell_width
Default: 30.
The distance between the left and right sides of the SVG and the co-ordinate grid, in pixels.
The number of cells down the SVG.
Each cell will be cell_height pixels high.
cell_height
The distance between the top and bottom sides of the SVG and the co-ordinate grid, in pixels.
Gets the height of each cell, in pixels.
cell_height is a parameter to "new()".
Gets the width of each cell, in pixels.
cell_width is a parameter to "new()".
Here, [] indicates an optional parameter.
Gets or sets the default hashref of colors.
colors is a parameter to "new()".
colors
Draws the frame.
This method uses these keys in %options:
%options
Default: 0.
Default: 'rgb(105, 105, 105)' aka dimgray.
Default: 1.
Draws a grid onto the SVG.
Default: 14.
Default: 1;
Default: 'rgb(0, 0, 255)' aka blue.
Returns the calculated height, in pixels, of the SVG.
Places an image onto the SVG and makes it clickable.
This is the link you are taken to if you click in the specified image. Sample:
image
href => 'http://savage.net.au/Flowers/Chorizema.cordatum.html'
This is the image which appears on the SVG, and which is made clickable. Sample:
image => 'http://savage.net.au/Flowers/images/Chorizema.cordatum.0.jpg'
For $string you must choose one of the SVG specification values: embed|new|none|other|replace.
The SVG specification for Behavior Attributes.
Note: The parameter passed to SVG is actually called -show.
-show
Default: 'new'
'new' is similar to the effect achieved by the following HTML fragment:
<A HREF="http://www.example.org" target="_blank">...</A>
This string, if not empty, is passed to SVG as the value of the -title parameter.
-title
The effect is to activate a tooltip when you MouseOver the image.
This is the cell # across the SVG.
Cell co-ordinates are numbered 1 .. N.
This is the cell # down the SVG.
Gets or sets the name of the output file.
output_file_name is a parameter to "new()".
output_file_name
Places a rectangle (which fills a cell) onto the SVG and makes it clickable.
Default: 'rgb(205, 92, 92)' aka indianred.
Default: 0.5.
This is the link you are taken to if you click in the rectangle specified by (x, y). Sample:
href => 'http://savage.net.au/Flowers/Alyogyne.huegelii.html'
The effect is to activate a tooltip when you MouseOver the rectangle.
Gets or sets the default hashref of styles.
style is a parameter to "new()".
Returns the internal SVG object.
Places a text string onto the SVG.
Warning: This method uses (x, y) in pixels.
Default: 'normal'.
This is the pixel # across the SVG.
Pixel co-ordinates are numbered 0 .. N.
This is the pixel # down the SVG.
Places a text string onto the SVG and makes it clickable.
The clickable area is just the text. The remainer of the cell does not respond to the click.
This is the link you are taken to if you click in the text in the cell specified by (x, y). Sample:
text
href => 'http://savage.net.au/Flowers/Aquilegia.McKana.html'
This is the text which will be written into the cell and made clickable.
Returns the calculated width, in pixels, of the SVG.
Writes the SVG to the file name passed to "new(%options)" or passed to write(). The latter value has priority.
write()
Gets the count of cells horizontally.
x_cell_count is a parameter to "new()".
x_cell_count
Gets the horizontal gap between the edges of the SVG and the grid.
x_offset is a parameter to "new()".
x_offset
Gets the count of cells vertically.
y_cell_count is a parameter to "new()".
y_cell_count
Gets the vertical gap between the edges of the SVG and the grid.
y_offset is a parameter to "new()".
y_offset
Yes. The "write(%options)" method uses an encoding of UTF-8 on the output file handle.
Note: To use Unicode, you must include 'use utf8;' in your programs. See scripts/synopsis.pl.
Yes. Just search this document for 'MouseOver'.
No. This means there is no grouping done by default. Nevertheless, you can call "svg()" to get the internal SVG object, and use 'g' yourself at any time.
See https://www.w3.org/TR/SVG11/struct.html#Groups for details of the 'g' element.
By using method parameters to generate a hopefully-unique id. This line copied from the "image_link(%options)" method shows the general technique I've used:
id => "image_$options{x}_$options{y}", # Try to make it unique.
fill
stroke
I don't think so, but I have had some odd results. Ultimately, you need to read the docs for the SVG module to see what it expects.
Not in V 1.00. However, it is on the TODO list.
GD
Imager
Image::Magick
Image::Magick::Chart
Image::Magick::PolyText
Image::Magick::Tiler
SVG
https://www.w3.org/Graphics/SVG/
The file Changes was converted into Changelog.ini by Module::Metadata::Changes.
Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
https://github.com/ronsavage/SVG-Grid
Email the author, or log a bug on RT:
https://rt.cpan.org/Public/Dist/Display.html?Name=SVG::Grid.
SVG::Grid was written by Ron Savage <ron@savage.net.au> in 2016.
My homepage: http://savage.net.au/
Australian copyright (c) 2016, Ron Savage.
All Programs of mine are 'OSI Certified Open Source Software'; you can redistribute them and/or modify them under the terms of The Perl License, a copy of which is available at: http://dev.perl.org/licenses/
To install SVG::Grid, copy and paste the appropriate command in to your terminal.
cpanm
CPAN shell
perl -MCPAN -e shell install SVG::Grid
For more information on module installation, please visit the detailed CPAN module installation guide.