Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Plotting #614

Merged
merged 53 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
76463d1
new plotting draft
PythonFZ Aug 14, 2024
b9cf229
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 14, 2024
c1322d3
duplicate button, snap to grid
PythonFZ Aug 14, 2024
8e1d57e
working version of multiple plots
PythonFZ Aug 15, 2024
3dca9b8
show plots
PythonFZ Aug 15, 2024
d02235f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 15, 2024
3cb53ea
support upload
PythonFZ Aug 15, 2024
fc0c20f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 15, 2024
cb7cd5d
fix analysis methods
PythonFZ Aug 15, 2024
e0c8592
update analysis tests
PythonFZ Aug 15, 2024
cf499e4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 15, 2024
a72499c
Merge branch 'main' into plotting-updates
PythonFZ Aug 15, 2024
017ac98
support selected frames
PythonFZ Aug 15, 2024
4956f79
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 15, 2024
4bfdd29
sort, unique and log selected ids
PythonFZ Aug 15, 2024
468c5b0
update progress bar viewer
PythonFZ Aug 16, 2024
a53ab20
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 16, 2024
f830aad
improve UI looks
PythonFZ Aug 19, 2024
66fac17
use set
PythonFZ Aug 19, 2024
df3569c
reset selection
PythonFZ Aug 19, 2024
87fbc67
fix bookmarks
PythonFZ Aug 19, 2024
0d84e3c
improve plottly hover experience
PythonFZ Aug 19, 2024
269cc46
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 19, 2024
e0d343a
allow for default plot size
PythonFZ Aug 19, 2024
de4b5ec
react state bugfix
PythonFZ Aug 19, 2024
ce91fa6
show SOME plot when running
PythonFZ Aug 19, 2024
bc16161
add `ShowPlotsWindow`
PythonFZ Aug 19, 2024
cda742a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 19, 2024
a25eede
add missing tooltip
PythonFZ Aug 19, 2024
f201f37
Merge branch 'plotting-updates' of https://github.com/zincware/ZnDraw…
PythonFZ Aug 19, 2024
5bf5228
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 19, 2024
07f3e65
bugfix and UI improvement
PythonFZ Aug 19, 2024
5d229d5
add controls crosshair
PythonFZ Aug 19, 2024
e3dc471
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 19, 2024
5fc67a7
split progress bar into multiple pars
PythonFZ Aug 20, 2024
7977c2d
remove iteration over all positions
PythonFZ Aug 20, 2024
c189a0e
performance improvements
PythonFZ Aug 20, 2024
0fbb98a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 20, 2024
dc43953
make handle draggable
PythonFZ Aug 20, 2024
96b096a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 20, 2024
a66fcb0
add plots window button
PythonFZ Aug 20, 2024
fd8c4ad
remove showplots python code
PythonFZ Aug 20, 2024
6ea658f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 20, 2024
f4cc100
limit max and minimum frame for dragging
PythonFZ Aug 20, 2024
1371bc1
improve progress bar style
PythonFZ Aug 23, 2024
d7e4374
add allowDrag button
PythonFZ Aug 23, 2024
677d20b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 23, 2024
2b3615d
use `bg-secondary` instead of `bg-dark`
PythonFZ Aug 23, 2024
cd55820
toggle frame
PythonFZ Aug 26, 2024
316dd30
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 26, 2024
32fcda9
full plots support
PythonFZ Aug 26, 2024
d5b5f46
Merge branch 'plotting-updates' of https://github.com/zincware/ZnDraw…
PythonFZ Aug 26, 2024
5113862
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions app/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,62 @@
height: 100%;
border: none;
}
:root {
--handle-size: 12px; /* Base size for the handle */
--handle-color: rgb(48, 75, 183); /* Color of the handle */
}

.square {
width: var(--handle-size);
height: var(--handle-size);
background-color: var(--handle-color); /* Color of the square */
border-left: calc(var(--handle-size) / 2) solid transparent;
border-right: calc(var(--handle-size) / 2) solid transparent;
}

.triangle {
width: 0;
height: 0;
border-left: calc(var(--handle-size) / 2) solid transparent;
border-right: calc(var(--handle-size) / 2) solid transparent;
border-top: calc(var(--handle-size) / 2) solid var(--handle-color); /* Color of the triangle */
}

.handle {
position: absolute;
top: -15px; /* Adjust this value based on your design */
transform: translateX(-50%);
display: flex;
align-items: center;
flex-direction: column;
/* z-index: 2; */
}

.progress-bar-v-line {
position: absolute;
top: 0;
left: 0;
transform: translateX(-50%);
width: 2px; /* Thickness of the line */
height: 100%; /* Full height of the column */
background-color: var(--handle-color); /* Color of the line */
/* z-index: 1; */
}

.progress-bar-tick-line {
position: absolute;
top: 0;
left: 0;
transform: translateX(-50%) translateY(-100%);
width: 1px; /* Thickness of the line */
height: 14%; /* Size of the tick */
/* z-index: 1; */
}

.progress-bar-bookmark {
position: absolute;
top: 0;
left: 0;
/* z-index: 1; */
transform: translateX(-50%) translateY(100%);
}
95 changes: 89 additions & 6 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import {
import { Frames, Frame, Player } from "./components/particles";
import { Geometries } from "./components/geometries";
import "./App.css";
import { Plotting } from "./components/plotting";

import { Canvas, useThree } from "@react-three/fiber";
import { Canvas, useThree, useFrame } from "@react-three/fiber";
import {
OrbitControls,
PerspectiveCamera,
TrackballControls,
TransformControls,
Box,
} from "@react-three/drei";
import { Button, InputGroup, Form } from "react-bootstrap";
import * as THREE from "three";
Expand All @@ -36,6 +38,52 @@ import { ParticleInfoOverlay, SceneInfoOverlay } from "./components/overlays";
import VectorField from "./components/vectorfield";
import { useColorMode } from "./components/utils";

const MoveCameraTarget = ({
controlsRef,
colorMode,
}: {
controlsRef: any;
colorMode: string;
}) => {
Comment on lines +42 to +48
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to a module

const controlsCrosshairRef = useRef<THREE.Object3D>(null);
const shortDimension = 0.05;
const longDimension = 0.5;

// Update the controlsCrosshair position to match the orbit controls target
useFrame(() => {
if (controlsCrosshairRef.current && controlsRef.current) {
const crosshair = controlsCrosshairRef.current;
const target = controlsRef.current.target;
crosshair.position.copy(target);
}
});

return (
<group ref={controlsCrosshairRef}>
{/* X axis box */}
<Box scale={[longDimension, shortDimension, shortDimension]}>
<meshStandardMaterial
color={colorMode == "light" ? "#454b66" : "#f5fdc6"}
/>
</Box>

{/* Y axis box */}
<Box scale={[shortDimension, longDimension, shortDimension]}>
<meshStandardMaterial
color={colorMode == "light" ? "#454b66" : "#f5fdc6"}
/>
</Box>

{/* Z axis box */}
<Box scale={[shortDimension, shortDimension, longDimension]}>
<meshStandardMaterial
color={colorMode == "light" ? "#454b66" : "#f5fdc6"}
/>
</Box>
</group>
);
};

export default function App() {
// const [isConnected, setIsConnected] = useState(socket.connected);
// const [fooEvents, setFooEvents] = useState([]);
Expand All @@ -60,6 +108,7 @@ export default function App() {
const [length, setLength] = useState<number>(0);
// updated via sockets
const [step, setStep] = useState<number>(0);
const [selectedFrames, setSelectedFrames] = useState<Set<number>>(new Set());
const [selectedIds, setSelectedIds] = useState<Set<number>>(new Set());
const [bookmarks, setBookmarks] = useState<any>({}); // {name: [step, ...]
const [points, setPoints] = useState<THREE.Vector3[]>([]);
Expand Down Expand Up @@ -393,8 +442,18 @@ export default function App() {
setStep(nextBookmark);
}
} else {
// Move to the next step, or wrap around to the start
setStep((prevStep) => (prevStep + 1 < length ? prevStep + 1 : 0));
if (selectedFrames.size > 0) {
const nextFrame = Array.from(selectedFrames).find(
(frame) => frame > step,
);
if (nextFrame) {
setStep(nextFrame);
} else {
setStep(Math.min(...selectedFrames));
}
} else {
setStep((prevStep) => (prevStep + 1 < length ? prevStep + 1 : 0));
}
}
} else if (event.key === "ArrowLeft") {
setPlaying(false);
Expand All @@ -410,9 +469,22 @@ export default function App() {
}
} else {
// Move to the previous step, or wrap around to the end
setStep((prevStep) =>
prevStep - 1 >= 0 ? prevStep - 1 : length - 1,
);
// check if selectedFrames length is greater than 0, then only jump
// between selectedFrames
if (selectedFrames.size > 0) {
const previousFrame = Array.from(selectedFrames)
.reverse()
.find((frame) => frame < step);
if (previousFrame) {
setStep(previousFrame);
} else {
setStep(Math.max(...selectedFrames));
}
} else {
setStep((prevStep) =>
prevStep - 1 >= 0 ? prevStep - 1 : length - 1,
);
}
}
} else if (event.key == "ArrowUp") {
// jump 10 percent, or to the end
Expand All @@ -425,6 +497,7 @@ export default function App() {
const newStep = Math.max(step - Math.floor(length / 10), 0);
setStep(newStep);
} else if (event.key == " ") {
// backspace
updateLength();
setPlaying((prev) => !prev);
if (step == length - 1) {
Expand Down Expand Up @@ -656,6 +729,12 @@ export default function App() {
makeDefault
/>
)}
{roomConfig["scene"].crosshair && (
<MoveCameraTarget
controlsRef={controlsRef}
colorMode={colorMode}
/>
)}
<Player
playing={playing}
togglePlaying={setPlaying}
Expand All @@ -664,6 +743,7 @@ export default function App() {
fps={roomConfig["scene"].fps}
loop={roomConfig["scene"]["Animation Loop"]}
length={length}
selectedFrames={selectedFrames}
/>
<Line3D
points={points}
Expand Down Expand Up @@ -746,7 +826,10 @@ export default function App() {
setStep={setStep}
bookmarks={bookmarks}
setBookmarks={setBookmarks}
selectedFrames={selectedFrames}
setSelectedFrames={setSelectedFrames}
/>
<Plotting setStep={setStep} setSelectedFrames={setSelectedFrames} />
{showParticleInfo && (
<>
<ParticleInfoOverlay
Expand Down
34 changes: 31 additions & 3 deletions app/src/components/particles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ export interface Frames {
[key: number]: { _type: string; value: Frame };
}

interface PlayerProps {
playing: boolean;
step: number;
setStep: (step: number) => void;
fps: number;
length: number;
loop: boolean;
togglePlaying: (playing: boolean) => void;
selectedFrames: Set<number>;
}

export const Player = ({
playing,
step,
Expand All @@ -30,7 +41,8 @@ export const Player = ({
length,
loop,
togglePlaying: setPlaying,
}: any) => {
selectedFrames,
}: PlayerProps) => {
useFrame(({ clock }) => {
const a = clock.getElapsedTime();
if (a > 1 / fps) {
Expand All @@ -39,10 +51,26 @@ export const Player = ({
if (!loop) {
setPlaying(!playing);
} else {
setStep(0);
if (selectedFrames.size > 0) {
setStep(Math.min(...selectedFrames));
} else {
setStep(0);
}
}
} else {
setStep(step + 1);
// TODO: handle selectedFrames
if (selectedFrames.size > 0) {
const nextFrame = Array.from(selectedFrames).find(
(frame) => frame > step,
);
if (nextFrame) {
setStep(nextFrame);
} else {
setStep(Math.min(...selectedFrames));
}
} else {
setStep(step + 1);
}
}
}
// reset the clock
Expand Down
Loading
Loading