-
Notifications
You must be signed in to change notification settings - Fork 0
/
View.tsx
103 lines (97 loc) · 4.65 KB
/
View.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { TiledImageComponent } from 'libraries/component-tiled-image';
import { CompositeView } from 'libraries/view-composite';
import { ConsoleView } from 'libraries/view-console';
import { EpochsView } from 'libraries/view-epochs';
import { ExperimentalSelector1View } from 'libraries/view-experimental-selector-1';
import { MountainLayoutView } from 'libraries/view-mountain-layout';
import { MultiTimeseriesView } from 'libraries/view-multi-timeseries';
import { PositionPdfPlotView } from 'libraries/view-position-pdf-plot';
import { PositionPlotView } from 'libraries/view-position-plot';
import { SortingCurationView } from 'libraries/view-sorting-curation';
import { SortingLayoutView } from 'libraries/view-sorting-layout';
import { SortingSelectionView } from 'libraries/view-sorting-selection';
import { SummaryView } from 'libraries/view-summary';
import { Test1View } from 'libraries/view-test-1';
import { FunctionComponent, useMemo } from 'react';
import { isViewData } from 'ViewData';
import {loadView as loadCoreView} from '@figurl/core-views'
import {loadView as loadTimeseriesView} from '@figurl/timeseries-views'
import {loadView as loadSpikeSortingView} from '@figurl/spike-sorting-views'
import {loadView as loadFranklabView} from '@figurl/franklab-views'
import { EphysTracesView } from 'libraries/view-ephys-traces-dev';
export type TimeseriesLayoutOpts = {
hideToolbar?: boolean
hideTimeAxis?: boolean
useYAxis?: boolean
}
type Props = {
data: any
opts: any
width: number
height: number
}
const View: FunctionComponent<Props> = ({data, width, height, opts}) => {
// It's important to memoize this
// because validation of data can be slow
const v = useMemo(() => {
if (isViewData(data)) {
if (data.type === 'Composite') {
return <CompositeView data={data} ViewComponent={View} width={width} height={height} />
}
else if (data.type === 'MultiTimeseries') {
return <MultiTimeseriesView data={data} ViewComponent={View} width={width} height={height} />
}
else if (data.type === 'Summary') {
return <SummaryView data={data} width={width} height={height} />
}
else if (data.type === 'MountainLayout') {
return <MountainLayoutView data={data} ViewComponent={View} width={width} height={height} />
}
else if (data.type === 'PositionPlot') {
return <PositionPlotView data={data} timeseriesLayoutOpts={opts} width={width} height={height} />
}
else if (data.type === 'PositionPdfPlot') {
return <PositionPdfPlotView data={data} timeseriesLayoutOpts={opts} width={width} height={height} />
}
else if (data.type === 'Epochs') {
return <EpochsView data={data} timeseriesLayoutOpts={opts} width={width} height={height} />
}
else if (data.type === 'Console') {
return <ConsoleView data={data} width={width} height={height} />
}
else if (data.type === 'SortingLayout') {
return <SortingLayoutView data={data} ViewComponent={View} width={width} height={height} />
}
else if (data.type === 'SortingCuration') {
return <SortingCurationView data={data} width={width} height={height} />
}
else if (data.type === 'TiledImage') {
return <TiledImageComponent data={data} width={width} height={height} />
}
else if (data.type === 'SortingSelection') {
return <SortingSelectionView data={data} width={width} height={height} />
}
else if (data.type === 'ExperimentalSelector1') {
return <ExperimentalSelector1View data={data} width={width} height={height} />
}
else if (data.type === 'Test1') {
return <Test1View data={data} width={width} height={height} />
}
else if (data.type === 'EphysTraces') {
return <EphysTracesView data={data} width={width} height={height} />
}
}
else {
const viewLoaders = [loadCoreView, loadTimeseriesView, loadSpikeSortingView, loadFranklabView]
for (let loadView of viewLoaders) {
const v = loadView({data, width, height, opts, ViewComponent: View})
if (v) return v
}
return undefined
}
}, [data, height, width, opts])
if (v) return v
console.warn('Unsupported view data', data)
return <div>Unsupported view data: {data['type']}</div>
}
export default View