/** * Function: drawString */ function drawFixedText($string, $x, $y, $w, $h, $style) { $lines = explode("\n", $string); $lineCount = sizeof($lines); if ($lineCount > 0) { // Gets the orientation and alignment $horizontal = mxUtils::getValue($style, mxConstants::$STYLE_HORIZONTAL, true); $align = mxUtils::getValue($style, mxConstants::$STYLE_ALIGN, mxConstants::$ALIGN_CENTER); if ($align == mxConstants::$ALIGN_LEFT) { if ($horizontal) { $x += mxConstants::$LABEL_INSET; } else { $y -= mxConstants::$LABEL_INSET; } } else { if ($align == mxConstants::$ALIGN_RIGHT) { if ($horizontal) { $x -= mxConstants::$LABEL_INSET; } else { $y += mxConstants::$LABEL_INSET; } } } if ($horizontal) { $y += 2 * mxConstants::$LABEL_INSET; } else { $y += $h; $x += 2 * mxConstants::$LABEL_INSET; } // Gets the font $fontSize = mxUtils::getValue($style, mxConstants::$STYLE_FONTSIZE, mxConstants::$DEFAULT_FONTSIZE) * $this->scale; $fontFamily = mxUtils::getValue($style, mxConstants::$STYLE_FONTFAMILY, mxConstants::$DEFAULT_FONTFAMILY); $font = $this->getFixedFontSize($fontSize, $fontFamily); // Gets the color $fontColor = mxUtils::getValue($style, mxConstants::$STYLE_FONTCOLOR); $color = $this->getColor($fontColor, "black"); $dx = imageFontWidth($font); $dy = (($horizontal ? $h : $w) - 2 * mxConstants::$LABEL_INSET) / $lineCount; // Draws the text line by line for ($i = 0; $i < $lineCount; $i++) { $left = $x; $top = $y; $lineWidth = strlen($lines[$i]) * $dx; if ($align == mxConstants::$ALIGN_CENTER) { if ($horizontal) { $left += ($w - $lineWidth) / 2; } else { $top -= ($h - $lineWidth) / 2; } } else { if ($align == mxConstants::$ALIGN_RIGHT) { if ($horizontal) { $left += $w - $lineWidth; } else { $top -= $h - $lineWidth; } } } $this->drawFixedTextLine($lines[$i], $font, $left, $top, $color, $horizontal); if ($horizontal) { $y += $dy; } else { $x += $dy; } } } }
/** * */ public function apply($state, $source, $target, $points, &$result) { $pt = $points != null && sizeof($points) > 0 ? $points[0] : null; $vertical = false; $horizontal = false; if ($source != null && $target != null) { if ($pt != null) { $left = min($source->x, $target->x); $right = max($source->x + $source->width, $target->x + $target->width); $top = min($source->y, $target->y); $bottom = max($source->y + $source->height, $target->y + $target->height); $pt = $state->view->transformControlPoint($state, $pt); $vertical = $pt->y < $top || $pt->y > $bottom; $horizontal = $pt->x < $left || $pt->x > $right; } else { $left = max($source->x, $target->x); $right = min($source->x + $source->width, $target->x + $target->width); $vertical = $left == $right; if (!$vertical) { $top = max($source->y, $target->y); $bottom = min($source->y + $source->height, $target->y + $target->height); $horizontal = $top == $bottom; } } } if (!$horizontal && ($vertical || mxUtils::getValue($state->style, mxConstants::$STYLE_ELBOW) == mxConstants::$ELBOW_VERTICAL)) { mxEdgeStyle::$TopToBottom->apply($state, $source, $target, $points, $result); } else { mxEdgeStyle::$SideToSide->apply($state, $source, $target, $points, $result); } }
/** * Function: parseState * * Parses the bounds, absolute points and label information from the style * of the state into its respective fields and returns the label of the * cell. */ function parseState($state, $edge) { $style = $state->style; // Parses the bounds $state->x = mxUtils::getNumber($style, "x"); $state->y = mxUtils::getNumber($style, "y"); $state->width = mxUtils::getNumber($style, "width"); $state->height = mxUtils::getNumber($style, "height"); // Parses the absolute points list $tmp = mxUtils::getValue($style, "points"); if (strlen($tmp) > 0) { $pts = $this->parsePoints($tmp); if (sizeof($pts) > 0) { $state->absolutePoints = $pts; } } // Parses the label and label bounds $label = mxUtils::getValue($style, "label"); if ($label != null && strlen($label) > 0) { $offset = new mxPoint(mxUtils::getNumber($style, "dx"), mxUtils::getNumber($style, "dy")); $vertexBounds = !$edge ? $state : null; $state->labelBounds = mxUtils::getLabelPaintBounds($label, $style, mxUtils::getValue($style, "html", false), $offset, $vertexBounds, $this->scale); } return $label; }
/** * Function: setRoot * */ function getCell($id) { $result = null; if ($this->cells != null) { $result = mxUtils::getValue($this->cells, $id); } return $result; }
/** * Function: drawText * * Draws the specified text. */ function drawText($string, $x, $y, $w, $h, $style) { $horizontal = mxUtils::getValue($style, mxConstants::$STYLE_HORIZONTAL, 1); $font = mxUtils::getValue($style, mxConstants::$STYLE_FONTFAMILY, mxConstants::$W3C_DEFAULT_FONTFAMILY); $fontSize = mxUtils::getValue($style, mxConstants::$STYLE_FONTSIZE, mxConstants::$DEFAULT_FONTSIZE) * $this->scale; $color = mxUtils::getValue($style, mxConstants::$STYLE_FONTCOLOR, "black"); $align = mxUtils::getValue($style, mxConstants::$STYLE_ALIGN, "center"); $valign = mxUtils::getValue($style, mxConstants::$STYLE_VERTICAL_ALIGN, "middle"); $style = "position:absolute;" . "overflow:hidden;" . "left:" . ($x - 4) . "px;" . "width:" . $w . "px;" . "height:" . $h . "px;" . "font-family:{$font};" . "font-size:" . $fontSize . "px;" . "color:{$color};"; if ($horizontal) { $style .= "top:" . ($y - 5) . "px;"; } else { $style .= "top:" . ($y - $h) . "px;"; } $string = htmlentities($string); $string = str_replace("\n", "<br>", $string); $this->out("<TABLE STYLE='{$style}'>" . "<TR><TD ALIGN='{$align}' VALIGN='{$valign}'>" . "{$string}</TD></TR></TABLE>"); }
/** * Function: getLabel * * Returns a string or DOM node that represents the label for the given * cell. This implementation uses <convertValueToString> if <labelsVisible> * is true. Otherwise it returns an empty string. */ function getLabel($cell) { $result = ""; if ($cell != null) { $state = $this->view->getState($cell); $style = $state != null ? $state->style : $this->getCellStyle($cell); if ($this->labelsVisible && !mxUtils::getValue($style, mxConstants::$STYLE_NOLABEL, false)) { $result = $this->convertValueToString($cell); } } return $result; }
/** * Function: getPerimeterFunction * * Returns the perimeter function for the given state. */ function getPerimeterFunction($state) { $perimeter = mxUtils::getValue($state->style, mxConstants::$STYLE_PERIMETER); // Converts string values to objects if (is_string($perimeter)) { $tmp = mxStyleRegistry::getValue($perimeter); if ($tmp == null && strpos($perimeter, ".") !== false) { $tmp = mxUtils::evaluate($perimeter); } $perimeter = $tmp; } if ($perimeter instanceof mxPerimeterFunction) { return $perimeter; } return null; }
/** * Function: getConnectionConstraint * * Returns an <mxConnectionConstraint> that describes the given connection * point. This result can then be passed to <getConnectionPoint>. * * Parameters: * * edge - <mxCellState> that represents the edge. * terminal - <mxCellState> that represents the terminal. * source - Boolean indicating if the terminal is the source or target. */ function getConnectionConstraint($edge, $terminal, $source) { $point = null; $x = mxUtils::getValue($edge->style, $source ? mxConstants::$STYLE_EXIT_X : mxConstants::$STYLE_ENTRY_X); if (isset($x)) { $y = mxUtils::getValue($edge->style, $source ? mxConstants::$STYLE_EXIT_Y : mxConstants::$STYLE_ENTRY_Y); if (isset($y)) { $point = new mxPoint($x, $y); } } $perimeter = false; if (isset($point)) { $perimeter = mxUtils::getValue($edge->style, $source ? mxConstants::$STYLE_EXIT_PERIMETER : mxConstants::$STYLE_ENTRY_PERIMETER, true); } return new mxConnectionConstraint($point, $perimeter); }
/** * Function: getTrueTypeFont * * Returns the truetype font to be used to draw the text with the given style. */ static function getTrueTypeFont($style) { return mxUtils::getValue($style, mxConstants::$STYLE_FONTFAMILY, mxConstants::$DEFAULT_FONTFAMILY); }
/** * */ public function apply($bounds, $vertex, $next, $orthogonal) { $direction = $vertex != null ? mxUtils::getValue($vertex->style, mxConstants::$STYLE_DIRECTION) : null; $vertical = $direction == mxConstants::$DIRECTION_NORTH || $direction == mxConstants::$DIRECTION_SOUTH; $x = $bounds->x; $y = $bounds->y; $w = $bounds->width; $h = $bounds->height; $cx = $x + $w / 2; $cy = $y + $h / 2; $start = new mxPoint($x, $y); $corner = new mxPoint($x + $w, $cy); $end = new mxPoint($x, $y + $h); if ($direction == mxConstants::$DIRECTION_NORTH) { $start = end; $corner = new mxPoint($cx, $y); $end = new mxPoint($x + $w, $y + $h); } else { if ($direction == mxConstants::$DIRECTION_SOUTH) { $corner = new mxPoint($cx, $y + $h); $end = new mxPoint($x + $w, $y); } else { if ($direction == mxConstants::$DIRECTION_WEST) { $start = new mxPoint($x + $w, $y); $corner = new mxPoint($x, $cy); $end = new mxPoint($x + $w, $y + $h); } } } $dx = $next->x - $cx; $dy = $next->y - $cy; $alpha = $vertical ? atan2($dx, $dy) : atan2($dy, $dx); $t = $vertical ? Matan2($w, $h) : atan2($h, $w); $base = false; if ($direction == mxConstants::$DIRECTION_NORTH || $direction == mxConstants::$DIRECTION_WEST) { $base = $alpha > -$t && $alpha < $t; } else { $base = $alpha < -pi() + $t || $alpha > pi() - $t; } $result = null; if ($base) { if ($orthogonal && ($vertical && $next->x >= $start->x && $next->x <= $end->x || !$vertical && $next->y >= $start->y && $next->y <= $end->y)) { if ($vertical) { $result = new mxPoint($next->x, $start->y); } else { $result = new mxPoint($start->x, $next->y); } } else { if ($direction == mxConstants::$DIRECTION_NORTH) { $result = new mxPoint($x + $w / 2 + $h * tan($alpha) / 2, $y + $h); } else { if ($direction == mxConstants::$DIRECTION_SOUTH) { $result = new mxPoint($x + $w / 2 - $h * tan($alpha) / 2, $y); } else { if ($direction == mxConstants::$DIRECTION_WEST) { $result = new mxPoint($x + $w, $y + $h / 2 + $w * tan($alpha) / 2); } else { $result = new mxPoint($x, $y + $h / 2 - $w * tan($alpha) / 2); } } } } } else { if ($orthogonal) { $pt = new mxPoint($cx, $cy); if ($next->y >= $y && $next->y <= $y + $h) { $pt->x = $vertical ? $cx : ($direction == mxConstants::$DIRECTION_WEST ? $x + $w : $x); $pt->y = $next->y; } else { if ($next->x >= $x && $next->x <= $x + $w) { $pt->x = $next->x; $pt->y = !$vertical ? $cy : ($direction == mxConstants::$DIRECTION_NORTH ? $y + $h : $y); } } // Compute angle $dx = $next->x - $pt->x; $dy = $next->y - $pt->y; $cx = $pt->x; $cy = $pt->y; } if ($vertical && $next->x <= $x + $w / 2 || !$vertical && $next->y <= $y + $h / 2) { $result = mxUtils::intersection($next->x, $next->y, $cx, $cy, $start->x, $start->y, $corner->x, $corner->y); } else { $result = mxUtils::intersection($next->x, $next->y, $cx, $cy, $corner->x, $corner->y, $end->x, $end->y); } } if ($result == null) { $result = new mxPoint($cx, $cy); } return $result; }
/** * Function: drawLabel * * Draws the specified label using the canvas. */ function drawLabel($isEdge, $attrs) { $label = mxUtils::getValue($attrs, "label"); if (isset($label) && strlen($label) > 0) { $offset = new mxPoint(mxUtils::getNumber($attrs, "dx"), mxUtils::getNumber($attrs, "dy")); $vertexBounds = !$isEdge ? new mxRectangle(mxUtils::getNumber($attrs, "x"), mxUtils::getNumber($attrs, "y"), mxUtils::getNumber($attrs, "width"), mxUtils::getNumber($attrs, "height")) : null; $bounds = mxUtils::getLabelPaintBounds($label, $attrs, mxUtils::getValue($attrs, "html", false), $offset, $vertexBounds, $this->scale); $this->canvas->drawLabel($label, $bounds->x, $bounds->y, $bounds->width, $bounds->height, $attrs, false); } }