// swarmplot.js // @author jcpoir // Generates a swarmplot using d3's force algorithm. Optimized for // the matchup stat use case // unpack arguments const scriptTag = document.querySelector('script[src*="matchup_swarm.js"]'); const filepath = scriptTag.getAttribute('data-filepath'); const active_col = scriptTag.getAttribute('data-active_col') const matchup_str = scriptTag.getAttribute("data-matchup") c1 = scriptTag.getAttribute("data-color1"); c2 = scriptTag.getAttribute("data-color2"); components = matchup_str.split("vs"); const team1 = components[0]; const team2 = components[1]; pretty_matchup = `${team1} vs ${team2}` // Define a mapping between column names, formal names for stat categories const cm = new Map(); cm.set("PTS DIFF", "Win/Loss Margin"); cm.set("TOTAL PTS", "Scoring Total"); cm.set(team1, `Points Scored, ${team1}`); cm.set(team2, `Points Scored, ${team2}`); const long_name = cm.get(active_col); // Build an html dropdown menu for the above columns d = `