Public
Edited
Dec 3, 2023
Insert cell
Insert cell
data = [
{ label: "Test", value: test },
{ label: "Data", value: task },
]
Insert cell
Insert cell
{
return html`<pre>${datum.value
.split(/(\d+)/g)
.map((part, index) =>
index % 2 == 1
? html`<span style="color: ${isAdjacent(part, index) ? "blue" : "red"}">${part}</span>`
: part
)}</pre>`;
}
Insert cell
splittedData = datum.value.split(/\n/g)
Insert cell
dataWidth = splittedData[0].length;
Insert cell
dataHeight = splittedData.length;
Insert cell
function isAdjacent(part, index) {
const row = Math.floor(index / dataWidth);
const col = index % dataWidth;

console.log(index,row,col)

for (let i = row - 1; i <= row + 1; i++) {
for (let j = col - 1; j <= col + 1; j++) {
if (i === row && j === col) continue;

if (i >= 0 && i < dataHeight && j >= 0 && j < dataWidth) {
if (isSymbol(splittedData[i][j])) {
return true;
}
}
}
}

return false;
}
Insert cell
function isSymbol(char) {
const symbolRegex = /^[^\d.]$/;
return symbolRegex.test(char);
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more