<s> @ package ( '<STR_LIT>' ) <EOL> class Base : <EOL> __slots__ = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:label>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def __init__ ( self ) : <EOL> pass <EOL> def update_properties ( self , data ) : <EOL> for k , v in items ( data ) : <EOL> self [ k ] = v <EOL> @ package ( '<STR_LIT>' ) <EOL> class Node ( Base ) : <EOL> __slots__ = ( <EOL> '<STR_LIT:name>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:x>' , <EOL> '<STR_LIT:y>' , <EOL> '<STR_LIT:width>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def __init__ ( self , name ) : <EOL> super ( ) . __init__ ( ) <EOL> self . name = name <EOL> def update_properties ( self , val ) : <EOL> super ( ) . update_properties ( val ) <EOL> if val . pos : <EOL> self . parse_pos ( ) <EOL> if val . lp : <EOL> self . parse_lp ( ) <EOL> def parse_pos ( self ) : <EOL> x , y = self . pos . split ( '<STR_LIT:U+002C>' ) <EOL> self . x = float ( x ) <EOL> self . y = float ( y ) <EOL> def parse_lp ( self ) : <EOL> x , y = self . lp . split ( '<STR_LIT:U+002C>' ) <EOL> self . label_pos = Point ( float ( x ) , float ( y ) ) <EOL> class Point : <EOL> __slots__ = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] <EOL> def __init__ ( self , x , y ) : <EOL> self . x = x <EOL> self . y = y <EOL> @ package ( '<STR_LIT>' ) <EOL> class Edge ( Base ) : <EOL> __slots__ = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:path>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def __init__ ( self , snode , enode ) : <EOL> self . startnode = snode <EOL> self . endnode = enode <EOL> def update_properties ( self , val ) : <EOL> super ( ) . update_properties ( val ) <EOL> if val . pos : <EOL> self . parse_pos ( ) <EOL> def parse_pos ( self ) : <EOL> arr = self . pos . split ( '<STR_LIT:U+0020>' ) <EOL> self . path = [ ] <EOL> self . startpoint = None <EOL> self . endpoint = None <EOL> for item in values ( arr ) : <EOL> if item . charAt ( <NUM_LIT:0> ) == '<STR_LIT:e>' or item . charAt ( <NUM_LIT:0> ) == '<STR_LIT:s>' : <EOL> _c , x , y = item . split ( '<STR_LIT:U+002C>' ) <EOL> pt = Point ( float ( x ) , float ( y ) ) <EOL> if _c == '<STR_LIT:e>' : <EOL> self . endpoint = pt <EOL> else : <EOL> self . startpoint = pt <EOL> continue <EOL> x , y = item . split ( '<STR_LIT:U+002C>' ) <EOL> self . path . push ( Point ( float ( x ) , float ( y ) ) ) <EOL> @ package ( '<STR_LIT>' ) <EOL> class Subgraph ( Base ) : <EOL> __slots__ = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def __init__ ( self , name , parent ) : <EOL> super ( ) . __init__ ( ) <EOL> self . name = name <EOL> self . parent = parent <EOL> self . node_defaults = { } <EOL> self . edge_defaults = { } <EOL> self . nodes = { } <EOL> self . edges = [ ] <EOL> self . subgraphs = [ ] <EOL> self . directed = self . parent . directed <EOL> self . update_node_defaults ( self . parent . node_defaults ) <EOL> self . update_edge_defaults ( self . parent . edge_defaults ) <EOL> def update_node_defaults ( self , params ) : <EOL> for k , v in items ( params ) : <EOL> self . node_params [ k ] = v <EOL> def update_edge_defaults ( self , params ) : <EOL> for k , v in items ( params ) : <EOL> self . edge_params [ k ] = v <EOL> def add_subgraph ( self , name ) : <EOL> gr = Subgraph ( name , self ) <EOL> self . subgraphs . push ( gr ) <EOL> return gr <EOL> def add_edge ( self , start , end , properties ) : <EOL> edge = self . parent . add_edge ( start , end , properties ) <EOL> self . edges . push ( edge ) <EOL> return edge <EOL> def add_node ( self , name , properties ) : <EOL> node = self . parent . add_node ( name , properties ) <EOL> self . nodes [ name ] = node <EOL> return node <EOL> @ package ( '<STR_LIT>' ) <EOL> class AnonSubgraph ( Subgraph ) : <EOL> def __init__ ( self , parent ) : <EOL> super ( ) . __init__ ( None , parent ) <EOL> @ package ( '<STR_LIT>' ) <EOL> class Graph ( Base ) : <EOL> __slots__ = ( <EOL> '<STR_LIT:name>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:size>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def __init__ ( self , name ) : <EOL> super ( ) . __init__ ( ) <EOL> self . name = name <EOL> self . node_defaults = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . edge_defaults = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> self . nodes = { } <EOL> self . edges = [ ] <EOL> self . subgraphs = [ ] <EOL> self . directed = False <EOL> def update_properties ( self , val ) : <EOL> super ( ) . update_properties ( val ) <EOL> if val . bb and self . size or val . size and self . bb : <EOL> l , t , r , b = self . bb . split ( '<STR_LIT:U+002C>' ) <EOL> w , h = self . size . split ( '<STR_LIT:U+002C>' ) <EOL> self . scalex = r / w <EOL> self . scaley = b / h <EOL> def update_node_defaults ( self , params ) : <EOL> for k , v in items ( params ) : <EOL> self . node_defaults [ k ] = v <EOL> def update_edge_defaults ( self , params ) : <EOL> for k , v in items ( params ) : <EOL> self . edge_defaults [ k ] = v <EOL> def add_subgraph ( self , name ) : <EOL> gr = Subgraph ( name , self ) <EOL> self . subgraphs . push ( gr ) <EOL> return gr <EOL> def add_anonsub ( self ) : <EOL> gr = AnonSubgraph ( self ) <EOL> self . subgraphs . push ( gr ) <EOL> return gr <EOL> def add_edge ( self , start , end , properties ) : <EOL> snode = self . nodes [ start ] <EOL> if not snode : <EOL> snode = Node ( start ) <EOL> self . nodes [ start ] = snode <EOL> enode = self . nodes [ end ] <EOL> if not enode : <EOL> enode = Node ( end ) <EOL> self . nodes [ end ] = enode <EOL> edge = Edge ( snode , enode ) <EOL> edge . update_properties ( self . edge_defaults ) <EOL> edge . update_properties ( properties ) <EOL> self . edges . push ( edge ) <EOL> return edge <EOL> def add_node ( self , name , properties ) : <EOL> node = self . nodes [ name ] <EOL> if not node : <EOL> node = Node ( name ) <EOL> self . nodes [ name ] = node <EOL> node . update_properties ( self . node_defaults ) <EOL> node . update_properties ( properties ) <EOL> return node <EOL> @ package ( '<STR_LIT>' ) <EOL> class Digraph ( Graph ) : <EOL> __slots__ = [ ] <EOL> def __init__ ( self , name ) : <EOL> super ( ) . __init__ ( name ) <EOL> self . directed = True </s>
