Esempio n. 1
0
function test($start, $step, $anchor)
{
    static $need_header = 0;
    global $cases, $errors, $verbose;
    $plot = new PHPlot_test();
    // Minimal plot setup. Data values do not matter - only CalcTicks is used.
    $plot->SetPlotAreaWorld(NULL, $start, NULL, $start + 10 * $step);
    $plot->SetYTickIncrement($step);
    $plot->SetYTickAnchor($anchor);
    $plot->SetDataValues(array(array('', $start), array('', $start + 1)));
    $plot->SetDataType('text-data');
    $plot->SetPlotType('points');
    $plot->SetPrintImage(False);
    $plot->DrawGraph();
    // Get the actual values from CalcTicks() for Y:
    list($tick_start, $tick_end, $tick_step) = $plot->test_CalcTicks('y');
    $cases++;
    // Check results:
    $result = '';
    // Adjusted tick mark must not be to the left of the original:
    if ($tick_start < $start) {
        $result .= ' Wrong direction;';
        // Adjusted tick mark must not be more than 1 tick mark right of original:
    } elseif ($tick_start >= $start + $step) {
        $result .= ' Too far;';
    }
    // There should be an integer number of steps between start and anchor.
    // But allow for some fuzz.
    $n_tick = ($tick_start - $anchor) / $step;
    if ($n_tick > 0 && ($n_tick - (int) $n_tick) / $n_tick > 0.005) {
        $result .= ' No tick @ anchor;';
    }
    // Report results:
    if (empty($result)) {
        $status = 'OK';
    } else {
        $status = 'Error:';
        $errors++;
    }
    if ($verbose) {
        if ($need_header == 0) {
            $need_header = 20;
            echo "Start    Step     Anchor   => Adjusted  Result:\n";
            echo "-------- -------- -------- => --------  ------------\n";
        }
        printf("%8g %8g %8g => %8g  %s\n", $start, $step, $anchor, $tick_start, $status . $result);
        $need_header--;
    }
    if (!empty($result)) {
        fwrite(STDERR, "Error: start={$start} step={$step} anchor={$anchor}\n");
        fwrite(STDERR, "      Result={$tick_start}   Error={$result}\n");
    }
}