Skip to content

Commit

Permalink
Fix some lodash incompatibilities. Fixes #158
Browse files Browse the repository at this point in the history
  • Loading branch information
bramp committed Dec 27, 2016
1 parent 64e78ef commit ebb8987
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 34 deletions.
36 changes: 19 additions & 17 deletions dist/sequence-diagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ function clamp(x, min, max) {
}

function wobble(x1, y1, x2, y2) {
assert(_.all([x1,x2,y1,y2], _.isFinite), 'x1,x2,y1,y2 must be numeric');
assert(_.every([x1,x2,y1,y2], _.isFinite), 'x1,x2,y1,y2 must be numeric');

// Wobble no more than 1/25 of the line length
var factor = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) / 25;
Expand Down Expand Up @@ -925,7 +925,7 @@ function wobble(x1, y1, x2, y2) {
* Draws a wobbly (hand drawn) rect
*/
function handRect(x, y, w, h) {
assert(_.all([x, y, w, h], _.isFinite), 'x, y, w, h must be numeric');
assert(_.every([x, y, w, h], _.isFinite), 'x, y, w, h must be numeric');
return 'M' + x + ',' + y +
wobble(x, y, x + w, y) +
wobble(x + w, y, x + w, y + h) +
Expand All @@ -937,7 +937,7 @@ function handRect(x, y, w, h) {
* Draws a wobbly (hand drawn) line
*/
function handLine(x1, y1, x2, y2) {
assert(_.all([x1,x2,y1,y2], _.isFinite), 'x1,x2,y1,y2 must be numeric');
assert(_.every([x1,x2,y1,y2], _.isFinite), 'x1,x2,y1,y2 must be numeric');
return 'M' + x1.toFixed(1) + ',' + y1.toFixed(1) + wobble(x1, y1, x2, y2);
}

Expand Down Expand Up @@ -1001,7 +1001,7 @@ _.extend(BaseTheme.prototype, {
diagram.height += title.height;
}

_.each(actors, function(a) {
_.each(actors, _.bind(function(a) {
var bb = this.textBBox(a.name, font);
a.textBB = bb;

Expand All @@ -1012,7 +1012,7 @@ _.extend(BaseTheme.prototype, {
a.distances = [];
a.paddingRight = 0;
this.actorsHeight_ = Math.max(a.height, this.actorsHeight_);
}, this);
}, this));

function actorEnsureDistance(a, b, d) {
assert(a < b, 'a must be less than or equal to b');
Expand All @@ -1031,14 +1031,13 @@ _.extend(BaseTheme.prototype, {
}
}

_.each(signals, function(s) {
_.each(signals, _.bind(function(s) {
// Indexes of the left and right actors involved
var a;
var b;

var bb = this.textBBox(s.message, font);

//var bb = t.attr("text", s.message).getBBox();
s.textBB = bb;
s.width = bb.width;
s.height = bb.height;
Expand Down Expand Up @@ -1096,7 +1095,7 @@ _.extend(BaseTheme.prototype, {

actorEnsureDistance(a, b, s.width + extraWidth);
this.signalsHeight_ += s.height;
}, this);
}, this));

// Re-jig the positions
var actorsX = 0;
Expand All @@ -1117,7 +1116,7 @@ _.extend(BaseTheme.prototype, {
});

actorsX = a.x + a.width + a.paddingRight;
}, this);
});

diagram.width = Math.max(actorsX, diagram.width);

Expand All @@ -1141,7 +1140,7 @@ _.extend(BaseTheme.prototype, {

drawActors: function(offsetY) {
var y = offsetY;
_.each(this.diagram.actors, function(a) {
_.each(this.diagram.actors, _.bind(function(a) {
// Top box
this.drawActor(a, y, this.actorsHeight_);

Expand All @@ -1153,7 +1152,7 @@ _.extend(BaseTheme.prototype, {
this.drawLine(
aX, y + this.actorsHeight_ - ACTOR_MARGIN,
aX, y + this.actorsHeight_ + ACTOR_MARGIN + this.signalsHeight_);
}, this);
}, this));
},

drawActor: function(actor, offsetY, height) {
Expand All @@ -1164,7 +1163,7 @@ _.extend(BaseTheme.prototype, {

drawSignals: function(offsetY) {
var y = offsetY;
_.each(this.diagram.signals, function(s) {
_.each(this.diagram.signals, _.bind(function(s) {
// TODO Add debug mode, that draws padding/margin box
if (s.type == 'Signal') {
if (s.isSelf()) {
Expand All @@ -1178,7 +1177,7 @@ _.extend(BaseTheme.prototype, {
}

y += s.height;
}, this);
}, this));
},

drawSelfSignal: function(signal, offsetY) {
Expand Down Expand Up @@ -1433,7 +1432,9 @@ if (typeof Snap != 'undefined') {
},

createText: function(text, font) {
text = _.invoke(text.split('\n'), 'trim');
text = text.split('\n').map(function(x) {
return x.trim();
});
var t = this.paper_.text(0, 0, text);
t.attr(font || {});
if (text.length > 1) {
Expand Down Expand Up @@ -1581,7 +1582,7 @@ if (typeof Raphael != 'undefined') {
* Raphaël extras
******************/
Raphael.fn.line = function(x1, y1, x2, y2) {
assert(_.all([x1,x2,y1,y2], _.isFinite), 'x1,x2,y1,y2 must be numeric');
assert(_.every([x1,x2,y1,y2], _.isFinite), 'x1,x2,y1,y2 must be numeric');
return this.path('M{0},{1} L{2},{3}', x1, y1, x2, y2);
};

Expand Down Expand Up @@ -1640,8 +1641,9 @@ if (typeof Raphael != 'undefined') {
* Strip whitespace from each newline
*/
cleanText: function(text) {
text = _.invoke(text.split('\n'), 'trim');
return text.join('\n');
return text.split('\n').map(function(x) {
return x.trim();
}).join('\n');
},

/**
Expand Down
7 changes: 4 additions & 3 deletions src/theme-raphael.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (typeof Raphael != 'undefined') {
* Raphaël extras
******************/
Raphael.fn.line = function(x1, y1, x2, y2) {
assert(_.all([x1,x2,y1,y2], _.isFinite), 'x1,x2,y1,y2 must be numeric');
assert(_.every([x1,x2,y1,y2], _.isFinite), 'x1,x2,y1,y2 must be numeric');
return this.path('M{0},{1} L{2},{3}', x1, y1, x2, y2);
};

Expand Down Expand Up @@ -82,8 +82,9 @@ if (typeof Raphael != 'undefined') {
* Strip whitespace from each newline
*/
cleanText: function(text) {
text = _.invoke(text.split('\n'), 'trim');
return text.join('\n');
return text.split('\n').map(function(x) {
return x.trim();
}).join('\n');
},

/**
Expand Down
4 changes: 3 additions & 1 deletion src/theme-snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ if (typeof Snap != 'undefined') {
},

createText: function(text, font) {
text = _.invoke(text.split('\n'), 'trim');
text = text.split('\n').map(function(x) {
return x.trim();
});
var t = this.paper_.text(0, 0, text);
t.attr(font || {});
if (text.length > 1) {
Expand Down
25 changes: 12 additions & 13 deletions src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function clamp(x, min, max) {
}

function wobble(x1, y1, x2, y2) {
assert(_.all([x1,x2,y1,y2], _.isFinite), 'x1,x2,y1,y2 must be numeric');
assert(_.every([x1,x2,y1,y2], _.isFinite), 'x1,x2,y1,y2 must be numeric');

// Wobble no more than 1/25 of the line length
var factor = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) / 25;
Expand Down Expand Up @@ -122,7 +122,7 @@ function wobble(x1, y1, x2, y2) {
* Draws a wobbly (hand drawn) rect
*/
function handRect(x, y, w, h) {
assert(_.all([x, y, w, h], _.isFinite), 'x, y, w, h must be numeric');
assert(_.every([x, y, w, h], _.isFinite), 'x, y, w, h must be numeric');
return 'M' + x + ',' + y +
wobble(x, y, x + w, y) +
wobble(x + w, y, x + w, y + h) +
Expand All @@ -134,7 +134,7 @@ function handRect(x, y, w, h) {
* Draws a wobbly (hand drawn) line
*/
function handLine(x1, y1, x2, y2) {
assert(_.all([x1,x2,y1,y2], _.isFinite), 'x1,x2,y1,y2 must be numeric');
assert(_.every([x1,x2,y1,y2], _.isFinite), 'x1,x2,y1,y2 must be numeric');
return 'M' + x1.toFixed(1) + ',' + y1.toFixed(1) + wobble(x1, y1, x2, y2);
}

Expand Down Expand Up @@ -198,7 +198,7 @@ _.extend(BaseTheme.prototype, {
diagram.height += title.height;
}

_.each(actors, function(a) {
_.each(actors, _.bind(function(a) {
var bb = this.textBBox(a.name, font);
a.textBB = bb;

Expand All @@ -209,7 +209,7 @@ _.extend(BaseTheme.prototype, {
a.distances = [];
a.paddingRight = 0;
this.actorsHeight_ = Math.max(a.height, this.actorsHeight_);
}, this);
}, this));

function actorEnsureDistance(a, b, d) {
assert(a < b, 'a must be less than or equal to b');
Expand All @@ -228,14 +228,13 @@ _.extend(BaseTheme.prototype, {
}
}

_.each(signals, function(s) {
_.each(signals, _.bind(function(s) {
// Indexes of the left and right actors involved
var a;
var b;

var bb = this.textBBox(s.message, font);

//var bb = t.attr("text", s.message).getBBox();
s.textBB = bb;
s.width = bb.width;
s.height = bb.height;
Expand Down Expand Up @@ -293,7 +292,7 @@ _.extend(BaseTheme.prototype, {

actorEnsureDistance(a, b, s.width + extraWidth);
this.signalsHeight_ += s.height;
}, this);
}, this));

// Re-jig the positions
var actorsX = 0;
Expand All @@ -314,7 +313,7 @@ _.extend(BaseTheme.prototype, {
});

actorsX = a.x + a.width + a.paddingRight;
}, this);
});

diagram.width = Math.max(actorsX, diagram.width);

Expand All @@ -338,7 +337,7 @@ _.extend(BaseTheme.prototype, {

drawActors: function(offsetY) {
var y = offsetY;
_.each(this.diagram.actors, function(a) {
_.each(this.diagram.actors, _.bind(function(a) {
// Top box
this.drawActor(a, y, this.actorsHeight_);

Expand All @@ -350,7 +349,7 @@ _.extend(BaseTheme.prototype, {
this.drawLine(
aX, y + this.actorsHeight_ - ACTOR_MARGIN,
aX, y + this.actorsHeight_ + ACTOR_MARGIN + this.signalsHeight_);
}, this);
}, this));
},

drawActor: function(actor, offsetY, height) {
Expand All @@ -361,7 +360,7 @@ _.extend(BaseTheme.prototype, {

drawSignals: function(offsetY) {
var y = offsetY;
_.each(this.diagram.signals, function(s) {
_.each(this.diagram.signals, _.bind(function(s) {
// TODO Add debug mode, that draws padding/margin box
if (s.type == 'Signal') {
if (s.isSelf()) {
Expand All @@ -375,7 +374,7 @@ _.extend(BaseTheme.prototype, {
}

y += s.height;
}, this);
}, this));
},

drawSelfSignal: function(signal, offsetY) {
Expand Down

0 comments on commit ebb8987

Please sign in to comment.