コード例 #1
0
ファイル: fixedpoints.php プロジェクト: yangchaogit/mxgraph
/**
 * 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);
}
コード例 #2
0
ファイル: deployment.php プロジェクト: yangchaogit/mxgraph
/**
 * 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;
}
コード例 #3
0
ファイル: graph.php プロジェクト: maojinhui/mxgraph
/**
 * 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);
}
コード例 #4
0
ファイル: backend.php プロジェクト: maojinhui/mxgraph
/**
 * Creates a graph using the API and returns the XML.
 */
function createGraph()
{
    $id = $_GET["id"];
    error_log("Requested id=" . $id);
    // Creates the graph on the server-side
    $graph = new mxGraph();
    $model = $graph->getModel();
    $parent = $graph->getDefaultParent();
    $model->beginUpdate();
    $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);
    $model->endUpdate();
    $enc = new mxCodec();
    $xmlNode = $enc->encode($model);
    return str_replace("\n", "&#xa;", $xmlNode->ownerDocument->saveXML($xmlNode));
}
コード例 #5
0
ファイル: mxCodecTest.php プロジェクト: yangchaogit/mxgraph
/**
 * 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);
    }
}