Skip to content

Commit 9df9cb6

Browse files
committed
update efficiency
1 parent 9ace374 commit 9df9cb6

File tree

6 files changed

+202
-82
lines changed

6 files changed

+202
-82
lines changed

_site/index.html

Lines changed: 96 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,28 @@ <h2>Feasibility Indicators</h2>
233233

234234
const pirValue = getPIR(pirType, SEM, BM);
235235
// Overwrite the global array with new computed values.
236-
efficiencyData = [];
237-
for (let i = 0; i < SEM.length; i++) {
238-
const methodName = methods[i] ? methods[i] : "Method " + (i + 1);
239-
efficiencyData.push({
240-
method: methodName,
241-
sdf: SDF[i],
242-
pir: pirValue
243-
});
244-
}
236+
// Correct: append new rows without wiping out the existing data
237+
// Append new rows without wiping out the existing data.
238+
const initialLength = efficiencyData.length;
239+
for (let i = 0; i < SEM.length; i++) {
240+
const methodName = methods[i] ? methods[i] : "Method " + (initialLength + i + 1);
241+
efficiencyData.push({
242+
method: methodName,
243+
sdf: SDF[i],
244+
pir: pirValue
245+
});
246+
}
247+
248+
// Append only the newly added rows to the table.
249+
efficiencyData.slice(initialLength).forEach(d => {
250+
const tr = document.createElement("tr");
251+
tr.innerHTML = `<td>${d.method}</td>
252+
<td>${d.sdf}</td>
253+
<td>${(typeof d.pir === "number") ? d.pir.toFixed(4) : d.pir}</td>`;
254+
effTbody.appendChild(tr);
255+
});
256+
257+
245258

246259
efficiencyData.forEach(d => {
247260
const tr = document.createElement("tr");
@@ -487,36 +500,42 @@ <h2>Feasibility Indicators</h2>
487500
return [x1 + t * ABx, y1 + t * ABy];
488501
}
489502

490-
function drawAxisTicks(ctx, minVal, maxVal, step, scaleFunc, axis = "x") {
491-
ctx.save();
492-
ctx.fillStyle = "#000";
493-
ctx.font = "12px sans-serif";
494-
ctx.textAlign = axis === "x" ? "center" : "right";
495-
let v = minVal;
496-
while (v <= maxVal + 1e-9) {
497-
const valStr = (Math.abs(v) < 1e-6) ? "0" : v.toFixed(2).replace(/\.?0+$/, "");
498-
if (axis === "x") {
499-
const x = scaleFunc(v);
500-
const y0 = scaleFunc(minVal);
501-
ctx.beginPath();
502-
ctx.moveTo(x, y0);
503-
ctx.lineTo(x, y0 + 5);
504-
ctx.stroke();
505-
ctx.fillText(valStr, x, y0 + 15);
506-
} else {
507-
const y = scaleFunc(v);
508-
const x0 = scaleFunc(minVal);
509-
ctx.beginPath();
510-
ctx.moveTo(x0, y);
511-
ctx.lineTo(x0 - 5, y);
512-
ctx.stroke();
513-
ctx.textBaseline = "middle";
514-
ctx.fillText(valStr, x0 - 8, y);
503+
function drawAxisTicks(ctx, minVal, maxVal, step, scaleFunc, constantFunc, axis = "x") {
504+
ctx.save();
505+
ctx.fillStyle = "#000";
506+
ctx.font = "12px sans-serif";
507+
let v = minVal;
508+
while (v <= maxVal + 1e-9) {
509+
const valStr = (Math.abs(v) < 1e-6) ? "0" : v.toFixed(2).replace(/\.?0+$/, "");
510+
if (axis === "x") {
511+
// X-axis ticks: use the constant function to get the y coordinate (always H - pad)
512+
const x = scaleFunc(v);
513+
const y0 = constantFunc();
514+
ctx.beginPath();
515+
ctx.moveTo(x, y0);
516+
ctx.lineTo(x, y0 + 5);
517+
ctx.stroke();
518+
ctx.textAlign = "center";
519+
ctx.textBaseline = "top";
520+
ctx.fillText(valStr, x, y0 + 5);
521+
} else {
522+
// Y-axis ticks: rotate the text so it fits.
523+
const y = scaleFunc(v);
524+
const x0 = constantFunc();
525+
ctx.save();
526+
ctx.translate(x0 - 8, y);
527+
ctx.rotate(-Math.PI / 2);
528+
ctx.textAlign = "right";
529+
ctx.textBaseline = "middle";
530+
ctx.fillText(valStr, 0, 0);
531+
ctx.restore();
532+
}
533+
v += step;
515534
}
516-
v += step;
517-
}
518-
ctx.restore();
519-
}
535+
ctx.restore();
536+
}
537+
538+
520539

521540
// -------------------------
522541
// Draw Efficiency Plot
@@ -553,8 +572,45 @@ <h2>Feasibility Indicators</h2>
553572
ctx.lineWidth = 2;
554573
ctx.stroke();
555574

556-
drawAxisTicks(ctx, minSDF, maxSDF, 0.05, xScale, "x");
557-
drawAxisTicks(ctx, minPIR, maxPIR, 0.1, yScale, "y");
575+
// Draw X-axis ticks for Efficiency Plot (for SDF)
576+
ctx.save();
577+
ctx.font = "12px sans-serif";
578+
ctx.fillStyle = "#000";
579+
for (let v = minSDF; v <= maxSDF; v += 0.05) {
580+
// Use the y-position corresponding to the lower bound of PIR.
581+
// (In the feasibility plot, we use yScale(0) because minVal=0;
582+
// here use yScale(minPIR) since that is the lower bound for PIR.)
583+
const x = xScale(v);
584+
const y0 = yScale(minPIR);
585+
ctx.beginPath();
586+
ctx.moveTo(x, y0);
587+
ctx.lineTo(x, y0 + 5);
588+
ctx.stroke();
589+
// Mark the tick value (formatted as needed)
590+
ctx.fillText(v.toFixed(2).replace(/\.?0+$/, ""), x, y0 + 15);
591+
}
592+
ctx.restore();
593+
594+
// Draw Y-axis ticks for Efficiency Plot (for PIR)
595+
ctx.save();
596+
ctx.font = "12px sans-serif";
597+
ctx.fillStyle = "#000";
598+
for (let v = minPIR; v <= maxPIR; v += 0.1) {
599+
// Use the x-position corresponding to the lower bound of SDF.
600+
const y = yScale(v);
601+
const x0 = xScale(minSDF);
602+
ctx.beginPath();
603+
ctx.moveTo(x0, y);
604+
ctx.lineTo(x0 - 5, y);
605+
ctx.stroke();
606+
ctx.textAlign = "right";
607+
ctx.textBaseline = "middle";
608+
ctx.fillText(v.toFixed(2).replace(/\.?0+$/, ""), x0 - 8, y);
609+
}
610+
ctx.restore();
611+
612+
613+
558614

559615
ctx.save();
560616
ctx.fillStyle = "#000";

_site/liu/getPIR.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ def getPIR(type:str, SEM:list = None, BM:list = None, pir:list = None):
5151
return PIR
5252

5353
# some examples:
54-
getPIR(SEM=[1.2, 3], BM=[4], type = "same_win")
54+
getPIR(SEM=[1.2, 3], BM=[1.2], type = "same_win")
5555
# getPIR(SEM=[1.2, 3], BM=[3], type = "same_win")
5656
# getPIR(SEM=[1.2, 3], BM=[1,4], type = "same_bench")

_site/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,12 @@ h2 {
9494
justify-content: space-between;
9595
align-items: flex-start;
9696
gap: 1rem;
97+
max-width: 100%;
98+
box-sizing: border-box;
99+
overflow-x: auto;
97100
}
98101

102+
99103
.half {
100104
flex: 1;
101105
min-width: 300px;

index.html

Lines changed: 96 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,28 @@ <h2>Feasibility Indicators</h2>
233233

234234
const pirValue = getPIR(pirType, SEM, BM);
235235
// Overwrite the global array with new computed values.
236-
efficiencyData = [];
237-
for (let i = 0; i < SEM.length; i++) {
238-
const methodName = methods[i] ? methods[i] : "Method " + (i + 1);
239-
efficiencyData.push({
240-
method: methodName,
241-
sdf: SDF[i],
242-
pir: pirValue
243-
});
244-
}
236+
// Correct: append new rows without wiping out the existing data
237+
// Append new rows without wiping out the existing data.
238+
const initialLength = efficiencyData.length;
239+
for (let i = 0; i < SEM.length; i++) {
240+
const methodName = methods[i] ? methods[i] : "Method " + (initialLength + i + 1);
241+
efficiencyData.push({
242+
method: methodName,
243+
sdf: SDF[i],
244+
pir: pirValue
245+
});
246+
}
247+
248+
// Append only the newly added rows to the table.
249+
efficiencyData.slice(initialLength).forEach(d => {
250+
const tr = document.createElement("tr");
251+
tr.innerHTML = `<td>${d.method}</td>
252+
<td>${d.sdf}</td>
253+
<td>${(typeof d.pir === "number") ? d.pir.toFixed(4) : d.pir}</td>`;
254+
effTbody.appendChild(tr);
255+
});
256+
257+
245258

246259
efficiencyData.forEach(d => {
247260
const tr = document.createElement("tr");
@@ -487,36 +500,42 @@ <h2>Feasibility Indicators</h2>
487500
return [x1 + t * ABx, y1 + t * ABy];
488501
}
489502

490-
function drawAxisTicks(ctx, minVal, maxVal, step, scaleFunc, axis = "x") {
491-
ctx.save();
492-
ctx.fillStyle = "#000";
493-
ctx.font = "12px sans-serif";
494-
ctx.textAlign = axis === "x" ? "center" : "right";
495-
let v = minVal;
496-
while (v <= maxVal + 1e-9) {
497-
const valStr = (Math.abs(v) < 1e-6) ? "0" : v.toFixed(2).replace(/\.?0+$/, "");
498-
if (axis === "x") {
499-
const x = scaleFunc(v);
500-
const y0 = scaleFunc(minVal);
501-
ctx.beginPath();
502-
ctx.moveTo(x, y0);
503-
ctx.lineTo(x, y0 + 5);
504-
ctx.stroke();
505-
ctx.fillText(valStr, x, y0 + 15);
506-
} else {
507-
const y = scaleFunc(v);
508-
const x0 = scaleFunc(minVal);
509-
ctx.beginPath();
510-
ctx.moveTo(x0, y);
511-
ctx.lineTo(x0 - 5, y);
512-
ctx.stroke();
513-
ctx.textBaseline = "middle";
514-
ctx.fillText(valStr, x0 - 8, y);
503+
function drawAxisTicks(ctx, minVal, maxVal, step, scaleFunc, constantFunc, axis = "x") {
504+
ctx.save();
505+
ctx.fillStyle = "#000";
506+
ctx.font = "12px sans-serif";
507+
let v = minVal;
508+
while (v <= maxVal + 1e-9) {
509+
const valStr = (Math.abs(v) < 1e-6) ? "0" : v.toFixed(2).replace(/\.?0+$/, "");
510+
if (axis === "x") {
511+
// X-axis ticks: use the constant function to get the y coordinate (always H - pad)
512+
const x = scaleFunc(v);
513+
const y0 = constantFunc();
514+
ctx.beginPath();
515+
ctx.moveTo(x, y0);
516+
ctx.lineTo(x, y0 + 5);
517+
ctx.stroke();
518+
ctx.textAlign = "center";
519+
ctx.textBaseline = "top";
520+
ctx.fillText(valStr, x, y0 + 5);
521+
} else {
522+
// Y-axis ticks: rotate the text so it fits.
523+
const y = scaleFunc(v);
524+
const x0 = constantFunc();
525+
ctx.save();
526+
ctx.translate(x0 - 8, y);
527+
ctx.rotate(-Math.PI / 2);
528+
ctx.textAlign = "right";
529+
ctx.textBaseline = "middle";
530+
ctx.fillText(valStr, 0, 0);
531+
ctx.restore();
532+
}
533+
v += step;
515534
}
516-
v += step;
517-
}
518-
ctx.restore();
519-
}
535+
ctx.restore();
536+
}
537+
538+
520539

521540
// -------------------------
522541
// Draw Efficiency Plot
@@ -553,8 +572,45 @@ <h2>Feasibility Indicators</h2>
553572
ctx.lineWidth = 2;
554573
ctx.stroke();
555574

556-
drawAxisTicks(ctx, minSDF, maxSDF, 0.05, xScale, "x");
557-
drawAxisTicks(ctx, minPIR, maxPIR, 0.1, yScale, "y");
575+
// Draw X-axis ticks for Efficiency Plot (for SDF)
576+
ctx.save();
577+
ctx.font = "12px sans-serif";
578+
ctx.fillStyle = "#000";
579+
for (let v = minSDF; v <= maxSDF; v += 0.05) {
580+
// Use the y-position corresponding to the lower bound of PIR.
581+
// (In the feasibility plot, we use yScale(0) because minVal=0;
582+
// here use yScale(minPIR) since that is the lower bound for PIR.)
583+
const x = xScale(v);
584+
const y0 = yScale(minPIR);
585+
ctx.beginPath();
586+
ctx.moveTo(x, y0);
587+
ctx.lineTo(x, y0 + 5);
588+
ctx.stroke();
589+
// Mark the tick value (formatted as needed)
590+
ctx.fillText(v.toFixed(2).replace(/\.?0+$/, ""), x, y0 + 15);
591+
}
592+
ctx.restore();
593+
594+
// Draw Y-axis ticks for Efficiency Plot (for PIR)
595+
ctx.save();
596+
ctx.font = "12px sans-serif";
597+
ctx.fillStyle = "#000";
598+
for (let v = minPIR; v <= maxPIR; v += 0.1) {
599+
// Use the x-position corresponding to the lower bound of SDF.
600+
const y = yScale(v);
601+
const x0 = xScale(minSDF);
602+
ctx.beginPath();
603+
ctx.moveTo(x0, y);
604+
ctx.lineTo(x0 - 5, y);
605+
ctx.stroke();
606+
ctx.textAlign = "right";
607+
ctx.textBaseline = "middle";
608+
ctx.fillText(v.toFixed(2).replace(/\.?0+$/, ""), x0 - 8, y);
609+
}
610+
ctx.restore();
611+
612+
613+
558614

559615
ctx.save();
560616
ctx.fillStyle = "#000";

liu/getPIR.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ def getPIR(type:str, SEM:list = None, BM:list = None, pir:list = None):
5151
return PIR
5252

5353
# some examples:
54-
getPIR(SEM=[1.2, 3], BM=[4], type = "same_win")
54+
getPIR(SEM=[1.2, 3], BM=[1.2], type = "same_win")
5555
# getPIR(SEM=[1.2, 3], BM=[3], type = "same_win")
5656
# getPIR(SEM=[1.2, 3], BM=[1,4], type = "same_bench")

style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,12 @@ h2 {
9494
justify-content: space-between;
9595
align-items: flex-start;
9696
gap: 1rem;
97+
max-width: 100%;
98+
box-sizing: border-box;
99+
overflow-x: auto;
97100
}
98101

102+
99103
.half {
100104
flex: 1;
101105
min-width: 300px;

0 commit comments

Comments
 (0)