Compare commits
328 Commits
react_canv
...
v6.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63dbe41df0 | ||
|
|
c1485224ba | ||
|
|
9b58fa3963 | ||
|
|
3e69dafef9 | ||
|
|
442462af2d | ||
|
|
0d9ba41c9a | ||
|
|
73ef7df153 | ||
|
|
5fe7b37fc2 | ||
|
|
093e1f6a08 | ||
|
|
1e95edbc6f | ||
|
|
c92313f9b1 | ||
|
|
b8b66642d5 | ||
|
|
39dbbe3db9 | ||
|
|
1ba35fd518 | ||
|
|
04443ad85e | ||
|
|
17952c8829 | ||
|
|
a8234a1a8d | ||
|
|
3f86c36c44 | ||
|
|
a2cf7483f1 | ||
|
|
72739dc3d3 | ||
|
|
07df1fd6f5 | ||
|
|
ef9e72ed3a | ||
|
|
8df5ff94b6 | ||
|
|
17c5a3cfb9 | ||
|
|
a69ec38a5a | ||
|
|
2c66c18f6d | ||
|
|
012418741d | ||
|
|
3d71f5a80b | ||
|
|
c5b24f6e7b | ||
|
|
655462087f | ||
|
|
6bdc21826d | ||
|
|
27194cfd36 | ||
|
|
61c8d7e610 | ||
|
|
08f9ea6aa6 | ||
|
|
cef51577a3 | ||
|
|
e8fb8804a8 | ||
|
|
ef822f5540 | ||
|
|
2a28368d5e | ||
|
|
987d3c84ab | ||
|
|
1ea06fb3d5 | ||
|
|
3fdbe4c975 | ||
|
|
1aa1058eb5 | ||
|
|
ff2a668842 | ||
|
|
86b4c97e89 | ||
|
|
696994f0ad | ||
|
|
7d133abf58 | ||
|
|
53068cbe1f | ||
|
|
379e808d70 | ||
|
|
15d70e988e | ||
|
|
355add35a8 | ||
|
|
280a1fc0e4 | ||
|
|
eeece55c31 | ||
|
|
fb5f6e95e7 | ||
|
|
8d73d238fe | ||
|
|
49242281e7 | ||
|
|
f148b8e391 | ||
|
|
f78c5de4ae | ||
|
|
6e77f3503a | ||
|
|
4787163492 | ||
|
|
d8009f02a5 | ||
|
|
aa186f7040 | ||
|
|
09358d9b93 | ||
|
|
b84265d802 | ||
|
|
410d6cfccf | ||
|
|
1dd26253b2 | ||
|
|
7e15c55a73 | ||
|
|
61bc333658 | ||
|
|
8cf6b0269c | ||
|
|
51258b68b6 | ||
|
|
469dbc00af | ||
|
|
dbe0e595b8 | ||
|
|
20a6bfe012 | ||
|
|
fd38a20c23 | ||
|
|
5124c1a628 | ||
|
|
46d7aa14b5 | ||
|
|
971bae29f3 | ||
|
|
5ec4327912 | ||
|
|
1511bec663 | ||
|
|
3e91dad2e1 | ||
|
|
1d5ab683c3 | ||
|
|
96d6d0dcf2 | ||
|
|
ddc17a8dc3 | ||
|
|
a9e5575646 | ||
|
|
d0331cb205 | ||
|
|
8556937ff1 | ||
|
|
341e540af6 | ||
|
|
9bd86480e9 | ||
|
|
5e0a75d4ed | ||
|
|
91789729c4 | ||
|
|
361fbe4ffe | ||
|
|
80e9bdcfc0 | ||
|
|
97c66b99ab | ||
|
|
220852697f | ||
|
|
8e05f28931 | ||
|
|
a450c9b5b5 | ||
|
|
508fbf2777 | ||
|
|
11dc57a834 | ||
|
|
ed63bf151c | ||
|
|
6dd0677b28 | ||
|
|
ea6130d1a9 | ||
|
|
3c8839a1ec | ||
|
|
a7ab686463 | ||
|
|
11c2c70ec6 | ||
|
|
a3ca75d039 | ||
|
|
dedc627294 | ||
|
|
c000ffc3cd | ||
|
|
37babb3bb2 | ||
|
|
33651b22a1 | ||
|
|
dfc7102b1c | ||
|
|
a399f135ba | ||
|
|
36e097cb70 | ||
|
|
23e1742e99 | ||
|
|
5d913f28ba | ||
|
|
1c955b4d12 | ||
|
|
741851b855 | ||
|
|
4729bbedc9 | ||
|
|
994ff7c714 | ||
|
|
05f1345e62 | ||
|
|
5079188b99 | ||
|
|
13dd53f185 | ||
|
|
502faeef5a | ||
|
|
39c4f37d12 | ||
|
|
1dccace7e2 | ||
|
|
85857afd31 | ||
|
|
c875ce6e22 | ||
|
|
422b967be7 | ||
|
|
1a8b3caca4 | ||
|
|
116a296bf5 | ||
|
|
57f4e2d832 | ||
|
|
b0089662aa | ||
|
|
8ded9cd30e | ||
|
|
14a76ffbf5 | ||
|
|
1a7acafdc8 | ||
|
|
ad25420166 | ||
|
|
1fb622366b | ||
|
|
761ac41901 | ||
|
|
c8aa7a67ac | ||
|
|
e923245f6d | ||
|
|
0cb6c66b1f | ||
|
|
f20bb0bd2e | ||
|
|
0deaec246d | ||
|
|
cb79d4e390 | ||
|
|
35a53c8134 | ||
|
|
326567c290 | ||
|
|
7fa51d5ea0 | ||
|
|
e72e7e999c | ||
|
|
25fe2a8e64 | ||
|
|
e59edefbeb | ||
|
|
27022d2965 | ||
|
|
897237c9ca | ||
|
|
f0242c7924 | ||
|
|
cf9f9cb01d | ||
|
|
4c90895bcd | ||
|
|
3f6d04521d | ||
|
|
3a46047ee8 | ||
|
|
77418ee8e7 | ||
|
|
07c74d850f | ||
|
|
75d1b6bb5d | ||
|
|
4cae28c808 | ||
|
|
cff54426c9 | ||
|
|
3dd329b209 | ||
|
|
6396abc17c | ||
|
|
16f6b484b5 | ||
|
|
68c2c76d72 | ||
|
|
16033a658c | ||
|
|
96655baff2 | ||
|
|
630467cf97 | ||
|
|
23b174736c | ||
|
|
9de0708535 | ||
|
|
4786208fe6 | ||
|
|
98888f6d96 | ||
|
|
f017873cdc | ||
|
|
d14f1a3bb3 | ||
|
|
cdda07b026 | ||
|
|
fa6bebce6f | ||
|
|
04362b8da8 | ||
|
|
0dbdee9f18 | ||
|
|
a5c4d917eb | ||
|
|
93cc419767 | ||
|
|
7a7fef85d0 | ||
|
|
4eccdbdc8a | ||
|
|
962883ce4a | ||
|
|
6571dbe159 | ||
|
|
8fbd87df8c | ||
|
|
ce38f77027 | ||
|
|
bec82cd92c | ||
|
|
d2c5bac65c | ||
|
|
5fc17b6217 | ||
|
|
d2e1cf2dd1 | ||
|
|
9e2f6ffb0f | ||
|
|
cc900b2a90 | ||
|
|
51c6bd2391 | ||
|
|
a8c6031166 | ||
|
|
a6655dbf2d | ||
|
|
37532edd01 | ||
|
|
4538884a96 | ||
|
|
c9f7d2c516 | ||
|
|
5c66c84a31 | ||
|
|
4a57ecdc97 | ||
|
|
9fc65b7d7f | ||
|
|
2573c5d8cc | ||
|
|
a46e17306b | ||
|
|
7045d75ae7 | ||
|
|
47e4a14520 | ||
|
|
58eee117e9 | ||
|
|
09d5b65e59 | ||
|
|
6512ca0eb0 | ||
|
|
bfde4226ec | ||
|
|
ea6adbe61b | ||
|
|
5f74600157 | ||
|
|
3590245f6c | ||
|
|
46aa99b2ea | ||
|
|
80f86867fd | ||
|
|
52f9105b1b | ||
|
|
e9558919fb | ||
|
|
dd5a0b7d8d | ||
|
|
0f7930e132 | ||
|
|
3823adc8e8 | ||
|
|
fce011a11b | ||
|
|
4962343b54 | ||
|
|
45649146c9 | ||
|
|
74e24331ed | ||
|
|
0cc469fa44 | ||
|
|
0b78ba69c6 | ||
|
|
ca301b9d4d | ||
|
|
ad6c77da28 | ||
|
|
66b72b4465 | ||
|
|
bb878657ba | ||
|
|
1db1e21fc2 | ||
|
|
f4920ab4d0 | ||
|
|
ccfd8e026c | ||
|
|
702290d9b3 | ||
|
|
347377d3b4 | ||
|
|
44fd2ad91b | ||
|
|
39d49c9ee0 | ||
|
|
61c6d4b161 | ||
|
|
b324154eff | ||
|
|
17350a740a | ||
|
|
d7fc5370ab | ||
|
|
5fbe7ce9e4 | ||
|
|
3e37e34155 | ||
|
|
f46680596c | ||
|
|
3a2d3ccb73 | ||
|
|
f4aa1852ed | ||
|
|
e167885038 | ||
|
|
619e8a2347 | ||
|
|
4c1e67106a | ||
|
|
d08be537e1 | ||
|
|
8e5243da95 | ||
|
|
22236f8420 | ||
|
|
99fe94ae29 | ||
|
|
3b0c19d998 | ||
|
|
fc67d477a9 | ||
|
|
e4d427e0d3 | ||
|
|
bc2d444aee | ||
|
|
b15a326dab | ||
|
|
b54feb03e4 | ||
|
|
39eddc0a2a | ||
|
|
85a1fde2e5 | ||
|
|
c0dae87d02 | ||
|
|
fddec93370 | ||
|
|
01ffbce479 | ||
|
|
30790682d3 | ||
|
|
dc9c2eae66 | ||
|
|
969152a814 | ||
|
|
2e38a7cfd5 | ||
|
|
e3fe7319c1 | ||
|
|
c3a332ebab | ||
|
|
314bb908f9 | ||
|
|
9b16b3f4ed | ||
|
|
722b6d98f3 | ||
|
|
2c6971be9a | ||
|
|
ea0160cbcf | ||
|
|
efc53eec9b | ||
|
|
b5c86159d1 | ||
|
|
ea2070ec98 | ||
|
|
39c3611686 | ||
|
|
1ff63d4117 | ||
|
|
e80da8853f | ||
|
|
a06e23eaf6 | ||
|
|
4b599fc37f | ||
|
|
def92af022 | ||
|
|
01e9f5f2db | ||
|
|
aa1a02774d | ||
|
|
e60aac56db | ||
|
|
b2e74d8b97 | ||
|
|
e333a4f168 | ||
|
|
1d316409e1 | ||
|
|
9d947d40b7 | ||
|
|
7d80f15358 | ||
|
|
28844b86eb | ||
|
|
70c9aeac66 | ||
|
|
12a7bfbda5 | ||
|
|
650061db4a | ||
|
|
48c6d1f038 | ||
|
|
7cea7032f0 | ||
|
|
2b346aa326 | ||
|
|
0f7f8853d1 | ||
|
|
3a57ea711e | ||
|
|
de208e3250 | ||
|
|
2df09edb7e | ||
|
|
ba1401a8f2 | ||
|
|
c6137d03ce | ||
|
|
ead43957e3 | ||
|
|
b7d8ffa793 | ||
|
|
a289c73b68 | ||
|
|
b75976d091 | ||
|
|
a95010652d | ||
|
|
4cd24940c8 | ||
|
|
0f1dec1ebc | ||
|
|
eedc21cc87 | ||
|
|
b719178f44 | ||
|
|
12724748e6 | ||
|
|
0ebd6d918f | ||
|
|
591ec2e76e | ||
|
|
9f95ac8451 | ||
|
|
e3fc996092 | ||
|
|
de9765358f | ||
|
|
fa34f5c98b | ||
|
|
f4ac467056 | ||
|
|
5b142c1c61 | ||
|
|
40219d7a4d | ||
|
|
0eb432b302 | ||
|
|
ad5e7a4b4d | ||
|
|
0583db1c74 | ||
|
|
0b92e939ab | ||
|
|
8997eba4b4 | ||
|
|
3fbbeb82de |
@@ -2,30 +2,22 @@ version: 2
|
||||
jobs:
|
||||
build:
|
||||
docker:
|
||||
- image: projectstorm/react-diagrams-ci
|
||||
|
||||
- image: buildkite/puppeteer
|
||||
working_directory: ~/repo
|
||||
|
||||
steps:
|
||||
- checkout
|
||||
|
||||
# Download and cache dependencies
|
||||
- restore_cache:
|
||||
keys:
|
||||
- v1-dependencies-{{ checksum "package.json" }}
|
||||
|
||||
- v1-dependencies-{{ checksum "yarn.lock" }}
|
||||
- run: yarn install
|
||||
|
||||
- save_cache:
|
||||
paths:
|
||||
- node_modules
|
||||
key: v1-dependencies-{{ checksum "package.json" }}
|
||||
key: v1-dependencies-{{ checksum "yarn.lock" }}
|
||||
|
||||
# test building project
|
||||
- run: yarn run prepublishOnly
|
||||
|
||||
# test building storybook
|
||||
- run: yarn run storybook:build
|
||||
- run: yarn run build
|
||||
|
||||
# test e2e tests and jest snapshots
|
||||
- run: yarn run test:ci
|
||||
- run: cd packages/diagrams-demo-gallery && yarn run test --ci
|
||||
- run: cd packages/react-diagrams-routing && yarn run test --ci
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
[*]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# Some exceptions
|
||||
[{package.json}]
|
||||
[{package.json,*.yml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
4
.gitbook.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
root: ./docs/
|
||||
|
||||
structure:
|
||||
summary: README.md
|
||||
|
Before Width: | Height: | Size: 438 KiB After Width: | Height: | Size: 438 KiB |
|
Before Width: | Height: | Size: 313 KiB After Width: | Height: | Size: 313 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
BIN
.gitbook/assets/logo.jpg
Normal file
|
After Width: | Height: | Size: 129 KiB |
9
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -4,21 +4,18 @@
|
||||
- [ ] The tests pass on CircleCI
|
||||
- [ ] You have referenced the issue(s) or other PR(s) this fixes/relates-to
|
||||
- [ ] The PR Template has been filled out (see below)
|
||||
- [ ] Had a beer because you are awesome
|
||||
- [ ] Had a beer/coffee because you are awesome
|
||||
|
||||
## What?
|
||||
|
||||
(My awesome new feature does this really cool thing.)
|
||||
|
||||
## Why?
|
||||
|
||||
(Because obviously it could not do it before)
|
||||
|
||||
## How?
|
||||
|
||||
|
||||
(Basically I did this and that because im a super 1337 hacker)
|
||||
|
||||
## Feel-Good "programming lol" image:
|
||||
## Feel good image:
|
||||
|
||||
(Add your own one below :])
|
||||
|
||||
|
||||
200
.gitignore
vendored
@@ -1,194 +1,8 @@
|
||||
dist/
|
||||
dist/main.js
|
||||
dist/main.js.map
|
||||
/package
|
||||
*.tgz
|
||||
@types/
|
||||
|
||||
.out
|
||||
|
||||
# Created by https://www.gitignore.io/api/net,netbeans,sublimetext,phpstorm,windows,osx,node
|
||||
|
||||
#!! ERROR: net is undefined. Use list command to see defined gitignore types !!#
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
nbdist/
|
||||
nbactions.xml
|
||||
.nb-gradle/
|
||||
|
||||
|
||||
### SublimeText ###
|
||||
# cache files for sublime text
|
||||
*.tmlanguage.cache
|
||||
*.tmPreferences.cache
|
||||
*.stTheme.cache
|
||||
|
||||
# workspace files are user-specific
|
||||
*.sublime-workspace
|
||||
|
||||
# project files should be checked into the repository, unless a significant
|
||||
# proportion of contributors will probably not be using SublimeText
|
||||
# *.sublime-project
|
||||
|
||||
# sftp configuration file
|
||||
sftp-config.json
|
||||
|
||||
# Package control specific files
|
||||
Package Control.last-run
|
||||
Package Control.ca-list
|
||||
Package Control.ca-bundle
|
||||
Package Control.system-ca-bundle
|
||||
Package Control.cache/
|
||||
Package Control.ca-certs/
|
||||
bh_unicode_properties.cache
|
||||
|
||||
# Sublime-github package stores a github token in this file
|
||||
# https://packagecontrol.io/packages/sublime-github
|
||||
GitHub.sublime-settings
|
||||
|
||||
|
||||
### PhpStorm ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/workspace.xml
|
||||
.idea/tasks.xml
|
||||
.idea/dictionaries
|
||||
.idea/vcs.xml
|
||||
.idea/jsLibraryMappings.xml
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/dataSources.ids
|
||||
.idea/dataSources.xml
|
||||
.idea/dataSources.local.xml
|
||||
.idea/sqlDataSources.xml
|
||||
.idea/dynamic.xml
|
||||
.idea/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/gradle.xml
|
||||
.idea/libraries
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
### PhpStorm Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
|
||||
|
||||
### Windows ###
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
|
||||
### OSX ###
|
||||
*.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
|
||||
### Node ###
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules
|
||||
jspm_packages
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
dist
|
||||
.DS_Store
|
||||
.idea
|
||||
.out
|
||||
*.zip
|
||||
.env
|
||||
node_modules
|
||||
yarn-error.log
|
||||
|
||||
194
.npmignore
@@ -1,194 +0,0 @@
|
||||
demos
|
||||
images
|
||||
docs
|
||||
.out
|
||||
.storybook
|
||||
.circleci
|
||||
tests
|
||||
*.md
|
||||
|
||||
# Created by https://www.gitignore.io/api/net,netbeans,sublimetext,phpstorm,windows,osx,node
|
||||
|
||||
#!! ERROR: net is undefined. Use list command to see defined gitignore types !!#
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
nbdist/
|
||||
nbactions.xml
|
||||
.nb-gradle/
|
||||
|
||||
|
||||
### SublimeText ###
|
||||
# cache files for sublime text
|
||||
*.tmlanguage.cache
|
||||
*.tmPreferences.cache
|
||||
*.stTheme.cache
|
||||
|
||||
# workspace files are user-specific
|
||||
*.sublime-workspace
|
||||
|
||||
# project files should be checked into the repository, unless a significant
|
||||
# proportion of contributors will probably not be using SublimeText
|
||||
# *.sublime-project
|
||||
|
||||
# sftp configuration file
|
||||
sftp-config.json
|
||||
|
||||
# Package control specific files
|
||||
Package Control.last-run
|
||||
Package Control.ca-list
|
||||
Package Control.ca-bundle
|
||||
Package Control.system-ca-bundle
|
||||
Package Control.cache/
|
||||
Package Control.ca-certs/
|
||||
bh_unicode_properties.cache
|
||||
|
||||
# Sublime-github package stores a github token in this file
|
||||
# https://packagecontrol.io/packages/sublime-github
|
||||
GitHub.sublime-settings
|
||||
|
||||
|
||||
### PhpStorm ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
.idea/workspace.xml
|
||||
.idea/tasks.xml
|
||||
.idea/dictionaries
|
||||
.idea/vcs.xml
|
||||
.idea/jsLibraryMappings.xml
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
.idea/dataSources.ids
|
||||
.idea/dataSources.xml
|
||||
.idea/dataSources.local.xml
|
||||
.idea/sqlDataSources.xml
|
||||
.idea/dynamic.xml
|
||||
.idea/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
.idea/gradle.xml
|
||||
.idea/libraries
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
.idea/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
### PhpStorm Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
|
||||
|
||||
### Windows ###
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
|
||||
### OSX ###
|
||||
*.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
|
||||
### Node ###
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules
|
||||
jspm_packages
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
.idea
|
||||
3
.prettierignore
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
dist
|
||||
.out
|
||||
8
.prettierrc
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"jsxBracketSameLine": true,
|
||||
"useTabs": true,
|
||||
"printWidth": 120,
|
||||
"trailingComma": "none"
|
||||
}
|
||||
14
.storybook/addon-code/react.js
vendored
@@ -1,14 +0,0 @@
|
||||
import React from 'react';
|
||||
import addons from '@storybook/addons';
|
||||
|
||||
export class WithCode extends React.Component {
|
||||
render() {
|
||||
const { children, code } = this.props;
|
||||
const channel = addons.getChannel();
|
||||
|
||||
// send the notes to the channel.
|
||||
channel.emit('storybook/code/set_code', code);
|
||||
// return children elements.
|
||||
return children;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
import React from 'react';
|
||||
import addons from '@storybook/addons';
|
||||
import SyntaxHighlighter from 'react-syntax-highlighter';
|
||||
import { github } from 'react-syntax-highlighter/styles/hljs';
|
||||
|
||||
/**
|
||||
* @author Dylan
|
||||
*
|
||||
* Simple little addon for displaying code, might make this a seperate project at some point
|
||||
*/
|
||||
export class CodePreview extends React.Component {
|
||||
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
this.state = {
|
||||
code: ''
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { channel, api } = this.props;
|
||||
// Listen to the notes and render it.
|
||||
channel.on('storybook/code/set_code', (code) => {
|
||||
this.onAddCode(code);
|
||||
});
|
||||
|
||||
// Clear the current notes on every story change.
|
||||
this.stopListeningOnStory = api.onStory(() => {
|
||||
this.onAddCode('');
|
||||
});
|
||||
}
|
||||
|
||||
// This is some cleanup tasks when the Notes panel is unmounting.
|
||||
componentWillUnmount() {
|
||||
if (this.stopListeningOnStory) {
|
||||
this.stopListeningOnStory();
|
||||
}
|
||||
|
||||
this.unmounted = true;
|
||||
const { channel } = this.props;
|
||||
channel.removeListener('storybook/notes/add_notes', this.onAddCode);
|
||||
}
|
||||
|
||||
onAddCode(code) {
|
||||
this.setState({ code: code });
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<SyntaxHighlighter
|
||||
customStyle={{width: '100%', overflowX:'hidden', tabSize: 4}}
|
||||
showLineNumbers={true}
|
||||
language='language-tsx'
|
||||
style={github}
|
||||
>
|
||||
{this.state.code}
|
||||
</SyntaxHighlighter>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Register the addon with a unique name.
|
||||
addons.register('storybook/code', api => {
|
||||
// Also need to set a unique name to the panel.
|
||||
addons.addPanel('storybook/code/panel', {
|
||||
title: 'Code preview',
|
||||
render: () => <CodePreview channel={addons.getChannel()} api={api} />,
|
||||
});
|
||||
});
|
||||
@@ -1,39 +0,0 @@
|
||||
const path = require('path');
|
||||
module.exports = {
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.scss$/,
|
||||
loaders: ["style-loader", "css-loader", "sass-loader"],
|
||||
include: path.resolve(__dirname, '../')
|
||||
},
|
||||
{
|
||||
test: /\.css/,
|
||||
loaders: ["style-loader", "css-loader"],
|
||||
include: path.resolve(__dirname, '../')
|
||||
},
|
||||
{
|
||||
enforce: 'pre',
|
||||
test: /\.js$/,
|
||||
loader: "source-map-loader",
|
||||
exclude: [
|
||||
/node_modules\//
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
loader: 'awesome-typescript-loader',
|
||||
},
|
||||
{
|
||||
test: /\.(woff|woff2|eot|ttf|otf|svg)$/,
|
||||
loader: "file-loader"
|
||||
}
|
||||
]
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'storm-react-diagrams': path.join(__dirname, "..", "src", "main")
|
||||
},
|
||||
extensions: [".tsx", ".ts", ".js"]
|
||||
}
|
||||
};
|
||||
152
CHANGELOG.md
@@ -1,65 +1,131 @@
|
||||
__5.1.0__
|
||||
__6.2.0__
|
||||
|
||||
* [api] Rename XXXFactory into AbstractXXXFactory
|
||||
* [refactor] tslint and prettier are now the same
|
||||
* [refactor] Each class now explicitely has its own class file (consistency)
|
||||
* [feature] Smooth vertical links (no longer limited to horizontal)
|
||||
* [feature] Dedicated documentation via gitbook
|
||||
* [bug] forgot to export some
|
||||
* [refactor] consistently use lodash where possible
|
||||
* [maintenance] upgrade node modules
|
||||
* (improvement) Move away fromn math-js (https://github.com/projectstorm/react-diagrams/pull/651)
|
||||
* (fix) https://github.com/projectstorm/react-diagrams/pull/639
|
||||
* (fix) Fixing link spawning at (0,0) when clicking port once (inspired by https://github.com/projectstorm/react-diagrams/pull/637)
|
||||
|
||||
__6.1.1__
|
||||
|
||||
* (feature) https://github.com/projectstorm/react-diagrams/pull/576 [Add zoom to fit nodes feature, fixes #568]
|
||||
* (improvement) https://github.com/projectstorm/react-diagrams/pull/621 [Support deriving from DefaultLabelModel]
|
||||
* (fix) https://github.com/projectstorm/react-diagrams/pull/603
|
||||
[Fixes selectionChanged listener not being deregistered on NodeWidget, Fixes unchecked access to this.props.link.getSourcePort() on LinkWidget]
|
||||
* (maintenance) bump everything
|
||||
* fix serialize/deserialize issue with example project raw JS node
|
||||
|
||||
__6.0.0__
|
||||
|
||||
Note: This is a complete rewrite of the library, a good place to start to see how the new system works
|
||||
is with the new demo project which illustrates the new capability.
|
||||
|
||||
I would also recommend taking a look at the new updated DiamondPort widget which shows more capability.
|
||||
|
||||
* Break up library into monorepo
|
||||
* Introduce react-canvas-core as a new framework
|
||||
* Use geometry classes instead of raw X and Y primitives so we can do matrix stuff in the future
|
||||
* move testing framework to a name based system instead of ID's
|
||||
* Introduce multiple layers (can now have multiple node and link layers)
|
||||
* Rewrote the deserialization system to be promise based
|
||||
* Completely overhauled the observer framework on the models
|
||||
* Moved all the logic in the DiagramWidget into a a new hierarchical state machine
|
||||
* Introduces new states for editing
|
||||
* Introduced faster layout rendering when transforming the canvas directly
|
||||
* Moved all canvas smart routing into its own link-type under routing package
|
||||
* Broke up link rendering into a much more modular system that is much easier to extend
|
||||
* Introduced port alignment allowing the developer to specify how enter it
|
||||
* Improved generics throughout the entire model system with Mapped Types
|
||||
* Rewrote all the styles using emotion instead of sass
|
||||
* Fixed up all the demos to use the new API
|
||||
* Introduced a demo project that illustrates how to use the library with ES6 as well as with Typescript
|
||||
* Improved the grid rendering system to allow graphical elements to specify how they get transformed
|
||||
* Introduced a performance widget for improving performance in a more deterministic way by comparing the serialization of the model (with a way of opting out)
|
||||
* Renamed a bunch of methods to be more consistent and more understandable
|
||||
* Completely removed the double render state system that required nodes to render before links, this is done when ports report their new positions
|
||||
* Ports can now dynamically be added and removed without having to tell the system it happeend
|
||||
* Port widgets are now containers dumb containers for you own ports
|
||||
* Port widgets report new sizing information to their target links when they change position, you no longer need to invalidate them
|
||||
|
||||
__5.3.2__
|
||||
|
||||
* (maintenance) Upgrade :allthethings: (all the build tooling was upgrade)
|
||||
* (api) move to ES6 (JS now contains native classes)
|
||||
* (api) changed package name to @projectstorm/react-diagrams
|
||||
* (bug) (PR259)(https://github.com/projectstorm/react-diagrams/pull/259) Fixes #258
|
||||
* (refactor) (PR 306)(https://github.com/projectstorm/react-diagrams/pull/306) `:any` fix
|
||||
* (feature) (PR 178)(https://github.com/projectstorm/react-diagrams/pull/178) Trigger a positionChanged event when moving a Node that has the listener assigned.
|
||||
* (fix) (PR 356)(https://github.com/projectstorm/react-diagrams/pull/356) Fixed Type issue with 'PointModel()'
|
||||
* (demo) dark mode and upgrade storybook
|
||||
|
||||
__5.2.1__
|
||||
|
||||
* (fix) Always remove link from old source/target port on port change
|
||||
* (maintenance) upgrade node modules
|
||||
* (refactor) https://github.com/projectstorm/react-diagrams/commit/55f62587bd3b12513c7d37eff59edfc8bdb8d6c9
|
||||
* (bug) https://github.com/projectstorm/react-diagrams/commit/75ef02dd4d131a0e7c08b2680c69efc390e50b84
|
||||
-> and other improvements, also checkout the foundation work happening over at https://github.com/projectstorm/react-canvas
|
||||
|
||||
__5.1.0__
|
||||
|
||||
* (api) Rename XXXFactory into AbstractXXXFactory
|
||||
* (refactor) tslint and prettier are now the same
|
||||
* (refactor) Each class now explicitely has its own class file (consistency)
|
||||
* (feature) Smooth vertical links (no longer limited to horizontal)
|
||||
* (feature) Dedicated documentation via gitbook
|
||||
* (bug) forgot to export some
|
||||
* (refactor) consistently use lodash where possible
|
||||
* (maintenance) upgrade node modules
|
||||
|
||||
__5.0.0__ http://dylanv.blog/2018/03/03/storm-react-diagrams-5-0-0/
|
||||
|
||||
PR: https://github.com/projectstorm/react-diagrams/pull/145
|
||||
|
||||
* [refactor] Links completely overhauled
|
||||
* [feature] Smart Routing
|
||||
* [feature] Flow support
|
||||
* [demo] Smart Routing
|
||||
* [demo] Animated links
|
||||
* [api] Bootstrapping Improvements
|
||||
* [feature] add custom properties to all widgets
|
||||
* [refactor] use BEM for all css
|
||||
* [feature] Default Link factory hooks
|
||||
* [tests] e2e tests + helper framework
|
||||
* [tests] automatically load JEST Snapshots
|
||||
* [feature] Link labels!
|
||||
* (refactor) Links completely overhauled
|
||||
* (feature) Smart Routing
|
||||
* (feature) Flow support
|
||||
* (demo) Smart Routing
|
||||
* (demo) Animated links
|
||||
* (api) Bootstrapping Improvements
|
||||
* (feature) add custom properties to all widgets
|
||||
* (refactor) use BEM for all css
|
||||
* (feature) Default Link factory hooks
|
||||
* (tests) e2e tests + helper framework
|
||||
* (tests) automatically load JEST Snapshots
|
||||
* (feature) Link labels!
|
||||
|
||||
__4.0.0__ http://dylanv.blog/2018/01/18/storm-react-diagrams-v4-0-0/
|
||||
|
||||
* [refactor] Events system was completely overhauled
|
||||
* [demo] Custom Link Sizes
|
||||
* [refactor] Demos are now much more verbose and better managed
|
||||
* [update] node packages
|
||||
* [bug] Fix #129
|
||||
* [feature] Control link creation through ports
|
||||
* [refactor] Models are now in seperate files
|
||||
* [refactor] Merged the concept of instance factories and widget factories into one
|
||||
* [feature] Models can now be cloned at various parts of the model graph
|
||||
* [demo] Cloning
|
||||
* [feature] models control isLocked
|
||||
* (refactor) Events system was completely overhauled
|
||||
* (demo) Custom Link Sizes
|
||||
* (refactor) Demos are now much more verbose and better managed
|
||||
* (update) node packages
|
||||
* (bug) Fix #129
|
||||
* (feature) Control link creation through ports
|
||||
* (refactor) Models are now in seperate files
|
||||
* (refactor) Merged the concept of instance factories and widget factories into one
|
||||
* (feature) Models can now be cloned at various parts of the model graph
|
||||
* (demo) Cloning
|
||||
* (feature) models control isLocked
|
||||
|
||||
__3.2.0__ http://dylanv.blog/2017/11/22/storm-react-diagrams-3-2-0/
|
||||
* [feature] zoom to fit
|
||||
* (feature) zoom to fit
|
||||
* added Circle CI tests
|
||||
* [demo] dagre automatic layouts
|
||||
* [demo] zoom to fit
|
||||
* [demo] selection events
|
||||
* [demo] limit number of points
|
||||
* [demo] programmatic node updating
|
||||
* (demo) dagre automatic layouts
|
||||
* (demo) zoom to fit
|
||||
* (demo) selection events
|
||||
* (demo) limit number of points
|
||||
* (demo) programmatic node updating
|
||||
* updated dependencies
|
||||
* [bugs] swapping diagram models in engines
|
||||
* [bugs] issues with the rendering pipeline #107
|
||||
* (bugs) swapping diagram models in engines
|
||||
* (bugs) issues with the rendering pipeline #107
|
||||
* added ci badge to Readme
|
||||
|
||||
__3.1.3__
|
||||
__3.1.3__
|
||||
* Refactor links slightly
|
||||
* use min extension for css
|
||||
* bump package versions
|
||||
* export more classes
|
||||
|
||||
__3.1.2__
|
||||
__3.1.2__
|
||||
* Hotfix: fix zooming when canvas not in the top left corner
|
||||
(https://github.com/projectstorm/react-diagrams/pull/88)
|
||||
|
||||
@@ -68,7 +134,7 @@ __3.1.0__ http://dylanv.blog/2017/09/15/storm-react-diagrams-3-1-0/
|
||||
* Fixed links not connecting when grid is larger than port size
|
||||
* Prevented points from dragging when connected to a port and the node itself is not selected
|
||||
* API fixes
|
||||
* Code cleanup
|
||||
* Code cleanup
|
||||
|
||||
__3.0.0__ http://dylanv.blog/2017/09/13/storm-react-diagrams-v3/
|
||||
* Massive performance updates
|
||||
|
||||
102
README.md
@@ -1,46 +1,98 @@
|
||||
# STORM React Diagrams
|
||||
# Introduction
|
||||
|
||||
**PSA**: React Diagrams is currently getting a bit of a rewrite to enable much more advanced features. To see the new foundation WIP visit [https://github.com/projectstorm/react-canvas](https://github.com/projectstorm/react-canvas).
|
||||
[](https://gitter.im/projectstorm/react-diagrams?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://npmjs.org/package/@projectstorm/react-diagrams) [](https://packagequality.com/#?package=storm-react-diagrams) [](https://circleci.com/gh/projectstorm/react-diagrams/tree/master) [](https://lerna.js.org/)
|
||||
|
||||
---
|
||||

|
||||
|
||||
**DEMO**: [http://www.projectstorm.io/react-diagrams](http://www.projectstorm.io/react-diagrams)
|
||||
[pssst! Looking for the old version 5?](https://github.com/projectstorm/react-diagrams/tree/v5.3.2)
|
||||
|
||||
**DOCS:** [https://projectstorm.gitbooks.io/react-diagrams](https://projectstorm.gitbooks.io/react-diagrams)
|
||||
**DEMO**: [http://projectstorm.cloud/react-diagrams](http://projectstorm.cloud/react-diagrams)
|
||||
|
||||
**RELEASE NOTES** : [http://dylanv.blog/2018/03/03/storm-react-diagrams-5-0-0/](http://dylanv.blog/2018/03/03/storm-react-diagrams-5-0-0/)
|
||||
**DOCS \(wip\)** [https://projectstorm.gitbook.io/react-diagrams](https://projectstorm.gitbook.io/react-diagrams)
|
||||
|
||||
A super simple, no-nonsense diagramming library written in React that just works.
|
||||
Docs are currently being worked on, along with a migration path.
|
||||
|
||||
[](https://gitter.im/projectstorm/react-diagrams?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://npmjs.org/package/storm-react-diagrams) [](https://npmjs.org/package/storm-react-diagrams) [](http://packagequality.com/#?package=storm-react-diagrams) [](https://circleci.com/gh/projectstorm/react-diagrams/tree/master)
|
||||
## What
|
||||
|
||||

|
||||
A flow & process orientated diagramming library inspired by **Blender**, **Labview** and **Unreal engine**.
|
||||
|
||||

|
||||
* **Modern Codebase** written entirely in Typescript and React, the library makes use of powerful generics, advanced software engineering principles and is broken up into multiple modules.
|
||||
* **Hackable and extensible** the entire library including its core can be extended, rewired and re-assembled into fundamentally different software to suit your own software needs.
|
||||
* **HTML nodes as a first class citizen** the library was originally written to represent advanced dynamic nodes, that are difficult to represent as SVG's due to complex input requirements ux requirements.
|
||||
* **Designed for process** the library is aimed for software engineers that want to rewire their programs at runtime, and that want to make their software more dynamic.
|
||||
* **Fast diagram editing** the defaults provided give the highest priority to editing diagrams as fast as possible.
|
||||
|
||||

|
||||
## Gallery
|
||||
|
||||
## Introduction
|
||||
Example implementation using custom models: \(Dylan's personal code\)
|
||||
|
||||
A no-nonsense diagramming library written entirely in React with the help of a few small libraries. It aims to be:
|
||||

|
||||

|
||||
|
||||
* Simple, and void of any fuss/complications when implementing it into your own application
|
||||
* Customizable without having to hack the core \(adapters/factories etc..\)
|
||||
* Simple to operate and understand without sugar and magic
|
||||
* Fast and optimized to handle large diagrams with hundreds of nodes/links
|
||||
* Super easy to use, and should work as you expect it to
|
||||
* Perfect for creating declarative systems such as programmatic pipelines and visual programming languages
|
||||
Get started with the default models right out of the box:
|
||||
|
||||
#### Run the demos
|
||||

|
||||
|
||||
After running `yarn install` you must then run: `yarn run storybook`
|
||||
## Installing
|
||||
|
||||
#### Building from source
|
||||
For all the bells and whistles:
|
||||
|
||||
Simply run `webpack` in the root directory \(or `export NODE_ENV=production && webpack` if you want a production build\) and it will spit out the transpiled code and typescript definitions into the dist directory as a single file.
|
||||
We use webpack for this because TSC cannot compile a single UMD file \(TSC can currently only output multiple UMD files\).
|
||||
```text
|
||||
yarn add @projectstorm/react-diagrams
|
||||
```
|
||||
|
||||
## [Checkout the docs](https://projectstorm.gitbooks.io/react-diagrams)
|
||||
This includes all the packages listed below \(and works \(mostly and conceptually\) like it used to in version 5.0\)
|
||||
|
||||
### A more modular approach
|
||||
|
||||
This library now has a more modular design and you can import just the core \(contains no default factories or routing\)
|
||||
|
||||
```text
|
||||
yarn add @projectstorm/react-diagrams-core
|
||||
```
|
||||
|
||||
this is built ontop of the evolving **react-canvas-core** library
|
||||
|
||||
```text
|
||||
yarn add @projectstorm/react-canvas-core
|
||||
```
|
||||
|
||||
which makes use of
|
||||
|
||||
```text
|
||||
yarn add @projectstorm/geometry
|
||||
```
|
||||
|
||||
and of course, you can add some extras:
|
||||
|
||||
```text
|
||||
yarn add @projectstorm/react-diagrams-defaults
|
||||
yarn add @projectstorm/react-diagrams-routing
|
||||
```
|
||||
|
||||
## How to use
|
||||
|
||||
Before running any of the examples, please run `yarn build` in the root. This project is a monorepo, and the packages (including the demos) require the packages to first be built.
|
||||
|
||||
|
||||
Take a look at the [diagram demos](https://github.com/projectstorm/react-diagrams/tree/master/packages/diagrams-demo-gallery/demos)
|
||||
|
||||
**or**
|
||||
|
||||
Take a look at the [demo project](https://github.com/projectstorm/react-diagrams/tree/master/packages/diagrams-demo-project) which contains an example for ES6 as well as Typescript
|
||||
|
||||
**or**
|
||||
|
||||
[Checkout the docs](https://projectstorm.gitbook.io/react-diagrams/)
|
||||
|
||||
## Run the demos
|
||||
|
||||
After running `yarn install` you must then run: `cd packages/diagrams-demo-gallery && yarn run start`
|
||||
|
||||
## Building from source
|
||||
|
||||
Simply run `yarn` then `yarn build` or `yarn build:prod` in the root directory and it will spit out the transpiled code and typescript definitions into the dist directory as a single file.
|
||||
|
||||
## Built with react-diagrams
|
||||
|
||||
> Do you have an interesting project built with *react-diagrams*? PR it into this section for others to see.
|
||||
|
||||
11
SUMMARY.md
@@ -1,11 +0,0 @@
|
||||
# Summary
|
||||
|
||||
* [Introduction](README.md)
|
||||
* [Interacting with diagrams](/docs/Interactive Usage.md)
|
||||
* [Getting Started](/docs/Getting Started.md)
|
||||
* [About the project](about-the-project.md)
|
||||
* [Testing](/docs/Testing.md)
|
||||
* [Architecture Questions](/docs/Architecture Questions.md)
|
||||
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import * as React from "react";
|
||||
|
||||
export interface DemoWorkspaceWidgetProps {
|
||||
buttons?: any;
|
||||
}
|
||||
|
||||
export interface DemoWorkspaceWidgetState {}
|
||||
|
||||
export class DemoWorkspaceWidget extends React.Component<DemoWorkspaceWidgetProps, DemoWorkspaceWidgetState> {
|
||||
constructor(props: DemoWorkspaceWidgetProps) {
|
||||
super(props);
|
||||
this.state = {};
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="srd-demo-workspace">
|
||||
<div className="srd-demo-workspace__toolbar">{this.props.buttons}</div>
|
||||
<div className="srd-demo-workspace__content">{this.props.children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { withDocs } from "storybook-readme";
|
||||
import { WithCode } from "../../.storybook/addon-code/react.js";
|
||||
|
||||
export class Helper {
|
||||
/**
|
||||
* Logs the mouse position in the console, but overlays a div that consumes all events
|
||||
* since the actual story book stories are rendered as an iFrame.
|
||||
*/
|
||||
static logMousePosition() {
|
||||
let element = window.parent.document.createElement("mouse-position");
|
||||
element.style.position = "absolute";
|
||||
element.style.top = "0px";
|
||||
element.style.left = "0px";
|
||||
element.style.bottom = "0px";
|
||||
element.style.right = "0px";
|
||||
element.style.zIndex = "10";
|
||||
window.parent.document.body.appendChild(element);
|
||||
|
||||
window.parent.window.addEventListener("mousemove", event => {
|
||||
console.clear();
|
||||
console.log(event.clientX, event.clientY);
|
||||
});
|
||||
}
|
||||
|
||||
static makeDemo(widget, code, markdown?) {
|
||||
let container = () => <WithCode code={code}>{widget}</WithCode>;
|
||||
if (markdown) {
|
||||
return withDocs({
|
||||
PreviewComponent: ({ children }) => {
|
||||
return <div className="docs-preview-wrapper">{children}</div>;
|
||||
}
|
||||
})(markdown, container);
|
||||
}
|
||||
return container;
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
@import "../../src/sass/main";
|
||||
|
||||
.srd-demo-workspace{
|
||||
background: black;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
border-radius: 5px;
|
||||
overflow: hidden;
|
||||
|
||||
&__toolbar{
|
||||
padding: 5px;
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
|
||||
button{
|
||||
background: rgb(60,60,60);
|
||||
font-size: 14px;
|
||||
padding: 5px 10px;
|
||||
border: none;
|
||||
color: white;
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
margin: 2px;
|
||||
border-radius: 3px;
|
||||
|
||||
&:hover{
|
||||
background: rgb(0,192,255);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&__content{
|
||||
flex-grow: 1;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.docs-preview-wrapper{
|
||||
background: rgb(60,60,60);
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
padding: 10px;
|
||||
margin-top: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.srd-demo-canvas{
|
||||
height: 100%;
|
||||
min-height: 300px;
|
||||
background-color: rgb(60,60,60) !important;
|
||||
$color: rgba(white, .05);
|
||||
background-image:
|
||||
linear-gradient(0deg,
|
||||
transparent 24%,
|
||||
$color 25%,
|
||||
$color 26%,
|
||||
transparent 27%,
|
||||
transparent 74%,
|
||||
$color 75%,
|
||||
$color 76%,
|
||||
transparent 77%,
|
||||
transparent),
|
||||
linear-gradient(90deg,
|
||||
transparent 24%,
|
||||
$color 25%,
|
||||
$color 26%,
|
||||
transparent 27%,
|
||||
transparent 74%,
|
||||
$color 75%,
|
||||
$color 76%,
|
||||
transparent 77%,
|
||||
transparent);
|
||||
background-size:50px 50px;
|
||||
|
||||
.pointui{
|
||||
fill: rgba(white,0.5);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
import {
|
||||
DiagramEngine,
|
||||
DiagramModel,
|
||||
DefaultNodeModel,
|
||||
LinkModel,
|
||||
NodeModel,
|
||||
DiagramWidget,
|
||||
BaseModel
|
||||
} from "storm-react-diagrams";
|
||||
import * as _ from "lodash";
|
||||
import * as React from "react";
|
||||
import { DemoWorkspaceWidget } from "../.helpers/DemoWorkspaceWidget";
|
||||
|
||||
/**
|
||||
* Tests cloning
|
||||
*/
|
||||
class CloneSelected extends React.Component<any, any> {
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
this.cloneSelected = this.cloneSelected.bind(this);
|
||||
}
|
||||
|
||||
cloneSelected() {
|
||||
let { engine } = this.props;
|
||||
let offset = { x: 100, y: 100 };
|
||||
let model = engine.getDiagramModel();
|
||||
|
||||
let itemMap = {};
|
||||
_.forEach(model.getSelectedItems(), (item: BaseModel<any>) => {
|
||||
let newItem = item.clone(itemMap);
|
||||
|
||||
// offset the nodes slightly
|
||||
if (newItem instanceof NodeModel) {
|
||||
newItem.setPosition(newItem.x + offset.x, newItem.y + offset.y);
|
||||
model.addNode(newItem);
|
||||
} else if (newItem instanceof LinkModel) {
|
||||
// offset the link points
|
||||
newItem.getPoints().forEach(p => {
|
||||
p.updateLocation({ x: p.getX() + offset.x, y: p.getY() + offset.y });
|
||||
});
|
||||
model.addLink(newItem);
|
||||
}
|
||||
newItem.selected = false;
|
||||
});
|
||||
|
||||
this.forceUpdate();
|
||||
}
|
||||
|
||||
render() {
|
||||
const { engine } = this.props;
|
||||
return (
|
||||
<DemoWorkspaceWidget buttons={<button onClick={this.cloneSelected}>Clone Selected</button>}>
|
||||
<DiagramWidget className="srd-demo-canvas" diagramEngine={engine} />
|
||||
</DemoWorkspaceWidget>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
var engine = new DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
|
||||
//2) setup the diagram model
|
||||
var model = new DiagramModel();
|
||||
|
||||
//3-A) create a default node
|
||||
var node1 = new DefaultNodeModel("Node 1", "rgb(0,192,255)");
|
||||
let port = node1.addOutPort("Out");
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
//3-B) create another default node
|
||||
var node2 = new DefaultNodeModel("Node 2", "rgb(192,255,0)");
|
||||
let port2 = node2.addInPort("In");
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
// link the ports
|
||||
let link1 = port.link(port2);
|
||||
|
||||
//4) add the models to the root graph
|
||||
model.addAll(node1, node2, link1);
|
||||
|
||||
//5) load model into engine
|
||||
engine.setDiagramModel(model);
|
||||
|
||||
//6) render the diagram!
|
||||
return <CloneSelected engine={engine} model={model} />;
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
import * as SRD from "storm-react-diagrams";
|
||||
import { DiamonNodeWidget } from "./DiamondNodeWidget";
|
||||
import { DiamondNodeModel } from "./DiamondNodeModel";
|
||||
import * as React from "react";
|
||||
|
||||
export class DiamondNodeFactory extends SRD.AbstractNodeFactory {
|
||||
constructor() {
|
||||
super("diamond");
|
||||
}
|
||||
|
||||
generateReactWidget(diagramEngine: SRD.DiagramEngine, node: SRD.NodeModel): JSX.Element {
|
||||
return <DiamonNodeWidget node={node} />;
|
||||
}
|
||||
|
||||
getNewInstance() {
|
||||
return new DiamondNodeModel();
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { NodeModel } from "storm-react-diagrams";
|
||||
import { DiamondPortModel } from "./DiamondPortModel";
|
||||
|
||||
export class DiamondNodeModel extends NodeModel {
|
||||
constructor() {
|
||||
super("diamond");
|
||||
this.addPort(new DiamondPortModel("top"));
|
||||
this.addPort(new DiamondPortModel("left"));
|
||||
this.addPort(new DiamondPortModel("bottom"));
|
||||
this.addPort(new DiamondPortModel("right"));
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { DiamondNodeModel } from "./DiamondNodeModel";
|
||||
import { PortWidget } from "storm-react-diagrams";
|
||||
|
||||
export interface DiamonNodeWidgetProps {
|
||||
node: DiamondNodeModel;
|
||||
size?: number;
|
||||
}
|
||||
|
||||
export interface DiamonNodeWidgetState {}
|
||||
|
||||
/**
|
||||
* @author Dylan Vorster
|
||||
*/
|
||||
export class DiamonNodeWidget extends React.Component<DiamonNodeWidgetProps, DiamonNodeWidgetState> {
|
||||
public static defaultProps: DiamonNodeWidgetProps = {
|
||||
size: 150,
|
||||
node: null
|
||||
};
|
||||
|
||||
constructor(props: DiamonNodeWidgetProps) {
|
||||
super(props);
|
||||
this.state = {};
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div
|
||||
className={"diamond-node"}
|
||||
style={{
|
||||
position: "relative",
|
||||
width: this.props.size,
|
||||
height: this.props.size
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
width={this.props.size}
|
||||
height={this.props.size}
|
||||
dangerouslySetInnerHTML={{
|
||||
__html:
|
||||
`
|
||||
<g id="Layer_1">
|
||||
</g>
|
||||
<g id="Layer_2">
|
||||
<polygon fill="purple" stroke="#000000" stroke-width="3" stroke-miterlimit="10" points="10,` +
|
||||
this.props.size / 2 +
|
||||
` ` +
|
||||
this.props.size / 2 +
|
||||
`,10 ` +
|
||||
(this.props.size - 10) +
|
||||
`,` +
|
||||
this.props.size / 2 +
|
||||
` ` +
|
||||
this.props.size / 2 +
|
||||
`,` +
|
||||
(this.props.size - 10) +
|
||||
` "/>
|
||||
</g>
|
||||
`
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
zIndex: 10,
|
||||
top: this.props.size / 2 - 8,
|
||||
left: -8
|
||||
}}
|
||||
>
|
||||
<PortWidget name="left" node={this.props.node} />
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
zIndex: 10,
|
||||
left: this.props.size / 2 - 8,
|
||||
top: -8
|
||||
}}
|
||||
>
|
||||
<PortWidget name="top" node={this.props.node} />
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
zIndex: 10,
|
||||
left: this.props.size - 8,
|
||||
top: this.props.size / 2 - 8
|
||||
}}
|
||||
>
|
||||
<PortWidget name="right" node={this.props.node} />
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
zIndex: 10,
|
||||
left: this.props.size / 2 - 8,
|
||||
top: this.props.size - 8
|
||||
}}
|
||||
>
|
||||
<PortWidget name="bottom" node={this.props.node} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import * as _ from "lodash";
|
||||
import { LinkModel, DiagramEngine, PortModel, DefaultLinkModel } from "storm-react-diagrams";
|
||||
|
||||
export class DiamondPortModel extends PortModel {
|
||||
position: string | "top" | "bottom" | "left" | "right";
|
||||
|
||||
constructor(pos: string = "top") {
|
||||
super(pos, "diamond");
|
||||
this.position = pos;
|
||||
}
|
||||
|
||||
serialize() {
|
||||
return _.merge(super.serialize(), {
|
||||
position: this.position
|
||||
});
|
||||
}
|
||||
|
||||
deSerialize(data: any, engine: DiagramEngine) {
|
||||
super.deSerialize(data, engine);
|
||||
this.position = data.position;
|
||||
}
|
||||
|
||||
createLinkModel(): LinkModel {
|
||||
return new DefaultLinkModel();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import { PortModel, AbstractPortFactory } from "storm-react-diagrams";
|
||||
|
||||
export class SimplePortFactory extends AbstractPortFactory {
|
||||
cb: (initialConfig?: any) => PortModel;
|
||||
|
||||
constructor(type: string, cb: (initialConfig?: any) => PortModel) {
|
||||
super(type);
|
||||
this.cb = cb;
|
||||
}
|
||||
|
||||
getNewInstance(initialConfig?: any): PortModel {
|
||||
return this.cb(initialConfig);
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
import {
|
||||
DiagramEngine,
|
||||
DiagramModel,
|
||||
DefaultNodeModel,
|
||||
LinkModel,
|
||||
DefaultPortModel,
|
||||
DiagramWidget
|
||||
} from "storm-react-diagrams";
|
||||
import * as React from "react";
|
||||
|
||||
// import the custom models
|
||||
import { DiamondNodeModel } from "./DiamondNodeModel";
|
||||
import { DiamondNodeFactory } from "./DiamondNodeFactory";
|
||||
import { SimplePortFactory } from "./SimplePortFactory";
|
||||
import { DiamondPortModel } from "./DiamondPortModel";
|
||||
|
||||
/**
|
||||
* @Author Dylan Vorster
|
||||
*/
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
var engine = new DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
|
||||
// register some other factories as well
|
||||
engine.registerPortFactory(new SimplePortFactory("diamond", config => new DiamondPortModel()));
|
||||
engine.registerNodeFactory(new DiamondNodeFactory());
|
||||
|
||||
//2) setup the diagram model
|
||||
var model = new DiagramModel();
|
||||
|
||||
//3-A) create a default node
|
||||
var node1 = new DefaultNodeModel("Node 1", "rgb(0,192,255)");
|
||||
var port1 = node1.addOutPort("Out");
|
||||
node1.setPosition(100, 150);
|
||||
|
||||
//3-B) create our new custom node
|
||||
var node2 = new DiamondNodeModel();
|
||||
node2.setPosition(250, 108);
|
||||
|
||||
var node3 = new DefaultNodeModel("Node 3", "red");
|
||||
var port3 = node3.addInPort("In");
|
||||
node3.setPosition(500, 150);
|
||||
|
||||
//3-C) link the 2 nodes together
|
||||
var link1 = port1.link(node2.getPort("left"));
|
||||
var link2 = port3.link(node2.getPort("right"));
|
||||
|
||||
//4) add the models to the root graph
|
||||
model.addAll(node1, node2, node3, link1, link2);
|
||||
|
||||
//5) load model into engine
|
||||
engine.setDiagramModel(model);
|
||||
|
||||
//6) render the diagram!
|
||||
return <DiagramWidget className="srd-demo-canvas" diagramEngine={engine} />;
|
||||
};
|
||||
@@ -1,56 +0,0 @@
|
||||
import * as dagre from "dagre";
|
||||
import * as _ from "lodash";
|
||||
|
||||
const size = {
|
||||
width: 60,
|
||||
height: 60
|
||||
};
|
||||
|
||||
export function distributeElements(model) {
|
||||
let clonedModel = _.cloneDeep(model);
|
||||
let nodes = distributeGraph(clonedModel);
|
||||
nodes.forEach(node => {
|
||||
let modelNode = clonedModel.nodes.find(item => item.id === node.id);
|
||||
modelNode.x = node.x;
|
||||
modelNode.y = node.y;
|
||||
});
|
||||
return clonedModel;
|
||||
}
|
||||
|
||||
function distributeGraph(model) {
|
||||
let nodes = mapElements(model);
|
||||
let edges = mapEdges(model);
|
||||
let graph = new dagre.graphlib.Graph();
|
||||
graph.setGraph({});
|
||||
graph.setDefaultEdgeLabel(() => ({}));
|
||||
//add elements to dagre graph
|
||||
nodes.forEach(node => {
|
||||
graph.setNode(node.id, node.metadata);
|
||||
});
|
||||
edges.forEach(edge => {
|
||||
if (edge.from && edge.to) {
|
||||
graph.setEdge(edge.from, edge.to);
|
||||
}
|
||||
});
|
||||
//auto-distribute
|
||||
dagre.layout(graph);
|
||||
return graph.nodes().map(node => graph.node(node));
|
||||
}
|
||||
|
||||
function mapElements(model) {
|
||||
// dagre compatible format
|
||||
return model.nodes.map(node => ({ id: node.id, metadata: { ...size, id: node.id } }));
|
||||
}
|
||||
|
||||
function mapEdges(model) {
|
||||
// returns links which connects nodes
|
||||
// we check are there both from and to nodes in the model. Sometimes links can be detached
|
||||
return model.links
|
||||
.map(link => ({
|
||||
from: link.source,
|
||||
to: link.target
|
||||
}))
|
||||
.filter(
|
||||
item => model.nodes.find(node => node.id === item.from) && model.nodes.find(node => node.id === item.to)
|
||||
);
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
import {
|
||||
DiagramEngine,
|
||||
DefaultNodeFactory,
|
||||
DefaultLinkFactory,
|
||||
DiagramModel,
|
||||
DefaultNodeModel,
|
||||
LinkModel,
|
||||
DefaultPortModel,
|
||||
DiagramWidget
|
||||
} from "storm-react-diagrams";
|
||||
import { distributeElements } from "./dagre-utils";
|
||||
import * as React from "react";
|
||||
import { DemoWorkspaceWidget } from "../.helpers/DemoWorkspaceWidget";
|
||||
|
||||
function createNode(name) {
|
||||
return new DefaultNodeModel(name, "rgb(0,192,255)");
|
||||
}
|
||||
|
||||
let count = 0;
|
||||
|
||||
function connectNodes(nodeFrom, nodeTo) {
|
||||
//just to get id-like structure
|
||||
count++;
|
||||
const portOut = nodeFrom.addPort(new DefaultPortModel(true, `${nodeFrom.name}-out-${count}`, "Out"));
|
||||
const portTo = nodeTo.addPort(new DefaultPortModel(false, `${nodeFrom.name}-to-${count}`, "IN"));
|
||||
return portOut.link(portTo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests auto distribution
|
||||
*/
|
||||
class Demo8Widget extends React.Component<any, any> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {};
|
||||
this.autoDistribute = this.autoDistribute.bind(this);
|
||||
}
|
||||
|
||||
autoDistribute() {
|
||||
const { engine } = this.props;
|
||||
const model = engine.getDiagramModel();
|
||||
let distributedModel = getDistributedModel(engine, model);
|
||||
engine.setDiagramModel(distributedModel);
|
||||
this.forceUpdate();
|
||||
}
|
||||
|
||||
render() {
|
||||
const { engine } = this.props;
|
||||
|
||||
return (
|
||||
<DemoWorkspaceWidget buttons={<button onClick={this.autoDistribute}>Re-distribute</button>}>
|
||||
<DiagramWidget className="srd-demo-canvas" diagramEngine={engine} />
|
||||
</DemoWorkspaceWidget>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function getDistributedModel(engine, model) {
|
||||
const serialized = model.serializeDiagram();
|
||||
const distributedSerializedDiagram = distributeElements(serialized);
|
||||
|
||||
//deserialize the model
|
||||
let deSerializedModel = new DiagramModel();
|
||||
deSerializedModel.deSerializeDiagram(distributedSerializedDiagram, engine);
|
||||
return deSerializedModel;
|
||||
}
|
||||
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
let engine = new DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
|
||||
//2) setup the diagram model
|
||||
let model = new DiagramModel();
|
||||
|
||||
//3) create a default nodes
|
||||
let nodesFrom = [];
|
||||
let nodesTo = [];
|
||||
|
||||
nodesFrom.push(createNode("from-1"));
|
||||
nodesFrom.push(createNode("from-2"));
|
||||
nodesFrom.push(createNode("from-3"));
|
||||
|
||||
nodesTo.push(createNode("to-1"));
|
||||
nodesTo.push(createNode("to-2"));
|
||||
nodesTo.push(createNode("to-3"));
|
||||
|
||||
//4) link nodes together
|
||||
let links = nodesFrom.map((node, index) => {
|
||||
return connectNodes(node, nodesTo[index]);
|
||||
});
|
||||
|
||||
// more links for more complicated diagram
|
||||
links.push(connectNodes(nodesFrom[0], nodesTo[1]));
|
||||
links.push(connectNodes(nodesTo[0], nodesFrom[1]));
|
||||
links.push(connectNodes(nodesFrom[1], nodesTo[2]));
|
||||
|
||||
// initial random position
|
||||
nodesFrom.forEach((node, index) => {
|
||||
node.x = index * 70;
|
||||
model.addNode(node);
|
||||
});
|
||||
|
||||
nodesTo.forEach((node, index) => {
|
||||
node.x = index * 70;
|
||||
node.y = 100;
|
||||
model.addNode(node);
|
||||
});
|
||||
|
||||
links.forEach(link => {
|
||||
model.addLink(link);
|
||||
});
|
||||
|
||||
//5) load model into engine
|
||||
let model2 = getDistributedModel(engine, model);
|
||||
|
||||
engine.setDiagramModel(model2);
|
||||
|
||||
return <Demo8Widget engine={engine} />;
|
||||
};
|
||||
@@ -1,72 +0,0 @@
|
||||
import * as React from "react";
|
||||
import * as _ from "lodash";
|
||||
import { TrayWidget } from "./TrayWidget";
|
||||
import { Application } from "../Application";
|
||||
import { TrayItemWidget } from "./TrayItemWidget";
|
||||
import { DefaultNodeModel, DiagramWidget } from "storm-react-diagrams";
|
||||
|
||||
export interface BodyWidgetProps {
|
||||
app: Application;
|
||||
}
|
||||
|
||||
export interface BodyWidgetState {}
|
||||
|
||||
/**
|
||||
* @author Dylan Vorster
|
||||
*/
|
||||
export class BodyWidget extends React.Component<BodyWidgetProps, BodyWidgetState> {
|
||||
constructor(props: BodyWidgetProps) {
|
||||
super(props);
|
||||
this.state = {};
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="body">
|
||||
<div className="header">
|
||||
<div className="title">Storm React Diagrams - Demo 5</div>
|
||||
</div>
|
||||
<div className="content">
|
||||
<TrayWidget>
|
||||
<TrayItemWidget model={{ type: "in" }} name="In Node" color="rgb(192,255,0)" />
|
||||
<TrayItemWidget model={{ type: "out" }} name="Out Node" color="rgb(0,192,255)" />
|
||||
</TrayWidget>
|
||||
<div
|
||||
className="diagram-layer"
|
||||
onDrop={event => {
|
||||
var data = JSON.parse(event.dataTransfer.getData("storm-diagram-node"));
|
||||
var nodesCount = _.keys(
|
||||
this.props.app
|
||||
.getDiagramEngine()
|
||||
.getDiagramModel()
|
||||
.getNodes()
|
||||
).length;
|
||||
|
||||
var node = null;
|
||||
if (data.type === "in") {
|
||||
node = new DefaultNodeModel("Node " + (nodesCount + 1), "rgb(192,255,0)");
|
||||
node.addInPort("In");
|
||||
} else {
|
||||
node = new DefaultNodeModel("Node " + (nodesCount + 1), "rgb(0,192,255)");
|
||||
node.addOutPort("Out");
|
||||
}
|
||||
var points = this.props.app.getDiagramEngine().getRelativeMousePoint(event);
|
||||
node.x = points.x;
|
||||
node.y = points.y;
|
||||
this.props.app
|
||||
.getDiagramEngine()
|
||||
.getDiagramModel()
|
||||
.addNode(node);
|
||||
this.forceUpdate();
|
||||
}}
|
||||
onDragOver={event => {
|
||||
event.preventDefault();
|
||||
}}
|
||||
>
|
||||
<DiagramWidget className="srd-demo-canvas" diagramEngine={this.props.app.getDiagramEngine()} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import * as React from "react";
|
||||
|
||||
export interface TrayItemWidgetProps {
|
||||
model: any;
|
||||
color?: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface TrayItemWidgetState {}
|
||||
|
||||
export class TrayItemWidget extends React.Component<TrayItemWidgetProps, TrayItemWidgetState> {
|
||||
constructor(props: TrayItemWidgetProps) {
|
||||
super(props);
|
||||
this.state = {};
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div
|
||||
style={{ borderColor: this.props.color }}
|
||||
draggable={true}
|
||||
onDragStart={event => {
|
||||
event.dataTransfer.setData("storm-diagram-node", JSON.stringify(this.props.model));
|
||||
}}
|
||||
className="tray-item"
|
||||
>
|
||||
{this.props.name}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import * as React from "react";
|
||||
|
||||
export interface TrayWidgetProps {}
|
||||
|
||||
export interface TrayWidgetState {}
|
||||
|
||||
/**
|
||||
* @author Dylan Vorster
|
||||
*/
|
||||
export class TrayWidget extends React.Component<TrayWidgetProps, TrayWidgetState> {
|
||||
public static defaultProps: TrayWidgetProps = {};
|
||||
|
||||
constructor(props: TrayWidgetProps) {
|
||||
super(props);
|
||||
this.state = {};
|
||||
}
|
||||
|
||||
render() {
|
||||
return <div className="tray">{this.props.children}</div>;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import * as React from "react";
|
||||
|
||||
import { BodyWidget } from "./components/BodyWidget";
|
||||
import { Application } from "./Application";
|
||||
|
||||
import "./sass/main.scss";
|
||||
|
||||
export default () => {
|
||||
var app = new Application();
|
||||
|
||||
return <BodyWidget app={app} />;
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
.body{
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100%;
|
||||
|
||||
.header{
|
||||
display: flex;
|
||||
background: rgb(30,30,30);
|
||||
flex-grow: 0;
|
||||
flex-shrink: 0;
|
||||
color: white;
|
||||
font-family: Helvetica, Arial;
|
||||
padding: 10px;
|
||||
>*{
|
||||
align-self:center;
|
||||
}
|
||||
}
|
||||
|
||||
.content{
|
||||
display: flex;
|
||||
flex-grow: 1;
|
||||
|
||||
.diagram-layer{
|
||||
position: relative;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.tray{
|
||||
min-width: 200px;
|
||||
background: rgb(20,20,20);
|
||||
flex-grow: 0;
|
||||
flex-shrink: 0;
|
||||
|
||||
.tray-item{
|
||||
color: white;
|
||||
font-family: Helvetica, Arial;
|
||||
padding: 5px;
|
||||
margin: 0px 10px;
|
||||
border: solid 1px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 2px;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import { DiagramEngine, DiagramModel, DefaultNodeModel, LinkModel, DiagramWidget } from "storm-react-diagrams";
|
||||
import * as React from "react";
|
||||
|
||||
/**
|
||||
* Tests the grid size
|
||||
*/
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
var engine = new DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
|
||||
//2) setup the diagram model
|
||||
var model = new DiagramModel();
|
||||
model.setGridSize(50);
|
||||
|
||||
//3-A) create a default node
|
||||
var node1 = new DefaultNodeModel("Node 1", "rgb(0,192,255)");
|
||||
let port = node1.addOutPort("Out");
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
//3-B) create another default node
|
||||
var node2 = new DefaultNodeModel("Node 2", "rgb(192,255,0)");
|
||||
let port2 = node2.addInPort("In");
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
// link the ports
|
||||
let link1 = port.link(port2);
|
||||
|
||||
//4) add the models to the root graph
|
||||
model.addAll(node1, node2, link1);
|
||||
|
||||
//5) load model into engine
|
||||
engine.setDiagramModel(model);
|
||||
|
||||
//6) render the diagram!
|
||||
return <DiagramWidget className="srd-demo-canvas" diagramEngine={engine} />;
|
||||
};
|
||||
@@ -1,73 +0,0 @@
|
||||
import {
|
||||
DiagramEngine,
|
||||
DiagramModel,
|
||||
DefaultNodeModel,
|
||||
LinkModel,
|
||||
DefaultPortModel,
|
||||
DiagramWidget,
|
||||
DefaultLinkModel
|
||||
} from "storm-react-diagrams";
|
||||
import * as React from "react";
|
||||
import { DemoWorkspaceWidget } from "../.helpers/DemoWorkspaceWidget";
|
||||
import { action } from "@storybook/addon-actions";
|
||||
|
||||
export default () => {
|
||||
// setup the diagram engine
|
||||
const engine = new DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
|
||||
// setup the diagram model
|
||||
const model = new DiagramModel();
|
||||
|
||||
// create four nodes
|
||||
const node1 = new DefaultNodeModel("Node A", "rgb(0,192,255)");
|
||||
const port1 = node1.addOutPort("Out");
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
const node2 = new DefaultNodeModel("Node B", "rgb(255,255,0)");
|
||||
const port2 = node2.addInPort("In");
|
||||
node2.setPosition(400, 50);
|
||||
|
||||
const node3 = new DefaultNodeModel("Node C (no label)", "rgb(192,255,255)");
|
||||
const port3 = node3.addInPort("In");
|
||||
node3.setPosition(450, 180);
|
||||
|
||||
const node4 = new DefaultNodeModel("Node D", "rgb(192,0,255)");
|
||||
const port4 = node4.addInPort("In");
|
||||
node4.setPosition(300, 250);
|
||||
|
||||
// link node A and B together and give it a label
|
||||
const link1 = port1.link(port2);
|
||||
(link1 as DefaultLinkModel).addLabel("Custom label 1");
|
||||
(link1 as DefaultLinkModel).addLabel("Custom label 2");
|
||||
|
||||
// no label for A and C, just a link
|
||||
const link2 = port1.link(port3);
|
||||
|
||||
// also a label for A and D
|
||||
const link3 = port1.link(port4);
|
||||
link3.setTargetPort(port4);
|
||||
(link3 as DefaultLinkModel).addLabel("Emoji label: 🎉");
|
||||
|
||||
// add all to the main model
|
||||
model.addAll(node1, node2, node3, node4, link1, link2, link3);
|
||||
|
||||
// load model into engine and render
|
||||
engine.setDiagramModel(model);
|
||||
|
||||
return (
|
||||
<DemoWorkspaceWidget
|
||||
buttons={
|
||||
<button
|
||||
onClick={() => {
|
||||
action("Serialized Graph")(JSON.stringify(model.serializeDiagram(), null, 2));
|
||||
}}
|
||||
>
|
||||
Serialize Graph
|
||||
</button>
|
||||
}
|
||||
>
|
||||
<DiagramWidget className="srd-demo-canvas" diagramEngine={engine} />
|
||||
</DemoWorkspaceWidget>
|
||||
);
|
||||
};
|
||||
@@ -1,49 +0,0 @@
|
||||
import * as React from "react";
|
||||
import {
|
||||
DiagramEngine,
|
||||
DiagramModel,
|
||||
DefaultNodeModel,
|
||||
LinkModel,
|
||||
DiagramWidget,
|
||||
DiagramProps
|
||||
} from "storm-react-diagrams";
|
||||
|
||||
/**
|
||||
* Shows that a limit of points can be set for links
|
||||
*/
|
||||
export default () => {
|
||||
// setup the diagram engine
|
||||
var engine = new DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
|
||||
var model = new DiagramModel();
|
||||
|
||||
//3-A) create a default node
|
||||
var node1 = new DefaultNodeModel("Node 1", "rgb(0,192,255)");
|
||||
let port = node1.addOutPort("Out");
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
//3-B) create another default node
|
||||
var node2 = new DefaultNodeModel("Node 2", "rgb(192,255,0)");
|
||||
let port2 = node2.addInPort("In");
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
// link the ports
|
||||
let link1 = port.link(port2);
|
||||
|
||||
model.addAll(node1, node2, link1);
|
||||
|
||||
engine.setDiagramModel(model);
|
||||
|
||||
var props = {
|
||||
diagramEngine: engine,
|
||||
maxNumberPointsPerLink: 5
|
||||
} as DiagramProps;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<p>A maximum of 5 points can be created per link.</p>
|
||||
<DiagramWidget className="srd-demo-canvas" {...props} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,62 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { action } from "@storybook/addon-actions";
|
||||
import {
|
||||
DiagramEngine,
|
||||
DiagramModel,
|
||||
DiagramProps,
|
||||
DefaultNodeModel,
|
||||
LinkModel,
|
||||
DiagramWidget
|
||||
} from "storm-react-diagrams";
|
||||
|
||||
/**
|
||||
* Shows some of the events triggered when elements are selected
|
||||
*/
|
||||
export default () => {
|
||||
// setup the diagram engine
|
||||
var engine = new DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
|
||||
var model = new DiagramModel();
|
||||
|
||||
// sample for link with simple line
|
||||
var node1 = new DefaultNodeModel("Node 1", "rgb(255,99,66)");
|
||||
var port1 = node1.addOutPort("Out");
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
var node2 = new DefaultNodeModel("Node 2", "rgb(192,255,0)");
|
||||
var port2 = node2.addInPort("In");
|
||||
node2.setPosition(400, 40);
|
||||
|
||||
var node3 = new DefaultNodeModel("Node 3", "rgb(128,99,255)");
|
||||
var port3 = node3.addInPort("In");
|
||||
node3.setPosition(300, 160);
|
||||
|
||||
//link the nodes
|
||||
let link1 = port1.link(port2);
|
||||
let link2 = port1.link(port3);
|
||||
|
||||
// add all the models
|
||||
let models = model.addAll(node1, node2, node3, link1, link2);
|
||||
|
||||
// add a selection listener to each
|
||||
models.forEach(item => {
|
||||
item.addListener({
|
||||
selectionChanged: action("selectionChanged")
|
||||
});
|
||||
});
|
||||
|
||||
engine.setDiagramModel(model);
|
||||
|
||||
var props = {
|
||||
diagramEngine: engine,
|
||||
maxNumberPointsPerLink: 0 // no extra points so link selection is fired straight away
|
||||
} as DiagramProps;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<p>Click the diagram elements to inspect some of the possible events.</p>
|
||||
<DiagramWidget className="srd-demo-canvas" {...props} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -1,69 +0,0 @@
|
||||
import * as React from "react";
|
||||
import {
|
||||
DiagramEngine,
|
||||
DiagramModel,
|
||||
DefaultNodeModel,
|
||||
LinkModel,
|
||||
PointModel,
|
||||
DiagramWidget,
|
||||
DiagramProps
|
||||
} from "storm-react-diagrams";
|
||||
|
||||
/**
|
||||
*
|
||||
* Shows how you can lock down the system so that the entire scene cant be interacted with.
|
||||
*
|
||||
* @Author Dylan Vorster
|
||||
*/
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
var engine = new DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
|
||||
var model = new DiagramModel();
|
||||
|
||||
// sample for link with simple line (no additional points)
|
||||
var node1 = new DefaultNodeModel("Node 1", "rgb(0,192,255)");
|
||||
var port1 = node1.addOutPort("Out");
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
var node2 = new DefaultNodeModel("Node 2", "rgb(192,255,0)");
|
||||
var port2 = node2.addInPort("In");
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
let link1 = port1.link(port2);
|
||||
|
||||
model.addAll(node1, node2, link1);
|
||||
|
||||
// sample for link with complex line (additional points)
|
||||
var node3 = new DefaultNodeModel("Node 3", "rgb(0,192,255)");
|
||||
var port3 = node3.addOutPort("Out");
|
||||
node3.setPosition(100, 250);
|
||||
|
||||
var node4 = new DefaultNodeModel("Node 4", "rgb(192,255,0)");
|
||||
var port4 = node4.addInPort("In");
|
||||
node4.setPosition(400, 250);
|
||||
|
||||
var link2 = port3.link(port4);
|
||||
|
||||
link2.point(350, 225);
|
||||
link2.point(200, 225);
|
||||
|
||||
model.addAll(node3, node4, link2);
|
||||
|
||||
engine.setDiagramModel(model);
|
||||
|
||||
//!========================================= <<<<<<<
|
||||
|
||||
model.setLocked(true);
|
||||
var props = {
|
||||
diagramEngine: engine,
|
||||
allowLooseLinks: false,
|
||||
allowCanvasTranslation: false,
|
||||
allowCanvasZoom: false
|
||||
} as DiagramProps;
|
||||
|
||||
//!========================================= <<<<<<<
|
||||
|
||||
return <DiagramWidget className="srd-demo-canvas" {...props} />;
|
||||
};
|
||||
@@ -1,86 +0,0 @@
|
||||
import { DiagramEngine, DiagramModel, DefaultNodeModel, LinkModel, DiagramWidget } from "storm-react-diagrams";
|
||||
import * as React from "react";
|
||||
import { DemoWorkspaceWidget } from "../.helpers/DemoWorkspaceWidget";
|
||||
|
||||
/**
|
||||
* Tests the grid size
|
||||
*/
|
||||
class NodeDelayedPosition extends React.Component<any, any> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.updatePosition = this.updatePosition.bind(this);
|
||||
this.updatePositionViaSerialize = this.updatePositionViaSerialize.bind(this);
|
||||
}
|
||||
|
||||
updatePosition() {
|
||||
const { engine } = this.props;
|
||||
let model = engine.getDiagramModel();
|
||||
const nodes = model.getNodes();
|
||||
let node = nodes[Object.keys(nodes)[0]];
|
||||
node.setPosition(node.x + 30, node.y + 30);
|
||||
this.forceUpdate();
|
||||
}
|
||||
|
||||
updatePositionViaSerialize() {
|
||||
let { engine } = this.props;
|
||||
let model = engine.getDiagramModel();
|
||||
let str = JSON.stringify(model.serializeDiagram());
|
||||
let model2 = new DiagramModel();
|
||||
let obj = JSON.parse(str);
|
||||
let node = obj.nodes[0];
|
||||
node.x += 30;
|
||||
node.y += 30;
|
||||
model2.deSerializeDiagram(obj, engine);
|
||||
engine.setDiagramModel(model2);
|
||||
this.forceUpdate();
|
||||
}
|
||||
|
||||
render() {
|
||||
const { engine } = this.props;
|
||||
return (
|
||||
<DemoWorkspaceWidget
|
||||
buttons={[
|
||||
<button key={1} onClick={this.updatePosition}>
|
||||
Update position
|
||||
</button>,
|
||||
<button key={2} onClick={this.updatePositionViaSerialize}>
|
||||
Update position via serialize
|
||||
</button>
|
||||
]}
|
||||
>
|
||||
<DiagramWidget className="srd-demo-canvas" diagramEngine={engine} />
|
||||
</DemoWorkspaceWidget>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
var engine = new DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
|
||||
//2) setup the diagram model
|
||||
var model = new DiagramModel();
|
||||
|
||||
//3-A) create a default node
|
||||
var node1 = new DefaultNodeModel("Node 1", "rgb(0,192,255)");
|
||||
var port1 = node1.addOutPort("Out");
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
//3-B) create another default node
|
||||
var node2 = new DefaultNodeModel("Node 2", "rgb(192,255,0)");
|
||||
var port2 = node2.addInPort("In");
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
//3-C) link the 2 nodes together
|
||||
var link1 = port1.link(port2);
|
||||
|
||||
//4) add the models to the root graph
|
||||
model.addAll(node1, node2, link1);
|
||||
|
||||
//5) load model into engine
|
||||
engine.setDiagramModel(model);
|
||||
|
||||
//6) render the diagram!
|
||||
return <NodeDelayedPosition engine={engine} model={model} />;
|
||||
};
|
||||
@@ -1,59 +0,0 @@
|
||||
import { DiagramEngine, DiagramModel, DefaultNodeModel, LinkModel, DiagramWidget } from "storm-react-diagrams";
|
||||
import * as React from "react";
|
||||
import { DemoWorkspaceWidget } from "../.helpers/DemoWorkspaceWidget";
|
||||
import { action } from "@storybook/addon-actions";
|
||||
import * as beautify from "json-beautify";
|
||||
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
var engine = new DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
|
||||
//2) setup the diagram model
|
||||
var model = new DiagramModel();
|
||||
|
||||
//3-A) create a default node
|
||||
var node1 = new DefaultNodeModel("Node 1", "rgb(0,192,255)");
|
||||
var port1 = node1.addOutPort("Out");
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
//3-B) create another default node
|
||||
var node2 = new DefaultNodeModel("Node 2", "rgb(192,255,0)");
|
||||
var port2 = node2.addInPort("In");
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
//3-C) link the 2 nodes together
|
||||
var link1 = port1.link(port2);
|
||||
|
||||
//4) add the models to the root graph
|
||||
model.addAll(node1, node2, link1);
|
||||
|
||||
//5) load model into engine
|
||||
engine.setDiagramModel(model);
|
||||
|
||||
//!------------- SERIALIZING ------------------
|
||||
|
||||
var str = JSON.stringify(model.serializeDiagram());
|
||||
|
||||
//!------------- DESERIALIZING ----------------
|
||||
|
||||
var model2 = new DiagramModel();
|
||||
model2.deSerializeDiagram(JSON.parse(str), engine);
|
||||
engine.setDiagramModel(model2);
|
||||
|
||||
return (
|
||||
<DemoWorkspaceWidget
|
||||
buttons={
|
||||
<button
|
||||
onClick={() => {
|
||||
action("Serialized Graph")(beautify(model2.serializeDiagram(), null, 2, 80));
|
||||
}}
|
||||
>
|
||||
Serialize Graph
|
||||
</button>
|
||||
}
|
||||
>
|
||||
<DiagramWidget className="srd-demo-canvas" diagramEngine={engine} />
|
||||
</DemoWorkspaceWidget>
|
||||
);
|
||||
};
|
||||
@@ -1,38 +0,0 @@
|
||||
import { DiagramEngine, DiagramModel, DefaultNodeModel, LinkModel, DiagramWidget } from "storm-react-diagrams";
|
||||
import * as React from "react";
|
||||
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
var engine = new DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
|
||||
//2) setup the diagram model
|
||||
var model = new DiagramModel();
|
||||
|
||||
//3-A) create a default node
|
||||
var node1 = new DefaultNodeModel("Node 1", "rgb(0,192,255)");
|
||||
var port1 = node1.addOutPort("Out");
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
//3-B) create another default node
|
||||
var node2 = new DefaultNodeModel("Node 2", "rgb(192,255,0)");
|
||||
var port2 = node2.addInPort("In");
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
//3-C) link the 2 nodes together
|
||||
var link1 = port1.link(port2);
|
||||
|
||||
//3-D) create an orphaned node
|
||||
var node3 = new DefaultNodeModel("Node 3", "rgb(0,192,255)");
|
||||
node3.addOutPort("Out");
|
||||
node3.setPosition(100, 200);
|
||||
|
||||
//4) add the models to the root graph
|
||||
model.addAll(node1, node2, node3, link1);
|
||||
|
||||
//5) load model into engine
|
||||
engine.setDiagramModel(model);
|
||||
|
||||
//6) render the diagram!
|
||||
return <DiagramWidget className="srd-demo-canvas" diagramEngine={engine} allowLooseLinks={false} />;
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
# Simple Usage
|
||||
|
||||
Welcome to STORM React Diagrams (SRD). SRD is a no-nonsense easy to use library for creating
|
||||
flow diagrams in the web that can ultimately represent any type of process/network/graph etc..
|
||||
|
||||
<!-- STORY -->
|
||||
|
||||
Try moving around one of the nodes or clicking and dragging the links to create new link anchors (points).
|
||||
You can also zoom the canvas using the mouse wheel / scroll gesture and drag to select multiple entities on the graph by shift + dragging the mouse.
|
||||
@@ -1,41 +0,0 @@
|
||||
import {
|
||||
DiagramEngine,
|
||||
DiagramModel,
|
||||
DefaultNodeModel,
|
||||
LinkModel,
|
||||
DiagramWidget,
|
||||
DefaultLinkModel
|
||||
} from "storm-react-diagrams";
|
||||
import * as React from "react";
|
||||
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
var engine = new DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
|
||||
//2) setup the diagram model
|
||||
var model = new DiagramModel();
|
||||
|
||||
//3-A) create a default node
|
||||
var node1 = new DefaultNodeModel("Node 1", "rgb(0,192,255)");
|
||||
let port1 = node1.addOutPort("Out");
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
//3-B) create another default node
|
||||
var node2 = new DefaultNodeModel("Node 2", "rgb(192,255,0)");
|
||||
let port2 = node2.addInPort("In");
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
// link the ports
|
||||
let link1 = port1.link(port2);
|
||||
(link1 as DefaultLinkModel).addLabel("Hello World!");
|
||||
|
||||
//4) add the models to the root graph
|
||||
model.addAll(node1, node2, link1);
|
||||
|
||||
//5) load model into engine
|
||||
engine.setDiagramModel(model);
|
||||
|
||||
//6) render the diagram!
|
||||
return <DiagramWidget className="srd-demo-canvas" diagramEngine={engine} />;
|
||||
};
|
||||
@@ -1,68 +0,0 @@
|
||||
import {
|
||||
DiagramEngine,
|
||||
DiagramModel,
|
||||
DefaultNodeModel,
|
||||
LinkModel,
|
||||
DefaultPortModel,
|
||||
DiagramWidget
|
||||
} from "storm-react-diagrams";
|
||||
import * as React from "react";
|
||||
import { DemoWorkspaceWidget } from "../.helpers/DemoWorkspaceWidget";
|
||||
import { action } from "@storybook/addon-actions";
|
||||
|
||||
export default () => {
|
||||
// setup the diagram engine
|
||||
const engine = new DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
|
||||
// setup the diagram model
|
||||
const model = new DiagramModel();
|
||||
|
||||
// create four nodes in a way that straight links wouldn't work
|
||||
const node1 = new DefaultNodeModel("Node A", "rgb(0,192,255)");
|
||||
const port1 = node1.addPort(new DefaultPortModel(false, "out-1", "Out"));
|
||||
node1.setPosition(340, 350);
|
||||
|
||||
const node2 = new DefaultNodeModel("Node B", "rgb(255,255,0)");
|
||||
const port2 = node2.addPort(new DefaultPortModel(false, "out-1", "Out"));
|
||||
node2.setPosition(240, 80);
|
||||
const node3 = new DefaultNodeModel("Node C", "rgb(192,255,255)");
|
||||
const port3 = node3.addPort(new DefaultPortModel(true, "in-1", "In"));
|
||||
node3.setPosition(540, 180);
|
||||
const node4 = new DefaultNodeModel("Node D", "rgb(192,0,255)");
|
||||
const port4 = node4.addPort(new DefaultPortModel(true, "in-1", "In"));
|
||||
node4.setPosition(95, 185);
|
||||
const node5 = new DefaultNodeModel("Node E", "rgb(192,255,0)");
|
||||
node5.setPosition(250, 180);
|
||||
|
||||
// linking things together
|
||||
const link1 = port1.link(port4);
|
||||
const link2 = port2.link(port3);
|
||||
|
||||
// add all to the main model
|
||||
model.addAll(node1, node2, node3, node4, node5, link1, link2);
|
||||
|
||||
// load model into engine and render
|
||||
engine.setDiagramModel(model);
|
||||
|
||||
return (
|
||||
<DemoWorkspaceWidget
|
||||
buttons={
|
||||
<button
|
||||
onClick={() => {
|
||||
action("Serialized Graph")(JSON.stringify(model.serializeDiagram(), null, 2));
|
||||
}}
|
||||
>
|
||||
Serialize Graph
|
||||
</button>
|
||||
}
|
||||
>
|
||||
<DiagramWidget
|
||||
className="srd-demo-canvas"
|
||||
diagramEngine={engine}
|
||||
smartRouting={true}
|
||||
maxNumberPointsPerLink={0}
|
||||
/>
|
||||
</DemoWorkspaceWidget>
|
||||
);
|
||||
};
|
||||
129
demos/index.tsx
@@ -1,129 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { storiesOf, addDecorator } from "@storybook/react";
|
||||
import { setOptions } from "@storybook/addon-options";
|
||||
import { host } from "storybook-host";
|
||||
import { Helper } from "./.helpers/Helper";
|
||||
import { Toolkit } from "../src/Toolkit";
|
||||
|
||||
//include the SCSS for the demo
|
||||
import "./.helpers/demo.scss";
|
||||
|
||||
Toolkit.TESTING = true;
|
||||
|
||||
addDecorator(
|
||||
host({
|
||||
cropMarks: false,
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
padding: 20
|
||||
})
|
||||
);
|
||||
|
||||
setOptions({
|
||||
name: "STORM React Diagrams",
|
||||
url: "https://github.com/projectstorm/react-diagrams",
|
||||
addonPanelInRight: true
|
||||
});
|
||||
|
||||
storiesOf("Simple Usage", module)
|
||||
.add(
|
||||
"Simple example",
|
||||
Helper.makeDemo(
|
||||
require("./demo-simple/index").default(),
|
||||
require("!!raw-loader!./demo-simple/index"),
|
||||
require("./demo-simple/docs.md")
|
||||
)
|
||||
)
|
||||
.add(
|
||||
"Simple flow example",
|
||||
Helper.makeDemo(require("./demo-simple-flow/index").default(), require("!!raw-loader!./demo-simple-flow/index"))
|
||||
)
|
||||
.add(
|
||||
"Performance demo",
|
||||
Helper.makeDemo(require("./demo-performance/index").default(), require("!!raw-loader!./demo-performance/index"))
|
||||
)
|
||||
.add(
|
||||
"Locked widget",
|
||||
Helper.makeDemo(require("./demo-locks/index").default(), require("!!raw-loader!./demo-locks/index"))
|
||||
)
|
||||
.add(
|
||||
"Canvas grid size",
|
||||
Helper.makeDemo(require("./demo-grid/index").default(), require("!!raw-loader!./demo-grid/index"))
|
||||
)
|
||||
.add(
|
||||
"Limiting link points",
|
||||
Helper.makeDemo(
|
||||
require("./demo-limit-points/index").default(),
|
||||
require("!!raw-loader!./demo-limit-points/index")
|
||||
)
|
||||
)
|
||||
.add(
|
||||
"Events and listeners",
|
||||
Helper.makeDemo(require("./demo-listeners/index").default(), require("!!raw-loader!./demo-listeners/index"))
|
||||
)
|
||||
.add(
|
||||
"Zoom to fit",
|
||||
Helper.makeDemo(require("./demo-zoom-to-fit/index").default(), require("!!raw-loader!./demo-zoom-to-fit/index"))
|
||||
)
|
||||
.add(
|
||||
"Links with labels",
|
||||
Helper.makeDemo(
|
||||
require("./demo-labelled-links/index").default(),
|
||||
require("!!raw-loader!./demo-labelled-links/index")
|
||||
)
|
||||
);
|
||||
|
||||
storiesOf("Advanced Techniques", module)
|
||||
.add(
|
||||
"Clone Selected",
|
||||
Helper.makeDemo(require("./demo-cloning/index").default(), require("!!raw-loader!./demo-cloning/index"))
|
||||
)
|
||||
.add(
|
||||
"Serializing and de-serializing",
|
||||
Helper.makeDemo(require("./demo-serializing/index").default(), require("!!raw-loader!./demo-serializing/index"))
|
||||
)
|
||||
.add(
|
||||
"Programatically modifying graph",
|
||||
Helper.makeDemo(
|
||||
require("./demo-mutate-graph/index").default(),
|
||||
require("!!raw-loader!./demo-mutate-graph/index")
|
||||
)
|
||||
)
|
||||
.add(
|
||||
"Large application",
|
||||
Helper.makeDemo(
|
||||
require("./demo-drag-and-drop/index").default(),
|
||||
require("!!raw-loader!./demo-drag-and-drop/components/BodyWidget")
|
||||
)
|
||||
)
|
||||
.add(
|
||||
"Smart routing",
|
||||
Helper.makeDemo(
|
||||
require("./demo-smart-routing/index").default(),
|
||||
require("!!raw-loader!./demo-smart-routing/index")
|
||||
)
|
||||
);
|
||||
|
||||
storiesOf("Custom Models", module)
|
||||
.add(
|
||||
"Custom diamond node",
|
||||
Helper.makeDemo(
|
||||
require("./demo-custom-node1/index").default(),
|
||||
require("!!raw-loader!./demo-custom-node1/index")
|
||||
)
|
||||
)
|
||||
.add(
|
||||
"Custom animated links",
|
||||
Helper.makeDemo(
|
||||
require("./demo-custom-link1/index").default(),
|
||||
require("!!raw-loader!./demo-custom-link1/index")
|
||||
)
|
||||
);
|
||||
|
||||
storiesOf("3rd party libraries", module).add(
|
||||
"Auto Distribute (Dagre)",
|
||||
Helper.makeDemo(require("./demo-dagre/index").default(), require("!!raw-loader!./demo-dagre/index"))
|
||||
);
|
||||
|
||||
// enable this to log mouse location when writing new puppeteer tests
|
||||
//Helper.logMousePosition()
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"extends": [
|
||||
"../tslint.json"
|
||||
],
|
||||
"rules": {
|
||||
"no-console": false,
|
||||
"max-classes-per-file": false,
|
||||
"no-var-requires": false
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
# Architecture Questions
|
||||
|
||||
Here I will try to answer any questions relating to the design of the system
|
||||
|
||||
### What was the inspiration for this library?
|
||||
|
||||
Joint JS (a fantastic library) + my need for rich HTML nodes + LabView + Blender Composite sub system
|
||||
|
||||
### Why render the nodes as HTML Elements and not SVG's?
|
||||
|
||||
My original requirement for this library stemmed from the requirement of wanting HTML nodes that would allow me to
|
||||
embed rich controls such as input fields, drop downs and have the system treat such nodes as first class citizens.
|
||||
I originally tried to make this work in JointJS, but ran into a number of problems of which this was a relatively big one.
|
||||
|
||||
JointJS does allow you to do this, but at the time of writing this library originally, I was having a lot of trouble
|
||||
to make it work exactly like I needed it, and therefore decided from the very beginning that I would attempt this
|
||||
with an HTML first mindset.
|
||||
|
||||
|
||||
### Why Typescript?
|
||||
|
||||
Firstly, because it can transpile into any level of ECMAScript. This means that I don't need to break our the refactor tractor
|
||||
every time ECMAScript decides it wants to add features which it should have done years ago.
|
||||
|
||||
I also ported it to Typescript to accommodate the heavy architectural changes I was starting to make. Since porting
|
||||
the library to typescript, and seeing the project explode in size and complexity, I consider this the best decision
|
||||
made with regards to this library so far.
|
||||
|
||||
Porting to typescript also afforded us a set of powerful features such as generics and static analysis that
|
||||
all the project contributors have made exclusive use of.
|
||||
|
||||
Typescript is <3 typescript is life.
|
||||
|
||||
### Why not Flow instead of Typescript?
|
||||
|
||||
At the time when I first started evaluating languages that could transpile to ECMAScript, I was not so sold
|
||||
on the supporting environment surrounding flow, and and found that there was better tooling to support
|
||||
typescript, they are ultimately trying to do the same thing though, and I guess in the end, typescript just made
|
||||
more sense.
|
||||
|
||||
### Why React ?
|
||||
|
||||
React is really efficient at rendering and managing HTML in a declarative manner. React has also become
|
||||
one of the bigger industry standards and has a rich eco system that plays really well with typescript.
|
||||
Apart from these notable points, I am really fond of React and wanted a diagramming library that takes full advantage of it,
|
||||
and makes it easy for engineers to use its power as well, when extending this library.
|
||||
|
||||
### Why cant the Default models and widgets do this or that ?
|
||||
|
||||
They are intended to illustrate __how__ to use this library and act as a good starting point
|
||||
to extend and show the capability. Ultimately I designed this library to be completely
|
||||
pluggable in a way that you can use it as a library and not a framework. If the default widgets
|
||||
are not good enough, then a good place to start is with creating your own models/factories/widgets.
|
||||
|
||||
### Model vs Widget
|
||||
|
||||
For those that are new to [Scene Graphs](https://en.wikipedia.org/wiki/Scene_graph) or are not familiar with concepts
|
||||
such as [MVC](https://en.wikipedia.org/wiki/Model–view–controller), this library represents your entire graph as a model.
|
||||
The model is a traversable graph that represents the nodes and links between them in a virtual manner. Your program (aka the business logic/layer)
|
||||
can mutate this model imperatively or store snapshots decoratively of the complete model (via serialization) and then the engine and react
|
||||
widgets will take care of the rendering. For this reason every model in the library is represented by a widget, and the factories glue it all together.
|
||||
|
||||
|
||||
### How do I make my own elements?
|
||||
|
||||
Take a look at the __demos__ directory, with specific attention to the __DefaultNodeWidget__
|
||||
|
||||
That being said, the demos directory is an _example_ of how you can create your own elements.
|
||||
A number of people want to use the defaults as is, which is cool,
|
||||
but is recommended to create your own models/factories/widgets.
|
||||
|
||||
### How do I use the library?
|
||||
|
||||
Take a look at the demo folders, they have simple and complex examples of the complete usage.
|
||||
|
||||
A good example of a real-world example is Demo 5
|
||||
@@ -1,142 +0,0 @@
|
||||
# Getting started
|
||||
|
||||
## Installation via NPM
|
||||
|
||||
The first thing you need to do, is grab the distribution files on NPM. You can do this either using yarn or npm
|
||||
|
||||
**Via yarn:**
|
||||
|
||||
```
|
||||
yarn install storm-react-diagrams
|
||||
```
|
||||
|
||||
**Via npm:**
|
||||
|
||||
```
|
||||
npm install storm-react-diagrams
|
||||
```
|
||||
|
||||
When you run this in your project directory, this will install the library into node\_modules/storm-react-diagrams. You will then find a dist folder that contains all the minified and production ready code.
|
||||
|
||||
This will also install React and a few other dependencies that you need in order to use this library.
|
||||
|
||||
## Including the library
|
||||
|
||||
When including the library you will need both the javascript files as well as the raw BEM styles. Both are included in the dist folder and there are numerous ways to integrate them into your project:
|
||||
|
||||
#### Getting the javascript files
|
||||
|
||||
**Using Typescript / ES6: \(recommended\)**
|
||||
|
||||
```js
|
||||
import * as SRD from "storm-react-diagrams"
|
||||
```
|
||||
|
||||
**Using RequireJS:**
|
||||
|
||||
```js
|
||||
var SRD = require("storm-react-diagrams)
|
||||
```
|
||||
|
||||
**As a script tag \(not recommended\)**
|
||||
|
||||
```html
|
||||
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
|
||||
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
|
||||
<script src="node_modules/storm-react-diagrams/dist/main.js">
|
||||
```
|
||||
|
||||
#### Getting the CSS
|
||||
|
||||
**Using RequireJS / Typescript/ ES6 \(recommended\)**
|
||||
|
||||
Make sure you have the style-loader enabled and then:
|
||||
|
||||
```js
|
||||
require("storm-react-diagrams/dist/style.min.css");
|
||||
```
|
||||
|
||||
or make sure you have the sass-loader enabled and then:
|
||||
|
||||
```js
|
||||
require("storm-react-diagrams/src/sass/main.scss");
|
||||
```
|
||||
|
||||
If you are using typescript and get a "require function not found" then make sure to
|
||||
|
||||
```
|
||||
yarn add @types/node
|
||||
```
|
||||
|
||||
which will give you the typescript definition files for requireJS
|
||||
|
||||
**Using SASS:**
|
||||
|
||||
setup your include paths on webpack or lib sass using the following option
|
||||
|
||||
```
|
||||
includePaths: ["node_modules"]
|
||||
```
|
||||
|
||||
and then if you want the raw sass source code:
|
||||
|
||||
```sass
|
||||
@import "~storm-react-diagrams/src/sass/main";
|
||||
```
|
||||
|
||||
or if you want the minified css
|
||||
|
||||
```sass
|
||||
@import "~storm-react-diagrams/dist/style.min";
|
||||
```
|
||||
|
||||
**Using a style tag**
|
||||
|
||||
or if you want the minified css
|
||||
|
||||
```html
|
||||
<link rel="stylesheet" href="node_modules/dist/style.min.css">
|
||||
```
|
||||
|
||||
## Render your first diagram
|
||||
|
||||
In your library code
|
||||
|
||||
```js
|
||||
// 1) setup the diagram engine
|
||||
var engine = new SRD.DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
|
||||
// 2) setup the diagram model
|
||||
var model = new SRD.DiagramModel();
|
||||
|
||||
// 3) create a default node
|
||||
var node1 = new SRD.DefaultNodeModel("Node 1", "rgb(0,192,255)");
|
||||
let port1 = node1.addOutPort("Out");
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
// 4) create another default node
|
||||
var node2 = new SRD.DefaultNodeModel("Node 2", "rgb(192,255,0)");
|
||||
let port2 = node2.addInPort("In");
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
// 5) link the ports
|
||||
let link1 = port1.link(port2);
|
||||
|
||||
// 6) add the models to the root graph
|
||||
model.addAll(node1, node2, link1);
|
||||
|
||||
// 7) load model into engine
|
||||
engine.setDiagramModel(model);
|
||||
```
|
||||
|
||||
And then create an instance of the diagram widget. An example of the simplest possible react widget to do this would be:
|
||||
|
||||
```jsx
|
||||
function SimpleDiagramWidget(props) {
|
||||
return <SRD.DiagramWidget diagramEngine={props.engine} />;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
# End user usage
|
||||
|
||||
__Delete__ removes any selected items
|
||||

|
||||
|
||||
__Shift + Mouse Drag__ triggers a multi-selection box
|
||||

|
||||
|
||||
__Shift + Mouse Click__ selects the item (items can be multi-selected)
|
||||

|
||||
|
||||
__Mouse Drag__ drags the entire diagram
|
||||

|
||||
|
||||
__Mouse Wheel__ zooms the diagram in / out
|
||||

|
||||
|
||||
__Click Link + Drag__ creates a new link point
|
||||

|
||||
|
||||
__Click Node Port + Drag__ creates a new link
|
||||

|
||||
12
docs/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# Table of contents
|
||||
|
||||
* [Introduction](README.md)
|
||||
* [Getting Started](getting-started/README.md)
|
||||
* [Using the library](getting-started/using-the-library.md)
|
||||
* [Customizing](customizing/README.md)
|
||||
* [Extending DefaultLinkModel](customizing/extending-default-links.md)
|
||||
* [Custom Ports](customizing/ports.md)
|
||||
* [About the project](about-the-project/README.md)
|
||||
* [Testing](about-the-project/testing.md)
|
||||
* [Architecture Questions](about-the-project/architecture-questions.md)
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
# Testing
|
||||
|
||||
STORM React diagrams is tested two main ways.
|
||||
|
||||
## JEST Snapshot testing
|
||||
|
||||
With Jest snapshots, we render all the demos in the demo folder by automatically
|
||||
looking into each `demo-*` folder and searching for an __index.tsx__ file.
|
||||
|
||||
For each file we find, we dynamically include it as a storybook story and assemble one big test.
|
||||
This test then renders each demo in a deterministic way and compares it to the snapshot file
|
||||
situated in __snapshots__. If the snapshots don't match, then something has changed and either the snapshot
|
||||
needs to be updated, or the test is failing in which case we need to fix the code.
|
||||
|
||||
Snapshot testing does not test the functionality of the program but it is a first important step
|
||||
to make sure that changes aren't having a drastic effect on the overall system.
|
||||
|
||||
In the event that the snapshot needs to be updated, please run `yarn run test -u` to overwrite
|
||||
the snapshot file, and then make sure to your branch.
|
||||
|
||||
## End to end testing
|
||||
|
||||
To test the functionality of the library, we make use of e2e tests (end to end tests).
|
||||
In this library, we spin up a headless chrome using pupeteer and interactively and programmatically
|
||||
tell the mouse pointer to click and drag on various elements while making assertions along the way.
|
||||
|
||||
We use Jest for the assertions and the interactivity is handled by puppeteer. Due to the laborious nature
|
||||
of writing e2e tests, there is a helper method that is provided in each test that makes interacting
|
||||
with the diagrams a lot easier. Using this helper, you cna easily tell the mouse to drag links between nodes,
|
||||
select them and also easily assert information about them. The important thing here, is that this helper
|
||||
does not touch the model in any way, but is purely a helper for writing the tests themselves. Please
|
||||
make use of this helper when writing tests, as it ensure that the tests are defensive in nature, and also
|
||||
reduces the overhead of physically writing them.
|
||||
52
docs/about-the-project/architecture-questions.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Architecture Questions
|
||||
|
||||
Here I will try to answer any questions relating to the design of the system
|
||||
|
||||
## What was the inspiration for this library?
|
||||
|
||||
Joint JS \(a fantastic library\) + my need for rich HTML nodes + LabView + Blender Composite sub system
|
||||
|
||||
## Why render the nodes as HTML Elements and not SVG's?
|
||||
|
||||
My original requirement for this library stemmed from the requirement of wanting HTML nodes that would allow me to embed rich controls such as input fields, drop downs and have the system treat such nodes as first class citizens. I originally tried to make this work in JointJS, but ran into a number of problems of which this was a relatively big one.
|
||||
|
||||
JointJS does allow you to do this, but at the time of writing this library originally, I was having a lot of trouble to make it work exactly like I needed it, and therefore decided from the very beginning that I would attempt this with an HTML first mindset.
|
||||
|
||||
## Why Typescript?
|
||||
|
||||
Firstly, because it can transpile into any level of ECMAScript. This means that I don't need to break our the refactor tractor every time ECMAScript decides it wants to add features which it should have done years ago.
|
||||
|
||||
I also ported it to Typescript to accommodate the heavy architectural changes I was starting to make. Since porting the library to typescript, and seeing the project explode in size and complexity, I consider this the best decision made with regards to this library so far.
|
||||
|
||||
Porting to typescript also afforded us a set of powerful features such as generics and static analysis that all the project contributors have made exclusive use of.
|
||||
|
||||
Typescript is <3 typescript is life.
|
||||
|
||||
## Why not Flow instead of Typescript?
|
||||
|
||||
At the time when I first started evaluating languages that could transpile to ECMAScript, I was not so sold on the supporting environment surrounding flow, and and found that there was better tooling to support typescript, they are ultimately trying to do the same thing though, and I guess in the end, typescript just made more sense.
|
||||
|
||||
## Why React ?
|
||||
|
||||
React is really efficient at rendering and managing HTML in a declarative manner. React has also become one of the bigger industry standards and has a rich eco system that plays really well with typescript. Apart from these notable points, I am really fond of React and wanted a diagramming library that takes full advantage of it, and makes it easy for engineers to use its power as well, when extending this library.
|
||||
|
||||
## Why cant the Default models and widgets do this or that ?
|
||||
|
||||
They are intended to illustrate **how** to use this library and act as a good starting point to extend and show the capability. Ultimately I designed this library to be completely pluggable in a way that you can use it as a library and not a framework. If the default widgets are not good enough, then a good place to start is with creating your own models/factories/widgets.
|
||||
|
||||
## Model vs Widget
|
||||
|
||||
For those that are new to [Scene Graphs](https://en.wikipedia.org/wiki/Scene_graph) or are not familiar with concepts such as [MVC](https://en.wikipedia.org/wiki/Model–view–controller), this library represents your entire graph as a model. The model is a traversable graph that represents the nodes and links between them in a virtual manner. Your program \(aka the business logic/layer\) can mutate this model imperatively or store snapshots decoratively of the complete model \(via serialization\) and then the engine and react widgets will take care of the rendering. For this reason every model in the library is represented by a widget, and the factories glue it all together.
|
||||
|
||||
## How do I make my own elements?
|
||||
|
||||
Take a look at the **demos** directory, with specific attention to the **DefaultNodeWidget**
|
||||
|
||||
That being said, the demos directory is an _example_ of how you can create your own elements. A number of people want to use the defaults as is, which is cool, but is recommended to create your own models/factories/widgets.
|
||||
|
||||
## How do I use the library?
|
||||
|
||||
Take a look at the demo folders, they have simple and complex examples of the complete usage.
|
||||
|
||||
A good example of a real-world example is Demo 5
|
||||
|
||||
8
docs/about-the-project/testing.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Testing
|
||||
|
||||
## End to end testing
|
||||
|
||||
To test the functionality of the library, we make use of e2e tests \(end to end tests\). In this library, we spin up a headless chrome using pupeteer and interactively and programmatically tell the mouse pointer to click and drag on various elements while making assertions along the way.
|
||||
|
||||
We use Jest for the assertions and the interactivity is handled by puppeteer. Due to the laborious nature of writing e2e tests, there is a helper method that is provided in each test that makes interacting with the diagrams a lot easier. Using this helper, you can easily tell the mouse to drag links between nodes, select them and also easily assert information about them. The important thing here, is that this helper does not touch the model in any way, but is purely a helper for writing the tests themselves. Please make use of this helper when writing tests, as it ensure that the tests are defensive in nature, and also reduces the overhead of physically writing them.
|
||||
|
||||
11
docs/customizing/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Customizing
|
||||
|
||||
## Working with custom links
|
||||
|
||||
This is the easiest way to get started:
|
||||
|
||||
[Extending the default Link](./extending-default-links.md)
|
||||
|
||||
## Working with custom nodes
|
||||
|
||||
[Working with Ports](./ports.md)
|
||||
52
docs/customizing/extending-default-links.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Custom Links
|
||||
|
||||
## Extending the DefaultLinkModel
|
||||
|
||||
Much like extending nodes, custom links can also be created.
|
||||
In the below example, we have created a link that renders a circle animating from the source port to the target port.
|
||||
|
||||

|
||||
|
||||
In this specific example, we extended the `DefaultLinkModel` because we wanted to retain
|
||||
a lot of the functionality that it provides in the base class:
|
||||
|
||||
```typescript
|
||||
export class AdvancedLinkModel extends DefaultLinkModel {
|
||||
constructor() {
|
||||
super({
|
||||
type: 'advanced', // <-- here we give it a new type
|
||||
width: 10 // we specifically want this to also be width 10
|
||||
});
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Now we need to create a new link factory to tell the system how our new link model fits into the core system. We specifically are going to extend the `DefaultLinkFactory` because we still want to render a `DefaultLinkWidget`. The only difference is that we want each __path segment__ to be a red line with an animating circle. Fortunately, the `DefaultLinkWidget` already uses the `generateLinkSegment()` method defined in the `DefaultLinkFactory` to accomplish this. The only thing we need to do, is provide a different type of segment:
|
||||
|
||||
```typescript
|
||||
export class AdvancedLinkFactory extends DefaultLinkFactory {
|
||||
constructor() {
|
||||
super('advanced'); // <-- this matches with the link model above
|
||||
}
|
||||
|
||||
generateModel(): AdvancedLinkModel {
|
||||
return new AdvancedLinkModel(); // <-- this is how we get new instances
|
||||
}
|
||||
|
||||
/**
|
||||
* @override the DefaultLinkWidget makes use of this, and it normally renders that
|
||||
* familiar gray line, so in this case we simply make it return a new advanced segment.
|
||||
*/
|
||||
generateLinkSegment(model: AdvancedLinkModel, selected: boolean, path: string) {
|
||||
return (
|
||||
<g>
|
||||
<AdvancedLinkSegment model={model} path={path} />
|
||||
</g>
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The actual code for the `AdvancedLinkSegment` [can be found here](https://github.com/projectstorm/react-diagrams/blob/master/packages/diagrams-demo-gallery/demos/demo-custom-link1/index.tsx) (it is in the `demo-custom-link1` folder in the demo gallery).
|
||||
|
||||
This is the easiest and most simple way to get started with custom links.
|
||||
BIN
docs/customizing/images/custom-link.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
docs/customizing/images/diamond-node.png
Normal file
|
After Width: | Height: | Size: 60 KiB |
95
docs/customizing/ports.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# Ports
|
||||
|
||||
Ports allow links to connect to your nodes. Each port that is rendered in a node must also have a corresponding PortModel in the corresponding NodeModel (as is the case with essentially all of the models and widgets in this library).
|
||||
|
||||
## Custom port widgets
|
||||
|
||||
If you want to create a custom port that looks entirely different (much like in the image below), then you simply need to create your own widget and wrap it in a `PortWidget`:
|
||||
|
||||
```jsx
|
||||
<PortWidget
|
||||
port={this.props.node.getPort("in"}
|
||||
engine={this.props.engine} >
|
||||
<div
|
||||
style={{
|
||||
width: 40,
|
||||
height: 40,
|
||||
background: 'orange'
|
||||
}}
|
||||
/>
|
||||
</PortWidget>
|
||||
```
|
||||
|
||||
Obviously, you can create the React widgets in any way you like. Whether you use __Emotion__, __BEM__ or plain old __CSS__, the only important thing is that your custom port is wrapped inside a `PortWidget`
|
||||
|
||||
## Specifying alignment
|
||||
|
||||
When links enter ports, depending on the alignment specified, they can help the links render differently. Take the following example:
|
||||
|
||||

|
||||
|
||||
In the above example, the 4 ports on the diamond node model are setup with different alignment:
|
||||
|
||||
```typescript
|
||||
this.addPort(new DiamondPortModel(PortModelAlignment.TOP));
|
||||
this.addPort(new DiamondPortModel(PortModelAlignment.LEFT));
|
||||
this.addPort(new DiamondPortModel(PortModelAlignment.BOTTOM));
|
||||
this.addPort(new DiamondPortModel(PortModelAlignment.RIGHT));
|
||||
```
|
||||
|
||||
Each of the custom `DiamondPortModel` models forwards this through to the base `PortModel` class:
|
||||
|
||||
```typescript
|
||||
export class DiamondPortModel extends PortModel {
|
||||
...
|
||||
constructor(alignment: PortModelAlignment) {
|
||||
super({
|
||||
type: 'diamond',
|
||||
name: alignment,
|
||||
alignment: alignment // <-- here
|
||||
});
|
||||
}
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## Specifying if a link can be connected
|
||||
|
||||
A port is directly responsible for specifying if a link is allowed to connect to it. When you drag an un-connected link end-point to a target port, the target port lets the link know if it is allowed to connect.
|
||||
|
||||
```typescript
|
||||
class PortModel{
|
||||
...
|
||||
canLinkToPort(port: PortModel): boolean;
|
||||
}
|
||||
```
|
||||
|
||||
In the above definition, the port argument is the source port that the incoming link is connected to. By default, the method returns true, but you can extend this and overide this method to do more advanced checks.
|
||||
|
||||
The `DefaultPortModel` provided in the defaults package, makes use of this principle to only allow `Out` ports to connect to `In` ports:
|
||||
|
||||
```typescript
|
||||
class DefaultPortModel extends PortModel{
|
||||
...
|
||||
canLinkToPort(port: PortModel): boolean {
|
||||
if (port instanceof DefaultPortModel) {
|
||||
return this.options.in !== port.getOptions().in;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Specifying what type of link is generated from a port
|
||||
|
||||
When a user drags on a port to generate a link, the port is also responsible for specifying
|
||||
what link is created. This happens through the `createLinkModel()` method:
|
||||
|
||||
```typescript
|
||||
class DefaultPortModel extends PortModel{
|
||||
...
|
||||
createLinkModel(): LinkModel{
|
||||
return new DefaultLinkModel(); // <-- here we generate a DefaultLinkModel
|
||||
}
|
||||
}
|
||||
```
|
||||
40
docs/getting-started/README.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# Getting Started
|
||||
|
||||
## Get the package
|
||||
|
||||
The first thing you need to do, is grab the distribution files on NPM. You can do this either using **yarn** or **npm.**
|
||||
|
||||
**Via yarn:**
|
||||
|
||||
```text
|
||||
yarn add @projectstorm/react-diagrams@next
|
||||
```
|
||||
|
||||
**Via npm:**
|
||||
|
||||
```text
|
||||
npm install @projectstorm/react-diagrams@next
|
||||
```
|
||||
|
||||
When you run this in your project directory, this will install the library into `./node_modules/@projectstorm/react-diagrams`. You will then find a **dist** folder that contains all the minified and production ready code.
|
||||
|
||||
## Install the peer dependencies
|
||||
|
||||
The library includes it's dependencies as peer-dependencies, so yarn will output warnings letting you know which ones are missing. Simple install them, specifically these ones:
|
||||
|
||||
**Via yarn:**
|
||||
|
||||
```text
|
||||
yarn add closest lodash react dagre pathfinding paths-js @emotion/core @emotion/styled resize-observer-polyfill
|
||||
```
|
||||
|
||||
**Via npm:**
|
||||
|
||||
```text
|
||||
npm install closest lodash react dagre pathfinding paths-js @emotion/core @emotion/styled resize-observer-polyfill
|
||||
```
|
||||
|
||||
We do this, so that you can better control the versions of these libraries yourself since you might make use of `Lodash` in other parts of your software.
|
||||
|
||||
|
||||
|
||||
68
docs/getting-started/using-the-library.md
Normal file
@@ -0,0 +1,68 @@
|
||||
# Using the library
|
||||
|
||||
## Using Typescript
|
||||
|
||||
If you are using typescript, then you are in luck! The library is built in typescript, and includes advanced types for everything you need right out of the box.
|
||||
|
||||
Lets start by including the things we are going to need:
|
||||
|
||||
```typescript
|
||||
import createEngine, {
|
||||
DefaultLinkModel,
|
||||
DefaultNodeModel,
|
||||
DiagramModel
|
||||
} from '@projectstorm/react-diagrams';
|
||||
|
||||
import {
|
||||
CanvasWidget
|
||||
} from '@projectstorm/react-canvas-core';
|
||||
```
|
||||
|
||||
Now we call `createEngine` which will bootstrap a **DiagramEngine** for us that contains all the defaults setup.
|
||||
|
||||
```typescript
|
||||
// create an instance of the engine with all the defaults
|
||||
const engine = createEngine();
|
||||
```
|
||||
|
||||
Next, we create two nodes:
|
||||
|
||||
```typescript
|
||||
// node 1
|
||||
const node1 = new DefaultNodeModel({
|
||||
name: 'Node 1',
|
||||
color: 'rgb(0,192,255)',
|
||||
});
|
||||
node1.setPosition(100, 100);
|
||||
let port1 = node1.addOutPort('Out');
|
||||
|
||||
// node 2
|
||||
const node2 = new DefaultNodeModel({
|
||||
name: 'Node 1',
|
||||
color: 'rgb(0,192,255)',
|
||||
});
|
||||
node2.setPosition(100, 100);
|
||||
let port2 = node2.addOutPort('Out');
|
||||
```
|
||||
|
||||
Now we link the two ports of both of the nodes:
|
||||
|
||||
```typescript
|
||||
// link them and add a label to the link
|
||||
const link = port1.link<DefaultLinkModel>(port2);
|
||||
link.addLabel('Hello World!');
|
||||
```
|
||||
|
||||
Great! Now we have setup a simple diagram. All thats left to do, is create a **DiagramModel** to contain everything, add all the elements to it, and then add it to the engine.
|
||||
|
||||
```typescript
|
||||
const model = new DiagramModel();
|
||||
model.addAll(node1, node2, link);
|
||||
engine.setModel(model);
|
||||
```
|
||||
|
||||
And then we render with **React**!
|
||||
|
||||
```jsx
|
||||
<CanvasWidget engine={engine} />
|
||||
```
|
||||
|
Before Width: | Height: | Size: 94 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 52 KiB |
BIN
images/demo.gif
|
Before Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 47 KiB |
|
Before Width: | Height: | Size: 354 KiB |
|
Before Width: | Height: | Size: 161 KiB |
|
Before Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 113 KiB |
@@ -1,27 +0,0 @@
|
||||
const path = require("path");
|
||||
// jest.config.js
|
||||
module.exports = {
|
||||
verbose: true,
|
||||
moduleFileExtensions: [
|
||||
"ts",
|
||||
"tsx",
|
||||
"js",
|
||||
"jsx",
|
||||
"json",
|
||||
"node"
|
||||
],
|
||||
transform: {
|
||||
".*test_loader.*": path.join(__dirname, "tests", "helpers", "storybook-loader.js" ),
|
||||
"^.+\\.tsx?$": "ts-jest",
|
||||
},
|
||||
moduleNameMapper:{
|
||||
"\\.(scss|css|png)$": path.join(__dirname,"tests","helpers","css-mock.js"),
|
||||
"storm-react-diagrams": path.join(__dirname, "src", "main")
|
||||
},
|
||||
roots:[
|
||||
__dirname+'/tests'
|
||||
],
|
||||
testMatch: [
|
||||
"**/*\.test\.tsx"
|
||||
]
|
||||
};
|
||||
5
lerna.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"npmClient": "yarn",
|
||||
"useWorkspaces": true,
|
||||
"version": "6.3.0"
|
||||
}
|
||||
139
package.json
@@ -1,10 +1,14 @@
|
||||
{
|
||||
"name": "storm-react-diagrams",
|
||||
"version": "5.1.1",
|
||||
"name": "@projectstorm/react-diagrams",
|
||||
"author": "dylanvorster",
|
||||
"private": true,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/projectstorm/react-diagrams.git"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"keywords": [
|
||||
"web",
|
||||
"diagram",
|
||||
@@ -16,73 +20,82 @@
|
||||
"links",
|
||||
"nodes"
|
||||
],
|
||||
"main": "./dist/main.js",
|
||||
"typings": "./dist/@types/src/main",
|
||||
"author": "dylanvorster",
|
||||
"scripts": {
|
||||
"build:ts": "webpack",
|
||||
"build:ts:prod": "cross-env NODE_ENV=production webpack",
|
||||
"build:sass:prod": "node-sass --output-style compressed ./src/sass/main.scss > ./dist/style.min.css",
|
||||
"storybook": "start-storybook -p 9001 -c .storybook",
|
||||
"storybook:build": "build-storybook -c .storybook -o .out",
|
||||
"storybook:github": "storybook-to-ghpages",
|
||||
"pretty": "prettier --use-tabs --write \"{src,demos,tests}/**/*.{ts,tsx}\" --print-width 120",
|
||||
"lint": "tslint -p .",
|
||||
"test:ci": "rm -rf ./dist && node ./tests/e2e/generate-e2e.js && jest --no-cache",
|
||||
"test": "jest --no-cache",
|
||||
"prepublishOnly": "yarn run build:ts:prod && yarn run build:sass:prod"
|
||||
"build": "yarn build:clean && lerna run build --stream",
|
||||
"build:es": "lerna run build:es --stream",
|
||||
"build:prod": "yarn build:clean && lerna run build:prod --stream",
|
||||
"watch": "yarn build:clean && lerna run watch --stream",
|
||||
"publish:dev": "yarn build:prod && lerna publish --force-publish --dist-tag=next",
|
||||
"publish:prod": "yarn build:prod && lerna publish --force-publish",
|
||||
"publish:storybook": "cd packages/diagrams-demo-gallery && yarn storybook:build && ../../node_modules/.bin/storybook-to-ghpages --existing-output-dir .out",
|
||||
"build:clean": "lerna run clean --stream",
|
||||
"test:ci": "lerna run test --stream -- --runInBand --ci ",
|
||||
"pretty": "prettier --write \"packages/**/*.{ts,tsx,scss,js,jsx}\""
|
||||
},
|
||||
"dependencies": {
|
||||
"peerDependencies": {
|
||||
"closest": "^0.0.1",
|
||||
"lodash": "^4.17.5",
|
||||
"emotion": "10.*",
|
||||
"lodash": "4.*",
|
||||
"pathfinding": "^0.4.18",
|
||||
"paths-js": "^0.4.7",
|
||||
"react": "^16.2.0"
|
||||
"paths-js": "^0.4.11",
|
||||
"react": "16.*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@storybook/addon-actions": "^3.3.15",
|
||||
"@storybook/addon-options": "^3.3.15",
|
||||
"@storybook/addon-storyshots": "^3.3.15",
|
||||
"@storybook/addons": "^3.3.15",
|
||||
"@storybook/react": "^3.3.15",
|
||||
"@storybook/storybook-deployer": "^2.3.0",
|
||||
"@types/jest": "^22.2.0",
|
||||
"@types/lodash": "^4.14.104",
|
||||
"@types/node": "^9.4.7",
|
||||
"@babel/core": "^7.11.6",
|
||||
"@babel/preset-react": "^7.10.4",
|
||||
"@emotion/core": "^10.0.35",
|
||||
"@emotion/styled": "^10.0.27",
|
||||
"@storybook/addon-actions": "^6.0.21",
|
||||
"@storybook/addon-options": "^5.3.21",
|
||||
"@storybook/addons": "^6.0.21",
|
||||
"@storybook/react": "^6.0.21",
|
||||
"@storybook/storybook-deployer": "^2.8.6",
|
||||
"@storybook/theming": "^6.0.21",
|
||||
"@types/dagre": "^0.7.44",
|
||||
"@types/jest": "^26.0.14",
|
||||
"@types/jest-environment-puppeteer": "^4.3.2",
|
||||
"@types/lodash": "^4.14.161",
|
||||
"@types/node": "^14.11.2",
|
||||
"@types/promise": "^7.1.30",
|
||||
"@types/puppeteer": "^1.1.0",
|
||||
"@types/react": "^16.0.40",
|
||||
"awesome-typescript-loader": "^4.0.1",
|
||||
"copy-webpack-plugin": "^4.5.1",
|
||||
"cross-env": "^5.1.4",
|
||||
"css-loader": "^0.28.10",
|
||||
"dagre": "^0.8.2",
|
||||
"enzyme": "^3.3.0",
|
||||
"file-loader": "^1.1.11",
|
||||
"glob": "^7.1.2",
|
||||
"jest": "^22.4.2",
|
||||
"jest-cli": "^22.4.2",
|
||||
"json-beautify": "^1.0.1",
|
||||
"node-sass": "^4.7.2",
|
||||
"prettier": "^1.11.1",
|
||||
"puppeteer": "^1.1.1",
|
||||
"raf": "^3.4.0",
|
||||
"raw-loader": "^0.5.1",
|
||||
"react-dom": "^16.2.0",
|
||||
"react-syntax-highlighter": "^7.0.2",
|
||||
"react-test-renderer": "^16.2.0",
|
||||
"sass-loader": "^6.0.7",
|
||||
"source-map-loader": "^0.2.3",
|
||||
"storybook-host": "^4.1.5",
|
||||
"storybook-readme": "^3.2.1",
|
||||
"style-loader": "^0.20.3",
|
||||
"ts-jest": "^22.4.1",
|
||||
"tslint": "^5.9.1",
|
||||
"ts-loader": "^4.1.0",
|
||||
"typescript": "^2.7.2",
|
||||
"uglifyjs-webpack-plugin": "^1.2.3",
|
||||
"val-loader": "^1.1.0",
|
||||
"webpack": "^4.1.1",
|
||||
"webpack-cli": "^2.0.11"
|
||||
"@types/puppeteer": "^3.0.2",
|
||||
"@types/react": "^16.9.49",
|
||||
"babel-loader": "^8.1.0",
|
||||
"closest": "^0.0.1",
|
||||
"cross-env": "^7.0.2",
|
||||
"css-loader": "^4.3.0",
|
||||
"dagre": "^0.8.5",
|
||||
"enzyme": "^3.11.0",
|
||||
"file-loader": "^6.1.0",
|
||||
"glob": "^7.1.6",
|
||||
"jest": "^26.4.2",
|
||||
"jest-cli": "^26.4.2",
|
||||
"jest-puppeteer": "^4.4.0",
|
||||
"json-beautify": "^1.1.1",
|
||||
"lerna": "^3.22.1",
|
||||
"lodash": "4.*",
|
||||
"pathfinding": "^0.4.18",
|
||||
"paths-js": "^0.4.11",
|
||||
"prettier": "^2.1.2",
|
||||
"puppeteer": "^5.3.1",
|
||||
"raf": "^3.4.1",
|
||||
"raw-loader": "^4.0.1",
|
||||
"react": "^16.8.6",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-test-renderer": "^16.13.1",
|
||||
"resize-observer-polyfill": "^1.5.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"source-map-loader": "^1.1.0",
|
||||
"storybook-host": "^5.1.0",
|
||||
"storybook-readme": "^5.0.8",
|
||||
"style-loader": "^1.2.1",
|
||||
"terser-webpack-plugin": "^4.2.2",
|
||||
"ts-jest": "^26.4.0",
|
||||
"ts-loader": "^8.0.4",
|
||||
"typescript": "^4.0.3",
|
||||
"val-loader": "^2.1.1",
|
||||
"webpack": "^4.44.2",
|
||||
"webpack-cli": "^3.3.12",
|
||||
"webpack-dev-server": "^3.11.0",
|
||||
"webpack-node-externals": "^2.5.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
import './addon-code/register';
|
||||
import '@storybook/addon-actions/register';
|
||||
import '@storybook/addon-options/register';
|
||||
@@ -1,8 +1,8 @@
|
||||
import { configure } from '@storybook/react';
|
||||
|
||||
function loadStories() {
|
||||
require('../demos/index.tsx');
|
||||
require('../index.tsx');
|
||||
// You can require as many demos as you need.
|
||||
}
|
||||
|
||||
configure(loadStories, module);
|
||||
configure(loadStories, module);
|
||||
43
packages/diagrams-demo-gallery/.storybook/webpack.config.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const path = require('path');
|
||||
module.exports = async ({ config, mode }) => {
|
||||
return {
|
||||
...config,
|
||||
resolve: {
|
||||
...config.resolve,
|
||||
extensions: ['.tsx', '.ts', '.js']
|
||||
},
|
||||
module: {
|
||||
...config.module,
|
||||
rules: [
|
||||
...config.module.rules,
|
||||
...[
|
||||
{
|
||||
test: /\.scss$/,
|
||||
loaders: [
|
||||
'style-loader',
|
||||
'css-loader',
|
||||
{
|
||||
loader: 'postcss-loader',
|
||||
options: { config: { path: path.join(__dirname, '..') } }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
enforce: 'pre',
|
||||
test: /\.js$/,
|
||||
loader: 'source-map-loader',
|
||||
exclude: [/node_modules/]
|
||||
},
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'ts-loader',
|
||||
options: {
|
||||
transpileOnly: true
|
||||
}
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,89 @@
|
||||
import { Action, ActionEvent, InputType, State } from '@projectstorm/react-canvas-core';
|
||||
import { PortModel, LinkModel, DiagramEngine } from '@projectstorm/react-diagrams-core';
|
||||
import { MouseEvent, KeyboardEvent } from 'react';
|
||||
|
||||
/**
|
||||
* This state is controlling the creation of a link.
|
||||
*/
|
||||
export class CreateLinkState extends State<DiagramEngine> {
|
||||
sourcePort: PortModel;
|
||||
link: LinkModel;
|
||||
|
||||
constructor() {
|
||||
super({ name: 'create-new-link' });
|
||||
|
||||
this.registerAction(
|
||||
new Action({
|
||||
type: InputType.MOUSE_UP,
|
||||
fire: (actionEvent: ActionEvent<MouseEvent>) => {
|
||||
const element = this.engine.getActionEventBus().getModelForEvent(actionEvent);
|
||||
const {
|
||||
event: { clientX, clientY }
|
||||
} = actionEvent;
|
||||
const ox = this.engine.getModel().getOffsetX();
|
||||
const oy = this.engine.getModel().getOffsetY();
|
||||
|
||||
if (element instanceof PortModel && !this.sourcePort) {
|
||||
this.sourcePort = element;
|
||||
|
||||
/* would be cool if link creating could be done somewhat like
|
||||
const link = createLink({
|
||||
sourcePort: this.sourcePort,
|
||||
points: [{ x: clientX, y: clientY }, { x: clientX, y: clientY }]
|
||||
})
|
||||
*/
|
||||
const link = this.sourcePort.createLinkModel();
|
||||
link.setSourcePort(this.sourcePort);
|
||||
link.getFirstPoint().setPosition(clientX - ox, clientY - oy);
|
||||
link.getLastPoint().setPosition(clientX - ox + 20, clientY - oy + 20);
|
||||
|
||||
this.link = this.engine.getModel().addLink(link);
|
||||
} else if (element instanceof PortModel && this.sourcePort && element != this.sourcePort) {
|
||||
if (this.sourcePort.canLinkToPort(element)) {
|
||||
this.link.setTargetPort(element);
|
||||
element.reportPosition();
|
||||
this.clearState();
|
||||
this.eject();
|
||||
}
|
||||
} else if (element === this.link.getLastPoint()) {
|
||||
this.link.point(clientX - ox, clientY - oy, -1);
|
||||
}
|
||||
|
||||
this.engine.repaintCanvas();
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
this.registerAction(
|
||||
new Action({
|
||||
type: InputType.MOUSE_MOVE,
|
||||
fire: (actionEvent: ActionEvent<React.MouseEvent>) => {
|
||||
if (!this.link) return;
|
||||
const { event } = actionEvent;
|
||||
this.link.getLastPoint().setPosition(event.clientX, event.clientY);
|
||||
this.engine.repaintCanvas();
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
this.registerAction(
|
||||
new Action({
|
||||
type: InputType.KEY_UP,
|
||||
fire: (actionEvent: ActionEvent<KeyboardEvent>) => {
|
||||
// on esc press remove any started link and pop back to default state
|
||||
if (actionEvent.event.keyCode === 27) {
|
||||
this.link.remove();
|
||||
this.clearState();
|
||||
this.eject();
|
||||
this.engine.repaintCanvas();
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
clearState() {
|
||||
this.link = undefined;
|
||||
this.sourcePort = undefined;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { MouseEvent } from 'react';
|
||||
import {
|
||||
SelectingState,
|
||||
State,
|
||||
Action,
|
||||
InputType,
|
||||
ActionEvent,
|
||||
DragCanvasState
|
||||
} from '@projectstorm/react-canvas-core';
|
||||
import { PortModel, DiagramEngine, DragDiagramItemsState } from '@projectstorm/react-diagrams-core';
|
||||
import { CreateLinkState } from './CreateLinkState';
|
||||
|
||||
export class DefaultState extends State<DiagramEngine> {
|
||||
dragCanvas: DragCanvasState;
|
||||
createLink: CreateLinkState;
|
||||
dragItems: DragDiagramItemsState;
|
||||
|
||||
constructor() {
|
||||
super({ name: 'starting-state' });
|
||||
this.childStates = [new SelectingState()];
|
||||
this.dragCanvas = new DragCanvasState();
|
||||
this.createLink = new CreateLinkState();
|
||||
this.dragItems = new DragDiagramItemsState();
|
||||
|
||||
// determine what was clicked on
|
||||
this.registerAction(
|
||||
new Action({
|
||||
type: InputType.MOUSE_DOWN,
|
||||
fire: (event: ActionEvent<MouseEvent>) => {
|
||||
const element = this.engine.getActionEventBus().getModelForEvent(event);
|
||||
|
||||
// the canvas was clicked on, transition to the dragging canvas state
|
||||
if (!element) {
|
||||
this.transitionWithEvent(this.dragCanvas, event);
|
||||
}
|
||||
// initiate dragging a new link
|
||||
else if (element instanceof PortModel) {
|
||||
return;
|
||||
}
|
||||
// move the items (and potentially link points)
|
||||
else {
|
||||
this.transitionWithEvent(this.dragItems, event);
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
this.registerAction(
|
||||
new Action({
|
||||
type: InputType.MOUSE_UP,
|
||||
fire: (event: ActionEvent<MouseEvent>) => {
|
||||
const element = this.engine.getActionEventBus().getModelForEvent(event);
|
||||
|
||||
if (element instanceof PortModel) this.transitionWithEvent(this.createLink, event);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import * as React from 'react';
|
||||
import createEngine, { DiagramModel, DefaultNodeModel } from '@projectstorm/react-diagrams';
|
||||
import { CanvasWidget } from '@projectstorm/react-canvas-core';
|
||||
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';
|
||||
import { DefaultState } from './DefaultState';
|
||||
|
||||
export default () => {
|
||||
const engine = createEngine();
|
||||
const model = new DiagramModel();
|
||||
|
||||
const node1 = new DefaultNodeModel('Node 1', 'rgb(0,192,255)');
|
||||
node1.addOutPort('Out');
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
const node2 = new DefaultNodeModel('Node 2', 'rgb(192,255,0)');
|
||||
node2.addInPort('In');
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
model.addAll(node1, node2);
|
||||
|
||||
engine.setModel(model);
|
||||
|
||||
// Use this custom "DefaultState" instead of the actual default state we get with the engine
|
||||
engine.getStateMachine().pushState(new DefaultState());
|
||||
|
||||
return (
|
||||
<DemoCanvasWidget>
|
||||
<CanvasWidget engine={engine} />
|
||||
</DemoCanvasWidget>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,86 @@
|
||||
import createEngine, { DiagramModel, DefaultNodeModel } from '@projectstorm/react-diagrams';
|
||||
import * as React from 'react';
|
||||
import gsap from 'gsap';
|
||||
import { DemoWorkspaceWidget } from '../helpers/DemoWorkspaceWidget';
|
||||
import { CanvasWidget } from '@projectstorm/react-canvas-core';
|
||||
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';
|
||||
|
||||
/**
|
||||
* Tests the grid size
|
||||
*/
|
||||
class NodeDelayedPosition extends React.Component<any, any> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { engine } = this.props;
|
||||
return (
|
||||
<DemoWorkspaceWidget>
|
||||
<DemoCanvasWidget>
|
||||
<CanvasWidget engine={engine} />
|
||||
</DemoCanvasWidget>
|
||||
</DemoWorkspaceWidget>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
var engine = createEngine({ repaintDebounceMs: 12 });
|
||||
|
||||
//2) setup the diagram model
|
||||
var model = new DiagramModel();
|
||||
|
||||
//3-A) create a default node
|
||||
var node1 = new DefaultNodeModel('Node 1', 'rgb(0,192,255)');
|
||||
var port1 = node1.addOutPort('Out');
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
//3-B) create another default node
|
||||
var node2 = new DefaultNodeModel('Node 2', 'rgb(192,255,0)');
|
||||
var port2 = node2.addInPort('In');
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
//3-C) create another default node
|
||||
var node3 = new DefaultNodeModel('Node 3', 'rgb(192,255,0)');
|
||||
node2.setPosition(200, 300);
|
||||
|
||||
//3-D) create another default node
|
||||
var node4 = new DefaultNodeModel('Node 4', 'rgb(192,255,0)');
|
||||
node2.setPosition(400, 400);
|
||||
|
||||
//3-C) link the 2 nodes together
|
||||
var link1 = port1.link(port2);
|
||||
|
||||
//4) add the models to the root graph
|
||||
model.addAll(node1, node2, link1, node3, node4);
|
||||
|
||||
//5) load model into engine
|
||||
engine.setModel(model);
|
||||
|
||||
var interval = setInterval(() => {
|
||||
[node1, node2, node3, node4].map((node) => {
|
||||
var obj = { x: 0, y: 0 };
|
||||
gsap.fromTo(
|
||||
obj,
|
||||
{
|
||||
x: node.getPosition().x,
|
||||
y: node.getPosition().y
|
||||
},
|
||||
{
|
||||
x: Math.floor(Math.random() * 500),
|
||||
y: Math.floor(Math.random() * 500),
|
||||
duration: 0.8,
|
||||
onUpdate: () => {
|
||||
node.setPosition(obj.x, obj.y);
|
||||
engine.repaintCanvas();
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}, 2000);
|
||||
|
||||
//6) render the diagram!
|
||||
return <NodeDelayedPosition engine={engine} model={model} />;
|
||||
};
|
||||
@@ -0,0 +1,71 @@
|
||||
import * as React from 'react';
|
||||
import createEngine, { DiagramModel, DefaultNodeModel } from '@projectstorm/react-diagrams';
|
||||
import { DemoButton, DemoWorkspaceWidget } from '../helpers/DemoWorkspaceWidget';
|
||||
import { CanvasWidget } from '@projectstorm/react-canvas-core';
|
||||
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';
|
||||
|
||||
/**
|
||||
* Tests the drag on/off
|
||||
*/
|
||||
class CanvasDragToggle extends React.Component<any, any> {
|
||||
enableDrag = () => {
|
||||
const { engine } = this.props;
|
||||
const state = engine.getStateMachine().getCurrentState();
|
||||
state.dragCanvas.config.allowDrag = true;
|
||||
};
|
||||
|
||||
disableDrag = () => {
|
||||
const { engine } = this.props;
|
||||
const state = engine.getStateMachine().getCurrentState();
|
||||
state.dragCanvas.config.allowDrag = false;
|
||||
};
|
||||
|
||||
render() {
|
||||
const { engine } = this.props;
|
||||
return (
|
||||
<DemoWorkspaceWidget
|
||||
buttons={[
|
||||
<DemoButton key={1} onClick={this.enableDrag}>
|
||||
Enable canvas drag
|
||||
</DemoButton>,
|
||||
<DemoButton key={2} onClick={this.disableDrag}>
|
||||
Disable canvas drag
|
||||
</DemoButton>
|
||||
]}>
|
||||
<DemoCanvasWidget>
|
||||
<CanvasWidget engine={engine} />
|
||||
</DemoCanvasWidget>
|
||||
</DemoWorkspaceWidget>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
var engine = createEngine();
|
||||
|
||||
//2) setup the diagram model
|
||||
var model = new DiagramModel();
|
||||
|
||||
//3-A) create a default node
|
||||
var node1 = new DefaultNodeModel('Node 1', 'rgb(0,192,255)');
|
||||
var port1 = node1.addOutPort('Out');
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
//3-B) create another default node
|
||||
var node2 = new DefaultNodeModel('Node 2', 'rgb(192,255,0)');
|
||||
var port2 = node2.addInPort('In');
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
//3-C) link the 2 nodes together
|
||||
var link1 = port1.link(port2);
|
||||
|
||||
//4) add the models to the root graph
|
||||
model.addAll(node1, node2, link1);
|
||||
|
||||
//5) load model into engine
|
||||
engine.setModel(model);
|
||||
|
||||
//6) render the diagram!
|
||||
return <CanvasDragToggle engine={engine} model={model} />;
|
||||
};
|
||||
83
packages/diagrams-demo-gallery/demos/demo-cloning/index.tsx
Normal file
@@ -0,0 +1,83 @@
|
||||
import createEngine, { DiagramModel, DefaultNodeModel, LinkModel, NodeModel } from '@projectstorm/react-diagrams';
|
||||
import * as _ from 'lodash';
|
||||
import * as React from 'react';
|
||||
import { DemoButton, DemoWorkspaceWidget } from '../helpers/DemoWorkspaceWidget';
|
||||
import { BaseModel, CanvasWidget } from '@projectstorm/react-canvas-core';
|
||||
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';
|
||||
|
||||
/**
|
||||
* Tests cloning
|
||||
*/
|
||||
class CloneSelected extends React.Component<any, any> {
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
this.cloneSelected = this.cloneSelected.bind(this);
|
||||
}
|
||||
|
||||
cloneSelected() {
|
||||
let { engine } = this.props;
|
||||
let offset = { x: 100, y: 100 };
|
||||
let model = engine.getModel();
|
||||
|
||||
let itemMap = {};
|
||||
_.forEach(model.getSelectedEntities(), (item: BaseModel<any>) => {
|
||||
let newItem = item.clone(itemMap);
|
||||
|
||||
// offset the nodes slightly
|
||||
if (newItem instanceof NodeModel) {
|
||||
newItem.setPosition(newItem.getX() + offset.x, newItem.getY() + offset.y);
|
||||
model.addNode(newItem);
|
||||
} else if (newItem instanceof LinkModel) {
|
||||
// offset the link points
|
||||
newItem.getPoints().forEach((p) => {
|
||||
p.setPosition(p.getX() + offset.x, p.getY() + offset.y);
|
||||
});
|
||||
model.addLink(newItem);
|
||||
}
|
||||
(newItem as BaseModel).setSelected(false);
|
||||
});
|
||||
|
||||
this.forceUpdate();
|
||||
}
|
||||
|
||||
render() {
|
||||
const { engine } = this.props;
|
||||
return (
|
||||
<DemoWorkspaceWidget buttons={<DemoButton onClick={this.cloneSelected}>Clone Selected</DemoButton>}>
|
||||
<DemoCanvasWidget>
|
||||
<CanvasWidget engine={engine} />
|
||||
</DemoCanvasWidget>
|
||||
</DemoWorkspaceWidget>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
var engine = createEngine();
|
||||
|
||||
//2) setup the diagram model
|
||||
var model = new DiagramModel();
|
||||
|
||||
//3-A) create a default node
|
||||
var node1 = new DefaultNodeModel('Node 1', 'rgb(0,192,255)');
|
||||
let port = node1.addOutPort('Out');
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
//3-B) create another default node
|
||||
var node2 = new DefaultNodeModel('Node 2', 'rgb(192,255,0)');
|
||||
let port2 = node2.addInPort('In');
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
// link the ports
|
||||
let link1 = port.link(port2);
|
||||
|
||||
//4) add the models to the root graph
|
||||
model.addAll(node1, node2, link1);
|
||||
|
||||
//5) load model into engine
|
||||
engine.setModel(model);
|
||||
|
||||
//6) render the diagram!
|
||||
return <CloneSelected engine={engine} model={model} />;
|
||||
};
|
||||
@@ -0,0 +1,73 @@
|
||||
import * as React from 'react';
|
||||
import * as _ from 'lodash';
|
||||
import createEngine, { DiagramModel, DefaultNodeModel, DefaultLinkModel } from '@projectstorm/react-diagrams';
|
||||
import { CanvasWidget, Action, ActionEvent, InputType } from '@projectstorm/react-canvas-core';
|
||||
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';
|
||||
|
||||
interface CustomDeleteItemsActionOptions {
|
||||
keyCodes?: number[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all selected items, but asks for confirmation first
|
||||
*/
|
||||
class CustomDeleteItemsAction extends Action {
|
||||
constructor(options: CustomDeleteItemsActionOptions = {}) {
|
||||
options = {
|
||||
keyCodes: [46, 8],
|
||||
...options
|
||||
};
|
||||
super({
|
||||
type: InputType.KEY_DOWN,
|
||||
fire: (event: ActionEvent<React.KeyboardEvent>) => {
|
||||
if (options.keyCodes.indexOf(event.event.keyCode) !== -1) {
|
||||
const selectedEntities = this.engine.getModel().getSelectedEntities();
|
||||
if (selectedEntities.length > 0) {
|
||||
const confirm = window.confirm('Are you sure you want to delete?');
|
||||
|
||||
if (confirm) {
|
||||
_.forEach(selectedEntities, (model) => {
|
||||
// only delete items which are not locked
|
||||
if (!model.isLocked()) {
|
||||
model.remove();
|
||||
}
|
||||
});
|
||||
this.engine.repaintCanvas();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default () => {
|
||||
// create an engine without registering DeleteItemsAction
|
||||
const engine = createEngine({ registerDefaultDeleteItemsAction: false });
|
||||
const model = new DiagramModel();
|
||||
|
||||
const node1 = new DefaultNodeModel({ name: 'Node 1', color: 'rgb(0,192,255)' });
|
||||
node1.setPosition(100, 100);
|
||||
const port1 = node1.addOutPort('Out');
|
||||
|
||||
const node2 = new DefaultNodeModel('Node 2', 'rgb(192,255,0)');
|
||||
const port2 = node2.addInPort('In');
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
const link1 = port1.link<DefaultLinkModel>(port2);
|
||||
link1.getOptions().testName = 'Test';
|
||||
link1.addLabel('Hello World!');
|
||||
|
||||
model.addAll(node1, node2, link1);
|
||||
|
||||
engine.setModel(model);
|
||||
|
||||
// register an DeleteItemsAction with custom keyCodes (in this case, only Delete key)
|
||||
engine.getActionEventBus().registerAction(new CustomDeleteItemsAction());
|
||||
|
||||
return (
|
||||
<DemoCanvasWidget>
|
||||
<CanvasWidget engine={engine} />
|
||||
</DemoCanvasWidget>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
import * as React from 'react';
|
||||
import { AbstractReactFactory, GenerateWidgetEvent } from '@projectstorm/react-canvas-core';
|
||||
import { DiagramEngine } from '@projectstorm/react-diagrams';
|
||||
|
||||
import { EditableLabelModel } from './EditableLabelModel';
|
||||
import { EditableLabelWidget } from './EditableLabelWidget';
|
||||
|
||||
export class EditableLabelFactory extends AbstractReactFactory<EditableLabelModel, DiagramEngine> {
|
||||
constructor() {
|
||||
super('editable-label');
|
||||
}
|
||||
|
||||
generateModel(): EditableLabelModel {
|
||||
return new EditableLabelModel();
|
||||
}
|
||||
|
||||
generateReactWidget(event: GenerateWidgetEvent<EditableLabelModel>): JSX.Element {
|
||||
return <EditableLabelWidget model={event.model} />;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { LabelModel } from '@projectstorm/react-diagrams';
|
||||
import { BaseModelOptions, DeserializeEvent } from '@projectstorm/react-canvas-core';
|
||||
|
||||
export interface EditableLabelOptions extends BaseModelOptions {
|
||||
value?: string;
|
||||
}
|
||||
|
||||
export class EditableLabelModel extends LabelModel {
|
||||
value: string;
|
||||
|
||||
constructor(options: EditableLabelOptions = {}) {
|
||||
super({
|
||||
...options,
|
||||
type: 'editable-label'
|
||||
});
|
||||
this.value = options.value || '';
|
||||
}
|
||||
|
||||
serialize() {
|
||||
return {
|
||||
...super.serialize(),
|
||||
value: this.value
|
||||
};
|
||||
}
|
||||
|
||||
deserialize(event: DeserializeEvent<this>): void {
|
||||
super.deserialize(event);
|
||||
this.value = event.data.value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import { EditableLabelModel } from './EditableLabelModel';
|
||||
import styled from '@emotion/styled';
|
||||
import { action } from '@storybook/addon-actions';
|
||||
|
||||
export interface FlowAliasLabelWidgetProps {
|
||||
model: EditableLabelModel;
|
||||
}
|
||||
|
||||
namespace S {
|
||||
// NOTE: this CSS rules allows to interact with elements in label
|
||||
export const Label = styled.div`
|
||||
user-select: none;
|
||||
pointer-events: auto;
|
||||
`;
|
||||
}
|
||||
|
||||
// now we can render all what we want in the label
|
||||
export const EditableLabelWidget: React.FunctionComponent<FlowAliasLabelWidgetProps> = (props) => {
|
||||
const [str, setStr] = React.useState(props.model.value);
|
||||
|
||||
return (
|
||||
<S.Label>
|
||||
<input
|
||||
value={str}
|
||||
onChange={(event) => {
|
||||
const newVal = event.target.value;
|
||||
|
||||
// update value both in internal component state
|
||||
setStr(newVal);
|
||||
// and in model object
|
||||
props.model.value = newVal;
|
||||
}}
|
||||
/>
|
||||
|
||||
<button onClick={() => action('model eventDidFire')('You clicked the button')}>Click me!</button>
|
||||
</S.Label>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,55 @@
|
||||
import * as React from 'react';
|
||||
import createEngine, { DefaultNodeModel, DiagramModel } from '@projectstorm/react-diagrams';
|
||||
import { CanvasWidget } from '@projectstorm/react-canvas-core';
|
||||
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';
|
||||
|
||||
import { EditableLabelFactory } from './EditableLabelFactory';
|
||||
import { EditableLabelModel } from './EditableLabelModel';
|
||||
|
||||
/**
|
||||
* @Author Shumaf Lovpache (aka Soarex16)
|
||||
*/
|
||||
|
||||
export default () => {
|
||||
// engine setup
|
||||
const engine = createEngine();
|
||||
|
||||
// register our label factory
|
||||
engine.getLabelFactories().registerFactory(new EditableLabelFactory());
|
||||
|
||||
// setup diagram model
|
||||
const model = new DiagramModel();
|
||||
|
||||
// create some nodes
|
||||
const node1 = new DefaultNodeModel('Node1', 'red');
|
||||
const port1 = node1.addOutPort('out');
|
||||
node1.setPosition(250, 100);
|
||||
|
||||
const node2 = new DefaultNodeModel('Node2', 'green');
|
||||
const port2 = node2.addInPort('in');
|
||||
node2.setPosition(800, 300);
|
||||
|
||||
// link nodes together
|
||||
const link1 = port1.link(port2);
|
||||
|
||||
// !!!
|
||||
// add our custom label to link
|
||||
link1.addLabel(
|
||||
new EditableLabelModel({
|
||||
value: 'Hello, I am label!'
|
||||
})
|
||||
);
|
||||
|
||||
// add models to the root graph
|
||||
model.addAll(node1, port1, node2, port2, link1);
|
||||
|
||||
// load model into engine
|
||||
engine.setModel(model);
|
||||
|
||||
// render diagram
|
||||
return (
|
||||
<DemoCanvasWidget>
|
||||
<CanvasWidget engine={engine} />
|
||||
</DemoCanvasWidget>
|
||||
);
|
||||
};
|
||||
@@ -1,23 +1,20 @@
|
||||
import {
|
||||
DiagramEngine,
|
||||
import createEngine, {
|
||||
DiagramModel,
|
||||
DefaultNodeModel,
|
||||
LinkModel,
|
||||
DefaultPortModel,
|
||||
DiagramWidget,
|
||||
LinkWidget,
|
||||
LinkProps,
|
||||
DefaultLinkWidget,
|
||||
DefaultLinkModel,
|
||||
DefaultLinkFactory
|
||||
} from "storm-react-diagrams";
|
||||
import { action } from "@storybook/addon-actions";
|
||||
import * as React from "react";
|
||||
DefaultLinkFactory,
|
||||
DefaultLinkModel
|
||||
} from '@projectstorm/react-diagrams';
|
||||
import * as React from 'react';
|
||||
import { CanvasWidget } from '@projectstorm/react-canvas-core';
|
||||
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';
|
||||
|
||||
export class AdvancedLinkModel extends DefaultLinkModel {
|
||||
constructor() {
|
||||
super("advanced");
|
||||
this.width = 10;
|
||||
super({
|
||||
type: 'advanced',
|
||||
width: 10
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,8 +51,8 @@ export class AdvancedLinkSegment extends React.Component<{ model: AdvancedLinkMo
|
||||
|
||||
let point = this.path.getPointAtLength(this.path.getTotalLength() * (this.percent / 100.0));
|
||||
|
||||
this.circle.setAttribute("cx", "" + point.x);
|
||||
this.circle.setAttribute("cy", "" + point.y);
|
||||
this.circle.setAttribute('cx', '' + point.x);
|
||||
this.circle.setAttribute('cy', '' + point.y);
|
||||
|
||||
if (this.mounted) {
|
||||
requestAnimationFrame(this.callback);
|
||||
@@ -72,15 +69,16 @@ export class AdvancedLinkSegment extends React.Component<{ model: AdvancedLinkMo
|
||||
return (
|
||||
<>
|
||||
<path
|
||||
ref={ref => {
|
||||
fill="none"
|
||||
ref={(ref) => {
|
||||
this.path = ref;
|
||||
}}
|
||||
strokeWidth={this.props.model.width}
|
||||
strokeWidth={this.props.model.getOptions().width}
|
||||
stroke="rgba(255,0,0,0.5)"
|
||||
d={this.props.path}
|
||||
/>
|
||||
<circle
|
||||
ref={ref => {
|
||||
ref={(ref) => {
|
||||
this.circle = ref;
|
||||
}}
|
||||
r={10}
|
||||
@@ -93,15 +91,14 @@ export class AdvancedLinkSegment extends React.Component<{ model: AdvancedLinkMo
|
||||
|
||||
export class AdvancedLinkFactory extends DefaultLinkFactory {
|
||||
constructor() {
|
||||
super();
|
||||
this.type = "advanced";
|
||||
super('advanced');
|
||||
}
|
||||
|
||||
getNewInstance(initialConfig?: any): AdvancedLinkModel {
|
||||
generateModel(): AdvancedLinkModel {
|
||||
return new AdvancedLinkModel();
|
||||
}
|
||||
|
||||
generateLinkSegment(model: AdvancedLinkModel, widget: DefaultLinkWidget, selected: boolean, path: string) {
|
||||
generateLinkSegment(model: AdvancedLinkModel, selected: boolean, path: string) {
|
||||
return (
|
||||
<g>
|
||||
<AdvancedLinkSegment model={model} path={path} />
|
||||
@@ -117,29 +114,28 @@ export class AdvancedLinkFactory extends DefaultLinkFactory {
|
||||
*/
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
var engine = new DiagramEngine();
|
||||
engine.installDefaultFactories();
|
||||
engine.registerLinkFactory(new AdvancedLinkFactory());
|
||||
var engine = createEngine();
|
||||
engine.getLinkFactories().registerFactory(new AdvancedLinkFactory());
|
||||
|
||||
// create some nodes
|
||||
var node1 = new DefaultNodeModel("Source", "rgb(0,192,255)");
|
||||
let port1 = node1.addPort(new AdvancedPortModel(false, "out-1", "Out thick"));
|
||||
let port2 = node1.addPort(new DefaultPortModel(false, "out-2", "Out default"));
|
||||
var node1 = new DefaultNodeModel('Source', 'rgb(0,192,255)');
|
||||
let port1 = node1.addPort(new AdvancedPortModel(false, 'out-1', 'Out thick'));
|
||||
let port2 = node1.addPort(new DefaultPortModel(false, 'out-2', 'Out default'));
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
var node2 = new DefaultNodeModel("Target", "rgb(192,255,0)");
|
||||
var port3 = node2.addPort(new AdvancedPortModel(true, "in-1", "In thick"));
|
||||
var port4 = node2.addPort(new DefaultPortModel(true, "in-2", "In default"));
|
||||
var node2 = new DefaultNodeModel('Target', 'rgb(192,255,0)');
|
||||
var port3 = node2.addPort(new AdvancedPortModel(true, 'in-1', 'In thick'));
|
||||
var port4 = node2.addPort(new DefaultPortModel(true, 'in-2', 'In default'));
|
||||
node2.setPosition(300, 100);
|
||||
|
||||
var node3 = new DefaultNodeModel("Source", "rgb(0,192,255)");
|
||||
node3.addPort(new AdvancedPortModel(false, "out-1", "Out thick"));
|
||||
node3.addPort(new DefaultPortModel(false, "out-2", "Out default"));
|
||||
var node3 = new DefaultNodeModel('Source', 'rgb(0,192,255)');
|
||||
node3.addPort(new AdvancedPortModel(false, 'out-1', 'Out thick'));
|
||||
node3.addPort(new DefaultPortModel(false, 'out-2', 'Out default'));
|
||||
node3.setPosition(100, 200);
|
||||
|
||||
var node4 = new DefaultNodeModel("Target", "rgb(192,255,0)");
|
||||
node4.addPort(new AdvancedPortModel(true, "in-1", "In thick"));
|
||||
node4.addPort(new DefaultPortModel(true, "in-2", "In default"));
|
||||
var node4 = new DefaultNodeModel('Target', 'rgb(192,255,0)');
|
||||
node4.addPort(new AdvancedPortModel(true, 'in-1', 'In thick'));
|
||||
node4.addPort(new DefaultPortModel(true, 'in-2', 'In default'));
|
||||
node4.setPosition(300, 200);
|
||||
|
||||
var model = new DiagramModel();
|
||||
@@ -150,8 +146,12 @@ export default () => {
|
||||
model.addAll(node1, node2, node3, node4);
|
||||
|
||||
// load model into engine
|
||||
engine.setDiagramModel(model);
|
||||
engine.setModel(model);
|
||||
|
||||
// render the diagram!
|
||||
return <DiagramWidget className="srd-demo-canvas" diagramEngine={engine} />;
|
||||
return (
|
||||
<DemoCanvasWidget>
|
||||
<CanvasWidget engine={engine} />
|
||||
</DemoCanvasWidget>
|
||||
);
|
||||
};
|
||||
172
packages/diagrams-demo-gallery/demos/demo-custom-link2/index.tsx
Normal file
@@ -0,0 +1,172 @@
|
||||
import createEngine, {
|
||||
DiagramModel,
|
||||
DefaultNodeModel,
|
||||
DefaultPortModel,
|
||||
DefaultLinkFactory,
|
||||
DefaultLinkPointWidget,
|
||||
DefaultLinkModel,
|
||||
DefaultLinkWidget
|
||||
} from '@projectstorm/react-diagrams';
|
||||
import { DiagramEngine, LinkWidget, PointModel } from '@projectstorm/react-diagrams-core';
|
||||
import * as React from 'react';
|
||||
import { CanvasWidget } from '@projectstorm/react-canvas-core';
|
||||
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';
|
||||
|
||||
export class AdvancedLinkModel extends DefaultLinkModel {
|
||||
constructor() {
|
||||
super({
|
||||
type: 'advanced',
|
||||
width: 4
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class AdvancedPortModel extends DefaultPortModel {
|
||||
createLinkModel(): AdvancedLinkModel | null {
|
||||
return new AdvancedLinkModel();
|
||||
}
|
||||
}
|
||||
|
||||
const CustomLinkArrowWidget = (props) => {
|
||||
const { point, previousPoint } = props;
|
||||
|
||||
const angle =
|
||||
90 +
|
||||
(Math.atan2(
|
||||
point.getPosition().y - previousPoint.getPosition().y,
|
||||
point.getPosition().x - previousPoint.getPosition().x
|
||||
) *
|
||||
180) /
|
||||
Math.PI;
|
||||
|
||||
//translate(50, -10),
|
||||
return (
|
||||
<g className="arrow" transform={'translate(' + point.getPosition().x + ', ' + point.getPosition().y + ')'}>
|
||||
<g style={{ transform: 'rotate(' + angle + 'deg)' }}>
|
||||
<g transform={'translate(0, -3)'}>
|
||||
<polygon
|
||||
points="0,10 8,30 -8,30"
|
||||
fill={props.color}
|
||||
onMouseLeave={() => {
|
||||
this.setState({ selected: false });
|
||||
}}
|
||||
onMouseEnter={() => {
|
||||
this.setState({ selected: true });
|
||||
}}
|
||||
data-id={point.getID()}
|
||||
data-linkid={point.getLink().getID()}></polygon>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
);
|
||||
};
|
||||
|
||||
export class AdvancedLinkWidget extends DefaultLinkWidget {
|
||||
generateArrow(point: PointModel, previousPoint: PointModel): JSX.Element {
|
||||
return (
|
||||
<CustomLinkArrowWidget
|
||||
key={point.getID()}
|
||||
point={point as any}
|
||||
previousPoint={previousPoint as any}
|
||||
colorSelected={this.props.link.getOptions().selectedColor}
|
||||
color={this.props.link.getOptions().color}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
//ensure id is present for all points on the path
|
||||
var points = this.props.link.getPoints();
|
||||
var paths = [];
|
||||
this.refPaths = [];
|
||||
|
||||
//draw the multiple anchors and complex line instead
|
||||
for (let j = 0; j < points.length - 1; j++) {
|
||||
paths.push(
|
||||
this.generateLink(
|
||||
LinkWidget.generateLinePath(points[j], points[j + 1]),
|
||||
{
|
||||
'data-linkid': this.props.link.getID(),
|
||||
'data-point': j,
|
||||
onMouseDown: (event: MouseEvent) => {
|
||||
this.addPointToLink(event, j + 1);
|
||||
}
|
||||
},
|
||||
j
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
//render the circles
|
||||
for (let i = 1; i < points.length - 1; i++) {
|
||||
paths.push(this.generatePoint(points[i]));
|
||||
}
|
||||
|
||||
if (this.props.link.getTargetPort() !== null) {
|
||||
paths.push(this.generateArrow(points[points.length - 1], points[points.length - 2]));
|
||||
} else {
|
||||
paths.push(this.generatePoint(points[points.length - 1]));
|
||||
}
|
||||
|
||||
return <g data-default-link-test={this.props.link.getOptions().testName}>{paths}</g>;
|
||||
}
|
||||
}
|
||||
|
||||
export class AdvancedLinkFactory extends DefaultLinkFactory {
|
||||
constructor() {
|
||||
super('advanced');
|
||||
}
|
||||
|
||||
generateModel(): AdvancedLinkModel {
|
||||
return new AdvancedLinkModel();
|
||||
}
|
||||
|
||||
generateReactWidget(event): JSX.Element {
|
||||
return <AdvancedLinkWidget link={event.model} diagramEngine={this.engine} />;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* Simple link styling demo
|
||||
*
|
||||
* @Author kfrajtak
|
||||
*/
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
var engine = createEngine();
|
||||
engine.getLinkFactories().registerFactory(new AdvancedLinkFactory());
|
||||
|
||||
// create some nodes
|
||||
var node1 = new DefaultNodeModel('Source', 'rgb(0,192,255)');
|
||||
let port1 = node1.addPort(new AdvancedPortModel(false, 'out'));
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
var node2 = new DefaultNodeModel('Target', 'rgb(192,255,0)');
|
||||
var port2 = node2.addPort(new AdvancedPortModel(true, 'in'));
|
||||
node2.setPosition(500, 350);
|
||||
|
||||
var node3 = new DefaultNodeModel('Source', 'rgb(0,192,255)');
|
||||
let port3 = node3.addPort(new AdvancedPortModel(false, 'out'));
|
||||
node3.setPosition(100, 500);
|
||||
|
||||
var node4 = new DefaultNodeModel('Target', 'rgb(192,255,0)');
|
||||
var port4 = node4.addPort(new AdvancedPortModel(true, 'in'));
|
||||
node4.setPosition(500, 450);
|
||||
|
||||
var model = new DiagramModel();
|
||||
|
||||
model.addAll(port1.link(port2), port3.link(port4));
|
||||
|
||||
// add everything else
|
||||
model.addAll(node1, node2, node3, node4);
|
||||
|
||||
// load model into engine
|
||||
engine.setModel(model);
|
||||
|
||||
// render the diagram!
|
||||
return (
|
||||
<DemoCanvasWidget>
|
||||
<CanvasWidget engine={engine} />
|
||||
</DemoCanvasWidget>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
import { DiamondNodeWidget } from './DiamondNodeWidget';
|
||||
import { DiamondNodeModel } from './DiamondNodeModel';
|
||||
import * as React from 'react';
|
||||
import { AbstractReactFactory } from '@projectstorm/react-canvas-core';
|
||||
import { DiagramEngine } from '@projectstorm/react-diagrams-core';
|
||||
|
||||
export class DiamondNodeFactory extends AbstractReactFactory<DiamondNodeModel, DiagramEngine> {
|
||||
constructor() {
|
||||
super('diamond');
|
||||
}
|
||||
|
||||
generateReactWidget(event): JSX.Element {
|
||||
return <DiamondNodeWidget engine={this.engine} size={50} node={event.model} />;
|
||||
}
|
||||
|
||||
generateModel(event) {
|
||||
return new DiamondNodeModel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { NodeModel, NodeModelGenerics, PortModelAlignment } from '@projectstorm/react-diagrams';
|
||||
import { DiamondPortModel } from './DiamondPortModel';
|
||||
|
||||
export interface DiamondNodeModelGenerics {
|
||||
PORT: DiamondPortModel;
|
||||
}
|
||||
|
||||
export class DiamondNodeModel extends NodeModel<NodeModelGenerics & DiamondNodeModelGenerics> {
|
||||
constructor() {
|
||||
super({
|
||||
type: 'diamond'
|
||||
});
|
||||
this.addPort(new DiamondPortModel(PortModelAlignment.TOP));
|
||||
this.addPort(new DiamondPortModel(PortModelAlignment.LEFT));
|
||||
this.addPort(new DiamondPortModel(PortModelAlignment.BOTTOM));
|
||||
this.addPort(new DiamondPortModel(PortModelAlignment.RIGHT));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
import * as React from 'react';
|
||||
import { DiamondNodeModel } from './DiamondNodeModel';
|
||||
import { DiagramEngine, PortModelAlignment, PortWidget } from '@projectstorm/react-diagrams';
|
||||
import styled from '@emotion/styled';
|
||||
|
||||
export interface DiamondNodeWidgetProps {
|
||||
node: DiamondNodeModel;
|
||||
engine: DiagramEngine;
|
||||
size?: number;
|
||||
}
|
||||
|
||||
namespace S {
|
||||
export const Port = styled.div`
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
z-index: 10;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: rgba(0, 0, 0, 1);
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Dylan Vorster
|
||||
*/
|
||||
export class DiamondNodeWidget extends React.Component<DiamondNodeWidgetProps> {
|
||||
render() {
|
||||
return (
|
||||
<div
|
||||
className={'diamond-node'}
|
||||
style={{
|
||||
position: 'relative',
|
||||
width: this.props.size,
|
||||
height: this.props.size
|
||||
}}>
|
||||
<svg
|
||||
width={this.props.size}
|
||||
height={this.props.size}
|
||||
dangerouslySetInnerHTML={{
|
||||
__html:
|
||||
`
|
||||
<g id="Layer_1">
|
||||
</g>
|
||||
<g id="Layer_2">
|
||||
<polygon fill="mediumpurple" stroke="${
|
||||
this.props.node.isSelected() ? 'white' : '#000000'
|
||||
}" stroke-width="3" stroke-miterlimit="10" points="10,` +
|
||||
this.props.size / 2 +
|
||||
` ` +
|
||||
this.props.size / 2 +
|
||||
`,10 ` +
|
||||
(this.props.size - 10) +
|
||||
`,` +
|
||||
this.props.size / 2 +
|
||||
` ` +
|
||||
this.props.size / 2 +
|
||||
`,` +
|
||||
(this.props.size - 10) +
|
||||
` "/>
|
||||
</g>
|
||||
`
|
||||
}}
|
||||
/>
|
||||
<PortWidget
|
||||
style={{
|
||||
top: this.props.size / 2 - 8,
|
||||
left: -8,
|
||||
position: 'absolute'
|
||||
}}
|
||||
port={this.props.node.getPort(PortModelAlignment.LEFT)}
|
||||
engine={this.props.engine}>
|
||||
<S.Port />
|
||||
</PortWidget>
|
||||
<PortWidget
|
||||
style={{
|
||||
left: this.props.size / 2 - 8,
|
||||
top: -8,
|
||||
position: 'absolute'
|
||||
}}
|
||||
port={this.props.node.getPort(PortModelAlignment.TOP)}
|
||||
engine={this.props.engine}>
|
||||
<S.Port />
|
||||
</PortWidget>
|
||||
<PortWidget
|
||||
style={{
|
||||
left: this.props.size - 8,
|
||||
top: this.props.size / 2 - 8,
|
||||
position: 'absolute'
|
||||
}}
|
||||
port={this.props.node.getPort(PortModelAlignment.RIGHT)}
|
||||
engine={this.props.engine}>
|
||||
<S.Port />
|
||||
</PortWidget>
|
||||
<PortWidget
|
||||
style={{
|
||||
left: this.props.size / 2 - 8,
|
||||
top: this.props.size - 8,
|
||||
position: 'absolute'
|
||||
}}
|
||||
port={this.props.node.getPort(PortModelAlignment.BOTTOM)}
|
||||
engine={this.props.engine}>
|
||||
<S.Port />
|
||||
</PortWidget>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { LinkModel, PortModel, DefaultLinkModel, PortModelAlignment } from '@projectstorm/react-diagrams';
|
||||
|
||||
export class DiamondPortModel extends PortModel {
|
||||
constructor(alignment: PortModelAlignment) {
|
||||
super({
|
||||
type: 'diamond',
|
||||
name: alignment,
|
||||
alignment: alignment
|
||||
});
|
||||
}
|
||||
|
||||
createLinkModel(): LinkModel {
|
||||
return new DefaultLinkModel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { DiagramEngine, PortModel } from '@projectstorm/react-diagrams';
|
||||
import { AbstractModelFactory } from '@projectstorm/react-canvas-core';
|
||||
|
||||
export class SimplePortFactory extends AbstractModelFactory<PortModel, DiagramEngine> {
|
||||
cb: (initialConfig?: any) => PortModel;
|
||||
|
||||
constructor(type: string, cb: (initialConfig?: any) => PortModel) {
|
||||
super(type);
|
||||
this.cb = cb;
|
||||
}
|
||||
|
||||
generateModel(event): PortModel {
|
||||
return this.cb(event.initialConfig);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import createEngine, { DefaultNodeModel, DiagramModel, PortModelAlignment } from '@projectstorm/react-diagrams';
|
||||
import * as React from 'react';
|
||||
// import the custom models
|
||||
import { DiamondNodeModel } from './DiamondNodeModel';
|
||||
import { DiamondNodeFactory } from './DiamondNodeFactory';
|
||||
import { SimplePortFactory } from './SimplePortFactory';
|
||||
import { DiamondPortModel } from './DiamondPortModel';
|
||||
import { CanvasWidget } from '@projectstorm/react-canvas-core';
|
||||
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';
|
||||
|
||||
/**
|
||||
* @Author Dylan Vorster
|
||||
*/
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
var engine = createEngine();
|
||||
|
||||
// register some other factories as well
|
||||
engine
|
||||
.getPortFactories()
|
||||
.registerFactory(new SimplePortFactory('diamond', (config) => new DiamondPortModel(PortModelAlignment.LEFT)));
|
||||
engine.getNodeFactories().registerFactory(new DiamondNodeFactory());
|
||||
|
||||
//2) setup the diagram model
|
||||
var model = new DiagramModel();
|
||||
|
||||
//3-A) create a default node
|
||||
var node1 = new DefaultNodeModel('Node 1', 'rgb(0,192,255)');
|
||||
var port1 = node1.addOutPort('Out');
|
||||
node1.setPosition(100, 200);
|
||||
|
||||
//3-B) create our new custom node
|
||||
var node2 = new DiamondNodeModel();
|
||||
node2.setPosition(250, 108);
|
||||
|
||||
var node3 = new DefaultNodeModel('Node 3', 'red');
|
||||
var port3 = node3.addInPort('In');
|
||||
node3.setPosition(500, 100);
|
||||
|
||||
//3-C) link the 2 nodes together
|
||||
var link1 = port1.link(node2.getPort(PortModelAlignment.LEFT));
|
||||
var link2 = port3.link(node2.getPort(PortModelAlignment.RIGHT));
|
||||
|
||||
var node4 = new DefaultNodeModel('Node 4', 'rgb(0,192,255)');
|
||||
var port4 = node4.addOutPort('Out');
|
||||
node4.setPosition(200, 10);
|
||||
|
||||
var link3 = port4.link(node2.getPort(PortModelAlignment.TOP));
|
||||
|
||||
var node5 = new DefaultNodeModel('Node 5', 'mediumpurple');
|
||||
var port5 = node5.addInPort('In');
|
||||
node5.setPosition(400, 300);
|
||||
|
||||
var link4 = port5.link(node2.getPort(PortModelAlignment.BOTTOM));
|
||||
|
||||
//4) add the models to the root graph
|
||||
model.addAll(node1, node2, node3, link1, link2, node4, link3, link4, node5);
|
||||
|
||||
//5) load model into engine
|
||||
engine.setModel(model);
|
||||
|
||||
//6) render the diagram!
|
||||
return (
|
||||
<DemoCanvasWidget>
|
||||
<CanvasWidget engine={engine} />
|
||||
</DemoCanvasWidget>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
import * as React from 'react';
|
||||
import createEngine, { DiagramModel, DefaultNodeModel, DefaultLinkModel } from '@projectstorm/react-diagrams';
|
||||
import { CanvasWidget, DeleteItemsAction } from '@projectstorm/react-canvas-core';
|
||||
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';
|
||||
|
||||
export default () => {
|
||||
// create an engine without registering DeleteItemsAction
|
||||
const engine = createEngine({ registerDefaultDeleteItemsAction: false });
|
||||
const model = new DiagramModel();
|
||||
|
||||
const node1 = new DefaultNodeModel({ name: 'Node 1', color: 'rgb(0,192,255)' });
|
||||
node1.setPosition(100, 100);
|
||||
const port1 = node1.addOutPort('Out');
|
||||
|
||||
const node2 = new DefaultNodeModel('Node 2', 'rgb(192,255,0)');
|
||||
const port2 = node2.addInPort('In');
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
const link1 = port1.link<DefaultLinkModel>(port2);
|
||||
link1.getOptions().testName = 'Test';
|
||||
link1.addLabel('Hello World!');
|
||||
|
||||
model.addAll(node1, node2, link1);
|
||||
|
||||
engine.setModel(model);
|
||||
|
||||
// register an DeleteItemsAction with custom keyCodes (in this case, only Delete key)
|
||||
engine.getActionEventBus().registerAction(new DeleteItemsAction({ keyCodes: [46] }));
|
||||
|
||||
return (
|
||||
<DemoCanvasWidget>
|
||||
<CanvasWidget engine={engine} />
|
||||
</DemoCanvasWidget>
|
||||
);
|
||||
};
|
||||
131
packages/diagrams-demo-gallery/demos/demo-dagre/index.tsx
Normal file
@@ -0,0 +1,131 @@
|
||||
import createEngine, {
|
||||
DiagramModel,
|
||||
DefaultNodeModel,
|
||||
DefaultPortModel,
|
||||
NodeModel,
|
||||
DagreEngine,
|
||||
DiagramEngine,
|
||||
PathFindingLinkFactory
|
||||
} from '@projectstorm/react-diagrams';
|
||||
import * as React from 'react';
|
||||
import { DemoButton, DemoWorkspaceWidget } from '../helpers/DemoWorkspaceWidget';
|
||||
import { CanvasWidget } from '@projectstorm/react-canvas-core';
|
||||
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';
|
||||
|
||||
function createNode(name): any {
|
||||
return new DefaultNodeModel(name, 'rgb(0,192,255)');
|
||||
}
|
||||
|
||||
let count = 0;
|
||||
|
||||
function connectNodes(nodeFrom, nodeTo, engine: DiagramEngine) {
|
||||
//just to get id-like structure
|
||||
count++;
|
||||
const portOut = nodeFrom.addPort(new DefaultPortModel(true, `${nodeFrom.name}-out-${count}`, 'Out'));
|
||||
const portTo = nodeTo.addPort(new DefaultPortModel(false, `${nodeFrom.name}-to-${count}`, 'IN'));
|
||||
return portOut.link(portTo);
|
||||
|
||||
// ################# UNCOMMENT THIS LINE FOR PATH FINDING #############################
|
||||
// return portOut.link(portTo, engine.getLinkFactories().getFactory(PathFindingLinkFactory.NAME));
|
||||
// #####################################################################################
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests auto distribution
|
||||
*/
|
||||
class DemoWidget extends React.Component<{ model: DiagramModel; engine: DiagramEngine }, any> {
|
||||
engine: DagreEngine;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.engine = new DagreEngine({
|
||||
graph: {
|
||||
rankdir: 'RL',
|
||||
ranker: 'longest-path',
|
||||
marginx: 25,
|
||||
marginy: 25
|
||||
},
|
||||
includeLinks: true
|
||||
});
|
||||
}
|
||||
|
||||
autoDistribute = () => {
|
||||
this.engine.redistribute(this.props.model);
|
||||
|
||||
// only happens if pathfing is enabled (check line 25)
|
||||
this.reroute();
|
||||
this.props.engine.repaintCanvas();
|
||||
};
|
||||
|
||||
componentDidMount(): void {
|
||||
setTimeout(() => {
|
||||
this.autoDistribute();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
reroute() {
|
||||
this.props.engine
|
||||
.getLinkFactories()
|
||||
.getFactory<PathFindingLinkFactory>(PathFindingLinkFactory.NAME)
|
||||
.calculateRoutingMatrix();
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<DemoWorkspaceWidget buttons={<DemoButton onClick={this.autoDistribute}>Re-distribute</DemoButton>}>
|
||||
<DemoCanvasWidget>
|
||||
<CanvasWidget engine={this.props.engine} />
|
||||
</DemoCanvasWidget>
|
||||
</DemoWorkspaceWidget>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default () => {
|
||||
//1) setup the diagram engine
|
||||
let engine = createEngine();
|
||||
|
||||
//2) setup the diagram model
|
||||
let model = new DiagramModel();
|
||||
|
||||
//3) create a default nodes
|
||||
let nodesFrom: NodeModel[] = [];
|
||||
let nodesTo: NodeModel[] = [];
|
||||
|
||||
nodesFrom.push(createNode('from-1'));
|
||||
nodesFrom.push(createNode('from-2'));
|
||||
nodesFrom.push(createNode('from-3'));
|
||||
|
||||
nodesTo.push(createNode('to-1'));
|
||||
nodesTo.push(createNode('to-2'));
|
||||
nodesTo.push(createNode('to-3'));
|
||||
|
||||
//4) link nodes together
|
||||
let links = nodesFrom.map((node, index) => {
|
||||
return connectNodes(node, nodesTo[index], engine);
|
||||
});
|
||||
|
||||
// more links for more complicated diagram
|
||||
links.push(connectNodes(nodesFrom[0], nodesTo[1], engine));
|
||||
links.push(connectNodes(nodesTo[0], nodesFrom[1], engine));
|
||||
links.push(connectNodes(nodesFrom[1], nodesTo[2], engine));
|
||||
|
||||
// initial random position
|
||||
nodesFrom.forEach((node, index) => {
|
||||
node.setPosition(index * 70, index * 70);
|
||||
model.addNode(node);
|
||||
});
|
||||
|
||||
nodesTo.forEach((node, index) => {
|
||||
node.setPosition(index * 70, 100);
|
||||
model.addNode(node);
|
||||
});
|
||||
|
||||
links.forEach((link) => {
|
||||
model.addLink(link);
|
||||
});
|
||||
|
||||
engine.setModel(model);
|
||||
|
||||
return <DemoWidget model={model} engine={engine} />;
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as SRD from "storm-react-diagrams";
|
||||
import * as SRD from '@projectstorm/react-diagrams';
|
||||
|
||||
/**
|
||||
* @author Dylan Vorster
|
||||
@@ -8,24 +8,22 @@ export class Application {
|
||||
protected diagramEngine: SRD.DiagramEngine;
|
||||
|
||||
constructor() {
|
||||
this.diagramEngine = new SRD.DiagramEngine();
|
||||
this.diagramEngine.installDefaultFactories();
|
||||
|
||||
this.diagramEngine = SRD.default();
|
||||
this.newModel();
|
||||
}
|
||||
|
||||
public newModel() {
|
||||
this.activeModel = new SRD.DiagramModel();
|
||||
this.diagramEngine.setDiagramModel(this.activeModel);
|
||||
this.diagramEngine.setModel(this.activeModel);
|
||||
|
||||
//3-A) create a default node
|
||||
var node1 = new SRD.DefaultNodeModel("Node 1", "rgb(0,192,255)");
|
||||
let port = node1.addOutPort("Out");
|
||||
var node1 = new SRD.DefaultNodeModel('Node 1', 'rgb(0,192,255)');
|
||||
let port = node1.addOutPort('Out');
|
||||
node1.setPosition(100, 100);
|
||||
|
||||
//3-B) create another default node
|
||||
var node2 = new SRD.DefaultNodeModel("Node 2", "rgb(192,255,0)");
|
||||
let port2 = node2.addInPort("In");
|
||||
var node2 = new SRD.DefaultNodeModel('Node 2', 'rgb(192,255,0)');
|
||||
let port2 = node2.addInPort('In');
|
||||
node2.setPosition(400, 100);
|
||||
|
||||
// link the ports
|
||||