<?php if (!defined('PmWiki')) exit();

 $RecipeInfo['gchart']['Version'] = '2008-01-11';

Markup('gchart',
       'directives',
       '/\\(:gchart(\\s+.*?)?:\\)/ei',
       'Keep(gchart("$1"))');

SDV($gchart_atypes, array("lc","lxy","bhs","bvs","bhg","bvg","p","p3","v","s"));
SDV($HTMLStylesFmt['gchart'], ".gchart_warning {font-weight: bold;} .gchart_warning span {color: red}");

function gchart($unparsed_args){

    global $gchart_atypes, $gchart_datasetpattern;
    $error = '';
    $out = '';
    $args = ParseArgs($unparsed_args);

    #check args

    #size (300000 pixel maximum)
    if ($args['xsize']*$args['ysize']>300000){
        $error .= '<div class="gchart_warning"><span>Warning:</span>The specified size (product of x and y) exceeds the maximum of 300 000 pixel.<div>';
    }
    #check if selected type is available
    if (!in_array($args['type'],$gchart_atypes)){
        $error .= '<div class="gchart_warning"><span>Warning:</span>The specified type is not available. See the <a href="http://code.google.com/apis/chart/#chart_type">documentation</a> for alternatives.<div>';
    }
    if (strlen($error)>0){
        return $error;
    }
    $out .= '<img src="http://chart.apis.google.com/chart?';
    $out .= 'chs='.$args['xsize'].'x'.$args['ysize'];
    $out .= '&amp;';
    $out .= 'chd=s:'.$args['data'];
    $out .= '&amp;';
    $out .= 'cht='.$args['type'];
    $out .= '" />';
    return $out;
}

?>