Commit 4e84c689ec8b5cd2767905c5162ebf111cb8a103
wip days
nomand committed on 6/4/2018, 10:29:09 AMParent: 485f638a8b571b23f46c23f86f86061d68765f2a
Files changed
js/letnice.js | changed |
js/letnice.js | ||
---|---|---|
@@ -3,83 +3,26 @@ | ||
3 | 3 | let base = document.body; |
4 | 4 | |
5 | 5 | let year = new Date().getFullYear(); |
6 | 6 | |
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" ] | |
18 | 9 | |
19 | 10 | // let leap = new Date(year, 1, 29).getDate() === 29; |
20 | 11 | // let days = leap ? 366 : 365; |
21 | 12 | // let cell = parseInt((base.getBoundingClientRect().width - 52*2)/52); |
22 | 13 | |
23 | - let week = 0; | |
24 | 14 | let count = 1; |
25 | 15 | let month = 0; |
26 | 16 | |
27 | 17 | 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 | + | |
76 | 19 | while(month < 12) |
77 | 20 | { |
78 | 21 | base.innerHTML += ` |
79 | 22 | <div class="month"> |
80 | 23 | <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]}"> | |
82 | 25 | ${dayLabels()} |
83 | 26 | ${populateMonth(month)} |
84 | 27 | </svg></div>` |
85 | 28 | month++ |
@@ -88,71 +31,48 @@ | ||
88 | 31 | function dayLabels() |
89 | 32 | { |
90 | 33 | let html = ""; |
91 | 34 | let y = 0; |
92 | - | |
35 | + | |
93 | 36 | for(i = 0; i < 7; i++) |
94 | 37 | { |
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>` | |
97 | 40 | } |
98 | 41 | return html; |
99 | 42 | } |
100 | 43 | |
101 | - function populateMonth(m) | |
44 | + function populateMonth(month) | |
102 | 45 | { |
103 | 46 | html = ""; |
104 | - monthLength = new Date(year, m, 0).getDate(); | |
47 | + monthLength = new Date(year, month+1, 0).getDate(); | |
105 | 48 | let day = 0; |
106 | - let x = 14; | |
49 | + let x = 0; | |
107 | 50 | let y = 0; |
108 | 51 | |
109 | 52 | while(day < monthLength) |
110 | 53 | { |
111 | - let i = 0 | |
112 | 54 | x += 14; |
55 | + let weekDay = 0 | |
113 | 56 | |
114 | - while(i < 7) | |
57 | + while(weekDay < 7 && day != monthLength) | |
115 | 58 | { |
116 | - y = i * 14; | |
59 | + y = weekDay * 14; | |
117 | 60 | |
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++ | |
122 | 72 | day++ |
123 | 73 | count++ |
124 | 74 | } |
125 | 75 | } |
126 | 76 | return html; |
127 | 77 | } |
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