Skip to content

Commit

Permalink
keep same x and y data with both 2d and 3d
Browse files Browse the repository at this point in the history
  • Loading branch information
ndittren committed Apr 24, 2024
1 parent 9c7faa5 commit ff2d1f6
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions media/js/src/simulationOne/scatterPlot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ export const ScatterPlot = ({ N, correlation, seed, setAppRvalue,
const generateData = () => {
const rng = seedrandom(seed);

const generatedData = [];
if (typeof correlation === 'number') {
let generatedData = [...data];
if (generatedData.length === 0 && typeof correlation === 'number') {
for (let i = 0; i < N; i++) {
const x = Math.round(rng() * 100);
const y = Math.round(correlation * x + Math.sqrt(
1 - Math.pow(correlation, 2)) * rng() * 100);
if (plotType === '3d') {
const z = Math.round(correlation * y + Math.sqrt(
1 - Math.pow(correlation, 2)) * rng() * 100);
generatedData.push({ x, y, z });
} else {
generatedData.push({ x, y });
}
generatedData.push({ x, y });
}
}

if (plotType === '3d') {
generatedData = generatedData.map(point => ({
...point,
z: Math.round(correlation * point.x + Math.sqrt(
1 - Math.pow(correlation, 2)) * rng() * 100)
}));
}

return generatedData;
};

Expand Down

0 comments on commit ff2d1f6

Please sign in to comment.