(self, graph_xml)
| 662 | raise EasyGraphError("No <graph> element in GEXF file.") |
| 663 | |
| 664 | def make_graph(self, graph_xml): |
| 665 | edgedefault = graph_xml.get("defaultedgetype", None) |
| 666 | if edgedefault == "directed": |
| 667 | G = eg.MultiDiGraph() |
| 668 | else: |
| 669 | G = eg.MultiGraph() |
| 670 | |
| 671 | # graph attributes |
| 672 | graph_name = graph_xml.get("name", "") |
| 673 | if graph_name != "": |
| 674 | G.graph["name"] = graph_name |
| 675 | graph_start = graph_xml.get("start") |
| 676 | if graph_start is not None: |
| 677 | G.graph["start"] = graph_start |
| 678 | graph_end = graph_xml.get("end") |
| 679 | if graph_end is not None: |
| 680 | G.graph["end"] = graph_end |
| 681 | graph_mode = graph_xml.get("mode", "") |
| 682 | if graph_mode == "dynamic": |
| 683 | G.graph["mode"] = "dynamic" |
| 684 | else: |
| 685 | G.graph["mode"] = "static" |
| 686 | |
| 687 | # timeformat |
| 688 | self.timeformat = graph_xml.get("timeformat") |
| 689 | if self.timeformat == "date": |
| 690 | self.timeformat = "string" |
| 691 | |
| 692 | # node and edge attributes |
| 693 | attributes_elements = graph_xml.findall(f"{{{self.NS_GEXF}}}attributes") |
| 694 | # dictionaries to hold attributes and attribute defaults |
| 695 | node_attr = {} |
| 696 | node_default = {} |
| 697 | edge_attr = {} |
| 698 | edge_default = {} |
| 699 | for a in attributes_elements: |
| 700 | attr_class = a.get("class") |
| 701 | if attr_class == "node": |
| 702 | na, nd = self.find_gexf_attributes(a) |
| 703 | node_attr.update(na) |
| 704 | node_default.update(nd) |
| 705 | G.graph["node_default"] = node_default |
| 706 | elif attr_class == "edge": |
| 707 | ea, ed = self.find_gexf_attributes(a) |
| 708 | edge_attr.update(ea) |
| 709 | edge_default.update(ed) |
| 710 | G.graph["edge_default"] = edge_default |
| 711 | else: |
| 712 | raise # unknown attribute class |
| 713 | |
| 714 | # Hack to handle Gephi0.7beta bug |
| 715 | # add weight attribute |
| 716 | ea = {"weight": {"type": "double", "mode": "static", "title": "weight"}} |
| 717 | ed = {} |
| 718 | edge_attr.update(ea) |
| 719 | edge_default.update(ed) |
| 720 | G.graph["edge_default"] = edge_default |
| 721 |
no test coverage detected