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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more