Skip to content

Commit

Permalink
enable dragging on stepIdx == 0
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-williams committed Oct 4, 2023
1 parent ae00bc0 commit 8321f36
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ export type HistoryState = {
t: Targets
}

function usePreviousValue<T>(value: T) {
const ref = useRef<T>();
useEffect(() => {
ref.current = value;
});
return ref.current;
}

export function Body() {
const fizzBuzzLink = <A href={"https://en.wikipedia.org/wiki/Fizz_buzz"}>Fizz Buzz</A>
const exampleTargets: LinkItem<Targets>[] = useMemo(
Expand Down Expand Up @@ -1094,13 +1102,10 @@ export function Body() {
]
)
return setLabelPoints ? values(setLabelPoints).reduce<BoundingBox<number>>(
(box, { x, y }) => [{
x: min(x, box[0].x),
y: min(y, box[0].y),
}, {
x: max(x, box[1].x),
y: max(y, box[1].y),
}],
(box, { x, y }) => [
{ x: min(x, box[0].x), y: min(y, box[0].y), },
{ x: max(x, box[1].x), y: max(y, box[1].y), },
],
shapesBox
) : shapesBox
},
Expand Down Expand Up @@ -1138,18 +1143,24 @@ export function Body() {
useEffect(
() => {
if (!autoCenter) return
if (stepIdx == 0) {
// console.log("setDoPanZoom(1): model start, panZoom warp")
panZoom(1)
return
}
if (runningState == 'none') return
// console.log(`setDoPanZoom(${autoCenterInterpRate}): autoCenter`)
// console.log(`panZoom(${autoCenterInterpRate}): autoCenter`)
panZoom(autoCenterInterpRate)
},
[ curStep, stepIdx, runningState, autoCenterInterpRate, autoCenter, panZoom ]
)

const prevBoundingBox = usePreviousValue(boundingBox)
useEffect(
() => {
if (stepIdx == 0 && !_.isEqual(prevBoundingBox, boundingBox)) {
console.log("stepIdx == 0 + new bounding box: panZoom(1)")
panZoom(1)
}
},
[ boundingBox, prevBoundingBox, stepIdx, panZoom ]
)

// panZoom "warp" on vStepIdx changes (e.g. mouseover history slider or error plot)
useEffect(
() => {
Expand Down

0 comments on commit 8321f36

Please sign in to comment.