De-duplicating code to render subexp and charset containers

This commit is contained in:
Jeff Avallone
2014-12-10 18:27:07 -05:00
parent fc7032241f
commit ff7525a6e4
4 changed files with 49 additions and 63 deletions
+3 -30
View File
@@ -5,18 +5,7 @@ export default _.extend({}, Base, {
type: 'charset',
render() {
this.label = this.container.text()
.addClass('charset-label')
.attr({
text: this.invert() ? 'None of:' : 'One of:'
});
this.box = this.container.rect()
.addClass('charset-box')
.attr({
rx: 3,
ry: 3
});
this.renderLabeledBox(this.invert() ? 'None of:' : 'One of:');
this.partContainer = this.container.group();
@@ -27,30 +16,14 @@ export default _.extend({}, Base, {
},
position() {
var box;
_.invoke(this.parts.elements, 'position');
this.spaceVertically(this.parts.elements, {
padding: 5
});
box = this.label.getBBox();
this.label.transform(Snap.matrix()
.translate(0, box.height));
this.partContainer.transform(Snap.matrix()
.translate(5, 5 + box.height));
this.box.transform(Snap.matrix()
.translate(0, box.height));
box = this.partContainer.getBBox();
this.box.attr({
width: box.width + 10,
height: box.height + 10
this.positionLabeledBox(this.partContainer, {
padding: 5
});
},