예제 #1
0
 public function render($title = '')
 {
     $buf = new Buffer();
     $g = new Graphics($buf);
     $chartWidth = $this->width;
     $maxValue = 0;
     foreach ($this->bars as $bar) {
         if ($bar->value > $maxValue) {
             $maxValue = $bar->value;
         }
     }
     $chartWidth -= strlen($maxValue) + 1;
     $g->drawLine(0, 0, 0, count($this->bars) * 4 + 1)->transit(0, 1);
     foreach ($this->bars as $bar) {
         $bar->render($g, $chartWidth, $maxValue);
         $g->transit(0, 4);
     }
     if ($title != '') {
         $g->transit(0, -1);
         $g->drawLine(0, 0, $this->width, 0);
         $titleLen = WString::stringWidth($title);
         $x = ceil(($this->width - $titleLen) / 2);
         $g->drawString($x, 1, $title);
     }
     return implode("\n", $buf->exportAll()) . "\n";
 }
예제 #2
0
 public function render($title = '')
 {
     $colWidth = array();
     $colMaxWidth = array();
     foreach ($this->data as $rid => $row) {
         $rowWidths = array();
         foreach ($row as $cid => $col) {
             $w = WString::stringWidth($col);
             $rowWidths[$cid] = $w;
             if (!isset($colMaxWidth[$cid]) or $colMaxWidth[$cid] < $w) {
                 $colMaxWidth[$cid] = $w;
             }
         }
         $colWidth[$rid] = $rowWidths;
     }
     $totalWidth = count($colMaxWidth) - 1 - 1;
     foreach ($colMaxWidth as $w) {
         $totalWidth += $w;
     }
     $totalHeight = count($this->data) * 2 - 1 - 1;
     $buf = new Buffer();
     $g = new Graphics($buf);
     $f = "drawTextBlockCenter";
     switch ($this->align) {
         case "left":
             $f = "drawTextBlock";
             break;
         case "right":
             $f = "drawTextBlockRight";
             break;
     }
     if ($title != '') {
         $g->drawTextBlockCenter(0, 0, $totalWidth, 0, $title)->drawLine(0, 1, $totalWidth, 1)->transit(0, 2);
     }
     foreach ($this->data as $rid => $row) {
         $pos = 0;
         foreach ($row as $cid => $col) {
             $g->{$f}($pos, $rid * 2, $pos + $colMaxWidth[$cid], $rid * 2, $col);
             $pos += $colMaxWidth[$cid] + 1;
         }
     }
     // draw vertical lines
     $pos = 0;
     for ($i = 0; $i < count($colMaxWidth) - 1; $i++) {
         $pos += $colMaxWidth[$i];
         $g->drawLine($pos, 0, $pos, $totalHeight);
         $pos++;
     }
     // draw horizontal lines
     for ($i = 1; $i < count($this->data); $i++) {
         $g->drawLine(0, $i * 2 - 1, $totalWidth, $i * 2 - 1);
     }
     return implode("\n", $buf->exportAll()) . "\n";
 }
예제 #3
0
 public function render(Graphics $g, $chartWidth, $maxValue)
 {
     $size = $this->width($chartWidth, $maxValue);
     $g->drawLine(0, 0, $size, 0);
     $g->drawLine(0, 2, $size, 2);
     $g->drawLine($size, 0, $size, 2);
     $valStr = $this->value . '';
     $lblWidth = WString::stringWidth($this->label);
     if ($size - 1 >= $lblWidth + 2) {
         $g->drawString($size - 2 - $lblWidth, 1, $this->label);
     } else {
         $valStr .= ' ' . $this->label;
     }
     $g->drawString($size + 2, 1, $valStr);
     return;
 }
예제 #4
0
 /**
  * @dataProvider stringP
  */
 public function testStringWidth($char, $len)
 {
     $actual = WString::stringWidth($char);
     $this->assertEquals($len, $actual, $char);
 }