{
"cells": [
{
"cell_type": "markdown",
"id": "101e0116-b2a4-4bee-beb0-3bae0d3f340d",
"metadata": {},
"source": [
"## Displaying a legend with MODA and CHADA elements for all MOCHADA themes in a single diagram"
]
},
{
"cell_type": "markdown",
"id": "ac922004-fc53-4d8a-9d20-cb19785813dc",
"metadata": {},
"source": [
"This example shows how to pack a legend (a.k.a colour key) showing all MODA and CHADA elements grouped, for each MOCHADA theme into a single svg image for easy comparison."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "d0d50342-7630-43fb-a0e0-43f275a651bf",
"metadata": {},
"outputs": [],
"source": [
"import contextlib\n",
"import glob\n",
"import pathlib\n",
"\n",
"import mochada_kit.running as mr"
]
},
{
"cell_type": "markdown",
"id": "8535da94-afb3-4482-9b68-aab8364de82a",
"metadata": {},
"source": [
"
\n",
"\n",
"Get the paths to all the MOCHADA themes in `mochada_kit/themes`"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "c70f9347-f3d3-4a7c-8a83-7ab8bf3c6249",
"metadata": {},
"outputs": [],
"source": [
"theme_files = glob.glob(str(pathlib.Path(\"../../themes/puml-theme-MOCHADA-*.puml\")))\n",
"themes = [str(i).split(\"puml-theme-\")[1][:-5] for i in theme_files]"
]
},
{
"cell_type": "markdown",
"id": "70969e3a-f501-4913-becf-4784fbad8280",
"metadata": {},
"source": [
"
\n",
"\n",
"Make sure the theme based on the current working agreement (CWA) comes first in the list, and remove the themes \"MOCHADA-plasma_A4w\" and \"MOCHADA-plasma_wide\", if they are present - these themes look the same as \"MOCHADA-plasma\" in a colour key but have one parameter changed to make CHADA tables fit better onto an A4 page/wide screen."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "1df277ab-9d70-447e-b6f5-43658dbd82d5",
"metadata": {},
"outputs": [],
"source": [
"themes.remove(\"MOCHADA-CWA\")\n",
"themes.insert(0, \"MOCHADA-CWA\")\n",
"for i in [\"MOCHADA-plasma_A4w\", \"MOCHADA-plasma_wide\"]:\n",
" with contextlib.suppress(ValueError):\n",
" themes.remove(i)"
]
},
{
"cell_type": "markdown",
"id": "70bc5245-2a75-444d-9b68-f2e82c1afebb",
"metadata": {},
"source": [
"
\n",
"\n",
"Now we write the same key (an activity element for each of the CHADA and MODA elements with its corresponding stereotype, grouped into CHADA and MODA) for each theme into a different \"label\" in the diagram. There appears to be little control of placing the keys in rows and columns but this adjusts automatically as you add more themes."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "c21260bb-a285-42f6-b80a-c95a23cc874f",
"metadata": {},
"outputs": [],
"source": [
"with open(\n",
" pathlib.Path(\"../../gallery/puml_code/legend_moda_and_chada_all_themes.puml\"), \"w\"\n",
") as f:\n",
" f.write(\"@startuml\\n\")\n",
"\n",
" for i, j in enumerate(themes):\n",
" f.write(f\"label l{i+1} [\\n\")\n",
" f.write(\"{{\\n\")\n",
" chada_blocks_uml = f\"\"\"!theme {j} from ../../themes\n",
"title {j}\n",
"group CHADA <>\n",
" :User Case; <>\n",
" :Experiment; <>\n",
" :Raw Data; <>\n",
" :Data Processing; <>\n",
" :Final Data; <>\n",
"end group\n",
"group MODA <>\n",
" :User Case Input; <>\n",
" split\n",
" :Model; <>\n",
" split again\n",
" :Data Based Model; <>\n",
" end split\n",
" :Raw Output; <>\n",
" :Processed Output; <>\n",
"end group\n",
"\"\"\"\n",
"\n",
" f.write(chada_blocks_uml)\n",
" f.write(\"}}\\n]\\n\")\n",
"\n",
" f.write(\"@enduml\\n\")"
]
},
{
"cell_type": "markdown",
"id": "cbb3b66b-39c5-4d60-b148-3be2ab2bc7c9",
"metadata": {},
"source": [
"
\n",
"\n",
"Finally we run the puml code to generate the svg diagram"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "6b26c0c0-7642-4725-ada8-697e00c70499",
"metadata": {},
"outputs": [],
"source": [
"mr.run_plantuml_code(\n",
" pathlib.Path(\"../../gallery/puml_code/legend_moda_and_chada_all_themes.puml\"),\n",
" output_dir=pathlib.Path(\"../\"),\n",
")"
]
},
{
"cell_type": "markdown",
"id": "15227e59-4b49-447c-a9c2-f8bd7afd9a90",
"metadata": {},
"source": [
"Here's the diagram:\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.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}