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 =
"""<script>var test_nodes = JSON.parse('{nodes_json}');</script>""".format(
254 var radius = diameter / 2;
255 var innerRadius = radius - 120;
257 var cluster = d3.layout.cluster()
258 .size([360, innerRadius])
260 .value(function(d) { return d.size; });
262 var bundle = d3.layout.bundle();
264 var line = d3.svg.line.radial()
265 .interpolate("bundle")
267 .radius(function(d) { return d.y; })
268 .angle(function(d) { return d.x / 180 * Math.PI; });
270 var svg = d3.select("#""" + self.
element_nameelement_name +
"""").append("svg")
271 .attr("width", diameter)
272 .attr("height", diameter)
274 .attr("transform", "translate(" + radius + "," + radius + ")");
276 var link = svg.append("g").selectAll(".link");
277 var node = svg.append("g").selectAll(".node");
279 var nodes = cluster.nodes(test_nodes);
280 var links = relations(nodes);
286 .each(function(d) { d.source = d[0], d.target = d[d.length - 1]; })
287 .attr("class", "link")
291 .data(nodes.filter(function(n) { return !n.children; }))
294 .attr("class", "node")
296 .attr("transform", function(d) {
297 return "rotate(" + (d.x - 90) +
298 ")translate(" + (d.y + 8) + ",0)"
299 + (d.x < 180 ? "" : "rotate(180)");})
300 .style("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
301 .text(function(d) { return d.key; })
302 .on("mouseover", mouseovered)
303 .on("mouseout", mouseouted);
305 function mouseovered(d) {
306 node.each(function(n) { n.target = n.source = false; });
308 link.classed("link--target", function(l) { if (l.target === d) return l.source.source = true; })
309 .classed("link--source", function(l) { if (l.source === d) return l.target.target = true; })
310 .filter(function(l) { return l.target === d || l.source === d; })
311 .each(function() { this.parentNode.appendChild(this); });
313 node.classed("node--target", function(n) { return n.target; })
314 .classed("node--source", function(n) { return n.source; });
317 function mouseouted(d) {
318 link.classed("link--target", false)
319 .classed("link--source", false);
321 node.classed("node--target", false)
322 .classed("node--source", false);
325 d3.select(self.frameElement).style("height", diameter + "px");
327 // Return a list of imports for the given array of nodes.
328 function relations(nodes) {
332 // Compute a map from name to node.
333 nodes.forEach(function(d) {
337 // For each import, construct a link from the source to target node.
338 nodes.forEach(function(d) {
339 if (d.relation) d.relation.forEach(function(i) {
340 relation.push({source: map[d.name], target: map[i]});
353 import ipywidgets
as widgets