Exemple #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);
    } 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);
}
Exemple #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, 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);
}
Exemple #3
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);
}
Exemple #4
0
    $xml = addslashes(htmlentities(str_replace("\n", "
", $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;
}
// Uses a local font so that all examples work on all platforms. This can be
// changed to vera on Mac or arial on Windows systems.
mxConstants::$DEFAULT_FONTFAMILY = "ttf/verah.ttf";
// If you can't get the fonts to render try using one of the following:
//mxConstants::$DEFAULT_FONTFAMILY = "C:\WINDOWS\Fonts\arial.ttf";
//mxConstants::$DEFAULT_FONTFAMILY = "verah"; putenv("GDFONTPATH=".realpath("./ttf"));
//mxConstants::$TTF_ENABLED = false;
// Handles save image request
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $xml = urldecode($_POST["xml"]);
    // Creates a PNG representation of the file
    $image = mxGraphViewImageReader::convert($xml, "#FFFFFF");
    header("Content-Type: image/png");
    echo mxUtils::encodeImage($image);
} else {
    main();
}
Exemple #5
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