@@ -5,8 +5,9 @@ import { StoryFn } from "storybook/internal/types";
55
66import { TBlock } from "../../components/canvas/blocks/Block" ;
77import { random } from "../../components/canvas/blocks/generate" ;
8+ import { ConnectionLayer } from "../../components/canvas/layers/connectionLayer/ConnectionLayer" ;
89import { Graph , GraphState , TGraphConfig } from "../../graph" ;
9- import { GraphBlock , GraphCanvas , HookGraphParams , useGraph , useGraphEvent } from "../../react-component" ;
10+ import { GraphBlock , GraphCanvas , HookGraphParams , useGraph , useGraphEvent , useLayer } from "../../react-component" ;
1011import { ECanChangeBlockGeometry } from "../../store/settings" ;
1112import { useFn } from "../../utils/hooks/useFn" ;
1213import { EAnchorType } from "../configurations/definitions" ;
@@ -93,10 +94,50 @@ const graphSizeOptions: RadioButtonOption[] = [
9394 { value : "10000" , content : "10 000" } ,
9495] ;
9596
97+ const createIcon = {
98+ path : "M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" , // Plus icon
99+ fill : "rgba(255, 190, 92, 1)" ,
100+ width : 24 ,
101+ height : 24 ,
102+ viewWidth : 24 ,
103+ viewHeight : 24 ,
104+ } ;
105+
106+ // Icon for connection point
107+ const pointIcon = {
108+ path : "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z" , // Circle icon
109+ fill : "rgba(234, 201, 74, 1)" ,
110+ stroke : "rgba(255, 190, 92, 1)" ,
111+ width : 24 ,
112+ height : 24 ,
113+ viewWidth : 24 ,
114+ viewHeight : 24 ,
115+ } ;
116+
117+ // Function for drawing connection line
118+ const drawLine = ( start , end ) => {
119+ const path = new Path2D ( ) ;
120+ path . moveTo ( start . x , start . y ) ;
121+ path . lineTo ( end . x , end . y ) ;
122+ return {
123+ path,
124+ style : {
125+ color : "rgba(255, 190, 92, 1)" ,
126+ dash : [ 5 , 5 ] , // Dashed line
127+ } ,
128+ } ;
129+ } ;
130+
96131export function GraphPLayground ( ) {
97132 const { graph, setEntities, updateEntities, start } = useGraph ( config ) ;
98133 const editorRef = useRef < ConfigEditorController > ( null ) ;
99134
135+ useLayer ( graph , ConnectionLayer , {
136+ createIcon,
137+ point : pointIcon ,
138+ drawLine,
139+ } ) ;
140+
100141 const updateVisibleConfig = useFn ( ( ) => {
101142 const config = graph . rootStore . getAsConfig ( ) ;
102143 editorRef ?. current . setContent ( {
@@ -154,7 +195,7 @@ export function GraphPLayground() {
154195 }
155196 let block : TBlock ;
156197 const pullSourceAnchor = graph . rootStore . blocksList . getBlockState ( sourceBlockId ) . getAnchorById ( sourceAnchorId ) ;
157- if ( pullSourceAnchor . state . type === EAnchorType . IN ) {
198+ if ( pullSourceAnchor ? .state . type === EAnchorType . IN ) {
158199 block = createActionBlock ( point . x - 126 , point . y - 63 , graph . rootStore . blocksList . $blocksMap . value . size + 1 ) ;
159200 graph . api . addBlock ( block ) ;
160201 graph . api . addConnection ( {
0 commit comments