-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathnba_cmv.js
246 lines (206 loc) · 6.78 KB
/
nba_cmv.js
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// libraries
const Project = require("../../src/index").Project;
const Canvas = require("../../src/Canvas").Canvas;
const Jump = require("../../src/Jump").Jump;
const Layer = require("../../src/Layer").Layer;
const View = require("../../src/View").View;
// project components
const renderers = require("../nba/renderers");
const transforms = require("../nba/transforms");
const placements = require("../nba/placements");
// construct a project
var p = new Project("nba", "../../../config.txt");
p.addRenderingParams(renderers.renderingParams);
p.addStyles("../nba/nba.css");
// ================== Canvas teamlogo ===================
var teamLogoCanvas = new Canvas("teamlogo", 1000, 1000);
p.addCanvas(teamLogoCanvas);
// logo layer
var teamLogoLayer = new Layer(transforms.teamLogoTransform, true);
teamLogoCanvas.addLayer(teamLogoLayer);
teamLogoLayer.addRenderingFunc(renderers.teamLogoRendering);
// ================== Canvas team timeline ===================
var width = 1000 * 16;
var height = 1000;
// construct a new canvas
var teamTimelineCanvas = new Canvas("teamtimeline", width, height);
p.addCanvas(teamTimelineCanvas);
// pannable timeline layer
var timelineLayer = new Layer(transforms.teamTimelineTransform, false);
teamTimelineCanvas.addLayer(timelineLayer);
timelineLayer.addPlacement(placements.teamTimelinePlacement);
timelineLayer.addRenderingFunc(renderers.teamTimelineRendering);
// static background layer
var timelineBkgLayer = new Layer(transforms.teamTimelineStaticTransform, true);
teamTimelineCanvas.addLayer(timelineBkgLayer);
timelineBkgLayer.addRenderingFunc(renderers.teamTimelineStaticBkg);
// ================== Canvas play by play ===================
var width = 1000;
var height = 0;
var wString = "";
var hString = "0:select (max(play_id) + 2) * 160 from plays;"; // todo: the "where" clause is assumed to be at the end right now
// construct a new canvas
var playByPlayCanvas = new Canvas(
"playbyplay",
width,
height,
wString,
hString
);
p.addCanvas(playByPlayCanvas);
// pannable play by play layer
var playByPlayLayer = new Layer(transforms.playByPlayTransform, false);
playByPlayCanvas.addLayer(playByPlayLayer);
playByPlayLayer.addPlacement(placements.playByPlayPlacement);
playByPlayLayer.addRenderingFunc(renderers.playByPlayRendering);
// static background layer
var playByPlayBkgLayer = new Layer(transforms.playByPlayStaticTransform, true);
playByPlayCanvas.addLayer(playByPlayBkgLayer);
playByPlayBkgLayer.addRenderingFunc(renderers.playByPlayStaticBkg);
// ================== Canvas boxscore ===================
var width = 1750;
var height = 1000;
// construct a new canvas
var boxscoreCanvas = new Canvas("boxscore", width, height);
p.addCanvas(boxscoreCanvas);
// static pk column layer
var boxscorePkColumnLayer = new Layer(transforms.boxscoreTransform, true);
boxscoreCanvas.addLayer(boxscorePkColumnLayer);
boxscorePkColumnLayer.addRenderingFunc(renderers.boxscorePkRendering);
// pannable stats layer
var statsLayer = new Layer(transforms.boxscoreTransform, false);
boxscoreCanvas.addLayer(statsLayer);
statsLayer.addPlacement(placements.boxscorePlacement);
statsLayer.addRenderingFunc(renderers.boxscoreStatsRendering);
// ================== Views ===================
var leftView = new View("left", 1000, 1000);
p.addView(leftView);
p.setInitialStates(leftView, teamLogoCanvas, 0, 0);
var rightView = new View("right", 1000, 1000);
p.addView(rightView);
// ================== teamlogo -> teamtimeline (load) ===================
var selector = function() {
return true;
};
var newViewport = function() {
return {constant: [0, 0]};
};
var newPredicate = function(row) {
var pred0 = {
OR: [{"==": ["home_team", row.abbr]}, {"==": ["away_team", row.abbr]}]
};
var pred1 = {"==": ["abbr", row.abbr]};
return {layer0: pred0, layer1: pred1};
};
var jumpName = function(row) {
return "2017~2018 Regular Season Games of\n" + row.city + " " + row.name;
};
p.addJump(
new Jump(teamLogoCanvas, teamTimelineCanvas, "load", {
selector: selector,
viewport: newViewport,
predicates: newPredicate,
name: jumpName,
sourceView: leftView,
destView: rightView
})
);
// ================== teamlogo -> teamtimeline (highlight) ===================
var selector = function() {
return true;
};
var newPredicate = function(row) {
var pred = {
OR: [{"==": ["home_team", row.abbr]}, {"==": ["away_team", row.abbr]}]
};
return {layer0: pred};
};
var jumpName = function(row) {
return "all games against\n" + row.city + " " + row.name;
};
p.addJump(
new Jump(teamLogoCanvas, teamTimelineCanvas, "highlight", {
selector: selector,
predicates: newPredicate,
name: jumpName,
sourceView: leftView,
destView: rightView
})
);
// ================== teamtimeline -> playbyplay ===================
var selector = function(row, args) {
return args.layerId == 0;
};
var newViewport = function() {
return {constant: [0, 0]};
};
var newPredicate = function(row) {
var pred0 = {"==": ["game_id", row.game_id]};
var pred1 = {
AND: [
{"==": ["abbr1", row.home_team]},
{"==": ["abbr2", row.away_team]}
]
};
return {layer0: pred0, layer1: pred1};
};
var jumpName = function(row) {
return "Play-by-Play of " + row.away_team + "@" + row.home_team;
};
p.addJump(
new Jump(teamTimelineCanvas, playByPlayCanvas, "semantic_zoom", {
selector: selector,
viewport: newViewport,
predicates: newPredicate,
name: jumpName
})
);
// ================== teamtimeline -> boxscore ===================
var selector = function(row, args) {
return args.layerId == 0;
};
var newViewport = function() {
return {constant: [0, 0]};
};
var newPredicateHome = function(row) {
var pred = {
AND: [
{"==": ["GAME_ID", row.game_id]},
{"==": ["TEAM_ABBR", row.home_team]}
]
};
return {layer0: pred, layer1: pred};
};
var newPredicateAway = function(row) {
var pred = {
AND: [
{"==": ["GAME_ID", row.game_id]},
{"==": ["TEAM_ABBR", row.away_team]}
]
};
return {layer0: pred, layer1: pred};
};
var jumpNameHome = function(row) {
return "Box score of " + row.home_team;
};
var jumpNameAway = function(row) {
return "Box score of " + row.away_team;
};
p.addJump(
new Jump(teamTimelineCanvas, boxscoreCanvas, "semantic_zoom", {
selector: selector,
viewport: newViewport,
predicates: newPredicateHome,
name: jumpNameHome
})
);
p.addJump(
new Jump(teamTimelineCanvas, boxscoreCanvas, "semantic_zoom", {
selector: selector,
viewport: newViewport,
predicates: newPredicateAway,
name: jumpNameAway
})
);
// save to db
p.saveProject();