* @param minNumberOfPoint Minimum number of points (1 for bars, 2 for lines).
*
* @return true if data set empty
*/
protected function isEmptyDataSet($minNumberOfPoint) {
if ($this->dataSet instanceof LibchartXYDataSet) {
$pointList = $this->dataSet->getPointList();
$pointCount = count($pointList);
return $pointCount < $minNumberOfPoint;
} else if ($this->dataSet instanceof LibchartXYSeriesDataSet) {
$serieList = $this->dataSet->getSerieList();
reset($serieList);
if (count($serieList) > 0) {
$serie = current($serieList);
$pointList = $serie->getPointList();
$pointCount = count($pointList);
return $pointCount < $minNumberOfPoint;
}
} else {
die("Error: unknown dataset type");
}
}
/**
* Checks the data model before rendering the graph.
*/
protected function checkDataModel() {
// Check if a dataset was defined
if (!$this->dataSet) {
die("Error: No dataset defined.");
}
// Bar charts accept both XYDataSet and XYSeriesDataSet
if ($this->dataSet instanceof LibchartXYDataSet) {
// The dataset contains only one serie
$this->hasSeveralSerie = false;
} else if ($this->dataSet instanceof LibchartXYSeriesDataSet) {
// Check if each series has the same number of points
unset($lastPointCount);
$serieList = $this->dataSet->getSerieList();
for ($i = 0; $i < count($serieList); $i++) {
$serie = $serieList[$i];
$pointCount = count($serie->getPointList());
if (isset($lastPointCount) && $pointCount != $lastPointCount) {
die("Error: serie <" . $i . "> doesn't have the same number of points as last serie (last one: <" . $lastPointCount. ">, this one: <" . $pointCount. ">).");
}
$lastPointCount = $pointCount;
}
// The dataset contains several series
$this->hasSeveralSerie = true;
} else {
die("Error: Bar chart accept only XYDataSet and XYSeriesDataSet");
}
}
/**
* Return the data as a series list (for consistency).
*
* @return List of series
*/
protected function getDataAsSerieList() {
// Get the data as a series list
$serieList = null;
if ($this->dataSet instanceof LibchartXYSeriesDataSet) {
$serieList = $this->dataSet->getSerieList();
} else if ($this->dataSet instanceof LibchartXYDataSet) {
$serieList = array();
array_push($serieList, $this->dataSet);
}
return $serieList;
}
/**
* Return the first serie of the list, or the dataSet itself if there is no serie.
*
* @return XYDataSet
*/
protected function getFirstSerieOfList() {
$pointList = null;
if ($this->dataSet instanceof LibchartXYSeriesDataSet) {
// For a series dataset, print the legend from the first serie
$serieList = $this->dataSet->getSerieList();
reset($serieList);
$serie = current($serieList);
$pointList = $serie->getPointList();
} else if ($this->dataSet instanceof LibchartXYDataSet) {