public function insert(Canvas $canvas, $y, $x = 0, $h = 0, $w = 0) { $this->logger->debug("Inserting canvas at X:{$x}, Y:{$y}. Replacing W:{$w}, H:{$h}", ['canvas' => $canvas]); //remove height for ($i = $y; $i < $y + $h; $i++) { if (isset($this[$i])) { if ($x > 0) { foreach ($this[$i] as $ci => $col) { if ($ci > $x) { unset($this[$i][$x]); } } } else { unset($this[$i]); } } } //make space $insertHeight = $canvas->getHeight(); foreach ($this->getArrayCopy() as $thisRowNum => $row) { if ($thisRowNum >= $y + $h && $x === 0) { $this->logger->debug("Shifting row {$thisRowNum} to " . ($thisRowNum + $insertHeight) . " due to >= Y:{$y} + H:{$h} = " . ($y + $h) . " and X === 0. Insertheight is: {$insertHeight}", ['row' => $row]); //unset($this[$thisRowNum]); $this[$thisRowNum + $insertHeight - $h] = $row; } } /*$startRowNum = $canvas->getLowestRow(); $insertWidth = $canvas->getHighestCol() - $w; foreach ($this->getArrayCopy() as $thisRowNum => $row) { if ($thisRowNum == $startRowNum) { foreach ($row as $thisColNum => $col) { if ($thisColNum > $x + $w && $col != '') { $this[$thisRowNum][$thisColNum + $insertWidth] = $col; } } } }*/ $r = $c = 0; foreach ($canvas as $row) { foreach ($row as $c => $col) { $this->set($x + $c, $y + $r, $col); } $r++; } $this->sort(); }
/** * @return Canvas */ private function renderItem(array $data, $namedRangeName) { $this->logger->debug("[START] Rendering START for item {$namedRangeName}"); $data = array_change_key_case($data, CASE_UPPER); $namedRangeName = strtoupper($namedRangeName); $namedRange = $this->namedRanges[$namedRangeName]; if (!isset($namedRange)) { throw new \RuntimeException("Could not find named range {$namedRangeName}"); } $canvas = new Canvas($this->logger); $compiledData = $this->reportDataCompiler->compile($data, $namedRange); //zero-base all data $compiledData = array_values($compiledData); foreach ($compiledData as &$row) { $row = array_values($row); } $canvas->write($compiledData); $i = 0; foreach ($data as $node => $item) { if (is_array($item)) { $itemNamedRange = isset($this->namedRanges[$node]) ? $this->namedRanges[$node] : null; if (self::isDeepArray($item) && $itemNamedRange) { $this->logger->debug("[START] List and Insert operation for {$node}"); $y = $this->calculateOffsetY($namedRange, $itemNamedRange); $h = count($itemNamedRange); $x = $this->calculateOffsetX($namedRange, $itemNamedRange); //$w = count($this->namedRanges[$node][array_keys($this->namedRanges[$node])[0]]); $w = 0; $itemCanvas = $this->renderList($item, $node); $canvas->insert($itemCanvas, $y, $x, $h, $w); $this->logger->debug("[DONE] List and Insert operation for {$node}"); } } $i++; } $this->logger->debug("[DONE] Rendering for item {$namedRangeName}"); return $canvas; }
public function render(Canvas $fromCanvas, Canvas $toCanvas) { $toCanvas->write((array) $fromCanvas); $toCanvas->setPointer($toCanvas->getHighestCol() + 1); }