panelui-native 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/lib/module/components/area-chart/index.js +15 -3
- package/lib/module/components/area-chart/index.js.map +1 -1
- package/lib/module/components/bar-chart/index.js +15 -3
- package/lib/module/components/bar-chart/index.js.map +1 -1
- package/lib/module/components/bottom-sheet/index.js +34 -2
- package/lib/module/components/bottom-sheet/index.js.map +1 -1
- package/lib/module/components/bubble-chart/index.js +13 -3
- package/lib/module/components/bubble-chart/index.js.map +1 -1
- package/lib/module/components/bump-chart/index.js +15 -3
- package/lib/module/components/bump-chart/index.js.map +1 -1
- package/lib/module/components/candlestick-chart/index.js +15 -3
- package/lib/module/components/candlestick-chart/index.js.map +1 -1
- package/lib/module/components/line-chart/index.js +15 -3
- package/lib/module/components/line-chart/index.js.map +1 -1
- package/lib/module/components/live-line-chart/index.js +15 -3
- package/lib/module/components/live-line-chart/index.js.map +1 -1
- package/lib/module/components/mirror-area-chart/index.js +15 -3
- package/lib/module/components/mirror-area-chart/index.js.map +1 -1
- package/lib/module/components/plot/index.js +15 -3
- package/lib/module/components/plot/index.js.map +1 -1
- package/lib/module/components/pyramid-chart/index.js +15 -3
- package/lib/module/components/pyramid-chart/index.js.map +1 -1
- package/lib/module/components/scatter-chart/index.js +13 -3
- package/lib/module/components/scatter-chart/index.js.map +1 -1
- package/lib/module/components/waterfall-chart/index.js +15 -3
- package/lib/module/components/waterfall-chart/index.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/components/area-chart/index.d.ts +11 -1
- package/lib/typescript/src/components/area-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/bar-chart/index.d.ts +11 -1
- package/lib/typescript/src/components/bar-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/bottom-sheet/index.d.ts +12 -6
- package/lib/typescript/src/components/bottom-sheet/index.d.ts.map +1 -1
- package/lib/typescript/src/components/bubble-chart/index.d.ts +11 -1
- package/lib/typescript/src/components/bubble-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/bump-chart/index.d.ts +11 -1
- package/lib/typescript/src/components/bump-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/candlestick-chart/index.d.ts +11 -1
- package/lib/typescript/src/components/candlestick-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/line-chart/index.d.ts +11 -1
- package/lib/typescript/src/components/line-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/live-line-chart/index.d.ts +11 -1
- package/lib/typescript/src/components/live-line-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/mirror-area-chart/index.d.ts +11 -1
- package/lib/typescript/src/components/mirror-area-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/plot/index.d.ts +11 -1
- package/lib/typescript/src/components/plot/index.d.ts.map +1 -1
- package/lib/typescript/src/components/pyramid-chart/index.d.ts +11 -1
- package/lib/typescript/src/components/pyramid-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/scatter-chart/index.d.ts +11 -1
- package/lib/typescript/src/components/scatter-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/waterfall-chart/index.d.ts +11 -1
- package/lib/typescript/src/components/waterfall-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +7 -2
- package/src/components/area-chart/index.tsx +31 -3
- package/src/components/bar-chart/index.tsx +40 -3
- package/src/components/bottom-sheet/index.tsx +41 -11
- package/src/components/bubble-chart/index.tsx +23 -2
- package/src/components/bump-chart/index.tsx +31 -3
- package/src/components/candlestick-chart/index.tsx +25 -2
- package/src/components/line-chart/index.tsx +31 -3
- package/src/components/live-line-chart/index.tsx +29 -3
- package/src/components/mirror-area-chart/index.tsx +25 -2
- package/src/components/plot/index.tsx +37 -3
- package/src/components/pyramid-chart/index.tsx +25 -2
- package/src/components/scatter-chart/index.tsx +23 -2
- package/src/components/waterfall-chart/index.tsx +35 -2
- package/src/index.ts +12 -1
|
@@ -947,6 +947,15 @@ function CrosshairDot({
|
|
|
947
947
|
);
|
|
948
948
|
}
|
|
949
949
|
|
|
950
|
+
/**
|
|
951
|
+
* How long the readout waits before claiming the touch, in milliseconds.
|
|
952
|
+
*
|
|
953
|
+
* Long enough that a tap reaches a button drawn over the chart and a swipe
|
|
954
|
+
* scrolls the screen, short enough that a deliberate press does not feel
|
|
955
|
+
* ignored.
|
|
956
|
+
*/
|
|
957
|
+
const DEFAULT_HOLD = 180;
|
|
958
|
+
|
|
950
959
|
export interface AreaChartTooltipProps {
|
|
951
960
|
color?: string;
|
|
952
961
|
/** Format one series' value. Defaults to a compact number. */
|
|
@@ -954,6 +963,16 @@ export interface AreaChartTooltipProps {
|
|
|
954
963
|
/** Format the readout's heading from the row. Defaults to the value at xDataKey. */
|
|
955
964
|
formatX?: (datum: AreaChartDatum) => string;
|
|
956
965
|
className?: string;
|
|
966
|
+
/**
|
|
967
|
+
* How long a press has to be held before the readout takes the touch, in
|
|
968
|
+
* milliseconds.
|
|
969
|
+
*
|
|
970
|
+
* Until then the touch belongs to whatever else wants it: a quick tap still
|
|
971
|
+
* reaches a button floating over the chart, and a swipe still scrolls the
|
|
972
|
+
* screen the chart sits in. Set `0` to read on contact, only for a chart with
|
|
973
|
+
* nothing over it and no scroll view around it.
|
|
974
|
+
*/
|
|
975
|
+
activateAfterLongPress?: number;
|
|
957
976
|
}
|
|
958
977
|
|
|
959
978
|
/**
|
|
@@ -962,7 +981,13 @@ export interface AreaChartTooltipProps {
|
|
|
962
981
|
* The hit area is the whole plot. A crosshair you have to land on a band to
|
|
963
982
|
* summon is a crosshair nobody finds.
|
|
964
983
|
*/
|
|
965
|
-
function AreaChartTooltip({
|
|
984
|
+
function AreaChartTooltip({
|
|
985
|
+
color,
|
|
986
|
+
formatValue,
|
|
987
|
+
formatX,
|
|
988
|
+
className,
|
|
989
|
+
activateAfterLongPress = DEFAULT_HOLD,
|
|
990
|
+
}: AreaChartTooltipProps) {
|
|
966
991
|
const {
|
|
967
992
|
data,
|
|
968
993
|
xDataKey,
|
|
@@ -1001,7 +1026,8 @@ function AreaChartTooltip({ color, formatValue, formatX, className }: AreaChartT
|
|
|
1001
1026
|
|
|
1002
1027
|
return Gesture.Pan()
|
|
1003
1028
|
.minDistance(0)
|
|
1004
|
-
.
|
|
1029
|
+
.activateAfterLongPress(activateAfterLongPress)
|
|
1030
|
+
.onStart((event) => {
|
|
1005
1031
|
'worklet';
|
|
1006
1032
|
resolve(event.x);
|
|
1007
1033
|
})
|
|
@@ -1011,10 +1037,12 @@ function AreaChartTooltip({ color, formatValue, formatX, className }: AreaChartT
|
|
|
1011
1037
|
})
|
|
1012
1038
|
.onFinalize(() => {
|
|
1013
1039
|
'worklet';
|
|
1040
|
+
// Fires whether or not the readout ever took the touch.
|
|
1041
|
+
if (activeIndex.value === -1) return;
|
|
1014
1042
|
activeIndex.value = -1;
|
|
1015
1043
|
runOnJS(setActiveIndexJS)(-1);
|
|
1016
1044
|
});
|
|
1017
|
-
}, [total, left, width, activeIndex, setActiveIndexJS]);
|
|
1045
|
+
}, [total, left, width, activeIndex, setActiveIndexJS, activateAfterLongPress]);
|
|
1018
1046
|
|
|
1019
1047
|
const crosshairStyle = useAnimatedStyle(() => {
|
|
1020
1048
|
const index = activeIndex.value;
|
|
@@ -1073,12 +1073,31 @@ BarChartYAxis.layer = 'overlay' as Layer;
|
|
|
1073
1073
|
// makes what it is drawn over unreadable too.
|
|
1074
1074
|
BarChartYAxis.axis = 'y' as const;
|
|
1075
1075
|
|
|
1076
|
+
/**
|
|
1077
|
+
* How long the readout waits before claiming the touch, in milliseconds.
|
|
1078
|
+
*
|
|
1079
|
+
* Long enough that a tap reaches a button drawn over the chart and a swipe
|
|
1080
|
+
* scrolls the screen, short enough that a deliberate press does not feel
|
|
1081
|
+
* ignored.
|
|
1082
|
+
*/
|
|
1083
|
+
const DEFAULT_HOLD = 180;
|
|
1084
|
+
|
|
1076
1085
|
export interface BarChartTooltipProps {
|
|
1077
1086
|
/** Format one series' value. Defaults to a compact number. */
|
|
1078
1087
|
formatValue?: (value: number, key: string) => string;
|
|
1079
1088
|
/** Format the readout's heading from the row. Defaults to the value at xDataKey. */
|
|
1080
1089
|
formatX?: (datum: BarChartDatum) => string;
|
|
1081
1090
|
className?: string;
|
|
1091
|
+
/**
|
|
1092
|
+
* How long a press has to be held before the readout takes the touch, in
|
|
1093
|
+
* milliseconds.
|
|
1094
|
+
*
|
|
1095
|
+
* Until then the touch belongs to whatever else wants it: a quick tap still
|
|
1096
|
+
* reaches a button floating over the chart, and a swipe still scrolls the
|
|
1097
|
+
* screen the chart sits in. Set `0` to read on contact, only for a chart with
|
|
1098
|
+
* nothing over it and no scroll view around it.
|
|
1099
|
+
*/
|
|
1100
|
+
activateAfterLongPress?: number;
|
|
1082
1101
|
}
|
|
1083
1102
|
|
|
1084
1103
|
/**
|
|
@@ -1093,7 +1112,12 @@ export interface BarChartTooltipProps {
|
|
|
1093
1112
|
* summon is a readout nobody finds — and the thinner the bars, the truer that
|
|
1094
1113
|
* gets.
|
|
1095
1114
|
*/
|
|
1096
|
-
function BarChartTooltip({
|
|
1115
|
+
function BarChartTooltip({
|
|
1116
|
+
formatValue,
|
|
1117
|
+
formatX,
|
|
1118
|
+
className,
|
|
1119
|
+
activateAfterLongPress = DEFAULT_HOLD,
|
|
1120
|
+
}: BarChartTooltipProps) {
|
|
1097
1121
|
const {
|
|
1098
1122
|
data,
|
|
1099
1123
|
xDataKey,
|
|
@@ -1142,7 +1166,8 @@ function BarChartTooltip({ formatValue, formatX, className }: BarChartTooltipPro
|
|
|
1142
1166
|
|
|
1143
1167
|
return Gesture.Pan()
|
|
1144
1168
|
.minDistance(0)
|
|
1145
|
-
.
|
|
1169
|
+
.activateAfterLongPress(activateAfterLongPress)
|
|
1170
|
+
.onStart((event) => {
|
|
1146
1171
|
'worklet';
|
|
1147
1172
|
resolve(event.x, event.y);
|
|
1148
1173
|
})
|
|
@@ -1152,10 +1177,22 @@ function BarChartTooltip({ formatValue, formatX, className }: BarChartTooltipPro
|
|
|
1152
1177
|
})
|
|
1153
1178
|
.onFinalize(() => {
|
|
1154
1179
|
'worklet';
|
|
1180
|
+
// Fires whether or not the readout ever took the touch.
|
|
1181
|
+
if (activeIndex.value === -1) return;
|
|
1155
1182
|
activeIndex.value = -1;
|
|
1156
1183
|
runOnJS(setActiveIndexJS)(-1);
|
|
1157
1184
|
});
|
|
1158
|
-
}, [
|
|
1185
|
+
}, [
|
|
1186
|
+
total,
|
|
1187
|
+
left,
|
|
1188
|
+
top,
|
|
1189
|
+
width,
|
|
1190
|
+
height,
|
|
1191
|
+
horizontal,
|
|
1192
|
+
activeIndex,
|
|
1193
|
+
setActiveIndexJS,
|
|
1194
|
+
activateAfterLongPress,
|
|
1195
|
+
]);
|
|
1159
1196
|
|
|
1160
1197
|
/*
|
|
1161
1198
|
* The readout centres over its band and is clamped inside the plot, so it
|
|
@@ -429,14 +429,18 @@ export interface BottomSheetContentProps extends ViewProps {
|
|
|
429
429
|
*
|
|
430
430
|
* `auto` sizes to the content, which is right for a sheet that is a handful
|
|
431
431
|
* of rows. It stops short of the status bar, and a `Body` inside it scrolls
|
|
432
|
-
* once the content is taller than that. `half` and `full` fix the height
|
|
433
|
-
* be given the room rather than allowed to
|
|
434
|
-
*
|
|
435
|
-
*
|
|
432
|
+
* once the content is taller than that. `half` and `full` fix the height
|
|
433
|
+
* instead, for content that has to be given the room rather than allowed to
|
|
434
|
+
* ask for it — a list, a form, a document. For any other height, pass a
|
|
435
|
+
* number of points (`320`) or a percentage of the screen (`'30%'`). Every
|
|
436
|
+
* fixed height is clamped to leave the status bar clear, so `full` is as tall
|
|
437
|
+
* as the screen allows rather than as tall as the screen.
|
|
436
438
|
*
|
|
437
|
-
* On the native sheet this maps onto the platform's detents
|
|
439
|
+
* On the native sheet this maps onto the platform's detents: a number becomes
|
|
440
|
+
* `{ height }` and a percentage `{ fraction }`, which Android snaps to the
|
|
441
|
+
* nearer of `half` and `full`.
|
|
438
442
|
*/
|
|
439
|
-
size?: 'auto' | 'half' | 'full'
|
|
443
|
+
size?: 'auto' | 'half' | 'full' | number | `${number}%`;
|
|
440
444
|
children?: ReactNode;
|
|
441
445
|
}
|
|
442
446
|
|
|
@@ -447,6 +451,34 @@ export interface BottomSheetContentProps extends ViewProps {
|
|
|
447
451
|
*/
|
|
448
452
|
const SIZE_FRACTION = { half: 0.5, full: 0.94 } as const;
|
|
449
453
|
|
|
454
|
+
/** How tall `BottomSheet.Content` opens: a keyword, points, or a percentage of the screen. */
|
|
455
|
+
export type BottomSheetSize = NonNullable<BottomSheetContentProps['size']>;
|
|
456
|
+
|
|
457
|
+
/** A percentage string as a fraction of the screen, or `undefined` if it is not one. */
|
|
458
|
+
function percentFraction(size: BottomSheetSize): number | undefined {
|
|
459
|
+
if (typeof size !== 'string' || !size.endsWith('%')) return undefined;
|
|
460
|
+
const value = Number(size.slice(0, -1));
|
|
461
|
+
return Number.isFinite(value) && value > 0 ? value / 100 : undefined;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** The height a sized sheet aims for before it is clamped, or `undefined` for `auto`. */
|
|
465
|
+
function sizeTarget(size: BottomSheetSize, screenHeight: number): number | undefined {
|
|
466
|
+
if (size === 'half' || size === 'full') return screenHeight * SIZE_FRACTION[size];
|
|
467
|
+
if (typeof size === 'number') return Number.isFinite(size) && size > 0 ? size : undefined;
|
|
468
|
+
const fraction = percentFraction(size);
|
|
469
|
+
return fraction === undefined ? undefined : screenHeight * fraction;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** The native sheet's detents for a `size`, or `undefined` to size to the content. */
|
|
473
|
+
function sizeSnapPoints(size: BottomSheetSize): BottomSheetProps['snapPoints'] {
|
|
474
|
+
if (size === 'half' || size === 'full') return [size];
|
|
475
|
+
if (typeof size === 'number') {
|
|
476
|
+
return Number.isFinite(size) && size > 0 ? [{ height: size }] : undefined;
|
|
477
|
+
}
|
|
478
|
+
const fraction = percentFraction(size);
|
|
479
|
+
return fraction === undefined ? undefined : [{ fraction: Math.min(fraction, 1) }];
|
|
480
|
+
}
|
|
481
|
+
|
|
450
482
|
function BottomSheetContent({
|
|
451
483
|
className,
|
|
452
484
|
dismissible = true,
|
|
@@ -814,10 +846,8 @@ function BottomSheetContent({
|
|
|
814
846
|
* those is unreadable at exactly the moment the sheet is at its tallest.
|
|
815
847
|
*/
|
|
816
848
|
const sheetCap = screenHeight - insets.top - (detached ? detachedGap : 8);
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
? undefined
|
|
820
|
-
: Math.min(screenHeight * SIZE_FRACTION[size], sheetCap);
|
|
849
|
+
const target = sizeTarget(size, screenHeight);
|
|
850
|
+
const sizedHeight = target === undefined ? undefined : Math.min(target, sheetCap);
|
|
821
851
|
|
|
822
852
|
const surface = useMemo(
|
|
823
853
|
() => ({ scrollGesture, scrollOffset, hasScrollable, scrollHold }),
|
|
@@ -832,7 +862,7 @@ function BottomSheetContent({
|
|
|
832
862
|
* height, so a native sheet keeps the system's snapping.
|
|
833
863
|
*/
|
|
834
864
|
const snapPoints =
|
|
835
|
-
nativeSheet.snapPoints ?? (size
|
|
865
|
+
nativeSheet.snapPoints ?? sizeSnapPoints(size);
|
|
836
866
|
/*
|
|
837
867
|
* `true` means the theme's surface, and a string means itself. A token
|
|
838
868
|
* that did not resolve is dropped rather than passed on — an unresolved
|
|
@@ -1794,6 +1794,15 @@ BubbleChartYAxis.layer = 'overlay' as Layer;
|
|
|
1794
1794
|
// plot out.
|
|
1795
1795
|
BubbleChartYAxis.axis = 'y' as const;
|
|
1796
1796
|
|
|
1797
|
+
/**
|
|
1798
|
+
* How long the readout waits before claiming the touch, in milliseconds.
|
|
1799
|
+
*
|
|
1800
|
+
* Long enough that a tap reaches a button drawn over the chart and a swipe
|
|
1801
|
+
* scrolls the screen, short enough that a deliberate press does not feel
|
|
1802
|
+
* ignored.
|
|
1803
|
+
*/
|
|
1804
|
+
const DEFAULT_HOLD = 180;
|
|
1805
|
+
|
|
1797
1806
|
export interface BubbleChartTooltipProps {
|
|
1798
1807
|
/** Float a small readout beside the selected bubble. On by default. */
|
|
1799
1808
|
showLabel?: boolean;
|
|
@@ -1806,6 +1815,16 @@ export interface BubbleChartTooltipProps {
|
|
|
1806
1815
|
/** Floor on the touch target, for a chart whose smallest bubbles are tiny. */
|
|
1807
1816
|
hitRadius?: number;
|
|
1808
1817
|
className?: string;
|
|
1818
|
+
/**
|
|
1819
|
+
* How long a press has to be held before the readout takes the touch, in
|
|
1820
|
+
* milliseconds.
|
|
1821
|
+
*
|
|
1822
|
+
* Until then the touch belongs to whatever else wants it: a quick tap still
|
|
1823
|
+
* reaches a button floating over the chart, and a swipe still scrolls the
|
|
1824
|
+
* screen the chart sits in. Set `0` to read on contact, only for a chart with
|
|
1825
|
+
* nothing over it and no scroll view around it.
|
|
1826
|
+
*/
|
|
1827
|
+
activateAfterLongPress?: number;
|
|
1809
1828
|
}
|
|
1810
1829
|
|
|
1811
1830
|
/**
|
|
@@ -1831,6 +1850,7 @@ function BubbleChartTooltip({
|
|
|
1831
1850
|
formatSize,
|
|
1832
1851
|
hitRadius = HIT_RADIUS,
|
|
1833
1852
|
className,
|
|
1853
|
+
activateAfterLongPress = DEFAULT_HOLD,
|
|
1834
1854
|
}: BubbleChartTooltipProps) {
|
|
1835
1855
|
const {
|
|
1836
1856
|
bubbles,
|
|
@@ -1926,7 +1946,8 @@ function BubbleChartTooltip({
|
|
|
1926
1946
|
|
|
1927
1947
|
return Gesture.Pan()
|
|
1928
1948
|
.minDistance(0)
|
|
1929
|
-
.
|
|
1949
|
+
.activateAfterLongPress(activateAfterLongPress)
|
|
1950
|
+
.onStart((event) => {
|
|
1930
1951
|
'worklet';
|
|
1931
1952
|
resolve(event.x, event.y);
|
|
1932
1953
|
})
|
|
@@ -1938,7 +1959,7 @@ function BubbleChartTooltip({
|
|
|
1938
1959
|
'worklet';
|
|
1939
1960
|
clear();
|
|
1940
1961
|
});
|
|
1941
|
-
}, [hit, activeIndex, select]);
|
|
1962
|
+
}, [hit, activeIndex, select, activateAfterLongPress]);
|
|
1942
1963
|
|
|
1943
1964
|
/*
|
|
1944
1965
|
* The readout's own height, measured rather than assumed. It decides whether
|
|
@@ -1170,6 +1170,15 @@ function BumpLabel({
|
|
|
1170
1170
|
/** Height of one name's hit box. */
|
|
1171
1171
|
const LABEL_ROW = 20;
|
|
1172
1172
|
|
|
1173
|
+
/**
|
|
1174
|
+
* How long the readout waits before claiming the touch, in milliseconds.
|
|
1175
|
+
*
|
|
1176
|
+
* Long enough that a tap reaches a button drawn over the chart and a swipe
|
|
1177
|
+
* scrolls the screen, short enough that a deliberate press does not feel
|
|
1178
|
+
* ignored.
|
|
1179
|
+
*/
|
|
1180
|
+
const DEFAULT_HOLD = 180;
|
|
1181
|
+
|
|
1173
1182
|
export interface BumpChartTooltipProps {
|
|
1174
1183
|
color?: string;
|
|
1175
1184
|
/** Format a rank in the readout. Defaults to `#1`, `#2`… */
|
|
@@ -1177,13 +1186,29 @@ export interface BumpChartTooltipProps {
|
|
|
1177
1186
|
/** Format the readout's heading from the row. Defaults to the value at xDataKey. */
|
|
1178
1187
|
formatX?: (datum: BumpChartDatum) => string;
|
|
1179
1188
|
className?: string;
|
|
1189
|
+
/**
|
|
1190
|
+
* How long a press has to be held before the readout takes the touch, in
|
|
1191
|
+
* milliseconds.
|
|
1192
|
+
*
|
|
1193
|
+
* Until then the touch belongs to whatever else wants it: a quick tap still
|
|
1194
|
+
* reaches a button floating over the chart, and a swipe still scrolls the
|
|
1195
|
+
* screen the chart sits in. Set `0` to read on contact, only for a chart with
|
|
1196
|
+
* nothing over it and no scroll view around it.
|
|
1197
|
+
*/
|
|
1198
|
+
activateAfterLongPress?: number;
|
|
1180
1199
|
}
|
|
1181
1200
|
|
|
1182
1201
|
/**
|
|
1183
1202
|
* A scrub across the columns, and a readout listing every series in the order
|
|
1184
1203
|
* it stood at the column under the finger.
|
|
1185
1204
|
*/
|
|
1186
|
-
function BumpChartTooltip({
|
|
1205
|
+
function BumpChartTooltip({
|
|
1206
|
+
color,
|
|
1207
|
+
formatRank,
|
|
1208
|
+
formatX,
|
|
1209
|
+
className,
|
|
1210
|
+
activateAfterLongPress = DEFAULT_HOLD,
|
|
1211
|
+
}: BumpChartTooltipProps) {
|
|
1187
1212
|
const {
|
|
1188
1213
|
data,
|
|
1189
1214
|
xDataKey,
|
|
@@ -1221,7 +1246,8 @@ function BumpChartTooltip({ color, formatRank, formatX, className }: BumpChartTo
|
|
|
1221
1246
|
|
|
1222
1247
|
return Gesture.Pan()
|
|
1223
1248
|
.minDistance(0)
|
|
1224
|
-
.
|
|
1249
|
+
.activateAfterLongPress(activateAfterLongPress)
|
|
1250
|
+
.onStart((event) => {
|
|
1225
1251
|
'worklet';
|
|
1226
1252
|
resolve(event.x);
|
|
1227
1253
|
})
|
|
@@ -1231,10 +1257,12 @@ function BumpChartTooltip({ color, formatRank, formatX, className }: BumpChartTo
|
|
|
1231
1257
|
})
|
|
1232
1258
|
.onFinalize(() => {
|
|
1233
1259
|
'worklet';
|
|
1260
|
+
// Fires whether or not the readout ever took the touch.
|
|
1261
|
+
if (activeIndex.value === -1) return;
|
|
1234
1262
|
activeIndex.value = -1;
|
|
1235
1263
|
runOnJS(setActiveIndexJS)(-1);
|
|
1236
1264
|
});
|
|
1237
|
-
}, [total, left, width, activeIndex, setActiveIndexJS]);
|
|
1265
|
+
}, [total, left, width, activeIndex, setActiveIndexJS, activateAfterLongPress]);
|
|
1238
1266
|
|
|
1239
1267
|
const crosshairStyle = useAnimatedStyle(() => {
|
|
1240
1268
|
const index = activeIndex.value;
|
|
@@ -1093,6 +1093,15 @@ CandlestickChartYAxis.layer = 'overlay' as Layer;
|
|
|
1093
1093
|
// drawn over unreadable too.
|
|
1094
1094
|
CandlestickChartYAxis.axis = 'y' as const;
|
|
1095
1095
|
|
|
1096
|
+
/**
|
|
1097
|
+
* How long the readout waits before claiming the touch, in milliseconds.
|
|
1098
|
+
*
|
|
1099
|
+
* Long enough that a tap reaches a button drawn over the chart and a swipe
|
|
1100
|
+
* scrolls the screen, short enough that a deliberate press does not feel
|
|
1101
|
+
* ignored.
|
|
1102
|
+
*/
|
|
1103
|
+
const DEFAULT_HOLD = 180;
|
|
1104
|
+
|
|
1096
1105
|
export interface CandlestickChartTooltipProps {
|
|
1097
1106
|
/** Format one of the four prices. Defaults to a compact number. */
|
|
1098
1107
|
formatValue?: (value: number, field: 'open' | 'high' | 'low' | 'close') => string;
|
|
@@ -1101,6 +1110,16 @@ export interface CandlestickChartTooltipProps {
|
|
|
1101
1110
|
/** Show the period's change from open to close under the four prices. */
|
|
1102
1111
|
showChange?: boolean;
|
|
1103
1112
|
className?: string;
|
|
1113
|
+
/**
|
|
1114
|
+
* How long a press has to be held before the readout takes the touch, in
|
|
1115
|
+
* milliseconds.
|
|
1116
|
+
*
|
|
1117
|
+
* Until then the touch belongs to whatever else wants it: a quick tap still
|
|
1118
|
+
* reaches a button floating over the chart, and a swipe still scrolls the
|
|
1119
|
+
* screen the chart sits in. Set `0` to read on contact, only for a chart with
|
|
1120
|
+
* nothing over it and no scroll view around it.
|
|
1121
|
+
*/
|
|
1122
|
+
activateAfterLongPress?: number;
|
|
1104
1123
|
}
|
|
1105
1124
|
|
|
1106
1125
|
/**
|
|
@@ -1118,6 +1137,7 @@ function CandlestickChartTooltip({
|
|
|
1118
1137
|
formatX,
|
|
1119
1138
|
showChange = true,
|
|
1120
1139
|
className,
|
|
1140
|
+
activateAfterLongPress = DEFAULT_HOLD,
|
|
1121
1141
|
}: CandlestickChartTooltipProps) {
|
|
1122
1142
|
const {
|
|
1123
1143
|
data,
|
|
@@ -1156,7 +1176,8 @@ function CandlestickChartTooltip({
|
|
|
1156
1176
|
|
|
1157
1177
|
return Gesture.Pan()
|
|
1158
1178
|
.minDistance(0)
|
|
1159
|
-
.
|
|
1179
|
+
.activateAfterLongPress(activateAfterLongPress)
|
|
1180
|
+
.onStart((event) => {
|
|
1160
1181
|
'worklet';
|
|
1161
1182
|
resolve(event.x);
|
|
1162
1183
|
})
|
|
@@ -1166,10 +1187,12 @@ function CandlestickChartTooltip({
|
|
|
1166
1187
|
})
|
|
1167
1188
|
.onFinalize(() => {
|
|
1168
1189
|
'worklet';
|
|
1190
|
+
// Fires whether or not the readout ever took the touch.
|
|
1191
|
+
if (activeIndex.value === -1) return;
|
|
1169
1192
|
activeIndex.value = -1;
|
|
1170
1193
|
runOnJS(setActiveIndexJS)(-1);
|
|
1171
1194
|
});
|
|
1172
|
-
}, [total, left, width, activeIndex, setActiveIndexJS]);
|
|
1195
|
+
}, [total, left, width, activeIndex, setActiveIndexJS, activateAfterLongPress]);
|
|
1173
1196
|
|
|
1174
1197
|
// The readout centres over its candle and is clamped inside the plot, so it
|
|
1175
1198
|
// never runs off the edge at the first or last one.
|
|
@@ -954,6 +954,15 @@ LineChartYAxis.layer = 'overlay' as Layer;
|
|
|
954
954
|
// plot out.
|
|
955
955
|
LineChartYAxis.axis = 'y' as const;
|
|
956
956
|
|
|
957
|
+
/**
|
|
958
|
+
* How long the readout waits before claiming the touch, in milliseconds.
|
|
959
|
+
*
|
|
960
|
+
* Long enough that a tap reaches a button drawn over the chart and a swipe
|
|
961
|
+
* scrolls the screen, short enough that a deliberate press does not feel
|
|
962
|
+
* ignored.
|
|
963
|
+
*/
|
|
964
|
+
const DEFAULT_HOLD = 180;
|
|
965
|
+
|
|
957
966
|
export interface LineChartTooltipProps {
|
|
958
967
|
color?: string;
|
|
959
968
|
/**
|
|
@@ -965,6 +974,16 @@ export interface LineChartTooltipProps {
|
|
|
965
974
|
formatValue?: (value: number, key: string) => string;
|
|
966
975
|
/** Format the label's heading from the row. Defaults to the value at xDataKey. */
|
|
967
976
|
formatX?: (datum: LineChartDatum) => string;
|
|
977
|
+
/**
|
|
978
|
+
* How long a press has to be held before the readout takes the touch, in
|
|
979
|
+
* milliseconds.
|
|
980
|
+
*
|
|
981
|
+
* Until then the touch belongs to whatever else wants it: a quick tap still
|
|
982
|
+
* reaches a button floating over the chart, and a swipe still scrolls the
|
|
983
|
+
* screen the chart sits in. Set `0` to read on contact, only for a chart with
|
|
984
|
+
* nothing over it and no scroll view around it.
|
|
985
|
+
*/
|
|
986
|
+
activateAfterLongPress?: number;
|
|
968
987
|
}
|
|
969
988
|
|
|
970
989
|
/**
|
|
@@ -979,7 +998,13 @@ export interface LineChartTooltipProps {
|
|
|
979
998
|
* The hit area is the whole plot. A crosshair you have to land on the line to
|
|
980
999
|
* summon is a crosshair nobody finds.
|
|
981
1000
|
*/
|
|
982
|
-
function LineChartTooltip({
|
|
1001
|
+
function LineChartTooltip({
|
|
1002
|
+
color,
|
|
1003
|
+
showLabel = true,
|
|
1004
|
+
formatValue,
|
|
1005
|
+
formatX,
|
|
1006
|
+
activateAfterLongPress = DEFAULT_HOLD,
|
|
1007
|
+
}: LineChartTooltipProps) {
|
|
983
1008
|
const {
|
|
984
1009
|
data,
|
|
985
1010
|
xDataKey,
|
|
@@ -1022,7 +1047,8 @@ function LineChartTooltip({ color, showLabel = true, formatValue, formatX }: Lin
|
|
|
1022
1047
|
|
|
1023
1048
|
return Gesture.Pan()
|
|
1024
1049
|
.minDistance(0)
|
|
1025
|
-
.
|
|
1050
|
+
.activateAfterLongPress(activateAfterLongPress)
|
|
1051
|
+
.onStart((event) => {
|
|
1026
1052
|
'worklet';
|
|
1027
1053
|
resolve(event.x);
|
|
1028
1054
|
})
|
|
@@ -1032,10 +1058,12 @@ function LineChartTooltip({ color, showLabel = true, formatValue, formatX }: Lin
|
|
|
1032
1058
|
})
|
|
1033
1059
|
.onFinalize(() => {
|
|
1034
1060
|
'worklet';
|
|
1061
|
+
// Fires whether or not the readout ever took the touch.
|
|
1062
|
+
if (activeIndex.value === -1) return;
|
|
1035
1063
|
activeIndex.value = -1;
|
|
1036
1064
|
runOnJS(setActiveIndexJS)(-1);
|
|
1037
1065
|
});
|
|
1038
|
-
}, [total, left, width, activeIndex, setActiveIndexJS]);
|
|
1066
|
+
}, [total, left, width, activeIndex, setActiveIndexJS, activateAfterLongPress]);
|
|
1039
1067
|
|
|
1040
1068
|
const crosshairStyle = useAnimatedStyle(() => {
|
|
1041
1069
|
const index = activeIndex.value;
|
|
@@ -1107,10 +1107,29 @@ LiveLineChartYAxis.displayName = 'LiveLineChart.YAxis';
|
|
|
1107
1107
|
LiveLineChartYAxis.layer = 'overlay' as Layer;
|
|
1108
1108
|
LiveLineChartYAxis.axis = 'y' as const;
|
|
1109
1109
|
|
|
1110
|
+
/**
|
|
1111
|
+
* How long the readout waits before claiming the touch, in milliseconds.
|
|
1112
|
+
*
|
|
1113
|
+
* Long enough that a tap reaches a button drawn over the chart and a swipe
|
|
1114
|
+
* scrolls the screen, short enough that a deliberate press does not feel
|
|
1115
|
+
* ignored.
|
|
1116
|
+
*/
|
|
1117
|
+
const DEFAULT_HOLD = 180;
|
|
1118
|
+
|
|
1110
1119
|
export interface LiveLineChartTooltipProps {
|
|
1111
1120
|
/** Format the value. Defaults to a compact number. */
|
|
1112
1121
|
formatValue?: (value: number) => string;
|
|
1113
1122
|
className?: string;
|
|
1123
|
+
/**
|
|
1124
|
+
* How long a press has to be held before the readout takes the touch, in
|
|
1125
|
+
* milliseconds.
|
|
1126
|
+
*
|
|
1127
|
+
* Until then the touch belongs to whatever else wants it: a quick tap still
|
|
1128
|
+
* reaches a button floating over the chart, and a swipe still scrolls the
|
|
1129
|
+
* screen the chart sits in. Set `0` to read on contact, only for a chart with
|
|
1130
|
+
* nothing over it and no scroll view around it.
|
|
1131
|
+
*/
|
|
1132
|
+
activateAfterLongPress?: number;
|
|
1114
1133
|
}
|
|
1115
1134
|
|
|
1116
1135
|
/**
|
|
@@ -1120,7 +1139,11 @@ export interface LiveLineChartTooltipProps {
|
|
|
1120
1139
|
* place on screen, so it travels left with the reading it named instead of
|
|
1121
1140
|
* sitting still while the line slides out from under it.
|
|
1122
1141
|
*/
|
|
1123
|
-
function LiveLineChartTooltip({
|
|
1142
|
+
function LiveLineChartTooltip({
|
|
1143
|
+
formatValue,
|
|
1144
|
+
className,
|
|
1145
|
+
activateAfterLongPress = DEFAULT_HOLD,
|
|
1146
|
+
}: LiveLineChartTooltipProps) {
|
|
1124
1147
|
const {
|
|
1125
1148
|
plot,
|
|
1126
1149
|
times,
|
|
@@ -1182,7 +1205,8 @@ function LiveLineChartTooltip({ formatValue, className }: LiveLineChartTooltipPr
|
|
|
1182
1205
|
|
|
1183
1206
|
return Gesture.Pan()
|
|
1184
1207
|
.minDistance(0)
|
|
1185
|
-
.
|
|
1208
|
+
.activateAfterLongPress(activateAfterLongPress)
|
|
1209
|
+
.onStart((event) => {
|
|
1186
1210
|
'worklet';
|
|
1187
1211
|
resolve(event.x);
|
|
1188
1212
|
})
|
|
@@ -1192,10 +1216,12 @@ function LiveLineChartTooltip({ formatValue, className }: LiveLineChartTooltipPr
|
|
|
1192
1216
|
})
|
|
1193
1217
|
.onFinalize(() => {
|
|
1194
1218
|
'worklet';
|
|
1219
|
+
// Fires whether or not the readout ever took the touch.
|
|
1220
|
+
if (activeTime.value === -1) return;
|
|
1195
1221
|
activeTime.value = -1;
|
|
1196
1222
|
runOnJS(report)(-1, 0);
|
|
1197
1223
|
});
|
|
1198
|
-
}, [times, values, now, windowMs, plot, activeTime, report]);
|
|
1224
|
+
}, [times, values, now, windowMs, plot, activeTime, report, activateAfterLongPress]);
|
|
1199
1225
|
|
|
1200
1226
|
const crosshairStyle = useAnimatedStyle(() => {
|
|
1201
1227
|
const time = activeTime.value;
|
|
@@ -1002,6 +1002,15 @@ MirrorAreaChartYAxis.layer = 'overlay' as Layer;
|
|
|
1002
1002
|
// Read by the root, which leaves room for the labels before laying the plot out.
|
|
1003
1003
|
MirrorAreaChartYAxis.axis = 'y' as const;
|
|
1004
1004
|
|
|
1005
|
+
/**
|
|
1006
|
+
* How long the readout waits before claiming the touch, in milliseconds.
|
|
1007
|
+
*
|
|
1008
|
+
* Long enough that a tap reaches a button drawn over the chart and a swipe
|
|
1009
|
+
* scrolls the screen, short enough that a deliberate press does not feel
|
|
1010
|
+
* ignored.
|
|
1011
|
+
*/
|
|
1012
|
+
const DEFAULT_HOLD = 180;
|
|
1013
|
+
|
|
1005
1014
|
export interface MirrorAreaChartTooltipProps {
|
|
1006
1015
|
/** Colour of the crosshair and the dot. Defaults to the foreground token. */
|
|
1007
1016
|
color?: string;
|
|
@@ -1015,6 +1024,16 @@ export interface MirrorAreaChartTooltipProps {
|
|
|
1015
1024
|
*/
|
|
1016
1025
|
formatSummary?: (datum: MirrorAreaChartDatum) => string;
|
|
1017
1026
|
className?: string;
|
|
1027
|
+
/**
|
|
1028
|
+
* How long a press has to be held before the readout takes the touch, in
|
|
1029
|
+
* milliseconds.
|
|
1030
|
+
*
|
|
1031
|
+
* Until then the touch belongs to whatever else wants it: a quick tap still
|
|
1032
|
+
* reaches a button floating over the chart, and a swipe still scrolls the
|
|
1033
|
+
* screen the chart sits in. Set `0` to read on contact, only for a chart with
|
|
1034
|
+
* nothing over it and no scroll view around it.
|
|
1035
|
+
*/
|
|
1036
|
+
activateAfterLongPress?: number;
|
|
1018
1037
|
}
|
|
1019
1038
|
|
|
1020
1039
|
/**
|
|
@@ -1027,6 +1046,7 @@ function MirrorAreaChartTooltip({
|
|
|
1027
1046
|
formatX,
|
|
1028
1047
|
formatSummary,
|
|
1029
1048
|
className,
|
|
1049
|
+
activateAfterLongPress = DEFAULT_HOLD,
|
|
1030
1050
|
}: MirrorAreaChartTooltipProps) {
|
|
1031
1051
|
const {
|
|
1032
1052
|
data,
|
|
@@ -1067,7 +1087,8 @@ function MirrorAreaChartTooltip({
|
|
|
1067
1087
|
|
|
1068
1088
|
return Gesture.Pan()
|
|
1069
1089
|
.minDistance(0)
|
|
1070
|
-
.
|
|
1090
|
+
.activateAfterLongPress(activateAfterLongPress)
|
|
1091
|
+
.onStart((event) => {
|
|
1071
1092
|
'worklet';
|
|
1072
1093
|
resolve(event.x);
|
|
1073
1094
|
})
|
|
@@ -1077,10 +1098,12 @@ function MirrorAreaChartTooltip({
|
|
|
1077
1098
|
})
|
|
1078
1099
|
.onFinalize(() => {
|
|
1079
1100
|
'worklet';
|
|
1101
|
+
// Fires whether or not the readout ever took the touch.
|
|
1102
|
+
if (activeIndex.value === -1) return;
|
|
1080
1103
|
activeIndex.value = -1;
|
|
1081
1104
|
runOnJS(setActiveIndexJS)(-1);
|
|
1082
1105
|
});
|
|
1083
|
-
}, [total, left, width, activeIndex, setActiveIndexJS]);
|
|
1106
|
+
}, [total, left, width, activeIndex, setActiveIndexJS, activateAfterLongPress]);
|
|
1084
1107
|
|
|
1085
1108
|
/*
|
|
1086
1109
|
* The dot sits on the outermost edge on the top half — the largest value of
|