@@ -81,7 +81,7 @@ export class OneToManyLinkModel extends RightAngleLinkModel {
81
81
data : this . getData ( ) ,
82
82
} ;
83
83
}
84
-
84
+
85
85
setPointType ( nodesDict ) {
86
86
let data = this . getData ( ) ;
87
87
let target = nodesDict [ data [ 'local_table_uid' ] ] . getData ( ) ;
@@ -97,6 +97,18 @@ export class OneToManyLinkModel extends RightAngleLinkModel {
97
97
getPointType ( ) {
98
98
return this . _linkPointType ;
99
99
}
100
+
101
+ setFirstAndLastPathsDirection ( ) {
102
+ let points = this . getPoints ( ) ;
103
+ if ( points . length > 2 ) {
104
+ super . setFirstAndLastPathsDirection ( ) ;
105
+ } else {
106
+ let dx = Math . abs ( points [ 1 ] . getX ( ) - points [ 0 ] . getX ( ) ) ;
107
+ let dy = Math . abs ( points [ 1 ] . getY ( ) - points [ 0 ] . getY ( ) ) ;
108
+ this . _firstPathXdirection = dx > dy ;
109
+ this . _lastPathXdirection = dx > dy ;
110
+ }
111
+ }
100
112
}
101
113
102
114
const svgLinkSelected = keyframes `
@@ -147,49 +159,33 @@ ChenNotation.propTypes = {
147
159
type : PropTypes . string ,
148
160
} ;
149
161
150
- function CustomLinkEndWidget ( props ) {
151
- const { point, rotation, tx, ty, type } = props ;
152
-
162
+ function NotationForType ( { itype, width, rotation} ) {
153
163
const settings = useContext ( ERDCanvasSettings ) ;
154
164
155
- const svgForType = ( itype ) => {
156
- if ( settings . cardinality_notation == 'chen' ) {
157
- return < ChenNotation rotation = { rotation } type = { itype } /> ;
158
- }
159
- if ( itype == 'many' ) {
160
- return (
161
- < >
162
- < circle className = { [ 'OneToMany-svgLink' , 'OneToMany-svgLinkCircle' ] . join ( ' ' ) } cx = "0" cy = "16" r = { props . width * 2.5 } strokeWidth = { props . width } />
163
- < polyline className = 'OneToMany-svgLink' points = "-8,0 0,15 0,0 0,30 0,15 8,0" fill = "none" strokeWidth = { props . width } />
164
- </ >
165
- ) ;
166
- } else if ( itype == 'one' ) {
167
- return (
168
- < polyline className = 'OneToMany-svgLink' points = "-8,15 0,15 0,0 0,30 0,15 8,15" fill = "none" strokeWidth = { props . width } />
169
- ) ;
170
- }
171
- } ;
172
-
173
- return (
174
- < g transform = { 'translate(' + point . getPosition ( ) . x + ', ' + point . getPosition ( ) . y + ')' } >
175
- < g transform = { 'translate(' + tx + ',' + ty + ')' } >
176
- < g transform = { 'rotate(' + rotation + ')' } >
177
- { svgForType ( type ) }
178
- </ g >
179
- </ g >
180
- </ g >
181
- ) ;
165
+ if ( settings . cardinality_notation == 'chen' ) {
166
+ return < ChenNotation rotation = { rotation } type = { itype } /> ;
167
+ }
168
+ if ( itype == 'many' ) {
169
+ return (
170
+ < >
171
+ < circle className = { [ 'OneToMany-svgLink' , 'OneToMany-svgLinkCircle' ] . join ( ' ' ) } cx = "0" cy = "16" r = { width * 2.5 } strokeWidth = { width } />
172
+ < polyline className = 'OneToMany-svgLink' points = "-8,0 0,15 0,0 0,30 0,15 8,0" fill = "none" strokeWidth = { width } />
173
+ </ >
174
+ ) ;
175
+ } else if ( itype == 'one' ) {
176
+ return (
177
+ < polyline className = 'OneToMany-svgLink' points = "-8,15 0,15 0,0 0,30 0,15 8,15" fill = "none" strokeWidth = { width } />
178
+ ) ;
179
+ }
182
180
}
183
181
184
- CustomLinkEndWidget . propTypes = {
185
- point : PropTypes . instanceOf ( PointModel ) . isRequired ,
182
+ NotationForType . propTypes = {
183
+ itype : PropTypes . oneOf ( [ 'many' , 'one' ] ) . isRequired ,
186
184
rotation : PropTypes . number . isRequired ,
187
- tx : PropTypes . number . isRequired ,
188
- ty : PropTypes . number . isRequired ,
189
- type : PropTypes . oneOf ( [ 'many' , 'one' ] ) . isRequired ,
190
185
width : PropTypes . number ,
191
186
} ;
192
187
188
+
193
189
export class OneToManyLinkWidget extends RightAngleLinkWidget {
194
190
constructor ( props ) {
195
191
super ( props ) ;
@@ -255,17 +251,13 @@ export class OneToManyLinkWidget extends RightAngleLinkWidget {
255
251
256
252
generateCustomEndWidget ( { type, point, rotation, tx, ty} ) {
257
253
return (
258
- < CustomLinkEndWidget
259
- key = { point . getID ( ) }
260
- point = { point }
261
- rotation = { rotation }
262
- tx = { tx }
263
- ty = { ty }
264
- type = { type }
265
- colorSelected = { this . props . link . getOptions ( ) . selectedColor }
266
- color = { this . props . link . getOptions ( ) . color }
267
- width = { this . props . width }
268
- />
254
+ < g key = { point . getID ( ) } transform = { 'translate(' + point . getPosition ( ) . x + ', ' + point . getPosition ( ) . y + ')' } >
255
+ < g transform = { 'translate(' + tx + ',' + ty + ')' } >
256
+ < g transform = { 'rotate(' + rotation + ')' } >
257
+ < NotationForType itype = { type } width = { this . props . width } rotation = { rotation } />
258
+ </ g >
259
+ </ g >
260
+ </ g >
269
261
) ;
270
262
}
271
263
@@ -318,6 +310,7 @@ export class OneToManyLinkWidget extends RightAngleLinkWidget {
318
310
}
319
311
320
312
// If there is existing link which has two points add one
313
+ // and the link is horizontal
321
314
if ( points . length === 2 && ! this . state . canDrag && onePoint . point . getX ( ) != manyPoint . point . getX ( ) ) {
322
315
this . props . link . addPoint (
323
316
new PointModel ( {
@@ -357,7 +350,6 @@ export class OneToManyLinkWidget extends RightAngleLinkWidget {
357
350
}
358
351
paths . push ( this . generateCustomEndWidget ( manyPoint ) ) ;
359
352
360
- this . refPaths = [ ] ;
361
353
return < StyledG data-default-link-test = { this . props . link . getOptions ( ) . testName } > { paths } </ StyledG > ;
362
354
}
363
355
}
0 commit comments