Skip to content

Commit

Permalink
No specimens, no traits plots
Browse files Browse the repository at this point in the history
Added logic to display a message when no specimens are encoded for a trait rather than showing an empty plot. Also cleaned up the TraitPlotManager class a little and added plot-specific styling for buttons.
  • Loading branch information
cdtyrrell committed Nov 18, 2021
1 parent 44be5c6 commit 65af87f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
7 changes: 5 additions & 2 deletions classes/TraitPlotManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,18 @@ public function getViewboxHeight() {
return $this->plotInstance->getPlotHeight();
}

public function monthlyPolarPlot() {
public function getNumberOfSpecimens() {
return $this->plotInstance->getNumDataValues();
}

public function calendarPlot() {
if($this->rankId > 180) { // limit to below genus
$this->plotInstance->setAxisNumber(12);
$this->plotInstance->setAxisRotation(0);
$this->plotInstance->setTickNumber(10); //3
$this->plotInstance->setAxisLabels(array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'));
$this->plotInstance->setDataValues($this->summarizeTraitByMonth());
$this->setPlotCaption();
return $this->plotInstance->display();
}
}

Expand Down
4 changes: 3 additions & 1 deletion css/symb/taxa/traitplot.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
button{
.PlotButton{
border: none;
background-color: white;
margin: 0px;
}
.PlotCaption {
font-size: x-small;
Expand Down
56 changes: 38 additions & 18 deletions taxa/plottab.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ function toggleDisplay(id) {
}
</script>

<button onclick="toggleDisplay('barplots')"><img class="PlotIcon" src="../images/barplot.png" alt="bar plot icon" /></button>
<button onclick="toggleDisplay('lineplots')"><img class="PlotIcon" src="../images/lineplot.png" alt="line plot icon" /></button>
<button onclick="toggleDisplay('polarplots')"><img class="PlotIcon" src="../images/polarplot.png" alt="line plot icon" /></button>
<button class="PlotButton" onclick="toggleDisplay('barplots')"><img class="PlotIcon" src="../images/barplot.png" alt="bar plot icon" /></button>
<button class="PlotButton" onclick="toggleDisplay('lineplots')"><img class="PlotIcon" src="../images/lineplot.png" alt="line plot icon" /></button>
<button class="PlotButton" onclick="toggleDisplay('polarplots')"><img class="PlotIcon" src="../images/polarplot.png" alt="line plot icon" /></button>

<!--label class="PlotSwitch" for="_0"><img class="PlotIcon" src="../images/barplot.png" alt="bar plot icon" /></label>
<input id="_0" type="radio" name="c1"-->
Expand All @@ -52,11 +52,18 @@ function toggleDisplay(id) {
$traitPlotter = new TraitPlotManager("bar");
if($tid) $traitPlotter->setTid($tid);
$traitPlotter->setTraitStateId($tsid);
echo '<div class="resource-title">'.$traitPlotter->getTraitName(). ': '.$traitPlotter->getStateName().'</div>';
echo '<svg height="'.$traitPlotter->getViewboxHeight().'px" viewbox="0 0 ' . $traitPlotter->getViewboxWidth() . ' ' . $traitPlotter->getViewboxHeight() . '" ><g>' . PHP_EOL;
echo $traitPlotter->monthlyPolarPlot();
echo '</g></svg>';
echo '<p class="PlotCaption">'.$traitPlotter->getPlotCaption().'</p>';
$traitPlotter->calendarPlot();
if($traitPlotter->getNumberOfSpecimens() > 0){
echo '<div class="resource-title">'.$traitPlotter->getTraitName(). ': '.$traitPlotter->getStateName().'</div>';
echo '<svg height="'.$traitPlotter->getViewboxHeight().'px" viewbox="0 0 ' . $traitPlotter->getViewboxWidth() . ' ' . $traitPlotter->getViewboxHeight() . '" ><g>' . PHP_EOL;
echo $traitPlotter->display();
echo '</g></svg>';
echo '<p class="PlotCaption">'.$traitPlotter->getPlotCaption().'</p>';
} else {
echo '<div class="resource-title">'.$traitPlotter->getTraitName(). ': '.$traitPlotter->getStateName().'</div>';
echo '<p class="PlotCaption">No specimens encoded for '.$traitPlotter->getTraitName(). ': '.$traitPlotter->getStateName().'</p>';
}

}
echo '</div>';

Expand All @@ -66,11 +73,18 @@ function toggleDisplay(id) {
$traitPlotter = new TraitPlotManager("line");
if($tid) $traitPlotter->setTid($tid);
$traitPlotter->setTraitStateId($tsid);
echo '<div class="resource-title">'.$traitPlotter->getTraitName(). ': '.$traitPlotter->getStateName().'</div>';
echo '<svg height="'.$traitPlotter->getViewboxHeight().'px" viewbox="0 0 ' . $traitPlotter->getViewboxWidth() . ' ' . $traitPlotter->getViewboxHeight() . '" ><g>' . PHP_EOL;
echo $traitPlotter->monthlyPolarPlot();
echo '</g></svg>';
echo '<p class="PlotCaption">'.$traitPlotter->getPlotCaption().'</p>';
$traitPlotter->calendarPlot();
if($traitPlotter->getNumberOfSpecimens() > 0){
echo '<div class="resource-title">'.$traitPlotter->getTraitName(). ': '.$traitPlotter->getStateName().'</div>';
echo '<svg height="'.$traitPlotter->getViewboxHeight().'px" viewbox="0 0 ' . $traitPlotter->getViewboxWidth() . ' ' . $traitPlotter->getViewboxHeight() . '" ><g>' . PHP_EOL;
echo $traitPlotter->display();
echo '</g></svg>';
echo '<p class="PlotCaption">'.$traitPlotter->getPlotCaption().'</p>';
} else {
echo '<div class="resource-title">'.$traitPlotter->getTraitName(). ': '.$traitPlotter->getStateName().'</div>';
echo '<p class="PlotCaption">No specimens encoded for '.$traitPlotter->getTraitName(). ': '.$traitPlotter->getStateName().'</p>';
}

}
echo '</div>';

Expand All @@ -80,11 +94,17 @@ function toggleDisplay(id) {
$traitPlotter = new TraitPlotManager("polar");
if($tid) $traitPlotter->setTid($tid);
$traitPlotter->setTraitStateId($tsid);
echo '<div class="resource-title">'.$traitPlotter->getTraitName(). ': '.$traitPlotter->getStateName().'</div>';
echo '<svg height="'.$traitPlotter->getViewboxHeight().'px" viewbox="0 0 ' . $traitPlotter->getViewboxWidth() . ' ' . $traitPlotter->getViewboxHeight() . '" ><g>' . PHP_EOL;
echo $traitPlotter->monthlyPolarPlot();
echo '</g></svg>';
echo '<p class="PlotCaption">'.$traitPlotter->getPlotCaption().'</p>';
$traitPlotter->calendarPlot();
if($traitPlotter->getNumberOfSpecimens() > 0){
echo '<div class="resource-title">'.$traitPlotter->getTraitName(). ': '.$traitPlotter->getStateName().'</div>';
echo '<svg height="'.$traitPlotter->getViewboxHeight().'px" viewbox="0 0 ' . $traitPlotter->getViewboxWidth() . ' ' . $traitPlotter->getViewboxHeight() . '" ><g>' . PHP_EOL;
echo $traitPlotter->display();
echo '</g></svg>';
echo '<p class="PlotCaption">'.$traitPlotter->getPlotCaption().'</p>';
} else {
echo '<div class="resource-title">'.$traitPlotter->getTraitName(). ': '.$traitPlotter->getStateName().'</div>';
echo '<p class="PlotCaption">No specimens encoded for '.$traitPlotter->getTraitName(). ': '.$traitPlotter->getStateName().'</p>';
}
}
echo '</div>';
?>

0 comments on commit 65af87f

Please sign in to comment.