-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawDailyPlanner.mjs
70 lines (50 loc) · 2.29 KB
/
drawDailyPlanner.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { drawDots } from "./drawDots.mjs";
import { prepareHoursIterator } from "./hoursLabels.factory.mjs";
export function drawDailyPlanner(doc, x, y, w, h, startingHour = 8, hours = 19) {
doc.rect(x, y, w, h);
const cellSize = h / hours;
// draw separation line for hour hours labels
// with the same width as row height (cell size)
const hoursX = x + cellSize
doc.line(hoursX, y, hoursX, y + h);
// draw separation line between half hour rows
const halfHourW = (w - cellSize) / 2;
const halfHourX = x + cellSize + halfHourW;
doc.line(halfHourX, y, halfHourX, y + h);
const hourLabelX = x + cellSize / 2 - 2; // approxmimate coordinate for hour label X coordinate
const hourLabelYShift = cellSize / 2 + 1; // approxmimate shift for hour label Y coordinate
const getHourLabel = prepareHoursIterator(startingHour);
for (let r = 0; r < hours; r++) {
const hourLabelY = y + cellSize * r + hourLabelYShift;
doc.text(hourLabelX, hourLabelY, getHourLabel());
const rowY = y + cellSize * r;
if (r != 0) {
doc.line(x, rowY, x + w, rowY)
}
drawDots(doc, x + cellSize, rowY, halfHourW, cellSize, cellSize);
drawDots(doc, x + cellSize + halfHourW, rowY, halfHourW, cellSize, cellSize);
}
}
export function drawDailyPlanner2(doc, x, y, w, h, startingHour = 8, hours = 19) {
doc.rect(x, y, w, h);
const cellSize = h / hours;
// draw separation line for hour hours labels
// with the same width as row height (cell size)
const hoursX = x + cellSize
doc.line(hoursX, y, hoursX, y + h);
// draw separation line between half hour rows
const hourW = w - cellSize;
const hourLabelX = x + cellSize / 2 - 2; // approxmimate coordinate for hour label X coordinate
const hourLabelYShift = cellSize / 2 + 1; // approxmimate shift for hour label Y coordinate
const getHourLabel = prepareHoursIterator(startingHour);
for (let r = 0; r < hours; r++) {
const hourLabelY = y + cellSize * r + hourLabelYShift;
doc.text(hourLabelX, hourLabelY, getHourLabel());
const rowY = y + cellSize * r;
if (r != 0) {
doc.line(x, rowY, hoursX, rowY)
}
if (r !== hours - 1) drawDots(doc, x + cellSize, rowY + cellSize - cellSize/4, hourW, cellSize / 2, cellSize / 2);
drawDots(doc, x + cellSize, rowY, hourW, cellSize, cellSize);
}
}