Skip to content

Commit 9021361

Browse files
over-uml improvements - dynamic block sizes, colored labels, fixes
1 parent 0bcac39 commit 9021361

File tree

6 files changed

+94
-41
lines changed

6 files changed

+94
-41
lines changed

web/css/classView.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,22 @@ text {
3636

3737
.uml-class-name-text:hover {
3838
fill: red;
39+
}
40+
41+
.uml-class-attrs-label {
42+
font-family: monospace;
43+
font-weight: 900;
44+
fill: orange;
45+
}
46+
47+
.uml-class-methods-label {
48+
font-family: monospace;
49+
font-weight: 900;
50+
fill: blue;
51+
}
52+
53+
.uml-class-params-label {
54+
font-family: monospace;
55+
font-weight: 900;
56+
fill: magenta;
3957
}

web/css/joint.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/js/ClassView.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,26 @@ ClassView.prototype.openClassDoc = function (className, nameSpace) {
7979
*/
8080
ClassView.prototype.createClassInstance = function (name, classMetaData) {
8181

82-
var attrArr, methArr, nameArr,
83-
classParams = classMetaData["parameters"],
82+
var classParams = classMetaData["parameters"],
8483
classProps = classMetaData["properties"],
8584
classMethods = classMetaData["methods"],
8685
self = this;
8786

8887
var insertString = function (array, string, extraString) {
89-
string.match(/.{1,44}/g).forEach(function (p) {
90-
array.push(p + (extraString ? extraString : ""));
91-
});
88+
array.push(string + (extraString ? extraString : ""));
9289
};
9390

9491
return new joint.shapes.uml.Class({
95-
name: nameArr = (classMetaData["ABSTRACT"] ? ["<<Abstract>>", name] : [name]),
96-
attributes: attrArr = (function (params, ps) {
92+
name: (classMetaData["ABSTRACT"] ? ["<<Abstract>>", name] : [name]),
93+
params: (function (params) {
9794
var arr = [], n;
9895
for (n in params) {
9996
insertString(arr, n + (params[n]["type"] ? ": " + params[n]["type"] : ""));
10097
}
98+
return arr;
99+
})(classParams),
100+
attributes: (function (ps) {
101+
var arr = [], n;
101102
for (n in ps) {
102103
insertString(
103104
arr,
@@ -106,8 +107,8 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
106107
);
107108
}
108109
return arr;
109-
})(classParams, classProps),
110-
methods: methArr = (function (met) {
110+
})(classProps),
111+
methods: (function (met) {
111112
var arr = [], n;
112113
for (n in met) {
113114
insertString(
@@ -126,11 +127,6 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
126127
nameClickHandler: function () {
127128
self.openClassDoc(name, classMetaData["NAMESPACE"]);
128129
}
129-
},
130-
size: {
131-
width: 300,
132-
height: Math.max(nameArr.length*12.1, 0) + Math.max(attrArr.length*12.1, 0)
133-
+ Math.max(methArr.length*12.1, 0) + 30
134130
}
135131
});
136132

web/js/Lib.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ Lib.prototype.load = function (url, data, callback) {
1515

1616
xhr.onreadystatechange = function () {
1717
if (xhr.readyState === 4 && xhr.status === 200) {
18-
try {
18+
//try {
1919
return callback(null, JSON.parse(xhr.responseText) || {})
20-
} catch (e) {
21-
console.error(e);
22-
return callback(
23-
"<h1>Unable to parse server response</h1><p>" + xhr.responseText + "</p>",
24-
null
25-
);
26-
}
20+
//} catch (e) {
21+
// console.error(e);
22+
// return callback(
23+
// "<h1>Unable to parse server response</h1><p>" + xhr.responseText + "</p>",
24+
// null
25+
// );
26+
//}
2727
} else if (xhr.readyState === 4) {
2828
callback(xhr.responseText + ", " + xhr.status + ": " + xhr.statusText);
2929
}

web/jsLib/joint.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17145,7 +17145,7 @@ if ( typeof window === "object" && typeof window.document === "object" ) {
1714517145
// in the top left corner we translate the `<text>` element by `0.8em`.
1714617146
// See `http://www.w3.org/Graphics/SVG/WG/wiki/How_to_determine_dominant_baseline`.
1714717147
// See also `http://apike.ca/prog_svg_text_style.html`.
17148-
this.attr('y', '0.8em');
17148+
this.attr('y', opt.paddingTop || '0.8em');
1714917149

1715017150
// An empty text gets rendered into the DOM in webkit-based browsers.
1715117151
// In order to unify this behaviour across all browsers
@@ -20943,9 +20943,7 @@ joint.dia.ElementView = joint.dia.CellView.extend({
2094320943
// Vectorizer `text()` method sets on the element its own attributes and it has to be possible
2094420944
// to rewrite them, if needed. (i.e display: 'none')
2094520945
if (!_.isUndefined(attrs.text)) {
20946-
2094720946
$selected.each(function() {
20948-
2094920947
V(this).text(attrs.text + '', attrs);
2095020948
});
2095120949
specialAttributes.push('lineHeight','textPath');

web/jsLib/joint.shapes.uml.js

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,56 @@ joint.shapes.uml.Class = joint.shapes.basic.Generic.extend({
2727
markup: [
2828
'<g class="rotatable">',
2929
'<g class="scalable">',
30-
'<rect class="uml-class-name-rect"/><rect class="uml-class-attrs-rect"/><rect class="uml-class-methods-rect"/>',
30+
'<rect class="uml-class-name-rect"/><rect class="uml-class-params-rect"/><text class="uml-class-params-label">Parameters</text><rect class="uml-class-attrs-rect"/><text class="uml-class-attrs-label">Properties</text><rect class="uml-class-methods-rect"/><text class="uml-class-methods-label">Methods</text>',
3131
'</g>',
32-
'<text class="uml-class-name-text"/><text class="uml-class-attrs-text"/><text class="uml-class-methods-text"/>',
32+
'<text class="uml-class-name-text"/><text class="uml-class-params-text"/><text class="uml-class-attrs-text"/><text class="uml-class-methods-text"/>',
3333
'</g>'
3434
].join(''),
3535

3636
defaults: joint.util.deepSupplement({
3737

3838
type: 'uml.Class',
3939

40+
size: { width: 300, height: 300 },
41+
4042
attrs: {
4143
rect: { 'width': 200 },
4244

4345
'.uml-class-name-rect': { 'stroke': 'black', 'stroke-width': 1, 'fill': '#3498db' },
46+
'.uml-class-params-rect': { 'stroke': 'black', 'stroke-width': 1, 'fill': 'white' },
4447
'.uml-class-attrs-rect': { 'stroke': 'black', 'stroke-width': 1, 'fill': '#2980b9' },
4548
'.uml-class-methods-rect': { 'stroke': 'black', 'stroke-width': 1, 'fill': '#2980b9' },
4649

4750
'.uml-class-name-text': {
4851
'ref': '.uml-class-name-rect', 'ref-y': .5, 'ref-x': .5, 'text-anchor': 'middle', 'y-alignment': 'middle', 'font-weight': 'bold',
49-
'fill': 'black', 'font-size': 12, 'font-family': 'Times New Roman'
52+
'fill': 'black', 'font-size': 12
53+
},
54+
'.uml-class-params-text': {
55+
'ref': '.uml-class-params-rect', 'ref-y': 5, 'ref-x': 5,
56+
'fill': 'black', 'font-size': 12
5057
},
5158
'.uml-class-attrs-text': {
5259
'ref': '.uml-class-attrs-rect', 'ref-y': 5, 'ref-x': 5,
53-
'fill': 'black', 'font-size': 12, 'font-family': 'Times New Roman'
60+
'fill': 'black', 'font-size': 12
5461
},
5562
'.uml-class-methods-text': {
5663
'ref': '.uml-class-methods-rect', 'ref-y': 5, 'ref-x': 5,
57-
'fill': 'black', 'font-size': 12, 'font-family': 'Times New Roman'
64+
'fill': 'black', 'font-size': 12
65+
},
66+
'.uml-class-attrs-label': {
67+
ref: '.uml-class-attrs-label', fill: "black", 'font-size': 10,
68+
xPos: -56
69+
},
70+
'.uml-class-methods-label': {
71+
ref: '.uml-class-methods-label', fill: "black", 'font-size': 10
72+
},
73+
'.uml-class-params-label': {
74+
ref: '.uml-class-methods-label', fill: "black", 'font-size': 10
5875
}
5976
},
6077

6178
name: [],
79+
params: [],
6280
attributes: [],
6381
methods: []
6482

@@ -68,7 +86,7 @@ joint.shapes.uml.Class = joint.shapes.basic.Generic.extend({
6886

6987
this.on('change:name change:attributes change:methods', function() {
7088
this.updateRectangles();
71-
this.trigger('uml-update');
89+
this.trigger('uml-update');
7290
}, this);
7391

7492
this.updateRectangles();
@@ -87,31 +105,55 @@ joint.shapes.uml.Class = joint.shapes.basic.Generic.extend({
87105

88106
var rects = [
89107
{ type: 'name', text: this.getClassName() },
108+
{ type: 'params', text: this.get('params') },
90109
{ type: 'attrs', text: this.get('attributes') },
91110
{ type: 'methods', text: this.get('methods') }
92111
];
93112

94-
var offsetY = 0;
113+
var offsetY = 0,
114+
maxWidth = 100;
95115

96116
var dp = self.get("directProps") || {},
97117
nameClickHandler = dp.nameClickHandler;
98118

119+
_.each(rects, function (rect) {
120+
(rect.text instanceof Array ? rect.text : [rect.text]).forEach(function (s) { var t = s.split("\x1b")[0].length*6.66 + 8; if (t > maxWidth) {
121+
maxWidth = t;
122+
}});
123+
});
124+
125+
this.attributes.size.width = maxWidth; // max width assign
126+
99127
_.each(rects, function(rect) {
100128

101-
var lines = _.isArray(rect.text) ? rect.text : [rect.text];
102-
var rectHeight = lines.length * 20 + 20;
129+
var lines = _.isArray(rect.text) ? rect.text : [rect.text],
130+
rectHeight = lines.length * 12 + (lines.length ? 10 : 0),
131+
rectText = attrs['.uml-class-' + rect.type + '-text'],
132+
rectRect = attrs['.uml-class-' + rect.type + '-rect'],
133+
rectLabel = attrs['.uml-class-' + rect.type + '-label'];
103134

104-
attrs['.uml-class-' + rect.type + '-text'].text = lines.join('\n');
135+
rectText.text = lines.join('\n');
105136
if (nameClickHandler) {
106137
if (rect.type === "name") {
107-
attrs['.uml-class-' + rect.type + '-text'].clickHandler = nameClickHandler;
138+
rectText.clickHandler = nameClickHandler;
139+
}
140+
}
141+
rectRect.transform = 'translate(0,'+ offsetY + ')';
142+
if (rectLabel) {
143+
if (lines.length) {
144+
rectText.paddingTop = "17px"; rectHeight += 5;
145+
rectLabel.transform = 'translate(' + (2) + ','+ (offsetY + 9) + ')';
146+
} else {
147+
rectLabel.display = "none";
108148
}
109149
}
110-
attrs['.uml-class-' + rect.type + '-rect'].height = rectHeight;
111-
attrs['.uml-class-' + rect.type + '-rect'].transform = 'translate(0,'+ offsetY + ')';
150+
rectRect.height = rectHeight;
112151
offsetY += rectHeight;
113152

114153
});
154+
155+
this.attributes.size.height = offsetY;
156+
this.attributes.attrs.rect.width = maxWidth;
115157
}
116158

117159
});
@@ -135,6 +177,7 @@ joint.shapes.uml.Abstract = joint.shapes.uml.Class.extend({
135177
type: 'uml.Abstract',
136178
attrs: {
137179
'.uml-class-name-rect': { fill : '#e74c3c' },
180+
'.uml-class-params-rect': { fill : '#c0392b' },
138181
'.uml-class-attrs-rect': { fill : '#c0392b' },
139182
'.uml-class-methods-rect': { fill : '#c0392b' }
140183
}
@@ -258,12 +301,10 @@ joint.shapes.uml.State = joint.shapes.basic.Generic.extend({
258301
},
259302

260303
updateName: function() {
261-
262304
this.attr('.uml-state-name/text', this.get('name'));
263305
},
264306

265307
updateEvents: function() {
266-
267308
this.attr('.uml-state-events/text', this.get('events').join('\n'));
268309
},
269310

0 commit comments

Comments
 (0)