function doAutoscaleXAxis() { //Check if we should autoscale x-axis if (!$this->xscale->IsSpecified()) { if (substr($this->axtype, 0, 4) == "text") { $max = 0; $n = count($this->plots); for ($i = 0; $i < $n; ++$i) { $p = $this->plots[$i]; // We need some unfortunate sub class knowledge here in order // to increase number of data points in case it is a line plot // which has the barcenter set. If not it could mean that the // last point of the data is outside the scale since the barcenter // settings means that we will shift the entire plot half a tick step // to the right in oder to align with the center of the bars. if (class_exists('BarPlot', false)) { $cl = strtolower(get_class($p)); if (class_exists('BarPlot', false) && $p instanceof BarPlot || empty($p->barcenter)) { $max = max($max, $p->numpoints - 1); } else { $max = max($max, $p->numpoints); } } else { if (empty($p->barcenter)) { $max = max($max, $p->numpoints - 1); } else { $max = max($max, $p->numpoints); } } } $min = 0; if ($this->y2axis != null) { foreach ($this->y2plots as $p) { $max = max($max, $p->numpoints - 1); } } $n = count($this->ynaxis); for ($i = 0; $i < $n; ++$i) { if ($this->ynaxis[$i] != null) { foreach ($this->ynplots[$i] as $p) { $max = max($max, $p->numpoints - 1); } } } $this->xscale->Update($this->img, $min, $max); $this->xscale->ticks->Set($this->xaxis->tick_step, 1); $this->xscale->ticks->SupressMinorTickMarks(); } else { list($min, $max) = $this->GetXMinMax(); $lres = $this->GetLinesXMinMax($this->lines); if ($lres) { list($linmin, $linmax) = $lres; $min = min($min, $linmin); $max = max($max, $linmax); } $lres = $this->GetLinesXMinMax($this->y2lines); if ($lres) { list($linmin, $linmax) = $lres; $min = min($min, $linmin); $max = max($max, $linmax); } $tres = $this->GetTextsXMinMax(); if ($tres) { list($tmin, $tmax) = $tres; $min = min($min, $tmin); $max = max($max, $tmax); } $tres = $this->GetTextsXMinMax(true); if ($tres) { list($tmin, $tmax) = $tres; $min = min($min, $tmin); $max = max($max, $tmax); } $this->xscale->AutoScale($this->img, $min, $max, round($this->img->plotwidth / $this->xtick_factor)); } //Adjust position of y-axis and y2-axis to minimum/maximum of x-scale if (!is_numeric($this->yaxis->pos) && !is_string($this->yaxis->pos)) { $this->yaxis->SetPos($this->xscale->GetMinVal()); } } elseif ($this->xscale->IsSpecified() && ($this->xscale->auto_ticks || !$this->xscale->ticks->IsSpecified())) { // The tick calculation will use the user suplied min/max values to determine // the ticks. If auto_ticks is false the exact user specifed min and max // values will be used for the scale. // If auto_ticks is true then the scale might be slightly adjusted // so that the min and max values falls on an even major step. $min = $this->xscale->scale[0]; $max = $this->xscale->scale[1]; $this->xscale->AutoScale($this->img, $min, $max, round($this->img->plotwidth / $this->xtick_factor), false); // Now make sure we show enough precision to accurate display the // labels. If this is not done then the user might end up with // a scale that might actually start with, say 13.5, butdue to rounding // the scale label will ony show 14. if (abs(floor($min) - $min) > 0) { // If the user has set a format then we bail out if ($this->xscale->ticks->label_formatstr == '' && $this->xscale->ticks->label_dateformatstr == '') { $this->xscale->ticks->precision = abs(floor(log10(abs(floor($min) - $min)))) + 1; } } } // Position the optional Y2 and Yn axis to the rightmost position of the x-axis if ($this->y2axis != null) { if (!is_numeric($this->y2axis->pos) && !is_string($this->y2axis->pos)) { $this->y2axis->SetPos($this->xscale->GetMaxVal()); } $this->y2axis->SetTitleSide(SIDE_RIGHT); } $n = count($this->ynaxis); $nY2adj = $this->y2axis != null ? $this->iYAxisDeltaPos : 0; for ($i = 0; $i < $n; ++$i) { if ($this->ynaxis[$i] != null) { if (!is_numeric($this->ynaxis[$i]->pos) && !is_string($this->ynaxis[$i]->pos)) { $this->ynaxis[$i]->SetPos($this->xscale->GetMaxVal()); $this->ynaxis[$i]->SetPosAbsDelta($i * $this->iYAxisDeltaPos + $nY2adj); } $this->ynaxis[$i]->SetTitleSide(SIDE_RIGHT); } } }