Skip to content

Commit

Permalink
Fixed #9 - Alloy's subset singnature indication missing in instances
Browse files Browse the repository at this point in the history
  • Loading branch information
soaibsafi committed Aug 17, 2024
1 parent c586626 commit ead831b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
37 changes: 36 additions & 1 deletion frontend/src/assets/js/alloyUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export function getGraphData(alloyInstance) {
const nodes = new Set();
const edges = [];
const subsetSigs = new Set();

function getAtomsFromSig(d) {
function searchNestedDict(d) {
Expand All @@ -27,6 +28,21 @@ export function getGraphData(alloyInstance) {
}
}
searchNestedDict(d);

// Handle Subset sigs. Issue #9
const varSigs = d
.filter(item => item.var === "yes" && item.atom)
.flatMap(item => {
const atoms = Array.isArray(item.atom) ? item.atom : [item.atom];
return atoms.map(atomItem => ({
atom: atomItem.label.replace('$', ''), // Remove the $ symbol
label: item.label,
}));
});
varSigs.forEach(item => {
subsetSigs.add(item);
});

}

function processField(field) {
Expand Down Expand Up @@ -116,14 +132,33 @@ export function getGraphData(alloyInstance) {

const nodeList = Array.from(nodes).map(node => ({ "data": { "id": node, "label": node } }));
const elements = nodeList.concat(edges);

// Handle Subset sigs. Issue #9
const atomLabelMap = new Map();
subsetSigs.forEach(item => {
// Group labels by atom
if (atomLabelMap.has(item.atom)) {
atomLabelMap.get(item.atom).push(item.label);
} else {
atomLabelMap.set(item.atom, [item.label]);
}
});
elements.forEach(element => {
const id = element.data.id;
if (atomLabelMap.has(id)) {
const labels = atomLabelMap.get(id);
// Update the element's label by concatenating all related labels
element.data.label = `${id} (${labels.join(', ')})`;
}
});
return elements;
}

export function parseAlloyErrorMessage(error) {
let message = '';
if (error.includes('error') && error.includes('.als') && error.includes('line')) {
message = error.replace(/ in .+\.als/, '');
}else if (error.includes('The required JNI library cannot be found')) {
} else if (error.includes('The required JNI library cannot be found')) {
message = 'The required JNI library cannot be found.';
} else {
message = error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const CytoscapeStylesheet = (uniqueRelationships) => {
shape: 'roundrectangle',
'text-valign': 'center',
'text-halign': 'center',
label: 'data(label)',
'text-wrap': 'wrap',
'text-max-width': '80px',
label: 'data(label)',
},
},
{
Expand Down

0 comments on commit ead831b

Please sign in to comment.