git ssb

0+

Rômulo Alves / dat-letnice



Commit 4e84c689ec8b5cd2767905c5162ebf111cb8a103

wip days

nomand committed on 6/4/2018, 10:29:09 AM
Parent: 485f638a8b571b23f46c23f86f86061d68765f2a

Files changed

js/letnice.jschanged
js/letnice.jsView
@@ -3,83 +3,26 @@
33 let base = document.body;
44
55 let year = new Date().getFullYear();
66
7- const monthNames = [
8- "January", "February", "March",
9- "April", "May", "June",
10- "July", "August", "September",
11- "October", "November", "December"
12- ];
13-
14- const dayNames = [
15- "Sunday", "Monday", "Tuesday", "Wednesday",
16- "Thursday", "Friday", "Saturday"
17- ]
7+ const monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
8+ const dayNames = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]
189
1910 // let leap = new Date(year, 1, 29).getDate() === 29;
2011 // let days = leap ? 366 : 365;
2112 // let cell = parseInt((base.getBoundingClientRect().width - 52*2)/52);
2213
23- let week = 0;
2414 let count = 1;
2515 let month = 0;
2616
2717 let style = "day";
28-
29- // make grid
30- // while(week < 52)
31- // {
32- // let x = parseInt(week * (cell+2));
33- // let day = 0;
34- // while(day < 7)
35- // {
36- // let y = parseInt(day * (cell+2))
37- // count++;
38- // base.innerHTML += `<rect class='day' x='${x}' y='${y}' title='${count}' width='${cell}' height='${cell}' rx="2" ry="2" onclick=""></rect>`;
39- // day += 1
40- // }
41- // week += 1
42- // }
43-
44-// let i = 0;
45-// while(month < 12)
46-// {
47-// let day = 0;
48-// let x = 0;
49-// while(day < new Date(year, month).monthDays(month))
50-// {
51-// if(i === 7)
52-// {
53-// week++
54-// i=0
55-// }
56-// day++;
57-// i++
58-// count++;
59-// let y = parseInt(count * (cell+1));
60-// console.log(count + ", M" + month + ", W" + week + ", D" + day);
61-// base.innerHTML += `<rect class='${CheckDay(year, month, day)}' x='${x}' y='${y}' title='${count}' width='${cell}' height='${cell}' rx="2" ry="2" onclick=""></rect>`;
62-// }
63-// month++;
64-// }
65-// }
66-
67- //start container
68- //add month text
69- //mtwtfss
70- //start comparing date with weekdays
71- //start iterating through days from a match until month is over
72-
73-
74- //let cell = parseInt((base.getBoundingClientRect().width - 52*2)/52)
75-
18+
7619 while(month < 12)
7720 {
7821 base.innerHTML += `
7922 <div class="month">
8023 <p class="m" x="" y='${month * 140}' dy="10">${monthNames[new Date(year, month).getMonth()].substr(0,2)}</p>
81- <svg class="graph">
24+ <svg class="graph" id="${monthNames[month]}">
8225 ${dayLabels()}
8326 ${populateMonth(month)}
8427 </svg></div>`
8528 month++
@@ -88,71 +31,48 @@
8831 function dayLabels()
8932 {
9033 let html = "";
9134 let y = 0;
92-
35+
9336 for(i = 0; i < 7; i++)
9437 {
95- y = i * 20;
96- html += `<text class="dayLabel" x="7" y='${y}' dy="10">${dayNames[i].substr(0,1)}</text>`
38+ y = i * 14;
39+ html += `<text class="dayLabel" x="3" y='${y}' dy="10">${dayNames[i].substr(0,1)}</text>`
9740 }
9841 return html;
9942 }
10043
101- function populateMonth(m)
44+ function populateMonth(month)
10245 {
10346 html = "";
104- monthLength = new Date(year, m, 0).getDate();
47+ monthLength = new Date(year, month+1, 0).getDate();
10548 let day = 0;
106- let x = 14;
49+ let x = 0;
10750 let y = 0;
10851
10952 while(day < monthLength)
11053 {
111- let i = 0
11254 x += 14;
55+ let weekDay = 0
11356
114- while(i < 7)
57+ while(weekDay < 7 && day != monthLength)
11558 {
116- y = i * 14;
59+ y = weekDay * 14;
11760
118- //is it monday? is it tuesday? etc. instantiate null until day match then start for every day;
119-
120- html += `<rect class="day" x='${x}' y='${y}' title='${day}' width="12px" height="12px" rx="2" ry="2" onclick=""></rect>`
121- i++
61+ if(new Date(year, month, day).getDay() != weekDay)
62+ {
63+ style = "null";
64+ }
65+ else
66+ {
67+ style = "day";
68+ }
69+
70+ html += `<rect class='${style}' x='${x}' y='${y}' title='${day+1}' width="12px" height="12px" rx="2" ry="2" onclick=""></rect>`
71+ weekDay++
12272 day++
12373 count++
12474 }
12575 }
12676 return html;
12777 }
128-}
129-
130-
131-
132- // while(count <= days)
133- // {
134- // t = new Date(year, month, count)
135- // let x = cell;
136- // let y = parseInt(count * (cell+2));
137-
138- // console.log(t);
139-
140- // base.innerHTML += `<rect class='${CheckDay(t)}' x='${x}' y='${y}' title='${count}' width='${cell}' height='${cell}' rx="2" ry="2" onclick=""></rect>`;
141- // count++;
142- // }
143-
144- // function CheckDay(day)
145- // {
146- // switch(day.getDay())
147- // {
148- // case 0:
149- // style = "weekend";
150- // break;
151- // case 6:
152- // style = "weekend";
153- // break;
154- // default:
155- // style = "day";
156- // }
157- // return style;
158- // }
78+}

Built with git-ssb-web