8 from hep_ipython_tools
import viewer
14 """The css string for styling the notebook."""
19 background-color: rgba(20, 166, 255, 0.3);
20 background-image: url("http://www-ekp.physik.uni-karlsruhe.de/~nbraun/belle.svg");
21 background-repeat: no-repeat;
22 background-position: right bottom;
42 Viewer object for the ipython_handler_basf2 path.
43 Do not use it on your own.
48 Create a new path viewer object with the path from the process
52 self.
pathpath = path.modules()
64 import ipywidgets
as widgets
66 if self.
pathpath
is None:
67 return widgets.HTML(
"No modules in path.")
69 a = widgets.Accordion()
72 for i, element
in enumerate(self.
pathpath):
74 children.append(html.create())
75 if isinstance(html.module.name, str):
76 a.set_title(i, html.module.name)
78 a.set_title(i, html.module.name())
87 A widget for showing module parameter with their content (not standalone)
88 or with their description (standalone).
92 """ Init with a module as a string or a registered one. """
95 if isinstance(module, str):
97 self.
modulemodule = _basf2.register_module(module)
106 border-collapse: separate; border-spacing: 0px;">"""
109 self.
td_htmltd_html =
"style=\"padding: 10px;\""
113 <td{color_text} {td_style}>{param.values}</td>
114 <td style="color: gray; {td_style}>{param.default}</td></tr>"""
118 <td {td_style}>{param.type}</td>
119 <td {td_style}>{param.values}</td>
120 <td style="color: gray; {td_style}>{param.description}</td></tr>"""
126 self.
table_title_htmltable_title_html =
"""<thead><td colspan="4" style="text-align: center;
127 font-size: 18pt;" {td_style}>{module_name} ({package})</td></thead>"""
131 Handy function for getting a color based on a parameter:
132 if it has the default value, no color,
135 if str(param.values) != str(param.default)
and str(param.default) !=
"":
136 color_text =
" style='color: red;'"
145 import ipywidgets
as widgets
147 html = widgets.HTML()
151 if isinstance(self.
modulemodule.name, str):
152 module_name = self.
modulemodule.name
154 module_name = self.
modulemodule.name()
156 html.value += self.
table_title_htmltable_title_html.format(module_name=module_name, package=self.
modulemodule.package(),
161 if len(self.
modulemodule.available_params()) == 0:
164 for param
in self.
modulemodule.available_params():
172 html.value += table_row_html.format(param=param, color_text=color_text, td_style=self.
td_htmltd_html)
173 html.value +=
"</table>"
179 """Show the dependencies in a nice and fancy way :-)"""
181 def __init__(self, store_arrays_with_dependencies_JSON):
182 """Create a new dependency viewer."""
187 self.
random_namerandom_name =
''.join(random.choice(string.ascii_letters)
for _
in range(10))
192 self.
d3_include_stringd3_include_string =
"""<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>"""
199 /* d3 related settings */
201 font: 300 14px "Helvetica Neue", Helvetica, Arial, sans-serif;
211 stroke: rgba(20, 166, 255, 0.3);
214 pointer-events: none;
247 self.
nodes_templatenodes_template = f
"""<script>var test_nodes = JSON.parse('{self.store_arrays_with_dependencies_JSON}');</script>"""
253 var radius = diameter / 2;
254 var innerRadius = radius - 120;
256 var cluster = d3.layout.cluster()
257 .size([360, innerRadius])
259 .value(function(d) { return d.size; });
261 var bundle = d3.layout.bundle();
263 var line = d3.svg.line.radial()
264 .interpolate("bundle")
266 .radius(function(d) { return d.y; })
267 .angle(function(d) { return d.x / 180 * Math.PI; });
269 var svg = d3.select("#""" + self.
element_nameelement_name +
"""").append("svg")
270 .attr("width", diameter)
271 .attr("height", diameter)
273 .attr("transform", "translate(" + radius + "," + radius + ")");
275 var link = svg.append("g").selectAll(".link");
276 var node = svg.append("g").selectAll(".node");
278 var nodes = cluster.nodes(test_nodes);
279 var links = relations(nodes);
285 .each(function(d) { d.source = d[0], d.target = d[d.length - 1]; })
286 .attr("class", "link")
290 .data(nodes.filter(function(n) { return !n.children; }))
293 .attr("class", "node")
295 .attr("transform", function(d) {
296 return "rotate(" + (d.x - 90) +
297 ")translate(" + (d.y + 8) + ",0)"
298 + (d.x < 180 ? "" : "rotate(180)");})
299 .style("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
300 .text(function(d) { return d.key; })
301 .on("mouseover", mouseovered)
302 .on("mouseout", mouseouted);
304 function mouseovered(d) {
305 node.each(function(n) { n.target = n.source = false; });
307 link.classed("link--target", function(l) { if (l.target === d) return l.source.source = true; })
308 .classed("link--source", function(l) { if (l.source === d) return l.target.target = true; })
309 .filter(function(l) { return l.target === d || l.source === d; })
310 .each(function() { this.parentNode.appendChild(this); });
312 node.classed("node--target", function(n) { return n.target; })
313 .classed("node--source", function(n) { return n.source; });
316 function mouseouted(d) {
317 link.classed("link--target", false)
318 .classed("link--source", false);
320 node.classed("node--target", false)
321 .classed("node--source", false);
324 d3.select(self.frameElement).style("height", diameter + "px");
326 // Return a list of imports for the given array of nodes.
327 function relations(nodes) {
331 // Compute a map from name to node.
332 nodes.forEach(function(d) {
336 // For each import, construct a link from the source to target node.
337 nodes.forEach(function(d) {
338 if (d.relation) d.relation.forEach(function(i) {
339 relation.push({source: map[d.name], target: map[i]});
352 import ipywidgets
as widgets