Codec Class
This class converts the Editor's XML format into a flat javascript format which is inserted into the Neo4j database.
1. Load XML
2. Add all nodes as children to the layers (unpack the <mxCell> from the <object> tag)
the <object> tag is used to wrap an mxCell with its attributes
3. Remove groups
4. Edges (There will be no edge without token -> drop layer information)
- edges don't work inter groups, but they can be intra groups
-> they have to be unwrapped as well
5. Flatten the hierarchical tree
- merge mxCells with their layers to obtain the layer-attributes
6. Collect all possible attributes
(1) Drop following attributes
- Graph
- grid
- gridSize
- guides
- toolTips
- connect
- arrows
- fold
- page
- pageScale
(2) Parse the style attribute in order to retrieve the following attributes
- MxCell
- tokenType
-> first: read the saved mxgraph with xml2js into a javscript object
-> then make the validity checks
- is the structure of the xml correct
- mxGraph
- root
- cell
- geometry
- object
- cell
- geometry
- are all necessary attributes at hand
- mxGraphModel
- dx
- dy
- pageWidth
- pageHeight
- mxCell
- id
- parent
-> then drop unnecessary attributes
-> export as GraphML (http://graphml.graphdrawing.org/primer/graphml-primer.html)
This class was developed by Test Driven Development.
Item Index
Methods
Methods
add_all_completed_fragments_to_neo4j
()
Promise
Adds all fragments that have the flag completed set to true to the database There is SHA1 hash comparing done here in order to eliminate unnecessary computations.
Returns:
get_node_by_id
-
root -
id
Works on a mxGraph xml2js-object Finds a node given an id
Parameters:
-
rootObjectmxGraph tree
-
idObject
Returns:
get_nodes_by_parent_id
-
root -
parent_id
Works on a mxGraph xml2js-object Gets all nodes with a given parent
Parameters:
-
rootObject -
parent_idObject
Returns:
mxgraph_to_flattened_object
-
filename
Converts an mxGraph to a flat object structured as follows
graph.mxGraphModel.data.token1 graph.mxGraphModel.data.token2 graph.mxGraphModel.data.edge1
Parameters:
-
filenameObject
mxgraph_to_graphml
-
filename
Converts a mxGraph into the GraphML format
It removes groups and is not necessary for the code Only nice to have
Parameters:
-
filenameObject
mxgraph_to_layered_object
-
filename
Converts the mxGraph to an object structured ad follows
obj.mxGraphModel.layer1.node1
It removes groups
Parameters:
-
filenameObject
mxgraph_to_neo4j
-
image_id -
fragment_id -
overwrite_xml_path
Loads an mxGraph over the flat xml2js-object into the neo4j database
Parameters:
-
image_idObject -
fragment_idObject -
overwrite_xml_pathObjectif you don't want to load the standard xml file_path for the fragment use this
mxgraph_to_object
-
filename
Parses the mxGraph XML file into a javascript object
Parameters:
-
filenamePromisethe resource to load return
Properties
builder
Object
The xml2js builder
This object can create xml files
parser
Object
The xml2js parser
