data_long_siklus = data_hormon_siklus.flatMap(d => [
{hari: d.hari, hormon: "LH (IU/L)", nilai: d.LH},
{hari: d.hari, hormon: "Progesteron (ng/mL)", nilai: d.Progesteron},
{hari: d.hari, hormon: "Estradiol (×10 pg/mL)", nilai: d.Estradiol_scaled}
])
Plot.plot({
height: 430,
marginLeft: 55,
marginBottom: 50,
grid: true,
x: {domain: [1, 28], ticks: [1, 7, 14, 21, 28], label: "Hari Siklus Menstruasi"},
y: {domain: [0, 48], label: "Kadar Hormon (Skala Relatif)"},
color: {
legend: true,
domain: ["LH (IU/L)", "Progesteron (ng/mL)", "Estradiol (×10 pg/mL)"],
range: ["#d81b60", "#1565c0", "#2e7d32"]
},
marks: [
// Zona highlight fase ovulasi & mid-luteal
Plot.rect([{x1: 13, x2: 15, y1: 0, y2: 48}], {x1: "x1", x2: "x2", y1: "y1", y2: "y2", fill: "#fce4ec", fillOpacity: 0.6}),
Plot.rect([{x1: 20, x2: 22, y1: 0, y2: 48}], {x1: "x1", x2: "x2", y1: "y1", y2: "y2", fill: "#e3f2fd", fillOpacity: 0.6}),
Plot.text([{x: 14, y: 46}], {text: ["Ovulasi"], fill: "#ad1457", fontSize: 11}),
Plot.text([{x: 21, y: 46}], {text: ["Mid-Luteal"], fill: "#1565c0", fontSize: 11}),
// Kurva ketiga hormon
Plot.lineY(data_long_siklus, {x: "hari", y: "nilai", stroke: "hormon", strokeWidth: 3}),
// Garis vertikal indikator hari yang dipilih user
Plot.ruleX([hari_siklus], {stroke: "#333", strokeWidth: 2, strokeDasharray: "4,4"}),
// Titik-titik pada hari yang dipilih
Plot.dot(data_long_siklus.filter(d => d.hari === hari_siklus), {
x: "hari", y: "nilai", fill: "hormon", r: 6, stroke: "white", strokeWidth: 1.5
})
]
})