Skip to content

Commit 9abfbcd

Browse files
committed
efficiency is good now
1 parent ea57bc8 commit 9abfbcd

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

_site/index.html

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -672,16 +672,22 @@ <h2>Feasibility Rank Plot</h2>
672672
}
673673

674674
// -- 8) Collision‐avoidance for text labels
675-
const usedLabelYs = [];
675+
const usedLabels = []; // Store (x, y) pairs
676676
function placeLabel(px, py, text) {
677-
let labelY = py - 4;
678-
while (usedLabelYs.some(y => Math.abs(y - labelY) < 10)) {
679-
labelY += 10;
677+
let labelY = py + 10; // Start slightly above the point
678+
679+
while (usedLabels.some(([ux, uy]) =>
680+
Math.abs(uy - labelY) < 10 && Math.abs(ux - px) < 20)) {
681+
// Check both y and x distances
682+
683+
labelY += 12;
680684
}
681-
usedLabelYs.push(labelY);
682-
ctx.fillText(text, px + 6, labelY);
685+
686+
usedLabels.push([px, labelY]); // Store both x and y
687+
ctx.fillText(text, px + 4, labelY);
683688
}
684689

690+
685691
// -- 9) Plot each data point
686692
efficiencyData.forEach(d => {
687693
// (a) Convert to pixel

index.html

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -672,16 +672,22 @@ <h2>Feasibility Rank Plot</h2>
672672
}
673673

674674
// -- 8) Collision‐avoidance for text labels
675-
const usedLabelYs = [];
675+
const usedLabels = []; // Store (x, y) pairs
676676
function placeLabel(px, py, text) {
677-
let labelY = py - 4;
678-
while (usedLabelYs.some(y => Math.abs(y - labelY) < 10)) {
679-
labelY += 10;
677+
let labelY = py + 10; // Start slightly above the point
678+
679+
while (usedLabels.some(([ux, uy]) =>
680+
Math.abs(uy - labelY) < 10 && Math.abs(ux - px) < 20)) {
681+
// Check both y and x distances
682+
683+
labelY += 12;
680684
}
681-
usedLabelYs.push(labelY);
682-
ctx.fillText(text, px + 6, labelY);
685+
686+
usedLabels.push([px, labelY]); // Store both x and y
687+
ctx.fillText(text, px + 4, labelY);
683688
}
684689

690+
685691
// -- 9) Plot each data point
686692
efficiencyData.forEach(d => {
687693
// (a) Convert to pixel

0 commit comments

Comments
 (0)