Skip to content

Added animation scripts to visualize grid auto-placement algorithm #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions auto-placement-explicit.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.container {
display: grid;
grid-gap: 10px;
grid-template-rows: repeat(5, 60px);
grid-template-columns: repeat(4, 1fr);
grid-auto-rows: 60px;
/*grid-auto-flow: dense;*/
}
.box{
display: grid;
grid-template-rows: auto;
grid-template-rows: auto;
align-items: center;
justify-items: center;
}

.box.two {
grid-row: span 2;
}
.box.four {
grid-column: 1 / span 2; /* INTERESTING */
}
.box.seven {
grid-column: span 1;
}
.box.eight {
grid-column: span 1;
}
/* explicit grid placement */
.box.six {
grid-row: 3 / span 2;
grid-column: 2 / span 2;
}
.box.five{
grid-row: 2;
grid-column: 4;
}
.box.eleven {
grid-row: 5;;
grid-column: 3 / span 2;
}

/* Old school css*/
.container {
border: 2px solid black;
}
.box {
border: 0.5px solid blue;
}
16 changes: 16 additions & 0 deletions auto-placement-explicit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<body>
<div class="container">
<div class="box one"><span></span></div>
<div class="box two"><span></span></div>
<div class="box three"><span></span></div>
<div class="box four"><span></span></div>
<div class="box five"><span></span></div>
<div class="box six"><span></span></div>
<div class="box seven"><span></span></div>
<div class="box eight"><span></span></div>
<div class="box nine"><span></span></div>
<div class="box ten"><span></span></div>
<div class="box eleven"><span></span></div>
<div class="box twelve"><span></span></div>
</div>
</body>
58 changes: 58 additions & 0 deletions auto-placement-explicit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var container = document.getElementsByClassName("container");
console.log(container);

var boxes = container[0].getElementsByClassName("box");
console.log(boxes);

function setBoxContent (currBox, i, color) {
currBox.style.backgroundColor = color;
let countNode = (currBox.firstElementChild||currBox.firstChild);
countNode.innerHTML = (i+1);
countNode.style.fontSize = "40px";
countNode.style.color = "black";
}
/*
function fillExplicitBox(i, color){
let currBoxNumber = explicitBoxes[i];
let currBox = boxes.item(currBoxNumber);
setBoxContent(currBox, currBoxNumber, color);
}
*/

function fillBox(i, color){
let currBox = boxes.item(i);
console.log(currBox);
setBoxContent(currBox, i, color);
}

var explicitBoxes = [6,5,11];
var implicitBoxes = [];
let numBoxes = boxes.length;
let numExplicitBoxes = explicitBoxes.length;
for(let j=1; j<=numBoxes; j++) {
if(! explicitBoxes.includes(j)){
implicitBoxes.push(j);
}
}
let orderBoxes = explicitBoxes.concat(implicitBoxes);

let delayInMilliseconds = 1000;
let counter = 0;
let color = "#ffb";
let exColor = "#0fb";

var timedLoop = setInterval(function() {
if(counter < numExplicitBoxes){
fillBox(orderBoxes[counter]-1, exColor);
}
else {
fillBox(orderBoxes[counter]-1, color);
}
counter++;
if(counter===numBoxes) {
//clearInterval(i);
counter = 0;
exColor = (exColor === "#0fb" ? "#bf0" : "#0fb");
color = (color === "#ffb" ? "#bff" : "#ffb");
}
}, delayInMilliseconds);
48 changes: 48 additions & 0 deletions auto-placement.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.container {
display: grid;
grid-gap: 10px;
grid-template-rows: repeat(3, 60px);
grid-template-columns: repeat(4, 1fr);
grid-auto-rows: 60px;
grid-auto-flow: dense;
}
.box{
display: grid;
grid-template-rows: auto;
grid-template-rows: auto;
align-items: center;
justify-items: center;
}
.box.two {
grid-row: span 2;
}
/*
Try::
.box.four {
grid-column: span 2;
}
*/
.box.four {
grid-column: span 2;
}
.box.six {
grid-row: span 2;
grid-column: span 3;
}
.box.seven {
grid-column: span 1;
}
.box.eight {
grid-column: span 1;
}
.box.eleven {
grid-row: span 2;
grid-column: span 2;
}
/* Old school css*/
.container {
border: 2px solid black;
}
.box {
border: 0.5px solid blue;
}
18 changes: 18 additions & 0 deletions auto-placement.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<body>
<div class="container">
<div class="box one"><span></span></div>
<div class="box two"><span></span></div>
<div class="box three"><span></span></div>
<div class="box four"><span></span></div>
<div class="box five"><span></span></div>
<div class="box six"><span></span></div>
<div class="box seven"><span></span></div>
<div class="box eight"><span></span></div>
<div class="box nine"><span></span></div>
<div class="box ten"><span></span></div>
<div class="box eleven"><span></span></div>
<div class="box twelve"><span></span></div>
<div class="box thirteen"><span></span></div>
<div class="box fourteen"><span></span></div>
</div>
</body>
33 changes: 33 additions & 0 deletions auto-placement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var container = document.getElementsByClassName("container");
console.log(container);

var boxes = container[0].getElementsByClassName("box");
console.log(boxes);

function fillBox(i, color){
let currBox = boxes.item(i);
console.log(currBox);
currBox.style.backgroundColor = color;
// to center text
//let countNode = document.createElement("span");
let countNode = (currBox.firstElementChild||currBox.firstChild);
countNode.innerHTML = (i+1);
countNode.style.fontSize = "40px";
countNode.style.color = "black";
//countNode.style.border = "0.5px solid red";
currBox.appendChild(countNode);
}

var delayInMilliseconds = 1000; //1 second
var counter = 0;
var numBoxes = boxes.length;
var color = "#ffb";
var timedLoop = setInterval(function() {
fillBox(counter, color);
counter++;
if(counter===numBoxes) {
//clearInterval(i);
counter = 0;
color = (color === "#ffb" ? "#bff" : "#ffb");
}
}, delayInMilliseconds);