Exemple #1
0
function init_image()
{
    global $im, $xlm, $xrm, $ytm, $ybm, $iw, $ih, $graph, $cl, $iface, $colorscheme, $style;
    if ($graph == 'none') {
        return;
    }
    //
    // image object
    //
    $xlm = 70;
    $xrm = 20;
    $ytm = 35;
    $ybm = 60;
    if ($graph == 'small') {
        $iw = 300 + $xrm + $xlm;
        $ih = 100 + $ytm + $ybm;
    } else {
        $iw = 600 + $xrm + $xlm;
        $ih = 200 + $ytm + $ybm;
    }
    $im = imagecreatetruecolor($iw, $ih);
    //
    // colors
    //
    $cs = $colorscheme;
    $cl['image_background'] = allocate_color($im, $cs['image_background']);
    $cl['background'] = allocate_color($im, $cs['graph_background']);
    $cl['background_2'] = allocate_color($im, $cs['graph_background_2']);
    $cl['grid_stipple_1'] = allocate_color($im, $cs['grid_stipple_1']);
    $cl['grid_stipple_2'] = allocate_color($im, $cs['grid_stipple_2']);
    $cl['text'] = allocate_color($im, $cs['text']);
    $cl['border'] = allocate_color($im, $cs['border']);
    $cl['rx'] = allocate_color($im, $cs['rx']);
    $cl['rx_border'] = allocate_color($im, $cs['rx_border']);
    $cl['tx'] = allocate_color($im, $cs['tx']);
    $cl['tx_border'] = allocate_color($im, $cs['tx_border']);
    imagefilledrectangle($im, 0, 0, $iw, $ih, $cl['image_background']);
    imagefilledrectangle($im, $xlm, $ytm, $iw - $xrm, $ih - $ybm, $cl['background']);
    $x_step = ($iw - $xlm - $xrm) / 12;
    $depth = $x_step / 8 + 4;
    imagefilledpolygon($im, array($xlm, $ytm, $xlm, $ih - $ybm, $xlm - $depth, $ih - $ybm + $depth, $xlm - $depth, $ytm + $depth), 4, $cl['background_2']);
    imagefilledpolygon($im, array($xlm, $ih - $ybm, $xlm - $depth, $ih - $ybm + $depth, $iw - $xrm - $depth, $ih - $ybm + $depth, $iw - $xrm, $ih - $ybm), 4, $cl['background_2']);
    // draw title
    $text = T('Traffic data for') . " {$iface}";
    $bbox = imagettfbbox(10, 0, GRAPH_FONT, $text);
    $textwidth = $bbox[2] - $bbox[0];
    imagettftext($im, 10, 0, ($iw - $textwidth) / 2, $ytm / 2, $cl['text'], GRAPH_FONT, $text);
}
Exemple #2
0
// We have to do this first so we can allocate the colors using it
$im = imagecreatetruecolor($width, $height);
imagesavealpha($im, true);
// Set up the colors
// Not that if foreground is transparent and background isn't 100% transparent
// they'll blend
$background_color_spec = 'ffffffff';
$foreground_color_spec = '00000000';
if (isset($_REQUEST['b'])) {
    $background_color_spec = ltrim($_REQUEST['b'], '#');
}
if (isset($_REQUEST['f'])) {
    $foreground_color_spec = ltrim($_REQUEST['f'], '#');
}
$background_color = allocate_color($im, $background_color_spec);
$foreground_color = allocate_color($im, $foreground_color_spec);
// Calculate the font size
$size = floor($height / 1.29);
// 24;
$lineheight = $size + $size / 6;
// Calculate the padding
//FIXME: Calculate initial offset as well
switch (strlen($text)) {
    case 1:
        $padding = floor($width - $size) / 2 - 1;
        //29;
        break;
    case 2:
        $padding = floor($width - $size) / 4;
        //15;
        break;
    foreach ($domlist as $dom => $freq) {
        $index = (int) $freq;
        if (!array_key_exists($index, $c)) {
            $c[$index] = $palette[$i];
            ++$i;
        }
    }
    return $c;
}
if ($hovered) {
    $palette = array("00F", "00D", "00C", "00B", "009", "007", "005", "003", "001");
    $colors = allocate_color($hovered, $palette);
    foreach ($hovered as $dom => $freq) {
        $cdata_widget .= ' displayFreq("' . $dom . '", "' . $freq . '", "#' . $colors[(int) $freq] . '"); ' . PHP_EOL;
    }
}
if ($clicked) {
    $palette = array("F00", "D00", "C00", "B00", "900", "700", "500", "300", "100");
    $colors = allocate_color($clicked, $palette);
    foreach ($clicked as $dom => $freq) {
        $cdata_widget .= ' displayFreq("' . $dom . '", "' . $freq . '", "#' . $colors[(int) $freq] . '"); ' . PHP_EOL;
    }
}
$cdata_widget .= '
  });
  
})();
//]]>
';
// create user data script
$js_widget = $doc->createInlineScript($cdata_widget);
Exemple #4
0
function init_image()
{
    global $xlm, $xrm, $ytm, $ybm, $iw, $ih, $graph, $cl, $iface, $colorscheme, $style;
    if ($graph == 'none') {
        return;
    }
    //
    // image object
    //
    $xlm = 70;
    $xrm = 20;
    $ytm = 35;
    $ybm = 60;
    if ($graph == 'small') {
        $iw = 300 + $xrm + $xlm;
        $ih = 100 + $ytm + $ybm;
    } else {
        $iw = 600 + $xrm + $xlm;
        $ih = 200 + $ytm + $ybm;
    }
    svg_create($iw, $ih);
    //
    // colors
    //
    $cs = $colorscheme;
    $cl['image_background'] = allocate_color($cs['image_background']);
    $cl['background'] = allocate_color($cs['graph_background']);
    $cl['background_2'] = allocate_color($cs['graph_background_2']);
    $cl['grid_stipple_1'] = allocate_color($cs['grid_stipple_1']);
    $cl['grid_stipple_2'] = allocate_color($cs['grid_stipple_2']);
    $cl['text'] = allocate_color($cs['text']);
    $cl['border'] = allocate_color($cs['border']);
    $cl['rx'] = allocate_color($cs['rx']);
    $cl['rx_border'] = allocate_color($cs['rx_border']);
    $cl['tx'] = allocate_color($cs['tx']);
    $cl['tx_border'] = allocate_color($cs['tx_border']);
    svg_rect(0, 0, $iw, $ih, array('stroke' => 'none', 'stroke-width' => 0, 'fill' => $cl['image_background']['rgb']));
    svg_rect($xlm, $ytm, $iw - $xrm - $xlm, $ih - $ybm - $ytm, array('stroke' => 'none', 'stroke-width' => 0, 'fill' => $cl['background']['rgb']));
    $depth = 12;
    svg_group(array('stroke' => 'none', 'stroke-width' => 0, 'fill' => $cl['background_2']['rgb'], 'fill-opacity' => $cl['background_2']['opacity']));
    svg_poly(array($xlm, $ytm, $xlm, $ih - $ybm, $xlm - $depth, $ih - $ybm + $depth, $xlm - $depth, $ytm + $depth));
    svg_poly(array($xlm, $ih - $ybm, $xlm - $depth, $ih - $ybm + $depth, $iw - $xrm - $depth, $ih - $ybm + $depth, $iw - $xrm, $ih - $ybm));
    svg_group_end();
    // draw title
    $text = T('Traffic data for') . " {$iface}";
    svg_text($iw / 2, $ytm / 2, $text, array('stroke' => $cl['text'], 'fill' => $cl['text']['rgb'], 'stroke-width' => 0, 'font-family' => SVG_FONT, 'font-weight' => 'bold', 'text-anchor' => 'middle'));
}