# Creating Diagrams

## Context

Creating editable diagrams in open formats using open source tools is challenging. Here, we suggest [Draw.io](https://app.diagrams.net/) for creating diagrams and saving them directly in GitHub repository.

## Creating new diagram

1. On [Draw.io](https://app.diagrams.net/) website choose *Device* as your storage.

<figure><img src="https://1098398587-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYPoyCjtgyun9HOF3pnQT%2Fuploads%2Fgit-blob-618ad5f7a3736b8d6dea4adf8481cf6e13191663%2Fdraw-io-storage.png?alt=media" alt=""><figcaption></figcaption></figure>

2. Select the format of the diagram as XML`.drawio.`

<figure><img src="https://1098398587-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYPoyCjtgyun9HOF3pnQT%2Fuploads%2Fgit-blob-a80ea35432397a425d4065d6ea9c74d2ae7c6525%2Fdraw-io-file-format.png?alt=media" alt=""><figcaption></figcaption></figure>

3. Create the diagram and save it on your local machine. Make sure you follow the file naming convention of lowercase with hyphens as word separations.
4. Fork `openg2p-documentation` repository to your Github account.
5. Disable workflow in your repository fork:

<figure><img src="https://1098398587-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYPoyCjtgyun9HOF3pnQT%2Fuploads%2Fgit-blob-c2998b759c2b74a6c901468b8143ebc4b93ae509%2Fgithub-dislable-workflow.png?alt=media" alt=""><figcaption></figcaption></figure>

6. On Github, upload/commit the `.drawio` file to **your fork** of `openg2p-documentation` repository in the branch of choice to the following folder: `.gitbook/assets`.
7. Send a Pull Request.
8. After the PR is merged on the upstream repo a [Gitbook Action Workflow](https://github.com/OpenG2P/openg2p-documentation/blob/1.1/.github/workflows/drawio.yml) will get triggered to convert the same to PNG format with `*.png` extension. The PNG file will be available in the same folder as the `.drawio` file. In this case, it will be the repository's `.gitbook/assets` folder.
9. On Gitbook, insert the PNG image using the *URL* options shown by Gitbook. The URL to be given will be the GitHub URL e.g. <https://github.com/OpenG2P/openg2p-documentation/raw/1.1/.gitbook/assets/add-deduplication-manager.png>. Make sure you pick this URL in **Raw** format which will be available on the *Download* button on Github

<figure><img src="https://1098398587-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYPoyCjtgyun9HOF3pnQT%2Fuploads%2Fgit-blob-f2b154b388da874493f014cf98f6e9b9b6b81dc0%2Fgithub-raw-image-link.png?alt=media" alt=""><figcaption></figcaption></figure>

## Editing existing diagram

If a `.drawio` already exists in the `.gitbook/assets` folder then you must directly edit the repository version of the same by following the procedure given below.

1. Fork the `openg2p-documentation` repository to your local Github account. Disable workflow as shown above.
2. On the [Draw.io](https://app.diagrams.net/) website choose Github as your storage.

<figure><img src="https://1098398587-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYPoyCjtgyun9HOF3pnQT%2Fuploads%2Fgit-blob-618ad5f7a3736b8d6dea4adf8481cf6e13191663%2Fdraw-io-storage.png?alt=media" alt=""><figcaption></figcaption></figure>

3. Authorize the Draw\.io app on Github (follow the steps prompted).
4. Select the diagram in `.drawio` format from `openg2p-documentation` --> your branch --> `.gitbook/assests` folder.

<figure><img src="https://1098398587-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYPoyCjtgyun9HOF3pnQT%2Fuploads%2Fgit-blob-a80ea35432397a425d4065d6ea9c74d2ae7c6525%2Fdraw-io-file-format.png?alt=media" alt=""><figcaption></figcaption></figure>

5. Make changes.
6. Save the diagram - it will get Git-committed to your repository.
7. Send a Pull Request to `OpenG2P/openg2p-documentation` repo.
8. Upon acceptance of the Pull Request, a [Github Action Workflow](https://github.com/OpenG2P/openg2p-documentation/blob/1.1/.github/workflows/drawio.yml) will trigger the conversion of the`.drawio` file to `.png`.
9. If you have not added the URL of the PNG to your Gitbook pages follow step 6 of [Creating New Diagram](#creating-new-diagram).
10. If the URL already exists in Gitbook, the updated image should appear after a page refresh.

## Deleting a digram

1. Delete the diagram from Gitbook listing found here:

<div align="center"><figure><img src="https://1098398587-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYPoyCjtgyun9HOF3pnQT%2Fuploads%2Fgit-blob-6f58fe0498d455dc772e8a1c4d7bdedb981e2639%2Fimages-listing.png?alt=media" alt="" width="256"><figcaption></figcaption></figure></div>

2. Delete the diagram from Github repository `openg2p-documentation` from the corresponding branch
