josephsoo commited on
Commit
ed01a53
·
1 Parent(s): 3d638e4

Keep automatic dataset playback running

Browse files
Files changed (1) hide show
  1. assets/dataset_link.js +11 -18
assets/dataset_link.js CHANGED
@@ -50,7 +50,7 @@
50
  makeElement(
51
  "span",
52
  "dataset-link-hint",
53
- "Hover the raster or scrub the timeline to inspect a moment."
54
  )
55
  );
56
 
@@ -210,16 +210,18 @@
210
  const selectFromNeural = (event) => {
211
  const index = eventIndex(state, event);
212
  if (index === null) return;
213
- pause(state);
214
  renderIndex(state, index);
 
215
  };
216
  const selectFromTarget = (event) => {
217
  const point = event && event.points && event.points[0];
218
  if (!point || point.curveNumber !== state.exampleTrace) return;
219
  const index = eventIndex(state, event);
220
  if (index === null) return;
221
- pause(state);
222
  renderIndex(state, index);
 
223
  };
224
  state.neural.on("plotly_hover", selectFromNeural);
225
  state.neural.on("plotly_click", selectFromNeural);
@@ -249,19 +251,12 @@
249
  function maybeAutoplay(state) {
250
  const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
251
  if (reducedMotion) return;
252
- state.intersectionObserver = new IntersectionObserver((entries) => {
253
- const visible = entries.some((entry) => entry.isIntersecting && entry.intersectionRatio >= 0.25);
254
- if (!visible || activeState !== state) return;
255
- state.intersectionObserver.disconnect();
256
- state.intersectionObserver = null;
257
- state.autoplayTimer = window.setTimeout(() => {
258
- if (activeState === state) {
259
- renderIndex(state, 0);
260
- play(state);
261
- }
262
- }, 150);
263
- }, { threshold: [0.25] });
264
- state.intersectionObserver.observe(state.controls);
265
  }
266
 
267
  function destroy(state) {
@@ -270,7 +265,6 @@
270
  if (state.renderFrame !== null) cancelAnimationFrame(state.renderFrame);
271
  if (state.autoplayTimer !== null) window.clearTimeout(state.autoplayTimer);
272
  if (state.resizeObserver) state.resizeObserver.disconnect();
273
- if (state.intersectionObserver) state.intersectionObserver.disconnect();
274
  if (state.abortController) state.abortController.abort();
275
  (state.plotlyListeners || []).forEach(([graph, event, listener]) => {
276
  if (graph && typeof graph.removeListener === "function") {
@@ -309,7 +303,6 @@
309
  renderFrame: null,
310
  autoplayTimer: null,
311
  resizeObserver: null,
312
- intersectionObserver: null,
313
  abortController: new AbortController(),
314
  plotlyListeners: [],
315
  };
 
50
  makeElement(
51
  "span",
52
  "dataset-link-hint",
53
+ "Playback loops automatically. Pause or scrub to inspect."
54
  )
55
  );
56
 
 
210
  const selectFromNeural = (event) => {
211
  const index = eventIndex(state, event);
212
  if (index === null) return;
213
+ const keepPlaying = state.playing;
214
  renderIndex(state, index);
215
+ if (keepPlaying) play(state);
216
  };
217
  const selectFromTarget = (event) => {
218
  const point = event && event.points && event.points[0];
219
  if (!point || point.curveNumber !== state.exampleTrace) return;
220
  const index = eventIndex(state, event);
221
  if (index === null) return;
222
+ const keepPlaying = state.playing;
223
  renderIndex(state, index);
224
+ if (keepPlaying) play(state);
225
  };
226
  state.neural.on("plotly_hover", selectFromNeural);
227
  state.neural.on("plotly_click", selectFromNeural);
 
251
  function maybeAutoplay(state) {
252
  const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
253
  if (reducedMotion) return;
254
+ state.autoplayTimer = window.setTimeout(() => {
255
+ if (activeState === state) {
256
+ renderIndex(state, 0);
257
+ play(state);
258
+ }
259
+ }, 150);
 
 
 
 
 
 
 
260
  }
261
 
262
  function destroy(state) {
 
265
  if (state.renderFrame !== null) cancelAnimationFrame(state.renderFrame);
266
  if (state.autoplayTimer !== null) window.clearTimeout(state.autoplayTimer);
267
  if (state.resizeObserver) state.resizeObserver.disconnect();
 
268
  if (state.abortController) state.abortController.abort();
269
  (state.plotlyListeners || []).forEach(([graph, event, listener]) => {
270
  if (graph && typeof graph.removeListener === "function") {
 
303
  renderFrame: null,
304
  autoplayTimer: null,
305
  resizeObserver: null,
 
306
  abortController: new AbortController(),
307
  plotlyListeners: [],
308
  };