ipydrawio/docs/Diagram Rich Display.ipynb

131 wiersze
3.0 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "addressed-population",
"metadata": {},
"source": [
"# Diagram Rich Display\n",
"\n",
"The _Rich Display_ is a good deal simpler than the [Diagram Widget](./Diagram%20Widget.ipynb), but offers more computability than the [Diagram Document](./Diagram%20Document.ipynb)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "another-cricket",
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import display"
]
},
{
"cell_type": "markdown",
"id": "secondary-lingerie",
"metadata": {},
"source": [
"If you just need to show a diagram (or want a _really_ temporary scratchpad), just send a display message to the frontend with the `application/x-drawio` mimetype."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "academic-injury",
"metadata": {},
"outputs": [],
"source": [
"MIMETYPE = \"application/x-drawio\""
]
},
{
"cell_type": "markdown",
"id": "3aa64017-9bc4-422a-9fa5-7de9377285f4",
"metadata": {},
"source": [
"```{note}\n",
"This mimetype is also available as `ipydrawio.constants.MIMETYPE`.\n",
"```\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "oriented-poland",
"metadata": {},
"outputs": [],
"source": [
"def display_drawio(xml, **kwargs):\n",
" \"\"\"Send some xml to the frontend\n",
"\n",
" Get a handle to update later by calling `display_drawio` with `display_id=True`\n",
" \"\"\"\n",
" return display({MIMETYPE: xml}, raw=True, **kwargs)"
]
},
{
"cell_type": "markdown",
"id": "fiscal-decline",
"metadata": {},
"source": [
"Apparently, an empty string is valid."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "extensive-sharing",
"metadata": {},
"outputs": [],
"source": [
"handle = display_drawio(\"\")"
]
},
{
"cell_type": "markdown",
"id": "wrong-connecticut",
"metadata": {},
"source": [
"## Metadata\n",
"The `drawioUrlParams` and `drawioConfig` (as well as `width` and `height`) can change how the application works."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "empirical-scout",
"metadata": {},
"outputs": [],
"source": [
"handle = display_drawio(\n",
" \"\",\n",
" metadata={\n",
" MIMETYPE: {\"height\": \"200px\", \"drawioUrlParams\": {\"ui\": \"dark\", \"chrome\": 0}},\n",
" },\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}