Skip to content

Commit

Permalink
Tweak matrixdisplaytable to handle single column matrices
Browse files Browse the repository at this point in the history
Also, adjust php header defaults to match those in html and code
  • Loading branch information
drlippman committed Oct 13, 2020
1 parent ff8f987 commit 37c7973
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions assessment/libs/matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ function matrixformat($m, $bracket='[') {
// table, either 0 or 1. Use 0 if you are
// building an answerbox matrix.
//
// 0 do not use math ticks
// default 1 use math ticks
// def 0 do not use math ticks
// 1 use math ticks
//
// linemode: Show none, augments, or simplex style
// 0 show no lines
// default 1 show aumented line
// def 0 show no lines
// 1 show aumented line
// 2 show simplex lines
//
// headernames: list or array of the variables "x1,x2,x3" that are
Expand Down Expand Up @@ -130,7 +130,6 @@ function matrixdisplaytable() {
return "";
}
$m = $args[0];
if (!isMatrix($m)) { echo 'error: input not a matrix'; return '';}

// matrixname
if($args[1]!=null) {
Expand Down Expand Up @@ -239,11 +238,13 @@ function matrixdisplaytable() {
if($rloop==0) {
if($matrixname!="") {
if(!empty($headers)) { $matricnamerows = $rows+1; } else { $matricnamerows = $rows; }
// Accessible option added
$Tableau.= "<td rowspan='$matricnamerows'> $matrixname </td>\r\n";
}

if(!empty($headers)) {
if($rowheader!="") {
// Accessible option added
$Tableau.= "<th scope=\"col\">$rowheader</th>\r\n";
} else {
if($rownames!=null) {
Expand All @@ -259,6 +260,7 @@ function matrixdisplaytable() {
}
if(($headers[$cloop]!=null)&&($headers[$cloop]!=""))
{
// Accessible option added
$Tableau.= "<th scope=\"col\">".$headers[$cloop]."</th>\r\n";
}
else
Expand All @@ -271,6 +273,7 @@ function matrixdisplaytable() {
}

if(!empty($rownames)) {
// Accessible option added
if(($rownames[$rloop]!=null)&&($rownames[$rloop]!="")) {
$Tableau.= "<th scope=\"row\">".$rownames[$rloop]."</th>\r\n";
} else {
Expand All @@ -279,17 +282,21 @@ function matrixdisplaytable() {
}

for ($cloop=0;$cloop<$cols; $cloop++) {
$index =$rloop*$ctemp + $cloop;
//$index =$rloop*$ctemp + $cloop;

$TableElement = "&nbsp;".$ticks.$m[$rloop][$cloop].$ticks."&nbsp;";
//$TableElement = "&nbsp;".$ticks.$m[$rloop][$cloop].$ticks."&nbsp;";
$TableElement = $ticks.$m[$rloop][$cloop].$ticks;

if ($rloop==0) {
if($rows==1) {
// only 1 row
if ($cloop==0) { // R1C1
$Tableau.= "<td $onerowleftborder>&nbsp;</td>\r\n<td $pivotsyle>$TableElement</td>\r\n";
if($cloop==$lastcol) {
$Tableau.= "<td $onerowrightborder>&nbsp;</td>\r\n";
}
}
elseif ($cloop==$lastcol) { // R1C(Last)
elseif ($cloop==$lastcol) { // R1C(Last)
if($mode>0) { $Tableau.= "<td $nopad>&nbsp;</td><td $leftborder >&nbsp;</td>\r\n";} // add augemented column
$Tableau.= "<td>$TableElement</td><td $onerowrightborder>&nbsp;</td>\r\n";
}
Expand All @@ -301,6 +308,9 @@ function matrixdisplaytable() {
// top row
if ($cloop==0) { // R1C1
$Tableau.= "<td $topleftborder>&nbsp;</td>\r\n<td>$TableElement</td>\r\n";
if($cloop==$lastcol) {
$Tableau.= "<td $toprightborder>&nbsp;</td>\r\n";
}
}
elseif ($cloop==$lastcol) { // R1C(Last)
if($mode>0) { $Tableau.= "<td $nopad>&nbsp;</td><td $leftborder >&nbsp;</td>\r\n";} // add augemented column
Expand All @@ -320,6 +330,9 @@ function matrixdisplaytable() {
else {
$Tableau.= "<td>$TableElement</td>\r\n";
}
if ($cloop==$lastcol){ // R(last)C(Last)
$Tableau.= "<td $bottomrightborder>&nbsp;</td>\r\n";
}
}
elseif ($cloop==$lastcol){ // R(last)C(Last)
if($mode==2) { $Tableau.= "<td $Simplex>&nbsp;</td><td $leftborderSimplex >&nbsp;</td>\r\n"; }
Expand All @@ -344,6 +357,9 @@ function matrixdisplaytable() {
else {
if ($cloop==0) {
$Tableau.= "<td $leftborder>&nbsp;</td><td>$TableElement</td>\r\n";
if ($cloop==$lastcol) {
$Tableau.= "<td $rightborder>&nbsp;</td>\r\n";
}
}
elseif ($cloop==$lastcol) {
if($mode>0) { $Tableau.= "<td $nopad>&nbsp;</td><td $leftborder >&nbsp;</td>\r\n"; }
Expand Down

0 comments on commit 37c7973

Please sign in to comment.