From 1a41f086a2553543dfa9b9d1e98b257d5b9b748e Mon Sep 17 00:00:00 2001 From: Tolu Date: Sat, 3 Feb 2024 17:31:43 -0500 Subject: [PATCH] Added percentiles for player compare chart --- .../compare-page/compare-function.js | 3 +- .../compare-page/compare-player-section.css | 83 +++++++++++++++++++ .../compare-page/compare-player-section.js | 46 ++++++++-- 3 files changed, 124 insertions(+), 8 deletions(-) diff --git a/prem-data/src/components/compare-page/compare-function.js b/prem-data/src/components/compare-page/compare-function.js index 359d468..21472e8 100644 --- a/prem-data/src/components/compare-page/compare-function.js +++ b/prem-data/src/components/compare-page/compare-function.js @@ -76,7 +76,6 @@ const normalizeNames = {'Expected Goals per 90': 'xG90', const findNestedField = (obj, targetField) => { for (const key in obj) { if (key === targetField) { - console.log(obj[key][0]); return obj[key][0]; } else if (typeof obj[key] === 'object') { @@ -89,7 +88,7 @@ const findNestedField = (obj, targetField) => { return undefined; // Field not found }; -export default function RadarAxisMaker({player1, player2, attributes}){ +export default function RadarAxisMaker({player1, player2, attributes, }){ var playerChartList = []; diff --git a/prem-data/src/components/compare-page/compare-player-section.css b/prem-data/src/components/compare-page/compare-player-section.css index 477a8fe..4311122 100644 --- a/prem-data/src/components/compare-page/compare-player-section.css +++ b/prem-data/src/components/compare-page/compare-player-section.css @@ -35,4 +35,87 @@ } .compare-search-field{ width: 40%; + height: fit-content; +} + +.percentile-toggle { + display: flex; + justify-items: center; + align-items: center; +} +.percentile-toggle p { + color: white; + font-size: 0.8em; +} + + +/* slider */ +.switch { + position: relative; + display: inline-block; + width: 60px; + height: 20px; + } +.switch input { + opacity: 0; + width: 0; + height: 0; +} +.slider { + position: absolute; + cursor: pointer; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: #ccc; + -webkit-transition: .4s; + transition: .4s; +} + +.slider:before { + position: absolute; + content: ""; + height: 16px; + width: 16px; + left: 4px; + bottom: 2px; + background-color: white; + -webkit-transition: .4s; + transition: .4s; +} + +input:checked + .slider { + background-color: #2196F3; +} + +input:focus + .slider { + box-shadow: 0 0 1px #2196F3; +} + +input:checked + .slider:before { + -webkit-transform: translateX(36px); + -ms-transform: translateX(36px); + transform: translateX(36px); +} + + /* Rounded sliders */ +.slider.round { + border-radius: 12px; +} + +.slider.round:before { + border-radius: 50%; +} +.percentile-options{ + color: white; + height: 100%; + display: flex; + justify-content: center; +} +.compare-image-percentile{ + display: flex; + height: 70%; + align-items: center; + justify-content: center; } \ No newline at end of file diff --git a/prem-data/src/components/compare-page/compare-player-section.js b/prem-data/src/components/compare-page/compare-player-section.js index e86ad0c..364640a 100644 --- a/prem-data/src/components/compare-page/compare-player-section.js +++ b/prem-data/src/components/compare-page/compare-player-section.js @@ -10,6 +10,8 @@ const ComparePlayerSection = ({setPlayer}) => { const [player1, setPlayer1] = useState(); const [player2, setPlayer2] = useState(); const [selectedItems, setSelectedItems] = useState([]); + const [isPercentileMode, setIsPercentileMode] = useState(false); + const [percentileComparer, setPercentileComparer] = useState(0); const options = ['Expected Goals per 90', @@ -87,8 +89,10 @@ const ComparePlayerSection = ({setPlayer}) => { setSelectedItems(checkedItems); }; - console.log(player1) - console.log(player2) + const handlePercentileToggle = event => { + setIsPercentileMode(current => !current); + setPercentileComparer(0); + }; return(
@@ -100,18 +104,48 @@ const ComparePlayerSection = ({setPlayer}) => {
- { - player1 && + {player1 && +
+ + { + isPercentileMode && player1.position.includes(",") && +
+ + + + +
+ + } +
}
- { - player2 && + {player2 && +
+ + { + isPercentileMode && player2.position.includes(",") && +
+ + + + +
+ } +
}
+
+

Use percentiles on graph

+ +