mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-08 10:06:40 +02:00
Added rendering for annotations
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
node_modules/
|
node_modules/
|
||||||
coverage/
|
coverage/
|
||||||
|
.idea/
|
||||||
|
|
||||||
dist/*.js
|
dist/*.js
|
||||||
dist/*.map
|
dist/*.map
|
||||||
|
@@ -15,7 +15,8 @@ export const addClass = function(id) {
|
|||||||
classes[id] = {
|
classes[id] = {
|
||||||
id: id,
|
id: id,
|
||||||
methods: [],
|
methods: [],
|
||||||
members: []
|
members: [],
|
||||||
|
annotations: []
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -261,9 +261,26 @@ const drawClass = function(elem, classDef) {
|
|||||||
.attr('class', 'classGroup');
|
.attr('class', 'classGroup');
|
||||||
const title = g
|
const title = g
|
||||||
.append('text')
|
.append('text')
|
||||||
.attr('x', conf.padding)
|
|
||||||
.attr('y', conf.textHeight + conf.padding)
|
.attr('y', conf.textHeight + conf.padding)
|
||||||
.text(classDef.id);
|
.attr('x', 0);
|
||||||
|
|
||||||
|
// TODO: remove testing code
|
||||||
|
classDef.annotations = ['interface', 'injected'];
|
||||||
|
|
||||||
|
// add annotations
|
||||||
|
let isFirst = true;
|
||||||
|
classDef.annotations.forEach(function(member) {
|
||||||
|
const titleText2 = title.append('tspan').text('«' + member + '»');
|
||||||
|
if (!isFirst) titleText2.attr('dy', conf.textHeight);
|
||||||
|
isFirst = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// add class title
|
||||||
|
title
|
||||||
|
.append('tspan')
|
||||||
|
.text(classDef.id)
|
||||||
|
.attr('class', 'title')
|
||||||
|
.attr('dy', conf.textHeight);
|
||||||
|
|
||||||
const titleHeight = title.node().getBBox().height;
|
const titleHeight = title.node().getBBox().height;
|
||||||
|
|
||||||
@@ -280,7 +297,7 @@ const drawClass = function(elem, classDef) {
|
|||||||
.attr('fill', 'white')
|
.attr('fill', 'white')
|
||||||
.attr('class', 'classText');
|
.attr('class', 'classText');
|
||||||
|
|
||||||
let isFirst = true;
|
isFirst = true;
|
||||||
classDef.members.forEach(function(member) {
|
classDef.members.forEach(function(member) {
|
||||||
addTspan(members, member, isFirst);
|
addTspan(members, member, isFirst);
|
||||||
isFirst = false;
|
isFirst = false;
|
||||||
@@ -315,6 +332,12 @@ const drawClass = function(elem, classDef) {
|
|||||||
.attr('width', classBox.width + 2 * conf.padding)
|
.attr('width', classBox.width + 2 * conf.padding)
|
||||||
.attr('height', classBox.height + conf.padding + 0.5 * conf.dividerMargin);
|
.attr('height', classBox.height + conf.padding + 0.5 * conf.dividerMargin);
|
||||||
|
|
||||||
|
// Center title
|
||||||
|
title.node().childNodes.forEach(function(x) {
|
||||||
|
console.dir(x.getBBox());
|
||||||
|
x.setAttribute('x', (classBox.width + 2 * conf.padding - x.getBBox().width) / 2);
|
||||||
|
});
|
||||||
|
|
||||||
membersLine.attr('x2', classBox.width + 2 * conf.padding);
|
membersLine.attr('x2', classBox.width + 2 * conf.padding);
|
||||||
methodsLine.attr('x2', classBox.width + 2 * conf.padding);
|
methodsLine.attr('x2', classBox.width + 2 * conf.padding);
|
||||||
|
|
||||||
|
@@ -3,6 +3,10 @@ g.classGroup text {
|
|||||||
stroke: none;
|
stroke: none;
|
||||||
font-family: 'trebuchet ms', verdana, arial;
|
font-family: 'trebuchet ms', verdana, arial;
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-weight: bolder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g.classGroup rect {
|
g.classGroup rect {
|
||||||
|
Reference in New Issue
Block a user