|
1 | 1 | <script lang="ts"> |
2 | 2 | import { onMount } from 'svelte'; |
| 3 | + import { activeDatasets } from '../store'; |
3 | 4 | import type DataSet from '../data/DataSet'; |
4 | | - import type DataGroup from '../data/DataSet'; |
5 | 5 | import { DEFAULT_VIEWPORT } from '../data/DataSet'; |
6 | 6 | import EpiDate from '../data/EpiDate'; |
7 | 7 | import { Align, contains, isTouchEvent, NavMode, zeroPad } from './chartUtils'; |
|
82 | 82 | export let showPoints = false; |
83 | 83 | export let interpolate = false; |
84 | 84 | export let highlightedDate: EpiDate | null = null; |
85 | | - export let datasets: DataSet[] = []; |
| 85 | +
|
| 86 | + $: datasets = $activeDatasets; |
86 | 87 |
|
87 | 88 | function date2x(date: number): number { |
88 | 89 | return ((date - xMin) / (xMax - xMin)) * width; |
|
381 | 382 | return { x: x + dx, y: y + dy - h, w: w, h: h }; |
382 | 383 | } |
383 | 384 |
|
384 | | - // Fit viewport to the currently available datasets. |
385 | | - // Since there is a delay to new changes propagating to the datasets variable, the |
386 | | - // include and exclude arguments are used to make sure a recently selected |
387 | | - // or de-selected dataset is properly accounted for. |
388 | | - export function fitData( |
389 | | - shouldAnimate = false, |
390 | | - include: DataSet | DataGroup | null = null, |
391 | | - exclude: DataSet | DataGroup | null = null, |
392 | | - ): void { |
393 | | - // No data, nothing to fit |
394 | | - if (datasets.length === 0 && !include) { |
395 | | - return; |
396 | | - } |
397 | | - // Just deselected the only dataset, nothing to fit |
398 | | - if (datasets.length === 1 && exclude) { |
| 385 | + export function fitData(shouldAnimate = false): void { |
| 386 | + if (datasets.length === 0) { |
399 | 387 | return; |
400 | 388 | } |
401 | | - let temp = null; |
402 | | - if (datasets.length === 0 && include) { |
403 | | - // If no previous data, set dataset to the new one |
404 | | - temp = include; |
405 | | - } else if (datasets[0] && datasets[0] == exclude) { |
406 | | - // If we just deselected the first dataset, don't fit to that one |
407 | | - temp = datasets[1]; |
408 | | - } else { |
409 | | - // Generally fit to the first dataset |
410 | | - temp = datasets[0]; |
411 | | - } |
412 | | - let _xMin = temp.data[0].getDate().getIndex() - 0.5; |
413 | | - let _xMax = temp.data[temp.data.length - 1].getDate().getIndex() + 0.5; |
414 | | - let _yMin = temp.getPointValue(0); |
| 389 | + const temp = datasets[0].data; |
| 390 | + let _xMin = temp[0].getDate().getIndex() - 0.5; |
| 391 | + let _xMax = temp[temp.length - 1].getDate().getIndex() + 0.5; |
| 392 | + let _yMin = datasets[0].getPointValue(0); |
415 | 393 | let _yMax = _yMin; |
416 | | - let dss = null; |
417 | | - if (include) { |
418 | | - dss = [...datasets, include]; |
419 | | - } else if (exclude) { |
420 | | - dss = datasets.filter((d) => d !== exclude); |
421 | | - } else { |
422 | | - dss = datasets; |
423 | | - } |
424 | | - for (const ds of dss) { |
| 394 | + for (const ds of datasets) { |
425 | 395 | const data = ds.data; |
426 | 396 | _xMin = Math.min(_xMin, data[0].getDate().getIndex() - 0.5); |
427 | 397 | _xMax = Math.max(_xMax, data[data.length - 1].getDate().getIndex() + 0.5); |
|
0 commit comments