2014-12-03 02:02:48 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
import Base from './base.js';
|
|
|
|
|
|
|
|
export default _.extend({}, Base, {
|
2014-12-07 22:38:24 +00:00
|
|
|
type: 'charset',
|
|
|
|
|
|
|
|
render() {
|
|
|
|
this.label = this.container.text()
|
2014-12-10 00:03:50 +00:00
|
|
|
.addClass('charset-label')
|
2014-12-07 22:38:24 +00:00
|
|
|
.attr({
|
|
|
|
text: this.invert() ? 'None of:' : 'One of:'
|
2014-12-09 22:48:44 +00:00
|
|
|
});
|
2014-12-07 22:38:24 +00:00
|
|
|
|
|
|
|
this.box = this.container.rect()
|
|
|
|
.addClass('charset-box')
|
|
|
|
.attr({
|
|
|
|
rx: 3,
|
|
|
|
ry: 3
|
|
|
|
});
|
|
|
|
|
|
|
|
this.partContainer = this.container.group();
|
|
|
|
|
2014-12-09 22:48:44 +00:00
|
|
|
_.each(this.parts.elements, (part => {
|
2014-12-10 21:57:42 +00:00
|
|
|
part.setContainer(this.partContainer.group());
|
2014-12-07 22:38:24 +00:00
|
|
|
part.render();
|
|
|
|
}).bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
position() {
|
2014-12-10 01:08:34 +00:00
|
|
|
var box;
|
2014-12-07 22:38:24 +00:00
|
|
|
|
2014-12-10 01:08:34 +00:00
|
|
|
_.invoke(this.parts.elements, 'position');
|
2014-12-07 22:38:24 +00:00
|
|
|
|
2014-12-10 01:08:34 +00:00
|
|
|
this.spaceVertically(this.parts.elements, {
|
|
|
|
padding: 5
|
|
|
|
});
|
2014-12-07 22:38:24 +00:00
|
|
|
|
2014-12-10 02:00:36 +00:00
|
|
|
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));
|
|
|
|
|
2014-12-07 22:38:24 +00:00
|
|
|
box = this.partContainer.getBBox();
|
|
|
|
|
|
|
|
this.box.attr({
|
|
|
|
width: box.width + 10,
|
|
|
|
height: box.height + 10
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
invert() {
|
|
|
|
return this._invert.textValue !== '';
|
|
|
|
}
|
2014-12-03 02:02:48 +00:00
|
|
|
});
|