forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxCodecTest.php
More file actions
75 lines (64 loc) · 1.86 KB
/
mxCodecTest.php
File metadata and controls
75 lines (64 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Copyright (c) 2006, Gaudenz Alder
*/
include_once("../src/mxServer.php");
/**
* 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);
}
}
// 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 = "verah";
putenv("GDFONTPATH=".realpath("../examples/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::$TTF_ENABLED = false;
main();
?>