Beispiel #1
0
function make_plot($plot_type, $data_type, $nx, $ny)
{
    $plot = new PHPlot(1280, 1024);
    $plot->SetPrintImage(False);
    $plot->SetFailureImage(False);
    $plot->SetDataType($data_type);
    $plot->SetDataValues(make_data_array($plot_type, $data_type, $nx, $ny, 100));
    $plot->SetPlotType($plot_type);
    $plot->SetTitle("Serialize/Unserialize Tests\n{$plot_type} - {$data_type}");
    $plot->SetXTickIncrement(5);
    $plot->SetYTickIncrement(10);
    $plot->SetPlotBorderType('full');
    $plot->SetDrawXGrid(True);
    $plot->SetDrawYGrid(True);
    $plot->SetXTitle('X Axis Title');
    $plot->SetYTitle('Y Axis Title');
    # Select data labels or tick labels based on data type:
    if ($data_type == 'data-data') {
        $plot->SetXDataLabelPos('none');
        $plot->SetXTickLabelPos('plotdown');
        $plot->SetXTickPos('plotdown');
    } elseif ($data_type == 'text-data') {
        $plot->SetXDataLabelPos('plotdown');
        $plot->SetXTickLabelPos('none');
        $plot->SetXTickPos('none');
    } elseif ($data_type == 'data-data-yx') {
        $plot->SetYDataLabelPos('none');
        $plot->SetYTickLabelPos('plotleft');
        $plot->SetYTickPos('plotleft');
    } elseif ($data_type == 'text-data-yx') {
        $plot->SetYDataLabelPos('plotleft');
        $plot->SetYTickLabelPos('none');
        $plot->SetYTickPos('none');
    }
    return $plot;
}
Beispiel #2
0
        // Will suppress the label
        $max_indexes[] = $max_index;
    }
    return $max_indexes;
}
# Custom label formatting function: Return an empty string, unless this is
# the largest value in the row.
function fmt_label($value, $maxes, $row, $column)
{
    if ($maxes[$row] == $column) {
        return $value;
    }
    return "";
}
# Get the data array with 11 rows, 6 values per row:
$data = make_data_array(11, 6);
# Process the data array to find the largest Y per row:
$max_indexes = find_max_indexes($data);
# Now plot the data:
$plot = new PHPlot(800, 600);
$plot->SetImageBorderType('plain');
// For presentation in the manual
$plot->SetPlotType('linepoints');
$plot->SetDataType('data-data');
$plot->SetDataValues($data);
$plot->SetTitle('Linepoints plot with only max Y values labeled');
$plot->SetYDataLabelPos('plotin');
$plot->SetYDataLabelType('custom', 'fmt_label', $max_indexes);
$plot->SetLineStyles('solid');
$plot->SetYTickIncrement(100);
$plot->DrawGraph();
Beispiel #3
0
$title .= "\nAxis Data Labels suffix ':row[X|Y]'";
# Label formatting function for data value labels and axis data labels.
function fmtdl($label, $passthru, $row = NULL, $col = NULL)
{
    $result = $label;
    if (isset($row)) {
        $result .= ":{$row}";
        if (isset($col)) {
            $result .= ",{$col}";
        }
    }
    return "{$result}[{$passthru}]";
}
$plot = new PHPlot(800, 600);
$plot->SetDataType($data_type);
$plot->SetDataValues(make_data_array($plot_type, $data_type, $nx, $ny, $max));
$plot->SetPlotType($plot_type);
$plot->SetTitle($title);
$plot->SetXTitle('X Axis Title Here');
$plot->SetYTitle('Y Axis Title Here');
# Use the same custom formatting function for both label types:
#   Vertical plots:   X axis data labels, Y data value labels
#   Horizontal plots: X data value labels, Y axis data labels
$plot->SetXDataLabelType('custom', 'fmtdl', 'X');
$plot->SetYDataLabelType('custom', 'fmtdl', 'Y');
# Turn off ticks on independent axis, and turn on data value labels. This
# depends on the plot type and data type (horizontal or vertical):
$label_pos = $plot_type == 'stackedbars' ? 'plotstack' : 'plotin';
if ($data_type == 'text-data-yx' || $data_type == 'data-data-yx') {
    // Horizontal plot: configure X data value labels
    $plot->SetYTickPos('none');
Beispiel #4
0
function test($name, $plot_type, $data_type, $expected)
{
    global $test_verbose, $n_tests, $n_pass, $n_fail;
    $n_tests++;
    $title = "Test case {$n_tests}: {$name}";
    if ($test_verbose) {
        echo "{$title}\n";
    }
    $data = make_data_array($plot_type, $data_type);
    # See note above on error handler returning - need to check each method
    # here and stop if any returns FALSE, until the last.
    $plot = new PHPlot_noerr();
    if (!$plot->SetPlotType($plot_type) || !$plot->SetDataType($data_type) || !$plot->SetPrintImage(False) || !$plot->SetDataValues($data)) {
        $n_fail++;
        echo "Failed test case {$n_tests}: {$name} - Unexpected early error:\n" . "  {$plot->test_error_text}\n";
        return;
    }
    $plot->DrawGraph();
    # Regular expression match for error: unsupported data type for plot type.
    $errmatch = "Data type '[^']*' is not valid for '[^']*' plots";
    # Examine result - if there was an error message or not - based on
    # the expected outcome.
    $err = $plot->test_error_text;
    if ($expected) {
        # Plot type was expected to accept this data type.
        if (empty($err)) {
            $test_passed = 1;
        } else {
            $test_passed = 0;
            $details = "Plot type did not accept this data type." . " Error is:\n  {$err}";
        }
    } else {
        # Plot type was expected to NOT accept this data type.
        if (empty($err)) {
            $test_passed = 0;
            $details = "Plot type did not report an error for this data type.";
        } elseif (preg_match("/{$errmatch}/", $err)) {
            $test_passed = 1;
        } else {
            $test_passed = 0;
            $details = "Plot type reported an error, but not the expected" . " error:\n  {$err}";
        }
    }
    if ($test_passed) {
        $n_pass++;
    } else {
        $n_fail++;
        echo "Failed test case {$n_tests}: {$name}\n{$details}\n";
    }
}