{
if (!data || typeof cropFilter === 'undefined' || typeof highlightedCrop === 'undefined') {
return html`<div style="
padding: 1rem;
background: #fff8e1;
border: 1px solid #ffd54f;
border-radius: 4px;
">
<p>⚠️ Please ensure:</p>
<ol>
<li>Data cell has been executed</li>
<li>Control cells have been run</li>
<li>Page was refreshed if needed</li>
</ol>
</div>`;
}
const filteredData = data.filter(d => cropFilter.includes(d.label));
return Plot.plot({
marks: [
Plot.boxY(filteredData, {
x: "label",
y: "N",
stroke: "label",
strokeWidth: d => d.label === highlightedCrop ? 3 : 1,
tip: true,
title: d => `${d.label}\nNitrogen: ${d.N} ppm`
}),
Plot.boxY(filteredData, {
x: "label",
y: "P",
stroke: "label",
strokeWidth: d => d.label === highlightedCrop ? 3 : 1,
tip: true,
title: d => `${d.label}\nPhosphorus: ${d.P} ppm`
}),
Plot.boxY(filteredData, {
x: "label",
y: "K",
stroke: "label",
strokeWidth: d => d.label === highlightedCrop ? 3 : 1,
tip: true,
title: d => `${d.label}\nPotassium: ${d.K} ppm`
}),
...(highlightedCrop ? [
Plot.dot(
filteredData.filter(d => d.label === highlightedCrop),
{ x: "label", y: "N", fill: "red", r: 5 }
),
Plot.dot(
filteredData.filter(d => d.label === highlightedCrop),
{ x: "label", y: "P", fill: "red", r: 5 }
),
Plot.dot(
filteredData.filter(d => d.label === highlightedCrop),
{ x: "label", y: "K", fill: "red", r: 5 }
)
] : [])
],
facet: {
data: ["N", "P", "K"],
y: "Nutrient Level",
marginLeft: 60
},
x: {
label: "Crop",
tickRotate: -45
},
y: {
label: "Nutrient Level (ppm)",
grid: true
},
color: {
legend: true,
columns: 3
},
width: 1000,
marginLeft: 70
});
}