Compare commits

...

18 Commits

Author SHA1 Message Date
Dylan Vorster
160b88fccf Merge pull request #990 from projectstorm/changeset-release/master
Version Packages
2023-03-05 10:56:47 -07:00
github-actions[bot]
80cd9c9306 Version Packages 2023-03-05 17:56:31 +00:00
Dylan Vorster
2de55fdf68 Merge pull request #989 from projectstorm/sources
inline sources in source map
2023-03-05 10:55:51 -07:00
Dylan Vorster
b8a4cbdf1a changeset 2023-03-05 10:54:52 -07:00
Dylan Vorster
76a2659948 inline sources 2023-03-05 10:53:27 -07:00
Dylan Vorster
63e33c07d8 Merge pull request #981 from projectstorm/changeset-release/master
Version Packages
2023-01-24 20:25:08 -07:00
github-actions[bot]
70b17a749c Version Packages 2023-01-25 00:17:49 +00:00
Dylan Vorster
4ccc5d58f3 Merge pull request #980 from projectstorm/features
Some Features and fixes
2023-01-24 17:17:09 -07:00
Dylan Vorster
fb7d646bde prettyier and changset 2023-01-24 17:14:38 -07:00
Dylan Vorster
e0d21f1435 pretty and changeset 2023-01-24 17:09:35 -07:00
Dylan Vorster
6ed1e0f89d Merge branch 'features' of github.com:projectstorm/react-diagrams into features 2023-01-24 17:08:12 -07:00
Dylan Vorster
7da7fa4cc9 merge 2023-01-24 17:07:59 -07:00
Dylan Vorster
ed7988f722 Merge branch 'h0111in-Reroute-(redistribute)-links-only,-based-on-current-nodes-positions-#731' into features 2023-01-24 17:06:30 -07:00
Dylan Vorster
e6b86321e2 Merge branch 'Reroute-(redistribute)-links-only,-based-on-current-nodes-positions-#731' of https://github.com/h0111in/react-diagrams into h0111in-Reroute-(redistribute)-links-only,-based-on-current-nodes-positions-#731 2023-01-24 17:00:47 -07:00
Dylan Vorster
17bb78b130 Merge pull request #939 from ToTheHit/update_default_link_widget
Remove hardcode for PointModel in DefaultLinkWidget.tsx
2023-01-24 16:56:27 -07:00
Dmitry Ushakov
77011af27a Remove hardcode for PointModel in DefaultLinkWidget.tsx 2022-05-04 18:07:31 +03:00
Hosein Nourani
580a26c73d miners 2020-10-28 17:52:26 -04:00
Hosein Nourani
4c03583d91 auto-redistribute-without-nodes 2020-10-13 04:41:41 -04:00
21 changed files with 345 additions and 21 deletions

View File

@@ -1,7 +1,6 @@
{
"semi": true,
"singleQuote": true,
"jsxBracketSameLine": true,
"useTabs": true,
"printWidth": 120,
"trailingComma": "none"

View File

@@ -1,5 +1,32 @@
# @projectstorm/react-diagrams-gallery
## 7.1.1
### Patch Changes
- b8a4cbd: Inline sources in sourcemap
- Updated dependencies [b8a4cbd]
- @projectstorm/react-canvas-core@7.0.1
- @projectstorm/react-diagrams@7.0.2
- @projectstorm/react-diagrams-core@7.0.1
- @projectstorm/react-diagrams-defaults@7.1.1
## 7.1.0
### Minor Changes
- e0d21f1: - [feature] new ability to refresh links in auto distribute system [PR 756](https://github.com/projectstorm/react-diagrams/pull/756)
- [fix] Default link now uses the correct method for creating a point allowing this to be overridden [PR 939](https://github.com/projectstorm/react-diagrams/pull/939)
Big thanks to @ToTheHit and @h0111in for your help on these, even though its very delayed on my part :)
### Patch Changes
- Updated dependencies [e0d21f1]
- @projectstorm/react-diagrams-defaults@7.1.0
- @projectstorm/react-diagrams@7.0.1
## 7.0.0
### Major Changes

View File

@@ -45,7 +45,8 @@ class DemoWidget extends React.Component<{ model: DiagramModel; engine: DiagramE
marginx: 25,
marginy: 25
},
includeLinks: true
includeLinks: true,
nodeMargin: 25
});
}
@@ -57,6 +58,13 @@ class DemoWidget extends React.Component<{ model: DiagramModel; engine: DiagramE
this.props.engine.repaintCanvas();
};
autoRefreshLinks = () => {
this.engine.refreshLinks(this.props.model);
// only happens if pathfing is enabled (check line 25)
this.reroute();
this.props.engine.repaintCanvas();
};
componentDidMount(): void {
setTimeout(() => {
this.autoDistribute();
@@ -72,7 +80,14 @@ class DemoWidget extends React.Component<{ model: DiagramModel; engine: DiagramE
render() {
return (
<DemoWorkspaceWidget buttons={<DemoButton onClick={this.autoDistribute}>Re-distribute</DemoButton>}>
<DemoWorkspaceWidget
buttons={
<div>
<DemoButton onClick={this.autoDistribute}>Re-distribute</DemoButton>
<DemoButton onClick={this.autoRefreshLinks}>Refresh Links</DemoButton>
</div>
}
>
<DemoCanvasWidget>
<CanvasWidget engine={this.props.engine} />
</DemoCanvasWidget>
@@ -106,9 +121,11 @@ export default () => {
});
// 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));
links.push(connectNodes(nodesTo[0], nodesTo[1], engine));
links.push(connectNodes(nodesTo[1], nodesTo[2], engine));
links.push(connectNodes(nodesTo[0], nodesTo[2], engine));
links.push(connectNodes(nodesFrom[0], nodesFrom[2], engine));
links.push(connectNodes(nodesFrom[0], nodesTo[2], engine));
// initial random position
nodesFrom.forEach((node, index) => {

View File

@@ -1,6 +1,6 @@
{
"name": "@projectstorm/react-diagrams-gallery",
"version": "7.0.0",
"version": "7.1.1",
"author": "dylanvorster",
"license": "MIT",
"private": true,

View File

@@ -1,5 +1,19 @@
# @projectstorm/react-diagrams-demo
## 7.0.2
### Patch Changes
- b8a4cbd: Inline sources in sourcemap
- Updated dependencies [b8a4cbd]
- @projectstorm/react-diagrams@7.0.2
## 7.0.1
### Patch Changes
- @projectstorm/react-diagrams@7.0.1
## 7.0.0
### Major Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@projectstorm/react-diagrams-demo",
"version": "7.0.0",
"version": "7.0.2",
"author": "dylanvorster",
"license": "MIT",
"private": true,

View File

@@ -1,5 +1,11 @@
# @projectstorm/geometry
## 7.0.1
### Patch Changes
- b8a4cbd: Inline sources in sourcemap
## 7.0.0
### Major Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@projectstorm/geometry",
"version": "7.0.0",
"version": "7.0.1",
"author": "dylanvorster",
"license": "MIT",
"repository": {

View File

@@ -1,5 +1,13 @@
# @projectstorm/react-canvas-core
## 7.0.1
### Patch Changes
- b8a4cbd: Inline sources in sourcemap
- Updated dependencies [b8a4cbd]
- @projectstorm/geometry@7.0.1
## 7.0.0
### Major Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@projectstorm/react-canvas-core",
"version": "7.0.0",
"version": "7.0.1",
"author": "dylanvorster",
"license": "MIT",
"repository": {

View File

@@ -1,5 +1,14 @@
# Changelog
## 7.0.1
### Patch Changes
- b8a4cbd: Inline sources in sourcemap
- Updated dependencies [b8a4cbd]
- @projectstorm/geometry@7.0.1
- @projectstorm/react-canvas-core@7.0.1
## 7.0.0
### Major Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@projectstorm/react-diagrams-core",
"version": "7.0.0",
"version": "7.0.1",
"author": "dylanvorster",
"license": "MIT",
"repository": {

View File

@@ -1,5 +1,25 @@
# @projectstorm/react-diagrams-defaults
## 7.1.1
### Patch Changes
- b8a4cbd: Inline sources in sourcemap
- Updated dependencies [b8a4cbd]
- @projectstorm/geometry@7.0.1
- @projectstorm/react-canvas-core@7.0.1
- @projectstorm/react-diagrams-core@7.0.1
## 7.1.0
### Minor Changes
- e0d21f1: - [feature] new ability to refresh links in auto distribute system [PR 756](https://github.com/projectstorm/react-diagrams/pull/756)
- [fix] Default link now uses the correct method for creating a point allowing this to be overridden [PR 939](https://github.com/projectstorm/react-diagrams/pull/939)
Big thanks to @ToTheHit and @h0111in for your help on these, even though its very delayed on my part :)
## 7.0.0
### Major Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@projectstorm/react-diagrams-defaults",
"version": "7.0.0",
"version": "7.1.1",
"author": "dylanvorster",
"license": "MIT",
"repository": {

View File

@@ -58,11 +58,8 @@ export class DefaultLinkWidget extends React.Component<DefaultLinkProps, Default
!this.props.link.isLocked() &&
this.props.link.getPoints().length - 1 <= this.props.diagramEngine.getMaxNumberPointsPerLink()
) {
const point = new PointModel({
link: this.props.link,
position: this.props.diagramEngine.getRelativeMousePoint(event)
});
this.props.link.addPoint(point, index);
const position = this.props.diagramEngine.getRelativeMousePoint(event);
const point = this.props.link.point(position.x, position.y, index);
event.persist();
event.stopPropagation();
this.forceUpdate(() => {

View File

@@ -1,5 +1,31 @@
# @projectstorm/react-diagrams-routing
## 7.1.1
### Patch Changes
- b8a4cbd: Inline sources in sourcemap
- Updated dependencies [b8a4cbd]
- @projectstorm/geometry@7.0.1
- @projectstorm/react-canvas-core@7.0.1
- @projectstorm/react-diagrams-core@7.0.1
- @projectstorm/react-diagrams-defaults@7.1.1
## 7.1.0
### Minor Changes
- e0d21f1: - [feature] new ability to refresh links in auto distribute system [PR 756](https://github.com/projectstorm/react-diagrams/pull/756)
- [fix] Default link now uses the correct method for creating a point allowing this to be overridden [PR 939](https://github.com/projectstorm/react-diagrams/pull/939)
Big thanks to @ToTheHit and @h0111in for your help on these, even though its very delayed on my part :)
### Patch Changes
- Updated dependencies [e0d21f1]
- @projectstorm/react-diagrams-defaults@7.1.0
## 7.0.0
### Major Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@projectstorm/react-diagrams-routing",
"version": "7.0.0",
"version": "7.1.1",
"author": "dylanvorster",
"license": "MIT",
"repository": {

View File

@@ -1,15 +1,16 @@
import { DiagramModel, PointModel } from '@projectstorm/react-diagrams-core';
import * as dagre from 'dagre';
import * as _ from 'lodash';
import { GraphLabel } from 'dagre';
import * as _ from 'lodash';
import { Point } from '@projectstorm/geometry';
export interface DagreEngineOptions {
graph?: GraphLabel;
/**
* Will also layout links
* Will also re-layout links
*/
includeLinks?: boolean;
nodeMargin?: number;
}
export class DagreEngine {
@@ -68,4 +69,184 @@ export class DagreEngine {
});
}
}
/**
* TODO cleanup this method into smaller methods
*/
public refreshLinks(diagram: DiagramModel) {
const { nodeMargin } = this.options;
const nodes = diagram.getNodes();
const links = diagram.getLinks();
let maxChunkRowIndex = -1;
// build the chunk matrix
const chunks: { [id: number]: { [id: number]: boolean } } = {}; // true: occupied, false: blank
const NodeXColumnIndexDictionary: { [id: number]: number } = {};
let verticalLines: number[] = [];
_.forEach(nodes, (node) => {
// find vertical lines. vertical lines go through maximum number of nodes located under each other.
const nodeColumnCenter = node.getX() + node.width / 2;
if (
_.every(verticalLines, (vLine) => {
return Math.abs(nodeColumnCenter - vLine) > nodeMargin;
})
) {
verticalLines.push(nodeColumnCenter);
}
});
// sort chunk columns
verticalLines = verticalLines.sort((a, b) => a - b);
_.forEach(verticalLines, (line, index) => {
chunks[index] = {};
chunks[index + 0.5] = {};
});
// set occupied chunks
_.forEach(nodes, (node) => {
const nodeColumnCenter = node.getX() + node.width / 2;
const startChunkIndex = Math.floor(node.getY() / nodeMargin);
const endChunkIndex = Math.floor((node.getY() + node.height) / nodeMargin);
// find max ChunkRowIndex
if (endChunkIndex > maxChunkRowIndex) maxChunkRowIndex = endChunkIndex;
const nodeColumnIndex = _.findIndex(verticalLines, (vLine) => {
return Math.abs(nodeColumnCenter - vLine) <= nodeMargin;
});
_.forEach(_.range(startChunkIndex, endChunkIndex + 1), (chunkIndex) => {
chunks[nodeColumnIndex][chunkIndex] = true;
});
NodeXColumnIndexDictionary[node.getX()] = nodeColumnIndex;
});
// sort links based on their distances
const edges = _.map(links, (link) => {
if (link.getSourcePort() && link.getTargetPort()) {
const source = link.getSourcePort().getNode();
const target = link.getTargetPort().getNode();
const sourceIndex = NodeXColumnIndexDictionary[source.getX()];
const targetIndex = NodeXColumnIndexDictionary[target.getX()];
return sourceIndex > targetIndex
? {
link,
sourceIndex,
sourceY: source.getY() + source.height / 2,
source,
targetIndex,
targetY: target.getY() + source.height / 2,
target
}
: {
link,
sourceIndex: targetIndex,
sourceY: target.getY() + target.height / 2,
source: target,
targetIndex: sourceIndex,
targetY: source.getY() + source.height / 2,
target: source
};
}
});
const sortedEdges = _.sortBy(edges, (link) => {
return Math.abs(link.targetIndex - link.sourceIndex);
});
// set link points
if (this.options.includeLinks) {
_.forEach(sortedEdges, (edge) => {
const link = diagram.getLink(edge.link.getID());
// re-draw
if (Math.abs(edge.sourceIndex - edge.targetIndex) > 1) {
// get the length of link in column
const columns = _.range(edge.sourceIndex - 1, edge.targetIndex);
const chunkIndex = Math.floor(edge.sourceY / nodeMargin);
const targetChunkIndex = Math.floor(edge.targetY / nodeMargin);
// check upper paths
let northCost = 1;
let aboveRowIndex = chunkIndex;
for (; aboveRowIndex >= 0; aboveRowIndex--, northCost++) {
if (
_.every(columns, (columnIndex) => {
return !(
chunks[columnIndex][aboveRowIndex] ||
chunks[columnIndex + 0.5][aboveRowIndex] ||
chunks[columnIndex - 0.5][aboveRowIndex]
);
})
) {
break;
}
}
// check lower paths
let southCost = 0;
let belowRowIndex = chunkIndex;
for (; belowRowIndex <= maxChunkRowIndex; belowRowIndex++, southCost++) {
if (
_.every(columns, (columnIndex) => {
return !(
chunks[columnIndex][belowRowIndex] ||
chunks[columnIndex + 0.5][belowRowIndex] ||
chunks[columnIndex - 0.5][belowRowIndex]
);
})
) {
break;
}
}
// pick the cheapest path
const pathRowIndex =
southCost + (belowRowIndex - targetChunkIndex) < northCost + (targetChunkIndex - aboveRowIndex)
? belowRowIndex + 1
: aboveRowIndex - 1;
// Finally update the link points
const points = [link.getFirstPoint()];
points.push(
new PointModel({
link: link,
position: new Point(
(verticalLines[columns[0]] + verticalLines[columns[0] + 1]) / 2,
(pathRowIndex + 0.5) * nodeMargin
)
})
);
_.forEach(columns, (column) => {
points.push(
new PointModel({
link: link,
position: new Point(verticalLines[column], (pathRowIndex + 0.5) * nodeMargin)
})
);
points.push(
new PointModel({
link: link,
position: new Point(
(verticalLines[column] + verticalLines[column - 1]) / 2,
(pathRowIndex + 0.5) * nodeMargin
)
})
);
chunks[column][pathRowIndex] = true;
chunks[column][pathRowIndex + 1] = true;
chunks[column + 0.5][pathRowIndex] = true;
chunks[column + 0.5][pathRowIndex + 1] = true;
});
link.setPoints(points.concat(link.getLastPoint()));
} else {
// refresh
link.setPoints([link.getFirstPoint(), link.getLastPoint()]);
const columnIndex = (edge.sourceIndex + edge.targetIndex) / 2;
if (!chunks[columnIndex]) {
chunks[columnIndex] = {};
}
const rowIndex = Math.floor((edge.sourceY + edge.targetY) / 2 / nodeMargin);
chunks[columnIndex][rowIndex] = true;
chunks[columnIndex][rowIndex + 1] = true;
}
});
}
}
}

View File

@@ -1,5 +1,24 @@
# @projectstorm/react-diagrams
## 7.0.2
### Patch Changes
- b8a4cbd: Inline sources in sourcemap
- Updated dependencies [b8a4cbd]
- @projectstorm/react-canvas-core@7.0.1
- @projectstorm/react-diagrams-core@7.0.1
- @projectstorm/react-diagrams-defaults@7.1.1
- @projectstorm/react-diagrams-routing@7.1.1
## 7.0.1
### Patch Changes
- Updated dependencies [e0d21f1]
- @projectstorm/react-diagrams-defaults@7.1.0
- @projectstorm/react-diagrams-routing@7.1.0
## 7.0.0
### Major Changes

View File

@@ -1,6 +1,6 @@
{
"name": "@projectstorm/react-diagrams",
"version": "7.0.0",
"version": "7.0.2",
"author": "dylanvorster",
"license": "MIT",
"repository": {

View File

@@ -7,6 +7,7 @@
"incremental": true,
"strictNullChecks": false,
"sourceMap": true,
"inlineSources": true,
"skipLibCheck": true,
"jsx": "react",
"target": "ES6",