mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-10 02:49:40 +02:00
Merge pull request #2255 from mermaid-js/2253_class_diagram_v2_fixes
2253 class diagram v2 fixes
This commit is contained in:
@@ -43,25 +43,27 @@ export const insertEdgeLabel = (elem, edge) => {
|
|||||||
edge.width = bbox.width;
|
edge.width = bbox.width;
|
||||||
edge.height = bbox.height;
|
edge.height = bbox.height;
|
||||||
|
|
||||||
|
let fo;
|
||||||
if (edge.startLabelLeft) {
|
if (edge.startLabelLeft) {
|
||||||
// Create the actual text element
|
// Create the actual text element
|
||||||
const startLabelElement = createLabel(edge.startLabelLeft, edge.labelStyle);
|
const startLabelElement = createLabel(edge.startLabelLeft, edge.labelStyle);
|
||||||
const startEdgeLabelLeft = elem.insert('g').attr('class', 'edgeTerminals');
|
const startEdgeLabelLeft = elem.insert('g').attr('class', 'edgeTerminals');
|
||||||
const inner = startEdgeLabelLeft.insert('g').attr('class', 'inner');
|
const inner = startEdgeLabelLeft.insert('g').attr('class', 'inner');
|
||||||
inner.node().appendChild(startLabelElement);
|
fo=inner.node().appendChild(startLabelElement);
|
||||||
const slBox = startLabelElement.getBBox();
|
const slBox = startLabelElement.getBBox();
|
||||||
inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');
|
inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');
|
||||||
if (!terminalLabels[edge.id]) {
|
if (!terminalLabels[edge.id]) {
|
||||||
terminalLabels[edge.id] = {};
|
terminalLabels[edge.id] = {};
|
||||||
}
|
}
|
||||||
terminalLabels[edge.id].startLeft = startEdgeLabelLeft;
|
terminalLabels[edge.id].startLeft = startEdgeLabelLeft;
|
||||||
|
setTerminalWidth(fo,bbox);
|
||||||
}
|
}
|
||||||
if (edge.startLabelRight) {
|
if (edge.startLabelRight) {
|
||||||
// Create the actual text element
|
// Create the actual text element
|
||||||
const startLabelElement = createLabel(edge.startLabelRight, edge.labelStyle);
|
const startLabelElement = createLabel(edge.startLabelRight, edge.labelStyle);
|
||||||
const startEdgeLabelRight = elem.insert('g').attr('class', 'edgeTerminals');
|
const startEdgeLabelRight = elem.insert('g').attr('class', 'edgeTerminals');
|
||||||
const inner = startEdgeLabelRight.insert('g').attr('class', 'inner');
|
const inner = startEdgeLabelRight.insert('g').attr('class', 'inner');
|
||||||
startEdgeLabelRight.node().appendChild(startLabelElement);
|
fo=startEdgeLabelRight.node().appendChild(startLabelElement);
|
||||||
inner.node().appendChild(startLabelElement);
|
inner.node().appendChild(startLabelElement);
|
||||||
const slBox = startLabelElement.getBBox();
|
const slBox = startLabelElement.getBBox();
|
||||||
inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');
|
inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');
|
||||||
@@ -70,21 +72,25 @@ export const insertEdgeLabel = (elem, edge) => {
|
|||||||
terminalLabels[edge.id] = {};
|
terminalLabels[edge.id] = {};
|
||||||
}
|
}
|
||||||
terminalLabels[edge.id].startRight = startEdgeLabelRight;
|
terminalLabels[edge.id].startRight = startEdgeLabelRight;
|
||||||
|
setTerminalWidth(fo,bbox);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (edge.endLabelLeft) {
|
if (edge.endLabelLeft) {
|
||||||
// Create the actual text element
|
// Create the actual text element
|
||||||
const endLabelElement = createLabel(edge.endLabelLeft, edge.labelStyle);
|
const endLabelElement = createLabel(edge.endLabelLeft, edge.labelStyle);
|
||||||
const endEdgeLabelLeft = elem.insert('g').attr('class', 'edgeTerminals');
|
const endEdgeLabelLeft = elem.insert('g').attr('class', 'edgeTerminals');
|
||||||
const inner = endEdgeLabelLeft.insert('g').attr('class', 'inner');
|
const inner = endEdgeLabelLeft.insert('g').attr('class', 'inner');
|
||||||
inner.node().appendChild(endLabelElement);
|
fo=inner.node().appendChild(endLabelElement);
|
||||||
const slBox = endLabelElement.getBBox();
|
const slBox = endLabelElement.getBBox();
|
||||||
inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');
|
inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');
|
||||||
|
|
||||||
endEdgeLabelLeft.node().appendChild(endLabelElement);
|
endEdgeLabelLeft.node().appendChild(endLabelElement);
|
||||||
|
|
||||||
if (!terminalLabels[edge.id]) {
|
if (!terminalLabels[edge.id]) {
|
||||||
terminalLabels[edge.id] = {};
|
terminalLabels[edge.id] = {};
|
||||||
}
|
}
|
||||||
terminalLabels[edge.id].endLeft = endEdgeLabelLeft;
|
terminalLabels[edge.id].endLeft = endEdgeLabelLeft;
|
||||||
|
setTerminalWidth(fo,bbox);
|
||||||
}
|
}
|
||||||
if (edge.endLabelRight) {
|
if (edge.endLabelRight) {
|
||||||
// Create the actual text element
|
// Create the actual text element
|
||||||
@@ -92,7 +98,7 @@ export const insertEdgeLabel = (elem, edge) => {
|
|||||||
const endEdgeLabelRight = elem.insert('g').attr('class', 'edgeTerminals');
|
const endEdgeLabelRight = elem.insert('g').attr('class', 'edgeTerminals');
|
||||||
const inner = endEdgeLabelRight.insert('g').attr('class', 'inner');
|
const inner = endEdgeLabelRight.insert('g').attr('class', 'inner');
|
||||||
|
|
||||||
inner.node().appendChild(endLabelElement);
|
fo=inner.node().appendChild(endLabelElement);
|
||||||
const slBox = endLabelElement.getBBox();
|
const slBox = endLabelElement.getBBox();
|
||||||
inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');
|
inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');
|
||||||
|
|
||||||
@@ -101,9 +107,18 @@ export const insertEdgeLabel = (elem, edge) => {
|
|||||||
terminalLabels[edge.id] = {};
|
terminalLabels[edge.id] = {};
|
||||||
}
|
}
|
||||||
terminalLabels[edge.id].endRight = endEdgeLabelRight;
|
terminalLabels[edge.id].endRight = endEdgeLabelRight;
|
||||||
|
setTerminalWidth(fo,bbox);
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function setTerminalWidth(fo, box){
|
||||||
|
if(getConfig().flowchart.htmlLabels && fo){
|
||||||
|
fo.style.width=box.width;
|
||||||
|
fo.style.height=box.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const positionEdgeLabel = (edge, paths) => {
|
export const positionEdgeLabel = (edge, paths) => {
|
||||||
log.info('Moving label abc78 ', edge.id, edge.label, edgeLabels[edge.id]);
|
log.info('Moving label abc78 ', edge.id, edge.label, edgeLabels[edge.id]);
|
||||||
let path = paths.updatedPath ? paths.updatedPath : paths.originalPath;
|
let path = paths.updatedPath ? paths.updatedPath : paths.originalPath;
|
||||||
|
@@ -648,7 +648,11 @@ const class_box = (parent, node) => {
|
|||||||
let classTitleString = node.classData.id;
|
let classTitleString = node.classData.id;
|
||||||
|
|
||||||
if (node.classData.type !== undefined && node.classData.type !== '') {
|
if (node.classData.type !== undefined && node.classData.type !== '') {
|
||||||
classTitleString += '<' + node.classData.type + '>';
|
if (getConfig().flowchart.htmlLabels) {
|
||||||
|
classTitleString += '<' + node.classData.type + '>';
|
||||||
|
} else {
|
||||||
|
classTitleString += '<' + node.classData.type + '>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const classTitleLabel = labelContainer
|
const classTitleLabel = labelContainer
|
||||||
.node()
|
.node()
|
||||||
@@ -668,7 +672,10 @@ const class_box = (parent, node) => {
|
|||||||
}
|
}
|
||||||
const classAttributes = [];
|
const classAttributes = [];
|
||||||
node.classData.members.forEach((str) => {
|
node.classData.members.forEach((str) => {
|
||||||
const parsedText = parseMember(str).displayText;
|
let parsedText = parseMember(str).displayText;
|
||||||
|
if (getConfig().flowchart.htmlLabels) {
|
||||||
|
parsedText = parsedText.replace(/</g, '<').replace(/>/g, '>');
|
||||||
|
}
|
||||||
const lbl = labelContainer
|
const lbl = labelContainer
|
||||||
.node()
|
.node()
|
||||||
.appendChild(createLabel(parsedText, node.labelStyle, true, true));
|
.appendChild(createLabel(parsedText, node.labelStyle, true, true));
|
||||||
@@ -691,10 +698,21 @@ const class_box = (parent, node) => {
|
|||||||
|
|
||||||
const classMethods = [];
|
const classMethods = [];
|
||||||
node.classData.methods.forEach((str) => {
|
node.classData.methods.forEach((str) => {
|
||||||
const parsedText = parseMember(str).displayText;
|
const parsedInfo = parseMember(str);
|
||||||
|
let displayText =parsedInfo.displayText;
|
||||||
|
if (getConfig().flowchart.htmlLabels) {
|
||||||
|
displayText = displayText.replace(/</g, '<').replace(/>/g, '>');
|
||||||
|
}
|
||||||
const lbl = labelContainer
|
const lbl = labelContainer
|
||||||
.node()
|
.node()
|
||||||
.appendChild(createLabel(parsedText, node.labelStyle, true, true));
|
.appendChild(
|
||||||
|
createLabel(
|
||||||
|
displayText,
|
||||||
|
parsedInfo.cssStyle ? parsedInfo.cssStyle : node.labelStyle,
|
||||||
|
true,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
);
|
||||||
let bbox = lbl.getBBox();
|
let bbox = lbl.getBBox();
|
||||||
if (evaluate(getConfig().flowchart.htmlLabels)) {
|
if (evaluate(getConfig().flowchart.htmlLabels)) {
|
||||||
const div = lbl.children[0];
|
const div = lbl.children[0];
|
||||||
|
@@ -207,7 +207,7 @@ export const addRelations = function (relations, g) {
|
|||||||
edgeData.arrowheadStyle = 'fill: #333';
|
edgeData.arrowheadStyle = 'fill: #333';
|
||||||
edgeData.labelpos = 'c';
|
edgeData.labelpos = 'c';
|
||||||
|
|
||||||
if (getConfig().flowchart.htmlLabels && false) { // eslint-disable-line
|
if (getConfig().flowchart.htmlLabels) { // eslint-disable-line
|
||||||
edgeData.labelType = 'html';
|
edgeData.labelType = 'html';
|
||||||
edgeData.label = '<span class="edgeLabel">' + edge.text + '</span>';
|
edgeData.label = '<span class="edgeLabel">' + edge.text + '</span>';
|
||||||
} else {
|
} else {
|
||||||
|
@@ -85,7 +85,7 @@ export const draw = (txt, id) => {
|
|||||||
|
|
||||||
// Compute the position of each group on the pie:
|
// Compute the position of each group on the pie:
|
||||||
var pie = d3pie().value(function (d) {
|
var pie = d3pie().value(function (d) {
|
||||||
return d.value;
|
return d[1];
|
||||||
});
|
});
|
||||||
var dataReady = pie(Object.entries(data));
|
var dataReady = pie(Object.entries(data));
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ export const draw = (txt, id) => {
|
|||||||
.append('path')
|
.append('path')
|
||||||
.attr('d', arcGenerator)
|
.attr('d', arcGenerator)
|
||||||
.attr('fill', function (d) {
|
.attr('fill', function (d) {
|
||||||
return color(d.data.key);
|
return color(d.data[0]);
|
||||||
})
|
})
|
||||||
.attr('class', 'pieCircle');
|
.attr('class', 'pieCircle');
|
||||||
|
|
||||||
@@ -108,11 +108,11 @@ export const draw = (txt, id) => {
|
|||||||
// Use the centroid method to get the best coordinates.
|
// Use the centroid method to get the best coordinates.
|
||||||
svg
|
svg
|
||||||
.selectAll('mySlices')
|
.selectAll('mySlices')
|
||||||
.data(dataReady.filter((value) => value.data.value !== 0))
|
.data(dataReady)
|
||||||
.enter()
|
.enter()
|
||||||
.append('text')
|
.append('text')
|
||||||
.text(function (d) {
|
.text(function (d) {
|
||||||
return ((d.data.value / sum) * 100).toFixed(0) + '%';
|
return ((d.data[1] / sum) * 100).toFixed(0) + '%';
|
||||||
})
|
})
|
||||||
.attr('transform', function (d) {
|
.attr('transform', function (d) {
|
||||||
return 'translate(' + arcGenerator.centroid(d) + ')';
|
return 'translate(' + arcGenerator.centroid(d) + ')';
|
||||||
@@ -150,15 +150,15 @@ export const draw = (txt, id) => {
|
|||||||
.style('stroke', color);
|
.style('stroke', color);
|
||||||
|
|
||||||
legend
|
legend
|
||||||
.data(dataReady.filter((value) => value.data.value !== 0))
|
.data(dataReady)
|
||||||
.append('text')
|
.append('text')
|
||||||
.attr('x', legendRectSize + legendSpacing)
|
.attr('x', legendRectSize + legendSpacing)
|
||||||
.attr('y', legendRectSize - legendSpacing)
|
.attr('y', legendRectSize - legendSpacing)
|
||||||
.text(function (d) {
|
.text(function (d) {
|
||||||
if (parser.yy.getShowData() || conf.showData || conf.pie.showData) {
|
if (parser.yy.getShowData() || conf.showData || conf.pie.showData) {
|
||||||
return d.data.key + ' [' + d.data.value + ']';
|
return d.data[0] + ' [' + d.data[1]+ ']';
|
||||||
} else {
|
} else {
|
||||||
return d.data.key;
|
return d.data[0];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Reference in New Issue
Block a user