Normalize edge ratios to display numerator > denominator, center labels, use horizontal text

This commit is contained in:
Michael Winter 2026-04-22 10:48:19 +02:00
parent 1953c8b359
commit 8fc949e828

View file

@ -406,6 +406,19 @@
return parseFloat(fracStr); return parseFloat(fracStr);
} }
// Normalize display ratio so numerator >= denominator
function normalizeDisplayRatio(label) {
const parts = label.split('/');
if (parts.length === 2) {
const num = parseInt(parts[0]);
const den = parseInt(parts[1]);
if (num < den) {
return den + '/' + num;
}
}
return label;
}
// Multiply two fractions and return as string // Multiply two fractions and return as string
function multiplyFractions(frac1, frac2) { function multiplyFractions(frac1, frac2) {
const f1 = parseFraction(frac1); const f1 = parseFraction(frac1);
@ -653,8 +666,8 @@
'label': 'data(ratio)', 'label': 'data(ratio)',
'font-size': '12px', 'font-size': '12px',
'color': '#ffffff', 'color': '#ffffff',
'text-rotation': 'autorotate', 'text-rotation': '0deg',
'text-margin-y': -10, 'text-margin-y': 0,
'text-background-color': '#000000', 'text-background-color': '#000000',
'text-background-opacity': 0.8, 'text-background-opacity': 0.8,
'text-background-padding': '2px', 'text-background-padding': '2px',
@ -836,7 +849,7 @@
id: previewEdgeId, id: previewEdgeId,
source: node.id(), source: node.id(),
target: previewGhostId, target: previewGhostId,
ratio: nearestSnap.label, ratio: normalizeDisplayRatio(nearestSnap.label),
} }
}); });
@ -953,7 +966,7 @@
id: edgeId, id: edgeId,
source: node.id(), source: node.id(),
target: ghostId, target: ghostId,
ratio: nearestSnap.label, ratio: normalizeDisplayRatio(nearestSnap.label),
} }
}); });
@ -1286,7 +1299,7 @@
data: { data: {
source: idMap[e.source], source: idMap[e.source],
target: idMap[e.target], target: idMap[e.target],
ratio: e.ratio, ratio: normalizeDisplayRatio(e.ratio),
}, },
}); });
}); });