Ejemplo n.º 1
0
 public function init(awDriver $driver)
 {
     list($x1, $y1, $x2, $y2) = $this->getPosition();
     // Get space informations
     list($leftSpace, $rightSpace, $topSpace, $bottomSpace) = $this->getSpace($x2 - $x1, $y2 - $y1);
     $this->xAxis->setPadding($leftSpace, $rightSpace);
     if ($this->space->bottom > 0 or $this->space->top > 0) {
         list($min, $max) = $this->yAxis->getRange();
         $interval = $max - $min;
         $this->yAxis->setRange($min - $interval * $this->space->bottom / 100, $max + $interval * $this->space->top / 100);
     }
     // Auto-scaling mode
     $this->yAxis->autoScale();
     // Number of labels is not specified
     if ($this->yAxis->getLabelNumber() === NULL) {
         $number = round(($y2 - $y1) / 75) + 2;
         $this->yAxis->setLabelNumber($number);
     }
     $this->xAxis->line->setX($x1, $x2);
     $this->yAxis->line->setY($y2, $y1);
     // Set ticks
     /* <php5> */
     $this->xAxis->tick('major')->setNumber($this->getXAxisNumber());
     $this->yAxis->tick('major')->setNumber($this->yAxis->getLabelNumber());
     /* </php5> */
     /* <php4> --
     		$this->xAxis->ticks['major']->setNumber($this->getXAxisNumber());
     		$this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber());
     		-- </php4> */
     // Center X axis on zero
     if ($this->xAxisZero) {
         $this->xAxis->setYCenter($this->yAxis, 0);
     }
     // Center Y axis on zero
     if ($this->yAxisZero) {
         $this->yAxis->setXCenter($this->xAxis, 0);
     }
     // Set axis labels
     $labels = array();
     list($xMin, $xMax) = $this->xAxis->getRange();
     for ($i = $xMin; $i <= $xMax; $i++) {
         $labels[] = $i;
     }
     $this->xAxis->label->set($labels);
     parent::init($driver);
     list($x1, $y1, $x2, $y2) = $this->getPosition();
     list($leftSpace, $rightSpace) = $this->getSpace($x2 - $x1, $y2 - $y1);
     // Create the grid
     $this->createGrid();
     // Draw the grid
     $this->grid->setSpace($leftSpace, $rightSpace, 0, 0);
     $this->grid->draw($driver, $x1, $y1, $x2, $y2);
 }
Ejemplo n.º 2
0
$yAxis->label->set($labels);
$yAxis->label->setColor(new DarkGray());
$yAxis->label->setAlign(LABEL_RIGHT);
$yAxis->label->setFont(new Tuffy(7));
$yAxis->label->move(-5, 0);
$tick = new Tick(0, 2);
$yAxis->addTick('minor', $tick);
$tick = new Tick(11, 5);
$yAxis->addTick('major', $tick);
$yAxis->setNumberByTick('minor', 'major', 3);
$xAxis->setYCenter($yAxis, 0);
$yAxis->setXCenter($xAxis, 0);
$xAxis->draw($driver);
$yAxis->draw($driver);
for ($x = -10; $x <= 10; $x += 0.1) {
    $p = Axis::toPosition($xAxis, $yAxis, new Point($x, cos($x) * 4));
    $driver->point(new Red(), $p);
}
// Vertical axis
$axis = new Axis();
//$axis->line->setThickness(2);
$axis->setRange(8, -8);
$axis->setPadding(10, 10);
$axis->line->setLocation(new Point(20, 260), new Point(380, 380));
$tick = new Tick(0, 4);
$axis->addTick('minor', $tick);
$tick = new Tick(11, 8);
$axis->addTick('major', $tick);
$axis->setNumberByTick('minor', 'major', 3);
$axis->draw($driver);
$graph->draw();