Skip to content

Commit

Permalink
Support creation of Points
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Apr 23, 2024
1 parent 3f00da2 commit 5aced74
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/js/shape_editor/ellipse.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ CreatePoint.prototype.startDrag = function startDrag(startX, startY) {
};

CreatePoint.prototype.drag = function drag(dragX, dragY, shiftKey) {
this.point.updateHandle("end", dragX, dragY, shiftKey);
// no drag behaviour on Point creation
};

CreatePoint.prototype.stopDrag = function stopDrag() {
Expand All @@ -498,7 +498,7 @@ CreatePoint.prototype.stopDrag = function stopDrag() {
}
// on the 'new:shape' trigger, this shape will already be selected
this.point.setSelected(true);
this.manager.addShape(this.ellipse);
this.manager.addShape(this.point);
};


Expand Down
5 changes: 3 additions & 2 deletions src/js/shape_editor/shape_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var ShapeManager = function ShapeManager(elementId, width, height, options) {
options = options || {};

// Keep track of state, strokeColor etc
this.STATES = ["SELECT", "RECT", "LINE", "ARROW", "ELLIPSE", "POLYGON"];
this.STATES = ["SELECT", "RECT", "LINE", "ARROW", "ELLIPSE", "POLYGON", "POINT"];
this._state = "SELECT";
this._strokeColor = "#ff0000";
this._strokeWidth = 2;
Expand Down Expand Up @@ -87,6 +87,7 @@ var ShapeManager = function ShapeManager(elementId, width, height, options) {
ELLIPSE: new CreateEllipse({ manager: this, paper: this.paper }),
LINE: new CreateLine({ manager: this, paper: this.paper }),
ARROW: new CreateArrow({ manager: this, paper: this.paper }),
POINT: new CreatePoint({ manager: this, paper: this.paper }),
};

this.createShape = this.shapeFactories.LINE;
Expand Down Expand Up @@ -172,7 +173,7 @@ ShapeManager.prototype.setState = function setState(state) {
return;
}
// When creating shapes, cover existing shapes with newShapeBg
var shapes = ["RECT", "LINE", "ARROW", "ELLIPSE", "POLYGON"];
var shapes = ["RECT", "LINE", "ARROW", "ELLIPSE", "POLYGON", "POINT"];
if (shapes.indexOf(state) > -1) {
this.newShapeBg.toFront();
this.newShapeBg.attr({ cursor: "crosshair" });
Expand Down
4 changes: 3 additions & 1 deletion src/shapeEditorTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
Line:
<input type="radio" name="state" value="LINE"/> <br>
Arrow:
<input type="radio" name="state" value="ARROW"/>
<input type="radio" name="state" value="ARROW"/> <br>
Point:
<input type="radio" name="state" value="POINT"/>
</div>

<div class="toolbar">
Expand Down

0 comments on commit 5aced74

Please sign in to comment.