-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathindex.tsx
73 lines (66 loc) · 1.78 KB
/
index.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
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React, { useCallback } from 'react';
import {
Coordinate,
RectCoordinate
} from '../../../../../../typings/timeseries';
import { useChartsSync } from '../../../../../hooks/useChartsSync';
// @ts-ignore
import CustomPlot from '../../CustomPlot';
interface Props {
series: Array<{
color: string;
title: React.ReactNode;
titleShort?: React.ReactNode;
data: Array<Coordinate | RectCoordinate>;
type: string;
}>;
truncateLegends?: boolean;
tickFormatY: (y: number) => React.ReactNode;
formatTooltipValue: (c: Coordinate) => React.ReactNode;
yMax?: string | number;
height?: number;
stacked?: boolean;
onHover?: () => void;
}
const TransactionLineChart: React.FC<Props> = (props: Props) => {
const {
series,
tickFormatY,
formatTooltipValue,
yMax = 'max',
height,
truncateLegends,
stacked = false,
onHover
} = props;
const syncedChartsProps = useChartsSync();
// combine callback for syncedChartsProps.onHover and props.onHover
const combinedOnHover = useCallback(
(hoverX: number) => {
if (onHover) {
onHover();
}
return syncedChartsProps.onHover(hoverX);
},
[syncedChartsProps, onHover]
);
return (
<CustomPlot
series={series}
{...syncedChartsProps}
onHover={combinedOnHover}
tickFormatY={tickFormatY}
formatTooltipValue={formatTooltipValue}
yMax={yMax}
height={height}
truncateLegends={truncateLegends}
{...(stacked ? { stackBy: 'y' } : {})}
/>
);
};
export { TransactionLineChart };