-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplots.js
More file actions
1140 lines (1048 loc) · 38.6 KB
/
Copy pathplots.js
File metadata and controls
1140 lines (1048 loc) · 38.6 KB
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var masterData = []; // variable to store master data
var filteredData = []; // variable to store data of chosen year and position
var scatterPlotContainer = d3.select("#plot-containerScatter");
var plotContainerBubble = document.getElementById("plot-containerBubble");
plotContainerBubble.innerHTML = "";
var plotSpecScatter = {};
var scatterPlots = {};
var plotSpecBubble = {};
var bubblePlots = {};
var fantasyTeamData = {};
var opacity = 1;
var duration = 500;
var interval = 10;
var selectedPosition = "";
var selectedC = "";
var selected1B = "";
var selected2B = "";
var selected3B = "";
var selectedSS = "";
var selectedLF = "";
var selectedCF = "";
var selectedRF = "";
var selectedDH = "";
var selectedCData = [];
var selected1BData = [];
var selected2BData = [];
var selected3BData = [];
var selectedSSData = [];
var selectedLFData = [];
var selectedCFData = [];
var selectedRFData = [];
var selectedDHData = [];
// function to filter data by year and position
function filterDataByYear() {
// variables to store string from dropdowns
var year = document.getElementById("year").value.toString();
const csvFilePath = 'data/mlb17to22.csv';
// read the CSV file and insert data into master and filtered data variable
Papa.parse(csvFilePath, {
download: true,
header: true,
complete: function(results) {
masterData = results.data;
filteredData = results.data.filter(function(row) {
return row.Year == year;
});
// update the player dropdown menus
updatePlayerDropdowns();
// update the plot with new data
plotSpecScatter = drawScatterPlot()
updatePlot();
}
});
filterTeamByYear()
}
function filterTeamByYear() {
// variables to store string from dropdowns
var year = document.getElementById("year").value.toString();
const csvFilePath = 'data/teamData17to22.csv';
// read the CSV file and insert data into master and filtered data variable
Papa.parse(csvFilePath, {
download: true,
header: true,
complete: function(results) {
masterData = results.data;
filteredTeam = results.data.filter(function(row) {
return row.Year == year;
});
// update the plot with new data
plotSpecBubble = drawBubblePlot()
}
});
}
// positionString
function filterDataByPositionAndYear(position) {
// variables to store string from dropdowns
var year = document.getElementById("year").value;
selectedPosition = position;
const csvFilePath = 'data/mlb17to22.csv';
// ** AT THIS PT, position = clickedPosition = (string). But its not, therefore the
// scatter plot does not update. Commenting/deleting the snippet of code below,
// after clicking on the image, all scatter plot goes to blank.
// Validates the position value
const validPositions = ['C', '1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF', 'DH/UTL'];
if (!validPositions.includes(position)) {
return; // Exit the function if position is invalid
}
// read the CSV file and insert data into master and filtered data variable
Papa.parse(csvFilePath, {
download: true,
header: true,
complete: function(results) {
masterData = results.data;
filteredData = results.data.filter(function(row) {
return row.Year == year && row.Pos === position;
});
// update the player dropdown menus
updatePlayerDropdowns();
// update the plot with new data
plotSpecScatter = drawScatterPlot(position)
updatePlot(position);
}
});
//animateScatterPlot()
}
// function to update player dropdowns after data filtering
function updatePlayerDropdowns() {
// variables to store string from dropdowns
var player1Dropdown = document.getElementById("player1");
var player2Dropdown = document.getElementById("player2");
// clear previous options
player1Dropdown.innerHTML = "";
player2Dropdown.innerHTML = "";
// variables contain a null option for the player dropdowns
var nullOption1 = document.createElement("option")
var nullOption2 = document.createElement("option")
nullOption1.value = null
nullOption2.value = null
// add null option to dropdowns
player1Dropdown.append(nullOption1);
player2Dropdown.append(nullOption2);
// add options for each player in the filtered data
for (var i = 0; i < filteredData.length; i++) {
var playerName = filteredData[i].Name;
var option1 = document.createElement("option");
option1.value = playerName;
option1.textContent = playerName;
var option2 = document.createElement("option");
option2.value = playerName;
option2.textContent = playerName;
player1Dropdown.appendChild(option1);
player2Dropdown.appendChild(option2);
}
}
function drawScatterPlot(position) {
var player1 = document.getElementById("player1").value;
var player2 = document.getElementById("player2").value;
var yearValue = document.getElementById("year").value.toString();
scatterPlots = [
{
"title": "Batting Average vs. Slugging Percentage",
"xField": "SLG",
"yField": "BA"
},
{
"title": "Home Runs vs. Stolen Bases",
"xField": "SB",
"yField": "HR"
},
{
"title": "Strikeouts vs. Walks",
"xField": "BB",
"yField": "SO"
}
];
titleText = "Performance of all players in " + yearValue;
if (position) {
titleText = "Performance of all " + position + " players in " + yearValue;
}
plotSpecScatter = {
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": filteredData
},
"title": {
"text": titleText,
"fontSize": 24,
"anchor": "mid",
"color": "black"
},
"params": [{
"name": "brush",
"select": //"interval",
{
"type": "point",
"toggle": "event.shiftKey"
}
},
{"name": "grid",
"select": "interval",
"bind": "scales"
}],
"hconcat": scatterPlots.map(function (scatterPlot) {
return {
"title": scatterPlot.title,
"mark": "point",
"encoding": {
"x": {"field": scatterPlot.xField, "type": "quantitative"},
"y": {"field": scatterPlot.yField, "type": "quantitative"},
"text": {"field": "Name", "format": ".2%"},
"color": {
"condition": {
"param": "brush",
"field": "Pos",
"type": "nominal",
},
"value": "grey"
},
"size": {
"condition": [],
"value": 50
},
"tooltip": [
{"field": "Name", "title": "Name"},
{"field": "Age", "title": "Age"},
{"field": scatterPlot.xField, "title": scatterPlot.xField},
{"field": scatterPlot.yField, "title": scatterPlot.yField}
],
"order": {
"condition": [],
value: 0
},
"opacity": {"value": opacity}
}
};
})
};
vegaEmbed('#plot-containerScatter', plotSpecScatter).catch(console.error);
return plotSpecScatter;
}
// function to update plots
function updatePlot(position) {
// variables to store string from dropdowns
var player1 = document.getElementById("player1").value;
var player2 = document.getElementById("player2").value;
var yAxisLine = document.getElementById("y-axisLine").value;
// variables with data filtered for the selected players
var player1Data = filteredData.find(function(row) {
return row.Name === player1;
});
var player2Data = filteredData.find(function(row) {
return row.Name === player2;
});
// variable containing player1 and player2 data for all years
var playerCombinedData = masterData.filter(function(row) {
return row.Name === player1 || row.Name === player2;
})
// change year column to numbers
playerCombinedData.Year = Number(playerCombinedData.Year);
// variables for baseball diamond
var source = [{"x": 0, "y": 0, "img": "https://creazilla-store.fra1.digitaloceanspaces.com/cliparts/76536/baseball-diamond-clipart-md.png"}];
var framed = [{"x": 1, "y": 1},
{"x": -1, "y": -1},
{"x": -1, "y": 1},
{"x": 1, "y": -1}];
var player_locations = [{"x": 0, "y": -0.68, "position": "C"},
{"x": 0.37, "y": -0.08, "position": "1B"},
{"x": 0.25, "y": 0.28, "position": "2B"},
{"x": -0.37, "y": -0.08, "position": "3B"},
{"x": -0.25, "y": 0.28, "position": "SS"},
{ "x": 0.53, "y": 0.45, "position": "LF"},
{"x": 0, "y": 0.75, "position": "CF"},
{"x": -0.53, "y": 0.45, "position": "RF"},
{"x": 0.45, "y": -0.55, "position": "DH/UTL"}];
// create the plot containers
var plotContainerBarH = document.getElementById("plot-containerBarH");
plotContainerBarH.innerHTML = "";
var plotContainerBarHR = document.getElementById("plot-containerBarHR");
plotContainerBarHR.innerHTML = "";
var plotContainerBarRBI = document.getElementById("plot-containerBarRBI");
plotContainerBarRBI.innerHTML = "";
var plotContainerBarSB = document.getElementById("plot-containerBarSB");
plotContainerBarSB.innerHTML = "";
var plotContainerLine = document.getElementById("plot-containerLine");
plotContainerLine.innerHTML = "";
var plotContainerScatter = document.getElementById("plot-containerScatter");
plotContainerScatter.innerHTML = "";
var plotContainerDiamond = document.getElementById("plot-containerDiamond");
plotContainerDiamond.innerHTML = "";
// hits bar chart
var plotSpecBarH = {
"title": "Hits",
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [player1Data, player2Data]
},
"mark": "bar",
"encoding": {
"x": {"field": "Name", "type": "nominal"},
"y": {"field": "H", "type": "quantitative"},
"tooltip": {"field": "H", "type": "quantitative"},
"color": {
"field": "Name",
"type": "nominal",
"scale": {"range": ["#002d72", "#d50032"]},
"legend": null
}
}
};
// home runs bar chart
var plotSpecBarHR = {
"title": "Home Runs",
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [player1Data, player2Data]
},
"mark": "bar",
"encoding": {
"x": {"field": "Name", "type": "nominal"},
"y": {"field": "HR", "type": "quantitative"},
"tooltip": {"field": "HR", "type": "quantitative"},
"color": {
"field": "Name",
"type": "nominal",
"scale": {"range": ["#002d72", "#d50032"]},
"legend": null
}
}
};
// runs batted in bar chart
var plotSpecBarRBI = {
"title": "Runs Batted In",
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [player1Data, player2Data]
},
"mark": "bar",
"encoding": {
"x": {"field": "Name", "type": "nominal"},
"y": {"field": "RBI", "type": "quantitative"},
"tooltip": {"field": "RBI", "type": "quantitative"},
"color": {
"field": "Name",
"type": "nominal",
"scale": {"range": ["#002d72", "#d50032"]},
"legend": null
}
}
};
// stolen bases bar chart
var plotSpecBarSB = {
"title": "Stolen Bases",
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [player1Data, player2Data]
},
"mark": "bar",
"encoding": {
"x": {"field": "Name", "type": "nominal"},
"y": {"field": "SB", "type": "quantitative"},
"tooltip": {"field": "SB", "type": "quantitative"},
"color": {
"field": "Name",
"type": "nominal",
"scale": {"range": ["#002d72", "#d50032"]},
"legend": null
}
}
};
// hitting averages line chart
var plotSpecLine = {
"title": "Hitting Averages",
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": playerCombinedData
},
"layer": [{
"mark": {"type": "line", "point": true},
"encoding": {
"x": {"field": "Year", "type": "temporal"},
"y": {"field": yAxisLine, "type": "quantitative"},
"tooltip": [{"field": yAxisLine, "type": "quantitative"}],
"color": {
"field": "Name",
"type": "nominal",
"scale": {"range": ["#002d72", "#d50032"]}
}
}
}]
};
// Layered Diamond Plot
var plotSpecDiamond = {
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": source
},
"layer": [{
"mark": {
"type": "image",
"width": 170,
"height": 175,
},
"encoding": {
"x": {
"field": "x",
"type": "quantitative"
},
"y": {
"field": "y",
"type": "quantitative"
},
"url": {
"field": "img",
"type": "nominal"
}
}
},
{
"mark": {
"type": "circle",
"color": "white",
"size": 100
},
"encoding": {
"x": {
"field": "x",
"type": "quantitative"
},
"y": {
"field": "y",
"type": "quantitative"
}
},
"data": {
"values": framed
}
},
{
"mark": {
"type": "circle",
"color": "black",
"size": 300
},
"encoding": {
"x": {
"field": "x",
"type": "quantitative"
},
"y": {
"field": "y",
"type": "quantitative"
},
"tooltip": {
"field": "position",
"type": "nominal"
},
"transform": [
{
"calculate": "datum.position",
"as": "clickedPosition"
}
]
},
"data": {
"values": player_locations
},
"selection": {
"markSelection": {
"type": "single",
"on": "click",
"encodings": ["x", "y"],
"nearest": true
}
}
}
],
"config": {
"axis": {
"grid": false,
"title": null,
"domain": false,
"ticks": false,
"labels": false
}
}
};
// embed plots into containers
vegaEmbed('#plot-containerBarH', plotSpecBarH).catch(console.error);
vegaEmbed('#plot-containerBarHR', plotSpecBarHR).catch(console.error);
vegaEmbed('#plot-containerBarRBI', plotSpecBarRBI).catch(console.error);
vegaEmbed('#plot-containerBarSB', plotSpecBarSB).catch(console.error);
vegaEmbed('#plot-containerLine', plotSpecLine).catch(console.error);
/*
vegaEmbed('#plot-containerDiamond', plotSpecDiamond).then((result) => {
result.view.addSignalListener('markSelection', function (name, value) {
if (value !== null) {
var clickedPosition = value.clickedPosition;
// Call your desired function with the clickedPosition variable
filterDataByPositionAndYear(clickedPosition);
}
});
}).catch(console.error);
*/
updateScatterPlot(player1, player2, position);
}
function updateScatterPlot(player1, player2, position) {
// Update the colors
var yearValue = document.getElementById("year").value.toString();
console.log(position);
if (position != null) {
plotSpecScatter.title.text = "Performance of all " + position + " players in " + yearValue;
}
else if (player1 != "null" && player2 == "null") {
plotSpecScatter.title.text = "Performance of " + player1 + " in " + yearValue;
} else if (player1 == "null" && player2 != "null") {
plotSpecScatter.title.text = "Performance of " + player2 + " in " + yearValue;
} else if (player1 != "null" && player2 != "null") {
plotSpecScatter.title.text = "Performance of " + player1 + " and " + player2 + " in " + yearValue;
}
else if (player1 == player2 && player1 != "null") {
plotSpecScatter.title.text = "Performance of " + player1 + " in " + yearValue;
}
else {
plotSpecScatter.title = {"text": "Performance of all players in " + yearValue, "anchor": "mid", "fontSize": 24};
}
plotSpecScatter.hconcat.forEach((plot, i) => {
if (player1 != "null" || player2 != "null") {
plot.encoding.color.condition = [
{"test": "datum.Name === '" + player1.replace("'", "\\'") + "'", "value": "#8fce00"},
{"test": "datum.Name === '" + player2.replace("'", "\\'") + "'", "value": "#8fce00"},
]}
plot.encoding.size.condition = [
{"test": "datum.Name === '" + player1.replace("'", "\\'") + "'", "value": 200},
{"test": "datum.Name === '" + player2.replace("'", "\\'") + "'", "value": 200},
]
plot.encoding.order.condition = [
{"test": "datum.Name === '" + player1.replace("'", "\\'") + "'", "value": 1},
{"test": "datum.Name === '" + player2.replace("'", "\\'") + "'", "value": 2},
]
}
);
// Render the updated plot
vegaEmbed('#plot-containerScatter', plotSpecScatter).catch(console.error);
}
function drawBubblePlot(userTeam) {
var player1 = document.getElementById("player1").value;
var player2 = document.getElementById("player2").value;
var yearValue = document.getElementById("year").value.toString();
bubblePlots = [
{
"title": "Batting Average vs. Slugging Percentage",
"xField": "SLG",
"yField": "BA"
},
{
"title": "Home Runs vs. Stolen Bases",
"xField": "SB",
"yField": "HR"
},
{
"title": "Strikeouts vs. Walks",
"xField": "BB",
"yField": "SO"
}
];
titleText = "Performance of all teams in " + yearValue;
if (userTeam) {
titleText = "Performance of all teams and your dream team in " + yearValue;
}
plotSpecBubble = {
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": filteredTeam
},
"title": {
"text": titleText,
"fontSize": 24,
"anchor": "mid",
"color": "black"
},
"hconcat": bubblePlots.map(function(bubblePlot) {
const xMin = Math.min(...filteredTeam.map(d => d[bubblePlot.xField]));
const xMax = Math.max(...filteredTeam.map(d => d[bubblePlot.xField]));
const yMin = Math.min(...filteredTeam.map(d => d[bubblePlot.yField]));
const yMax = Math.max(...filteredTeam.map(d => d[bubblePlot.yField]));
console.log(xMin, xMax, yMin, yMax)
return {
"title": bubblePlot.title,
"layer": [{
"mark": "point",
"params": [{
"name": "gridBubble",
"select": "interval",
"bind": "scales"
}],
"encoding": {
"x": {
"field": bubblePlot.xField,
"type": "quantitative",
"title": bubblePlot.xField,
"scale": {
"domain": [xMin, xMax]
}
},
"y": {
"field": bubblePlot.yField,
"type": "quantitative",
"title": bubblePlot.yField,
"scale": {
"domain": [yMin, yMax]
}
},
"text": {
"field": "Name",
"format": ".2%"
},
"color": {
"field": "League",
"type": "nominal",
"title": "League",
"scale": {
"domain": ["AL", "NL", "My League"],
"range": ["#d50032", "#002d72", "#8fce00"]
}
},
"size": {
"condition": [],
"value": 50
},
"tooltip": [{
"field": "Tm",
"title": "Team Name"
},
{
"field": bubblePlot.xField,
"title": bubblePlot.xField
},
{
"field": bubblePlot.yField,
"title": bubblePlot.yField
}
],
"order": {
"condition": [],
"value": 0
},
"opacity": {
"value": opacity
}
}},
{
"mark": "rule",
"encoding": {
"y": {
"aggregate": "mean",
"field": bubblePlot.yField,
"type": "quantitative"
},
"color": { "value": "black" },
"size": { "value": 2 },
}
},
{
"mark": "rule",
"encoding": {
"x": {
"aggregate": "mean",
"field": bubblePlot.xField,
"type": "quantitative"
},
"color": { "value": "black" },
"size": { "value": 2 },
"align": { "value": "left" },
"baseline": { "value": "middle" },
"angle": { "value": 90 }
}
},
{
"mark": "text",
"encoding": {
"text": {
"value": "Low " + bubblePlot.xField
},
"x": {
"value": 30
},
"y": {
"value": 10
},
"baseline": {
"value": "top"
},
"align": {
"value": "left"
},
"color": {
"value": "black"
},
"size": {
"value": 14
}
}
},
{
"mark": "text",
"encoding": {
"text": {
"value": "High " + bubblePlot.yField
},
"x": {
"value": 30
},
"y": {
"value": 25
},
"baseline": {
"value": "top"
},
"align": {
"value": "left"
},
"color": {
"value": "black"
},
"size": {
"value": 14
}
}
},
{
"mark": "text",
"encoding": {
"text": {
"value": "High " + bubblePlot.xField
},
"x": {
"value": 165
},
"y": {
"value": 10
},
"baseline": {
"value": "top"
},
"align": {
"value": "left"
},
"color": {
"value": "black"
},
"size": {
"value": 14
}
}
},
{
"mark": "text",
"encoding": {
"text": {
"value": "High " + bubblePlot.yField
},
"x": {
"value": 165
},
"y": {
"value": 25
},
"baseline": {
"value": "top"
},
"align": {
"value": "left"
},
"color": {
"value": "black"
},
"size": {
"value": 14
}
}
},
{
"mark": "text",
"encoding": {
"text": {
"value": "Low " + bubblePlot.xField
},
"x": {
"value": 30
},
"y": {
"value": 175
},
"baseline": {
"value": "top"
},
"align": {
"value": "left"
},
"color": {
"value": "black"
},
"size": {
"value": 14
}
}
},
{
"mark": "text",
"encoding": {
"text": {
"value": "Low " + bubblePlot.yField
},
"x": {
"value": 30
},
"y": {
"value": 190
},
"baseline": {
"value": "top"
},
"align": {
"value": "left"
},
"color": {
"value": "black"
},
"size": {
"value": 14
}
}
},
{
"mark": "text",
"encoding": {
"text": {
"value": "High " + bubblePlot.xField
},
"x": {
"value": 165
},
"y": {
"value": 175
},
"baseline": {
"value": "top"
},
"align": {
"value": "left"
},
"color": {
"value": "black"
},
"size": {
"value": 14
}
}
},
{
"mark": "text",
"encoding": {
"text": {
"value": "Low " + bubblePlot.yField
},
"x": {
"value": 165
},
"y": {
"value": 190
},
"baseline": {
"value": "top"
},
"align": {
"value": "left"
},
"color": {
"value": "black"
},
"size": {
"value": 14
}
}
},
],
};
})
};
vegaEmbed('#plot-containerBubble', plotSpecBubble).catch(console.error);
return plotSpecBubble;
}
function resetScatterPlots(){
plotSpecScatter = {};
scatterPlots = {};
filterDataByYear();
}
function toggleText(id) {
var text = document.getElementById(id);
text.classList.toggle("show");
}
function player1Selected(){
if (selectedPosition === "C") {
selectedC = document.getElementById("player1").value;
selectedCData = filteredData.find(function(row) {
return row.Name === selectedC;
});
document.getElementById('CText').innerHTML = "<strong>Selected Catcher: </strong>" + selectedCData.Name;
}
else if (selectedPosition === "1B") {
selected1B = document.getElementById("player1").value;
selected1BData = filteredData.find(function(row) {
return row.Name === selected1B;
});
document.getElementById('1BText').innerHTML = "<strong>Selected First Baseman: </strong>" + selected1BData.Name;
}
else if (selectedPosition === "2B") {
selected2B = document.getElementById("player1").value;
selected2BData = filteredData.find(function(row) {
return row.Name === selected2B;
});
document.getElementById('2BText').innerHTML = "<strong>Selected Second Baseman: </strong>" + selected2BData.Name;
}
else if (selectedPosition === "3B") {
selected3B = document.getElementById("player1").value;
selected3BData = filteredData.find(function(row) {
return row.Name === selected3B;
});
document.getElementById('3BText').innerHTML = "<strong>Selected Third Baseman: </strong>" + selected3BData.Name;
}
else if (selectedPosition === "SS") {
selectedSS = document.getElementById("player1").value;
selectedSSData = filteredData.find(function(row) {
return row.Name === selectedSS;
});
document.getElementById('SSText').innerHTML = "<strong>Selected Shortstop: </strong>" + selectedSSData.Name;
}
else if (selectedPosition === "LF") {
selectedLF = document.getElementById("player1").value;
selectedLFData = filteredData.find(function(row) {
return row.Name === selectedLF;
});
document.getElementById('LFText').innerHTML = "<strong>Selected Left Fielder: </strong>" + selectedLFData.Name;
}
else if (selectedPosition === "CF") {
selectedCF = document.getElementById("player1").value;
selectedCFData = filteredData.find(function(row) {
return row.Name === selectedCF;
});
document.getElementById('CFText').innerHTML = "<strong>Selected Center Fielder: </strong>" + selectedCFData.Name;
}
else if (selectedPosition === "RF") {