Commit d7948acb authored by Fabien Maniere's avatar Fabien Maniere

export to GEXF: adding the weight attribute to all nodes

parent d937e72e
Pipeline #7224 passed with stages
in 75 minutes and 17 seconds
......@@ -51,20 +51,30 @@ graphToXML (G.Graph { .. }) = root _graph_nodes _graph_edges
desc = XML.tag "description" mempty $ XML.content "Gargantext gexf file"
graph :: (Monad m) => [G.Node] -> [G.Edge] -> ConduitT i XML.Event m ()
graph gn ge = XML.tag "graph" params $ (nodes gn) <> (edges ge)
graph gn ge = XML.tag "graph" params $ graphAttributes <> (nodes gn) <> (edges ge)
where
params = XML.attr "mode" "static"
<> XML.attr "defaultedgetype" "directed"
graphAttributes :: (Monad m) => ConduitT i XML.Event m ()
graphAttributes = XML.tag "attributes" graphAttributesParams $ graphAttributeWeight
where
graphAttributesParams = XML.attr "class" "node"
graphAttributeWeight = XML.tag "attribute" attrWeightParams $ XML.content ""
attrWeightParams = XML.attr "id" "0"
<> XML.attr "title" "weight"
<> XML.attr "type" "integer"
nodes :: (Monad m) => [G.Node] -> ConduitT i XML.Event m ()
nodes gn = XML.tag "nodes" mempty (yieldMany gn .| awaitForever node')
node' :: (Monad m) => G.Node -> ConduitT i XML.Event m ()
node' (G.Node { .. }) = XML.tag "node" params (XML.tag "viz:size" sizeParams $ XML.content "")
-- node' (G.Node { .. }) = XML.tag "node" params (XML.tag "viz:size" sizeParams $ XML.content "")
node' (G.Node { .. }) = XML.tag "node" params $ XML.tag "attvalues" mempty $ XML.tag "attvalue" sizeParams mempty
where
params = XML.attr "id" node_id
<> XML.attr "label" node_label
<> XML.attr "weight" (show node_size)
sizeParams = XML.attr "value" (show node_size)
sizeParams = XML.attr "for" "0"
<> XML.attr "value" (show node_size)
edges :: (Monad m) => [G.Edge] -> ConduitT i XML.Event m ()
edges ge = XML.tag "edges" mempty (yieldMany ge .| awaitForever edge')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment