PlotCalendar modules

make nice Calendars in html or Ascii



Screenshots and a cgi-bin example

Download here version 1.3


TABLE OF CONTENTS

  1. Description
  2. Availability
  3. Prerequisites
  4. Installation
  5. Running Tests
  6. Demonstration scripts
  7. Bugs
  8. Copyright
  9. Author Information

1. DESCRIPTION

This is a collection of modules for generating nice-looking calendars. There are 4 related modules in this set.

The modules are :

PlotCalendar::Day
PlotCalendar::Month
PlotCalendar::DateTools
PlotCalendar::DateDesc

Day.pm generates a single day, with (for html) controls for colors, fonts, etc.

Month.pm calls Day 28-31 times to create a proper Month-type calendar. Size, day to start week with, colors, etc are all controllable.

DateTools.pm is a pure perl replacement for parts of Date::Calc because I can't compile the c-code in Date::Calc on my webhoster's system.

DateDesc.pm is a simple parser for converting date descriptions like "First Tuesday" into an actual date.

Examples :

Day.pm

my $day = PlotCalendar::Day->new($digit);
$day -> size(100,100);
$day -> color('WHITE','RED',); # foreground and background
$day -> font('14','10','8'); # font size for digits, day-name, and text
$day -> style('bi','nbu','i'); # font styles for same
$day -> cliptext('yes'); # clip long text
$day -> dayname('Groundhog Day');
$day -> nameref('<A href="http://ooga.booga.com/">
$day -> text('text string 1','text string 2','abcdefghijklmno'); # 3 lines of text
$day -> textcolor('BLUE','RED','GREEN',);
$day -> textsize('8','10','8',);
$day -> textstyle('b','u','bi',);
my $html = $day -> gethtml;
Month.pm
my $month = PlotCalendar::Month->new(01,1999);
$month -> size(700,700);
$month -> font('14','10','8');
$month -> cliptext('yes');
$month -> firstday('Sun'); # first column
$month -> fgcolor('BLACK',);
$month -> bgcolor(@bgcolor); # background per day
$month -> styles('b','bi','ui',);
$month -> htmlref(@url); # url for each day
$month -> dayname(@daynames); # names for each day
my $html = $month -> gethtml;

2. AVAILABILITY

The newest version (which should be considered a beta version) is available through my home page: http://www.ajackson.org/software/plotcalendar Feel free to try it out.

The current (non-beta) version of this module is available from your nearest CPAN site.

The two will frequently be the same.

3. PREREQUISITES

Perl 5.004_01 is where I developed this. It may work with earlier versions, but I haven't tried it. I'm not too sophisticared, so I'd be a little surprised if I used anything not in 5.003 for example.

Time::DaysInMonth
Time::JulianDay

Both these are called by DateTools.pm. I have maintained compatibility with Date::Calc, so if you wished, you could edit the
use PlotCalendar::DateTools
lines, make them
use Date::Calc
and forget about the Time:: modules and DateTools.

4. INSTALLATION

To install, just type perl Makefile.PL
make
make test
make install

For help with Makefile.PL, try
perldoc ExtUtils::MakeMaker

If you wish to install in a non-standard place, use something like

perl Makefile.PL LIB=~/lib PREFIX=~

5. RUNNING TESTS

I can't imagine the tests failing, unless you were missing some key part of perl, but hey, things happen. If it fails, email me. Try running make test TEST_VERBOSE=1 and send me the results.

6. DEMONSTRATION SCRIPTS

In the /demo directory are some scripts that show what it can do. Hope they make the documentation clearer.

To run events_calendar.pl in it's fullest mode, type :
events_calendar.pl -mon 7 -yr 1999 -reg y -spec y > events.html
and view the output in your favorite browser.

7. BUGS

None that I know of - when you find one, let me know.

If you do report it, please include :

8. COPYRIGHT

Copyright (c) 1999 Alan Jackson. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

9. AUTHOR INFORMATION

Alan Jackson
alanj@ajackson.org
http://www.ajackson/org/

Day.pm


NAME

PlotCalendar::Day - Generate ascii or html for a single day in a calendar


SYNOPSIS

Creates a Day object for plotting as ASCII, HTML, or in a Perl/Tk Canvas. Intended to be gathered together by Month.pm to create a traditional calendar.


DESCRIPTION

Measurements in pixels because - well, because. It seemed simpler when I made the decision. And it works for both Tk and HTML.

The day is laid out like this :

    ------------------------------------------
    |         |        |                     |
    | digit   | digit  | Main day name       |
    |         |        |                     |
    |         |        |                     |
    |         |        |                     |
    |---------|--------|                     | <- bgcolmain
    |                                        |
    |                                        |
    |                                        |
    | Optional text                          |
    |      .                                 |
    |                                        |
    | Optional Text                          |
    |      .                                 |
    |      .                                 |
    |      .                                 | 
    |      .                                 |
    | Optional text                          |
    |      .                                 |
    |      .                                 |
    |      .                                 |
    |      .                                 |
    ------------------------------------------
    Globals : height, width, dayfont, mainfont, optfont, fgcol,
    bgcolmain, digit
    Optionals : dayname, optext[...]
    Font sizes in HTML translate as (rounding up) :
        6->-1
        8->+0
        10->+1
        12->+2
        14->+3
Various quantities can be set globally, or over-ridden for specific cases.

This is really meant to be called by month.pm to construct a calendar, but calling it with a *really big size* is a way to ``zoom in'' on a given day


EXAMPLE

        require PlotCalendar::Day;
        my $digit=10 ; # do it for the tenth
        my $day = PlotCalendar::Day->new($digit);
        #        These are values with default settings, so these are optional
    ------------ size of whole thing in pixels, X,Y
        $day -> size(100,100);
    ------------ Global foreground and background colors
        $day -> color('BLACK','#33cc00',);
        $day -> color('WHITE','RED',);
    ------------ Font sizes for digits, dayname, and optional text
        $day -> font('14','10','8');
    ------------ styles for digits, dayname, and optional text
    ------------ b=bold, i=italic, u=underline, n=normal
        $day -> style('bi','nbu','i');
    ------------ Clip text to avoid wrapping? (yes/no)
        $day -> cliptext('yes');
        #       HTML only options
        
    ------------ is it allowed to expand vertically if there is too much text?
        $day -> htmlexpand('yes');
        #       These values are defaulted to blank
    ------------ day name
        $day -> dayname('Groundhog Day');
    ------------ if set, name is a hotlink
        $day -> nameref('<A href="http://ooga.booga.com/";>');
    ------------ if set, text string is a hotlink. Note that an array is getting
    ------------ passed. Text is passed as an array also. Each line of text is
    ------------ an array element. THis example hotlinks only the first 2 lines.
        $day -> textref('<A href="http://booga.booga.com/";>','<A href="mailto:>;');
    ------------ Text strings, passed as elemnts of an array
        $day -> text('text string 1','text string 2','abcdefghijklmno 0 1 2 3 4 5 6 7 8 9 0',);
    ------------ override default text colors and set each string individually
        $day -> textcolor('BLUE','RED','GREEN',);
    ------------ override default text sizes and set each string individually
        $day -> textsize('8','10','8',);
    ------------ override default text styles and set each string individually
        $day -> textstyle('b','u','bi',);
    ------------ wrap a reference around the entire cell
        $day->htmlref('<A href="http://this_is_a_url/";>');
    ------------ unload what I set
        my @size = $day->size;
        my @color = $day->color;
        my @font = $day->font;
        my @text = $day->text;
        my $dayname = $day->dayname;
        #       So, what do we have now?
    ------------ Create an ascii text cell
        #my $text = $day -> gettext;
    ------------ Create and return html for a cell in a table
        my $html = $day -> gethtml;
    ------------ Create and return Tk code (not implemented yet)
        #my $tk = $day -> gettk;
        print "<HTML><BODY>\n";
        print "<H1>Normal Day</H1>\n";
        print "<TABLE BORDER=1><TR>\n";
        print $html;
        print "</TR></TABLE>\n";

AUTHOR

        Alan Jackson
        March 1999
        alan@ajackson.org

Month.pm


NAME

        PlotCalendar::Month - Plot an ASCII or HTML calendar

SYNOPSIS

Creates a Month object for plotting as ASCII, HTML, or in a Perl/Tk Canvas. Calls Day.pm for the individual days within the calendar.


DESCRIPTION

Measurements in pixels because - well, because. It seemed simpler when I made the decision. And it works for both Tk and HTML.

The month is laid out like this :

           Month_name                          Year
    ---------------------------------------------------------------
    | Sun    | Mon    | Tue    | Wed   | Thu    | Fri    | Sat    |
    ---------------------------------------------------------------
    |        |        |        |       |        |        |        |
    | day    | day    |        |       |        |        |        |
    |        |        |        |       |        |        |        |
    |--------|--------|--------|-------|--------|--------|--------|
    |        |        |        |       |        |        |        |
    | day    | day    |        |       |        |        |        |
    |        |        |        |       |        |        |        |
    |--------|--------|--------|-------|--------|--------|--------|
    |        |        |        |       |        |        |        |
    | day    | day    |        |       |        |        |        |
    |        |        |        |       |        |        |        |
    |--------|--------|--------|-------|--------|--------|--------|
    |        |        |        |       |        |        |        |
    | day    | day    |        |       |        |        |        |
    |        |        |        |       |        |        |        |
    |--------|--------|--------|-------|--------|--------|--------|
    |        |        |        |       |        |        |        |
    | day    | day    |        |       |        |        |        |
    |        |        |        |       |        |        |        |
    |--------|--------|--------|-------|--------|--------|--------|
    |        |        |        |       |        |        |        |
    | day    | day    |        |       |        |        |        | optional
    |        |        |        |       |        |        |        | row
    |--------|--------|--------|-------|--------|--------|--------|
    Globals : height, width, fgcol,
    bgcolmain,
    References expect to be given the entire thing, that is
    <A HREF="http://yaddayaddayadda/";>
    or
    <A HREF="mailto:george_tirebiter@noway.nohow";>
    The software will terminate it with a </A> at the right spot.
 

EXAMPLE

        require PlotCalendar::Month;
        my $month = PlotCalendar::Month->new(01,1999); # Jan 1999
        # global values, to be applied to all cells
        ------------------------- size of whole calendar
        $month -> size(700,700); # width, height in pixels
        ------------------------- font sizes for digit, name of day, and text
        $month -> font('14','10','8');
        ------------------------- clip text if it wants to wrap?
        $month -> cliptext('yes');
        ------------------------- This can be any day you want
        $month -> firstday('Sun'); # First column is Sunday
        ------------------------- If this is not set, regular text will be used.
        ------------------------- If it is set, then in that directory should be
        ------------------------- gif files named 0.gif, 1.gif ... January.gif, ...
        $month -> artwork('/home/ajackson/public_html/cgi-bin/Calendar/Calendar_art3/');
        #       arrays of values, if not an array, apply to all cells, if an array
        #  apply to each cell, indexed by day-of-month
        The colors are the standard values used in html
        Textstyle encoding is b=bold, i=italic, u=underline, n=normal
        Fontsize = 6-14, roughly point sizes
        my @text;
        my @daynames;
        my @nameref;
        my @bgcolor;
        my @colors = ('WHITE','#33cc00','#FF99FF','#FF7070','#FFB0B0',);
        my (@textcol,@textsize,@textstyle,@textref);
        my @style = ('i','u','b',);
        my @url;
        ----------- build some random color and text fields as a demo
        for (my $i=1;$i<=31;$i++) {
                $daynames[$i] = "Day number $i";
                $nameref[$i] = "<A HREF=\"http://www.$i.ca\">";
                $bgcolor[$i] = $colors[$i%5];
                @{$text[$i]} = ("Text 1 for $i","Second $i text","$i bit of text",);
                @{$textref[$i]} = ("<A HREF=\"http://www.$i.com/\">","Second $i text","<A HREF=\"http://www.$i.net/\">",);
                @{$textcol[$i]} = ($colors[($i+1)%5],$colors[($i+2)%5],$colors[($i+3)%5]);
                @{$textsize[$i]} = ("8","10","8",);
                @{$textstyle[$i]} = @style;
                @style = reverse(@style);
                $url[$i] = '<A href="http://some.org/name_number_' . $i . '">';
        }
        ------------------------- Set global values
        $month -> fgcolor('BLACK',); #  Global foreground color
        $month -> bgcolor(@bgcolor); # Background color per day
        $month -> styles('b','bi','ui',); # Global text styles
        #       Comments
        my @prefs = ('before','after','after');
        my @comments = (['Comment one'],["Comment two","and so on"],['Comment three']);
        my @comcol = qw(b g b);
        my @comstyle = qw(n b bi);
        my @comsize = qw(8 10 14);
        ------------------------- Comments get stuck into an otherwise empty cell
        $month->comments(\@prefs,\@comments,\@comcol,\@comstyle,\@comsize);
        ------------------------- Wrap a hotlink around the whole day, for each day
        $month -> htmlref(@url);
        ------------------------- set the names for every day
        $month -> dayname(@daynames);
        ------------------------- wrap the name in a hotlink
        $month -> nameref(@nameref);
        ------------------------- set the text and it's properties for each day
        $month -> text(@text);
        $month -> textcolor(@textcol);
        $month -> textsize(@textsize);
        $month -> textstyle(@textstyle);
        $month -> textref(@textref);
        #       global HTML only options
        ----------------- allow days to expand vertically to accomodate text
        
        $month -> htmlexpand('yes');
        #       grab an ascii calendar and print it
        
        my $text = $month -> getascii;
        print $text;
        ------------------- get the html calendar
        my $html = $month -> gethtml;
        print "<HTML><BODY>\n";
        print $html;

SEE ALSO

        Also look at Day.pm

DEPENDENCIES

        PlotCalendar::DateTools
This is a pure perl replacement for Date::Calc. I needed it because Date::Calc contains C code which my web hosting service did not have available for CGI-BIN stuff.


AUTHOR

        Alan Jackson
        March 1999
        alan@ajackson.org

DateDesc.pm


NAME

PlotCalendar::DateDesc - Perl extension for interpreting a file of periodic (like weekly) events and assigning actual dates to them. Used to feed the calendar plotting software.


SYNOPSIS

  require PlotCalendar::DateDesc;
  my ($month, $year) = (3,1999);
    # ----    set the month and year
  my $trans = PlotCalendar::DateDesc->new($month, $year);
    # ----    parse a description and return the day of the month
    my $day = 'first monday and third monday';
   print "$day : ",join(',',@{$trans->getdom($day)}),"\n";
   $day = 'last monday and third monday';
   print "$day : ",join(',',@{$trans->getdom($day)}),"\n";
   $day = 'last fri and third Monday';
   print "$day : ",join(',',@{$trans->getdom($day)}),"\n";
    # ----    parse a description and return the date as mm/dd/yyyy
   $day = 'last fri and third Monday';
    print "$day dates: ", join(',',@{$trans->getdates($day)}),"\n";
    What gets returned by both routines is a pointer to an array of answers

DESCRIPTION

    input descriptions may be one of :
    a day of the week (monday, tuesday, etc)
    a qualified day of the week (first monday, second tuesday, last sunday)
    compound statements are allowed : mon and wed, first mon and third mon
    Qualifiers are : first, second, third, fourth, fifth, last
    Compounds are only formed with 'and' and are not associative

AUTHOR

    Alan Jackson
    March 1999
    alan@ajackson.org

SEE ALSO

PlotCalendar::Month PlotCalendar::Day


DateTools.pm


NAME

PlotCalendar::DateTools - This is an all perl replacement for parts of Date::Calc. I'd love to use it, but I ran into trouble installing the compiled C onto my hosting service account, since I can't do a compile over there (it'd cost $$) So I have reproduced those functions I needed in perl. Oh well.


SYNOPSIS

  require PlotCalendar::DateTools;
  my ($day, $month, $year) = (5,3,1999);
  my $dayname = 'Tuesday';
    # ----    initialize tool
      my $dow = Day_of_Year($yr,$mon,$day);
    my $numdays = Days_in_Month($yr,$mon);
    my $dow = Decode_Day_of_Week($dayname);
    my $dowfirst = Day_of_Week($yr,$mon,$day);
    my ($nyr, $nmon, $nday) = Add_Delta_Days($yr,$mon,$day, $numdays);
    my $dayname = Day_of_Week_to_Text($dow)
    my $month = Month_to_Text($mon);
    my $doy = Day_of_Year($year,$mon,$day);

DESCRIPTION

    A perl-only clone of a subset of Date::Calc

AUTHOR

    Alan Jackson
    April 1999
    alan@ajackson.org

REQUIREMENTS

    Requires modules : 
            Exporter
            Carp
            Time::DaysInMonth
            Time::JulianDay

SEE ALSO

PlotCalendar::Month PlotCalendar::Day
 

I may be reached at alan@ajackson.org or