예제 #1
0
function drawtriSSS($a, $b, $c)
{
    $labels = array_slice(func_get_args(), 3);
    for ($i = 0; $i < 6; $i++) {
        if (!isset($labels[$i])) {
            $labels[$i] = '';
        }
        $len[$i] = strlen($labels[$i]);
    }
    $xp = ($a * $a + $b * $b - $c * $c) / (2 * $b);
    $yp = sqrt($a * $a - $xp * $xp);
    //$com = "setBorder(10); initPicture(".(-.1*$m*$len[3]).','.($w+.1*$m*$len[1]).','.(-.1*$m*$len[2]).','.($h+.1*$m*$len[0]).');';
    $m = max(max($b, $xp), $yp);
    $com = "setBorder(10); initPicture(-.1*{$m},1.1*{$m},-.1*{$m},1.1*{$m});";
    $com .= "path([[0,0],[{$xp},{$yp}],[{$b},0],[0,0]]);";
    if ($len[0] > 0) {
        $com .= "text([{$xp}/2-.1*{$b}/{$yp},{$yp}/2+.1*{$b}/{$yp}],\"{$labels[0]}\",\"left\");";
    }
    if ($len[1] > 0) {
        $com .= "text([{$b}/2,0],\"{$labels[1]}\",\"below\");";
    }
    if ($len[2] > 0) {
        if ($xp > $b) {
            $com .= "text([({$b}+{$xp}+.1*{$b}/{$yp})/2,{$yp}/2+.1*{$b}/{$yp}],\"{$labels[2]}\",\"right\");";
        } else {
            $com .= "text([({$b}+{$xp}+.1*{$b}/{$yp})/2,{$yp}/2+.1*{$b}/{$yp}],\"{$labels[2]}\",\"right\");";
        }
    }
    $dw = 200;
    $dh = 200;
    return showasciisvg($com, $dw, $dh);
}
예제 #2
0
function graphdrawschedule($sc, $w = 600, $h = -1, $names = array())
{
    $p = count($sc);
    if ($h == -1) {
        $h = 70 * $p;
    }
    //text label is around 40 px, so can do w/40 labels.  Divide ct / (w/40)
    $colors = array('red', 'blue', 'green', 'orange', 'cyan', 'yellow', 'purple');
    $ct = graphschedulecompletion($sc);
    $sp = ceil($ct / ($w / 25));
    //penacto - video thing
    $com = "setBorder(12,8,12,20);initPicture(0,{$ct},0,{$p});stroke='gray';";
    for ($i = 0; $i <= $ct; $i++) {
        $com .= "line([{$i},-.1],[{$i},{$p}+.1]);";
    }
    $com .= "stroke='black';";
    for ($i = 0; $i <= $ct; $i += $sp) {
        $com .= "text([{$i},{$p}],'{$i}','above');";
        $com .= "line([{$i},-.1],[{$i},{$p}+.1]);";
    }
    $com .= "fill='gray';rect([0,0],[{$ct},{$p}]);";
    for ($i = 1; $i < $p; $i++) {
        $com .= "line([0,{$i}],[{$ct},{$i}]);";
    }
    $com .= "fontbackground='white';";
    $cnt = 0;
    foreach ($sc as $n => $tl) {
        foreach ($tl as $ti) {
            $col = $colors[$cnt % 7];
            $cnt++;
            if (count($names) == 0) {
                $tn = 'T' . ($ti[0] + 1);
            } else {
                $tn = $names[$ti[0]];
            }
            $com .= "fill='{$col}';rect([" . $ti[1] . "," . ($p - $n - 1) . "],[" . ($ti[1] + $ti[2]) . "," . ($p - $n) . "]);";
            $com .= "text([" . ($ti[1] + 0.5 * $ti[2]) . "," . ($p - $n - 0.5) . "],'{$tn}');";
        }
    }
    return showasciisvg($com, $w, $h);
}
예제 #3
0
function boxplot($arr, $label)
{
    if (func_num_args() > 2) {
        $dlbls = func_get_arg(2);
    }
    if (is_array($arr[0])) {
        $multi = count($arr);
    } else {
        $multi = 1;
    }
    $st = '';
    $bigmax = -10000000;
    $bigmin = 100000000;
    $alt = "Boxplot, axis label: {$label}. ";
    for ($i = 0; $i < $multi; $i++) {
        if ($multi == 1) {
            $a = $arr;
        } else {
            $a = $arr[$i];
        }
        sort($a, SORT_NUMERIC);
        $max = $a[count($a) - 1];
        if ($max > $bigmax) {
            $bigmax = $max;
        }
        if ($a[0] < $bigmin) {
            $bigmin = $a[0];
        }
        $q1 = percentile($a, 25);
        $q2 = percentile($a, 50);
        $q3 = percentile($a, 75);
        $yl = 2 + 5 * $i;
        $ym = $yl + 1;
        $yh = $ym + 1;
        $st .= "line([{$a['0']},{$yl}],[{$a['0']},{$yh}]); rect([{$q1},{$yl}],[{$q3},{$yh}]); line([{$q2},{$yl}],[{$q2},{$yh}]);";
        $st .= "line([{$max},{$yl}],[{$max},{$yh}]); line([{$a['0']},{$ym}],[{$q1},{$ym}]); line([{$q3},{$ym}],[{$max},{$ym}]);";
        $alt .= 'Boxplot ';
        if (isset($dlbls[$i])) {
            $alt .= "for {$dlbls[$i]}";
        } else {
            $alt .= $i + 1;
        }
        $alt .= ": Left whisker at {$a[0]}. Leftside of box at {$q1}. Line through box at {$q2}.  Rightside of box at {$q3}. Right whisker at {$max}.\n";
    }
    if ($GLOBALS['sessiondata']['graphdisp'] == 0) {
        return $alt;
    }
    $outst = "setBorder(15); initPicture({$bigmin},{$bigmax},-3," . 5 * $multi . ");";
    $dw = $bigmax - $bigmin;
    if ($dw > 100) {
        $step = 20;
    } else {
        if ($dw > 50) {
            $step = 10;
        } else {
            if ($dw > 20) {
                $step = 5;
            } else {
                $step = 1;
            }
        }
    }
    $outst .= "axes({$step},100,1,null,null,1,'off');";
    $outst .= "text([" . ($bigmin + 0.5 * $dw) . ",-3],\"{$label}\");";
    if (isset($dlbls)) {
        for ($i = 0; $i < $multi; $i++) {
            if ($multi > 1) {
                $dlbl = $dlbls[$i];
            } else {
                $dlbl = $dlbls;
            }
            $st .= "text([{$bigmin}," . (5 + 5 * $i) . "],\"{$dlbl}\",\"right\");";
        }
    }
    $outst .= $st;
    return showasciisvg($outst, 400, 50 + 50 * $multi);
}
예제 #4
0
function normalcurve3($mu, $sigma, $a, $b, $axislabel = '', $x = null, $dirx = 'left', $y = null, $diry = 'right', $color = 'blue', $q = null, $dirq = 'left', $r = null, $dirr = 'right', $color2 = 'red', $w = 400, $h = 150)
{
    if ($sigma <= 0) {
        echo 'Invalid sigma';
        return;
    }
    if ($y !== null && $y < $x) {
        echo 'Second value should be bigger than the first';
        return;
    }
    if ($a >= $b) {
        echo 'xmin should be smaller than xmax';
        return;
    }
    if ($y !== null && $dirx == $diry) {
        echo 'directions should not be equal';
        return;
    }
    $za = ($a - $mu) / $sigma;
    $zb = ($b - $mu) / $sigma;
    if ($x !== null) {
        $zx = ($x - $mu) / $sigma;
    }
    if ($y !== null) {
        $zy = ($y - $mu) / $sigma;
    }
    if ($q !== null) {
        $zq = ($q - $mu) / $sigma;
    }
    if ($r !== null) {
        $zr = ($r - $mu) / $sigma;
    }
    $dz = ($zb - $za) / 80;
    $zab = $za - $sigma;
    $zbb = $zb + $sigma;
    $plot = "setBorder(10,30,10,5);initPicture({$za},{$zb},-.1,.45);line([{$zab},0],[{$zbb},0]);";
    for ($i = ceil($za); $i < $zb + $dz; $i++) {
        $label = $mu + $i * $sigma;
        $plot .= "line([{$i},.02],[{$i},-.02]);text([{$i},-.01],\"{$label}\",\"below\");";
    }
    $midx = $w / 2;
    $plot .= "textabs([{$midx},0],'{$axislabel}','above');";
    $pts = array();
    $xpts = array();
    $ypts = array();
    $qpts = array();
    $rpts = array();
    $coef = 1 / sqrt(2 * 3.1415926);
    if ($x !== null && $dirx == 'right') {
        $py = $coef * exp(-$zx * $zx / 2);
        $xpts[] = "[{$zx},0]";
        $xpts[] = "[{$zx},{$py}]";
    }
    if ($y !== null && $diry == 'right') {
        $py = $coef * exp(-$zy * $zy / 2);
        $ypts[] = "[{$zy},{$py}]";
    }
    if ($q !== null && $dirq == 'right') {
        $pr = $coef * exp(-$zq * $zq / 2);
        $qpts[] = "[{$zq},0]";
        $qpts[] = "[{$zq},{$pr}]";
    }
    if ($r !== null && $dirr == 'right') {
        $pr = $coef * exp(-$zr * $zr / 2);
        $rpts[] = "[{$zr},{$pr}]";
    }
    for ($z = $za; $z <= $zb + 1.0E-5; $z += $dz) {
        $py = $coef * exp(-$z * $z / 2);
        $pts[] = "[{$z},{$py}]";
        if ($x !== null && ($dirx == 'left' && $z < $zx || $dirx == 'right' && $z > $zx && ($y === null || $z < $zy))) {
            $xpts[] = "[{$z},{$py}]";
        }
        if ($y !== null && $diry == 'right' && $z > $zy) {
            $ypts[] = "[{$z},{$py}]";
        }
        if ($q !== null && ($dirq == 'left' && $z < $zq || $dirq == 'right' && $z > $zq && ($r === null || $z < $zr))) {
            $qpts[] = "[{$z},{$py}]";
        }
        if ($r !== null && $dirr == 'right' && $z > $zr) {
            $rpts[] = "[{$z},{$py}]";
        }
    }
    if ($x !== null && $dirx == 'left') {
        $py = $coef * exp(-$zx * $zx / 2.0);
        $xpts[] = "[{$zx},{$py}]";
        $xpts[] = "[{$zx},0]";
        $xpts[] = "[{$za},0]";
    }
    if ($x !== null && $dirx == 'right' && $y === null) {
        $xpts[] = "[{$zb},0]";
    }
    if ($y !== null && $diry == 'left') {
        $py = $coef * exp(-$zy * $zy / 2.0);
        $xpts[] = "[{$zy},{$py}]";
        $xpts[] = "[{$zy},0]";
        $xpts[] = "[{$zx},0]";
    }
    if ($y !== null && $diry == 'right') {
        $ypts[] = "[{$zb},0]";
        $ypts[] = "[{$zy},0]";
    }
    if ($q !== null && $dirq == 'left') {
        $py = $coef * exp(-$zq * $zq / 2.0);
        $qpts[] = "[{$zq},{$py}]";
        $qpts[] = "[{$zq},0]";
        $qpts[] = "[{$zq},0]";
    }
    if ($q !== null && $dirq == 'right' && $r === null) {
        $qpts[] = "[{$zb},0]";
    }
    if ($r !== null && $dirr == 'left') {
        $py = $coef * exp(-$zr * $zr / 2.0);
        $qpts[] = "[{$zr},{$py}]";
        $qpts[] = "[{$zy},0]";
        $qpts[] = "[{$zx},0]";
    }
    if ($r !== null && $dirr == 'right') {
        $rpts[] = "[{$zb},0]";
        $rpts[] = "[{$zy},0]";
    }
    $plot .= 'fill="none";path([' . implode(',', $pts) . ']);';
    if ($x !== null) {
        $plot .= 'fill="' . $color . '";path([' . implode(',', $xpts) . ']);';
    }
    if ($y !== null && $diry == 'right') {
        $plot .= 'fill="' . $color . '";path([' . implode(',', $ypts) . ']);';
    }
    if ($q !== null) {
        $plot .= 'fill="' . $color2 . '";path([' . implode(',', $qpts) . ']);';
    }
    if ($r !== null && $dirr == 'right') {
        $plot .= 'fill="' . $color2 . '";path([' . implode(',', $rpts) . ']);';
    }
    return showasciisvg($plot, $w, $h);
}