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; fill: #6b6659;
} }
.escape text, .literal text { .escape text, .charset-escape text, .literal text {
fill: #000; fill: #000;
} }
.escape rect { .escape rect, .charset-escape rect {
fill: #bada55; fill: #bada55;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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