/** * Function: getBoundsForCells * * Returns the bounds for the given cells. */ function getBoundsForCells($cells, $includeEdges = false, $includeDescendants = false, $boundingBox = false) { $cellCount = sizeof($cells); $result = null; if ($cellCount > 0) { for ($i = 0; $i < $cellCount; $i++) { $bounds = $this->getCellBounds($cells[$i], $includeEdges, $includeDescendants, $boundingBox); if ($bounds != null) { if ($result == null) { $result = new mxRectangle($bounds->x, $bounds->y, $bounds->width, $bounds->height); } else { $result->add($bounds); } } } } return $result; }
/** * Function: updateBoundingBox * * Updates the bounding box in the given cell state. */ function updateBoundingBox($state) { // Gets the cell bounds and adds shadows and markers $rect = new mxRectangle($state->x, $state->y, $state->width, $state->height); $style = $state->style; // Adds extra pixels for the marker and stroke assuming // that the border stroke is centered around the bounds // and the first pixel is drawn inside the bounds $strokeWidth = max(1, mxUtils::getNumber($style, mxConstants::$STYLE_STROKEWIDTH, 1) * $this->scale); $strokeWidth -= max(1, $strokeWidth / 2); if ($this->graph->model->isEdge($state->cell)) { $ms = 0; if (isset($style[mxConstants::$STYLE_ENDARROW]) || isset($style[mxConstants::$STYLE_STARTARROW])) { $ms = round(mxConstants::$DEFAULT_MARKERSIZE * $this->scale); } // Adds the strokewidth $rect->grow($ms + $strokeWidth); // Adds worst case border for an arrow shape if (mxUtils::getValue($style, mxConstants::$STYLE_SHAPE) == mxConstants::$SHAPE_ARROW) { $rect->grow(mxConstants::$ARROW_WIDTH / 2); } } else { $rect->grow($strokeWidth); } // Adds extra pixels for the shadow if (mxUtils::getValue($style, mxConstants::$STYLE_SHADOW, false) == true) { $rect->width += mxConstants::$SHADOW_OFFSETX; $rect->height += mxConstants::$SHADOW_OFFSETY; } // Adds oversize images in labels if (mxUtils::getValue($style, mxConstants::$STYLE_SHAPE) == mxConstants::$SHAPE_LABEL) { if (mxUtils::getValue($style, mxConstants::$STYLE_IMAGE) != null) { $w = mxUtils::$getValue($style, mxConstants::$STYLE_IMAGE_WIDTH, mxConstants::$DEFAULT_IMAGESIZE) * $this->scale; $h = mxUtils::$getValue($style, mxConstants::$STYLE_IMAGE_HEIGHT, mxConstants::$DEFAULT_IMAGESIZE) * $this->scale; $x = $state->x; $y = 0; $imgAlign = mxUtils::getValue($style, mxConstants::$STYLE_IMAGE_ALIGN, mxConstants::$ALIGN_CENTER); $imgValign = mxUtils::getValue(style, mxConstants::$STYLE_IMAGE_VERTICAL_ALIGN, mxConstants::$ALIGN_MIDDLE); if ($imgAlign == mxConstants::$ALIGN_RIGHT) { $x += $state->width - $w; } else { if ($imgAlign == mxConstants::$ALIGN_CENTER) { $x += ($state->width - $w) / 2; } } if ($imgValign == mxConstants::$ALIGN_TOP) { $y = $state->y; } else { if ($imgValign == mxConstants::$ALIGN_BOTTOM) { $y = $state->y + $state->height - $h; } else { $y = $state->y + ($state->height - $h) / 2; } } $rect->add(new mxRectangle($x, $y, $w, $h)); } } // No need to add rotated rectangle bounds here because // GD does not support rotation // Unifies the cell bounds and the label bounds $rect->add($state->labelBounds); $state->boundingBox = $rect; return $rect; }