Setting class names of nodes automatically

This commit is contained in:
Jeff Avallone 2014-12-10 16:57:42 -05:00
parent 60d7cab504
commit 0b85f552c3
14 changed files with 22 additions and 27 deletions

View File

@ -48,11 +48,11 @@
fill: #6b6659;
}
.escape text, .literal text {
.escape text, .charset-escape text, .literal text {
fill: #000;
}
.escape rect {
.escape rect, .charset-escape rect {
fill: #bada55;
}

View File

@ -2,11 +2,9 @@ import _ from 'lodash';
import Base from './base.js';
export default _.extend({}, Base, {
type: 'any_character',
type: 'any-character',
render() {
this.container.addClass('any-character');
this.label = this.renderLabel(this.container, 'any character');
}
});

View File

@ -1,6 +1,11 @@
import _ from 'lodash';
export default {
setContainer(container) {
this.container = container;
this.container.addClass(this.type);
},
getBBox() {
return this.container.getBBox();
},

View File

@ -5,8 +5,6 @@ export default _.extend({}, Base, {
type: 'charset',
render() {
this.container.addClass('charset');
this.label = this.container.text()
.addClass('charset-label')
.attr({
@ -23,7 +21,7 @@ export default _.extend({}, Base, {
this.partContainer = this.container.group();
_.each(this.parts.elements, (part => {
part.container = this.partContainer.group();
part.setContainer(this.partContainer.group());
part.render();
}).bind(this));
},

View File

@ -2,7 +2,7 @@ import _ from 'lodash';
import Escape from './escape.js';
export default _.extend({}, Escape, {
type: 'charset_escape',
type: 'charset-escape',
b: 'backspace'
});

View File

@ -2,13 +2,13 @@ import _ from 'lodash';
import Base from './base.js';
export default _.extend({}, Base, {
type: 'charset_range',
type: 'charset-range',
render() {
this.first.container = this.container.group();
this.first.setContainer(this.container.group());
this.first.render();
this.last.container = this.container.group();
this.last.setContainer(this.container.group());
this.last.render();
this.hyphen = this.container.text()

View File

@ -13,8 +13,6 @@ export default _.extend({}, Base, {
},
render() {
this.container.addClass('escape');
this.label = this.renderLabel(this.container, _.result(this, this.code()));
this.label.select('rect').attr({

View File

@ -5,8 +5,6 @@ export default _.extend({}, Base, {
type: 'literal',
render() {
this.container.addClass('literal');
this.label = this.renderLabel(this.container, '"' + this.literal.textValue + '"');
this.label.select('rect').attr({

View File

@ -15,7 +15,7 @@ export default _.extend({}, Base, {
}
this.contents.parts = _.map(this.parts(), function(part) {
part.container = self.container.group();
part.setContainer(self.container.group());
part.render();
return part;
});

View File

@ -2,10 +2,10 @@ import _ from 'lodash';
import Base from './base.js';
export default _.extend({}, Base, {
type: 'match_fragment',
type: 'match-fragment',
render() {
this._content.container = this.container.group();
this._content.setContainer(this.container.group());
this._content.render();
},

View File

@ -10,7 +10,7 @@ export default _.extend({}, Base, {
this.matchContainer = this.container.group();
_.each(this.matches(), match => {
match.container = self.matchContainer.group();
match.setContainer(self.matchContainer.group());
match.render();
return match.container;
});

View File

@ -5,8 +5,8 @@ export default _.extend({}, Base, {
type: 'root',
render() {
this.regexp.container = this.container.group().transform(Snap.matrix()
.translate(10, 0));
this.regexp.setContainer(this.container.group().transform(Snap.matrix()
.translate(10, 0)));
this.regexp.render();
this.start = this.container.circle()

View File

@ -16,8 +16,6 @@ export default _.extend({}, Base, {
var label = this.groupLabel();
if (label) {
this.container.addClass('subexp');
this.label = this.container.text()
.addClass('subexp-label')
.attr({
@ -31,10 +29,10 @@ export default _.extend({}, Base, {
ry: 3
});
this.regexp.container = this.container.group();
this.regexp.setContainer(this.container.group());
this.regexp.render();
} else {
this.regexp.container = this.container;
this.regexp.setContainer(this.container);
this.regexp.render();
}
},

View File

@ -91,7 +91,7 @@ export default class Regexper {
return Q.fcall(parser.parse.bind(parser), expression)
.then((result) => {
result.container = snap.group();
result.setContainer(snap.group());
result.render();
return result;
}, this.showError.bind(this))