Menu

Part of title bold?

gt651
2011-10-23
2012-09-07
  • gt651

    gt651 - 2011-10-23

    In this application ( graphbarometer.com ), is it possible to make the
    $pressure value at the end of the title Bold?

    $title = $y . " Current " . $pressure;

    Thanks Gary

     
  • lbayuk

    lbayuk - 2011-10-24

    There isn't any way (in PHPlot, or PHP/GD for that matter) to switch fonts in
    the middle of a string. The way to do what you want in PHPlot is using a
    drawing callback to draw 2 strings, one in a normal font, and one in bold,
    lined up so they appear to be a single line of text. It isn't that hard, but
    only you can decide if it is worth it for your application. Here is a simple
    example. It does not attempt to center the text or position it relative to the
    top of the plot (taking into account the font size). These are also possible,
    but more work.

    <?php
    require_once 'phplot.php';
    define('FONT_NORMAL', 'LiberationSans-Regular.ttf'); // System dependent
    define('FONT_BOLD', 'LiberationSans-Bold.ttf'); // System dependent
    
    // Drawing callback function:
    function add_title($img, $title)
    {
        $black = imagecolorresolve($img, 0, 0, 0);
        $x = 20;
        $y = 40;
        $bbox = imagettftext($img, 12, 0, $x, $y, $black, FONT_NORMAL, $title[0]);
        $x += $bbox[2] - $bbox[0]; // Skip past width of first part
        imagettftext($img, 12, 0, $x, $y, $black, FONT_BOLD, $title[1]);
    }
    
    $data = array(array('A', 1), array('B', 2), array('C', 3));
    $p = new PHPlot(800, 600);
    $p->SetDataType('text-data');
    $p->SetDataValues($data);
    $p->SetMarginsPixels(NULL, NULL, 60); // Leave room at top for special title
    $p->SetPlotType('bars');
    $p->SetCallback('draw_all', 'add_title', array('Plain Text ', 'Bold Text'));
    $p->DrawGraph();
    
     
  • gt651

    gt651 - 2011-10-24

    OK thanks lbayuk, I'll work with it but it's probably a bit much for me.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.