Extracting a method to ease readability

This commit is contained in:
Jeff Avallone 2014-12-14 17:03:40 -05:00
parent d216c0fe5f
commit 97b816ffc9

View File

@ -29,35 +29,7 @@ export default _.extend({}, Base, {
});
containerBox = this.getBBox();
paths = _.map(matches, match => {
var box = match.getBBox(),
direction = box.cy > containerBox.cy ? 1 : -1,
distance = Math.abs(box.cy - containerBox.cy),
pathStr;
if (distance >= 15) {
pathStr = [
'M10,{box.cy}m0,{shift}q0,{curve} 10,{curve}',
'M{containerBox.width},{box.cy}m30,{shift}q0,{curve} -10,{curve}'
].join('');
} else {
pathStr = [
'M0,{containerBox.cy}c10,0 10,{anchor.y} 20,{anchor.y}',
'M{containerBox.width},{containerBox.cy}m40,0c-10,0 -10,{anchor.y} -20,{anchor.y}'
].join('');
}
return Snap.format(pathStr, {
containerBox,
box,
shift: -10 * direction,
curve: 10 * direction,
anchor: {
x: box.x + 20,
y: box.cy - containerBox.cy
}
});
});
paths = _.map(matches, this.makeConnectorLine.bind(this, containerBox));
paths.push(Snap.format([
'M0,{box.cy}q10,0 10,-10V{top}',
@ -76,6 +48,36 @@ export default _.extend({}, Base, {
}
},
makeConnectorLine(containerBox, match) {
var box = match.getBBox(),
direction = box.cy > containerBox.cy ? 1 : -1,
distance = Math.abs(box.cy - containerBox.cy),
pathStr;
if (distance >= 15) {
pathStr = [
'M10,{box.cy}m0,{shift}q0,{curve} 10,{curve}',
'M{containerBox.width},{box.cy}m30,{shift}q0,{curve} -10,{curve}'
].join('');
} else {
pathStr = [
'M0,{containerBox.cy}c10,0 10,{anchor.y} 20,{anchor.y}',
'M{containerBox.width},{containerBox.cy}m40,0c-10,0 -10,{anchor.y} -20,{anchor.y}'
].join('');
}
return Snap.format(pathStr, {
containerBox,
box,
shift: -10 * direction,
curve: 10 * direction,
anchor: {
x: box.x + 20,
y: box.cy - containerBox.cy
}
});
},
matches() {
return [this._match].concat(_.map(this._alternates.elements, _.property('match')));
}