mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-09 18:39:41 +02:00
#1295 Styling of composite states
This commit is contained in:
@@ -14,9 +14,6 @@
|
|||||||
.mermaid2 {
|
.mermaid2 {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.mermaid-apa #pointEnd {
|
|
||||||
fill: green !important;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -41,7 +38,7 @@
|
|||||||
end
|
end
|
||||||
a-->id1
|
a-->id1
|
||||||
</div>
|
</div>
|
||||||
<div class="mermaid mermaid-apa" style="width: 100%; height: 20%;">
|
<div class="mermaid2 mermaid-apa" style="width: 100%; height: 20%;">
|
||||||
stateDiagram-v2
|
stateDiagram-v2
|
||||||
[*] --> Still
|
[*] --> Still
|
||||||
[*] --> Moving
|
[*] --> Moving
|
||||||
@@ -57,6 +54,24 @@
|
|||||||
Moving --> Crash
|
Moving --> Crash
|
||||||
Crash --> [*]
|
Crash --> [*]
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mermaid" style="width: 100%; height: 100%;">
|
||||||
|
stateDiagram-v2
|
||||||
|
[*] --> First
|
||||||
|
|
||||||
|
state First {
|
||||||
|
[*] --> Second
|
||||||
|
|
||||||
|
state Second {
|
||||||
|
[*] --> second
|
||||||
|
second --> Third
|
||||||
|
|
||||||
|
state Third {
|
||||||
|
[*] --> third
|
||||||
|
third --> [*]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</div>
|
||||||
<div class="mermaid2" style="width: 100%; height: 100%;">
|
<div class="mermaid2" style="width: 100%; height: 100%;">
|
||||||
stateDiagram-v2
|
stateDiagram-v2
|
||||||
[*]-->TV
|
[*]-->TV
|
||||||
|
@@ -55,7 +55,66 @@ const rect = (parent, node) => {
|
|||||||
return shapeSvg;
|
return shapeSvg;
|
||||||
};
|
};
|
||||||
|
|
||||||
const shapes = { rect };
|
const roundedWithTitle = (parent, node) => {
|
||||||
|
// Add outer g element
|
||||||
|
const shapeSvg = parent
|
||||||
|
.insert('g')
|
||||||
|
.attr('class', node.class)
|
||||||
|
.attr('id', node.id);
|
||||||
|
|
||||||
|
// add the rect
|
||||||
|
const rect = shapeSvg.insert('rect', ':first-child');
|
||||||
|
|
||||||
|
// Create the label and insert it after the rect
|
||||||
|
const label = shapeSvg.insert('g').attr('class', 'cluster-label');
|
||||||
|
const innerRect = shapeSvg.append('rect');
|
||||||
|
|
||||||
|
const text = label.node().appendChild(createLabel(node.labelText, node.labelStyle));
|
||||||
|
|
||||||
|
// Get the size of the label
|
||||||
|
const bbox = text.getBBox();
|
||||||
|
|
||||||
|
const padding = 0 * node.padding;
|
||||||
|
const halfPadding = padding / 2;
|
||||||
|
|
||||||
|
// center the rect around its coordinate
|
||||||
|
rect
|
||||||
|
.attr('class', 'outer')
|
||||||
|
.attr('x', node.x - node.width / 2 - halfPadding)
|
||||||
|
.attr('y', node.y - node.height / 2 - halfPadding)
|
||||||
|
.attr('width', node.width + padding)
|
||||||
|
.attr('height', node.height + padding);
|
||||||
|
innerRect
|
||||||
|
.attr('class', 'inner')
|
||||||
|
.attr('x', node.x - node.width / 2 - halfPadding)
|
||||||
|
.attr('y', node.y - node.height / 2 - halfPadding + bbox.height - 1)
|
||||||
|
.attr('width', node.width + padding)
|
||||||
|
.attr('height', node.height + padding - bbox.height - 3);
|
||||||
|
|
||||||
|
// logger.info('bbox', bbox.width, node.x, node.width);
|
||||||
|
// Center the label
|
||||||
|
// label.attr('transform', 'translate(' + adj + ', ' + (node.y - node.height / 2) + ')');
|
||||||
|
label.attr(
|
||||||
|
'transform',
|
||||||
|
'translate(' +
|
||||||
|
(node.x - bbox.width / 2) +
|
||||||
|
', ' +
|
||||||
|
(node.y - node.height / 2 - node.padding / 3 + 3) +
|
||||||
|
')'
|
||||||
|
);
|
||||||
|
|
||||||
|
const rectBox = rect.node().getBBox();
|
||||||
|
node.width = rectBox.width;
|
||||||
|
node.height = rectBox.height;
|
||||||
|
|
||||||
|
node.intersect = function(point) {
|
||||||
|
return intersectRect(node, point);
|
||||||
|
};
|
||||||
|
|
||||||
|
return shapeSvg;
|
||||||
|
};
|
||||||
|
|
||||||
|
const shapes = { rect, roundedWithTitle };
|
||||||
|
|
||||||
let clusterElems = {};
|
let clusterElems = {};
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ export const getClasses = function(text) {
|
|||||||
return stateDb.getClasses();
|
return stateDb.getClasses();
|
||||||
};
|
};
|
||||||
|
|
||||||
const setupNode = (g, parent, node) => {
|
const setupNode = (g, parent, node, altFlag) => {
|
||||||
// Add the node
|
// Add the node
|
||||||
if (node.id !== 'root') {
|
if (node.id !== 'root') {
|
||||||
let shape = 'rect';
|
let shape = 'rect';
|
||||||
@@ -63,6 +63,7 @@ const setupNode = (g, parent, node) => {
|
|||||||
if (!nodeDb[node.id].type && node.doc) {
|
if (!nodeDb[node.id].type && node.doc) {
|
||||||
logger.info('Setting cluser for ', node.id);
|
logger.info('Setting cluser for ', node.id);
|
||||||
nodeDb[node.id].type = 'group';
|
nodeDb[node.id].type = 'group';
|
||||||
|
nodeDb[node.id].shape = 'roundedWithTitle';
|
||||||
}
|
}
|
||||||
|
|
||||||
const nodeData = {
|
const nodeData = {
|
||||||
@@ -71,9 +72,7 @@ const setupNode = (g, parent, node) => {
|
|||||||
shape: nodeDb[node.id].shape,
|
shape: nodeDb[node.id].shape,
|
||||||
label: node.id,
|
label: node.id,
|
||||||
labelText: nodeDb[node.id].description,
|
labelText: nodeDb[node.id].description,
|
||||||
rx: 5,
|
class: altFlag ? 'statediagram-cluster statediagram-cluster-alt' : 'statediagram-cluster', //classStr,
|
||||||
ry: 5,
|
|
||||||
class: 'default', //classStr,
|
|
||||||
style: '', //styles.style,
|
style: '', //styles.style,
|
||||||
id: node.id,
|
id: node.id,
|
||||||
type: nodeDb[node.id].type,
|
type: nodeDb[node.id].type,
|
||||||
@@ -91,18 +90,18 @@ const setupNode = (g, parent, node) => {
|
|||||||
}
|
}
|
||||||
if (node.doc) {
|
if (node.doc) {
|
||||||
logger.trace('Adding nodes children ');
|
logger.trace('Adding nodes children ');
|
||||||
setupDoc(g, node, node.doc);
|
setupDoc(g, node, node.doc, !altFlag);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let cnt = 0;
|
let cnt = 0;
|
||||||
const setupDoc = (g, parent, doc) => {
|
const setupDoc = (g, parent, doc, altFlag) => {
|
||||||
logger.trace('items', doc);
|
logger.trace('items', doc);
|
||||||
doc.forEach(item => {
|
doc.forEach(item => {
|
||||||
if (item.stmt === 'state' || item.stmt === 'default') {
|
if (item.stmt === 'state' || item.stmt === 'default') {
|
||||||
setupNode(g, parent, item, true);
|
setupNode(g, parent, item, altFlag);
|
||||||
} else if (item.stmt === 'relation') {
|
} else if (item.stmt === 'relation') {
|
||||||
setupNode(g, parent, item.state1, true);
|
setupNode(g, parent, item.state1, altFlag);
|
||||||
setupNode(g, parent, item.state2);
|
setupNode(g, parent, item.state2, altFlag);
|
||||||
const edgeData = {
|
const edgeData = {
|
||||||
arrowhead: 'normal',
|
arrowhead: 'normal',
|
||||||
arrowType: 'arrow_barb',
|
arrowType: 'arrow_barb',
|
||||||
@@ -143,7 +142,7 @@ export const draw = function(text, id) {
|
|||||||
// Fetch the default direction, use TD if none was found
|
// Fetch the default direction, use TD if none was found
|
||||||
let dir = stateDb.getDirection();
|
let dir = stateDb.getDirection();
|
||||||
if (typeof dir === 'undefined') {
|
if (typeof dir === 'undefined') {
|
||||||
dir = 'TD';
|
dir = 'LR';
|
||||||
}
|
}
|
||||||
|
|
||||||
const conf = getConfig().state;
|
const conf = getConfig().state;
|
||||||
@@ -156,7 +155,7 @@ export const draw = function(text, id) {
|
|||||||
compound: true
|
compound: true
|
||||||
})
|
})
|
||||||
.setGraph({
|
.setGraph({
|
||||||
rankdir: dir,
|
rankdir: 'LR',
|
||||||
nodesep: nodeSpacing,
|
nodesep: nodeSpacing,
|
||||||
ranksep: rankSpacing,
|
ranksep: rankSpacing,
|
||||||
marginx: 8,
|
marginx: 8,
|
||||||
|
@@ -75,10 +75,6 @@ export const draw = function(text, id) {
|
|||||||
const width = bounds.width + padding * 2;
|
const width = bounds.width + padding * 2;
|
||||||
const height = bounds.height + padding * 2;
|
const height = bounds.height + padding * 2;
|
||||||
|
|
||||||
// diagram.attr('height', '100%');
|
|
||||||
// diagram.attr('style', `width: ${bounds.width * 3 + conf.padding * 2};`);
|
|
||||||
// diagram.attr('height', height);
|
|
||||||
|
|
||||||
// Zoom in a bit
|
// Zoom in a bit
|
||||||
diagram.attr('width', width * 1.75);
|
diagram.attr('width', width * 1.75);
|
||||||
// diagram.attr('height', bounds.height * 3 + conf.padding * 2);
|
// diagram.attr('height', bounds.height * 3 + conf.padding * 2);
|
||||||
@@ -86,15 +82,6 @@ export const draw = function(text, id) {
|
|||||||
'viewBox',
|
'viewBox',
|
||||||
`${bounds.x - conf.padding} ${bounds.y - conf.padding} ` + width + ' ' + height
|
`${bounds.x - conf.padding} ${bounds.y - conf.padding} ` + width + ' ' + height
|
||||||
);
|
);
|
||||||
// diagram.attr('transform', `translate(, 0)`);
|
|
||||||
|
|
||||||
// diagram.attr(
|
|
||||||
// 'viewBox',
|
|
||||||
// `${conf.padding * -1} ${conf.padding * -1} ` +
|
|
||||||
// (bounds.width * 1.5 + conf.padding * 2) +
|
|
||||||
// ' ' +
|
|
||||||
// (bounds.height + conf.padding * 5)
|
|
||||||
// );
|
|
||||||
};
|
};
|
||||||
const getLabelWidth = text => {
|
const getLabelWidth = text => {
|
||||||
return text ? text.length * conf.fontSizeFactor : 1;
|
return text ? text.length * conf.fontSizeFactor : 1;
|
||||||
|
@@ -79,4 +79,23 @@ g.stateGroup line {
|
|||||||
}
|
}
|
||||||
#statediagram-barbEnd {
|
#statediagram-barbEnd {
|
||||||
fill: $nodeBorder
|
fill: $nodeBorder
|
||||||
|
}
|
||||||
|
|
||||||
|
.statediagram-cluster rect {
|
||||||
|
fill: $nodeBkg;
|
||||||
|
stroke: $nodeBorder;
|
||||||
|
stroke-width: 1px;
|
||||||
|
rx: 5px;
|
||||||
|
ry: 5px;
|
||||||
|
}
|
||||||
|
.statediagram-cluster.statediagram-cluster .inner {
|
||||||
|
fill: white;
|
||||||
|
}
|
||||||
|
.statediagram-cluster.statediagram-cluster-alt .inner {
|
||||||
|
fill: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.statediagram-cluster .inner {
|
||||||
|
rx:0;
|
||||||
|
ry:0;
|
||||||
}
|
}
|
Reference in New Issue
Block a user