@pie-element/hotspot 9.3.4-next.0 → 10.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configure/lib/DeleteWidget.js +30 -43
- package/configure/lib/DeleteWidget.js.map +1 -1
- package/configure/lib/button.js +26 -45
- package/configure/lib/button.js.map +1 -1
- package/configure/lib/buttons/circle.js +20 -27
- package/configure/lib/buttons/circle.js.map +1 -1
- package/configure/lib/buttons/polygon.js +26 -33
- package/configure/lib/buttons/polygon.js.map +1 -1
- package/configure/lib/buttons/rectangle.js +26 -33
- package/configure/lib/buttons/rectangle.js.map +1 -1
- package/configure/lib/defaults.js +2 -3
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/hotspot-circle.js +132 -198
- package/configure/lib/hotspot-circle.js.map +1 -1
- package/configure/lib/hotspot-container.js +250 -355
- package/configure/lib/hotspot-container.js.map +1 -1
- package/configure/lib/hotspot-drawable.js +360 -472
- package/configure/lib/hotspot-drawable.js.map +1 -1
- package/configure/lib/hotspot-palette.js +92 -139
- package/configure/lib/hotspot-palette.js.map +1 -1
- package/configure/lib/hotspot-polygon.js +212 -317
- package/configure/lib/hotspot-polygon.js.map +1 -1
- package/configure/lib/hotspot-rectangle.js +128 -192
- package/configure/lib/hotspot-rectangle.js.map +1 -1
- package/configure/lib/icons.js.map +1 -1
- package/configure/lib/image-konva.js +46 -86
- package/configure/lib/image-konva.js.map +1 -1
- package/configure/lib/index.js +162 -222
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/root.js +301 -393
- package/configure/lib/root.js.map +1 -1
- package/configure/lib/shapes/circle.js +69 -101
- package/configure/lib/shapes/circle.js.map +1 -1
- package/configure/lib/shapes/index.js +4 -12
- package/configure/lib/shapes/index.js.map +1 -1
- package/configure/lib/shapes/polygon.js +64 -96
- package/configure/lib/shapes/polygon.js.map +1 -1
- package/configure/lib/shapes/rectagle.js +69 -101
- package/configure/lib/shapes/rectagle.js.map +1 -1
- package/configure/lib/shapes/utils.js +2 -8
- package/configure/lib/shapes/utils.js.map +1 -1
- package/configure/lib/upload-control.js +25 -52
- package/configure/lib/upload-control.js.map +1 -1
- package/configure/lib/utils.js +84 -137
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +11 -10
- package/configure/src/__tests__/hotspot-container.test.js +50 -19
- package/configure/src/__tests__/hotspot-drawable.test.js +55 -34
- package/configure/src/__tests__/index.test.js +167 -5
- package/configure/src/__tests__/root.test.js +89 -63
- package/configure/src/button.jsx +12 -20
- package/configure/src/hotspot-circle.jsx +5 -18
- package/configure/src/hotspot-container.jsx +82 -98
- package/configure/src/hotspot-drawable.jsx +43 -45
- package/configure/src/hotspot-palette.jsx +45 -37
- package/configure/src/hotspot-polygon.jsx +4 -20
- package/configure/src/hotspot-rectangle.jsx +4 -17
- package/configure/src/index.js +12 -2
- package/configure/src/root.jsx +85 -79
- package/configure/src/upload-control.jsx +6 -16
- package/controller/lib/defaults.js +2 -3
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +151 -205
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js +14 -34
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +2 -2
- package/lib/hotspot/circle.js +110 -169
- package/lib/hotspot/circle.js.map +1 -1
- package/lib/hotspot/container.js +174 -260
- package/lib/hotspot/container.js.map +1 -1
- package/lib/hotspot/icons.js.map +1 -1
- package/lib/hotspot/image-konva-tooltip.js +65 -112
- package/lib/hotspot/image-konva-tooltip.js.map +1 -1
- package/lib/hotspot/index.js +135 -198
- package/lib/hotspot/index.js.map +1 -1
- package/lib/hotspot/polygon.js +150 -214
- package/lib/hotspot/polygon.js.map +1 -1
- package/lib/hotspot/rectangle.js +128 -185
- package/lib/hotspot/rectangle.js.map +1 -1
- package/lib/index.js +187 -256
- package/lib/index.js.map +1 -1
- package/lib/session-updater.js +12 -18
- package/lib/session-updater.js.map +1 -1
- package/package.json +14 -11
- package/src/__tests__/container.test.jsx +27 -175
- package/src/__tests__/index.test.js +70 -30
- package/src/hotspot/circle.jsx +2 -13
- package/src/hotspot/container.jsx +35 -50
- package/src/hotspot/index.jsx +16 -28
- package/src/hotspot/polygon.jsx +4 -13
- package/src/hotspot/rectangle.jsx +5 -15
- package/src/index.js +21 -12
- package/configure/src/__tests__/DeleteWidget.test.js +0 -64
- package/configure/src/__tests__/__snapshots__/hotspot-container.test.js.snap +0 -192
- package/configure/src/__tests__/__snapshots__/hotspot-drawable.test.js.snap +0 -562
- package/configure/src/__tests__/__snapshots__/root.test.js.snap +0 -469
- package/src/__tests__/__snapshots__/container.test.jsx.snap +0 -264
- package/src/__tests__/__snapshots__/index.test.js.snap +0 -81
- package/src/__tests__/__snapshots__/polygon.test.jsx.snap +0 -192
- package/src/__tests__/__snapshots__/rectangle.test.jsx.snap +0 -127
- package/src/__tests__/polygon.test.jsx +0 -230
- package/src/__tests__/rectangle.test.jsx +0 -232
|
@@ -1,99 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports
|
|
9
|
-
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
|
|
12
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
-
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
-
|
|
16
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
17
|
-
|
|
18
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
19
|
-
|
|
20
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
21
|
-
|
|
22
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
23
|
-
|
|
7
|
+
exports.default = void 0;
|
|
24
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
25
|
-
|
|
26
9
|
var _react = _interopRequireDefault(require("react"));
|
|
27
|
-
|
|
28
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
29
|
-
|
|
30
11
|
var _reactKonva = require("react-konva");
|
|
31
|
-
|
|
32
|
-
var _index = require("@material-ui/core/styles/index");
|
|
33
|
-
|
|
34
12
|
var _ReactKonvaCore = require("react-konva/lib/ReactKonvaCore");
|
|
35
|
-
|
|
36
13
|
var _DeleteWidget = _interopRequireDefault(require("./DeleteWidget"));
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
45
|
-
|
|
46
|
-
var HOVERED_COLOR = '#00BFFF';
|
|
47
|
-
|
|
48
|
-
var PolComponent = /*#__PURE__*/function (_React$Component) {
|
|
49
|
-
(0, _inherits2["default"])(PolComponent, _React$Component);
|
|
50
|
-
|
|
51
|
-
var _super = _createSuper(PolComponent);
|
|
52
|
-
|
|
53
|
-
function PolComponent() {
|
|
54
|
-
var _this;
|
|
55
|
-
|
|
56
|
-
(0, _classCallCheck2["default"])(this, PolComponent);
|
|
57
|
-
|
|
58
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
59
|
-
args[_key] = arguments[_key];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
63
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getOffset", function (points) {
|
|
64
|
-
var xList = points.map(function (p) {
|
|
65
|
-
return p.x;
|
|
66
|
-
});
|
|
67
|
-
var yList = points.map(function (p) {
|
|
68
|
-
return p.y;
|
|
69
|
-
});
|
|
14
|
+
const HOVERED_COLOR = '#00BFFF';
|
|
15
|
+
class PolComponent extends _react.default.Component {
|
|
16
|
+
constructor(...args) {
|
|
17
|
+
super(...args);
|
|
18
|
+
(0, _defineProperty2.default)(this, "getOffset", points => {
|
|
19
|
+
const xList = points.map(p => p.x);
|
|
20
|
+
const yList = points.map(p => p.y);
|
|
70
21
|
return {
|
|
71
|
-
x: Math.min
|
|
72
|
-
y: Math.max
|
|
22
|
+
x: Math.min(...xList),
|
|
23
|
+
y: Math.max(...yList)
|
|
73
24
|
};
|
|
74
25
|
});
|
|
75
|
-
(0, _defineProperty2
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return points.reduce(
|
|
81
|
-
return [].concat((0, _toConsumableArray2["default"])(acc), [point.x - xOffset, point.y - yOffset]);
|
|
82
|
-
}, []);
|
|
26
|
+
(0, _defineProperty2.default)(this, "serialize", points => {
|
|
27
|
+
const {
|
|
28
|
+
x: xOffset,
|
|
29
|
+
y: yOffset
|
|
30
|
+
} = this.getOffset(points);
|
|
31
|
+
return points.reduce((acc, point) => [...acc, point.x - xOffset, point.y - yOffset], []);
|
|
83
32
|
});
|
|
84
|
-
(0, _defineProperty2
|
|
33
|
+
(0, _defineProperty2.default)(this, "getInitialState", points => {
|
|
85
34
|
if (points.length) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
35
|
+
const {
|
|
36
|
+
x,
|
|
37
|
+
y
|
|
38
|
+
} = this.getOffset(points);
|
|
90
39
|
return {
|
|
91
|
-
x
|
|
92
|
-
y
|
|
93
|
-
points
|
|
40
|
+
x,
|
|
41
|
+
y,
|
|
42
|
+
points
|
|
94
43
|
};
|
|
95
44
|
}
|
|
96
|
-
|
|
97
45
|
return {
|
|
98
46
|
id: '',
|
|
99
47
|
x: 0,
|
|
@@ -101,299 +49,246 @@ var PolComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
101
49
|
points: []
|
|
102
50
|
};
|
|
103
51
|
});
|
|
104
|
-
(0, _defineProperty2
|
|
52
|
+
(0, _defineProperty2.default)(this, "state", {
|
|
105
53
|
hovered: false,
|
|
106
|
-
isDragging: false
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
54
|
+
isDragging: false,
|
|
55
|
+
...this.getInitialState(this.props.points)
|
|
56
|
+
});
|
|
57
|
+
(0, _defineProperty2.default)(this, "handleClick", e => {
|
|
58
|
+
const {
|
|
59
|
+
points
|
|
60
|
+
} = this.props;
|
|
61
|
+
const xList = points.map(p => p.x);
|
|
62
|
+
const yList = points.map(p => p.y);
|
|
63
|
+
const width = Math.max(...xList) - Math.min(...xList);
|
|
64
|
+
const height = Math.max(...yList) - Math.min(...yList);
|
|
65
|
+
const {
|
|
66
|
+
isDrawing,
|
|
67
|
+
onClick,
|
|
68
|
+
id
|
|
69
|
+
} = this.props;
|
|
123
70
|
if (width < 0 && height < 0 && isDrawing) {
|
|
124
71
|
return;
|
|
125
72
|
}
|
|
126
|
-
|
|
127
73
|
if (isDrawing && id === 'newPolygon') {
|
|
128
|
-
|
|
129
|
-
|
|
74
|
+
this.props.addPolygonPoint(e);
|
|
130
75
|
return;
|
|
131
76
|
}
|
|
132
|
-
|
|
133
77
|
e.cancelBubble = true;
|
|
134
78
|
onClick(id);
|
|
135
79
|
});
|
|
136
|
-
(0, _defineProperty2
|
|
137
|
-
|
|
80
|
+
(0, _defineProperty2.default)(this, "handleMouseEnter", () => {
|
|
81
|
+
this.setState({
|
|
138
82
|
hovered: true
|
|
139
83
|
});
|
|
140
|
-
|
|
141
84
|
document.body.style.cursor = 'pointer';
|
|
142
85
|
});
|
|
143
|
-
(0, _defineProperty2
|
|
144
|
-
|
|
86
|
+
(0, _defineProperty2.default)(this, "handleMouseLeave", () => {
|
|
87
|
+
this.setState({
|
|
145
88
|
hovered: false
|
|
146
89
|
});
|
|
147
|
-
|
|
148
90
|
document.body.style.cursor = 'default';
|
|
149
91
|
});
|
|
150
|
-
(0, _defineProperty2
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
var newPoints = points.reduce(function (acc, currentPointCoordinate, index) {
|
|
92
|
+
(0, _defineProperty2.default)(this, "handleOnDragEnd", (e, updateModel = false) => {
|
|
93
|
+
const {
|
|
94
|
+
onDragEnd,
|
|
95
|
+
id
|
|
96
|
+
} = this.props;
|
|
97
|
+
const points = e.target.points() || this.serialize(this.state.points);
|
|
98
|
+
const newPoints = points.reduce((acc, currentPointCoordinate, index) => {
|
|
159
99
|
if (index % 2 === 0 && index + 1 < points.length) {
|
|
160
|
-
return [
|
|
100
|
+
return [...acc, {
|
|
161
101
|
x: currentPointCoordinate + e.target.x(),
|
|
162
102
|
y: points[index + 1] + e.target.y()
|
|
163
|
-
}]
|
|
103
|
+
}];
|
|
164
104
|
}
|
|
165
|
-
|
|
166
105
|
return acc;
|
|
167
106
|
}, []);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}));
|
|
174
|
-
|
|
107
|
+
this.setState({
|
|
108
|
+
points: newPoints,
|
|
109
|
+
...this.getOffset(newPoints),
|
|
110
|
+
isDragging: updateModel ? false : this.state.isDragging
|
|
111
|
+
});
|
|
175
112
|
if (updateModel) {
|
|
176
113
|
onDragEnd(id, {
|
|
177
114
|
points: newPoints
|
|
178
115
|
});
|
|
179
116
|
}
|
|
180
117
|
});
|
|
181
|
-
(0, _defineProperty2
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
118
|
+
(0, _defineProperty2.default)(this, "handleOnDragVertex", (e, changedIndex, updateModel) => {
|
|
119
|
+
const {
|
|
120
|
+
onDragEnd,
|
|
121
|
+
id
|
|
122
|
+
} = this.props;
|
|
123
|
+
const {
|
|
124
|
+
points
|
|
125
|
+
} = this.state;
|
|
126
|
+
const newPoints = points.map((point, index) => index === changedIndex ? {
|
|
127
|
+
x: e.target.x(),
|
|
128
|
+
y: e.target.y()
|
|
129
|
+
} : point);
|
|
130
|
+
this.setState({
|
|
131
|
+
points: newPoints,
|
|
132
|
+
...this.getOffset(newPoints),
|
|
133
|
+
isDragging: updateModel ? false : this.state.isDragging
|
|
191
134
|
});
|
|
192
|
-
|
|
193
|
-
_this.setState(_objectSpread(_objectSpread({
|
|
194
|
-
points: newPoints
|
|
195
|
-
}, _this.getOffset(newPoints)), {}, {
|
|
196
|
-
isDragging: updateModel ? false : _this.state.isDragging
|
|
197
|
-
}));
|
|
198
|
-
|
|
199
135
|
if (updateModel) {
|
|
200
136
|
onDragEnd(id, {
|
|
201
137
|
points: newPoints
|
|
202
138
|
});
|
|
203
139
|
}
|
|
204
140
|
});
|
|
205
|
-
(0, _defineProperty2
|
|
206
|
-
|
|
141
|
+
(0, _defineProperty2.default)(this, "onDragStart", () => {
|
|
142
|
+
this.setState({
|
|
207
143
|
isDragging: true
|
|
208
144
|
});
|
|
209
145
|
});
|
|
210
|
-
(0, _defineProperty2
|
|
211
|
-
|
|
146
|
+
(0, _defineProperty2.default)(this, "handleDelete", id => {
|
|
147
|
+
const {
|
|
148
|
+
onDeleteShape
|
|
149
|
+
} = this.props;
|
|
212
150
|
onDeleteShape(id);
|
|
213
151
|
});
|
|
214
|
-
return _this;
|
|
215
152
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
var minX = Math.min.apply(Math, (0, _toConsumableArray2["default"])(xValues));
|
|
230
|
-
var maxX = Math.max.apply(Math, (0, _toConsumableArray2["default"])(xValues));
|
|
231
|
-
var minY = Math.min.apply(Math, (0, _toConsumableArray2["default"])(yValues));
|
|
232
|
-
var maxY = Math.max.apply(Math, (0, _toConsumableArray2["default"])(yValues));
|
|
153
|
+
static getDerivedStateFromProps(nextProps, prevState) {
|
|
154
|
+
const {
|
|
155
|
+
id,
|
|
156
|
+
points,
|
|
157
|
+
imageHeight,
|
|
158
|
+
imageWidth
|
|
159
|
+
} = nextProps;
|
|
160
|
+
// we execute this code only if image dimensions changed or an hotspot was added/deleted
|
|
161
|
+
if (prevState.imageHeight !== imageHeight || prevState.imageWidth !== imageWidth || prevState.id !== nextProps.id || JSON.stringify(prevState.points) !== JSON.stringify(points)) {
|
|
162
|
+
const xList = points.map(p => p.x);
|
|
163
|
+
const yList = points.map(p => p.y);
|
|
164
|
+
const x = Math.min(...xList);
|
|
165
|
+
const y = Math.max(...yList);
|
|
233
166
|
return {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
167
|
+
id,
|
|
168
|
+
x,
|
|
169
|
+
y,
|
|
170
|
+
points,
|
|
171
|
+
imageHeight,
|
|
172
|
+
imageWidth
|
|
238
173
|
};
|
|
239
174
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
onDragMove: function onDragMove(e) {
|
|
308
|
-
_this2.handleOnDragVertex(e, index);
|
|
309
|
-
},
|
|
310
|
-
onDragEnd: function onDragEnd(e) {
|
|
311
|
-
_this2.handleOnDragVertex(e, index, true);
|
|
312
|
-
},
|
|
313
|
-
draggable: true
|
|
314
|
-
});
|
|
315
|
-
}), !this.state.isDragging && this.state.hovered && /*#__PURE__*/_react["default"].createElement(_DeleteWidget["default"], {
|
|
316
|
-
x: x,
|
|
317
|
-
y: y,
|
|
318
|
-
id: id,
|
|
319
|
-
handleWidgetClick: this.handleDelete,
|
|
320
|
-
points: points
|
|
321
|
-
}));
|
|
322
|
-
}
|
|
323
|
-
}], [{
|
|
324
|
-
key: "getDerivedStateFromProps",
|
|
325
|
-
value: function getDerivedStateFromProps(nextProps, prevState) {
|
|
326
|
-
var id = nextProps.id,
|
|
327
|
-
points = nextProps.points,
|
|
328
|
-
imageHeight = nextProps.imageHeight,
|
|
329
|
-
imageWidth = nextProps.imageWidth; // we execute this code only if image dimensions changed or an hotspot was added/deleted
|
|
330
|
-
|
|
331
|
-
if (prevState.imageHeight !== imageHeight || prevState.imageWidth !== imageWidth || prevState.id !== nextProps.id || JSON.stringify(prevState.points) !== JSON.stringify(points)) {
|
|
332
|
-
var xList = points.map(function (p) {
|
|
333
|
-
return p.x;
|
|
334
|
-
});
|
|
335
|
-
var yList = points.map(function (p) {
|
|
336
|
-
return p.y;
|
|
337
|
-
});
|
|
338
|
-
var x = Math.min.apply(Math, (0, _toConsumableArray2["default"])(xList));
|
|
339
|
-
var y = Math.max.apply(Math, (0, _toConsumableArray2["default"])(yList));
|
|
340
|
-
return {
|
|
341
|
-
id: id,
|
|
342
|
-
x: x,
|
|
343
|
-
y: y,
|
|
344
|
-
points: points,
|
|
345
|
-
imageHeight: imageHeight,
|
|
346
|
-
imageWidth: imageWidth
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
return null;
|
|
351
|
-
}
|
|
352
|
-
}]);
|
|
353
|
-
return PolComponent;
|
|
354
|
-
}(_react["default"].Component);
|
|
355
|
-
|
|
356
|
-
var styles = function styles() {
|
|
357
|
-
return {
|
|
358
|
-
base: {
|
|
359
|
-
cursor: 'pointer',
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
// serialize(points) {
|
|
178
|
+
// return points.reduce((acc, point) => [...acc, point.x, point.y], []);
|
|
179
|
+
// }
|
|
180
|
+
|
|
181
|
+
getBoundingBox(points) {
|
|
182
|
+
const xValues = points.map(point => point.x);
|
|
183
|
+
const yValues = points.map(point => point.y);
|
|
184
|
+
const minX = Math.min(...xValues);
|
|
185
|
+
const maxX = Math.max(...xValues);
|
|
186
|
+
const minY = Math.min(...yValues);
|
|
187
|
+
const maxY = Math.max(...yValues);
|
|
188
|
+
return {
|
|
189
|
+
x: minX,
|
|
190
|
+
y: minY,
|
|
191
|
+
width: maxX - minX,
|
|
192
|
+
height: maxY - minY
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
render() {
|
|
196
|
+
const {
|
|
197
|
+
correct,
|
|
198
|
+
id,
|
|
199
|
+
hotspotColor,
|
|
200
|
+
outlineColor,
|
|
201
|
+
selectedHotspotColor,
|
|
202
|
+
hoverOutlineColor,
|
|
203
|
+
strokeWidth = 5
|
|
204
|
+
} = this.props;
|
|
205
|
+
const {
|
|
206
|
+
points,
|
|
207
|
+
x,
|
|
208
|
+
y,
|
|
209
|
+
hovered
|
|
210
|
+
} = this.state;
|
|
211
|
+
const isInProgress = id === 'newPolygon';
|
|
212
|
+
const showPoints = hovered || id === 'newPolygon';
|
|
213
|
+
const calculatedStrokeWidth = correct ? strokeWidth : hovered ? 1 : 0;
|
|
214
|
+
const calculatedStroke = correct ? outlineColor : hovered ? HOVERED_COLOR : '';
|
|
215
|
+
const boundingBox = this.getBoundingBox(points);
|
|
216
|
+
const calculatedFill = correct && selectedHotspotColor ? selectedHotspotColor : hotspotColor;
|
|
217
|
+
return /*#__PURE__*/_react.default.createElement(_reactKonva.Group, {
|
|
218
|
+
onMouseLeave: this.handleMouseLeave,
|
|
219
|
+
onMouseEnter: this.handleMouseEnter
|
|
220
|
+
}, hoverOutlineColor && hovered && /*#__PURE__*/_react.default.createElement(_ReactKonvaCore.Rect, {
|
|
221
|
+
x: boundingBox.x,
|
|
222
|
+
y: boundingBox.y,
|
|
223
|
+
width: boundingBox.width,
|
|
224
|
+
height: boundingBox.height,
|
|
225
|
+
stroke: hoverOutlineColor,
|
|
226
|
+
strokeWidth: 2,
|
|
227
|
+
listening: false
|
|
228
|
+
}), /*#__PURE__*/_react.default.createElement(_reactKonva.Line, {
|
|
229
|
+
points: this.serialize(points),
|
|
230
|
+
closed: !isInProgress,
|
|
231
|
+
fill: isInProgress ? 'transparent' : calculatedFill,
|
|
232
|
+
onClick: this.handleClick,
|
|
233
|
+
onTap: this.handleClick,
|
|
234
|
+
draggable: true,
|
|
235
|
+
stroke: isInProgress ? outlineColor : calculatedStroke,
|
|
236
|
+
strokeWidth: isInProgress ? 1 : calculatedStrokeWidth,
|
|
237
|
+
onDragStart: this.onDragStart,
|
|
238
|
+
onDragMove: this.handleOnDragEnd,
|
|
239
|
+
onDragEnd: e => this.handleOnDragEnd(e, true),
|
|
240
|
+
x: x,
|
|
241
|
+
y: y,
|
|
360
242
|
opacity: 0.5
|
|
361
|
-
},
|
|
362
|
-
|
|
243
|
+
}), showPoints && points.map((point, index) => /*#__PURE__*/_react.default.createElement(_reactKonva.Circle, {
|
|
244
|
+
key: index,
|
|
245
|
+
x: point.x,
|
|
246
|
+
y: point.y,
|
|
247
|
+
radius: 5,
|
|
248
|
+
fill: index === 0 && id === 'newPolygon' ? 'blue' : 'white',
|
|
249
|
+
stroke: HOVERED_COLOR,
|
|
250
|
+
strokeWidth: 1,
|
|
251
|
+
onClick: this.handleClick,
|
|
252
|
+
onDragStart: this.onDragStart,
|
|
253
|
+
onDragMove: e => {
|
|
254
|
+
this.handleOnDragVertex(e, index);
|
|
255
|
+
},
|
|
256
|
+
onDragEnd: e => {
|
|
257
|
+
this.handleOnDragVertex(e, index, true);
|
|
258
|
+
},
|
|
259
|
+
draggable: true,
|
|
363
260
|
opacity: 4
|
|
364
|
-
},
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
261
|
+
})), !this.state.isDragging && this.state.hovered && /*#__PURE__*/_react.default.createElement(_DeleteWidget.default, {
|
|
262
|
+
x: x,
|
|
263
|
+
y: y,
|
|
264
|
+
id: id,
|
|
265
|
+
handleWidgetClick: this.handleDelete,
|
|
266
|
+
points: points
|
|
267
|
+
}));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
371
270
|
PolComponent.propTypes = {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
y: _propTypes["default"].number
|
|
271
|
+
correct: _propTypes.default.bool,
|
|
272
|
+
isDrawing: _propTypes.default.bool.isRequired,
|
|
273
|
+
id: _propTypes.default.string.isRequired,
|
|
274
|
+
imageHeight: _propTypes.default.number,
|
|
275
|
+
imageWidth: _propTypes.default.number,
|
|
276
|
+
hotspotColor: _propTypes.default.string.isRequired,
|
|
277
|
+
selectedHotspotColor: _propTypes.default.string,
|
|
278
|
+
hoverOutlineColor: _propTypes.default.string,
|
|
279
|
+
onClick: _propTypes.default.func.isRequired,
|
|
280
|
+
addPolygonPoint: _propTypes.default.func.isRequired,
|
|
281
|
+
onDeleteShape: _propTypes.default.func.isRequired,
|
|
282
|
+
onDragEnd: _propTypes.default.func.isRequired,
|
|
283
|
+
outlineColor: _propTypes.default.string.isRequired,
|
|
284
|
+
points: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
285
|
+
x: _propTypes.default.number,
|
|
286
|
+
y: _propTypes.default.number
|
|
389
287
|
})).isRequired,
|
|
390
|
-
strokeWidth: _propTypes
|
|
288
|
+
strokeWidth: _propTypes.default.number
|
|
391
289
|
};
|
|
392
290
|
PolComponent.defaultProps = {
|
|
393
291
|
correct: false
|
|
394
292
|
};
|
|
395
|
-
|
|
396
|
-
var _default = (0, _index.withStyles)(styles)(PolComponent);
|
|
397
|
-
|
|
398
|
-
exports["default"] = _default;
|
|
293
|
+
var _default = exports.default = PolComponent;
|
|
399
294
|
//# sourceMappingURL=hotspot-polygon.js.map
|