Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the demos #1029

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spicy-falcons-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@projectstorm/react-diagrams-gallery': patch
---

Fixed the demos
54 changes: 52 additions & 2 deletions diagrams-demo-gallery/demos/demo-custom-link2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import * as React from 'react';
import { CanvasWidget } from '@projectstorm/react-canvas-core';
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';
import { MouseEvent } from 'react';
import { DefaultLinkPointWidget, DefaultLinkSegmentWidget } from '@projectstorm/react-diagrams-defaults/dist';
import { DiagramEngine } from '@projectstorm/react-diagrams-core/dist';

export class AdvancedLinkModel extends DefaultLinkModel {
constructor() {
Expand Down Expand Up @@ -56,7 +58,56 @@ const CustomLinkArrowWidget = (props) => {
);
};

export class AdvancedLinkWidget extends DefaultLinkWidget {
export interface AdvancedLinkWWidgetProps {
link: DefaultLinkModel;
diagramEngine: DiagramEngine;
pointAdded?: (point: PointModel, event: MouseEvent) => any;
renderPoints?: boolean;
selected?: (event: MouseEvent) => any;
}

export class AdvancedLinkWidget extends React.Component<AdvancedLinkWWidgetProps> {
generatePoint = (point: PointModel): JSX.Element => {
return (
<DefaultLinkPointWidget
key={point.getID()}
point={point as any}
colorSelected={this.props.link.getOptions().selectedColor ?? ''}
color={this.props.link.getOptions().color}
/>
);
};

generateLink = (path: string, extraProps: any, id: string | number): JSX.Element => {
return (
<DefaultLinkSegmentWidget
key={`link-${id}`}
path={path}
diagramEngine={this.props.diagramEngine}
factory={this.props.diagramEngine.getFactoryForLink(this.props.link)}
link={this.props.link}
extras={extraProps}
/>
);
};

addPointToLink = (event: MouseEvent, index: number) => {
if (
!event.shiftKey &&
!this.props.link.isLocked() &&
this.props.link.getPoints().length - 1 <= this.props.diagramEngine.getMaxNumberPointsPerLink()
) {
const position = this.props.diagramEngine.getRelativeMousePoint(event);
const point = this.props.link.point(position.x, position.y, index);
event.persist();
event.stopPropagation();
this.props.diagramEngine.getActionEventBus().fireAction({
event,
model: point
});
}
};

generateArrow(point: PointModel, previousPoint: PointModel): JSX.Element {
return (
<CustomLinkArrowWidget
Expand All @@ -73,7 +124,6 @@ export class AdvancedLinkWidget extends DefaultLinkWidget {
//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++) {
Expand Down
9 changes: 3 additions & 6 deletions diagrams-demo-gallery/demos/demo-dagre/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ function autoRefreshLinks(engine: DiagramEngine) {
}

function reroute(engine: DiagramEngine) {
engine
.getLinkFactories()
.getFactory<PathFindingLinkFactory>(PathFindingLinkFactory.NAME)
.calculateRoutingMatrix();
engine.getLinkFactories().getFactory<PathFindingLinkFactory>(PathFindingLinkFactory.NAME).calculateRoutingMatrix();
}

function DemoWidget(props) {
Expand All @@ -83,11 +80,11 @@ function DemoWidget(props) {

const redistribute = () => {
autoDistribute(engine);
}
};

const refreshLinks = () => {
autoRefreshLinks(engine);
}
};

return (
<DemoWorkspaceWidget
Expand Down
Loading