Published
Edited
Insert cell
Insert cell
Insert cell
Insert cell
function isStart(indices, image) {
let y = indices[0]
let x = indices[1]
if (image[y][x] !== 0) {
return false
}
if ((-1 < y - 1 < image.length) && !!image[y - 1] && image[y - 1][x] === 0) {
return false
}
if ((-1 < x - 1 < image[0].length) && image[y][x - 1] === 0) {
return false
}
return true
}
Insert cell
function findCurrentEnd(indices, image) {
let startJ = indices[0]
let startI = indices[1]
let endJ = startJ
let endI = startI
while (image[endJ][endI] === 0) {
endI++
}
while (!!image[endJ] && image[endJ][startI] === 0) {
endJ++
}
return [endJ - 1, endI - 1]
}
Insert cell
function findRectangles(image) {
let arrayOfStartsAndEnds = []
for (let j = 0; j < image.length; j++) {
for (let i = 0; i < image[0].length; i++) {
if (isStart([j, i], image)) {
let currentStart = [j, i]
let currentEnd = findCurrentEnd(currentStart, image)
arrayOfStartsAndEnds.push([currentStart, currentEnd])
}
}
}
return arrayOfStartsAndEnds
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
grid_4 = {
var res = JSON.parse(JSON.stringify(image4));
var res2 = modifyData(res)
console.log(res2)
return getChart(res2)
}
Insert cell
Insert cell
Insert cell
image5 = [
[0, 1, 1, 0, 0],
[0, 1, 1, 0, 0],
[0, 1, 1, 0, 0],
];
Insert cell
md`#### Step 2: Visualize the data (image5) and the results`
Insert cell
grid_5 = {
var res = JSON.parse(JSON.stringify(image5));
var res2 = modifyData(res)
console.log(res2)
return getChart(res2)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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