@@ -7,6 +7,10 @@ toc: false
77``` js
88// Load the data files
99const stats = await FileAttachment (" ./data/stats.json" ).json ();
10+
11+ const teamSelector = Inputs .select ([" All" , ... stats .teams ], {label: " Select Team:" });
12+ const selectedTeam = Generators .input (teamSelector);
13+
1014```
1115
1216<h3 >Goal Distribution</h3 >
@@ -59,30 +63,47 @@ ${Plot.plot({
5963 ]
6064})}
6165
66+ ${teamSelector}
67+
68+ ``` js
69+ const forwards = stats .contractRanking .filter (s => ((selectedTeam === " All" ) || (s .Team === selectedTeam)) && (s .Position === " F" ));
70+ const defencemen = stats .contractRanking .filter (s => ((selectedTeam === " All" ) || (s .Team === selectedTeam)) && (s .Position === " D" ));
71+ const goalies = stats .contractRanking .filter (s => ((selectedTeam === " All" ) || (s .Team === selectedTeam)) && (s .Position === " G" ));
72+ ```
73+
6274<h3 >Forwards Salary vs Rating</h3 >
6375${Plot.plot({
6476 marks: [
65- Plot.dot(stats.contractRanking.filter(s => s.Position === "F") , { x: "Salary", y: "Rating"}),
66- Plot.linearRegressionY(stats.contractRanking.filter(s => s.Position === "F") , {x: "Salary", y: "Rating", stroke: "red"}),
67- Plot.tip(stats.contractRanking.filter(s => s.Position === "F") , Plot.pointer({ x: "Salary", y: "Rating", title: (d) => d.Name }))
77+ Plot.dot(forwards , { x: "Salary", y: "Rating"}),
78+ Plot.linearRegressionY(forwards , {x: "Salary", y: "Rating", stroke: "red"}),
79+ Plot.tip(forwards , Plot.pointer({ x: "Salary", y: "Rating", title: (d) => d.Name }))
6880 ]
6981})}
7082
7183<h3 >Defencemen Salary vs Rating</h3 >
7284${Plot.plot({
7385 marks: [
74- Plot.dot(stats.contractRanking.filter(s => s.Position === "D") , { x: "Salary", y: "Rating"}),
75- Plot.linearRegressionY(stats.contractRanking.filter(s => s.Position === "F") , {x: "Salary", y: "Rating", stroke: "red"}),
76- Plot.tip(stats.contractRanking.filter(s => s.Position === "D") , Plot.pointer({ x: "Salary", y: "Rating", title: (d) => d.Name }))
86+ Plot.dot(defencemen , { x: "Salary", y: "Rating"}),
87+ Plot.linearRegressionY(defencemen , {x: "Salary", y: "Rating", stroke: "red"}),
88+ Plot.tip(defencemen , Plot.pointer({ x: "Salary", y: "Rating", title: (d) => d.Name }))
7789 ]
7890})}
7991
8092<h3 >Goalies Salary vs Rating</h3 >
81- ${Plot.plot({
82- marks: [
83- Plot.dot(stats.contractRanking.filter(s => s.Position === "G"), { x: "Salary", y: "Rating"}),
84- Plot.linearRegressionY(stats.contractRanking.filter(s => s.Position === "F"), {x: "Salary", y: "Rating", stroke: "red"}),
85- Plot.tip(stats.contractRanking.filter(s => s.Position === "G"), Plot.pointer({ x: "Salary", y: "Rating", title: (d) => d.Name })),
86- ]
87- })}
93+ ${
94+ (selectedTeam === "All") ?
95+ Plot.plot({
96+ marks: [
97+ Plot.dot(goalies, { x: "Salary", y: "Rating"}),
98+ Plot.linearRegressionY(goalies, {x: "Salary", y: "Rating", stroke: "red"}),
99+ Plot.tip(goalies, Plot.pointer({ x: "Salary", y: "Rating", title: (d) => d.Name })),
100+ ]
101+ }) :
102+ Plot.plot({
103+ marks: [
104+ Plot.dot(goalies, { x: "Salary", y: "Rating"}),
105+ Plot.tip(goalies, Plot.pointer({ x: "Salary", y: "Rating", title: (d) => d.Name })),
106+ ]
107+ })
108+ }
88109
0 commit comments