Skip to content

Commit

Permalink
Swap axis order when showing ranks
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmatter committed May 10, 2024
1 parent 3602de0 commit 1bc0313
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ui/views/PlayerGraphs/ScatterPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ScatterPlotProps<Row> = {
getLink: (row: Row) => string;
getTooltipTitle: (row: Row) => string;
renderTooltip: (value: number, row: Row, i: number) => ReactNode;
reverseAxis: [boolean, boolean];
stat: [string, string];
statType: [string, string];
};
Expand Down Expand Up @@ -90,6 +91,7 @@ const ScatterPlot = <Row extends unknown>({
getLink,
getTooltipTitle,
renderTooltip,
reverseAxis,
width: totalWidth,
}: ScatterPlotProps<Row> & {
width: number;
Expand All @@ -100,8 +102,14 @@ const ScatterPlot = <Row extends unknown>({
const yVals = data.map(point => point.y);

const xDomain = [Math.min(...xVals), Math.max(...xVals)];
if (reverseAxis[0]) {
xDomain.reverse();
}

const yDomain = [Math.min(...yVals), Math.max(...yVals)];
if (reverseAxis[1]) {
yDomain.reverse();
}

// tooltip handler
const {
Expand Down
1 change: 1 addition & 0 deletions src/ui/views/PlayerGraphs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ const GraphCreation = ({
</div>
);
}}
reverseAxis={[false, false]}
stat={stat}
statType={statType}
/>
Expand Down
5 changes: 5 additions & 0 deletions src/ui/views/TeamGraphs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ const GraphCreation = <Team extends ViewProps["teamsX"][number]>({
const titleY = getStatsWithLabels([stat[1]], statType[1], true)[0];
const descShort: [string, string] = [titleX.title, titleY.title];

const reverseAxis = stat.map(
(stat, i) => statType[i] === "powerRankings" && stat.startsWith("rank"),
) as [boolean, boolean];

return (
<StatGraph<Team>
data={data}
Expand All @@ -257,6 +261,7 @@ const GraphCreation = <Team extends ViewProps["teamsX"][number]>({
</div>
);
}}
reverseAxis={reverseAxis}
stat={stat}
statType={statType}
/>
Expand Down

0 comments on commit 1bc0313

Please sign in to comment.