Skip to content

Commit

Permalink
feat(howtos): visualize plantuml image
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Sep 7, 2024
1 parent 786cede commit 3ade177
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 25 deletions.
92 changes: 92 additions & 0 deletions how-tos/plantuml.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%dependency /add net.sourceforge.plantuml:plantuml-mit:1.2024.6\n",
"%dependency /resolve"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import net.sourceforge.plantuml.SourceStringReader;\n",
"import net.sourceforge.plantuml.FileFormatOption;\n",
"import net.sourceforge.plantuml.FileFormat;\n",
"\n",
"static java.awt.Image plantUML2PNG( String code ) throws IOException { \n",
" var reader = new SourceStringReader(code);\n",
"\n",
" try(var imageOutStream = new java.io.ByteArrayOutputStream()) {\n",
"\n",
" var description = reader.outputImage( imageOutStream, 0, new FileFormatOption(FileFormat.PNG));\n",
"\n",
" var imageInStream = new java.io.ByteArrayInputStream( imageOutStream.toByteArray() );\n",
"\n",
" return javax.imageio.ImageIO.read( imageInStream );\n",
"\n",
" }\n",
"}\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAJMAAACOCAIAAAC6z60HAAAMDklEQVR4Xu2deVAUxx7HF6944H2LeOOFRwUtnyaKghr1aZVVGPVZPs96llomPhLvPziiLIdCNBpfhKiFioo+Ee8jqUSEeJuKFY9oFDVEFJ+WSqlJIIm8L9vl1LzpZnd2dpzd9v0+1UVN9/T8erY/2z09wO7Yygg5sWkLCEkgc7JC5mSFzMkKmZMVMicrZE5WyJyskDlZIXOyQuZkhczJCpmTFTInK2ROVsicrHjH3IsXL4qKirSlhDtYbQ7O5s+fHxAQYLPZatasee3atejo6KlTp544cUJb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MRwJzFizZLWjCdMhcORY0YTo+YW7Hjh3x8fHJFRAREaEt+l+ysrK0ETlKS0tTU1O1R77EeRN64luP983l5OR68nC4n38uzszMysvL08ZVUVJSsnDh4u+++5E/3GVC/O3bs3JzncX3Ct43FxtrF37RvP6Ew+PinH13wrp1qd9+e40/UGdCfHr+nAALvlXD8+9DWbqUvg+FI4q+ycYQZE5XInMCyJwxyJyuROYEkDljkDldicwJIHPG8HVz9OTAivB1c/TkwIrwaXP05EAn+LQ5enKgE3zaHD050Am+a46eHOgc3zVHTw50ju+aoycHOsdHzdGTA13io+boyYEu8VFz9ORAl/ioOXeTYXM6E5kTQOaMQeZ0JTIngMwZg8zpSmROAJkzBpnTlcicgOjoOOEfM/UnHO78f5A/+2zd+fMe/Xc6mRPw5ZfH0tN38P2lP23atDMnJ1cbV0VJSckHHywwLA/xjx07rg3qbbxvrqz8U1j/ttsTjaXY2GXbt2dqI3KUlpZ++um/+MNdJp3xrccnzBEGIHOyQuZkhczJyn8BOxw+IaOVu64AAAAASUVORK5C"
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"43555a3a-e968-4837-b7d4-5c2a08783d0f"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"var code = \"\"\"\n",
" @startuml\n",
" title my first diagram\n",
" A --> B\n",
" @enduml\n",
" \"\"\";\n",
"\n",
"display( plantUML2PNG( code ) );\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Java (rjk 2.1.0)",
"language": "java",
"name": "rapaio-jupyter-kernel"
},
"language_info": {
"codemirror_mode": "java",
"file_extension": ".jshell",
"mimetype": "text/x-java-source",
"name": "java",
"nbconvert_exporter": "script",
"pygments_lexer": "java",
"version": "22.0.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 3ade177

Please sign in to comment.