Example #1
0
/**
* Draw the labels for all of the tests
* 
*/
function DrawLabels($tests, $im)
{
    global $min_font_size, $labelFont, $textColor, $forceFontSize, $bgEvenText, $bgOddText;
    // First, go through and pick a font size that will fit all of the labels
    if ($forceFontSize) {
        $font_size = $forceFontSize;
    } else {
        $maxLabelLen = 30;
        do {
            $font_size = GetLabelFontSize($tests);
            if ($font_size < $min_font_size) {
                // go through and trim the length of all the labels
                foreach ($tests as &$test) {
                    if (isset($test['labelRect']) && isset($test['label']) && strlen($test['label']) > $maxLabelLen) {
                        $test['label'] = substr($test['label'], 0, $maxLabelLen) . '...';
                    }
                }
                $maxLabelLen--;
            }
        } while ($font_size < $min_font_size && $maxLabelLen > 1);
    }
    if ($font_size > $min_font_size) {
        foreach ($tests as $index => &$test) {
            if (isset($test['labelRect']) && isset($test['label']) && strlen($test['label'])) {
                $rect = $test['labelRect'];
                $bgColor = $index % 2 ? $bgEvenText : $bgOddText;
                imagefilledrectangle($im, $rect['x'], $rect['y'], $rect['x'] + $rect['width'], $rect['y'] + $rect['height'], $bgColor);
                $pos = CenterText($im, $rect['x'], $rect['y'], $rect['width'], $rect['height'], $font_size, $test['label'], $labelFont, null, $test['labelRect']['align']);
                if (isset($pos)) {
                    imagettftext($im, $font_size, 0, $pos['x'], $pos['y'], $textColor, $labelFont, $test['label']);
                }
            }
        }
    }
}
Example #2
0
/**
* Draw the labels for all of the tests
* 
*/
function DrawLabels($tests, $im)
{
    global $min_font_size, $labelFont, $textColor;
    // First, go through and pick a font size that will fit all of the labels
    $maxLabelLen = 30;
    do {
        $font_size = GetLabelFontSize($tests);
        if ($font_size < $min_font_size) {
            // go through and trim the length of all the labels
            foreach ($tests as &$test) {
                if (isset($test['labelRect']) && isset($test['label']) && strlen($test['label']) > $maxLabelLen) {
                    $test['label'] = substr($test['label'], 0, $maxLabelLen) . '...';
                }
            }
            $maxLabelLen--;
        }
    } while ($font_size < $min_font_size && $maxLabelLen > 1);
    if ($font_size > $min_font_size) {
        foreach ($tests as &$test) {
            if (isset($test['labelRect']) && isset($test['label']) && strlen($test['label'])) {
                $rect = $test['labelRect'];
                $pos = CenterText($im, $rect['x'], $rect['y'], $rect['width'], $rect['height'], $font_size, $test['label'], $labelFont);
                if (isset($pos)) {
                    imagettftext($im, $font_size, 0, $pos['x'], $pos['y'], $textColor, $labelFont, $test['label']);
                }
            }
        }
    }
}