12-Canvas Calendar
Here’s an Omni Automation plug-in for OmniGraffle that creates a calendar for a specifed year. A calendar for each month of the specified year is placed on its own canvas, and the text shapes for each day of the month are named using the index of the month and the index of the day, for example: 2-24
Twelve-Canvas Calendar | ||
01 | /*{ | |
02 | "type": "action", | |
03 | "targets": ["omnigraffle"], | |
04 | "author": "Otto Automator", | |
05 | "identifier": "com.omni-automation.og.twelve-canvas-calendar", | |
06 | "version": "1.3", | |
07 | "description": "This action will add twelve canvases to current document, each containing a monthly calendar for the specified year.", | |
08 | "label": "Twelve Canvas Calendar", | |
09 | "shortLabel": "Calendar" | |
10 | }*/ | |
11 | var _ = function(){ | |
12 | var action = new PlugIn.Action(function(selection, sender){ | |
13 | ||
14 | // CREATE FORM FOR GATHERING USER INPUT | |
15 | var inputForm = new Form() | |
16 | ||
17 | // CREATE TEXT FIELD | |
18 | textField = new Form.Field.String( | |
19 | "textInput", | |
20 | null, | |
21 | new Date().getFullYear().toString() | |
22 | ) | |
23 | ||
24 | // ADD THE FIELD TO THE FORM | |
25 | inputForm.addField(textField) | |
26 | ||
27 | // PRESENT THE FORM TO THE USER | |
28 | formPrompt = "Enter the year for the calendar:" | |
29 | formPromise = inputForm.show(formPrompt,"Continue") | |
30 | ||
31 | // VALIDATE THE USER INPUT | |
32 | inputForm.validate = function(formObject){ | |
33 | textValue = formObject.values["textInput"] | |
34 | ||
35 | if(!textValue){return false} | |
36 | ||
37 | intValue = parseInt(textValue) | |
38 | ||
39 | validation = (isNaN(intValue) || intValue < 1979 || intValue >= 3000) ? false:true | |
40 | ||
41 | return validation | |
42 | } | |
43 | ||
44 | // PROCESSING USING THE DATA EXTRACTED FROM THE FORM | |
45 | formPromise.then(function(formObject){ | |
46 | textValue = formObject.values["textInput"] | |
47 | var calendarYear = Number(textValue) | |
48 | ||
49 | // CALENDAR PROPERTIES | |
50 | var cellWidth = 100 | |
51 | var cellHeight = 75 | |
52 | var indent = 36 | |
53 | ||
54 | for (var m = 1; m <= 12; m++ ){ | |
55 | monthName = nameOfMonth(m, "en-us") | |
56 | dayCount = daysInMonth(m, calendarYear) | |
57 | startDay = startingWeekdayIndexForMonth(m, calendarYear) | |
58 | rowCount = weekCount(m, calendarYear) | |
59 | ||
60 | cnvs = addCanvas() | |
61 | cnvs.name = monthName | |
62 | ||
63 | // Month Title | |
64 | titleShape = cnvs.addShape('Rectangle',new Rect(indent, indent, cellWidth * 7, cellHeight)) | |
65 | titleShape.text = monthName + " " + calendarYear.toString() | |
66 | setUpMonthTitle(titleShape) | |
67 | ||
68 | dayIndex = 1 | |
69 | for (var r = 1; r <= rowCount; r++ ){ | |
70 | leftOffset = indent | |
71 | topOffset = indent + (cellHeight * r) | |
72 | for (var c = 0; c < 7; c++ ){ | |
73 | cell = cnvs.addShape('Rectangle',new Rect(leftOffset, topOffset, cellWidth, cellHeight)) | |
74 | leftOffset = leftOffset + cellWidth | |
75 | if (r == 1 && c >= startDay){ | |
76 | cell.name = String(m) + "-" + String(dayIndex) | |
77 | cell.text = dayIndex.toString() | |
78 | setupCell(cell) | |
79 | dayIndex = dayIndex + 1 | |
80 | } else if (r != 1 && dayIndex <= dayCount){ | |
81 | cell.name = String(m) + "-" + String(dayIndex) | |
82 | cell.text = dayIndex.toString() | |
83 | setupCell(cell) | |
84 | dayIndex = dayIndex + 1 | |
85 | } else { | |
86 | cell.name = "blank" | |
87 | setUpEmptyCell(cell) | |
88 | } | |
89 | } | |
90 | } | |
91 | } | |
92 | ||
93 | }) | |
94 | ||
95 | // PROMISE FUNCTION CALLED UPON FORM CANCELLATION | |
96 | formPromise.catch(function(err){ | |
97 | console.log("form cancelled", err.message) | |
98 | }) | |
99 | }); | |
100 | ||
101 | action.validate = function(selection, sender){ | |
102 | return true | |
103 | }; | |
104 | ||
105 | return action; | |
106 | }(); | |
107 | _; | |
108 | ||
109 | function setUpMonthTitle(shape){ | |
110 | shape.fillColor = Color.white | |
111 | shape.shadowColor = null | |
112 | shape.strokeType = StrokeType.Single | |
113 | shape.strokeColor = Color.black | |
114 | shape.strokePattern = StrokeDash.Solid | |
115 | shape.strokeThickness = 2 | |
116 | shape.textColor = Color.black | |
117 | shape.textHorizontalPadding = 10 | |
118 | shape.textHorizontalAlignment = HorizontalTextAlignment.Center | |
119 | shape.textSize = 48 | |
120 | shape.fontName = "Helvetica-Bold" | |
121 | } | |
122 | ||
123 | function setupCell(shape){ | |
124 | shape.fillColor = Color.white | |
125 | shape.shadowColor = null | |
126 | shape.strokeType = StrokeType.Single | |
127 | shape.strokeColor = Color.black | |
128 | shape.strokePattern = StrokeDash.Solid | |
129 | shape.strokeThickness = 2 | |
130 | shape.textColor = Color.black | |
131 | shape.textHorizontalPadding = 10 | |
132 | shape.textHorizontalAlignment = HorizontalTextAlignment.Right | |
133 | shape.textVerticalPadding = 10 | |
134 | shape.textVerticalPlacement = VerticalTextPlacement.Center | |
135 | shape.textSize = 18 | |
136 | shape.fontName = "Helvetica" | |
137 | } | |
138 | ||
139 | function setUpEmptyCell(shape){ | |
140 | shape.fillColor = Color.White(0.8,1) | |
141 | shape.shadowColor = null | |
142 | shape.strokeType = StrokeType.Single | |
143 | shape.strokeColor = Color.black | |
144 | shape.strokePattern = StrokeDash.Solid | |
145 | shape.strokeThickness = 2 | |
146 | shape.textColor = Color.black | |
147 | shape.textHorizontalPadding = 10 | |
148 | shape.textHorizontalAlignment = HorizontalTextAlignment.Right | |
149 | shape.textVerticalPadding = 10 | |
150 | shape.textVerticalPlacement = VerticalTextPlacement.Center | |
151 | shape.textSize = 18 | |
152 | shape.fontName = "Helvetica" | |
153 | } | |
154 | ||
155 | function daysInMonth(month, year){ | |
156 | return new Date(year, month, 0).getDate(); | |
157 | } | |
158 | ||
159 | function startingWeekdayIndexForMonth(month, year){ | |
160 | // returns 0-6 with 0 as Sunday | |
161 | return new Date(year, month - 1, 1).getDay(); | |
162 | } | |
163 | ||
164 | function weekCount(month, year){ | |
165 | firstOfMonth = new Date(year, month - 1, 1); | |
166 | lastOfMonth = new Date(year, month, 0); | |
167 | used = firstOfMonth.getDay() + lastOfMonth.getDate(); | |
168 | return Math.ceil( used / 7); | |
169 | } | |
170 | ||
171 | function nameOfMonth(month, locale){ | |
172 | yr = new Date().getFullYear(); | |
173 | objDate = new Date(yr, month - 1, 1); | |
174 | return objDate.toLocaleString(locale,{month:"long"}); | |
175 | } |
This webpage is in the process of being developed. Any content may change and may not be accurate or complete at this time.