├── .browserslistrc ├── .eslintrc.js ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── babel.config.js ├── package-lock.json ├── package.json ├── pnpm-lock.yaml ├── postcss.config.js ├── public ├── favicon.ico └── index.html ├── src ├── App.vue ├── assets │ └── logo.png ├── components │ ├── graph │ │ ├── GraphModeler.vue │ │ ├── GraphModelerConfigBar.vue │ │ ├── GraphModelerElementsBar.vue │ │ ├── GraphModelerToolbar.vue │ │ └── GraphValidationErrors.vue │ └── shared │ │ ├── ModalComponent.vue │ │ └── easymde │ │ ├── EasymdeView.vue │ │ └── index.ts ├── main.ts ├── shims-vue.d.ts ├── style │ └── index.scss └── utils │ ├── antv-model.ts │ ├── data │ ├── base64.ts │ ├── download.ts │ ├── indent.ts │ ├── pick.ts │ ├── titleCase.ts │ └── uuid.ts │ ├── graph.ts │ ├── modal.ts │ └── transformer │ ├── antvis.ts │ ├── docassemble.ts │ ├── index.ts │ └── json.ts ├── tailwind.config.js ├── tsconfig.json └── vue.config.js /.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not dead 4 | not ie 11 5 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true, 5 | 'vue/setup-compiler-macros': true 6 | }, 7 | 'extends': [ 8 | 'plugin:vue/vue3-essential', 9 | 'eslint:recommended', 10 | '@vue/typescript/recommended' 11 | ], 12 | parserOptions: { 13 | ecmaVersion: 2020 14 | }, 15 | rules: { 16 | 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 17 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 18 | 19 | 'prefer-const': 'warn', 20 | 21 | '@typescript-eslint/no-unused-vars': 'off' 22 | 23 | // '@typescript-eslint/ban-ts-comment': 'off', 24 | // 'vue/script-setup-uses-vars': 'error', 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | .dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | pnpm-debug.log* 14 | 15 | # Editor directories and files 16 | .idea 17 | .vscode 18 | *.suo 19 | *.ntvs* 20 | *.njsproj 21 | *.sln 22 | *.sw? 23 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Usage: 2 | # Build the image: docker build -t graphdoc ./ 3 | # Run image in container: docker run -p 8080:80 graphdoc 4 | 5 | FROM node:lts-alpine 6 | 7 | # install simple http server for serving static content 8 | RUN npm install -g http-server 9 | 10 | # make the 'app' folder the current working directory 11 | WORKDIR /app 12 | 13 | # copy both 'package.json' and 'package-lock.json' (if available) 14 | COPY package*.json ./ 15 | 16 | # copy project files and folders to the current working directory (i.e. 'app' folder) 17 | COPY . . 18 | 19 | # install project dependencies 20 | RUN npm install 21 | 22 | # build app for production with minification 23 | RUN npm run build 24 | 25 | # serve dist folder on port 8080 26 | EXPOSE 80 27 | CMD [ "http-server", "dist", "-p", "80" ] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | 179 | Copyright 2022 Maastricht University 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GraphDoc 2 | 3 | ## Introduction 4 | 5 | GraphDoc is a web-application that has been developed by [Sander van Essel](https://github.com/eensander) as part of an internship for the [Maastricht Law & Tech Lab](https://github.com/maastrichtlawtech/), which is part of Maastricht University, The Netherlands. 6 | 7 | The goal of this application is to aid users in visually constructing [Docassemble](https://github.com/jhpyle/docassemble/) interview configuration files. 8 | 9 | ## Demo 10 | The demo is available at [https://maastrichtlawtech.github.io/graphdoc/](https://maastrichtlawtech.github.io/graphdoc/). 11 | 12 | ### Example 13 | 14 | User Interface | Docassemble 15 | -- | -- 16 | ![ui](https://user-images.githubusercontent.com/50321538/174894290-6d5a6e41-4966-406d-9537-3bdf127eb63b.png) | ![docassemble output](https://user-images.githubusercontent.com/50321538/173640275-d485c7cb-06a4-4eae-93a6-0aa080d208a5.png) 17 | 18 | The interview constructed in the above screenshot results in the following generated Docassemble interview configuration file: 19 | ```yaml 20 | question: Start 21 | subquestion: | 22 | walk or bus? 23 | continue button field: walk_or_bus 24 | --- 25 | question: Question 26 | subquestion: | 27 | is it raining? 28 | field: is_raining 29 | buttons: 30 | - "No" 31 | - "Yes" 32 | --- 33 | question: Notice 34 | subquestion: | 35 | take an umbrella 36 | continue button field: notice_take_umbrella 37 | --- 38 | event: end_bus 39 | question: End 40 | subquestion: | 41 | take the bus 42 | --- 43 | event: end_walk 44 | question: End 45 | subquestion: | 46 | take a walk 47 | --- 48 | mandatory: True 49 | code: | 50 | walk_or_bus 51 | if is_raining == 'Yes': 52 | notice_take_umbrella 53 | end_bus 54 | if is_raining == 'No': 55 | end_walk 56 | ``` 57 | 58 | 59 | ## Usage 60 | 61 | ### Docker 62 | 63 | The recommended method for installing GraphDoc on a server is using Docker. 64 | 65 | First clone the repositry and navigate with the command line to the destination folder. 66 | ``` 67 | git clone https://github.com/maastrichtlawtech/graphdoc 68 | cd graphdoc 69 | ``` 70 | 71 | Next, build the container 72 | ``` 73 | docker build -t graphdoc ./ 74 | ``` 75 | 76 | Then run the container on the desired port, which is `80` by default. 77 | 78 | ``` 79 | docker run graphdoc --name graphdoc -p 80:80 80 | ``` 81 | 82 | ### Manual installation 83 | 84 | To manually install GraphDoc, you are required to have atleast npm installed. It does not require a webserver, however this is recommended. 85 | 86 | First clone the repositry and navigate with the command line to the destination folder. 87 | ``` 88 | git clone https://github.com/maastrichtlawtech/graphdoc 89 | cd graphdoc 90 | ``` 91 | 92 | Next, install the npm dependencies and build the files using npm 93 | ``` 94 | npm install 95 | npm run build 96 | ``` 97 | 98 | The built package is located at `./dist`. This folder can be served using any webserver, like [http-server](https://www.npmjs.com/package/http-server): 99 | ``` 100 | npx http-server dist 101 | ``` 102 | 103 | Alternatively, the index.html file in the dist folder (`dist/index.html`) can be opened using a webbrowser from the file explorer. 104 | 105 | ## License 106 | See the LICENSE file for license rights and limitations (Apache 2.0). 107 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GraphDoc", 3 | "version": "1.10.1", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "@antv/x6-vue-shape": "^1.3.2", 12 | "core-js": "^3.8.3", 13 | "vue": "^3.2.13" 14 | }, 15 | "devDependencies": { 16 | "@antv/x6": "^1.31.1", 17 | "@tailwindcss/forms": "^0.5.0", 18 | "@types/node": "^20.10.0", 19 | "@types/uuid": "^8.3.4", 20 | "@typescript-eslint/eslint-plugin": "^5.4.0", 21 | "@typescript-eslint/parser": "^5.4.0", 22 | "@vue/cli-plugin-babel": "~5.0.0", 23 | "@vue/cli-plugin-eslint": "~5.0.0", 24 | "@vue/cli-plugin-typescript": "~5.0.0", 25 | "@vue/cli-service": "~5.0.0", 26 | "@vue/eslint-config-typescript": "^9.1.0", 27 | "autoprefixer": "^10.4.4", 28 | "axios": "^0.26.1", 29 | "easymde": "^2.16.1", 30 | "eslint": "^7.32.0", 31 | "eslint-plugin-vue": "^8.0.3", 32 | "postcss": "^8.4.12", 33 | "sass": "^1.32.7", 34 | "sass-loader": "^12.0.0", 35 | "tailwindcss": "^3.0.23", 36 | "typescript": "~4.5.5", 37 | "uuid": "^8.3.2", 38 | "vue-toastification": "^2.0.0-rc.5" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maastrichtlawtech/graphdoc/03326fcadaf6e66a2d372b821580e866e5d20fdd/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | <%= htmlWebpackPlugin.options.title %> 11 | 12 | 13 | 16 |
17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 10 | 11 | 17 | -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maastrichtlawtech/graphdoc/03326fcadaf6e66a2d372b821580e866e5d20fdd/src/assets/logo.png -------------------------------------------------------------------------------- /src/components/graph/GraphModeler.vue: -------------------------------------------------------------------------------- 1 | 98 | 99 | 368 | 369 | -------------------------------------------------------------------------------- /src/components/graph/GraphModelerConfigBar.vue: -------------------------------------------------------------------------------- 1 | 67 | 68 | 209 | 210 | 236 | -------------------------------------------------------------------------------- /src/components/graph/GraphValidationErrors.vue: -------------------------------------------------------------------------------- 1 | 25 | 26 | 33 | 34 | -------------------------------------------------------------------------------- /src/components/shared/ModalComponent.vue: -------------------------------------------------------------------------------- 1 | 26 | 27 | 56 | 57 | -------------------------------------------------------------------------------- /src/components/shared/easymde/EasymdeView.vue: -------------------------------------------------------------------------------- 1 | 4 | 49 | 50 | -------------------------------------------------------------------------------- /src/components/shared/easymde/index.ts: -------------------------------------------------------------------------------- 1 | import EasymdeView from './EasymdeView.vue'; 2 | 3 | export default EasymdeView; -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import App from './App.vue' 3 | 4 | import Toast from "vue-toastification"; 5 | import "vue-toastification/dist/index.css"; 6 | 7 | import './style/index.scss' 8 | 9 | createApp(App) 10 | .use(Toast, {closeOnClick: false, draggable: false}) 11 | .mount('#app') 12 | -------------------------------------------------------------------------------- /src/shims-vue.d.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | declare module '*.vue' { 3 | import type { DefineComponent } from 'vue' 4 | const component: DefineComponent<{}, {}, any> 5 | export default component 6 | } 7 | -------------------------------------------------------------------------------- /src/style/index.scss: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | span.code { 6 | @apply font-mono bg-gray-200 px-0.5 text-xs; 7 | padding-top: 0.1rem; 8 | padding-left: 0.125rem; 9 | padding-bottom: 0.1rem; 10 | padding-right: 0.125rem; 11 | } 12 | 13 | $node_start_color: #03B54D; 14 | $node_decision_color: #6A7FDB; 15 | $node_notice_color: #9a969c; 16 | $node_end_color: #DF5361; 17 | 18 | html { 19 | // to prevent 'jumping' of content when overflow occurs 20 | overflow-y: scroll; 21 | } 22 | 23 | a.styled { 24 | @apply text-blue-600 underline; 25 | &:hover { 26 | @apply text-blue-700; 27 | } 28 | } 29 | 30 | textarea.style-soft { 31 | @apply block shadow-sm focus:ring-blue-500 focus:border-blue-500; 32 | @apply sm:text-sm border border-gray-300 rounded-md; 33 | } 34 | 35 | input[type="text"].style-soft { 36 | @apply flex-1 block w-full rounded-none rounded-md sm:text-sm border-gray-300; 37 | @apply focus:ring-blue-500 focus:border-blue-500; 38 | } 39 | 40 | .node { 41 | 42 | @apply block w-full h-full flex items-center pl-3 text-sm; 43 | @apply rounded; 44 | 45 | border: 1px solid rgb(177, 177, 177); 46 | background-color: white; 47 | /* border-bottom: 4px solid rgb(38, 179, 38); */ 48 | 49 | span { 50 | @apply truncate; 51 | } 52 | 53 | &.node-start { 54 | border-bottom: 4px solid $node_start_color; 55 | } 56 | 57 | &.node-decision { 58 | border-bottom: 4px solid $node_decision_color; 59 | } 60 | 61 | &.node-notice { 62 | border-bottom: 4px solid $node_notice_color; 63 | } 64 | 65 | &.node-end { 66 | border-bottom: 4px solid $node_end_color; 67 | } 68 | 69 | &.node-has-errors:after { 70 | content: ""; 71 | position: absolute; 72 | height: 100%; 73 | width: 20px; 74 | top: 0px; 75 | right: 0; 76 | background-image: radial-gradient(circle at center, theme('colors.red.200') 4px, transparent 5px); 77 | background-size: 20px 20px; 78 | background-position: top center, bottom center; 79 | background-repeat: no-repeat; 80 | } 81 | 82 | span { 83 | &.node-label-variable { 84 | @apply font-mono; 85 | font-size: 0.85rem; 86 | } 87 | &.node-label-content { 88 | // ... 89 | @apply font-serif; 90 | } 91 | &.node-label-unnamed { 92 | font-style: italic; 93 | color:rgb(108, 108, 108); 94 | } 95 | } 96 | } 97 | 98 | .x6-cell { 99 | &.x6-node { 100 | &.x6-node-selected { 101 | .node-start { 102 | border-color: $node_start_color; 103 | box-shadow: 0 0 0 4px rgba($node_start_color, 0.2); 104 | } 105 | 106 | .node-decision { 107 | border-color: $node_decision_color; 108 | box-shadow: 0 0 0 4px rgba($node_decision_color, 0.2); 109 | } 110 | 111 | .node-notice { 112 | border-color: $node_notice_color; 113 | box-shadow: 0 0 0 4px rgba($node_notice_color, 0.25); 114 | } 115 | 116 | .node-end { 117 | border-color: $node_end_color; 118 | box-shadow: 0 0 0 4px rgba($node_end_color, 0.2); 119 | } 120 | } 121 | } 122 | 123 | &.x6-edge { 124 | &:hover path:nth-child(2) { 125 | 126 | } 127 | 128 | &.x6-edge-selected path { 129 | stroke: #1890ff; 130 | stroke-width: 1.5px !important; 131 | } 132 | } 133 | } 134 | 135 | button.btn { 136 | 137 | &[disabled] { 138 | @apply bg-gray-300 cursor-not-allowed; 139 | } 140 | 141 | @apply bg-white border border-gray-300 text-gray-800 px-3 py-1 rounded-md font-normal; 142 | 143 | i { 144 | @apply mr-2 text-lg leading-none; 145 | } 146 | 147 | &:hover { 148 | @apply ring-4 ring-gray-200 border-gray-400 cursor-pointer ; 149 | } 150 | 151 | &.btn-red { 152 | @apply bg-red-600 border-0 text-white; 153 | &:focus { 154 | @apply outline-none ring-2 ring-offset-2 ring-red-500; 155 | } 156 | &:hover { 157 | @apply bg-red-500; 158 | @apply ring-0 cursor-pointer; 159 | } 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /src/utils/antv-model.ts: -------------------------------------------------------------------------------- 1 | import { Graph, Node as AntvNode, Path } from '@antv/x6'; 2 | import { Options } from '@antv/x6/lib/graph/options'; 3 | 4 | import { Node, NodeDefault } from './graph'; 5 | 6 | // import '@antv/x6-vue-shape' 7 | 8 | export const default_edge_label = (text: string | null = '') => { 9 | if (text == null) 10 | return null; 11 | 12 | return { 13 | attrs: { 14 | text: { 15 | text: text, 16 | } 17 | }, 18 | position: { 19 | distance: .40, 20 | }, 21 | } 22 | } 23 | 24 | export const default_edge_attrs = { 25 | // shape: 'dag-edge', 26 | attrs: { 27 | line: { 28 | strokeWidth: '1', 29 | }, 30 | }, 31 | zIndex: -1, 32 | } 33 | 34 | export const graph_options_defaults: Partial = { 35 | grid: true, 36 | 37 | background: { 38 | color: 'white' 39 | }, 40 | 41 | mousewheel: { 42 | enabled: true, 43 | zoomAtMousePosition: true, 44 | modifiers: 'ctrl', 45 | minScale: 0.5, 46 | maxScale: 3, 47 | }, 48 | 49 | scroller: { 50 | enabled: true, 51 | pannable: true, 52 | }, 53 | 54 | connecting: { 55 | 56 | // https://x6.antv.vision/en/docs/tutorial/intermediate/interacting/#%E8%BF%9E%E7%BA%BF%E8%A7%84%E5%88%99 57 | allowBlank: false, 58 | allowMulti: false, 59 | allowLoop: false, 60 | allowEdge: false, 61 | 62 | allowNode: false, 63 | allowPort: true, 64 | 65 | highlight: true, 66 | snap: true, 67 | 68 | // https://x6.antv.vision/en/examples/showcase/practices#dag 69 | connector: 'algo-connector', 70 | connectionPoint: 'boundary', 71 | anchor: 'top', 72 | 73 | validateMagnet({ e, magnet, view, cell }) { 74 | // console.log("magnet", e, magnet, view, cell) 75 | return magnet.getAttribute('port-group') !== 'in' 76 | }, 77 | createEdge(this) { 78 | return this.createEdge(default_edge_attrs) 79 | }, 80 | 81 | validateEdge({edge, type, previous}) { 82 | // console.log("edge data", edge) 83 | // TODO: only allow (multiple) for decision 84 | return true; 85 | }, 86 | 87 | validateConnection({edge, sourceMagnet, targetMagnet}) { 88 | if (sourceMagnet == null || targetMagnet == null) 89 | return false; 90 | 91 | return sourceMagnet.getAttribute('port-group') == "out" && 92 | targetMagnet.getAttribute('port-group') == "in"; 93 | }, 94 | }, 95 | 96 | history: { 97 | enabled: true, 98 | beforeAddCommand(event: any, args: any) { 99 | // console.log(event, args); 100 | // prevent adding/removing tools on hover to be added to history 101 | if (args.key == 'tools') 102 | { 103 | return false 104 | } 105 | }, 106 | }, 107 | resizing: { 108 | enabled: false, 109 | }, 110 | selecting: { 111 | enabled: true, 112 | multiple: false, 113 | 114 | }, 115 | 116 | } 117 | 118 | export function graph_register_defaults(graph: Graph) { 119 | /* 120 | // https://x6.antv.vision/en/docs/api/registry/edge-tool 121 | graph.on('edge:mouseenter', ({ cell }) => { 122 | // console.log(cell) 123 | cell.addTools( 124 | [ 125 | { 126 | name: 'button-remove', 127 | args: { 128 | distance: 30, 129 | fill: '#000000' 130 | }, 131 | }, 132 | ] 133 | ) 134 | }) 135 | graph.on('edge:mouseleave', ({ cell }) => { 136 | setTimeout(() => { 137 | cell.removeTool('button-remove') 138 | }, 1500) 139 | }) 140 | */ 141 | 142 | graph.on('node:mouseenter', ({ cell }) => { 143 | cell.addTools([{name: 'button-remove'}]) 144 | }) 145 | 146 | graph.on('node:mouseleave', ({ cell }) => { 147 | setTimeout(() => { 148 | cell.removeTool('button-remove') 149 | }, 1000) 150 | }) 151 | 152 | Graph.registerConnector('algo-connector', (s, e) => { 153 | const offset = 4 154 | const deltaY = Math.abs(e.y - s.y) 155 | const control = Math.floor((deltaY / 3) * 2) 156 | 157 | const v1 = { x: s.x, y: s.y + offset + control } 158 | const v2 = { x: e.x, y: e.y - offset - control } 159 | 160 | return Path.normalize( 161 | `M ${s.x} ${s.y} 162 | L ${s.x} ${s.y + offset} 163 | C ${v1.x} ${v1.y} ${v2.x} ${v2.y} ${e.x} ${e.y - offset} 164 | L ${e.x} ${e.y} 165 | `, 166 | ) 167 | }, true) 168 | 169 | } 170 | 171 | const default_port_groups = { 172 | in: { 173 | attrs: { 174 | circle: { 175 | r: 6, 176 | stroke: "#6a6a6b", 177 | magnet: true, 178 | } 179 | }, 180 | // markup: { 181 | // tagName: 'path', 182 | // selector: 'path', 183 | // attrs: { 184 | // d: "M 0 5 L 6.25 -5 L -6.25 -5 L 0 5", 185 | // fill: "#fff", 186 | // stroke: "#6a6a6b", 187 | // 'stroke-width': "1", 188 | // magnet: true 189 | // } 190 | // }, 191 | position: 'top' 192 | }, 193 | out: { 194 | attrs: { 195 | circle: { 196 | r: 6, 197 | stroke: "#6a6a6b", 198 | magnet: true, 199 | } 200 | }, 201 | // markup: { 202 | // tagName: 'path', 203 | // selector: 'path', 204 | // attrs: { 205 | // d: "M 0 -5 L 6.25 5 L -6.25 5 L 0 -5", 206 | // fill: "#fff", 207 | // stroke: "#6a6a6b", 208 | // 'stroke-width': "1", 209 | // magnet: true 210 | // } 211 | // }, 212 | position: 'bottom' 213 | }, 214 | } 215 | 216 | export function default_node_ports(ports: Array) { 217 | const default_ports = { 218 | groups: default_port_groups, 219 | items: [] as {id: string, group: keyof typeof default_port_groups}[] 220 | } 221 | 222 | for (const port_group of ports) { 223 | default_ports.items.push({ 224 | id: `${port_group}-1`, 225 | group: port_group, 226 | }) 227 | } 228 | 229 | return default_ports 230 | } 231 | 232 | export type AntvNodeData = { 233 | errors?: boolean, 234 | is_stencil_node?: boolean, 235 | 236 | gd: Node['gd'], 237 | } 238 | 239 | export type node_types = { 240 | [ 241 | key in "start" | "notice" | "decision" | "end" 242 | ]: { 243 | antv_metadata: Omit & {data: Partial}, // override 'data' type of antv 244 | config_fields: { 245 | general?: string[], 246 | additional?: string[] 247 | } 248 | } 249 | }; 250 | export const node_type_default = 'notice'; 251 | 252 | const node_html = { 253 | render(node: AntvNode) { 254 | const data = node.getData() as AntvNodeData; 255 | 256 | let label = ''; 257 | let label_class = ''; 258 | 259 | if (data.gd.variable) { 260 | label = data.gd.variable; 261 | label_class = 'node-label-variable'; 262 | } else if (data.gd.content) { 263 | label = `"${data.gd.content}"`; 264 | label_class = 'node-label-content'; 265 | } else if (data.is_stencil_node ?? false) { 266 | label = `new ${data.gd.type} node`; 267 | label_class = 'node-label-unnamed'; 268 | } else { 269 | // label = `unnamed ${data.gd.type} node`; 270 | label = `${ data.gd.type }_${node.id.toString().substring(0, 8)}`; 271 | label_class = 'node-label-unnamed'; 272 | } 273 | 274 | return( 275 | `
276 | ${ label } 277 |
` 278 | ) 279 | }, 280 | shouldComponentUpdate(node: AntvNode) { 281 | return node.hasChanged('data') 282 | }, 283 | } 284 | 285 | export const node_types: node_types = { 286 | // https://github.com/eensander/graph-quiz/blob/master/resources/js/components/dashboard/graph/GraphModeler.vue#L112 287 | start: { 288 | antv_metadata: { 289 | shape: 'html', 290 | html: node_html, 291 | // tools: ['button-remove'], 292 | width: 180, 293 | height: 36, 294 | data: { 295 | gd: Object.assign({}, NodeDefault.gd, { 296 | type: 'start' 297 | }), 298 | }, 299 | ports: default_node_ports(['out']), 300 | }, 301 | config_fields: { 302 | general: [ 303 | 'variable', 304 | 'label', 305 | ], 306 | additional: [ 307 | // 'annotation' 308 | ], 309 | } 310 | }, 311 | decision: { 312 | antv_metadata: { 313 | shape: 'html', 314 | html: node_html, 315 | // tools: ['button-remove'], 316 | width: 180, 317 | height: 36, 318 | 319 | data: { 320 | gd: Object.assign({}, NodeDefault.gd, { 321 | type: 'decision' 322 | }), 323 | }, 324 | ports: default_node_ports(['in', 'out']), 325 | }, 326 | config_fields: { 327 | general: [ 328 | 'variable', 329 | 'label', 330 | ], 331 | additional: [ 332 | // 'annotation', 333 | // 'subgraph' 334 | ], 335 | } 336 | }, 337 | notice: { 338 | antv_metadata: { 339 | shape: 'html', 340 | html: node_html, 341 | // tools: ['button-remove'], 342 | width: 180, 343 | height: 36, 344 | 345 | data: { 346 | gd: Object.assign({}, NodeDefault.gd, { 347 | type: 'notice' 348 | }), 349 | }, 350 | ports: default_node_ports(['in', 'out']), 351 | }, 352 | config_fields: { 353 | general: [ 354 | 'variable', 355 | 'label', 356 | ], 357 | additional: [ 358 | // 'annotation' 359 | ], 360 | } 361 | }, 362 | end: { 363 | antv_metadata: { 364 | shape: 'html', 365 | html: node_html, 366 | // tools: ['button-remove'], 367 | width: 180, 368 | height: 36, 369 | 370 | data: { 371 | gd: Object.assign({}, NodeDefault.gd, { 372 | type: 'end' 373 | }), 374 | }, 375 | ports: default_node_ports(['in']), 376 | }, 377 | config_fields: { 378 | general: [ 379 | 'variable', 380 | 'label', 381 | ], 382 | } 383 | } 384 | } -------------------------------------------------------------------------------- /src/utils/data/base64.ts: -------------------------------------------------------------------------------- 1 | import { Buffer } from "buffer"; 2 | 3 | // Base64 decode/encode logic from: https://stackoverflow.com/a/61155795 4 | export const base64 = { 5 | decode: (str: string): string => { 6 | // Base64 validation from: https://stackoverflow.com/a/35002237 7 | const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/; 8 | if (!base64regex.test(str)) throw Error("Input is not base64") 9 | return Buffer.from(str, 'base64').toString('binary') 10 | }, 11 | encode: (str: string): string => Buffer.from(str, 'binary').toString('base64') 12 | } 13 | 14 | export default base64; -------------------------------------------------------------------------------- /src/utils/data/download.ts: -------------------------------------------------------------------------------- 1 | // from: https://stackoverflow.com/a/57721086/17864167 2 | export function download(filename: string, text: string, type="text/plain") { 3 | // Create an invisible A element 4 | const a = document.createElement("a"); 5 | a.style.display = "none"; 6 | document.body.appendChild(a); 7 | 8 | // Set the HREF to a Blob representation of the data to be downloaded 9 | a.href = window.URL.createObjectURL( 10 | new Blob([text], { type }) 11 | ); 12 | 13 | // Use download attribute to set set desired file name 14 | a.setAttribute("download", filename); 15 | 16 | // Trigger the download by simulating click 17 | a.click(); 18 | 19 | // Cleanup 20 | window.URL.revokeObjectURL(a.href); 21 | document.body.removeChild(a); 22 | } 23 | -------------------------------------------------------------------------------- /src/utils/data/indent.ts: -------------------------------------------------------------------------------- 1 | // from: self 2 | export function indent(lines: string[], indent = 1, spaces_per = 2): string[] { 3 | return lines.map(line => ' '.repeat(indent*2).concat(line)) 4 | } -------------------------------------------------------------------------------- /src/utils/data/pick.ts: -------------------------------------------------------------------------------- 1 | // from: https://stackoverflow.com/a/47232883/17864167 (2022-04-22) 2 | export function pick(obj: T, ...keys: K[]): Pick { 3 | const ret: any = {}; 4 | keys.forEach(key => { 5 | ret[key] = obj[key]; 6 | }) 7 | return ret; 8 | } -------------------------------------------------------------------------------- /src/utils/data/titleCase.ts: -------------------------------------------------------------------------------- 1 | // from: https://stackoverflow.com/a/63511295/17864167 2 | export default function(str: string){ 3 | return str[0].toUpperCase() + str.slice(1).toLowerCase(); 4 | } -------------------------------------------------------------------------------- /src/utils/data/uuid.ts: -------------------------------------------------------------------------------- 1 | import { v4 as uuidv4 } from 'uuid'; 2 | export function uuid() { 3 | return uuidv4() 4 | } -------------------------------------------------------------------------------- /src/utils/graph.ts: -------------------------------------------------------------------------------- 1 | // This file is basically 'graphdoc-model' 2 | 3 | import { node_types } from "./antv-model"; 4 | import { Filter } from "@antv/x6/lib/registry"; 5 | import { uuid } from "./data/uuid"; 6 | 7 | export type Id = string; 8 | 9 | export interface Node { 10 | graph: Graph 11 | id: Id, 12 | 13 | gd: { 14 | type: keyof node_types, 15 | variable?: string | null, 16 | content?: string | null, 17 | } 18 | // content: {[lang: string]: string}, // for multilang support 19 | 20 | // options: {[key: string]: any}, 21 | appearance: { 22 | x: number, y: number, 23 | width: number, height: number, 24 | }, 25 | } 26 | 27 | export const NodeDefault: Partial = { 28 | appearance: { 29 | x: 0, y: 0, 30 | width: 100, height: 100 31 | }, 32 | gd: { 33 | type: 'notice', // notice is most generic 34 | content: null, 35 | variable: null 36 | }, 37 | } 38 | 39 | export class Node { 40 | 41 | constructor(options: Partial & Pick) { 42 | if (typeof options.id == "undefined") 43 | options.id = uuid(); 44 | // options.variable = `${options.id}`; 45 | 46 | Object.assign(this, NodeDefault, options); 47 | } 48 | 49 | // not sure if this is the best method of determining the type 50 | is_node() { return true; } 51 | is_edge() { return false; } 52 | 53 | get_label() { 54 | // return this.gd.variable ?? this.gd.content ?? this.id.substring(0, 8); 55 | return this.gd.variable ?? this.gd.content ?? `${ this.gd.type }_${this.id.toString().substring(0, 8)}`; 56 | } 57 | 58 | get_variable() { 59 | // return this.gd.variable ?? this.gd.content ?? this.id.substring(0, 8); 60 | return this.gd.variable ?? `${ this.gd.type }_${this.id.toString().substring(0, 8)}`; 61 | } 62 | 63 | get_edges_in() { 64 | return this.graph.edges 65 | .filter(edge => edge.node_to_id == this.id) 66 | } 67 | 68 | get_edges_out() { 69 | return this.graph.edges 70 | .filter(edge => edge.node_from_id == this.id) 71 | } 72 | 73 | get_nodes_in() { 74 | const node_ids = this.get_edges_in() 75 | .map(edge => edge.node_from_id) ?? []; // only return node_ids 76 | return this.graph.nodes 77 | .filter(node => node_ids.includes(node.id)); 78 | } 79 | 80 | get_nodes_out() { 81 | const node_ids = this.get_edges_out() 82 | .map(edge => edge.node_to_id) ?? []; 83 | return this.graph.nodes 84 | .filter(node => node_ids.includes(node.id)); 85 | } 86 | 87 | } 88 | 89 | 90 | export interface Edge { 91 | graph: Graph 92 | id: Id, 93 | node_from_id: Id, 94 | node_to_id: Id, 95 | 96 | gd: { 97 | content: string | null, 98 | } 99 | } 100 | 101 | export const EdgeDefault: Partial = { 102 | gd: { 103 | content: null, 104 | } 105 | } 106 | 107 | export class Edge { 108 | 109 | constructor(options: Partial & Pick) { 110 | options.id = options.id ?? uuid() 111 | 112 | Object.assign(this, EdgeDefault, options); 113 | } 114 | 115 | /* 116 | constructor(graph: Graph, id: Id | null = null, node_from_id: Id, node_to_id: Id, content: string | null = null) { 117 | this.graph = graph; 118 | this.id = id ?? get_id(); 119 | 120 | this.node_from_id = node_from_id; 121 | this.node_to_id = node_to_id; 122 | this.content = content; 123 | } 124 | */ 125 | 126 | is_node() { return false; } 127 | is_edge() { return true; } 128 | 129 | get_node_from() { 130 | return this.graph.nodes 131 | .filter(node => node.id == this.node_from_id)[0] 132 | } 133 | 134 | get_node_to() { 135 | return this.graph.nodes 136 | .filter(node => node.id == this.node_to_id)[0] 137 | } 138 | 139 | } 140 | 141 | class Graph { 142 | name: string; 143 | nodes: Array = []; 144 | edges: Array = []; 145 | 146 | constructor(name = 'Untitled graph') { 147 | this.name = name; 148 | } 149 | 150 | get_nodes_by_type(type: keyof node_types) { 151 | return this.nodes.filter(x => x.gd.type == type) ?? []; 152 | } 153 | 154 | // add_node(options: Partial) { 155 | add_node(options: Partial & Pick) { 156 | this.nodes.push(new Node({...options, graph: this})) 157 | } 158 | 159 | add_edge(options: Partial & Pick) { 160 | this.edges.push(new Edge({...options, graph: this})) 161 | } 162 | 163 | clear() { 164 | this.nodes = []; 165 | this.edges = []; 166 | } 167 | 168 | } 169 | 170 | export default Graph -------------------------------------------------------------------------------- /src/utils/modal.ts: -------------------------------------------------------------------------------- 1 | import { reactive, Ref, ref, UnwrapNestedRefs } from "vue"; 2 | 3 | type TEvents = { 4 | onOpen?: () => void; 5 | onClose?: () => void; 6 | } 7 | 8 | export class Modal { 9 | // private _data: DataT; // for resetting state, like https://stackoverflow.com/a/61509432/17864167 10 | data: UnwrapNestedRefs; 11 | 12 | events: TEvents 13 | 14 | constructor(data?: DataT, events?: TEvents) { 15 | if (data) 16 | this.data = reactive(data) as UnwrapNestedRefs; 17 | else 18 | this.data = reactive({}) as UnwrapNestedRefs; 19 | 20 | this.events = {...events}; 21 | } 22 | 23 | is_open = ref(false); 24 | open() { 25 | this.is_open.value = true; 26 | if (this.events.onOpen) 27 | this.events.onOpen(); 28 | } 29 | close() { 30 | this.is_open.value = false; 31 | if (this.events.onClose) 32 | this.events.onClose(); 33 | } 34 | } -------------------------------------------------------------------------------- /src/utils/transformer/antvis.ts: -------------------------------------------------------------------------------- 1 | import Graph from "../graph"; 2 | import { Graph as AntvGraph } from "@antv/x6"; 3 | import { AntvNodeData, default_edge_attrs, default_edge_label, default_node_ports, node_types, node_type_default } from "../antv-model"; 4 | import { ITransformer } from "."; 5 | import { uuid } from "../data/uuid"; 6 | 7 | export class AntvisTransformer implements ITransformer { 8 | 9 | 10 | // inspired from: https://github.com/eensander/graph-quiz/blob/master/resources/js/components/dashboard/graph/GraphModeler.vue#L442 11 | in(graph: Graph, antv_graph: AntvGraph): Graph { 12 | graph.clear(); 13 | 14 | const local_data = { 15 | 'nodes': antv_graph.getNodes(), 16 | 'edges': antv_graph.getEdges(), 17 | }; 18 | 19 | for(const loc_node of local_data.nodes) { 20 | const loc_node_data = loc_node.getData() as AntvNodeData 21 | const rem_node = { 22 | id: loc_node.id, 23 | gd: loc_node_data.gd, 24 | 25 | appearance: { 26 | x: loc_node.getPosition().x ?? 0, 27 | y: loc_node.getPosition().y ?? 0, 28 | width: loc_node.getSize().width 29 | ?? node_types[loc_node_data.gd.type].antv_metadata.width, 30 | height: loc_node.getSize().height 31 | ?? node_types[loc_node_data.gd.type].antv_metadata.height, 32 | } 33 | } 34 | 35 | graph.add_node(rem_node) 36 | } 37 | 38 | for(const loc_edge of local_data['edges']) { 39 | // console.log("loc_edge", loc_edge); 40 | 41 | // both source and target ought to be known (non null) 42 | if (loc_edge.getSourceCell() == null || loc_edge.getTargetCell() == null) 43 | continue 44 | 45 | let edge_content = loc_edge.getLabelAt(0)?.attrs?.text?.text?.toString() ?? null; 46 | if (edge_content == "") 47 | edge_content = null; 48 | 49 | const rem_edge = { 50 | id: loc_edge.id, 51 | 52 | node_from_id: loc_edge.getSourceCellId(), 53 | node_to_id: loc_edge.getTargetCellId(), 54 | 55 | gd: { 56 | content: edge_content, 57 | }, 58 | 59 | appearance: { 60 | vertices: loc_edge.getVertices(), 61 | }, 62 | } 63 | 64 | graph.add_edge(rem_edge) 65 | } 66 | 67 | return graph; 68 | } 69 | 70 | // inspired from: https://github.com/eensander/graph-quiz/blob/master/resources/js/components/dashboard/graph/GraphModeler.vue#L525 71 | out(graph: Graph) { 72 | 73 | const data_nodes: Array = []; 74 | let last_x = 0; 75 | 76 | Object.values(graph.nodes).forEach((node) => { 77 | 78 | let node_ser = { 79 | // default values (includes ports etc); can be overwritten after spread 80 | ...node_types[node.gd.type].antv_metadata, 81 | 82 | // id: `node-${node.id}`, 83 | id: node.id, 84 | 85 | x: node.appearance?.x ?? (last_x += 50), 86 | y: node.appearance?.y ?? 50, 87 | 88 | data: { 89 | gd: node.gd 90 | }, 91 | } 92 | 93 | // https://stackoverflow.com/a/58245240 94 | node_ser = Object.assign( 95 | {}, 96 | node_types[node.gd.type].antv_metadata ?? node_types.notice.antv_metadata ?? {}, 97 | node_ser, 98 | ); 99 | 100 | // because there are defaults 101 | /* 102 | if (node_ser.width == null && node.appearance?.width != null) 103 | node_ser.width = node.appearance.width; 104 | if (node_ser.height == null && node.appearance?.height != null) 105 | node_ser.height = node.appearance.height; 106 | */ 107 | 108 | data_nodes.push(node_ser); 109 | }) 110 | 111 | const data_edges: Array = []; 112 | 113 | Object.values(graph.edges).forEach((edge) => { 114 | const edge_label = default_edge_label(edge.gd.content); 115 | 116 | const edge_ser = { 117 | ...default_edge_attrs, 118 | 119 | // id: `edge-${edge.id}`, 120 | id: edge.id, 121 | 122 | labels: edge_label != null ? [ edge_label ] : [], 123 | 124 | source: { 125 | // cell: `node-${edge.node_from_id}`, 126 | cell: edge.node_from_id, 127 | port: 'out-1' 128 | }, 129 | target: { 130 | // cell: `node-${edge.node_to_id}`, 131 | cell: edge.node_to_id, 132 | port: 'in-1' 133 | }, 134 | 135 | data: { 136 | // edge_id: edge.id, 137 | gd: edge.gd 138 | }, 139 | 140 | } 141 | 142 | data_edges.push(edge_ser) 143 | }) 144 | 145 | 146 | const data = { 147 | nodes: data_nodes, 148 | edges: data_edges, 149 | } 150 | 151 | // this.graph.fromJSON(data); 152 | 153 | return data; 154 | } 155 | } -------------------------------------------------------------------------------- /src/utils/transformer/docassemble.ts: -------------------------------------------------------------------------------- 1 | import { ITransformer } from "."; 2 | import Graph, { Edge, Node } from "../graph"; 3 | import { indent } from "@/utils/data/indent" 4 | 5 | export type validationErrorPart = string | Node | Edge; 6 | export type validationErrorList = Array[]; 7 | 8 | export class DocassembleTransformer implements ITransformer { 9 | 10 | validate_graph(graph: Graph): validationErrorList { 11 | const errors: validationErrorList = []; 12 | 13 | // General graph errors 14 | const node_start = graph.get_nodes_by_type('start'); 15 | if (node_start.length !== 1) 16 | errors.push([`graph must have exactly one start node (has ${node_start.length})`]); 17 | const nodes_end = graph.get_nodes_by_type('end'); 18 | if (nodes_end.length === 0) 19 | errors.push([`graph must have atleast one end node`]) 20 | 21 | // General input/output amount errors, and uniqueness of ID's. 22 | const variable_list: {[variable: string]: {amount: number, nodes: Node[]}} = {}; 23 | for (const node of graph.nodes) { 24 | 25 | // Add variables to list in this phase, to save iterations 26 | const node_var = this.da_node_get_variable(node); 27 | if (node_var in variable_list) { 28 | variable_list[node_var].amount += 1; 29 | variable_list[node_var].nodes.push(node); 30 | } else { 31 | variable_list[node_var] = {amount: 1, nodes: [node]}; 32 | } 33 | 34 | // Interpreting of edge amount errors 35 | if (node.gd.type == 'start' && node.get_edges_out().length !== 1) 36 | errors.push(['start node ', node, ` must have 1 outgoing edge (has ${node.get_edges_out().length})`]) 37 | 38 | // else if (node.type == 'decision' && node.get_edges_out().length === 1) 39 | // errors.push(`decision node with label ${node.content} has one outgoing edge, which makes it purpose trivial`) // warning 40 | else if (node.gd.type == 'decision' && node.get_edges_in().length === 0) 41 | errors.push(['decision node ', node, ' must have atleast one ingoing edge']) 42 | else if (node.gd.type == 'decision' && node.get_edges_out().length === 0) 43 | errors.push(['decision node ', node, ' must have atleast one outgoing edge']) 44 | 45 | else if (node.gd.type == 'notice' && node.get_edges_in().length === 0) 46 | errors.push(['notice node ', node, ' must have atleast one ingoing edge']) 47 | else if (node.gd.type == 'notice' && node.get_edges_out().length !== 1) 48 | errors.push(['notice node ', node, ' must have one outgoing edge']) 49 | 50 | else if (node.gd.type == 'end' && node.get_edges_in().length === 0){ 51 | errors.push(['end node ', node, ' must have atleast one ingoing edge']) 52 | } 53 | } 54 | 55 | // Checking variable names: duplicate and invalid names 56 | for (const [variable, {amount, nodes}] of Object.entries(variable_list)) { 57 | 58 | const seperated_error_nodes: (string | Node)[] = []; 59 | nodes.forEach((node, i) => { 60 | seperated_error_nodes.push(node); 61 | if (i < (nodes.length - 1)) 62 | seperated_error_nodes.push(', '); 63 | }) 64 | 65 | if (!variable.match(/^[a-zA-Z_][a-zA-Z0-9_]*$/)) 66 | errors.push([ 67 | `invalid (python) variable name '${variable}' on the node(s): `, 68 | ...seperated_error_nodes 69 | ]) 70 | 71 | if (amount > 1) { 72 | errors.push([ 73 | `variable name '${variable}' occurs is defined more than once, in the nodes: `, 74 | ...seperated_error_nodes 75 | ]); 76 | } 77 | } 78 | 79 | // Decision-node specific errors 80 | const nodes_decision = graph.get_nodes_by_type('decision'); 81 | for(const node_decision of nodes_decision) { 82 | let has_edge_out_content_null = false; 83 | 84 | const content_edges_out: {[content: string]: number} = {}; 85 | const node_edges_out = node_decision.get_edges_out(); 86 | 87 | for (const edge_out of node_edges_out) { 88 | if (edge_out.gd.content == null) 89 | has_edge_out_content_null = true; 90 | 91 | // if length == 1, to ensure it's only printed once 92 | // if (content_edges_out.filter(x => x == edge_out.content).length == 1) 93 | // errors.push(`decision node with label '${node_decision.content}' has multiple edges with content '${ edge_out.content }' (should be unique)`) 94 | 95 | if (edge_out.gd.content != null){ 96 | // https://stackoverflow.com/a/39591024 97 | content_edges_out[edge_out.gd.content] = (content_edges_out[edge_out.gd.content]+1) || 1 ; 98 | } 99 | } 100 | 101 | if (has_edge_out_content_null) 102 | errors.push(['decision node ', node_decision, ' has atleast one outgoing edge with no content']); 103 | 104 | Object.entries(content_edges_out).forEach(([content, amount]) => { 105 | 106 | if (amount > 1) { 107 | const edges = node_edges_out.filter(edge => edge.gd.content = content); 108 | const error_start: validationErrorPart[] = [ 109 | `the decision node `, 110 | node_decision, 111 | ` has multiple edges with content '${ edges[0].gd.content }' on the edges: `, 112 | ]; 113 | edges.forEach((tmp_edge, i) => { 114 | error_start.push(tmp_edge) 115 | if (i < (edges.length - 1)) 116 | error_start.push(', ') 117 | }) 118 | 119 | errors.push(error_start) 120 | } 121 | }); 122 | } 123 | 124 | // only perform cycle check if no other errors are present 125 | if (errors.length === 0) { 126 | 127 | // Cycle detection algorithm: https://en.wikipedia.org/wiki/Topological_sorting#Kahn's_algorithm 128 | 129 | const L = []; 130 | const S = graph.nodes.filter(x => x.get_edges_in().length === 0); 131 | 132 | let edges = [...graph.edges] 133 | 134 | while (S.length > 0) { 135 | const n = S.pop()!; 136 | L.push(n); 137 | 138 | for (const e of edges.filter(x => x.node_from_id == n.id)) { 139 | const m = e.get_node_to(); 140 | 141 | edges = edges.filter(x => !(x.id==e.id)) // remove e from edges 142 | if (edges.filter(x => x.node_to_id == m.id).length === 0) 143 | S.push(m) 144 | } 145 | } 146 | 147 | if (edges.length > 0) { 148 | errors.push(['graph must not contain cycles/loops']) 149 | } 150 | } 151 | 152 | return errors; 153 | } 154 | 155 | da_node_get_variable(node: Node): string { 156 | // return `${ node.type }_${ node.variable }` 157 | // return node.gd.variable ?? `${ node.gd.type }_${node.id.toString().substring(0, 8)}`; 158 | return node.get_variable(); 159 | } 160 | 161 | da_node_escaped_markdown(node: Node): string { 162 | if (!node.gd.content) 163 | return `'[content of node ${ node.id.substring(0, 8) }]'`; 164 | 165 | const lines = node.gd.content.split(/\r?\n/); 166 | const escaped = []; 167 | for (const line of lines) { 168 | escaped.push(`${line}`); 169 | } 170 | return "|\n".concat(indent(escaped).join("\n")); 171 | } 172 | 173 | /** 174 | * Construct python code block for docassemble, from given graph and node 175 | * Performs recursive preorder depth-first search 176 | * @param node The root node to start traversal from 177 | * @param indent To indent this code relative to indent of current node 178 | * @returns string[] lines of code 179 | */ 180 | da_build_logic(graph: Graph, node: Node): string[] { 181 | 182 | const node_edges_out = node.get_edges_out(); 183 | 184 | const code: string[] = []; 185 | 186 | switch(node.gd.type) { 187 | case 'start': { 188 | code.push(...[ this.da_node_get_variable(node) ]) 189 | 190 | for(const node_edge_out of node_edges_out) 191 | code.push(...this.da_build_logic(graph, node_edge_out.get_node_to())); 192 | 193 | break 194 | } 195 | case 'end': 196 | code.push(`${ this.da_node_get_variable(node) }`); 197 | 198 | break 199 | case 'decision': { 200 | 201 | for(const node_edge_out of node_edges_out) { 202 | const node_edge_out_content = node_edge_out.gd.content; 203 | if (node_edge_out_content == null) 204 | continue 205 | 206 | const sub_node = this.da_build_logic(graph, node_edge_out.get_node_to()) 207 | 208 | code.push(`if ${ this.da_node_get_variable(node) } == '${ node_edge_out.gd.content }':`); 209 | code.push(...indent(sub_node || ['pass'], 1)) 210 | } 211 | 212 | break 213 | } 214 | case 'notice': { 215 | code.push(`${ this.da_node_get_variable(node) }`); 216 | 217 | for(const node_edge_out of node_edges_out) 218 | code.push(...this.da_build_logic(graph, node_edge_out.get_node_to())); 219 | 220 | break 221 | } 222 | } 223 | 224 | return code 225 | } 226 | 227 | /** 228 | * Generate the docassemble interview configuration content 229 | * @param graph Graph object satisfying the contract in utils/graph.ts 230 | * and has been verified according to the validate_graph() 231 | * @returns string docassemble interview code 232 | */ 233 | out(graph: Graph): string { 234 | 235 | const node_start = graph.get_nodes_by_type('start')[0]; 236 | const nodes_end = graph.get_nodes_by_type('end'); 237 | 238 | const blocks: Array = []; 239 | 240 | for (const node of graph.nodes) { 241 | 242 | switch(node.gd.type) { 243 | case 'start': 244 | blocks.push([ 245 | 'question: Start', 246 | `subquestion: ${ this.da_node_escaped_markdown(node) }`, 247 | `continue button field: ${ this.da_node_get_variable(node) }`, 248 | ]); 249 | 250 | break 251 | case 'end': 252 | blocks.push([ 253 | `event: ${ this.da_node_get_variable(node) }`, 254 | 'question: End', 255 | `subquestion: ${ this.da_node_escaped_markdown(node) }`, 256 | ]); 257 | 258 | break 259 | case 'decision': { 260 | 261 | const edges_out = graph.edges 262 | .filter(edge => edge.node_from_id == node.id); 263 | 264 | let buttons: Array = []; 265 | 266 | for (const edge_out of edges_out) { 267 | if (edge_out.gd.content != null) 268 | buttons.push(` - "${ edge_out.gd.content }"`) 269 | } 270 | 271 | // TODO: add option for priority of buttons (instead of sort) 272 | buttons.sort() 273 | 274 | if (buttons.length > 0) 275 | buttons = ['buttons:', ...buttons] 276 | 277 | blocks.push([ 278 | 'question: Question', 279 | `subquestion: ${ this.da_node_escaped_markdown(node) }`, 280 | `field: ${ this.da_node_get_variable(node) }`, 281 | ...buttons 282 | ]); 283 | 284 | break 285 | } 286 | case 'notice': { 287 | blocks.push([ 288 | 'question: Notice', 289 | `subquestion: ${ this.da_node_escaped_markdown(node) }`, 290 | `continue button field: ${ this.da_node_get_variable(node) }`, 291 | ]); 292 | 293 | break 294 | } 295 | } 296 | } 297 | 298 | const logic_code: string[] = []; 299 | logic_code.push(...indent(this.da_build_logic(graph, node_start))); 300 | 301 | if (logic_code.length > 0) { 302 | blocks.push([ 303 | 'mandatory: True', 304 | 'code: |', ...logic_code 305 | ]) 306 | } 307 | 308 | let content = blocks.map((block) => { 309 | if (typeof block == "string") 310 | return block; 311 | else if(Array.isArray(block)) 312 | return block.join("\n"); 313 | }).join("\n---\n") 314 | 315 | return content; 316 | } 317 | } -------------------------------------------------------------------------------- /src/utils/transformer/index.ts: -------------------------------------------------------------------------------- 1 | import { Graph as AntvGraph } from "@antv/x6"; 2 | import { default as Graph, } from "../graph"; 3 | import { DocassembleTransformer } from "./docassemble"; 4 | import { AntvisTransformer } from "./antvis"; 5 | import { JSONGraphData, JSONTransformer } from "./json"; 6 | 7 | export interface ITransformer { 8 | in?: (graph: Graph, ...params: Array) => Graph 9 | out: (graph: Graph, ...params: Array) => any 10 | } 11 | 12 | export default class { 13 | 14 | graph: Graph; 15 | json: JSONTransformer; 16 | antvis: AntvisTransformer; 17 | docassemble: DocassembleTransformer; 18 | 19 | 20 | constructor(graph?: Graph) { 21 | this.graph = graph ?? new Graph(); 22 | 23 | this.json = new JSONTransformer() 24 | this.antvis = new AntvisTransformer() 25 | this.docassemble = new DocassembleTransformer() 26 | } 27 | 28 | // json 29 | 30 | in_json(data: JSONGraphData) { 31 | this.graph = this.json.in_json(this.graph, data); 32 | 33 | return this; 34 | } 35 | 36 | out_json() { 37 | return this.json.out_json(this.graph); 38 | } 39 | 40 | // antv 41 | 42 | in_antv(antv_graph: AntvGraph) { 43 | this.graph = this.antvis.in(this.graph, antv_graph) 44 | 45 | return this; 46 | } 47 | 48 | out_antv() { 49 | return this.antvis.out(this.graph) 50 | } 51 | 52 | // docassemble 53 | 54 | out_docassemble() { 55 | return this.docassemble.out(this.graph) 56 | } 57 | } -------------------------------------------------------------------------------- /src/utils/transformer/json.ts: -------------------------------------------------------------------------------- 1 | import { pick } from "@/utils/data/pick"; 2 | import Graph, { Edge, Node } from "@/utils/graph"; 3 | 4 | // export type JSONGraphData = Partial & Pick 5 | // export type JSONGraphData = Partial & Pick & { 6 | export type JSONGraphData = { 7 | 'main': { 8 | 'name': string 9 | }, 10 | 'nodes': Array & Pick>, 11 | 'edges': Array & Pick>, 12 | } 13 | 14 | export class JSONTransformer { 15 | 16 | in_json(graph: Graph, data: JSONGraphData) { 17 | graph.clear(); 18 | 19 | graph.name = data.main.name; 20 | for (const node of data.nodes) { 21 | graph.add_node(node) 22 | } 23 | for (const edge of data.edges) { 24 | graph.add_edge(edge) 25 | } 26 | 27 | return graph; 28 | } 29 | 30 | out_json(graph: Graph) { 31 | 32 | const data = { 33 | 'nodes': graph.nodes.map(node => pick(node, 'id', 'appearance', 'gd')), 34 | 'edges': graph.edges.map(edge => pick(edge, 'id', 'node_from_id', 'node_to_id', 'gd')), 35 | 'main': { 36 | 'name': graph.name 37 | } 38 | } 39 | 40 | return data; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | content: [ 3 | "./index.html", 4 | "./src/**/*.{vue,js,ts,jsx,tsx}", 5 | ], 6 | theme: { 7 | extend: {}, 8 | }, 9 | plugins: [ 10 | require('@tailwindcss/forms')({ 11 | strategy: 'base', 12 | }), 13 | ], 14 | } 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "esnext", 5 | "strict": true, 6 | "jsx": "preserve", 7 | "moduleResolution": "node", 8 | "skipLibCheck": true, 9 | "esModuleInterop": true, 10 | "allowSyntheticDefaultImports": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "useDefineForClassFields": true, 13 | "sourceMap": true, 14 | "baseUrl": ".", 15 | "types": [ 16 | "webpack-env" 17 | ], 18 | "paths": { 19 | "@/*": [ 20 | "src/*" 21 | ] 22 | }, 23 | "lib": [ 24 | "esnext", 25 | "dom", 26 | "dom.iterable", 27 | "scripthost" 28 | ] 29 | }, 30 | "include": [ 31 | "src/**/*.ts", 32 | "src/**/*.tsx", 33 | "src/**/*.vue", 34 | "tests/**/*.ts", 35 | "tests/**/*.tsx" 36 | ], 37 | "exclude": [ 38 | "node_modules" 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | // https://cli.vuejs.org/config/#publicpath 2 | // "The value can also be set to an empty string ('') or a relative path (./) 3 | // so that all assets are linked using relative paths. This allows the built 4 | // bundle to be deployed under any public path, or used in a file system based 5 | // environment like a Cordova hybrid app." 6 | module.exports = { 7 | publicPath: '', 8 | } --------------------------------------------------------------------------------