gloomberb 0.20.13 → 0.20.14
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/package.json +2 -1
- package/patches/@opentui%2Fcore@0.3.2.patch +22 -4
- package/src/account/auth-dialog.tsx +22 -4
- package/src/account/auth-form.tsx +6 -1
- package/src/account/checkout-handoff.tsx +7 -14
- package/src/account/device-signin-dialog.tsx +35 -24
- package/src/api-client/crypto-markets.ts +10 -0
- package/src/api-client/errors.ts +3 -1
- package/src/api-client/money-markets.ts +7 -0
- package/src/api-client/request.ts +12 -2
- package/src/architecture/floating-promise-allowlist.json +0 -1
- package/src/brokers/signed-in/sign-in-dialog.tsx +38 -38
- package/src/cli/commands/market.ts +95 -23
- package/src/cli/commands/overview.ts +18 -4
- package/src/cli/errors.ts +3 -1
- package/src/cli/freshness.ts +7 -2
- package/src/cli/glossary.ts +10 -5
- package/src/cli/helpers.ts +8 -16
- package/src/cli/history-export.ts +4 -0
- package/src/cli/known-gaps.ts +2 -2
- package/src/cli/listing-arg.ts +79 -11
- package/src/cli/not-a-ticker.ts +4 -0
- package/src/cli/pane-functions/catalog.ts +29 -8
- package/src/cli/pane-functions/headless.ts +5 -2
- package/src/cli/pane-functions/options.ts +7 -0
- package/src/cli/pane-functions/resolver.ts +61 -15
- package/src/cli/result.ts +22 -4
- package/src/cli/symbol-args.ts +5 -3
- package/src/cli/symbol-list.ts +23 -10
- package/src/cli/symbol-rows.ts +135 -3
- package/src/cli/treasury-yields.ts +15 -1
- package/src/components/chart/composite/format.ts +2 -1
- package/src/components/chart/composite/panel-surface/axis-markers.ts +133 -0
- package/src/components/chart/composite/panel-surface/level-labels.tsx +78 -0
- package/src/components/chart/composite/panel-surface/overlays.ts +108 -0
- package/src/components/chart/composite/panel-surface/pan-coast.ts +54 -0
- package/src/components/chart/composite/panel-surface/panel-cursor.tsx +138 -0
- package/src/components/chart/composite/panel-surface/panel-levels.ts +47 -0
- package/src/components/chart/composite/panel-surface/plot-gestures.ts +403 -0
- package/src/components/chart/composite/panel-surface/plot-pointer.ts +65 -0
- package/src/components/chart/composite/panel-surface/plot-wheel.ts +102 -0
- package/src/components/chart/composite/panel-surface/pointer.ts +12 -0
- package/src/components/chart/composite/panel-surface/props.ts +79 -0
- package/src/components/chart/composite/panel-surface/tool-readout.ts +151 -0
- package/src/components/chart/composite/panel-surface/value-axis-gestures.ts +152 -0
- package/src/components/chart/composite/panel-surface.tsx +81 -1177
- package/src/components/command-bar/commands/collection-list.ts +1 -0
- package/src/components/command-bar/routes/root/results.ts +3 -2
- package/src/components/command-bar/routes/root/runtime.ts +3 -2
- package/src/components/command-bar/routes/root/selection.ts +3 -2
- package/src/components/command-bar/routes/root/shortcuts.ts +15 -0
- package/src/components/layout/pane/title.ts +10 -4
- package/src/components/pane-settings-dialog/tui.tsx +6 -3
- package/src/components/pane-settings-dialog.tsx +2 -1
- package/src/components/pane-template-wizard.tsx +2 -0
- package/src/components/ui/choice-dialog.tsx +1 -1
- package/src/components/ui/confirm-dialog.tsx +3 -2
- package/src/components/ui/frame.tsx +7 -3
- package/src/components/ui/icon.tsx +4 -2
- package/src/components/ui/list-view.tsx +8 -0
- package/src/components/ui/number-prompt-dialog.tsx +2 -1
- package/src/components/use-pane-notice-footer.tsx +3 -1
- package/src/docs/snapshot.json +2 -2
- package/src/i18n/es.ts +1 -0
- package/src/i18n/ja.ts +1 -0
- package/src/i18n/ko.ts +1 -0
- package/src/i18n/zh-cn.ts +1 -0
- package/src/i18n/zh-tw.ts +1 -0
- package/src/market-data/market/format.ts +35 -1
- package/src/market-data/quotes/contributions.ts +13 -0
- package/src/market-data/quotes/export-identity.ts +36 -1
- package/src/market-data/quotes/resolution.ts +16 -0
- package/src/plugins/builtin/account-management/password-dialog.tsx +2 -2
- package/src/plugins/builtin/analytics/risk-client.ts +12 -2
- package/src/plugins/builtin/analytics/risk-headless.ts +66 -6
- package/src/plugins/builtin/analytics/risk-math.ts +23 -6
- package/src/plugins/builtin/analytics/risk-model.ts +20 -9
- package/src/plugins/builtin/analytics/risk-pane.tsx +2 -2
- package/src/plugins/builtin/chart-composer/catalog-inventory.ts +5 -2
- package/src/plugins/builtin/chart-composer/editor.tsx +1 -0
- package/src/plugins/builtin/chart-composer/pane.tsx +1 -1
- package/src/plugins/builtin/chart-composer/quick-add.tsx +4 -1
- package/src/plugins/builtin/chart-composer/series-catalog.ts +17 -1
- package/src/plugins/builtin/cloud/plugin.tsx +2 -0
- package/src/plugins/builtin/cloud/thesis/module.tsx +2 -0
- package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +6 -2
- package/src/plugins/builtin/cpi/headless.ts +6 -1
- package/src/plugins/builtin/cpi/model.ts +17 -0
- package/src/plugins/builtin/cpi/pane.tsx +3 -1
- package/src/plugins/builtin/crypto-board/client.ts +6 -1
- package/src/plugins/builtin/crypto-board/headless.ts +10 -2
- package/src/plugins/builtin/crypto-board/model.ts +89 -11
- package/src/plugins/builtin/crypto-board/pane.tsx +20 -5
- package/src/plugins/builtin/dividend-yield/client.ts +24 -2
- package/src/plugins/builtin/dividend-yield/headless.ts +4 -2
- package/src/plugins/builtin/dividend-yield/ranking.ts +2 -1
- package/src/plugins/builtin/dividend-yield/view.ts +5 -1
- package/src/plugins/builtin/earnings/history-table.ts +8 -0
- package/src/plugins/builtin/earnings-ripple/index.tsx +2 -0
- package/src/plugins/builtin/econ/calendar-model.ts +17 -1
- package/src/plugins/builtin/econ/fred-catalog.ts +33 -4
- package/src/plugins/builtin/econ-statistics/headless.ts +21 -0
- package/src/plugins/builtin/macro-day/headless.ts +21 -10
- package/src/plugins/builtin/macro-day/model.ts +40 -3
- package/src/plugins/builtin/macro-day/pane.tsx +26 -8
- package/src/plugins/builtin/macro-day/releases.ts +24 -1
- package/src/plugins/builtin/money-markets/client.ts +4 -1
- package/src/plugins/builtin/money-markets/headless.ts +15 -4
- package/src/plugins/builtin/money-markets/index.tsx +1 -1
- package/src/plugins/builtin/money-markets/pane.tsx +7 -1
- package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +4 -2
- package/src/plugins/builtin/portfolio-list/cli/period-report.ts +61 -11
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +11 -3
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -0
- package/src/plugins/builtin/portfolio-list/headless.ts +33 -6
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +5 -3
- package/src/plugins/builtin/portfolio-list/pane/period-pnl.ts +24 -6
- package/src/plugins/builtin/portfolio-list/period-pnl.ts +16 -1
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +4 -1
- package/src/plugins/builtin/portfolio-list/summary/totals.ts +6 -4
- package/src/plugins/builtin/portfolio-list/table.tsx +25 -15
- package/src/plugins/builtin/shared/cloud-upgrade.ts +4 -2
- package/src/plugins/builtin/shared/cpi-year-gap.ts +67 -0
- package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +45 -2
- package/src/plugins/builtin/ticker-detail/headless.ts +26 -1
- package/src/plugins/builtin/ticker-detail/overview/components.tsx +4 -5
- package/src/plugins/builtin/ticker-detail/overview/model.ts +4 -1
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +10 -2
- package/src/portfolio/collection-name.ts +2 -1
- package/src/portfolio/column-values.ts +14 -4
- package/src/portfolio/listed-symbol.ts +4 -2
- package/src/portfolio/period-pnl.ts +51 -1
- package/src/renderers/dom/dialog-host.tsx +5 -5
- package/src/renderers/electrobun/view/remote/capability-invoker.ts +1 -1
- package/src/renderers/opentui/dialog-host.tsx +3 -4
- package/src/sources/gloomberb-cloud/normalizers.ts +5 -0
- package/src/sources/provider-router/history.ts +5 -2
- package/src/test-support/plugin-persistence.ts +12 -0
- package/src/tickers/company-name-listing.ts +4 -3
- package/src/tickers/company-name.ts +19 -1
- package/src/tickers/instrument-coverage.ts +27 -0
- package/src/tickers/search/home-listing.ts +38 -1
- package/src/tickers/search/index.ts +3 -2
- package/src/tickers/search/ranking.ts +21 -2
- package/src/time-series/base-series.ts +4 -0
- package/src/time-series/types.ts +5 -2
- package/src/types/financials.ts +13 -0
- package/src/types/headless.ts +2 -0
- package/src/ui/dialog-stack.ts +17 -0
- package/src/ui/dialog.tsx +6 -2
- package/src/utils/crypto-pair.ts +9 -0
- package/src/utils/exchanges.ts +13 -0
- package/src/utils/financial-statements.ts +60 -3
- package/src/utils/futures-generic.ts +14 -0
- package/src/utils/trailing-dividend.ts +13 -3
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { useEffect, useMemo } from "react";
|
|
2
|
+
import { colors as themeColors } from "../../../../theme/colors";
|
|
3
|
+
import { formatCompositeCursorValue } from "../format";
|
|
4
|
+
import { unprojectCompositeValue } from "../scene";
|
|
5
|
+
import { unprojectCompositeTimestamp } from "../time-scale";
|
|
6
|
+
import {
|
|
7
|
+
countMeasureBars,
|
|
8
|
+
resolveMeasureAxisDomain,
|
|
9
|
+
resolveMeasureDirection,
|
|
10
|
+
summarizeMeasure,
|
|
11
|
+
summarizeZoomRange,
|
|
12
|
+
summarizeZoomSelection,
|
|
13
|
+
type ChartToolDrag,
|
|
14
|
+
} from "../tools";
|
|
15
|
+
import type { KeyboardToolDrag } from "../use-composite-chart-keyboard";
|
|
16
|
+
import type { CompositePanelSurfaceProps } from "./props";
|
|
17
|
+
|
|
18
|
+
/** Where a measure started, marked on the value axes. */
|
|
19
|
+
export interface ToolAnchorMarker {
|
|
20
|
+
side: null;
|
|
21
|
+
yRatio: number;
|
|
22
|
+
label: string;
|
|
23
|
+
color: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* What a tool in hand reads out while it drags, or while it is placed from
|
|
28
|
+
* the keyboard: the summary over the plot, the span it covers (told to the
|
|
29
|
+
* chart, which marks it on the time axis), and the value it started from.
|
|
30
|
+
*/
|
|
31
|
+
export function usePanelToolReadout({
|
|
32
|
+
panel,
|
|
33
|
+
scene,
|
|
34
|
+
colors,
|
|
35
|
+
activeDrag,
|
|
36
|
+
keyboardDrag,
|
|
37
|
+
onToolSpanChange,
|
|
38
|
+
plotWidth,
|
|
39
|
+
leftAxisWidth,
|
|
40
|
+
axisGap,
|
|
41
|
+
}: Pick<CompositePanelSurfaceProps, "panel" | "scene" | "colors" | "onToolSpanChange" | "plotWidth" | "leftAxisWidth" | "axisGap"> & {
|
|
42
|
+
activeDrag: ChartToolDrag | null;
|
|
43
|
+
keyboardDrag: KeyboardToolDrag | null;
|
|
44
|
+
}) {
|
|
45
|
+
const measureDomain = useMemo(() => resolveMeasureAxisDomain(panel), [panel]);
|
|
46
|
+
const toolReadout = useMemo(() => {
|
|
47
|
+
if (!activeDrag) return null;
|
|
48
|
+
// A keyboard placement knows its data points exactly, even off screen; a
|
|
49
|
+
// pointer drag reads them back from the plot.
|
|
50
|
+
const startTime = keyboardDrag?.start.time
|
|
51
|
+
?? unprojectCompositeTimestamp(scene.timeScale, activeDrag.startXRatio);
|
|
52
|
+
const endTime = keyboardDrag?.end.time
|
|
53
|
+
?? unprojectCompositeTimestamp(scene.timeScale, activeDrag.endXRatio);
|
|
54
|
+
if (activeDrag.kind === "zoom") {
|
|
55
|
+
return {
|
|
56
|
+
direction: "up" as const,
|
|
57
|
+
summary: keyboardDrag
|
|
58
|
+
? summarizeZoomRange(scene, startTime, endTime)
|
|
59
|
+
: summarizeZoomSelection(scene, activeDrag),
|
|
60
|
+
startTime,
|
|
61
|
+
startValueLabel: null,
|
|
62
|
+
endValueLabel: null,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const startValue = keyboardDrag
|
|
66
|
+
? keyboardDrag.start.value
|
|
67
|
+
: measureDomain ? unprojectCompositeValue(activeDrag.startYRatio, measureDomain) : null;
|
|
68
|
+
const endValue = keyboardDrag
|
|
69
|
+
? keyboardDrag.end.value
|
|
70
|
+
: measureDomain ? unprojectCompositeValue(activeDrag.endYRatio, measureDomain) : null;
|
|
71
|
+
return {
|
|
72
|
+
direction: resolveMeasureDirection(startValue, endValue),
|
|
73
|
+
summary: summarizeMeasure({
|
|
74
|
+
startValue,
|
|
75
|
+
endValue,
|
|
76
|
+
startTime,
|
|
77
|
+
endTime,
|
|
78
|
+
// Cross-market cursor stops include every listing's observations;
|
|
79
|
+
// measured bars still follow the primary market's session scale.
|
|
80
|
+
bars: countMeasureBars(scene.timeScale.kind === "market"
|
|
81
|
+
? scene.timeScale.anchors.map(({ timestamp }) => new Date(timestamp))
|
|
82
|
+
: scene.dates, startTime, endTime),
|
|
83
|
+
domain: measureDomain,
|
|
84
|
+
}),
|
|
85
|
+
startTime,
|
|
86
|
+
startValueLabel: measureDomain && startValue !== null
|
|
87
|
+
? formatCompositeCursorValue(startValue, measureDomain)
|
|
88
|
+
: null,
|
|
89
|
+
endValueLabel: measureDomain && endValue !== null
|
|
90
|
+
? formatCompositeCursorValue(endValue, measureDomain)
|
|
91
|
+
: null,
|
|
92
|
+
};
|
|
93
|
+
}, [activeDrag, keyboardDrag, measureDomain, scene]);
|
|
94
|
+
const toolSummary = toolReadout?.summary ?? null;
|
|
95
|
+
const toolStartTime = toolReadout?.startTime ?? null;
|
|
96
|
+
const toolSpan = useMemo(() => {
|
|
97
|
+
if (!activeDrag || !toolSummary || toolStartTime === null) return null;
|
|
98
|
+
return {
|
|
99
|
+
startXRatio: activeDrag.startXRatio,
|
|
100
|
+
endXRatio: activeDrag.endXRatio,
|
|
101
|
+
startTime: toolStartTime,
|
|
102
|
+
color: activeDrag.kind === "zoom"
|
|
103
|
+
? colors.crosshair
|
|
104
|
+
: toolReadout?.direction === "down" ? colors.negative : themeColors.positive,
|
|
105
|
+
};
|
|
106
|
+
}, [activeDrag, colors.crosshair, colors.negative, toolReadout?.direction, toolStartTime, toolSummary]);
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
onToolSpanChange(toolSpan);
|
|
109
|
+
}, [onToolSpanChange, toolSpan]);
|
|
110
|
+
const measureReadout = useMemo(() => {
|
|
111
|
+
if (!activeDrag || !toolReadout?.summary) return null;
|
|
112
|
+
const text = toolReadout.summary;
|
|
113
|
+
const centreX = (activeDrag.startXRatio + activeDrag.endXRatio) / 2;
|
|
114
|
+
const centreY = activeDrag.kind === "zoom"
|
|
115
|
+
? 0.5
|
|
116
|
+
: (activeDrag.startYRatio + activeDrag.endYRatio) / 2;
|
|
117
|
+
const width = Math.min([...text].length, plotWidth);
|
|
118
|
+
return {
|
|
119
|
+
text,
|
|
120
|
+
width,
|
|
121
|
+
color: activeDrag.kind === "zoom"
|
|
122
|
+
? colors.text
|
|
123
|
+
: toolReadout.direction === "down" ? colors.negative : themeColors.positive,
|
|
124
|
+
left: leftAxisWidth + (leftAxisWidth ? axisGap : 0)
|
|
125
|
+
+ Math.max(0, Math.min(plotWidth - width, Math.round(centreX * plotWidth - width / 2))),
|
|
126
|
+
top: Math.max(0, Math.min(panel.height - 1, Math.round(centreY * (panel.height - 1)))),
|
|
127
|
+
};
|
|
128
|
+
}, [
|
|
129
|
+
activeDrag,
|
|
130
|
+
axisGap,
|
|
131
|
+
colors.negative,
|
|
132
|
+
colors.text,
|
|
133
|
+
leftAxisWidth,
|
|
134
|
+
panel.height,
|
|
135
|
+
plotWidth,
|
|
136
|
+
toolReadout,
|
|
137
|
+
]);
|
|
138
|
+
const anchorMarker = useMemo((): ToolAnchorMarker | null => {
|
|
139
|
+
// The crosshair already marks the moving end, so the axes only need the
|
|
140
|
+
// anchor the drag started from.
|
|
141
|
+
if (!activeDrag || activeDrag.kind === "zoom" || !toolReadout?.startValueLabel) return null;
|
|
142
|
+
return {
|
|
143
|
+
side: null,
|
|
144
|
+
// A keyboard anchor can leave the value range once the view moves.
|
|
145
|
+
yRatio: Math.max(0, Math.min(1, activeDrag.startYRatio)),
|
|
146
|
+
label: toolReadout.startValueLabel,
|
|
147
|
+
color: toolReadout.direction === "down" ? colors.negative : themeColors.positive,
|
|
148
|
+
};
|
|
149
|
+
}, [activeDrag, colors.negative, toolReadout]);
|
|
150
|
+
return { toolDirection: toolReadout?.direction, measureReadout, anchorMarker };
|
|
151
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, type RefObject } from "react";
|
|
2
|
+
import type { BoxRenderable } from "../../../../ui";
|
|
3
|
+
import { clamp } from "../../../../utils/math";
|
|
4
|
+
import { consumeChartMouseEvent, type ChartMouseEvent } from "../../core/pointer";
|
|
5
|
+
import { resolveCompositeWheelZoom } from "../interactions";
|
|
6
|
+
import { AXIS_DOUBLE_PRESS_MS, isVerticalWheelDirection, type PendingAxisWheel, type ValueAxisStart } from "../panel-gestures";
|
|
7
|
+
import type { CompositeAxisSide } from "../types";
|
|
8
|
+
import { resolveAxisDragSpanFactor, zoomValueRange } from "../value-scale";
|
|
9
|
+
import { pointerRow, webFrame } from "./pointer";
|
|
10
|
+
import type { CompositePanelSurfaceProps } from "./props";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A value axis under the pointer: a drag stretches (up) or squeezes (down)
|
|
14
|
+
* it around its middle, the wheel around the pointer, and a double click
|
|
15
|
+
* fits it to the data again. Read through refs, so the handlers stay put.
|
|
16
|
+
*/
|
|
17
|
+
export function useValueAxisGestures({
|
|
18
|
+
plotRef,
|
|
19
|
+
panel,
|
|
20
|
+
valueScalable,
|
|
21
|
+
onSetValueScale,
|
|
22
|
+
onResetValueScale,
|
|
23
|
+
onActivate,
|
|
24
|
+
isDesktopWeb,
|
|
25
|
+
cellHeightPx,
|
|
26
|
+
fractionalViewport,
|
|
27
|
+
}: Pick<CompositePanelSurfaceProps, "panel" | "valueScalable" | "onSetValueScale" | "onResetValueScale" | "onActivate"> & {
|
|
28
|
+
plotRef: RefObject<BoxRenderable | null>;
|
|
29
|
+
isDesktopWeb: boolean;
|
|
30
|
+
cellHeightPx: number;
|
|
31
|
+
fractionalViewport: boolean;
|
|
32
|
+
}) {
|
|
33
|
+
const axisGestureRef = useRef<(ValueAxisStart & { startRow: number; moved: boolean }) | null>(null);
|
|
34
|
+
const lastAxisPressRef = useRef<{ side: CompositeAxisSide; at: number } | null>(null);
|
|
35
|
+
const latestAxesRef = useRef({ panel, onSetValueScale, onResetValueScale, onActivate });
|
|
36
|
+
latestAxesRef.current = { panel, onSetValueScale, onResetValueScale, onActivate };
|
|
37
|
+
/** The pointer's height down the panel, 0 at the top and 1 at the bottom. */
|
|
38
|
+
const axisPointerRatio = useCallback((event: ChartMouseEvent): number => {
|
|
39
|
+
const plot = plotRef.current as unknown as { absoluteY?: number; y?: number; height?: number } | null;
|
|
40
|
+
const top = plot?.absoluteY ?? plot?.y;
|
|
41
|
+
const height = plot?.height ?? 0;
|
|
42
|
+
if (top === undefined || height <= 1) return 0.5;
|
|
43
|
+
return clamp((pointerRow(event) - top) / (fractionalViewport ? height : height - 1), 0, 1);
|
|
44
|
+
}, [fractionalViewport]);
|
|
45
|
+
const pressAxis = useCallback((side: CompositeAxisSide, event: ChartMouseEvent) => {
|
|
46
|
+
const latest = latestAxesRef.current;
|
|
47
|
+
const domain = latest.panel.axes[side];
|
|
48
|
+
if (!domain?.scaleKey) return;
|
|
49
|
+
latest.onActivate?.();
|
|
50
|
+
consumeChartMouseEvent(event);
|
|
51
|
+
// The desktop counts clicks; the terminal has two presses close together.
|
|
52
|
+
const now = Date.now();
|
|
53
|
+
const last = lastAxisPressRef.current;
|
|
54
|
+
const double = typeof event.detail === "number"
|
|
55
|
+
? event.detail >= 2
|
|
56
|
+
: !!last && last.side === side && now - last.at < AXIS_DOUBLE_PRESS_MS;
|
|
57
|
+
if (double) {
|
|
58
|
+
lastAxisPressRef.current = null;
|
|
59
|
+
axisGestureRef.current = null;
|
|
60
|
+
latest.onResetValueScale(latest.panel.id);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
lastAxisPressRef.current = { side, at: now };
|
|
64
|
+
axisGestureRef.current = {
|
|
65
|
+
side,
|
|
66
|
+
key: domain.scaleKey,
|
|
67
|
+
scale: domain.scale,
|
|
68
|
+
start: { min: domain.min, max: domain.max },
|
|
69
|
+
startRow: pointerRow(event),
|
|
70
|
+
moved: false,
|
|
71
|
+
};
|
|
72
|
+
}, []);
|
|
73
|
+
const dragAxis = useCallback((event: ChartMouseEvent) => {
|
|
74
|
+
const gesture = axisGestureRef.current;
|
|
75
|
+
if (!gesture) return;
|
|
76
|
+
consumeChartMouseEvent(event);
|
|
77
|
+
const deltaPx = (pointerRow(event) - gesture.startRow) * cellHeightPx;
|
|
78
|
+
if (!gesture.moved && Math.abs(deltaPx) < 1) return;
|
|
79
|
+
// A drag is not the first half of a double click.
|
|
80
|
+
gesture.moved = true;
|
|
81
|
+
lastAxisPressRef.current = null;
|
|
82
|
+
const latest = latestAxesRef.current;
|
|
83
|
+
latest.onSetValueScale(
|
|
84
|
+
latest.panel.id,
|
|
85
|
+
gesture.side,
|
|
86
|
+
gesture.key,
|
|
87
|
+
zoomValueRange(gesture.start, gesture.scale, resolveAxisDragSpanFactor(deltaPx), 0.5),
|
|
88
|
+
);
|
|
89
|
+
}, [cellHeightPx]);
|
|
90
|
+
const releaseAxis = useCallback(() => {
|
|
91
|
+
axisGestureRef.current = null;
|
|
92
|
+
}, []);
|
|
93
|
+
const pendingAxisWheelRef = useRef<PendingAxisWheel | null>(null);
|
|
94
|
+
const axisWheelFrameRef = useRef<number | null>(null);
|
|
95
|
+
const flushAxisWheel = useCallback(() => {
|
|
96
|
+
axisWheelFrameRef.current = null;
|
|
97
|
+
const pending = pendingAxisWheelRef.current;
|
|
98
|
+
pendingAxisWheelRef.current = null;
|
|
99
|
+
const latest = latestAxesRef.current;
|
|
100
|
+
const domain = pending ? latest.panel.axes[pending.side] : undefined;
|
|
101
|
+
if (!pending || !domain?.scaleKey || pending.spanLog === 0) return;
|
|
102
|
+
latest.onSetValueScale(
|
|
103
|
+
latest.panel.id,
|
|
104
|
+
pending.side,
|
|
105
|
+
domain.scaleKey,
|
|
106
|
+
zoomValueRange({ min: domain.min, max: domain.max }, domain.scale, Math.exp(pending.spanLog), pending.anchorRatio),
|
|
107
|
+
);
|
|
108
|
+
}, []);
|
|
109
|
+
useEffect(() => () => {
|
|
110
|
+
pendingAxisWheelRef.current = null;
|
|
111
|
+
if (axisWheelFrameRef.current !== null) {
|
|
112
|
+
webFrame.cancelAnimationFrame?.(axisWheelFrameRef.current);
|
|
113
|
+
axisWheelFrameRef.current = null;
|
|
114
|
+
}
|
|
115
|
+
}, []);
|
|
116
|
+
const wheelAxis = useCallback((side: CompositeAxisSide, event: ChartMouseEvent) => {
|
|
117
|
+
const scroll = event.scroll;
|
|
118
|
+
if (!scroll || !latestAxesRef.current.panel.axes[side]?.scaleKey) return;
|
|
119
|
+
latestAxesRef.current.onActivate?.();
|
|
120
|
+
consumeChartMouseEvent(event);
|
|
121
|
+
if (!isVerticalWheelDirection(scroll.direction)) return;
|
|
122
|
+
const pending = pendingAxisWheelRef.current?.side === side
|
|
123
|
+
? pendingAxisWheelRef.current
|
|
124
|
+
: { side, spanLog: 0, anchorRatio: 0.5 };
|
|
125
|
+
// Up stretches, as Ctrl and the wheel zoom the plot in.
|
|
126
|
+
pending.spanLog -= Math.log(resolveCompositeWheelZoom(scroll));
|
|
127
|
+
pending.anchorRatio = axisPointerRatio(event);
|
|
128
|
+
pendingAxisWheelRef.current = pending;
|
|
129
|
+
if (!isDesktopWeb || typeof webFrame.requestAnimationFrame !== "function") {
|
|
130
|
+
flushAxisWheel();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (axisWheelFrameRef.current === null) {
|
|
134
|
+
axisWheelFrameRef.current = webFrame.requestAnimationFrame(flushAxisWheel);
|
|
135
|
+
}
|
|
136
|
+
}, [axisPointerRatio, flushAxisWheel, isDesktopWeb]);
|
|
137
|
+
const leftAxisGestures = useMemo(() => valueScalable ? {
|
|
138
|
+
onMouseDown: (event: ChartMouseEvent) => pressAxis("left", event),
|
|
139
|
+
onMouseDrag: dragAxis,
|
|
140
|
+
onMouseUp: releaseAxis,
|
|
141
|
+
onMouseDragEnd: releaseAxis,
|
|
142
|
+
onMouseScroll: (event: ChartMouseEvent) => wheelAxis("left", event),
|
|
143
|
+
} : undefined, [dragAxis, pressAxis, releaseAxis, valueScalable, wheelAxis]);
|
|
144
|
+
const rightAxisGestures = useMemo(() => valueScalable ? {
|
|
145
|
+
onMouseDown: (event: ChartMouseEvent) => pressAxis("right", event),
|
|
146
|
+
onMouseDrag: dragAxis,
|
|
147
|
+
onMouseUp: releaseAxis,
|
|
148
|
+
onMouseDragEnd: releaseAxis,
|
|
149
|
+
onMouseScroll: (event: ChartMouseEvent) => wheelAxis("right", event),
|
|
150
|
+
} : undefined, [dragAxis, pressAxis, releaseAxis, valueScalable, wheelAxis]);
|
|
151
|
+
return { leftAxisGestures, rightAxisGestures };
|
|
152
|
+
}
|