This document is written for those want to integrate ZenUML to their applications. If you are an end user, please read tutorials; if your would like to contribute, please read contributor’s guide.
An important goal of this project is to be easily integrated into other projects. There are mainly two ways to do this.
ZenUML Core exposes a simple API for integration:
interface IZenUml {
get code(): string | undefined;
get theme(): string | undefined;
// Resolve after rendering is finished.
render: (code: string | undefined, theme: string | undefined) => Promise<IZenUml>
}
// client code
import ZenUml from '@ZenUML/core'
const zenUml = new ZenUml(el)
await zenUml.render('A.method', 'theme-blue')
When rendering is finished, the render
method will return a promise that resolves to the
instance of IZenUml
. The html
properties of the instance will be updated to the rendered
HTML.
Note
|
Vue’s reactive system works against the |
It is tricky to know when the rendering is finished. The Lifeline
components used $nextTick
in their mounted
and updated
hooks to set the top when a creation
message is sent to it.
We have to wait until all those $nextTick
calls are finished.
Note
|
It seems that (to be confirmed) the |
The diagram is rendered in the following steps:
-
The lifeline layer;
-
The message layer;
-
Update lifeline layer with
setTimeout
forcreation
messages.
You can embed the ZenUML core renderer as an application within another app, where you store the diagram data in the host app. It takes around 5 minutes to get a basic example running.
To test this out open https://embed.zenuml.com/embed.html
. In the developer console, type in the
following command.
window.postMessage( {action: 'eval', args: { code: 'ZenUML.Hello' }})
The protocol is a simple JSON object with the following fields.
{
"action": "eval",
"args": {
"code": "ZenUML.Hello",
"style": "#diagram { background-color: red; }",
"theme": "blue",
"css": "https://github.com/abruzzi/zenuml-css-overrides/blob/master/zenuml-override.css"
}
}
<iframe src="https://embed.zenuml.com/embed.html" id="zenuml-iframe"
style="width: 100%; height: 100%; border: none;">
</iframe>
<script>
const iframe = document.getElementById('zenuml-iframe');
const message = {
action: 'eval',
args: {
code: 'ZenUML.Hello',
style: '#diagram { background-color: red; }',
theme: 'blue',
css: ''
}
};
setTimeout(() => {
iframe.contentWindow.postMessage(message, '*');
}, 1000);
</script>
document.getElementsByTagName('iframe')[0] // get iframe
.contentWindow // get target window
.postMessage({action: "eval", args: { code: 'A.m' }})