1 from hep_ipython_tools
import viewer
7 """The css string for styling the notebook."""
12 background-color: rgba(20, 166, 255, 0.3);
13 background-image: url("http://www-ekp.physik.uni-karlsruhe.de/~nbraun/belle.svg");
14 background-repeat: no-repeat;
15 background-position: right bottom;
35 Viewer object for the ipython_handler_basf2 path.
36 Do not use it on your own.
41 Create a new path viewer object with the path from the process
57 import ipywidgets
as widgets
60 return widgets.HTML(
"No modules in path.")
62 a = widgets.Accordion()
65 for i, element
in enumerate(self.
path):
67 children.append(html.create())
68 if isinstance(html.module.name, str):
69 a.set_title(i, html.module.name)
71 a.set_title(i, html.module.name())
80 A widget for showing module parameter with their content (not standalone)
81 or with their description (standalone).
85 """ Init with a module as a string or a registered one. """
88 if isinstance(module, str):
90 self.
module = _basf2.register_module(module)
99 border-collapse: separate; border-spacing: 0px;">"""
106 <td{color_text} {td_style}>{param.values}</td>
107 <td style="color: gray; {td_style}>{param.default}</td></tr>"""
111 <td {td_style}>{param.type}</td>
112 <td {td_style}>{param.values}</td>
113 <td style="color: gray; {td_style}>{param.description}</td></tr>"""
120 font-size: 18pt;" {td_style}>{module_name} ({package})</td></thead>"""
124 Handy function for getting a color based on a parameter:
125 if it has the default value, no color,
128 if str(param.values) != str(param.default)
and str(param.default) !=
"":
129 color_text =
" style='color: red;'"
138 import ipywidgets
as widgets
140 html = widgets.HTML()
144 if isinstance(self.
module.name, str):
145 module_name = self.
module.name
147 module_name = self.
module.name()
154 if len(self.
module.available_params()) == 0:
157 for param
in self.
module.available_params():
165 html.value += table_row_html.format(param=param, color_text=color_text, td_style=self.
td_html)
166 html.value +=
"</table>"
172 """Show the dependencies in a nice and fancy way :-)"""
174 def __init__(self, store_arrays_with_dependencies_JSON):
175 """Create a new dependency viewer."""
180 self.
random_name =
''.join(random.choice(string.ascii_letters)
for _
in range(10))
185 self.
d3_include_string =
"""<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>"""
192 /* d3 related settings */
194 font: 300 14px "Helvetica Neue", Helvetica, Arial, sans-serif;
204 stroke: rgba(20, 166, 255, 0.3);
207 pointer-events: none;
240 self.
nodes_template =
"""<script>var test_nodes = JSON.parse('{nodes_json}');</script>""".format(
247 var radius = diameter / 2;
248 var innerRadius = radius - 120;
250 var cluster = d3.layout.cluster()
251 .size([360, innerRadius])
253 .value(function(d) { return d.size; });
255 var bundle = d3.layout.bundle();
257 var line = d3.svg.line.radial()
258 .interpolate("bundle")
260 .radius(function(d) { return d.y; })
261 .angle(function(d) { return d.x / 180 * Math.PI; });
263 var svg = d3.select("#""" + self.
element_name +
"""").append("svg")
264 .attr("width", diameter)
265 .attr("height", diameter)
267 .attr("transform", "translate(" + radius + "," + radius + ")");
269 var link = svg.append("g").selectAll(".link");
270 var node = svg.append("g").selectAll(".node");
272 var nodes = cluster.nodes(test_nodes);
273 var links = relations(nodes);
279 .each(function(d) { d.source = d[0], d.target = d[d.length - 1]; })
280 .attr("class", "link")
284 .data(nodes.filter(function(n) { return !n.children; }))
287 .attr("class", "node")
289 .attr("transform", function(d) {
290 return "rotate(" + (d.x - 90) +
291 ")translate(" + (d.y + 8) + ",0)"
292 + (d.x < 180 ? "" : "rotate(180)");})
293 .style("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
294 .text(function(d) { return d.key; })
295 .on("mouseover", mouseovered)
296 .on("mouseout", mouseouted);
298 function mouseovered(d) {
299 node.each(function(n) { n.target = n.source = false; });
301 link.classed("link--target", function(l) { if (l.target === d) return l.source.source = true; })
302 .classed("link--source", function(l) { if (l.source === d) return l.target.target = true; })
303 .filter(function(l) { return l.target === d || l.source === d; })
304 .each(function() { this.parentNode.appendChild(this); });
306 node.classed("node--target", function(n) { return n.target; })
307 .classed("node--source", function(n) { return n.source; });
310 function mouseouted(d) {
311 link.classed("link--target", false)
312 .classed("link--source", false);
314 node.classed("node--target", false)
315 .classed("node--source", false);
318 d3.select(self.frameElement).style("height", diameter + "px");
320 // Return a list of imports for the given array of nodes.
321 function relations(nodes) {
325 // Compute a map from name to node.
326 nodes.forEach(function(d) {
330 // For each import, construct a link from the source to target node.
331 nodes.forEach(function(d) {
332 if (d.relation) d.relation.forEach(function(i) {
333 relation.push({source: map[d.name], target: map[i]});
346 import ipywidgets
as widgets