-
Notifications
You must be signed in to change notification settings - Fork 322
/
tooltip.ts
29 lines (24 loc) 路 873 Bytes
/
tooltip.ts
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
import { BubblePoint, ObjectTypeDatetimePoint, Point } from '@t/options';
import { TooltipDataValue } from '@t/components/tooltip';
import { isObject } from '@src/helpers/utils';
import { isRangeValue } from './range';
function isBubblePointType(value: ObjectTypeDatetimePoint | Point): value is BubblePoint {
return value.hasOwnProperty('r');
}
export function getValueString(value: TooltipDataValue) {
let result = '';
if (isRangeValue(value)) {
result = `${value[0]} ~ ${value[1]}`;
} else if (isObject(value) && !Array.isArray(value)) {
result = `(${value.x}, ${value.y})` + (isBubblePointType(value) ? `, r: ${value.r}` : '');
} else {
result = String(value);
}
return result;
}
export function getScrollPosition() {
return {
scrollX: window.scrollX ?? window.pageXOffset,
scrollY: window.scrollY ?? window.pageYOffset,
};
}