Skip to content

Commit dded1a8

Browse files
committed
add ratio resize
1 parent c3144a1 commit dded1a8

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"import/imports-first": 0,
2020
"import/no-extraneous-dependencies": 0,
2121
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
22-
"camelcase": 0
22+
"camelcase": 0,
23+
"no-mixed-operators": 0,
2324
},
2425
"globals": {
2526
"db": true,

src/Dragresize.jsx

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ class Dragresize extends Component {
7979
cy = y;
8080
// ay = e.pageY;
8181
}
82+
83+
if (isRatio) {
84+
const bxmm = this.limitScope({ ax, ay, bx, cy }).bx;
85+
cy = ay + (bxmm - ax) * ratio;
86+
const cymm = this.limitScope({ ax, ay, bx, cy }).cy;
87+
bx = (cymm - ay) / ratio + ax;
88+
}
8289
break;
8390
case 'tl':
8491
diffX = m_x - x;
@@ -96,6 +103,13 @@ class Dragresize extends Component {
96103
ay = y + h;
97104
// cy = e.pageY;
98105
}
106+
107+
if (isRatio) {
108+
const axmm = this.limitScope({ ax, ay, bx, cy }).ax;
109+
ay = cy - (bx - axmm) * ratio;
110+
const aymm = this.limitScope({ ax, ay, bx, cy }).ay;
111+
ax = bx - (cy - aymm) / ratio;
112+
}
99113
break;
100114
case 'tr':
101115
diffX = m_x - (x + w);
@@ -113,6 +127,13 @@ class Dragresize extends Component {
113127
ay = y + h;
114128
// cy = e.pageY;
115129
}
130+
131+
if (isRatio) {
132+
const bxmm = this.limitScope({ ax, ay, bx, cy }).bx;
133+
ay = cy - (bxmm - ax) * ratio;
134+
const aymm = this.limitScope({ ax, ay, bx, cy }).ay;
135+
bx = (cy - aymm) / ratio + ax;
136+
}
116137
break;
117138
case 'bl':
118139
diffX = m_x - x;
@@ -130,6 +151,12 @@ class Dragresize extends Component {
130151
cy = y;
131152
// ay = e.pageY;
132153
}
154+
if (isRatio) {
155+
const axmm = this.limitScope({ ax, ay, bx, cy }).ax;
156+
cy = ay + (bx - axmm) * ratio;
157+
const cymm = this.limitScope({ ax, ay, bx, cy }).cy;
158+
ax = bx - (cymm - ay) / ratio;
159+
}
133160
break;
134161
}
135162
const attr = computeAttr(this.limitScope({ ax, ay, bx, cy }));
@@ -262,11 +289,11 @@ Dragresize.propTypes = {
262289
Dragresize.defaultProps = {
263290
elmX: 10,
264291
elmY: 10,
265-
elmW: 150,
266-
elmH: 100,
292+
elmW: 100,
293+
elmH: 150,
267294
isDrag: true,
268295
isResize: true,
269-
isRatio: false,
296+
isRatio: true,
270297
isChecked: true,
271298
dragScope: {
272299
minLeft: 10,
@@ -277,7 +304,7 @@ Dragresize.defaultProps = {
277304
sizeScope: {
278305
minWidth: 30,
279306
minHeight: 30,
280-
maxWidth: 200,
307+
maxWidth: null,
281308
maxHeight: null,
282309
},
283310
onMouseMove: null,

0 commit comments

Comments
 (0)