Gitlab CSE Unil

Commit 23f1bc47 authored by Julien Furrer's avatar Julien Furrer
Browse files

Small improvements on Arrows

small changes in shape
shift-key while resizing will keep ratio
parent 65d25fde
......@@ -17,17 +17,6 @@ define(["paper"], function (paper) {
fill: true
};
// var confidenceStyle = {
// "1": {
// dashArray: [10, 10]
// },
// "2": {
// dashArray: [30, 10]
// },
// "3": {
// dashArray: null
// }
// };
var _transparent = new paper.Color([0,0,0,0]);
......@@ -86,15 +75,19 @@ define(["paper"], function (paper) {
// ----- Item -----------------------------------------
var _arrowSymbol;
var _arrowSymbol,
_arrowLeftMostPt,
_arrowHeadLeftMostPt,
_arrowRightMostPt,
_arrowMinLength;
function initArrowSymbol() {
if (_arrowSymbol)
return;
var defPath = new paper.Path({
segments: [
[0, -10],
[0 , 10],
[0, -2],
[0 , 2],
new paper.Segment([20, 5]), //, [-40, 0]),
[10, 30],
new paper.Segment([50, 0]), //, [-15, 0], [-15, 0]),
......@@ -105,6 +98,11 @@ define(["paper"], function (paper) {
strokeScaling: false,
closed: true
});
_arrowLeftMostPt = 1;
_arrowHeadLeftMostPt = 3;
_arrowRightMostPt = 4;
_arrowMinLength = defPath.segments[_arrowHeadLeftMostPt].point.x - defPath.segments[_arrowLeftMostPt].point.x;
_arrowSymbol = new paper.Symbol(defPath);
defPath.remove();
}
......@@ -112,18 +110,18 @@ define(["paper"], function (paper) {
function _hitArrowHead(point, arrowItem) {
arrowItem = arrowItem || this;
var a = arrowItem.symbol.definition.segments[2].point.x,
b = arrowItem.symbol.definition.segments[4].point.x,
b = arrowItem.symbol.definition.segments[_arrowRightMostPt].point.x,
c = arrowItem.globalToLocal(point).x;
return ((c - a) / (b - a)) > 0.3;
return ((c - a) / (b - a)) > 0.1;
}
function _minArrowLength(length, arrowItem) {
arrowItem = arrowItem || this;
length = length || (
arrowItem.symbol.definition.segments[4].point.x - arrowItem.symbol.definition.segments[1].point.x
arrowItem.symbol.definition.segments[_arrowRightMostPt].point.x - arrowItem.symbol.definition.segments[_arrowLeftMostPt].point.x
);
var b = (arrowItem.symbol.definition.segments[4].point.x - arrowItem.symbol.definition.segments[3].point.x);
return (length - b) < 10;
var b = (arrowItem.symbol.definition.segments[_arrowRightMostPt].point.x - arrowItem.symbol.definition.segments[_arrowHeadLeftMostPt].point.x);
return (length - b) < _arrowMinLength;
}
......@@ -320,7 +318,8 @@ define(["paper"], function (paper) {
// projection of the mouse point on the axe of the arrow. relative vector (centered at the origin)
var p = event.point.subtract(param.from).project(param.to.subtract(param.from));
var h_fact = p.length / this.symbol.definition.bounds.width;
var v_fact = event.point.subtract(p.add(param.from)).length / this.symbol.definition.bounds.height * 2;
var v_fact = (event.event.shiftKey) ? h_fact :
event.point.subtract(p.add(param.from)).length / this.symbol.definition.bounds.height * 2;
_scaleArrow.call(this, {h:h_fact, v:v_fact});
// console.clear();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment