20
20
def uri_to_dot_id (uri ):
21
21
return str (hash (uri )).replace ("-" , "d" )
22
22
23
- def make_table_popup_href (head_html ):
23
+ def make_table_popup_href (head_html , popup_output ):
24
24
if head_html is None :
25
25
return ""
26
26
@@ -30,31 +30,34 @@ def make_table_popup_href(head_html):
30
30
with tempfile .NamedTemporaryFile (dir = temp_dir , suffix = '.html' , delete = False ) as temp_fp :
31
31
popup_size = (800 , 200 )
32
32
temp_fp .write (head_html .toPython ().replace ("<" , "<" ).replace (">" , ">" ).replace (""" , "'" ).replace (" " , "\n " ).encode ('ascii' ))
33
- href = f"""href="javascript :
34
- /* alert(location.pathname.match(/.*\//) + ' \n ' + ' { temp_fp . name } ' + ' \n ' + ' { fstriplestore . triple_store . output_dir } '); */
35
- {{ window.open(location.pathname.match(/.*\//) + 'tmp/' + '{ os .path .basename (temp_fp .name )} ', '_blank', 'width={ popup_size [0 ]} ,height={ popup_size [1 ]} '); }}
33
+ if popup_output :
34
+ href = f"""href="javascript:
35
+ {{ window.open(location.pathname.match(/.*\//) + 'tmp/' + '{ os .path .basename (temp_fp .name )} ', '_blank', 'width={ popup_size [0 ]} ,height={ popup_size [1 ]} '); }}
36
36
"
37
- """
37
+ """
38
+ else :
39
+ href = 'href="tmp/' + os .path .basename (temp_fp .name ) + '"'
38
40
39
41
return href
40
42
41
- def make_image_popup_href (image_b64 ):
43
+ def make_image_popup_href (image_b64 , popup_output ):
42
44
href = ""
43
45
if fstriplestore .triple_store .output_dir :
44
46
temp_dir = os .path .join (fstriplestore .triple_store .output_dir , "tmp" )
45
47
with tempfile .NamedTemporaryFile (dir = temp_dir , suffix = '.html' , delete = False ) as temp_fp :
46
48
popup_size = (900 , 500 )
47
49
temp_fp .write (("<img src='data:image/png;base64," + image_b64 .toPython () + "'></img>" ).encode ('ascii' ))
48
- href = f"""href="javascript:
49
- /* alert(location.pathname.match(/.*\//) + '\n ' + '{ temp_fp .name } ' + '\n ' + '{ fstriplestore .triple_store .output_dir } '); */
50
- {{ window.open(location.pathname.match(/.*\//) + 'tmp/' + '{ os .path .basename (temp_fp .name )} ', '_blank', 'width={ popup_size [0 ]} ,height={ popup_size [1 ]} '); }}
51
- "
52
- """
50
+ if popup_output :
51
+ href = f"""href="javascript:
52
+ {{ window.open(location.pathname.match(/.*\//) + 'tmp/' + '{ os .path .basename (temp_fp .name )} ', '_blank', 'width={ popup_size [0 ]} ,height={ popup_size [1 ]} '); }}
53
+ "
54
+ """
55
+ else :
56
+ href = 'href="tmp/' + os .path .basename (temp_fp .name ) + '"'
53
57
54
58
return href
55
59
56
-
57
- def dump_subgraph (g , cc_uri , out_fd ):
60
+ def dump_subgraph (g , cc_uri , out_fd , popup_output ):
58
61
subgraphs = [r for r in g .query ("select ?pp ?pl { ?pp rdf:type <CodeBlock>; rdf:label ?pl; <part-of> ?sg }" , base = fstriplestore .base_uri , initBindings = {'sg' : cc_uri })]
59
62
for subgraph , subgraph_label in subgraphs :
60
63
if subgraph_label != rdflib .RDF .nil :
@@ -63,7 +66,7 @@ def dump_subgraph(g, cc_uri, out_fd):
63
66
label = "{ subgraph_label } ";
64
67
""" , file = out_fd )
65
68
66
- dump_subgraph (g , subgraph , out_fd )
69
+ dump_subgraph (g , subgraph , out_fd , popup_output )
67
70
68
71
rq = """
69
72
select ?obj_state ?version ?obj_type ?obj_uuid {
@@ -100,13 +103,13 @@ def dump_subgraph(g, cc_uri, out_fd):
100
103
for shape , head in g .query (glance_rq , base = fstriplestore .base_uri , initBindings = bindings ):
101
104
shape = shape
102
105
node_bgcolor = "#88000022"
103
- href = make_table_popup_href (head )
106
+ href = make_table_popup_href (head , popup_output )
104
107
elif obj_type .toPython () == "Series" :
105
108
glance_rq = "select ?shape { ?obj_state_cc <obj-state> ?obj_state; rdf:type ?target_cc_type; <shape> ?shape }"
106
109
for shape in g .query (glance_rq , base = fstriplestore .base_uri , initBindings = bindings ):
107
110
shape = shape [0 ]
108
111
node_bgcolor = "#88000022"
109
- href = make_table_popup_href (None )
112
+ href = make_table_popup_href (None , popup_output )
110
113
else :
111
114
raise Exception (f"unknown obj_type { obj_type } " )
112
115
elif target_cc_type == cc_basic_plot_uri :
@@ -115,7 +118,7 @@ def dump_subgraph(g, cc_uri, out_fd):
115
118
for shape , plot_im in g .query (basic_plot_rq , base = fstriplestore .base_uri , initBindings = bindings ):
116
119
shape = shape
117
120
node_bgcolor = "#44056022"
118
- href = make_image_popup_href (plot_im )
121
+ href = make_image_popup_href (plot_im , popup_output )
119
122
else :
120
123
raise Exception (f"unknown cc_type { target_cc_type } " )
121
124
@@ -165,7 +168,7 @@ def dump_subgraph(g, cc_uri, out_fd):
165
168
print (f"}}" , file = out_fd )
166
169
167
170
168
- def dump_dot_code (g , vertical , show_objects ):
171
+ def dump_dot_code (g , vertical , show_objects , popup_output ):
169
172
#ipdb.set_trace()
170
173
171
174
out_fd = StringIO ()
@@ -191,7 +194,7 @@ def dump_dot_code(g, vertical, show_objects):
191
194
""" .replace ("{rankdir}" , rankdir ), file = out_fd )
192
195
193
196
194
- dump_subgraph (g , rdflib .RDF .nil , out_fd )
197
+ dump_subgraph (g , rdflib .RDF .nil , out_fd , popup_output )
195
198
196
199
#for subgraph, subgraph_label in subgraphs:
197
200
if 1 :
@@ -304,7 +307,7 @@ def print_dot(vertical = False, show_objects = False):
304
307
g = fstriplestore .triple_store .get_graph ()
305
308
print (dump_dot_code (g , vertical = vertical , show_objects = show_objects ))
306
309
307
- def save_dot (dot_output_fn = None , vertical = False , show_objects = False ):
310
+ def save_dot (dot_output_fn = None , vertical = False , show_objects = False , popup_output = False ):
308
311
ts = fstriplestore .triple_store
309
312
if dot_output_fn is None :
310
313
if hasattr (ts , 'output_fn' ) and ts .output_fn is not None :
@@ -314,7 +317,7 @@ def save_dot(dot_output_fn = None, vertical = False, show_objects = False):
314
317
raise Exception ("can't guess dot_output_fn" )
315
318
316
319
g = ts .get_graph ()
317
- dot_code = dump_dot_code (g , vertical = vertical , show_objects = show_objects )
320
+ dot_code = dump_dot_code (g , vertical = vertical , show_objects = show_objects , popup_output = popup_output )
318
321
gvz = graphviz .Source (dot_code )
319
322
gvz .render (dot_output_fn , format = 'svg' , engine = 'dot' )
320
323
0 commit comments