-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathtooltip.tsx
50 lines (46 loc) · 1.36 KB
/
tooltip.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
import React from 'react';
import { JSONSchema7 } from 'json-schema';
import { LinearMetadataItem } from 'common/IntervalsDataViz/types';
import { isNil } from 'lodash';
interface LinearMetadataTooltipProps<T> {
item: LinearMetadataItem<T>;
point?: number;
schema: JSONSchema7;
}
export const LinearMetadataTooltip = <T extends Record<string, unknown>>({
item,
point,
schema,
}: LinearMetadataTooltipProps<T>) => {
const properties = Object.keys(schema.properties || {}).filter(
(i) => !['begin', 'end'].includes(i)
);
return (
<div className="linear-metadata-tooltip">
<div className="header">
<span>{Math.round(item.begin)}</span>
{point &&
Math.round(point) !== Math.round(item.begin) &&
Math.round(point) !== Math.round(item.end) && (
<>
<span>-</span>
<span>{Math.round(point)}</span>
</>
)}
<span>-</span>
<span>{Math.round(item.end)}</span>
</div>
<div className="content">
{properties.map((k) => (
<div key={k}>
<span className="mr-3">
{((schema.properties || {})[k] as JSONSchema7 | undefined)?.title || k}
</span>
{isNil(item[k]) ? '-' : `${item[k]}`}
</div>
))}
</div>
</div>
);
};
export default LinearMetadataTooltip;