-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add demo diamod node model and factory
- Loading branch information
Showing
7 changed files
with
195 additions
and
17 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
15 changes: 15 additions & 0 deletions
15
quake_webapp/quake-board/src/components/SimplePortFactory.ts
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,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: any): PortModel { | ||
return this.cb(event.initialConfig); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
quake_webapp/quake-board/src/components/base-model/DiamondNodeFactory.tsx
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,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: any): JSX.Element { | ||
return <DiamondNodeWidget engine={this.engine} size={50} node={event.model} />; | ||
} | ||
|
||
generateModel(event: any) { | ||
return new DiamondNodeModel(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
quake_webapp/quake-board/src/components/base-model/DiamondNodeModel.ts
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,18 @@ | ||
import {NodeModel, NodeModelGenerics, PortModelAlignment} from '@projectstorm/react-diagrams'; | ||
import {DiamondPortModel} from './DiamondPortModel'; | ||
|
||
export interface DiamondNodeModelGenerics extends NodeModelGenerics { | ||
PORT: DiamondPortModel; | ||
} | ||
|
||
export class DiamondNodeModel extends NodeModel<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)); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
quake_webapp/quake-board/src/components/base-model/DiamondNodeWidget.tsx
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,99 @@ | ||
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) as any} | ||
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) as any} | ||
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) as any} | ||
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) as any} | ||
engine={this.props.engine}> | ||
<S.Port /> | ||
</PortWidget> | ||
</div> | ||
); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
quake_webapp/quake-board/src/components/base-model/DiamondPortModel.ts
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,15 @@ | ||
import {DefaultLinkModel, LinkModel, PortModel, 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(); | ||
} | ||
} |