Skip to content

Commit e441565

Browse files
committed
patch for center arrow
1 parent b20aee9 commit e441565

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/ArrowFollow.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class ArrowFollow extends Component<IProps, IState> {
113113
const _start: [v: VERTICAL, h: HORIZONTAL] = props.start.corner.split('_') as unknown as [v: VERTICAL, h: HORIZONTAL];
114114
const _end: [v: VERTICAL, h: HORIZONTAL] = props.end.corner.split('_') as unknown as [v: VERTICAL, h: HORIZONTAL];
115115

116-
const { width, height } = this._geCropView(props, _start);
116+
const { width, height } = this._geCropView(props, _start, _end);
117117

118118
const //
119119
aspectRatio: IState['aspectRatio'] = height / width,
@@ -140,9 +140,15 @@ class ArrowFollow extends Component<IProps, IState> {
140140
* @param {IProps} props
141141
* @param {VERTICAL} startVertical
142142
* @param {HORIZONTAL} startHorizontal
143+
* @param {VERTICAL} endVertical
144+
* @param {HORIZONTAL} endHorizontal
143145
* @return {{width:number, height:number}}
144146
*/
145-
private _geCropView = (props: IProps, [startVertical, startHorizontal]: [v: VERTICAL, h: HORIZONTAL]): { width: number; height: number } => {
147+
private _geCropView = (
148+
props: IProps,
149+
[startVertical, startHorizontal]: [v: VERTICAL, h: HORIZONTAL],
150+
[endVertical, endHorizontal]: [v: VERTICAL, h: HORIZONTAL]
151+
): { width: number; height: number } => {
146152
const size = ((1000 / props.width) * (props.size ?? 12)) / 2;
147153
const triangleWidth = ((size * 3) / 1000) * props.width;
148154
const triangleWidthMiddle = triangleWidth / 2;
@@ -171,10 +177,18 @@ class ArrowFollow extends Component<IProps, IState> {
171177
}
172178
}
173179
} else {
174-
if (props.start.direction === DIRECTION.HORIZONTAL) {
175-
dimensionsView.height += triangleWidthMiddle;
180+
if (startVertical === endVertical || startHorizontal === endHorizontal) {
181+
if (props.start.direction === DIRECTION.HORIZONTAL) {
182+
dimensionsView.height += triangleWidthMiddle;
183+
} else {
184+
dimensionsView.width += triangleWidthMiddle;
185+
}
176186
} else {
177-
dimensionsView.width += triangleWidthMiddle;
187+
if (props.start.direction === DIRECTION.HORIZONTAL) {
188+
dimensionsView.height += triangleWidthMiddle + self / 2;
189+
} else {
190+
dimensionsView.width += triangleWidthMiddle + self / 2;
191+
}
178192
}
179193
}
180194

@@ -225,7 +239,7 @@ class ArrowFollow extends Component<IProps, IState> {
225239
margins.push({ left: -self });
226240
}
227241
if (startVertical === VERTICAL.TOP) {
228-
margins.push({ top: -self });
242+
// margins.push({ top: -self });
229243
} else {
230244
margins.push({ top: -triangleWidthMiddle });
231245
}

0 commit comments

Comments
 (0)