pythiaplotter.printers package¶
Submodules¶
pythiaplotter.printers.dot_config module¶
pythiaplotter.printers.dot_display_classes module¶
Classes to describe and generate visual attributes for making the Graphviz description.
Also set particle label in here, see get_particle_label()
. Or should this be a
method for the particle?
-
class
pythiaplotter.printers.dot_display_classes.
DotAttrGenerator
(particle_opts=None, label_opts=None)[source]¶ Bases:
object
Base class for generating particle attr dicts
-
get_non_particle_attr
(obj, fancy)[source]¶ Base method for getting an attribute dict for not a particle.
key:value pairs must be legal graphviz key/values.
The user should override this method.
Parameters: - obj (object) – The object in question.
- fancy (bool) –
Returns: Return type: dict
-
get_particle_attr
(particle, fancy)[source]¶ Base method for getting an attribute dict for a particle.
key:value pairs must be legal graphviz key/values.
The user should override this method.
Parameters: - particle (Particle) –
- fancy (bool) –
Returns: Return type: dict
-
-
class
pythiaplotter.printers.dot_display_classes.
DotEdgeAttrGenerator
(particle_opts, label_opts)[source]¶ Bases:
pythiaplotter.printers.dot_display_classes.DotAttrGenerator
AttrGenerator specifically for Edges.
-
class
pythiaplotter.printers.dot_display_classes.
DotGraphAttrGenerator
(attr)[source]¶ Bases:
pythiaplotter.printers.dot_display_classes.DotAttrGenerator
Generate Graphviz string with overall graph options
-
class
pythiaplotter.printers.dot_display_classes.
DotNodeAttrGenerator
(particle_opts, label_opts)[source]¶ Bases:
pythiaplotter.printers.dot_display_classes.DotAttrGenerator
AttrGenerator specifically for Nodes.
-
pythiaplotter.printers.dot_display_classes.
get_particle_label
(particle, representation, label_opts, fancy=True)[source]¶ Return string for particle label to be displayed on graph.
Parameters: - particle (Particle) – Particle under consideration
- representation ({"NODE", "EDGE"}) – Particle representation
- label_opts (dict) – Dict of labels for different representations and fancy/plain
- fancy (bool) – If True, will use HTML/unicode in labels
Returns: Particle label string
Return type: str
Raises: RuntimeError
– If representation is not one of “NODE”, “EDGE”
pythiaplotter.printers.dot_printer module¶
Print graph using Graphviz.
Aim to be fairly generic, so can have particles as edges or nodes. All we do is attach display attributes to each node/edge, then print these to file.
Several stages: 1. Go through nodes & edges and attach display attributes [add_display_attr()] 2. Write to Graphviz format file [write_gv()] 3. Render to file [print_diagram()]
-
class
pythiaplotter.printers.dot_printer.
DotPrinter
(opts)[source]¶ Bases:
object
Class to print event to file using Graphviz
-
pythiaplotter.printers.dot_printer.
construct_gv_full
(event)[source]¶ Turn event graph into Graphviz string in DOT language
Parameters: event (Event) – Returns: Return type: str
-
pythiaplotter.printers.dot_printer.
print_diagram
(gv_str, output_filename, renderer, output_format)[source]¶ Pass graph in DOT language to a Graphviz program to produce a diagram.
Parameters: - gv_str (str) – Graph contents in DOT language
- output_filename (str) – Final diagram filename
- renderer (str) – Graphviz program to use
- output_format (str) –
Each has its own advantages, see http://www.graphviz.org/doc/info/output.html
- ps - uses ps:cairo. Obeys HTML tags & unicode, but not searchable
- ps2 - PDF searchable, but won’t obey all HTML tags or unicode.
- pdf - obeys HTML but not searchable
Returns: List of commands run to produce diagram from graphviz file
Return type: list[str]
pythiaplotter.printers.web_config module¶
pythiaplotter.printers.web_printer module¶
Print webpage with interactive graph.
This uses vis.js to do all the hard work: http://visjs.org/, but we still use graphviz to do the layout for (a) parity with the PDF version, (b) because it is faster, whereas web pages (so far) crash.
Of course if I could find a graphviz-as-as-JS service, that would be cooler...
-
pythiaplotter.printers.web_printer.
add_node_positions
(graph, raw_json)[source]¶ Update graph nodes with their positions, using info in raw_json.
Parameters: - graph (NetworkX.MultiDiGraph) – Graph to be updated
- raw_json (str) – JSON with nodes & their positions
-
pythiaplotter.printers.web_printer.
construct_gv_only_edges
(graph, graph_attr=None)[source]¶ Create a graph in DOT language with just edges specified.
This is a minimal graph, just used to determine the node positioning.
Parameters: - graph (NetworkX.MultiDiGraph) –
- graph_attr (dict, optional) – Graph attributes such as rankdir, nodesep
Returns: The graph in DOT language
Return type: str
-
pythiaplotter.printers.web_printer.
create_vis_dicts
(graph)[source]¶ Create list of dicts for nodes & edges suitable for input to vis.js
This includes node position, label, hover info, etc
Parameters: graph (NetworkX.MultiDiGraph) – Returns: Lists of dicts corresponding to (nodes, edges) Return type: list[dict], list[dict]
-
pythiaplotter.printers.web_printer.
get_dot_json
(graphviz_str, renderer='dot')[source]¶ Get the JSON output (with co-ords) from running a layout renderer.
Parameters: - graphviz_str (str) – Graph in DOT language.
- renderer (str, optional) – Renderer to use. Default is dot.
Returns: JSON string
Return type: str
Module contents¶
Printers take in a NetworkX graph of Particles, then produce an output diagram.
-
pythiaplotter.printers.
printer_opts_all
¶ dict[str, PrinterOption]
Store a record of all printers and their requirements.
-
pythiaplotter.printers.
printer_opts_checked
¶ dict{str: PrinterOption}
Store a record of only those printers available on the user’s system.
-
class
pythiaplotter.printers.
PrinterOption
(description, printer, requires, default_output_fmt)[source]¶ Bases:
object
-
pythiaplotter.printers.
print_printers_requirements
(output=<built-in method write of file object>)[source]¶ Print program and python package requirements for all printers
Parameters: output (function, optional) – The outputmessage is passed as the parameter to this function. Default is sys.stdout.write()