示例#1
0
 private function updateAxis()
 {
     $this->xAxis->setRange($this->getXMin(), $this->getXMax());
     $this->yAxis->setRange($this->getRealYMin(), $this->getRealYMax());
 }
 function init($drawer)
 {
     list($x1, $y1, $x2, $y2) = $this->getPosition();
     $this->xAxis->line->setX($x1, $x2);
     $this->xAxis->label->setAlign(NULL, LABEL_BOTTOM);
     $this->xAxis->label->move(0, 3);
     $this->xAxis->setRange($this->extremum->left, $this->extremum->right);
     $this->yAxis->line->setY($y2, $y1);
     $this->yAxis->label->setAlign(LABEL_RIGHT);
     $this->yAxis->label->move(-6, 0);
     $this->yAxis->reverseTickStyle();
     $this->yAxis->setRange($this->extremum->bottom, $this->extremum->top);
     $this->xAxis->setYCenter($this->yAxis, 0);
     $this->yAxis->setXCenter($this->xAxis, 0);
     if ($this->yAxis->getLabelNumber() === NULL) {
         $number = $this->extremum->top - $this->extremum->bottom + 1;
         $this->yAxis->setLabelNumber($number);
     }
     if ($this->xAxis->getLabelNumber() === NULL) {
         $number = $this->extremum->right - $this->extremum->left + 1;
         $this->xAxis->setLabelNumber($number);
     }
     // Set ticks
     $this->xAxis->ticks['major']->setNumber($this->xAxis->getLabelNumber());
     $this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber());
     // Set axis labels
     $labels = array();
     for ($i = 0, $count = $this->xAxis->getLabelNumber(); $i < $count; $i++) {
         $labels[] = $i;
     }
     $this->xAxis->label->set($labels);
     $labels = array();
     for ($i = 0, $count = $this->yAxis->getLabelNumber(); $i < $count; $i++) {
         $labels[] = $i;
     }
     $this->yAxis->label->set($labels);
     parent::init($drawer);
     // Create the grid
     $this->createGrid();
     // Draw the grid
     $this->grid->draw($drawer, $x1, $y1, $x2, $y2);
 }
$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();