Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

GoalMeter

Summary: Create thermometers or columns showing goals and current values
Version: 2007-04-25
Prerequisites: pmwiki 2, GD library
Status: stable
Maintainer:
Categories: Images UpdateMe
Download: goalmeter.phpΔ

Questions answered by this recipe

I like to add a fundraising thermometer on a page.
I like to display bar graph images.

This section is optional; use it to indicate the types of questions (if any) this recipe is intended to answer.

Description

Show a thermometer or column with goal and current values. Install goalmeter.phpΔ the usual way by copying file to cookbook/ direcory and adding to a local configuration file:

include_once("$FarmD/cookbook/goalmeter.php");

Then use in a page the markup (:goalmeter current=... goal=... :) to display a standard thermometer image. The values to use for current= and goal= can be a combination of a number and other characters, for instance £ 3000, $10.000, 500 units.

To customise the image you can add lots of parameters. You can have multiple goalmeters on one page, by adding a unique id=... parameter to each. Set height=... for custom height. Image width will be calculated automatically, but you can also set it with width=.... You can set fontsize, bar thickness and colors for filled and empty space and bulb. The background color is transparent by default, and other colors can have a alpha transparency number added. You can turn the thermometer bulb off with nobulb=1, which results in a column display. Text and scale colors can be changed. Standard padding can be changed.

  Default settings:
    'id'      => '0',    # img id 
    'current' => '0',    # current value
    'goal'    => '100',  # goal value
    'max'     => '',     # max value as alternative to goal, goal will not be displayed
    'height'  => '360',  # outer height
    'width'   => '',     # outer width, default automatic calculation
    'bar'     => '3',    # bar thickness 1 ... 5
    'font'    => '4',    # font size 1 ... 5
    'bg'      => 'ffffffff',# background color (transparent)
    'fill'    => 'FF0000',  # main fill and border color
    'topfill' => 'FFFFCC',  # top fill color
    'bulbfill'=> '',        # bulb fill color (defaults to main fill color)
    'scale'   => '666666',  # scale color
    'value'   => '000000',  # value text color
    'percent' => 'FFFFFF',  # percent text color
    'border'  => '',    # outer border color     
    'nobulb'  => '',    # set to 1 for column only display
    'noscale' => '',    # set to 1 for no scale display
    'padding' => '8',   # img padding
    'rpad'    => '40',  # right hand extra padding 

The resulting image(s) are stored in a cache directory with unique filenames according to their id=... settings, as png images. The markup directive only constructs images fresh if the page is updated. Make sure to force a page refresh after changing any parameters in the markup, to force the new image file to be loaded.

You can see a demo here: http://softflow.co.uk/design/Test/GoalMeter

Notes

The server needs to have the php GD library installed, which supports image functions. See www.php.net/gd

Release Notes

  • 2007-04-25: Added $pagename to filename of image files, to support goalmeters on different pages.
  • 2007-04-24: Added noscale=1 parameter to suppress display of scale. Added max= parameter as alternative to goal= , max= will set goal value, but not display this value.
  • 2006-11-10: Initial release. Script based on thermometer script by Wendell Brown, Thank you!

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

Comments

Simon Brown 16/Nov/06 I added this recipe but I get an error message; Fatal error: Call to undefined function: imagefontwidth() in c:\inetpub\wwwroot\pmwiki\cookbook\goalmeter.php on line 66

When I try to preview or save. I am using Wiki 2.2.0.beta2 with the triad skin Any ideas?

I think your server does not have the GD graphic library installed. Probably not part of your local default php installation. See www.php.net/gd. ~HansB

See Also

  • PHPImages The script which inspired me to write this recipe.
  • Progress Bar - A recipe for displaying simple horizontal percentage indicator. Doesn't require graphics library - uses only CSS.

Contributors

Edit - History - Print - Recent Changes - Search
Page last modified on April 25, 2007, at 01:52 PM