sportsdataverse / sportyR

R package for drawing regulation playing surfaces for several sports
https://sportyR.sportsdataverse.org
GNU General Public License v3.0
101 stars 7 forks source link

geom_hockey plotting of objects outside of the ice surface #36

Closed alanryder closed 3 months ago

alanryder commented 6 months ago

The plotting of player benches, penalty boxes, and the off-ice officials box are not very useful and should not be the default behaviour. These can be suppressed only for the full rink only by setting the display_range parameter to "in bounds only". There is no option to exclude these out of bounds objects from the offensive, neutral, and defensive zone plots. I think it would be better to add these out of bounds objects based on a boolean parameter (which should default to FALSE).

rossdrucker commented 6 months ago

Thanks for the note @alanryder. When initially developing the hockey rink (as well as all other surfaces currently supported), I spent a good amount of time debating whether or not to include features that are out of bounds like team bench areas for hockey and football or the substitution area on a basketball court. What I ultimately settled on is that if specifications are provided in the rule books for the given sport, then I'll include the features as a default. As bench specs are provided for most hockey leagues (for example, Rule 3.1 here provides dimensions for NHL benches), I included them as the default behavior.

I'd respectfully push back a bit on these not being useful; I think it depends on the use case. While certain events like hits or passes may not depend on these features' presence, it may eventually be useful if(/hopefully when) tracking data becomes available to demonstrate where these features are by team if not by player, and the package was designed with this in mind. If, for example, you wanted to use {sportyR} to show play development where a player had just jumped on the ice and received a pass, replace a broken stick, or left the penalty box, it might be of interest to include where those features are in relation to the rest of the play. The off-ice officials box may not fit this description, but given that it's always situated between the benches, it was easier to include than exclude.

I'm also a bit hesitant to add a parameter for these types of features, as the intention/"philosophy" of the rest of the package is uniformity of arguments across sports. This enables myself and anyone else who wishes to contribute to the package to quickly get a new sport set up as well as identify any underlying problems. As not every sport has out-of-bounds features like this, and some have out-of-bounds features that may be important (e.g. behind the baseline of a tennis court, or the 10-foot line extension on a volleyball court where players are regularly out-of-bounds but in play), having this parameter and setting it to FALSE seems like it'd make maintenance harder than needed.

If you'd like the features you note to be effectively hidden, the code below should do the trick:

library(sportyR)
geom_hockey(
  league = "nhl",
  rink_updates = list(
    bench_length = 0,
    bench_depth = 0,
    bench_separation = 0,
    penalty_box_length = 0,
    penalty_box_depth = 0,
    penalty_box_separation = 0
  )
)

library(sportyR)
geom_hockey(
  league = "nhl",
  display_range = "ozone",
  rink_updates = list(
    bench_length = 0,
    bench_depth = 0,
    bench_separation = 0,
    penalty_box_length = 0,
    penalty_box_depth = 0,
    penalty_box_separation = 0
  )
)

library(sportyR)
geom_hockey(
  league = "nhl",
  display_range = "nzone",
  rink_updates = list(
    bench_length = 0,
    bench_depth = 0,
    bench_separation = 0,
    penalty_box_length = 0,
    penalty_box_depth = 0,
    penalty_box_separation = 0
  )
)

library(sportyR)
geom_hockey(
  league = "nhl",
  display_range = "dzone",
  rink_updates = list(
    bench_length = 0,
    bench_depth = 0,
    bench_separation = 0,
    penalty_box_length = 0,
    penalty_box_depth = 0,
    penalty_box_separation = 0
  )
)

I realize that in the full (default) display range and the nzone display range there is still a small rectangle that appears. There are a few options I can implement relatively quickly, although I'm admittedly a bit hesitant to introduce more parameters as it becomes much more challenging for both myself and users to maintain:

  1. Introduce new surface dimensions for each hockey league called bench_outline_thickness and penalty_box_outline_thickness, which may be controlled similarly to the ones I set above. They'll default to the same thickness as the boards, so it'll be up to users to set them to 0 when desired (as well as the features set in the examples above). Current behavior sets the thickness of the outline of the bench and penalty boxes to the same thickness as the boards, which seems appropriate as they're physically the same thickness as the boards at a rink
  2. Introduce new coloring parameters for bench_outline and penalty_box_outline. Given the code under the hood here, I'd likely implement the bench_outline color parameter as being team-dependent while the penalty_box_outline would be one color for both teams. This would be easy enough to implement relatively quickly, so setting the colors to #ffffff or NULL (or whatever color you have set for plot_background if you've adjusted it via color_updates) should remove the feature. You'd also need to set the color for the off-ice officials box to the same so it wouldn't show
  3. Implementing both 1 and 2 above, which is adding additional complexity but provides the most number of options (and also introducing the most number of places for things to error)

Does this help? If you'd like me to pursue additional development, do you have a preference of the options above or an alternative idea?

alanryder commented 6 months ago

Thanks for the quick and thoughtful response (and thanks even more for the package).

As a hockey guy, I think of the limits of the playing surface as quite black and white. But I can think of counter examples in most other sports. I fully appreciate your goal to have coding frameworks consistent across sports. My view of default behaviour is just mine (for hockey).

My use case is a half rink or offensive/ defensive zone plot. You implement these (including several synonyms for each), but the out-of-bounds objects become a visual distraction as we zoom in. You provide the option of removing these out-of-bounds objects for a full-rink plot, but not when “zoomed in” on parts of the rink. So, this just seems incomplete to me. Perhaps there is a more elegant solution than the one I suggested.

I agree that the code you provided should meet my needs. Don’t go recoding on my account.

Regards,

Alan

From: Ross Drucker @.> Sent: Friday, March 8, 2024 12:15 PM To: sportsdataverse/sportyR @.> Cc: alanryder @.>; Mention @.> Subject: Re: [sportsdataverse/sportyR] geom_hockey plotting of objects outside of the ice surface (Issue #36)

Thanks for the note @alanryder https://github.com/alanryder . When initially developing the hockey rink (as well as all other surfaces currently supported), I spent a good amount of time debating whether or not to include features that are out of bounds like team bench areas for hockey and football or the substitution area on a basketball court. What I ultimately settled on is that if specifications are provided in the rule books for the given sport, then I'll include the features as a default. As bench specs are provided for most hockey leagues (for example, Rule 3.1 here https://media.nhl.com/site/asset/public/ext/2023-24/2023-24Rulebook.pdf provides dimensions for NHL benches), I included them as the default behavior.

I'd respectfully push back a bit on these not being useful; I think it depends on the use case. While certain events like hits or passes may not depend on these features' presence, it may eventually be useful if(/hopefully when) tracking data becomes available to demonstrate where these features are by team if not by player, and the package was designed with this in mind. If, for example, you wanted to use {sportyR} to show play development where a player had just jumped on the ice and received a pass, replace a broken stick, or left the penalty box, it might be of interest to include where those features are in relation to the rest of the play. The off-ice officials box may not fit this description, but given that it's always situated between the benches, it was easier to include than exclude.

I'm also a bit hesitant to add a parameter for these types of features, as the intention/"philosophy" of the rest of the package is uniformity of arguments across sports. This enables myself and anyone else who wishes to contribute to the package to quickly get a new sport set up as well as identify any underlying problems. As not every sport has out-of-bounds features like this, and some have out-of-bounds features that may be important (e.g. behind the baseline of a tennis court, or the 10-foot line extension on a volleyball court where players are regularly out-of-bounds but in play), having this parameter and setting it to FALSE seems like it'd make maintenance harder than needed.

If you'd like the features you note to be effectively hidden, the code below should do the trick:

library(sportyR) geom_hockey( league = "nhl", rink_updates = list( bench_length = 0, bench_depth = 0, bench_separation = 0, penalty_box_length = 0, penalty_box_depth = 0, penalty_box_separation = 0 ) )

https://camo.githubusercontent.com/12d2439dc22e51da04a8831e7ede616b10dc77b60bc44bbc044ee628c6a5e4a5/68747470733a2f2f692e696d6775722e636f6d2f3353564b534d372e706e67

library(sportyR) geom_hockey( league = "nhl", display_range = "ozone", rink_updates = list( bench_length = 0, bench_depth = 0, bench_separation = 0, penalty_box_length = 0, penalty_box_depth = 0, penalty_box_separation = 0 ) )

https://camo.githubusercontent.com/aeddbee7965b013bfb7863b51c670e0e44861fecf5aad305320125642eb476c0/68747470733a2f2f692e696d6775722e636f6d2f426a50485564612e706e67

library(sportyR) geom_hockey( league = "nhl", display_range = "nzone", rink_updates = list( bench_length = 0, bench_depth = 0, bench_separation = 0, penalty_box_length = 0, penalty_box_depth = 0, penalty_box_separation = 0 ) )

https://camo.githubusercontent.com/0ee0370d63c13efce890419374c201543f52925e7ffcf47583174c0f299a4dea/68747470733a2f2f692e696d6775722e636f6d2f6b4b543479546e2e706e67

library(sportyR) geom_hockey( league = "nhl", display_range = "dzone", rink_updates = list( bench_length = 0, bench_depth = 0, bench_separation = 0, penalty_box_length = 0, penalty_box_depth = 0, penalty_box_separation = 0 ) )

https://camo.githubusercontent.com/cb0ef480539b90f0f335493e8a65e4aea6df87011217b1e81796a3091cc7bef1/68747470733a2f2f692e696d6775722e636f6d2f4743486a5272742e706e67

I realize that in the full (default) display range and the nzone display range there is still a small rectangle that appears. There are a few options I can implement relatively quickly, although I'm admittedly a bit hesitant to introduce more parameters as it becomes much more challenging for both myself and users to maintain:

  1. Introduce new surface dimensions for each hockey league called bench_outline_thickness and penalty_box_outline_thickness, which may be controlled similarly to the ones I set above. They'll default to the same thickness as the boards, so it'll be up to users to set them to 0 when desired (as well as the features set in the examples above). Current behavior sets the thickness of the outline of the bench and penalty boxes to the same thickness as the boards, which seems appropriate as they're physically the same thickness as the boards at a rink
  2. Introduce new coloring parameters for bench_outline and penalty_box_outline. Given the code under the hood here, I'd likely implement the bench_outline color parameter as being team-dependent while the penalty_box_outline would be one color for both teams. This would be easy enough to implement relatively quickly, so setting the colors to #ffffff or NULL (or whatever color you have set for plot_background if you've adjusted it via color_updates) should remove the feature. You'd also need to set the color for the off-ice officials box to the same so it wouldn't show
  3. Implementing both 1 and 2 above, which is adding additional complexity but provides the most number of options (and also introducing the most number of places for things to error)

Does this help? If you'd like me to pursue additional development, do you have a preference of the options above or an alternative idea?

— Reply to this email directly, https://github.com/sportsdataverse/sportyR/issues/36#issuecomment-1986357297 view it on GitHub, or https://github.com/notifications/unsubscribe-auth/AB57OMH24CBSP2ECY35SIH3YXIL4JAVCNFSM6AAAAABENJBZGWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBWGM2TOMRZG4 unsubscribe. You are receiving this because you were mentioned. https://github.com/notifications/beacon/AB57OMEICLSLKS5JDJT224LYXIL4JA5CNFSM6AAAAABENJBZGWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTWMVUDC.gif Message ID: < @.> @.>