示例#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, 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);
    }
}
    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;
    }
}
示例#3
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;
            }