feat(arch): implemented group icons

This commit is contained in:
NicolasNewman
2024-04-18 10:03:20 -05:00
parent 1d27fac4d9
commit 84f1d82aac
3 changed files with 19 additions and 4 deletions

View File

@@ -19,7 +19,7 @@
<h2>Simple diagram with groups</h2> <h2>Simple diagram with groups</h2>
<pre class="mermaid"> <pre class="mermaid">
architecture architecture
group api[API] group api(cloud)[API]
service db(database)[Database] in api service db(database)[Database] in api
service disk1(disk)[Storage] in api service disk1(disk)[Storage] in api

View File

@@ -265,7 +265,7 @@ function layoutArchitecture(
selector: '.node-group', selector: '.node-group',
style: { style: {
// @ts-ignore Incorrect library types // @ts-ignore Incorrect library types
padding: '30px', padding: '40px',
}, },
}, },
], ],

View File

@@ -150,8 +150,23 @@ export const drawGroups = function (groupsEl: D3Element, cy: cytoscape.Core) {
.attr('height', h) .attr('height', h)
.attr('class', 'node-bkg'); .attr('class', 'node-bkg');
const groupLabelContainer = groupsEl.append('g');
let shiftedX1 = x1;
let shiftedY1 = y1;
if (data.icon) {
const bkgElem = groupLabelContainer.append('g');
// TODO: magic number
getIcon(data.icon)?.(bkgElem, 32);
bkgElem.attr(
'transform',
'translate(' + (shiftedX1 + halfIconSize + 1) + ', ' + (shiftedY1 + halfIconSize + 1) + ')'
);
shiftedX1 += 32;
// TODO: proper values once dynamic sizes are implemented
shiftedY1 += 4;
}
if (data.label) { if (data.label) {
const textElem = groupsEl.append('g'); const textElem = groupLabelContainer.append('g');
createText( createText(
textElem, textElem,
data.label, data.label,
@@ -170,7 +185,7 @@ export const drawGroups = function (groupsEl: D3Element, cy: cytoscape.Core) {
textElem.attr( textElem.attr(
'transform', 'transform',
'translate(' + (x1 + halfIconSize + 4) + ', ' + (y1 + halfIconSize + 2) + ')' 'translate(' + (shiftedX1 + halfIconSize + 4) + ', ' + (shiftedY1 + halfIconSize + 2) + ')'
); );
} }
} }