-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
AdrySky
committed
Mar 30, 2022
1 parent
a9593bb
commit ac2de62
Showing
3 changed files
with
133 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { DefaultLinkFactory } from '@projectstorm/react-diagrams'; | ||
import * as React from 'react'; | ||
import { CustomLinkModel, TriangleLinkModel } from './CustomLinkModel'; | ||
import styled from '@emotion/styled'; | ||
import { css, keyframes } from '@emotion/react'; | ||
|
||
namespace S { | ||
export const Keyframes = keyframes` | ||
from { | ||
stroke-dashoffset: 24; | ||
} | ||
to { | ||
stroke-dashoffset: 0; | ||
} | ||
`; | ||
|
||
const selected = css` | ||
stroke-dasharray: 10, 2; | ||
animation: ${Keyframes} 1s linear infinite; | ||
`; | ||
|
||
export const Path = styled.path<{ selected: boolean }>` | ||
${(p) => p.selected && selected}; | ||
fill: none; | ||
pointer-events: auto; | ||
`; | ||
} | ||
|
||
export class CustomLinkFactory extends DefaultLinkFactory { | ||
constructor() { | ||
super('custom'); | ||
} | ||
|
||
generateModel(): CustomLinkModel { | ||
return new CustomLinkModel(); | ||
} | ||
|
||
generateLinkSegment(model: CustomLinkModel, selected: boolean, path: string) { | ||
return ( | ||
<S.Path | ||
selected={selected} | ||
stroke={selected ? 'yellow' : model.getOptions().color} | ||
strokeWidth={model.getOptions().width} | ||
d={path} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export class TriangleLinkFactory extends DefaultLinkFactory { | ||
constructor() { | ||
super('triangle'); | ||
} | ||
|
||
generateModel(): TriangleLinkModel { | ||
return new TriangleLinkModel(); | ||
} | ||
|
||
generateLinkSegment(model: TriangleLinkModel, selected: boolean, path: string) { | ||
return ( | ||
<S.Path | ||
selected={!selected} | ||
stroke={!selected ? model.getOptions().selectedColor : 'yellow'} | ||
strokeWidth={model.getOptions().width} | ||
d={path} | ||
/> | ||
); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { DefaultLinkModel } from '@projectstorm/react-diagrams'; | ||
import { CustomPortModel } from '../CustomPortModel'; | ||
|
||
// Custom link | ||
export class CustomLinkModel extends DefaultLinkModel { | ||
constructor() { | ||
super({ | ||
type: 'custom', | ||
width: 3 | ||
}); | ||
} | ||
} | ||
|
||
export class CustomLinkPortModel extends CustomPortModel { | ||
createLinkModel(): CustomLinkModel | null { | ||
return new CustomLinkModel(); | ||
} | ||
} | ||
|
||
// Triangle link | ||
export class TriangleLinkModel extends DefaultLinkModel { | ||
constructor() { | ||
super({ | ||
type: 'triangle', | ||
width: 3 | ||
}); | ||
} | ||
} | ||
|
||
export class TrianglePortModel extends CustomPortModel { | ||
createLinkModel(): TriangleLinkModel | null { | ||
return new TriangleLinkModel(); | ||
} | ||
} | ||
|