SWOG is a graphics language which makes it easy to visualyze data. The key idea is that You can name every object added to the picture and later use it locations when drawing other objects. So the SWOG language is kind of object-oriented.

Prog. Language Perl, requires GD.pm module
Interfaces You can use SWOG as a Perl module SWOG.pm
or as a command-line program: perl SWOG.pl.

SWOG helps to...


Drawing pictures

The picture is described in a text file. There is one command per line. Usually command asks to draw a object but it also might change drawing settings.

Here is a small example:
new 170,120 lightgray

frect 10,10 50 70 red :rect
string (rect.p2) blue {SIMPLE} :simple
line (rect.p3) (simple.p2) :line
string (line.center) purple {example}
At first it is said how big picture have to be drawn. For that is used command
new, 170,120 defines picture's width and height in pixels and lightgray sets the background color.

Next command frect draws a rectangle to point 10,10 whose width is 50 and height 70 pixels. The drawn object is names as rect.

Command string writes SIMPLE whose upper left corner is same as the latter rectangle upper right corner.

You can see which named points objects have at here.

Then the command line connects certain points on the rectangle and the string.

And finally string "example" is placed to the center of the line.

Creating HTML clickmaps

One can at same time describe a picture and add links to it's objects and create clickable images.

Here is a small example:
new 120,120

frect 10,10 30 20 black /AAA/ <http://www.aaa.com>

fellipse 60,60 15 10 blue /BBB/ <http://www.bbb.com> 

fcircle 100,100 10 red /DDD/ <http://www.ddd.com>
You can click on shapes or see tooltips.
The syntax is simple - you can add to the end of each figure drawing commands /tooltip/ or <link>.

And here is a snipped from cgi code, which might be used to create the clickmap.

#SWOG code is in variable $text

print "<map name=map>";
print "</map>";

print "<img src=display.cgi usemap=#map>";

Creating server-side clickmaps

SWOG can be used to create server-side clickmaps.

The key idea is that after one has described a picture for SWOG the engine does not only know how to draw the picture, but it also knows the structure of the picture.

You can use SWOG to find out to which objects a given point belongs to.

Here is an example application from examples/cgi. At first open lights.cgi shows three colors and asks user to click on the picture and then it says which color was hit.
Code snippet to show the initial picture:
	print "Click on your favorite color:<br/>";
        print "<form action=lights.cgi method=get>";
        print "<input type=image src=display_light.cgi/>";
        print "</form>";
Script display_light.cgi is a small piece which outputs SWOG file lights.swog as PNG image:
#!/usr/bin/perl -w

use lib "../../bin";
use SWOG;

print "Content-type: image/png\n\n";
And when user comes to script lights.cgi with parameters x and y, then the script uses SWOG to detect hit object:
        print "It seams that your favorite color is <b>";
        my $hit = SWOG::detect_click($cgi->param("x"),
        if (scalar @$hit == 1) {
                #exactly one object was clicked
                my ($row) = (@$hit);
                my ($obj_name)=(@$row);
                if ($obj_name =~ /(.*)_light/){
                        print $1;
        } else {
                #user clicked to somewhere else
                print "white";
        print ".";
The exact structure of detect_click return format can be found at here.

Picture and it's definition in file lights.swog
new 70,170

#draws a filled circle and defines it's bottom point 
#params: %1 - color
defObject light
  fcircle 25,25 25 %1
  point 0,50 :bottom

object 10,10 light red :red_light
object (red_light.bottom) light green :green_light
object (green_light.bottom) light blue :blue_light