Skip to content

Commit 79bdc80

Browse files
authored
Merge pull request #1029 from projectstorm/fix_demos
fix the demos
2 parents e497715 + adb4415 commit 79bdc80

File tree

3 files changed

+60
-8
lines changed

3 files changed

+60
-8
lines changed

.changeset/spicy-falcons-do.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@projectstorm/react-diagrams-gallery': patch
3+
---
4+
5+
Fixed the demos

diagrams-demo-gallery/demos/demo-custom-link2/index.tsx

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import * as React from 'react';
1111
import { CanvasWidget } from '@projectstorm/react-canvas-core';
1212
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';
1313
import { MouseEvent } from 'react';
14+
import { DefaultLinkPointWidget, DefaultLinkSegmentWidget } from '@projectstorm/react-diagrams-defaults/dist';
15+
import { DiagramEngine } from '@projectstorm/react-diagrams-core/dist';
1416

1517
export class AdvancedLinkModel extends DefaultLinkModel {
1618
constructor() {
@@ -56,7 +58,56 @@ const CustomLinkArrowWidget = (props) => {
5658
);
5759
};
5860

59-
export class AdvancedLinkWidget extends DefaultLinkWidget {
61+
export interface AdvancedLinkWWidgetProps {
62+
link: DefaultLinkModel;
63+
diagramEngine: DiagramEngine;
64+
pointAdded?: (point: PointModel, event: MouseEvent) => any;
65+
renderPoints?: boolean;
66+
selected?: (event: MouseEvent) => any;
67+
}
68+
69+
export class AdvancedLinkWidget extends React.Component<AdvancedLinkWWidgetProps> {
70+
generatePoint = (point: PointModel): JSX.Element => {
71+
return (
72+
<DefaultLinkPointWidget
73+
key={point.getID()}
74+
point={point as any}
75+
colorSelected={this.props.link.getOptions().selectedColor ?? ''}
76+
color={this.props.link.getOptions().color}
77+
/>
78+
);
79+
};
80+
81+
generateLink = (path: string, extraProps: any, id: string | number): JSX.Element => {
82+
return (
83+
<DefaultLinkSegmentWidget
84+
key={`link-${id}`}
85+
path={path}
86+
diagramEngine={this.props.diagramEngine}
87+
factory={this.props.diagramEngine.getFactoryForLink(this.props.link)}
88+
link={this.props.link}
89+
extras={extraProps}
90+
/>
91+
);
92+
};
93+
94+
addPointToLink = (event: MouseEvent, index: number) => {
95+
if (
96+
!event.shiftKey &&
97+
!this.props.link.isLocked() &&
98+
this.props.link.getPoints().length - 1 <= this.props.diagramEngine.getMaxNumberPointsPerLink()
99+
) {
100+
const position = this.props.diagramEngine.getRelativeMousePoint(event);
101+
const point = this.props.link.point(position.x, position.y, index);
102+
event.persist();
103+
event.stopPropagation();
104+
this.props.diagramEngine.getActionEventBus().fireAction({
105+
event,
106+
model: point
107+
});
108+
}
109+
};
110+
60111
generateArrow(point: PointModel, previousPoint: PointModel): JSX.Element {
61112
return (
62113
<CustomLinkArrowWidget
@@ -73,7 +124,6 @@ export class AdvancedLinkWidget extends DefaultLinkWidget {
73124
//ensure id is present for all points on the path
74125
var points = this.props.link.getPoints();
75126
var paths = [];
76-
this.refPaths = [];
77127

78128
//draw the multiple anchors and complex line instead
79129
for (let j = 0; j < points.length - 1; j++) {

diagrams-demo-gallery/demos/demo-dagre/index.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ function autoRefreshLinks(engine: DiagramEngine) {
6868
}
6969

7070
function reroute(engine: DiagramEngine) {
71-
engine
72-
.getLinkFactories()
73-
.getFactory<PathFindingLinkFactory>(PathFindingLinkFactory.NAME)
74-
.calculateRoutingMatrix();
71+
engine.getLinkFactories().getFactory<PathFindingLinkFactory>(PathFindingLinkFactory.NAME).calculateRoutingMatrix();
7572
}
7673

7774
function DemoWidget(props) {
@@ -83,11 +80,11 @@ function DemoWidget(props) {
8380

8481
const redistribute = () => {
8582
autoDistribute(engine);
86-
}
83+
};
8784

8885
const refreshLinks = () => {
8986
autoRefreshLinks(engine);
90-
}
87+
};
9188

9289
return (
9390
<DemoWorkspaceWidget

0 commit comments

Comments
 (0)