-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML system diagrams #125
HTML system diagrams #125
Conversation
- convert svg to html (remove namespaces) - insert javascript - remove default tooltips - convert graphviz tooltips to tippy tooltips note: `node['tooltip']` must be preceeded and postceeded by empty spaces to prevent graphviz from interpreting the string as html
@BenPortner, this is awesome. It is also great to see you added it for streams too. A good way to make this work for all units is to add it in the Regarding adding tooltips only if format is html, we can have a new preferences = bst.preferences
with preferences.temporary(): # This makes any changes to preferences temporary
if number is not None: preferences.number_path = number
if label is not None: preferences.label_streams = label
if profile is not None: preferences.profile = profile
if format is not None: preferences.diagram_format = format # Override if not given
if kind == 0 or kind == 'cluster':
f = self._cluster_digraph(graph_attrs)
elif kind == 1 or kind == 'thorough':
f = self._thorough_digraph(graph_attrs)
elif kind == 2 or kind == 'surface':
f = self._surface_digraph(graph_attrs)
elif kind == 3 or kind == 'minimal':
f = self._minimal_digraph(graph_attrs)
else:
raise ValueError("kind must be one of the following: "
"0 or 'cluster', 1 or 'thorough', 2 or 'surface', "
"3 or 'minimal'")
if display or file:
# Format will not be passed to finalize_diagram anymore.
# Instead, the format should be accessed from biosteam.preferences.
finalize_digraph(f, file)
else:
return f I have a question regarding output format and tooltips. In if format == 'html': graph_attrs['format'] = 'svg' # because html will cause error Is this temporary? I thought the format would need to be 'html' to inject js in Thanks! |
Creating tooltips in Having a
Unfortunately, overwriting |
@BenPortner, that makes sense, we can keep the format as an input parameter to Yes, let's remove the format from Thanks a bunch! |
@yoelcortes: It would be nice to include essential initialization parameters in the tooltips (e.g. efficiency of a turbine, number of stages for a multicompressor). Do you know a clever way to include these while preventing duplication of the |
@BenPortner, yes! I meant to mention this to you earlier but forgot. Thanks for asking! We can extend the def _get_design_info(self):
return [
('Residence time', self.tau, 'hr'),
('Conversion efficiency', self.efficiency, ''),
('Working volume fraction', 0.8, '')
] Hope this helps! |
Hi @yoelcortes, Thanks for your help with this! I'm a little bit swamped right now, so I cannot pour as much time into it as I'd like. Just a quick question: Did you tick the "make sure it works for save_digraph and display_digraph" box? Last time I tried, the HTML output did not work in notebooks because of this bug, which I am waiting to be resolved. Concerning your edit "add tooltips only if output format is html (Yoel edit: or svg?)": Although SVG offers a simple tooltip functionality, displaying large amounts of data like the ones returned by Ben |
@BenPortner, thanks for the notes on this! The html output doesn't show tooltips in jupyter notebooks (yet) unfortunately, but it is still working for me. Your right about the svg formating, I just tried it jaja. I'll make tooltips only available for html format. I think I'll set the default format back to svg since html is still not working on jupyter notebooks Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm super stoked about these new features. Thanks, @BenPortner! We still got a couple of items left to add, but I'll go ahead and merge to not have branches diverge too much.
I was able to get html diagrams to show on jupyter notebooks, but it requires to save the file: biosteam/biosteam/digraph/digraph.py Line 525 in 8f66a0b
I wasn't able to get the file to save in a path other than directly in the same folder (everything else I tried failed...). It would me nice if they could be saved as part of jupyter notebook ipynb checkpoints... or something of the sort. EDIT: Nevermind, I think I found the solution: jupyter/nbconvert#1166 (comment) import urllib
data_uri = 'data:text/html;charset=utf-8,' + urllib.parse.quote(html_str)
display(IFrame(data_uri, width='100%', height='250')) |
Hi @yoelcortes, Just to clarify: You don't see the HTML diagrams in the notebook if you don't save it? That is unusual, because last time I tried, it worked for me. The only thing that didn't work were the tooltips.
|
@BenPortner, Yes! This is solved already. I had a ton of fun getting it to work and updating the documentation over the weekend. Here are a couple of notes: 1.The default does not insert javascript and outputs diagrams as svg with tooltips (which has no issues on jupyter notebooks). For tooltips with full results, set Thanks! |
This PR adds an
html
output format for system diagrams. The format is equivalent tosvg
except it adds informative tooltips:Open issues:
digraph.js
anddigraph.css
to make them work independent of output file locationYoel edit: or svg?)save_digraph
anddisplay_digraph
(Fixed! Just needed IFrame for html with javascript)Help needed
@yoelcortes: Do you know a clever way to include other unit types without manually modifying each
_graphics.tailor_xyz_node
function? Perhaps we can make these part of the class definitions and have_unit.Unit
provide a default tooltip function?