-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpSet.tsx
69 lines (63 loc) · 2.02 KB
/
UpSet.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
import React, { lazy, Suspense, useMemo } from 'react';
import { PlotProps } from './PlotlyPlot';
import { UpSetData } from '../types/plots';
import { extractFromExpression } from '@upsetjs/react';
import Spinner from '../components/Spinner';
export interface UpSetProps extends PlotProps<UpSetData> {
/** label for intersection size axis */
intersectionSizeAxisLabel?: string;
/** label for set size axis */
setSizeAxisLabel?: string;
}
const EmptyUpSetData: UpSetData = { intersections: [] };
const UpSetJS = lazy(() => import('@upsetjs/react'));
export default function UpSet(props: UpSetProps) {
const {
data = EmptyUpSetData,
intersectionSizeAxisLabel,
setSizeAxisLabel,
// all the props below would normally be handled by PlotlyPlot, so we need to handle them here instead
title,
displayLegend = true,
containerStyles = { width: '100%', height: '400px' },
interactive = false,
displayLibraryControls,
legendOptions,
legendTitle,
spacingOptions,
showSpinner,
} = props;
// convert `data` into UpSetJS-friendly `sets` and `combinations`
// as a placeholder - just use demo data from
// https://github.com/upsetjs/upsetjs/blob/main/examples/staticData/src/App.tsx#L42
const { sets, combinations } = useMemo(
() =>
extractFromExpression(
[
{ sets: ['A'], cardinality: 10 },
{ sets: ['B'], cardinality: 7 },
{ sets: ['A', 'B'], cardinality: 5 },
],
{
// ExtractFromExpressionOptions:
type: 'distinctIntersection', // this makes the "Set Size" totals correct
}
),
[]
);
// width and height will need some extra work if we can't specify '100%'
return (
<Suspense fallback="Loading...">
<div style={{ ...containerStyles, position: 'relative' }}>
<UpSetJS
sets={sets}
combinations={combinations}
title={title}
width={500}
height={500}
/>
{showSpinner && <Spinner />}
</div>
</Suspense>
);
}