react-native-livechart 4.26.0 → 4.27.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.
Files changed (115) hide show
  1. package/dist/components/CustomReferenceLineOverlay.d.ts +8 -1
  2. package/dist/components/CustomReferenceLineOverlay.d.ts.map +1 -1
  3. package/dist/components/CustomTooltipOverlay.d.ts +3 -2
  4. package/dist/components/CustomTooltipOverlay.d.ts.map +1 -1
  5. package/dist/components/LiveChart.d.ts +1 -1
  6. package/dist/components/LiveChart.d.ts.map +1 -1
  7. package/dist/components/LiveChartSeries.d.ts.map +1 -1
  8. package/dist/components/ReferenceLineOverlay.d.ts +4 -0
  9. package/dist/components/ReferenceLineOverlay.d.ts.map +1 -1
  10. package/dist/components/ReferenceValueBadge.d.ts +15 -0
  11. package/dist/components/ReferenceValueBadge.d.ts.map +1 -0
  12. package/dist/components/XAxisOverlay.d.ts +17 -0
  13. package/dist/components/XAxisOverlay.d.ts.map +1 -1
  14. package/dist/core/liveChartEngineTick.d.ts +4 -0
  15. package/dist/core/liveChartEngineTick.d.ts.map +1 -1
  16. package/dist/core/liveChartSeriesEngineTick.d.ts +2 -0
  17. package/dist/core/liveChartSeriesEngineTick.d.ts.map +1 -1
  18. package/dist/core/resolveConfig.d.ts +28 -1
  19. package/dist/core/resolveConfig.d.ts.map +1 -1
  20. package/dist/core/useLiveChartEngine.d.ts +7 -0
  21. package/dist/core/useLiveChartEngine.d.ts.map +1 -1
  22. package/dist/core/useLiveChartSeriesEngine.d.ts +2 -0
  23. package/dist/core/useLiveChartSeriesEngine.d.ts.map +1 -1
  24. package/dist/draw/grid.d.ts +2 -2
  25. package/dist/draw/line.d.ts +15 -1
  26. package/dist/draw/line.d.ts.map +1 -1
  27. package/dist/hooks/crosshairShared.d.ts +16 -1
  28. package/dist/hooks/crosshairShared.d.ts.map +1 -1
  29. package/dist/hooks/referenceBadgeFont.d.ts +5 -0
  30. package/dist/hooks/referenceBadgeFont.d.ts.map +1 -0
  31. package/dist/hooks/resolveChartLayout.d.ts +8 -0
  32. package/dist/hooks/resolveChartLayout.d.ts.map +1 -1
  33. package/dist/hooks/useBadge.d.ts +16 -1
  34. package/dist/hooks/useBadge.d.ts.map +1 -1
  35. package/dist/hooks/useChartSkiaFont.d.ts +1 -0
  36. package/dist/hooks/useChartSkiaFont.d.ts.map +1 -1
  37. package/dist/hooks/useCrosshair.d.ts +7 -2
  38. package/dist/hooks/useCrosshair.d.ts.map +1 -1
  39. package/dist/hooks/useCrosshairSeries.d.ts +4 -1
  40. package/dist/hooks/useCrosshairSeries.d.ts.map +1 -1
  41. package/dist/hooks/useLatestCallback.d.ts +6 -0
  42. package/dist/hooks/useLatestCallback.d.ts.map +1 -0
  43. package/dist/hooks/useMarkers.d.ts.map +1 -1
  44. package/dist/hooks/usePanScroll.d.ts +3 -1
  45. package/dist/hooks/usePanScroll.d.ts.map +1 -1
  46. package/dist/hooks/usePinchZoom.d.ts.map +1 -1
  47. package/dist/hooks/useReferenceDrag.d.ts +20 -5
  48. package/dist/hooks/useReferenceDrag.d.ts.map +1 -1
  49. package/dist/hooks/useReferenceLine.d.ts +24 -12
  50. package/dist/hooks/useReferenceLine.d.ts.map +1 -1
  51. package/dist/hooks/useReferenceLinePress.d.ts +4 -2
  52. package/dist/hooks/useReferenceLinePress.d.ts.map +1 -1
  53. package/dist/hooks/useReferenceTagStack.d.ts +31 -0
  54. package/dist/hooks/useReferenceTagStack.d.ts.map +1 -0
  55. package/dist/hooks/useScrubMarkers.d.ts +12 -0
  56. package/dist/hooks/useScrubMarkers.d.ts.map +1 -0
  57. package/dist/hooks/useXAxis.d.ts +1 -1
  58. package/dist/hooks/useXAxis.d.ts.map +1 -1
  59. package/dist/hooks/useYAxisScaleGesture.d.ts +34 -0
  60. package/dist/hooks/useYAxisScaleGesture.d.ts.map +1 -0
  61. package/dist/index.d.ts +1 -1
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/math/axisBadgeLayout.d.ts +16 -0
  64. package/dist/math/axisBadgeLayout.d.ts.map +1 -0
  65. package/dist/math/markers.d.ts +3 -0
  66. package/dist/math/markers.d.ts.map +1 -1
  67. package/dist/math/range.d.ts +1 -1
  68. package/dist/math/range.d.ts.map +1 -1
  69. package/dist/math/referenceTagStack.d.ts +36 -0
  70. package/dist/math/referenceTagStack.d.ts.map +1 -0
  71. package/dist/math/scrubMarkers.d.ts +12 -0
  72. package/dist/math/scrubMarkers.d.ts.map +1 -0
  73. package/dist/types.d.ts +202 -32
  74. package/dist/types.d.ts.map +1 -1
  75. package/package.json +1 -1
  76. package/src/components/CustomReferenceLineOverlay.tsx +50 -8
  77. package/src/components/CustomTooltipOverlay.tsx +5 -1
  78. package/src/components/LiveChart.tsx +560 -138
  79. package/src/components/LiveChartSeries.tsx +113 -13
  80. package/src/components/ReferenceLineOverlay.tsx +62 -26
  81. package/src/components/ReferenceValueBadge.tsx +102 -0
  82. package/src/components/XAxisOverlay.tsx +104 -1
  83. package/src/core/liveChartEngineTick.ts +49 -4
  84. package/src/core/liveChartSeriesEngineTick.ts +37 -0
  85. package/src/core/resolveConfig.ts +95 -2
  86. package/src/core/useLiveChartEngine.ts +43 -9
  87. package/src/core/useLiveChartSeriesEngine.ts +5 -0
  88. package/src/draw/grid.ts +2 -2
  89. package/src/draw/line.ts +23 -1
  90. package/src/hooks/crosshairShared.ts +56 -1
  91. package/src/hooks/referenceBadgeFont.ts +35 -0
  92. package/src/hooks/resolveChartLayout.ts +17 -0
  93. package/src/hooks/useBadge.ts +44 -5
  94. package/src/hooks/useChartSkiaFont.ts +1 -1
  95. package/src/hooks/useCrosshair.ts +444 -310
  96. package/src/hooks/useCrosshairSeries.ts +29 -10
  97. package/src/hooks/useLatestCallback.ts +15 -0
  98. package/src/hooks/useMarkers.ts +51 -39
  99. package/src/hooks/usePanScroll.ts +155 -127
  100. package/src/hooks/usePinchZoom.ts +84 -63
  101. package/src/hooks/useReferenceDrag.ts +390 -155
  102. package/src/hooks/useReferenceLine.ts +453 -277
  103. package/src/hooks/useReferenceLineGrouping.ts +1 -1
  104. package/src/hooks/useReferenceLinePress.ts +121 -53
  105. package/src/hooks/useReferenceTagStack.ts +81 -0
  106. package/src/hooks/useScrubMarkers.ts +79 -0
  107. package/src/hooks/useXAxis.ts +11 -2
  108. package/src/hooks/useYAxisScaleGesture.ts +263 -0
  109. package/src/index.ts +10 -0
  110. package/src/math/axisBadgeLayout.ts +37 -0
  111. package/src/math/markers.ts +28 -3
  112. package/src/math/range.ts +35 -0
  113. package/src/math/referenceTagStack.ts +112 -0
  114. package/src/math/scrubMarkers.ts +55 -0
  115. package/src/types.ts +207 -32
package/src/index.ts CHANGED
@@ -61,9 +61,12 @@ export type {
61
61
  ChartPlotRect,
62
62
  ChartScale,
63
63
  ChartSegment,
64
+ ChartViewportControl,
64
65
  DegenOptions,
65
66
  DegenShakePayload,
67
+ DotConfig,
66
68
  DotGlowConfig,
69
+ DotRingConfig,
67
70
  EmptyStateMetrics,
68
71
  FontConfig,
69
72
  FontWeight,
@@ -74,6 +77,7 @@ export type {
74
77
  LegendConfig,
75
78
  LegendStyle,
76
79
  LineConfig,
80
+ LineStyleConfig,
77
81
  LiveChartCoreProps,
78
82
  LiveChartFrameStats,
79
83
  LiveChartHandle,
@@ -100,12 +104,14 @@ export type {
100
104
  RangeAnimationConfig,
101
105
  ReferenceLine,
102
106
  ReferenceLineBadgeConfig,
107
+ ReferenceLineValueBadgeConfig,
103
108
  ReferenceLineGroupingConfig,
104
109
  ReferenceLineRenderProps,
105
110
  ReturnToLiveConfig,
106
111
  ScrubActionConfig,
107
112
  ScrubActionPoint,
108
113
  ScrubConfig,
114
+ ScrubMarkerConfig,
109
115
  ScrubPoint,
110
116
  ScrubPointCore,
111
117
  ScrubPointMulti,
@@ -117,14 +123,18 @@ export type {
117
123
  ThemeMode,
118
124
  ThresholdConfig,
119
125
  ThresholdBadgeRenderProps,
126
+ ThresholdFillConfig,
120
127
  ThresholdLineConfig,
128
+ TimeScrollConfig,
121
129
  TooltipRenderProps,
122
130
  TradeEvent,
123
131
  TransitionConfig,
124
132
  ValueLineConfig,
133
+ ViewportConfig,
125
134
  VisibleRange,
126
135
  VolumeConfig,
127
136
  XAxisConfig,
128
137
  YAxisConfig,
138
+ YAxisScaleGestureConfig,
129
139
  ZoomConfig,
130
140
  } from "./types";
@@ -0,0 +1,37 @@
1
+ import { BADGE_METRICS_DEFAULTS } from "../constants";
2
+ import { badgeTailAndCap } from "../draw/line";
3
+ import type { BadgeMetrics } from "../types";
4
+
5
+ /** Horizontal price-column geometry, independent of the value's vertical position. */
6
+ export interface AxisBadgeConfig {
7
+ float?: boolean;
8
+ alignTextWithYAxis?: boolean;
9
+ showTail?: boolean;
10
+ fontSize?: number;
11
+ metrics?: BadgeMetrics;
12
+ offsetX?: number;
13
+ }
14
+
15
+ export function axisBadgeBounds(
16
+ width: number,
17
+ paddingRight: number,
18
+ textWidth: number,
19
+ fontSize: number,
20
+ config?: AxisBadgeConfig,
21
+ ) {
22
+ "worklet";
23
+ const metrics = config?.metrics ?? BADGE_METRICS_DEFAULTS;
24
+ const right = width - metrics.marginEdge + (config?.offsetX ?? 0);
25
+ const left = config?.float
26
+ ? right - textWidth - 2 * metrics.padX
27
+ : width -
28
+ paddingRight +
29
+ metrics.dotGap +
30
+ badgeTailAndCap(
31
+ config?.fontSize ?? fontSize,
32
+ config?.showTail ?? true,
33
+ metrics,
34
+ ) +
35
+ (config?.offsetX ?? 0);
36
+ return { left, right, textX: (left + right - textWidth) / 2 };
37
+ }
@@ -6,6 +6,9 @@ import { splineValueAtTime } from "./spline";
6
6
  export interface ProjectedMarker {
7
7
  x: number;
8
8
  y: number;
9
+ /** The anchor is on the plot: across within `EDGE_SLOP` of it, up and down
10
+ * within `CULL_MARGIN`. Only visible markers are drawn, clustered, or
11
+ * hit-tested. */
9
12
  visible: boolean;
10
13
  /** Collapsed cluster member that the representative stands in for — not drawn,
11
14
  * not hit-tested. Set by the cluster pass; `false` outside `markerCluster`. */
@@ -41,9 +44,25 @@ export interface ProjectMarkersOpts {
41
44
  lineLinear?: boolean;
42
45
  }
43
46
 
44
- /** How far off-chart (px) a marker may sit before it is culled. */
47
+ /**
48
+ * How far above / below the plot (px) a marker's anchor may sit before it is
49
+ * culled. Vertical only: across, the anchor must stay on the plot (see
50
+ * {@link EDGE_SLOP}).
51
+ */
45
52
  const CULL_MARGIN = 24;
46
53
 
54
+ /**
55
+ * Slack (px) past the plot's left / right edge before a marker is culled.
56
+ * `LiveChart`'s engine moves its right edge in half-pixel steps
57
+ * (`advanceTimestampByPixel`), so it can trail its target by up to half a
58
+ * pixel: a marker stamped with the current time sits just past the edge until
59
+ * the next step (on a wide window, for seconds), and after a `nowOverride`
60
+ * change the edge can rest just short of the new time indefinitely, so a
61
+ * marker at `nowOverride` would otherwise never show. Also absorbs float
62
+ * rounding of a marker exactly on an edge.
63
+ */
64
+ const EDGE_SLOP = 0.5;
65
+
47
66
  /**
48
67
  * Project one marker (given its primitive anchor fields) into `target`,
49
68
  * without allocation. Primitives only, so per-glyph worklet closures don't
@@ -115,9 +134,15 @@ function projectInto(
115
134
  const y = chartTop + ((opts.displayMax - v) / valRange) * chartH;
116
135
  target.x = x;
117
136
  target.y = y;
137
+ // Across, a marker shows only while its anchor is on the plot: it disappears
138
+ // at the plot's left / right edge instead of sliding on over a y-axis gutter
139
+ // (either side) or the left inset. A glyph anchored just inside an edge still
140
+ // overhangs it by up to half its width. Up and down keep CULL_MARGIN: a
141
+ // marker's value can sit just outside the fitted Y range, or lead it while
142
+ // the range eases out.
118
143
  target.visible =
119
- x >= chartLeft - CULL_MARGIN &&
120
- x <= chartRight + CULL_MARGIN &&
144
+ x >= chartLeft - EDGE_SLOP &&
145
+ x <= chartRight + EDGE_SLOP &&
121
146
  y >= chartTop - CULL_MARGIN &&
122
147
  y <= chartBottom + CULL_MARGIN;
123
148
  }
package/src/math/range.ts CHANGED
@@ -11,6 +11,7 @@ export function computeRange(
11
11
  exaggerate?: boolean,
12
12
  nonNegative?: boolean,
13
13
  maxValue?: number,
14
+ floorRange?: number,
14
15
  ): { min: number; max: number } {
15
16
  "worklet";
16
17
  let targetMin = Infinity;
@@ -47,6 +48,40 @@ export function computeRange(
47
48
  targetMax += margin;
48
49
  }
49
50
 
51
+ // Compare the bounded fit: a clamp can shrink an otherwise wider range.
52
+ // Slide a widened fit off either bound; both hard bounds win if the floor
53
+ // cannot fit between them. Mirrors the fitted range used by both engines.
54
+ if (floorRange !== undefined && floorRange > 0 && Number.isFinite(floorRange)) {
55
+ const boundedMin = nonNegative && targetMin < 0 ? 0 : targetMin;
56
+ const boundedMax =
57
+ maxValue !== undefined && targetMax > maxValue ? maxValue : targetMax;
58
+ if (floorRange > boundedMax - boundedMin) {
59
+ // Halve before adding so large finite prices cannot overflow the midpoint.
60
+ const mid = targetMin / 2 + targetMax / 2;
61
+ let nextMin = mid - floorRange / 2;
62
+ let nextMax = mid + floorRange / 2;
63
+ if (nonNegative && nextMin < 0) {
64
+ nextMax -= nextMin;
65
+ nextMin = 0;
66
+ }
67
+ if (maxValue !== undefined && nextMax > maxValue) {
68
+ nextMin -= nextMax - maxValue;
69
+ nextMax = maxValue;
70
+ }
71
+ if (nonNegative && nextMin < 0) nextMin = 0;
72
+ // Ignore a floor that would overflow or round the bounds onto each other.
73
+ if (
74
+ Number.isFinite(nextMin) &&
75
+ Number.isFinite(nextMax) &&
76
+ nextMin < nextMax &&
77
+ Number.isFinite(nextMax - nextMin)
78
+ ) {
79
+ targetMin = nextMin;
80
+ targetMax = nextMax;
81
+ }
82
+ }
83
+ }
84
+
50
85
  if (nonNegative && targetMin < 0) targetMin = 0;
51
86
  if (maxValue !== undefined && targetMax > maxValue) targetMax = maxValue;
52
87
 
@@ -0,0 +1,112 @@
1
+ /** Screen rectangles shared by reference-tag drawing and interaction. */
2
+ export interface TagRect { x: number; y: number; w: number; h: number }
3
+ export interface ReferenceTag extends TagRect {
4
+ index: number;
5
+ lineId?: string;
6
+ key: string;
7
+ kind: "name" | "value" | "custom";
8
+ /** Original projected price Y; displacement never changes the price. */
9
+ lineY: number;
10
+ }
11
+ export interface StackedReferenceTag extends ReferenceTag { offsetY: number }
12
+ export interface ReferenceTagStack {
13
+ offsets: number[];
14
+ valueOffsets: number[];
15
+ tags: StackedReferenceTag[];
16
+ }
17
+ export const EMPTY_TAG_STACK: ReferenceTagStack = { offsets: [], valueOffsets: [], tags: [] };
18
+
19
+ export function overlapsX(a: TagRect, b: TagRect): boolean {
20
+ "worklet";
21
+ return a.x < b.x + b.w && b.x < a.x + a.w;
22
+ }
23
+
24
+ /** Fit an ordered column without changing its order. Null means it cannot fit. */
25
+ function pack(tags: ReferenceTag[], top: number, bottom: number, radius: number): number[] | null {
26
+ "worklet";
27
+ if (!tags.length) return [];
28
+ const ys: number[] = [];
29
+ for (let i = 0; i < tags.length; i++) {
30
+ const t = tags[i];
31
+ const min = i === 0 ? top + t.h / 2 : ys[i - 1] + Math.max(radius, (tags[i - 1].h + t.h) / 2 + 2);
32
+ ys.push(Math.max(min, t.y + t.h / 2));
33
+ }
34
+ ys[ys.length - 1] = Math.min(ys[ys.length - 1], bottom - tags[tags.length - 1].h / 2);
35
+ for (let i = ys.length - 2; i >= 0; i--)
36
+ ys[i] = Math.min(ys[i], ys[i + 1] - Math.max(radius, (tags[i].h + tags[i + 1].h) / 2 + 2));
37
+ return ys[0] >= top + tags[0].h / 2 - 0.001 ? ys : null;
38
+ }
39
+
40
+ /**
41
+ * Pack only horizontally intersecting columns. Opposite edges stay independent.
42
+ * A fixed value-badge obstacle divides a column into above/below slots; choose
43
+ * the feasible split with the smallest total squared displacement. If there is
44
+ * physically insufficient height, retain every tag in bounds with best-effort
45
+ * spacing rather than hiding levels or moving their prices.
46
+ */
47
+ export function stackReferenceTags(
48
+ input: ReferenceTag[], top: number, bottom: number, radius = 18, obstacle: TagRect | null = null,
49
+ ): ReferenceTagStack {
50
+ "worklet";
51
+ const result: ReferenceTagStack = { offsets: [], valueOffsets: [], tags: [] };
52
+ if (!Number.isFinite(top) || !Number.isFinite(bottom) || bottom <= top) return result;
53
+ const tags = input.filter(t => [t.x, t.y, t.w, t.h, t.lineY].every(v => Number.isFinite(v)) && t.w > 0 && t.h > 0);
54
+ const separation = Number.isFinite(radius) && radius >= 0 ? radius : 18;
55
+ const visited: boolean[] = [];
56
+ for (let first = 0; first < tags.length; first++) {
57
+ if (visited[first]) continue;
58
+ const component = [tags[first]];
59
+ visited[first] = true;
60
+ for (let j = 0; j < component.length; j++) {
61
+ for (let k = 0; k < tags.length; k++) {
62
+ if (!visited[k] && overlapsX(component[j], tags[k])) {
63
+ visited[k] = true;
64
+ component.push(tags[k]);
65
+ }
66
+ }
67
+ }
68
+ component.sort((a, b) => (a.y + a.h / 2) - (b.y + b.h / 2) || (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
69
+ const blocked = obstacle && obstacle.h > 0 && obstacle.y < bottom && obstacle.y + obstacle.h > top && component.some(t => overlapsX(t, obstacle));
70
+ let positions: number[] | null = null;
71
+ if (blocked && obstacle) {
72
+ let bestCost = Infinity;
73
+ for (let split = 0; split <= component.length; split++) {
74
+ const above = pack(component.slice(0, split), top, Math.min(bottom, obstacle.y - 2), separation);
75
+ const below = pack(component.slice(split), Math.max(top, obstacle.y + obstacle.h + 2), bottom, separation);
76
+ if (!above || !below) continue;
77
+ const candidate = above.concat(below);
78
+ let cost = 0;
79
+ for (let j = 0; j < candidate.length; j++) cost += (candidate[j] - component[j].y - component[j].h / 2) ** 2;
80
+ if (cost < bestCost) { positions = candidate; bestCost = cost; }
81
+ }
82
+ } else positions = pack(component, top, bottom, separation);
83
+ if (!positions) {
84
+ // Crowded charts cannot guarantee separation. Keep stable price ordering
85
+ // and bounded centers; never silently collapse or discard a reference.
86
+ positions = component.map((t, i) => {
87
+ const half = Math.min(t.h / 2, (bottom - top) / 2);
88
+ return Math.max(top + half, Math.min(bottom - half,
89
+ component.length === 1 ? t.y + t.h / 2 : top + half + (bottom - top - 2 * half) * i / (component.length - 1)));
90
+ });
91
+ }
92
+ for (let j = 0; j < component.length; j++) {
93
+ const tag = component[j];
94
+ const offsetY = positions[j] - tag.y - tag.h / 2;
95
+ if (tag.kind === "value") result.valueOffsets[tag.index] = offsetY;
96
+ else result.offsets[tag.index] = offsetY;
97
+ result.tags.push({ ...tag, y: tag.y + offsetY, offsetY });
98
+ }
99
+ }
100
+ return result;
101
+ }
102
+
103
+ /** Exact rectangles beat inflated targets when adjacent tags have a small gap. */
104
+ export function stackedTagAt(tags: StackedReferenceTag[], x: number, y: number): StackedReferenceTag | null {
105
+ "worklet";
106
+ let hit: StackedReferenceTag | null = null;
107
+ for (let i = tags.length - 1; i >= 0; i--) {
108
+ const t = tags[i];
109
+ if ((!hit || t.index > hit.index) && x >= t.x && x <= t.x + t.w && y >= t.y && y <= t.y + t.h) hit = t;
110
+ }
111
+ return hit;
112
+ }
@@ -0,0 +1,55 @@
1
+ import type { Marker } from "../types";
2
+
3
+ export interface ScrubMarkerRange {
4
+ from: number;
5
+ to: number;
6
+ /** Candle buckets are [start, end); line proximity includes both edges. */
7
+ exclusiveEnd: boolean;
8
+ }
9
+
10
+ /** Timestamp matching deliberately ignores glyph offsets, Y, and clustering. */
11
+ export function matchScrubMarkers(
12
+ markers: Marker[],
13
+ range: ScrubMarkerRange | null,
14
+ ): Marker[] {
15
+ "worklet";
16
+ if (!range) return [];
17
+ return markers.filter(
18
+ (marker) => marker.time >= range.from &&
19
+ (range.exclusiveEnd ? marker.time < range.to : marker.time <= range.to),
20
+ );
21
+ }
22
+
23
+ /** Convert a horizontal touch tolerance to time using the drawn viewport. */
24
+ export function scrubMarkerRange(
25
+ time: number,
26
+ now: number,
27
+ window: number,
28
+ plotWidth: number,
29
+ radius: number,
30
+ candleMode: boolean,
31
+ candleTime: number | null,
32
+ candleWidth: number,
33
+ ): ScrubMarkerRange | null {
34
+ "worklet";
35
+ if (
36
+ !Number.isFinite(time) || time < 0 || !Number.isFinite(now) ||
37
+ !Number.isFinite(window) || window <= 0 ||
38
+ !Number.isFinite(plotWidth) || plotWidth <= 0
39
+ ) return null;
40
+ if (candleMode) {
41
+ if (
42
+ candleTime === null || !Number.isFinite(candleTime) ||
43
+ !Number.isFinite(candleWidth) || candleWidth <= 0
44
+ ) return null;
45
+ return { from: candleTime, to: candleTime + candleWidth, exclusiveEnd: true };
46
+ }
47
+ const start = now - window;
48
+ if (time < start || time > now) return null;
49
+ const tolerance = radius * window / plotWidth;
50
+ return {
51
+ from: Math.max(start, time - tolerance),
52
+ to: Math.min(now, time + tolerance),
53
+ exclusiveEnd: false,
54
+ };
55
+ }