Example #1
0
/**
 * Function: main
 * 
 * Creates a graph using the API and converts it into a PNG image.
 */
function main()
{
    // Creates graph with model
    $model = new mxGraphModel();
    $graph = new mxGraph($model);
    $parent = $graph->getDefaultParent();
    // Adds cells into the model
    $model->beginUpdate();
    try {
        $v1 = $graph->insertVertex($parent, null, "Hello,", 20, 20, 80, 60, "shape=triangle;perimeter=trianglePerimeter");
        $v2 = $graph->insertVertex($parent, null, "World!", 200, 150, 80, 60, "shape=ellipse;perimeter=ellipsePerimeter");
        $v3 = $graph->insertVertex($parent, null, "Hello,", 200, 20, 80, 30);
        $e1 = $graph->insertEdge($parent, null, "", $v1, $v2, "edgeStyle=elbowEdgeStyle;elbow=horizontal;" . "exitX=0.5;exitY=1;exitPerimeter=1;entryX=0;entryY=0;entryPerimeter=1;");
        $e2 = $graph->insertEdge($parent, null, "", $v3, $v2, "edgeStyle=elbowEdgeStyle;elbow=horizontal;orthogonal=0;" . "entryX=0;entryY=0;entryPerimeter=1;");
    } catch (Exception $e) {
        $model->endUpdate();
        throw $e;
    }
    $model->endUpdate();
    // Sends PNG image to client
    $image = $graph->createImage(null, "#FFFFFF");
    // Creates an interlaced image for better loading in the browser
    //imageInterlace($image, 1);
    // Marks background color as being transparent
    //imageColorTransparent($image, imageColorAllocate($image, 255, 255, 255));
    header("Content-Type: image/png");
    echo mxUtils::encodeImage($image);
}
Example #2
0
/**
 * Function: main
 * 
 * Creates a graph using the API and converts it into a PNG image.
 */
function main()
{
    // Creates graph with model
    $model = new mxGraphModel();
    $graph = new mxGraph($model);
    $parent = $graph->getDefaultParent();
    // Adds cells into the model
    $model->beginUpdate();
    try {
        $v1 = $graph->insertVertex($parent, null, "Hello,", 20, 20, 80, 30);
        $v2 = $graph->insertVertex($parent, null, "World!", 200, 150, 80, 30);
        $e1 = $graph->insertEdge($parent, null, "e1", $v1, $v2);
    } catch (Exception $e) {
        $model->endUpdate();
        throw $e;
    }
    $model->endUpdate();
    // Sends PNG image to client
    $image = $graph->createImage(null, "#FFFFFF");
    // Creates an interlaced image for better loading in the browser
    //imageInterlace($image, 1);
    // Marks background color as being transparent
    //imageColorTransparent($image, imageColorAllocate($image, 255, 255, 255));
    header("Content-Type: image/png");
    echo mxUtils::encodeImage($image);
}
Example #3
0
/**
 * Function: main
 * 
 * Demonstrates the deployment of a graph which is created on the server side
 * and then deployed with the client library in a single response. This is done
 * by replacing the %graph% placeholder in the javascript/example/template.html
 * file with the XML representation of the graph that was created on the server.
 * 
 * Point your browser to http://localhost/graph to fetch the HTML file. Make sure
 * to deploy the mxgraph distribution directory to the webroot for this example
 * to work, or replace the mxBasePath and URL for the mxClient.js in the
 * template to match your environment.
 *
 * This example returns an HTML page when the client issues a get request. The
 * readme in the php directory explains how to run this example.
 * 
 * The template.html file is used by this example. In main a graph is created
 * and the XML of the graph obtained by:
 * 
 *   $enc = new mxCodec();
 *   $xmlNode = $enc->encode($model);
 *   $xml = $xmlNode->ownerDocument->saveXML($xmlNode);
 * 
 * The template.html is then loaded as a string and instances of %graph% are
 * replaced with the XML of the graph. In the template.html the following line
 * defines the page body:
 * 
 *   <body onload="main(document.getElementById('graphContainer'), '%graph%');">
 * 
 * So the XML string of the graph becomes the second parameter of the main
 * function. When the template.html page is loaded in the browser, the main
 * function is called and within that function these lines:
 * 
 *   var doc = mxUtils.parseXml(xml);
 *   var codec = new mxCodec(doc);
 *   codec.decode(doc.documentElement, graph.getModel());
 * 
 * insert the XML into the graph model and that graph will then display.
 */
function main()
{
    // True-type fonts not needed in this example
    mxConstants::$TTF_ENABLED = false;
    // Creates the graph on the server-side
    $graph = new mxGraph();
    $model = $graph->getModel();
    $parent = $graph->getDefaultParent();
    $model->beginUpdate();
    try {
        $v1 = $graph->insertVertex($parent, null, "Hello", 20, 20, 80, 30);
        $v2 = $graph->insertVertex($parent, null, "World", 200, 150, 80, 30);
        $graph->insertEdge($parent, null, "", $v1, $v2);
    } catch (Exception $e) {
        $model->endUpdate();
        throw $e;
    }
    $model->endUpdate();
    // Turns the graph into XML data
    $enc = new mxCodec();
    $xmlNode = $enc->encode($model);
    $xml = addslashes(htmlentities(str_replace("\n", "&#xa;", $xmlNode->ownerDocument->saveXML($xmlNode))));
    // Loads the template into a single string
    $template = mxUtils::readFile("template.html");
    // Replaces the placeholder in the template with the XML data
    // which is then parsed into the graph model. Note: In a production
    // environment you should use a template engine instead.
    $page = str_replace("%graph%", $xml, $template);
    // Makes sure there is no caching on the client side
    header("Pragma: no-cache");
    // HTTP 1.0
    header("Cache-control: private, no-cache, no-store");
    header("Expires: 0");
    echo $page;
}
Example #4
0
/**
 * Function: main
 * 
 * Reads a graph view XML file and creates HTML on the fly,
 * ie. without creating a graph and model for it.
 */
function main()
{
    // Reads the XML representation of a graph_view_! If you need to
    // create an image for a graph_model_ then use the following code:
    //
    // $doc = mxUtils::parseXml($xml);
    // $dec = new mxCodec($doc);
    // $dec->decode($doc->documentElement, $graph->getModel());
    //
    // $image = $graph->createImage(null, "#FFFFFF");
    $filename = "diagrams/graphview.xml";
    //echo mxGraphViewHtmlReader::convertFile($filename);
    // Creates a PNG representation of the file
    $image = mxGraphViewImageReader::convertFile($filename, "#FFFFFF");
    // Creates an interlaced image for better loading in the browser
    //imageInterlace($image, 1);
    // Marks background color as being transparent
    //imageColorTransparent($image, imageColorAllocate($image, 255, 255, 255));
    header("Content-Type: image/png");
    echo mxUtils::encodeImage($image);
}
Example #5
0
/**
 * Function: main
 * 
 * Creates a graph using the API and converts it into a PNG image.
 */
function main()
{
    // Creates graph with model
    $model = new mxGraphModel();
    $graph = new mxGraph($model);
    $parent = $graph->getDefaultParent();
    // Adds cells into the model
    $model->beginUpdate();
    try {
        $v1 = $graph->insertVertex($parent, null, "Hello", 20, 20, 80, 30);
        $v2 = $graph->insertVertex($parent, null, "World!", 200, 150, 80, 30);
        $e1 = $graph->insertEdge($parent, null, "e1", $v1, $v2);
        $e1->getGeometry()->points = array(new mxPoint(10, 10));
        $v3 = $graph->insertVertex($e1, null, "v3", 0, 0, 40, 40, "shape=ellipse");
        $v3->getGeometry()->relative = true;
        $v3->getGeometry()->offset = new mxPoint(-20, -20);
        $model->add($parent, $e1, 0);
    } catch (Exception $e) {
        $model->endUpdate();
        throw $e;
    }
    $model->endUpdate();
    $doc = mxUtils::createXmlDocument();
    $enc = new mxCodec($doc);
    $node = $enc->encode($model);
    $xml1 = $doc->saveXML($node);
    $doc = mxUtils::parseXml($xml1);
    $dec = new mxCodec($doc);
    $dec->decode($doc->documentElement, $model);
    $doc = mxUtils::createXmlDocument();
    $enc = new mxCodec($doc);
    $node = $enc->encode($model);
    $xml2 = $doc->saveXML($node);
    if ($xml1 == $xml2) {
        echo "Test Passed: " . htmlentities($xml1);
    } else {
        echo "Test Failed: <br>xml1=" . htmlentities($xml1) . "<br>xml2=" . htmlentities($xml2);
    }
}
 /**
  * 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);
     }
 }
 /**
  * Override <mxObjectCodec.decode>.
  */
 function decode($dec, $node, $into = null)
 {
     $id = $node->getAttribute("id");
     $obj = in_array($id, $dec->objects) ? $dec->objects[$id] : null;
     if (!isset($obj)) {
         if (isset($into)) {
             $obj = $into;
         } else {
             $tmp = get_class($this->template);
             $obj = new $tmp();
         }
         if (isset($id)) {
             $dec->putObject($id, $obj);
         }
     }
     $node = $node->firstChild;
     while (isset($node)) {
         if (!$this->processInclude($dec, $node, $obj) && $node->nodeName == "add") {
             $as = $node->getAttribute("as");
             if (strlen($as) > 0) {
                 $extend = $node->getAttribute("extend");
                 $style = strlen($extend) > 0 && isset($obj->styles[$extend]) ? array_slice($obj->styles[$extend], 0) : null;
                 if (!isset($style)) {
                     $style = array();
                 }
                 $entry = $node->firstChild;
                 while (isset($entry)) {
                     if ($entry->nodeType == XML_ELEMENT_NODE) {
                         $key = $entry->getAttribute("as");
                         if ($entry->nodeName == "add") {
                             $text = $entry->textContent;
                             $value = null;
                             if (isset($text) && strlen($text) > 0) {
                                 $value = mxUtils::evaluate($text);
                             } else {
                                 $value = $entry->getAttribute("value");
                             }
                             if ($value != null) {
                                 $style[$key] = $value;
                             }
                         } else {
                             if ($entry->nodeName == "remove") {
                                 unset($style[$key]);
                             }
                         }
                     }
                     $entry = $entry->nextSibling;
                 }
                 $obj->putCellStyle($as, $style);
             }
         }
         $node = $node->nextSibling;
     }
     return $obj;
 }
 /**
  * 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;
 }
    return $n == "Folder" || $n == "Stock" || $n == "Converter" || $n == "Parameter" || $n == "Link" || $n == "Flow" || $n == "Setting";
}
function connectionValue($cell)
{
    if (is_null($cell) || $cell->value->nodeName == "Folder") {
        return "";
    } else {
        return $cell->id;
    }
}
function getID($value)
{
    return $value->id;
}
$graph = new mxGraph();
$insightdoc = mxUtils::parseXml($modelData);
$insightdec = new mxCodec($insightdoc);
$insightdec->decode($insightdoc->documentElement, $graph->model);
function orig($cell)
{
    if (is_null($cell) || $cell->value->nodeName == "Picture") {
        return null;
    }
    if ($cell->value->nodeName == "Ghost") {
        global $graph;
        $cellTab = $graph->model->getCells();
        return $cellTab[$cell->getAttribute("Source")];
    } else {
        return $cell;
    }
}
Example #10
0
 /**
  * Function: setCellStyles
  * 
  * Sets the key to value in the styles of the given cells. This will modify
  * the existing cell styles in-place and override any existing assignment
  * for the given key. If no cells are specified, then the selection cells
  * are changed. If no value is specified, then the respective key is
  * removed from the styles.
  * 
  * Parameters:
  * 
  * key - String representing the key to be assigned.
  * value - String representing the new value for the key.
  * cells - Array of <mxCells> to change the style for.
  */
 function setCellStyles($key, $value, $cells)
 {
     mxUtils::setCellStyles($this->model, $cells, $key, $value);
 }
 /**
  * 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>");
 }
Example #12
0
 /**
  *
  */
 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;
 }
Example #13
0
 *     is one of html, png or jpg.
 */
// Includes the mxGraph library
include_once "../src/mxServer.php";
// Gets the format parameter from the URL
$format = $_GET["format"];
// Gets the XML parameter from the POST request
$xml = stripslashes($_POST["xml"]);
if (isset($xml)) {
    // Creates an image for the given format
    if (isset($format)) {
        // Displays a saveAs dialog on the client
        header("Content-Disposition: attachment; filename=\"diagram.{$format}\"");
        header("Content-Type: image/{$format}");
        $image = mxGraphViewImageReader::convert($xml, "#FFFFFF");
        echo mxUtils::encodeImage($image, $format);
    } else {
        // Stores the xml in a local file
        $ext = "tmp";
        if (!isset($HTTP_GET_VARS["draft"])) {
            $ext = "xml";
            unlink("diagram.tmp");
        }
        $filename = "diagram.{$ext}";
        $fh = fopen($filename, "w");
        fputs($fh, stripslashes($xml));
        fclose($fh);
        chmod($filename, 0777);
    }
} else {
    // Sends the diagram file to the client if
Example #14
0
 /**
  * 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;
             }
         }
     }
 }
Example #15
0
 /**
  * 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);
 }
Example #16
0
 /**
  * Function: getElementById
  *
  * Returns the element with the given ID from
  * <document>. The optional attr argument specifies
  * the name of the ID attribute. Default is "id".
  * The XPath expression used to find the element is
  * //*[@attr='arg'] where attr is the name of the
  * ID attribute and arg is the given id.
  *
  * Parameters:
  *
  * id - String that contains the ID.
  * attr - Optional string for the attributename.
  * Default is "id".
  */
 function getElementById($id, $attr = "id")
 {
     $expr = "//*[@{$attr}='{$id}']";
     return mxUtils::selectSingleNode($this->document, $expr);
 }
Example #17
0
    // Deletes existing buffer
    if (is_file($filename)) {
        unlink($filename);
    }
    touch($filename);
    touch($filename . ".timestamp");
    chmod($filename, 0777);
} else {
    // Gets the XML parameter from the POST request and converts all linefeeds
    // into a HTML entity. This is required for correct handling of the XML on
    // the client side.
    if (isset($_POST["xml"])) {
        $xml = str_replace("\n", "&#xa;", stripslashes($_POST["xml"]));
        // TODO: Take only the edits from the XML
        $edits = "";
        $doc = mxUtils::parseXml($xml);
        $child = $doc->documentElement;
        if ($child->nodeName == "message") {
            $child = $child->firstChild;
            while ($child != null) {
                if ($child->nodeName == "delta") {
                    $edit = $child->firstChild;
                    while ($edit != null) {
                        if ($edit->nodeName == "edit") {
                            $edits .= $doc->saveXML($edit);
                        }
                        $edit = $edit->nextSibling;
                    }
                }
                $child = $child->nextSibling;
            }
Example #18
0
 /**
  * Function: processInclude
  *
  * Returns true if the given node is an include directive and
  * executes the include by decoding the XML document. Returns
  * false if the given node is not an include directive.
  *
  * Parameters:
  *
  * dec - <mxCodec> that controls the encoding/decoding process.
  * node - XML node to be checked.
  * into - Optional object to pass-thru to the codec.
  */
 function processInclude($dec, $node, $into)
 {
     if ($node->nodeName == "include") {
         $name = $node->getAttribute("name");
         if (isset($name)) {
             try {
                 $xml = mxUtils::loadXmlDocument($name)->documentElement;
                 if (isset($xml)) {
                     $dec->decode($xml, $into);
                 }
             } catch (Exception $e) {
                 // ignore
             }
         }
         return true;
     }
     return false;
 }
Example #19
0
 /**
  * Function: setRoot
  *
  */
 function getCell($id)
 {
     $result = null;
     if ($this->cells != null) {
         $result = mxUtils::getValue($this->cells, $id);
     }
     return $result;
 }
Example #20
0
 /**
  * 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);
 }
Example #21
0
 /**
  * Function: insertEdge
  *
  * Inserts the specified edge into the edge array and returns the edge.
  * Will update the respective terminal reference of the edge.
  * 
  * Parameters:
  * 
  * edge - <mxCell> to be inserted into the edge array.
  * outgoing - Boolean that specifies if the edge is outgoing.
  */
 function insertEdge($edge, $outgoing)
 {
     if (isset($edge)) {
         $edge->removeFromTerminal($outgoing);
         $edge->setTerminal($this, $outgoing);
         if ($this->edges == null || $edge->getTerminal(!$outgoing) !== $this || mxUtils::indexOf($this->edges, $edge) < 0) {
             if ($this->edges == null) {
                 $this->edges = array();
             }
             array_push($this->edges, $edge);
         }
     }
     return $edge;
 }
Example #22
0
 /**
  * 
  */
 public function apply($state, $source, $target, $points, &$result)
 {
     $view = $state->view;
     $pt = $points != null && sizeof($points) > 0 ? $points[0] : null;
     $pts = $state->absolutePoints;
     $p0 = $pts[0];
     $pe = $pts[sizeof($pts) - 1];
     if ($pt != null) {
         $pt = $view->transformControlPoint($state, $pt);
     }
     if (isset($p0)) {
         $source = new mxCellState();
         $source->x = $p0->x;
         $source->y = $p0->y;
     }
     if (isset($pe)) {
         $target = new mxCellState();
         $target->x = $pe->x;
         $target->y = $pe->y;
     }
     if (isset($source) && isset($target)) {
         $t = max($source->y, $target->y);
         $b = min($source->y + $source->height, $target->y + $target->height);
         $x = $view->getRoutingCenterX($source);
         if ($pt != null && $pt->x >= $source->x && $pt->x <= $source->x + $source->width) {
             $x = $pt->x;
         }
         $y = $pt != null ? $pt->y : $b + ($t - $b) / 2;
         if (!mxUtils::contains($target, $x, $y) && !mxUtils::contains($source, $x, $y)) {
             array_push($result, new mxPoint($x, $y));
         }
         if ($pt != null && $pt->x >= $target->x && $pt->x <= $target->x + $target->width) {
             $x = $pt->x;
         } else {
             $x = $view->getRoutingCenterX($target);
         }
         if (!mxUtils::contains($target, $x, $y) && !mxUtils::contains($source, $x, $y)) {
             array_push($result, new mxPoint($x, $y));
         }
         if (sizeof($result) == 1) {
             if ($pt == null) {
                 array_push($result, new mxPoint($x, $y));
             } else {
                 $l = max($source->x, $target->x);
                 $r = min($source->x + $source->width, $target->x + $target->width);
                 array_push($result, new mxPoint($r + ($r - $l) / 2, $y));
             }
         }
     }
 }
Example #23
0
 /**
  * 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;
 }