generated from Cumulo/cumulo-phlox-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compact.cirru
219 lines (218 loc) · 8.84 KB
/
compact.cirru
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
{} (:package |app)
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!) (:version |0.0.1)
:modules $ [] |memof/ |lilac/ |respo.calcit/ |respo-ui.calcit/ |phlox/
:entries $ {}
:files $ {}
|app.config $ {}
:defs $ {}
|dev? $ quote
def dev? $ = "\"env" (get-env "\"mode" "\"release")
|site $ quote
def site $ {} (:dev-ui "\"http://localhost:8100/main-fonts.css") (:release-ui "\"http://cdn.tiye.me/favored-fonts/main-fonts.css") (:cdn-url "\"http://cdn.tiye.me/in-time/") (:title "\"In time") (:icon "\"http://cdn.tiye.me/logo/memkits.png") (:storage-key "\"in-time")
:ns $ quote (ns app.config)
|app.container $ {}
:defs $ {}
|a-day $ quote
def a-day $ * 1000 3600 24
|a-year $ quote
def a-year $ * a-day 365.2425
|comp-container $ quote
defcomp comp-container (store)
let
states $ :states store
cursor $ []
state $ or (:data states)
{}
:from $ - now-time (* 1000 a-year)
:to now-time
current-records $ -> db :times
filter $ fn (record)
and
< (:from record) (:to state)
> (:to record) (:from state)
container ({})
comp-records (>> states :records) current-records (:from state) (:to state)
comp-controls states cursor state
|comp-controls $ quote
defcomp comp-controls (states cursor state)
container
{} $ :position
[] 20 $ - js/window.innerHeight 100
text $ {}
:text $ .format
dayjs $ :from state
, "\"YYYY-MM-DD"
:position $ [] 80 20
:style $ {}
:fill $ hslx 0 0 100
:font-size 14
text $ {}
:text $ .format
dayjs $ :to state
, "\"YYYY-MM-DD"
:position $ [] 180 20
:style $ {}
:fill $ hslx 0 0 100
:font-size 14
comp-slider (>> states :from)
{} (:title "\"From")
:value $ :from state
:unit $ * a-day 1000
:round? true
:max $ :to state
:position $ [] 80 60
:on-change $ fn (v d!)
d! cursor $ assoc state :from v
comp-slider (>> states :to)
{} (:title "\"To")
:value $ :to state
:unit $ * a-day 1000
:round? true
:max now-time
:position $ [] 240 60
:on-change $ fn (v d!)
d! cursor $ assoc state :to v
|comp-records $ quote
defcomp comp-records (states current-records from to)
let
cursor $ :cursor states
state $ or (:data states)
{} $ :selected nil
whole-width $ - js/window.innerWidth 80
container
{} $ :position ([] 60 28)
graphics $ {}
:ops $ []
g :line-style $ {}
:color $ hslx 0 0 20
:width 1
:alpha 1
g :move-to $ [] 0 0
g :line-to $ [] 0 400
g :move-to $ [] whole-width 0
g :line-to $ [] whole-width 400
create-list :container ({})
-> current-records (.sort-by :from)
map-indexed $ fn (idx record)
let
y $ * 12 idx
t1 $ :from record
t2 $ :to record
x1 $ &max 0
* whole-width $ / (- t1 from) (- to from)
x2 $ * whole-width
&min 1 $ / (- t2 from) (- to from)
selected? $ = (:name record) (:selected state)
[] idx $ container ({})
if selected? $ rect
{}
:position $ [] (- x1 100) (+ 6 y)
:size $ [] 600 2
:fill $ hslx 0 0 10
rect $ {}
:position $ [] x1 y
:size $ [] (- x2 x1)
case-default (:kind record) 8 (:person 10) (:dynasty 12)
:fill $ case-default (:kind record) (hslx 0 0 40)
:person $ hslx 200 80 30
:dynasty $ hslx 100 80 30
:on $ {}
:pointertap $ fn (e d!)
println $ assoc state :selected (:name record)
d! cursor $ assoc state :selected (:name record)
text $ {}
:text $ str (:name record) "\" "
.!format (dayjs t1) "\"YYYY-MM-DD"
, "\"~"
.!format (dayjs t2) "\"YYYY-MM-DD"
:position $ [] (- x1 20) (+ y 1)
:style $ {}
:fill $ hslx 0 0 70
:font-size 8
|db $ quote
def db $ ->
parse-cirru-edn $ inline "\"data/times.cirru"
update :times $ fn (times)
-> times $ map
fn (record)
-> record (update :from time->number) (update :to time->number)
|inline $ quote
defmacro inline (path) (read-file path)
|now-time $ quote
def now-time $ js/Date.now
|time->number $ quote
defn time->number (x)
let
parsed $ new js/Date x
when
= (first x) "\"-"
.!setYear parsed $ - 0 (.!getFullYear parsed)
.!valueOf parsed
:ns $ quote
ns app.container $ :require
[] phlox.core :refer $ [] defcomp >> hslx rect circle text container graphics create-list g
[] phlox.comp.slider :refer $ [] comp-slider
[] "\"dayjs" :default dayjs
|app.main $ {}
:defs $ {}
|*store $ quote (defatom *store schema/store)
|dispatch! $ quote
defn dispatch! (op op-data)
if (list? op)
recur :states $ [] op op-data
do
when
and dev? $ not= op :states
println "\"dispatch!" op op-data
let
op-id $ shortid/generate
op-time $ js/Date.now
reset! *store $ updater @*store op op-data op-id op-time
|global-fonts $ quote
def global-fonts $ js/Promise.all
js-array
.!load $ new FontFaceObserver "\"Josefin Sans"
.!load $ new FontFaceObserver "\"Hind"
|main! $ quote
defn main! () (; js/console.log PIXI)
-> global-fonts $ .then
fn (f)
render! (comp-container @*store) dispatch! $ {}
add-watch *store :change $ fn (s p)
render! (comp-container @*store) dispatch! $ {}
println "\"App Started"
|reload! $ quote
defn reload! () (println "\"Code updated")
render! (comp-container @*store) dispatch! $ {} (:swap? true)
:ns $ quote
ns app.main $ :require ([] "\"pixi.js" :as PIXI) ([] "\"shortid" :as shortid)
[] phlox.core :refer $ [] render!
[] app.container :refer $ [] comp-container
[] app.schema :as schema
[] app.config :refer $ [] dev?
[] app.updater :refer $ [] updater
[] "\"fontfaceobserver" :default FontFaceObserver
|app.schema $ {}
:defs $ {}
|store $ quote
def store $ {} (:tab :drafts) (:x 0)
:states $ {}
:ns $ quote (ns app.schema)
|app.updater $ {}
:defs $ {}
|updater $ quote
defn updater (store op op-data op-id op-time)
case-default op
do (println "\"Unknown op:" op op-data) store
:add-x $ update store :x
fn (x)
if (> x 10) 0 $ + x 1
:tab $ assoc store :tab op-data
:states $ let-sugar
[] cursor new-state
, op-data
assoc-in store
concat ([] :states) cursor $ [] :data
, new-state
:hydrate-storage op-data
:ns $ quote (ns app.updater)