forked from dickreuter/Poker
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3114bbc
commit 8969e05
Showing
5 changed files
with
132 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React from 'react'; | ||
import { VictoryChart, VictoryScatter, VictoryTooltip, VictoryAxis } from 'victory'; | ||
|
||
interface RawData { | ||
wins: string; | ||
losses: string; | ||
} | ||
|
||
interface ScatterData { | ||
x: number; | ||
y: number; | ||
z?: number; | ||
} | ||
|
||
interface ScatterplotProps { | ||
data: RawData; | ||
} | ||
|
||
const parseData = (rawData: RawData): { wins: ScatterData[], losses: ScatterData[] } => { | ||
if (!rawData.wins || !rawData.losses) { | ||
console.error('Data is not defined:', rawData); | ||
return { wins: [], losses: [] }; | ||
} | ||
|
||
let wins: ScatterData[] = []; | ||
let losses: ScatterData[] = []; | ||
try { | ||
wins = JSON.parse(rawData.wins).map((entry: any) => ({ | ||
// z: parseFloat(entry.FinalFundsChange), | ||
x: Number(entry.equity), | ||
y: parseFloat(entry.minCall) | ||
})); | ||
|
||
losses = JSON.parse(rawData.losses).map((entry: any) => ({ | ||
// z: parseFloat(entry.FinalFundsChange), | ||
x: Number(entry.equity), | ||
y: parseFloat(entry.minCall) | ||
})); | ||
} catch (error) { | ||
console.error('Error parsing the data:', error); | ||
} | ||
|
||
return { wins, losses }; | ||
} | ||
|
||
const ScatterplotComponent: React.FC<ScatterplotProps> = ({ data }) => { | ||
const parsedData = parseData(data); | ||
|
||
return ( | ||
<VictoryChart | ||
domainPadding={20} | ||
width={800} | ||
height={300} | ||
domain={{ x: [0, 1] }, { y: [0, 2] }} | ||
> | ||
<VictoryAxis | ||
label="Equity" | ||
/> | ||
<VictoryAxis | ||
dependentAxis | ||
label="Minimum Call" | ||
/> | ||
<VictoryScatter | ||
data={parsedData.wins} | ||
x="x" | ||
y="y" | ||
size={5} // Set a constant dot size. Adjust this value as needed. | ||
labels={({ datum }) => `Equity: ${datum.x}\nMinimum Call: ${datum.y}\nPayoff: ${datum.z}`} | ||
labelComponent={<VictoryTooltip />} | ||
style={{ data: { fill: "green" } }} | ||
/> | ||
<VictoryScatter | ||
data={parsedData.losses} | ||
x="x" | ||
y="y" | ||
size={5} // Set a constant dot size. Adjust this value as needed. | ||
labels={({ datum }) => `Equity: ${datum.x}\nMinimum Call: ${datum.y}`} | ||
labelComponent={<VictoryTooltip />} | ||
style={{ data: { fill: "red" } }} | ||
/> | ||
</VictoryChart> | ||
); | ||
} | ||
|
||
export default ScatterplotComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters