@pie-element/hotspot 6.23.3-next.7 → 6.23.3
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/CHANGELOG.md +17 -0
- package/configure/CHANGELOG.md +17 -0
- package/configure/lib/hotspot-circle.js +5 -3
- package/configure/lib/hotspot-circle.js.map +1 -1
- package/configure/lib/hotspot-container.js +10 -8
- package/configure/lib/hotspot-container.js.map +1 -1
- package/configure/lib/hotspot-drawable.js +114 -59
- package/configure/lib/hotspot-drawable.js.map +1 -1
- package/configure/lib/hotspot-polygon.js +21 -26
- package/configure/lib/hotspot-polygon.js.map +1 -1
- package/configure/lib/shapes/circle.js +5 -4
- package/configure/lib/shapes/circle.js.map +1 -1
- package/configure/lib/shapes/index.js +58 -0
- package/configure/lib/shapes/index.js.map +1 -0
- package/configure/lib/shapes/polygon.js +5 -2
- package/configure/lib/shapes/polygon.js.map +1 -1
- package/configure/lib/shapes/rectagle.js +5 -4
- package/configure/lib/shapes/rectagle.js.map +1 -1
- package/configure/lib/shapes/utils.js +27 -0
- package/configure/lib/shapes/utils.js.map +1 -0
- package/configure/lib/utils.js +10 -8
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +2 -2
- package/configure/src/__tests__/utils.test.js +2 -2
- package/configure/src/hotspot-circle.jsx +5 -2
- package/configure/src/hotspot-container.jsx +9 -8
- package/configure/src/hotspot-drawable.jsx +95 -44
- package/configure/src/hotspot-polygon.jsx +18 -25
- package/configure/src/shapes/circle.js +3 -1
- package/configure/src/shapes/index.js +4 -0
- package/configure/src/shapes/polygon.js +3 -1
- package/configure/src/shapes/rectagle.js +3 -1
- package/configure/src/shapes/utils.js +16 -0
- package/configure/src/utils.js +8 -7
- package/controller/CHANGELOG.md +11 -0
- package/controller/package.json +2 -2
- package/package.json +3 -3
package/configure/lib/utils.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.updateImageDimensions = exports.isPointInsidePolygon = exports.groupShapes = exports.getUpdatedShapes = exports.getUpdatedRectangle = exports.
|
|
8
|
+
exports.updateImageDimensions = exports.isPointInsidePolygon = exports.groupShapes = exports.getUpdatedShapes = exports.getUpdatedRectangle = exports.getUpdatedPolygon = exports.getAllShapes = exports.generateValidationMessage = exports.calculate = void 0;
|
|
9
9
|
|
|
10
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
11
|
|
|
@@ -15,6 +15,8 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
15
15
|
|
|
16
16
|
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
17
17
|
|
|
18
|
+
var _shapes = require("./shapes");
|
|
19
|
+
|
|
18
20
|
var _excluded = ["group"];
|
|
19
21
|
|
|
20
22
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -70,13 +72,13 @@ exports.getUpdatedRectangle = getUpdatedRectangle;
|
|
|
70
72
|
|
|
71
73
|
var getUpdatedCircles = function getUpdatedCircles(initialDim, nextDim, shape) {
|
|
72
74
|
return _objectSpread(_objectSpread({}, shape), {}, {
|
|
73
|
-
radius: getDelta(initialDim.
|
|
75
|
+
radius: getDelta(initialDim.width, nextDim.width, shape.radius),
|
|
74
76
|
x: getDelta(initialDim.width, nextDim.width, shape.x),
|
|
75
77
|
y: getDelta(initialDim.height, nextDim.height, shape.y)
|
|
76
78
|
});
|
|
77
79
|
};
|
|
78
80
|
|
|
79
|
-
var
|
|
81
|
+
var getUpdatedPolygon = function getUpdatedPolygon(initialDim, nextDim, shape) {
|
|
80
82
|
return _objectSpread(_objectSpread({}, shape), {}, {
|
|
81
83
|
points: shape.points.map(function (point) {
|
|
82
84
|
return {
|
|
@@ -90,19 +92,19 @@ var getUpdatedPlygon = function getUpdatedPlygon(initialDim, nextDim, shape) {
|
|
|
90
92
|
// shapes = array of shapes that have to be re-sized and re-positioned
|
|
91
93
|
|
|
92
94
|
|
|
93
|
-
exports.
|
|
95
|
+
exports.getUpdatedPolygon = getUpdatedPolygon;
|
|
94
96
|
|
|
95
97
|
var getUpdatedShapes = function getUpdatedShapes(initialDim, nextDim, shapes) {
|
|
96
98
|
return shapes.map(function (shape) {
|
|
97
|
-
if (shape.group ===
|
|
99
|
+
if (shape.group === _shapes.SHAPE_GROUPS.RECTANGLES) {
|
|
98
100
|
return getUpdatedRectangle(initialDim, nextDim, shape);
|
|
99
101
|
}
|
|
100
102
|
|
|
101
|
-
if (shape.group ===
|
|
102
|
-
return
|
|
103
|
+
if (shape.group === _shapes.SHAPE_GROUPS.POLYGONS) {
|
|
104
|
+
return getUpdatedPolygon(initialDim, nextDim, shape);
|
|
103
105
|
}
|
|
104
106
|
|
|
105
|
-
if (shape.group ===
|
|
107
|
+
if (shape.group === _shapes.SHAPE_GROUPS.CIRCLES) {
|
|
106
108
|
return getUpdatedCircles(initialDim, nextDim, shape);
|
|
107
109
|
}
|
|
108
110
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.js"],"names":["updateImageDimensions","initialDim","nextDim","keepAspectRatio","resizeType","imageAspectRatio","width","height","getDelta","referenceInitialValue","referenceNextValue","currentValue","getUpdatedRectangle","shape","x","y","getUpdatedCircles","radius","getUpdatedPlygon","points","map","point","getUpdatedShapes","shapes","group","getAllShapes","shapesMap","shapesArray","shapesKeys","Object","keys","length","reduce","acc","currentShapeKey","concat","index","groupShapes","rectangles","polygons","circles","shapeProps","isPointInsidePolygon","polygon","inside","i","j","xi","yi","xj","yj","intersect","calculate","polygonPoints","xPoints","yPoints","minX","Math","min","minY","maxX","max","maxY","textX","textY","generateValidationMessage","config","minShapes","maxShapes","maxSelections","shapesMessage","selectionsMessage","message"],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;AAEA,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,UAAD,EAAaC,OAAb,EAAsBC,eAAtB,EAAuCC,UAAvC,EAAsD;AAClF;AACA,MAAID,eAAJ,EAAqB;AACnB,QAAME,gBAAgB,GAAGJ,UAAU,CAACK,KAAX,GAAmBL,UAAU,CAACM,MAAvD;;AAEA,QAAIH,UAAU,KAAK,QAAnB,EAA6B;AAC3B;AACA,aAAO;AACLE,QAAAA,KAAK,EAAEJ,OAAO,CAACK,MAAR,GAAiBF,gBADnB;AAELE,QAAAA,MAAM,EAAEL,OAAO,CAACK;AAFX,OAAP;AAID,KATkB,CAWnB;;;AACA,WAAO;AACLD,MAAAA,KAAK,EAAEJ,OAAO,CAACI,KADV;AAELC,MAAAA,MAAM,EAAEL,OAAO,CAACI,KAAR,GAAgBD;AAFnB,KAAP;AAID,GAlBiF,CAoBlF;;;AACA,SAAO;AACLC,IAAAA,KAAK,EAAEJ,OAAO,CAACI,KADV;AAELC,IAAAA,MAAM,EAAEL,OAAO,CAACK;AAFX,GAAP;AAID,CAzBD,C,CA2BA;AACA;AACA;;;;;AACA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,CAACC,qBAAD,EAAwBC,kBAAxB,EAA4CC,YAA5C;AAAA,SACdD,kBAAkB,GAAGD,qBAAtB,GAA+CE,YADhC;AAAA,CAAjB;;AAGA,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACX,UAAD,EAAaC,OAAb,EAAsBW,KAAtB;AAAA,yCACvBA,KADuB;AAE1BP,IAAAA,KAAK,EAAEE,QAAQ,CAACP,UAAU,CAACK,KAAZ,EAAmBJ,OAAO,CAACI,KAA3B,EAAkCO,KAAK,CAACP,KAAxC,CAFW;AAG1BC,IAAAA,MAAM,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';\n\nconst updateImageDimensions = (initialDim, nextDim, keepAspectRatio, resizeType) => {\n // if we want to keep image aspect ratio\n if (keepAspectRatio) {\n const imageAspectRatio = initialDim.width / initialDim.height;\n\n if (resizeType === 'height') {\n // if we want to change image height => we update the width accordingly\n return {\n width: nextDim.height * imageAspectRatio,\n height: nextDim.height,\n };\n }\n\n // if we want to change image width => we update the height accordingly\n return {\n width: nextDim.width,\n height: nextDim.width / imageAspectRatio,\n };\n }\n\n // if we don't want to keep aspect ratio, we just update both values\n return {\n width: nextDim.width,\n height: nextDim.height,\n };\n};\n\n// referenceInitialValue = the initial value of the Stage\n// referenceNextValue = the next value of the Stage\n// currentValue = the value that has to be re-sized influenced by the changes that were made on the Stage\nconst getDelta = (referenceInitialValue, referenceNextValue, currentValue) =>\n (referenceNextValue / referenceInitialValue) * currentValue;\n\nconst getUpdatedRectangle = (initialDim, nextDim, shape) => ({\n ...shape,\n width: getDelta(initialDim.width, nextDim.width, shape.width),\n height: getDelta(initialDim.height, nextDim.height, shape.height),\n x: getDelta(initialDim.width, nextDim.width, shape.x),\n y: getDelta(initialDim.height, nextDim.height, shape.y),\n});\n\nconst getUpdatedCircles = (initialDim, nextDim, shape) => ({\n ...shape,\n radius: getDelta(initialDim.radius, nextDim.radius, shape.radius),\n x: getDelta(initialDim.width, nextDim.width, shape.x),\n y: getDelta(initialDim.height, nextDim.height, shape.y),\n});\n\nconst getUpdatedPlygon = (initialDim, nextDim, shape) => ({\n ...shape,\n points: shape.points.map((point) => ({\n x: getDelta(initialDim.width, nextDim.width, point.x),\n y: getDelta(initialDim.height, nextDim.height, point.y),\n })),\n});\n\n// initialDim = the initial dimensions: { width, height } of the Stage\n// nextDim = the next dimensions: { width, height } of the Stage\n// shapes = array of shapes that have to be re-sized and re-positioned\nconst getUpdatedShapes = (initialDim, nextDim, shapes) => {\n return shapes.map((shape) => {\n if (shape.group === 'rectangles') {\n return getUpdatedRectangle(initialDim, nextDim, shape);\n }\n\n if (shape.group === 'polygons') {\n return getUpdatedPlygon(initialDim, nextDim, shape);\n }\n\n if (shape.group === 'circles') {\n return getUpdatedCircles(initialDim, nextDim, shape);\n }\n });\n};\n\n// converts shapes map to shapes array\n// example:\n// from: { rectangles: [r1], polygons: [p1, p2]}\n// to: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]\n// if a shape has index defined, keep it, otherwise initialize it\n// index is used for the UNDO function\nconst getAllShapes = (shapesMap) => {\n shapesMap = shapesMap || {};\n const shapesArray = [];\n const shapesKeys = Object.keys(shapesMap);\n\n return shapesKeys.length\n ? shapesKeys.reduce(\n (acc, currentShapeKey) =>\n acc.concat(\n shapesMap[currentShapeKey]\n ? shapesMap[currentShapeKey].map((shape, index) => ({\n ...shape,\n group: currentShapeKey,\n index: shape.index || acc.length + index,\n }))\n : [],\n ),\n shapesArray,\n )\n : shapesArray;\n};\n\n// converts shapes array to shapes map\n// is the reverse of getAllShapes function\n// example:\n// from: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]\n// to: { rectangles: [r1], polygons: [p1, p2]}\nconst groupShapes = (shapesArray) => {\n shapesArray = shapesArray || [];\n const shapesMap = {\n rectangles: [],\n polygons: [],\n circles: [],\n };\n\n if (shapesArray.length) {\n return shapesArray.reduce((acc, { group, ...shapeProps }) => {\n acc[group] = [...(acc[group] || []), shapeProps];\n return acc;\n }, shapesMap);\n }\n\n return cloneDeep(shapesMap);\n};\n\nconst isPointInsidePolygon = (polygon, x, y) => {\n let inside = false;\n\n if (!polygon || polygon.length <= 0) {\n return inside;\n }\n\n for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {\n const xi = polygon[i].x;\n const yi = polygon[i].y;\n const xj = polygon[j].x;\n const yj = polygon[j].y;\n\n const intersect = yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;\n\n if (intersect) {\n inside = !inside;\n }\n }\n\n return inside;\n};\n\nconst calculate = (polygonPoints) => {\n if (!polygonPoints || polygonPoints.length <= 0) {\n return { x: 0, y: 0 };\n }\n\n const xPoints = polygonPoints.map((point) => point.x);\n const yPoints = polygonPoints.map((point) => point.y);\n const minX = Math.min(...xPoints);\n const minY = Math.min(...yPoints);\n const maxX = Math.max(...xPoints);\n const maxY = Math.max(...yPoints);\n\n // Find a suitable position for the text element within the polygon\n let textX, textY;\n\n for (let x = minX; x <= maxX - 20; x++) {\n for (let y = maxY - 20; y > minY; y--) {\n // Check if the text element's position (x, y) is within the polygon\n if (isPointInsidePolygon(polygonPoints, x, y)) {\n textX = x - 10;\n textY = y;\n break;\n }\n }\n }\n\n return { x: textX, y: textY };\n};\n\nconst generateValidationMessage = (config) => {\n const { minShapes, maxShapes, maxSelections } = config;\n\n const shapesMessage =\n `\\nThere should be at least ${minShapes} ` + (maxShapes ? `and at most ${maxShapes} ` : '') + 'shapes defined.';\n\n const selectionsMessage =\n '\\nThere should be at least 1 ' +\n (maxSelections ? `and at most ${maxSelections} ` : '') +\n 'shape' +\n (maxSelections ? 's' : '') +\n ' selected.';\n\n const message = 'Validation requirements:' + shapesMessage + selectionsMessage;\n\n return message;\n};\n\nexport {\n calculate,\n isPointInsidePolygon,\n updateImageDimensions,\n generateValidationMessage,\n getUpdatedShapes,\n getAllShapes,\n groupShapes,\n getUpdatedRectangle,\n getUpdatedPlygon,\n};\n"],"file":"utils.js"}
|
|
1
|
+
{"version":3,"sources":["../src/utils.js"],"names":["updateImageDimensions","initialDim","nextDim","keepAspectRatio","resizeType","imageAspectRatio","width","height","getDelta","referenceInitialValue","referenceNextValue","currentValue","getUpdatedRectangle","shape","x","y","getUpdatedCircles","radius","getUpdatedPolygon","points","map","point","getUpdatedShapes","shapes","group","SHAPE_GROUPS","RECTANGLES","POLYGONS","CIRCLES","getAllShapes","shapesMap","shapesArray","shapesKeys","Object","keys","length","reduce","acc","currentShapeKey","concat","index","groupShapes","rectangles","polygons","circles","shapeProps","isPointInsidePolygon","polygon","inside","i","j","xi","yi","xj","yj","intersect","calculate","polygonPoints","xPoints","yPoints","minX","Math","min","minY","maxX","max","maxY","textX","textY","generateValidationMessage","config","minShapes","maxShapes","maxSelections","shapesMessage","selectionsMessage","message"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;;;;;;;AAEA,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,UAAD,EAAaC,OAAb,EAAsBC,eAAtB,EAAuCC,UAAvC,EAAsD;AAClF;AACA,MAAID,eAAJ,EAAqB;AACnB,QAAME,gBAAgB,GAAGJ,UAAU,CAACK,KAAX,GAAmBL,UAAU,CAACM,MAAvD;;AAEA,QAAIH,UAAU,KAAK,QAAnB,EAA6B;AAC3B;AACA,aAAO;AACLE,QAAAA,KAAK,EAAEJ,OAAO,CAACK,MAAR,GAAiBF,gBADnB;AAELE,QAAAA,MAAM,EAAEL,OAAO,CAACK;AAFX,OAAP;AAID,KATkB,CAWnB;;;AACA,WAAO;AACLD,MAAAA,KAAK,EAAEJ,OAAO,CAACI,KADV;AAELC,MAAAA,MAAM,EAAEL,OAAO,CAACI,KAAR,GAAgBD;AAFnB,KAAP;AAID,GAlBiF,CAoBlF;;;AACA,SAAO;AACLC,IAAAA,KAAK,EAAEJ,OAAO,CAACI,KADV;AAELC,IAAAA,MAAM,EAAEL,OAAO,CAACK;AAFX,GAAP;AAID,CAzBD,C,CA2BA;AACA;AACA;;;;;AACA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,CAACC,qBAAD,EAAwBC,kBAAxB,EAA4CC,YAA5C;AAAA,SACdD,kBAAkB,GAAGD,qBAAtB,GAA+CE,YADhC;AAAA,CAAjB;;AAGA,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACX,UAAD,EAAaC,OAAb,EAAsBW,KAAtB;AAAA,yCACvBA,KADuB;AAE1BP,IAAAA,KAAK,EAAEE,QAAQ,CAACP,UAAU,CAACK,KAAZ,EAAmBJ,OAAO,CAACI,KAA3B,EAAkCO,KAAK,CAACP,KA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EA,SAAOC,OAAP;AACD,CAhBD","sourcesContent":["import cloneDeep from 'lodash/cloneDeep';\nimport { SHAPE_GROUPS } from './shapes';\n\nconst updateImageDimensions = (initialDim, nextDim, keepAspectRatio, resizeType) => {\n // if we want to keep image aspect ratio\n if (keepAspectRatio) {\n const imageAspectRatio = initialDim.width / initialDim.height;\n\n if (resizeType === 'height') {\n // if we want to change image height => we update the width accordingly\n return {\n width: nextDim.height * imageAspectRatio,\n height: nextDim.height,\n };\n }\n\n // if we want to change image width => we update the height accordingly\n return {\n width: nextDim.width,\n height: nextDim.width / imageAspectRatio,\n };\n }\n\n // if we don't want to keep aspect ratio, we just update both values\n return {\n width: nextDim.width,\n height: nextDim.height,\n };\n};\n\n// referenceInitialValue = the initial value of the Stage\n// referenceNextValue = the next value of the Stage\n// currentValue = the value that has to be re-sized influenced by the changes that were made on the Stage\nconst getDelta = (referenceInitialValue, referenceNextValue, currentValue) =>\n (referenceNextValue / referenceInitialValue) * currentValue;\n\nconst getUpdatedRectangle = (initialDim, nextDim, shape) => ({\n ...shape,\n width: getDelta(initialDim.width, nextDim.width, shape.width),\n height: getDelta(initialDim.height, nextDim.height, shape.height),\n x: getDelta(initialDim.width, nextDim.width, shape.x),\n y: getDelta(initialDim.height, nextDim.height, shape.y),\n});\n\nconst getUpdatedCircles = (initialDim, nextDim, shape) => ({\n ...shape,\n radius: getDelta(initialDim.width, nextDim.width, shape.radius),\n x: getDelta(initialDim.width, nextDim.width, shape.x),\n y: getDelta(initialDim.height, nextDim.height, shape.y),\n});\n\nconst getUpdatedPolygon = (initialDim, nextDim, shape) => ({\n ...shape,\n points: shape.points.map((point) => ({\n x: getDelta(initialDim.width, nextDim.width, point.x),\n y: getDelta(initialDim.height, nextDim.height, point.y),\n })),\n});\n\n// initialDim = the initial dimensions: { width, height } of the Stage\n// nextDim = the next dimensions: { width, height } of the Stage\n// shapes = array of shapes that have to be re-sized and re-positioned\nconst getUpdatedShapes = (initialDim, nextDim, shapes) => {\n return shapes.map((shape) => {\n if (shape.group === SHAPE_GROUPS.RECTANGLES) {\n return getUpdatedRectangle(initialDim, nextDim, shape);\n }\n\n if (shape.group === SHAPE_GROUPS.POLYGONS) {\n return getUpdatedPolygon(initialDim, nextDim, shape);\n }\n\n if (shape.group === SHAPE_GROUPS.CIRCLES) {\n return getUpdatedCircles(initialDim, nextDim, shape);\n }\n });\n};\n\n// converts shapes map to shapes array\n// example:\n// from: { rectangles: [r1], polygons: [p1, p2]}\n// to: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]\n// if a shape has index defined, keep it, otherwise initialize it\n// index is used for the UNDO function\nconst getAllShapes = (shapesMap) => {\n shapesMap = shapesMap || {};\n const shapesArray = [];\n const shapesKeys = Object.keys(shapesMap);\n\n return shapesKeys.length\n ? shapesKeys.reduce(\n (acc, currentShapeKey) =>\n acc.concat(\n shapesMap[currentShapeKey]\n ? shapesMap[currentShapeKey].map((shape, index) => ({\n ...shape,\n group: currentShapeKey,\n index: shape.index || acc.length + index,\n }))\n : [],\n ),\n shapesArray,\n )\n : shapesArray;\n};\n\n// converts shapes array to shapes map\n// is the reverse of getAllShapes function\n// example:\n// from: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]\n// to: { rectangles: [r1], polygons: [p1, p2]}\nconst groupShapes = (shapesArray) => {\n shapesArray = shapesArray || [];\n const shapesMap = {\n rectangles: [],\n polygons: [],\n circles: [],\n };\n\n if (shapesArray.length) {\n return shapesArray.reduce((acc, { group, ...shapeProps }) => {\n acc[group] = [...(acc[group] || []), shapeProps];\n return acc;\n }, shapesMap);\n }\n\n return cloneDeep(shapesMap);\n};\n\nconst isPointInsidePolygon = (polygon, x, y) => {\n let inside = false;\n\n if (!polygon || polygon.length <= 0) {\n return inside;\n }\n\n for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {\n const xi = polygon[i].x;\n const yi = polygon[i].y;\n const xj = polygon[j].x;\n const yj = polygon[j].y;\n\n const intersect = yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;\n\n if (intersect) {\n inside = !inside;\n }\n }\n\n return inside;\n};\n\nconst calculate = (polygonPoints) => {\n if (!polygonPoints || polygonPoints.length <= 0) {\n return { x: 0, y: 0 };\n }\n\n const xPoints = polygonPoints.map((point) => point.x);\n const yPoints = polygonPoints.map((point) => point.y);\n const minX = Math.min(...xPoints);\n const minY = Math.min(...yPoints);\n const maxX = Math.max(...xPoints);\n const maxY = Math.max(...yPoints);\n\n // Find a suitable position for the text element within the polygon\n let textX, textY;\n\n for (let x = minX; x <= maxX - 20; x++) {\n for (let y = maxY - 20; y > minY; y--) {\n // Check if the text element's position (x, y) is within the polygon\n if (isPointInsidePolygon(polygonPoints, x, y)) {\n textX = x - 10;\n textY = y;\n break;\n }\n }\n }\n\n return { x: textX, y: textY };\n};\n\nconst generateValidationMessage = (config) => {\n const { minShapes, maxShapes, maxSelections } = config;\n\n const shapesMessage =\n `\\nThere should be at least ${minShapes} ` + (maxShapes ? `and at most ${maxShapes} ` : '') + 'shapes defined.';\n\n const selectionsMessage =\n '\\nThere should be at least 1 ' +\n (maxSelections ? `and at most ${maxSelections} ` : '') +\n 'shape' +\n (maxSelections ? 's' : '') +\n ' selected.';\n\n const message = 'Validation requirements:' + shapesMessage + selectionsMessage;\n\n return message;\n};\n\nexport {\n calculate,\n isPointInsidePolygon,\n updateImageDimensions,\n generateValidationMessage,\n getUpdatedShapes,\n getAllShapes,\n groupShapes,\n getUpdatedRectangle,\n getUpdatedPolygon,\n};\n"],"file":"utils.js"}
|
package/configure/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/hotspot-configure",
|
|
3
3
|
"private": true,
|
|
4
|
-
"version": "6.22.
|
|
4
|
+
"version": "6.22.3",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "src/index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@material-ui/core": "^3.9.2",
|
|
11
11
|
"@material-ui/icons": "^3.0.2",
|
|
12
12
|
"@pie-framework/pie-configure-events": "^1.3.0",
|
|
13
|
-
"@pie-lib/pie-toolbox": "1.25.
|
|
13
|
+
"@pie-lib/pie-toolbox": "1.25.3",
|
|
14
14
|
"classnames": "^2.2.6",
|
|
15
15
|
"debug": "^3.1.0",
|
|
16
16
|
"konva": "^3.2.4",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { updateImageDimensions, getUpdatedRectangle,
|
|
2
|
+
import { updateImageDimensions, getUpdatedRectangle, getUpdatedPolygon, getAllShapes, groupShapes } from '../utils';
|
|
3
3
|
|
|
4
4
|
const width = 200;
|
|
5
5
|
const height = 100;
|
|
@@ -116,7 +116,7 @@ describe('getUpdatedPolygon', () => {
|
|
|
116
116
|
`(
|
|
117
117
|
'initialDimensions = $initialDimensions, nextDimensions = $nextDimensions, shape = $shape => $expected',
|
|
118
118
|
async ({ initialDimensions, nextDimensions, shape, expected }) => {
|
|
119
|
-
const result =
|
|
119
|
+
const result = getUpdatedPolygon(initialDimensions, nextDimensions, shape);
|
|
120
120
|
|
|
121
121
|
expect(result).toEqual(expected);
|
|
122
122
|
},
|
|
@@ -78,12 +78,15 @@ class CircleComponent extends React.Component {
|
|
|
78
78
|
render() {
|
|
79
79
|
const { classes, correct, radius, hotspotColor, id, outlineColor, x, y, strokeWidth = 5 } = this.props;
|
|
80
80
|
|
|
81
|
+
// Ensure radius is valid
|
|
82
|
+
const validRadius = isNaN(radius) || radius <= 0 ? 5 : radius;
|
|
83
|
+
|
|
81
84
|
return (
|
|
82
85
|
<Group classes={classes.group} onMouseLeave={this.handleMouseLeave} onMouseEnter={this.handleMouseEnter}>
|
|
83
86
|
<Circle
|
|
84
87
|
classes={classes.base}
|
|
85
88
|
ref={this.shapeRef}
|
|
86
|
-
radius={
|
|
89
|
+
radius={validRadius}
|
|
87
90
|
fill={hotspotColor}
|
|
88
91
|
onClick={this.handleClick}
|
|
89
92
|
onTap={this.handleClick}
|
|
@@ -98,7 +101,7 @@ class CircleComponent extends React.Component {
|
|
|
98
101
|
y={y}
|
|
99
102
|
/>
|
|
100
103
|
{!this.state.isDragging && this.state.hovered && (
|
|
101
|
-
<DeleteWidget id={id} radius={
|
|
104
|
+
<DeleteWidget id={id} radius={validRadius} x={x} y={y} handleWidgetClick={this.handleDelete} isCircle={true} />
|
|
102
105
|
)}
|
|
103
106
|
{this.state.hovered && (
|
|
104
107
|
<Transformer
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { withStyles } from '@material-ui/core/styles/index';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
|
+
import { SUPPORTED_SHAPES } from './shapes';
|
|
3
4
|
import PropTypes from 'prop-types';
|
|
4
5
|
import React, { Component } from 'react';
|
|
5
6
|
import Button from './button';
|
|
@@ -33,7 +34,7 @@ export class Container extends Component {
|
|
|
33
34
|
dragEnabled: true,
|
|
34
35
|
// always transform shapes map into shapes array at this level
|
|
35
36
|
shapes: getAllShapes(props.shapes),
|
|
36
|
-
selectedShape:
|
|
37
|
+
selectedShape: SUPPORTED_SHAPES.NONE,
|
|
37
38
|
};
|
|
38
39
|
this.fakeImageHandler = {
|
|
39
40
|
cancel: () => {},
|
|
@@ -141,7 +142,7 @@ export class Container extends Component {
|
|
|
141
142
|
handleFinishDrawing = () => {
|
|
142
143
|
// Explicitly end the current shape drawing session
|
|
143
144
|
// This would cause the finalizeCreation method to be called in the HotspotDrawable component
|
|
144
|
-
this.setState({ selectedShape:
|
|
145
|
+
this.setState({ selectedShape: SUPPORTED_SHAPES.NONE });
|
|
145
146
|
};
|
|
146
147
|
|
|
147
148
|
render() {
|
|
@@ -179,22 +180,22 @@ export class Container extends Component {
|
|
|
179
180
|
>
|
|
180
181
|
<div className={classes.toolbar}>
|
|
181
182
|
<div
|
|
182
|
-
onClick={() => this.setState({ selectedShape: selectedShape ===
|
|
183
|
+
onClick={() => this.setState({ selectedShape: selectedShape === SUPPORTED_SHAPES.RECTANGLE ? SUPPORTED_SHAPES.NONE : SUPPORTED_SHAPES.RECTANGLE })}
|
|
183
184
|
className={classes.buttonShape}
|
|
184
185
|
>
|
|
185
|
-
<RectangleButton isActive={selectedShape ===
|
|
186
|
+
<RectangleButton isActive={selectedShape === SUPPORTED_SHAPES.RECTANGLE} />
|
|
186
187
|
</div>
|
|
187
188
|
<div
|
|
188
|
-
onClick={() => this.setState({ selectedShape: selectedShape ===
|
|
189
|
+
onClick={() => this.setState({ selectedShape: selectedShape === SUPPORTED_SHAPES.POLYGON ? SUPPORTED_SHAPES.NONE : SUPPORTED_SHAPES.POLYGON })}
|
|
189
190
|
className={classes.buttonShape}
|
|
190
191
|
>
|
|
191
|
-
<PolygonButton isActive={selectedShape ===
|
|
192
|
+
<PolygonButton isActive={selectedShape === SUPPORTED_SHAPES.POLYGON} />
|
|
192
193
|
</div>
|
|
193
194
|
<div
|
|
194
|
-
onClick={() => this.setState({ selectedShape: selectedShape ===
|
|
195
|
+
onClick={() => this.setState({ selectedShape: selectedShape === SUPPORTED_SHAPES.CIRCLE ? SUPPORTED_SHAPES.NONE : SUPPORTED_SHAPES.CIRCLE })}
|
|
195
196
|
className={classes.buttonShape}
|
|
196
197
|
>
|
|
197
|
-
<CircleButton isActive={selectedShape ===
|
|
198
|
+
<CircleButton isActive={selectedShape === SUPPORTED_SHAPES.CIRCLE} />
|
|
198
199
|
</div>
|
|
199
200
|
|
|
200
201
|
{imageUrl && (
|
|
@@ -7,10 +7,8 @@ import { withStyles } from '@material-ui/core/styles/index';
|
|
|
7
7
|
import Rectangle from './hotspot-rectangle';
|
|
8
8
|
import Polygon from './hotspot-polygon';
|
|
9
9
|
import Circle from './hotspot-circle';
|
|
10
|
-
import {
|
|
11
|
-
import RectangleShape from './shapes
|
|
12
|
-
import CircleShape from './shapes/circle';
|
|
13
|
-
import PolygonShape from './shapes/polygon';
|
|
10
|
+
import { getUpdatedShapes, updateImageDimensions } from './utils';
|
|
11
|
+
import { RectangleShape, CircleShape, PolygonShape, SUPPORTED_SHAPES, SHAPE_GROUPS } from './shapes';
|
|
14
12
|
const IMAGE_MAX_WIDTH = 800;
|
|
15
13
|
|
|
16
14
|
export class Drawable extends React.Component {
|
|
@@ -48,14 +46,18 @@ export class Drawable extends React.Component {
|
|
|
48
46
|
return;
|
|
49
47
|
}
|
|
50
48
|
|
|
49
|
+
if (!Object.values(SUPPORTED_SHAPES).includes(shapeType)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
51
53
|
switch (shapeType) {
|
|
52
|
-
case
|
|
54
|
+
case SUPPORTED_SHAPES.RECTANGLE:
|
|
53
55
|
newState = RectangleShape.create(shapes, e);
|
|
54
56
|
break;
|
|
55
|
-
case
|
|
57
|
+
case SUPPORTED_SHAPES.CIRCLE:
|
|
56
58
|
newState = CircleShape.create(shapes, e);
|
|
57
59
|
break;
|
|
58
|
-
case
|
|
60
|
+
case SUPPORTED_SHAPES.POLYGON:
|
|
59
61
|
newShapeId = this.state.isDrawingShapeId;
|
|
60
62
|
|
|
61
63
|
if (newShapeId) {
|
|
@@ -73,7 +75,6 @@ export class Drawable extends React.Component {
|
|
|
73
75
|
}
|
|
74
76
|
break;
|
|
75
77
|
default:
|
|
76
|
-
console.error(`Unsupported shape type: ${shapeType}`);
|
|
77
78
|
return;
|
|
78
79
|
}
|
|
79
80
|
|
|
@@ -102,19 +103,18 @@ export class Drawable extends React.Component {
|
|
|
102
103
|
const { shapeType, onUpdateShapes } = this.props;
|
|
103
104
|
let newState;
|
|
104
105
|
|
|
105
|
-
if (shapeType ===
|
|
106
|
+
if (shapeType === SUPPORTED_SHAPES.POLYGON) {
|
|
106
107
|
return;
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
switch (shapeType) {
|
|
110
|
-
case
|
|
111
|
+
case SUPPORTED_SHAPES.RECTANGLE:
|
|
111
112
|
newState = RectangleShape.finalizeCreation(this.state, this.props);
|
|
112
113
|
break;
|
|
113
|
-
case
|
|
114
|
+
case SUPPORTED_SHAPES.CIRCLE:
|
|
114
115
|
newState = CircleShape.finalizeCreation(this.state, this.props);
|
|
115
116
|
break;
|
|
116
117
|
default:
|
|
117
|
-
console.error(`Unsupported shape type: ${shapeType}`);
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
120
|
|
|
@@ -127,28 +127,29 @@ export class Drawable extends React.Component {
|
|
|
127
127
|
};
|
|
128
128
|
|
|
129
129
|
handleMouseMove = (e) => {
|
|
130
|
-
const { shapeType, onUpdateShapes
|
|
130
|
+
const { shapeType, onUpdateShapes } = this.props;
|
|
131
131
|
let newState;
|
|
132
132
|
|
|
133
|
-
if (this.state.isDrawing) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
newState = RectangleShape.handleMouseMove(this.state, e);
|
|
137
|
-
break;
|
|
138
|
-
case 'circle':
|
|
139
|
-
newState = CircleShape.handleMouseMove(this.state, e);
|
|
140
|
-
break;
|
|
141
|
-
case 'polygon':
|
|
142
|
-
newState = PolygonShape.handleMouseMove(this.state, e);
|
|
143
|
-
break;
|
|
144
|
-
default:
|
|
145
|
-
console.error(`Unsupported shape type: ${shapeType}`);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
133
|
+
if (!this.state.isDrawing || !Object.values(SUPPORTED_SHAPES).includes(shapeType)) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
148
136
|
|
|
149
|
-
|
|
150
|
-
|
|
137
|
+
switch (shapeType) {
|
|
138
|
+
case SUPPORTED_SHAPES.RECTANGLE:
|
|
139
|
+
newState = RectangleShape.handleMouseMove(this.state, e);
|
|
140
|
+
break;
|
|
141
|
+
case SUPPORTED_SHAPES.CIRCLE:
|
|
142
|
+
newState = CircleShape.handleMouseMove(this.state, e);
|
|
143
|
+
break;
|
|
144
|
+
case SUPPORTED_SHAPES.POLYGON:
|
|
145
|
+
newState = PolygonShape.handleMouseMove(this.state, e);
|
|
146
|
+
break;
|
|
147
|
+
default:
|
|
148
|
+
return;
|
|
151
149
|
}
|
|
150
|
+
|
|
151
|
+
this.setState(newState);
|
|
152
|
+
onUpdateShapes(newState.shapes);
|
|
152
153
|
};
|
|
153
154
|
|
|
154
155
|
handleOnMouseOutOrLeave = (e) => {
|
|
@@ -158,13 +159,65 @@ export class Drawable extends React.Component {
|
|
|
158
159
|
};
|
|
159
160
|
|
|
160
161
|
handleOnDragEnd = (id, updatedProps) => {
|
|
161
|
-
const { shapes, onUpdateShapes } = this.props;
|
|
162
|
+
const { shapes, onUpdateShapes, dimensions } = this.props;
|
|
163
|
+
const { width: canvasWidth, height: canvasHeight } = dimensions;
|
|
164
|
+
|
|
165
|
+
// when a shape is moved completely outside the canvas
|
|
166
|
+
// remove that shape
|
|
162
167
|
const newShapes = shapes.map((shape) => {
|
|
163
|
-
if (shape.id
|
|
168
|
+
if (shape.id !== id) {
|
|
169
|
+
return shape;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
let newX = updatedProps.x;
|
|
173
|
+
let newY = updatedProps.y;
|
|
174
|
+
|
|
175
|
+
if (shape.group === 'rectangles') {
|
|
176
|
+
if (newX + shape.width < 0 || newX > canvasWidth || newY + shape.height < 0 || newY > canvasHeight) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return { ...shape, ...updatedProps };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
if (shape.group === 'circles') {
|
|
185
|
+
const radius = shape.radius;
|
|
186
|
+
if (newX + radius < 0 || newX - radius > canvasWidth || newY + radius < 0 || newY - radius > canvasHeight) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return { ...shape,...updatedProps};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (shape.group === 'polygons') {
|
|
194
|
+
const points = shape.points;
|
|
195
|
+
const xValues = points.map(point => point.x);
|
|
196
|
+
const yValues = points.map(point => point.y);
|
|
197
|
+
|
|
198
|
+
let minX = Math.min(...xValues);
|
|
199
|
+
let minY = Math.min(...yValues);
|
|
200
|
+
let maxX = Math.max(...xValues);
|
|
201
|
+
let maxY = Math.max(...yValues);
|
|
202
|
+
|
|
203
|
+
// Calculate deltas based on the first point as a reference
|
|
204
|
+
const deltaX = updatedProps['points'][0].x - points[0].x;
|
|
205
|
+
const deltaY = updatedProps['points'][0].y - points[0].y;
|
|
206
|
+
|
|
207
|
+
minX = minX + deltaX;
|
|
208
|
+
maxX = maxX + deltaX;
|
|
209
|
+
minY = minY + deltaY;
|
|
210
|
+
maxY = maxY + deltaY;
|
|
211
|
+
|
|
212
|
+
if (maxX < 0 || minX > canvasWidth || maxY < 0 || minY > canvasHeight) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
|
|
164
216
|
return { ...shape, ...updatedProps };
|
|
165
217
|
}
|
|
218
|
+
|
|
166
219
|
return shape;
|
|
167
|
-
});
|
|
220
|
+
}).filter(shape => shape !== null);
|
|
168
221
|
|
|
169
222
|
onUpdateShapes(cloneDeep(newShapes));
|
|
170
223
|
};
|
|
@@ -173,7 +226,7 @@ export class Drawable extends React.Component {
|
|
|
173
226
|
const { id } = shape;
|
|
174
227
|
const { multipleCorrect, shapes, onUpdateShapes } = this.props;
|
|
175
228
|
|
|
176
|
-
let newShapes
|
|
229
|
+
let newShapes;
|
|
177
230
|
|
|
178
231
|
if (multipleCorrect) {
|
|
179
232
|
newShapes = shapes.map((shape) => {
|
|
@@ -244,7 +297,6 @@ export class Drawable extends React.Component {
|
|
|
244
297
|
const box = this.image;
|
|
245
298
|
const { disableDrag, preserveAspectRatioEnabled, dimensions, shapes } = this.props;
|
|
246
299
|
|
|
247
|
-
// todo previously we had state.dimensions, is it needed?
|
|
248
300
|
const { width, height } = updateImageDimensions(
|
|
249
301
|
dimensions,
|
|
250
302
|
{
|
|
@@ -307,8 +359,8 @@ export class Drawable extends React.Component {
|
|
|
307
359
|
outlineColor,
|
|
308
360
|
shapes,
|
|
309
361
|
strokeWidth,
|
|
310
|
-
onDeleteShape,
|
|
311
362
|
} = this.props;
|
|
363
|
+
|
|
312
364
|
const {
|
|
313
365
|
stateShapes,
|
|
314
366
|
isDrawing,
|
|
@@ -352,13 +404,13 @@ export class Drawable extends React.Component {
|
|
|
352
404
|
{shapesToUse.map((shape, i) => {
|
|
353
405
|
let Tag;
|
|
354
406
|
switch (shape.group) {
|
|
355
|
-
case
|
|
407
|
+
case SHAPE_GROUPS.RECTANGLES:
|
|
356
408
|
Tag = Rectangle;
|
|
357
409
|
break;
|
|
358
|
-
case
|
|
410
|
+
case SHAPE_GROUPS.CIRCLES:
|
|
359
411
|
Tag = Circle;
|
|
360
412
|
break;
|
|
361
|
-
case
|
|
413
|
+
case SHAPE_GROUPS.POLYGONS:
|
|
362
414
|
Tag = Polygon;
|
|
363
415
|
break;
|
|
364
416
|
default:
|
|
@@ -367,11 +419,11 @@ export class Drawable extends React.Component {
|
|
|
367
419
|
|
|
368
420
|
return (
|
|
369
421
|
<Tag
|
|
422
|
+
{...(shape.group === SHAPE_GROUPS.CIRCLES ? { radius: shape.radius } : {})}
|
|
423
|
+
{...(shape.group === SHAPE_GROUPS.RECTANGLES ? { height: shape.height, width: shape.width } : {})}
|
|
424
|
+
{...(shape.group === SHAPE_GROUPS.POLYGONS ? { points: shape.points, addPolygonPoint: (e) => this.addPolygonPoint(e) } : {})}
|
|
370
425
|
correct={shape.correct}
|
|
371
426
|
isDrawing={isDrawing}
|
|
372
|
-
{...(shape.group === 'circles'
|
|
373
|
-
? { radius: shape.radius }
|
|
374
|
-
: { height: shape.height, width: shape.width })}
|
|
375
427
|
hotspotColor={hotspotColor}
|
|
376
428
|
id={shape.id}
|
|
377
429
|
key={i}
|
|
@@ -382,7 +434,6 @@ export class Drawable extends React.Component {
|
|
|
382
434
|
width={shape.width}
|
|
383
435
|
x={shape.x}
|
|
384
436
|
y={shape.y}
|
|
385
|
-
{...(shape.group === 'polygons' ? { points: shape.points } : {})}
|
|
386
437
|
strokeWidth={strokeWidth}
|
|
387
438
|
imageHeight={heightFromState || height}
|
|
388
439
|
imageWidth={widthFromState || width}
|
|
@@ -432,7 +483,7 @@ Drawable.propTypes = {
|
|
|
432
483
|
disableDrag: PropTypes.func.isRequired,
|
|
433
484
|
dimensions: PropTypes.object.isRequired,
|
|
434
485
|
enableDrag: PropTypes.func.isRequired,
|
|
435
|
-
shapeType: PropTypes.oneOf(
|
|
486
|
+
shapeType: PropTypes.oneOf(Object.values(SUPPORTED_SHAPES)),
|
|
436
487
|
imageUrl: PropTypes.string.isRequired,
|
|
437
488
|
handleFinishDrawing: PropTypes.func.isRequired,
|
|
438
489
|
hotspotColor: PropTypes.string.isRequired,
|
|
@@ -11,39 +11,28 @@ class PolComponent extends React.Component {
|
|
|
11
11
|
const { id, points, imageHeight, imageWidth } = nextProps;
|
|
12
12
|
// we execute this code only if image dimensions changed or an hotspot was added/deleted
|
|
13
13
|
if (
|
|
14
|
-
prevState.imageHeight !==
|
|
15
|
-
prevState.imageWidth !==
|
|
14
|
+
prevState.imageHeight !== imageHeight ||
|
|
15
|
+
prevState.imageWidth !== imageWidth ||
|
|
16
16
|
prevState.id !== nextProps.id ||
|
|
17
|
-
prevState.points
|
|
17
|
+
JSON.stringify(prevState.points) !== JSON.stringify(points)
|
|
18
18
|
) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const y = Math.max(...yList);
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
id,
|
|
28
|
-
x,
|
|
29
|
-
y,
|
|
30
|
-
points,
|
|
31
|
-
imageHeight,
|
|
32
|
-
imageWidth,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
19
|
+
const xList = points.map((p) => p.x);
|
|
20
|
+
const yList = points.map((p) => p.y);
|
|
21
|
+
|
|
22
|
+
const x = Math.min(...xList);
|
|
23
|
+
const y = Math.max(...yList);
|
|
35
24
|
|
|
36
25
|
return {
|
|
37
|
-
id
|
|
38
|
-
x
|
|
39
|
-
y
|
|
40
|
-
points
|
|
26
|
+
id,
|
|
27
|
+
x,
|
|
28
|
+
y,
|
|
29
|
+
points,
|
|
41
30
|
imageHeight,
|
|
42
31
|
imageWidth,
|
|
43
32
|
};
|
|
44
|
-
} else {
|
|
45
|
-
return null;
|
|
46
33
|
}
|
|
34
|
+
|
|
35
|
+
return null;
|
|
47
36
|
}
|
|
48
37
|
|
|
49
38
|
getOffset = (points) => {
|
|
@@ -143,6 +132,10 @@ class PolComponent extends React.Component {
|
|
|
143
132
|
...this.getOffset(newPoints),
|
|
144
133
|
isDragging: updateModel ? false : this.state.isDragging,
|
|
145
134
|
});
|
|
135
|
+
|
|
136
|
+
if (updateModel) {
|
|
137
|
+
onDragEnd(id, { points: newPoints });
|
|
138
|
+
}
|
|
146
139
|
};
|
|
147
140
|
|
|
148
141
|
handleOnDragVertex = (e, changedIndex, updateModel) => {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CircleShape } from './circle';
|
|
2
|
+
import { PolygonShape } from './polygon';
|
|
3
|
+
import { RectangleShape } from './rectagle';
|
|
4
|
+
|
|
5
|
+
export const SUPPORTED_SHAPES = {
|
|
6
|
+
CIRCLE: CircleShape.name,
|
|
7
|
+
POLYGON: PolygonShape.name,
|
|
8
|
+
RECTANGLE: RectangleShape.name,
|
|
9
|
+
NONE: 'none',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const SHAPE_GROUPS = {
|
|
13
|
+
CIRCLES: 'circles',
|
|
14
|
+
POLYGONS: 'polygons',
|
|
15
|
+
RECTANGLES: 'rectangles',
|
|
16
|
+
};
|
package/configure/src/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import cloneDeep from 'lodash/cloneDeep';
|
|
2
|
+
import { SHAPE_GROUPS } from './shapes';
|
|
2
3
|
|
|
3
4
|
const updateImageDimensions = (initialDim, nextDim, keepAspectRatio, resizeType) => {
|
|
4
5
|
// if we want to keep image aspect ratio
|
|
@@ -43,12 +44,12 @@ const getUpdatedRectangle = (initialDim, nextDim, shape) => ({
|
|
|
43
44
|
|
|
44
45
|
const getUpdatedCircles = (initialDim, nextDim, shape) => ({
|
|
45
46
|
...shape,
|
|
46
|
-
radius: getDelta(initialDim.
|
|
47
|
+
radius: getDelta(initialDim.width, nextDim.width, shape.radius),
|
|
47
48
|
x: getDelta(initialDim.width, nextDim.width, shape.x),
|
|
48
49
|
y: getDelta(initialDim.height, nextDim.height, shape.y),
|
|
49
50
|
});
|
|
50
51
|
|
|
51
|
-
const
|
|
52
|
+
const getUpdatedPolygon = (initialDim, nextDim, shape) => ({
|
|
52
53
|
...shape,
|
|
53
54
|
points: shape.points.map((point) => ({
|
|
54
55
|
x: getDelta(initialDim.width, nextDim.width, point.x),
|
|
@@ -61,15 +62,15 @@ const getUpdatedPlygon = (initialDim, nextDim, shape) => ({
|
|
|
61
62
|
// shapes = array of shapes that have to be re-sized and re-positioned
|
|
62
63
|
const getUpdatedShapes = (initialDim, nextDim, shapes) => {
|
|
63
64
|
return shapes.map((shape) => {
|
|
64
|
-
if (shape.group ===
|
|
65
|
+
if (shape.group === SHAPE_GROUPS.RECTANGLES) {
|
|
65
66
|
return getUpdatedRectangle(initialDim, nextDim, shape);
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
if (shape.group ===
|
|
69
|
-
return
|
|
69
|
+
if (shape.group === SHAPE_GROUPS.POLYGONS) {
|
|
70
|
+
return getUpdatedPolygon(initialDim, nextDim, shape);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
if (shape.group ===
|
|
73
|
+
if (shape.group === SHAPE_GROUPS.CIRCLES) {
|
|
73
74
|
return getUpdatedCircles(initialDim, nextDim, shape);
|
|
74
75
|
}
|
|
75
76
|
});
|
|
@@ -205,5 +206,5 @@ export {
|
|
|
205
206
|
getAllShapes,
|
|
206
207
|
groupShapes,
|
|
207
208
|
getUpdatedRectangle,
|
|
208
|
-
|
|
209
|
+
getUpdatedPolygon,
|
|
209
210
|
};
|