pinetr2e / napkin

Python as DSL for writing PlantUML sequence diagrams
MIT License
195 stars 10 forks source link

Integration into Jupyter notebook #2

Open jhermann opened 4 years ago

jhermann commented 4 years ago

Has anyone tried napkin in a notebook?

Not sure if it needs special integration code, or maybe some convenience additions…

pinetr2e commented 4 years ago

Using napkin in notebook will be great especially if there is already some supports for PlantUML.

Actually, I am not using notebook after I tried that quite long time ago. I might try notebook again soon.

jhermann commented 4 years ago

@pinetr2e This might help to get you going in case you're using Debian platforms: 1and1/debianized-jupyterhub: ♃ Debian packaging of JupyterHub, a multi-user server for Jupyter notebooks

Or try it in a Docker container…

pinetr2e commented 4 years ago

Related to this issue, for the Emacs users, Org babel integration is now supported. Please check https://github.com/pinetr2e/ob-napkin

pleabargain commented 3 years ago

Has anyone tried napkin in a notebook?

Not sure if it needs special integration code, or maybe some convenience additions…

I have https://github.com/pleabargain/ipynb/blob/master/napkin_UML_test.ipynb

Not much joy.

It would be great to get a sample working on Colab!

philipsd6 commented 3 years ago

You can do it like this:

import napkin
from IPython.display import Image

@napkin.seq_diagram()
def distributed_control(c):
    user = c.object("User")
    order = c.object("Order")
    orderLine = c.object("OrderLine")
    product = c.object("Product")
    customer = c.object("Customer")

    with user:
        with order.calculatePrice():
            with orderLine.calculatePrice():
                product.getPrice("quantity:number")
                with customer.getDiscountedValue(order):
                    order.getBaseValue().ret("value")
                    c.ret("discountedValue")

napkin.generate(output_format="plantuml_png", output_dir="/tmp")
Image(filename="/tmp/distributed_control.png")

It would definitely be nicer if napkin.generate() could just return an object that has the Jupyter _display_FMT methods to automatically display it.