@wick-charts/react 0.3.5 → 0.3.6

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/dist/index.d.ts CHANGED
@@ -412,7 +412,7 @@ export declare const catppuccin: ThemePreset;
412
412
  * - Legend — flex sibling at the bottom (or right, when `position="right"`), so its height is
413
413
  * reserved by browser layout.
414
414
  */
415
- export declare function ChartContainer({ children, theme, axis, padding, gradient, interactive, grid, headerLayout, perf, animations, style, className, }: ChartContainerProps): JSX_2.Element;
415
+ export declare function ChartContainer({ children, theme, axis, padding, gradient, interactive, grid, headerLayout, perf, animations, onEdgeReached, style, className, }: ChartContainerProps): JSX_2.Element;
416
416
 
417
417
  /** Props for the {@link ChartContainer} component. */
418
418
  declare interface ChartContainerProps {
@@ -509,6 +509,18 @@ declare interface ChartContainerProps {
509
509
  * Only read at mount; changing this prop after the chart is created is ignored.
510
510
  */
511
511
  perf?: PerfOption;
512
+ /**
513
+ * Fired after the user releases a pan/zoom gesture that pulled the viewport
514
+ * past a data edge by more than ~10% of the visible range. Hosts typically
515
+ * respond by prefetching more history.
516
+ *
517
+ * For threshold-based prefetch (load *before* the user fully overshoots),
518
+ * use `<EdgeLoader>` instead — that component subscribes to `viewportChange`
519
+ * and arms when the visible range nears the data edge.
520
+ *
521
+ * Captured at mount only; changing the prop identity later is ignored.
522
+ */
523
+ onEdgeReached?: (info: EdgeReachedInfo) => void;
512
524
  /** Inline style for the chart's outer wrapper element. */
513
525
  style?: CSSProperties;
514
526
  /** Extra class for the chart's outer wrapper element. */
@@ -618,6 +630,36 @@ export declare class ChartInstance extends EventEmitter<ChartEvents> {
618
630
  setVisibleRange(range: VisibleRange | number): void;
619
631
  getYRange(): YRange;
620
632
  getCrosshairPosition(): CrosshairPosition | null;
633
+ /**
634
+ * Programmatically set or clear the crosshair. Same effect as the user
635
+ * hovering over `(timeToX(time), valueToY(y))` — emits `crosshairMove`,
636
+ * marks the overlay layer dirty, and lets `<Crosshair>` / `<Tooltip>`
637
+ * react via their normal store subscriptions.
638
+ *
639
+ * Pass `null` to clear (mirrors the pointer-leave path).
640
+ *
641
+ * `y` is optional. Resolution order when omitted:
642
+ * 1. **current crosshair's y** — preserves whatever the chart already
643
+ * has (real cursor y, or a previously-synthesised value). This is
644
+ * what makes the cross-chart broadcast pattern work: when an echo
645
+ * arrives at the chart that originated the hover, the existing y
646
+ * stays in place and the idempotency check below short-circuits the
647
+ * loop. Without preservation, the echo would overwrite the source's
648
+ * real cursor y with the midpoint default and the tooltip would
649
+ * jitter between cursor and midpoint every mouse-move.
650
+ * 2. **midpoint of the current Y range** — fallback when there is no
651
+ * current crosshair (first programmatic set on a chart that hasn't
652
+ * been hovered yet).
653
+ *
654
+ * Idempotent: a call that produces the same `(time, y)` pair as the
655
+ * current crosshair is a no-op (no emit). Combined with the y-preservation
656
+ * above, this lets N charts broadcast their hover to each other without
657
+ * a feedback-loop guard.
658
+ */
659
+ setCrosshair(pos: {
660
+ time: number;
661
+ y?: number;
662
+ } | null): void;
621
663
  /** Get the last visible value and whether the absolute last point is on screen. */
622
664
  getLastValue(seriesId: string): {
623
665
  value: number;
@@ -1102,8 +1144,69 @@ export declare function detectInterval(times: number[]): number;
1102
1144
 
1103
1145
  export declare const dracula: ThemePreset;
1104
1146
 
1147
+ /**
1148
+ * Subscribes to the chart's viewport and triggers a fetch when the visible
1149
+ * range nears the chosen data edge. Handles the boilerplate every load-on-scroll
1150
+ * site otherwise has to re-implement: arming after first user pan, deduping
1151
+ * via Promise tracking, and exposing the boundary's pixel coordinate so a
1152
+ * loader can be anchored to "the wall of available history".
1153
+ *
1154
+ * Place as a child of `<ChartContainer>`.
1155
+ */
1156
+ export declare function EdgeLoader({ side, threshold, onTrigger, indicator, children }: EdgeLoaderProps): JSX_2.Element | null;
1157
+
1158
+ export declare interface EdgeLoaderProps {
1159
+ /** Which edge to watch. */
1160
+ side: EdgeSide;
1161
+ /**
1162
+ * Bars from the edge that arms the trigger. Multiplied by the chart's data
1163
+ * interval. Default `5`.
1164
+ */
1165
+ threshold?: number;
1166
+ /**
1167
+ * Called when the visible range moves within {@link EdgeLoaderProps.threshold}
1168
+ * bars of the data edge. Returning a Promise toggles `isLoading` for its
1169
+ * lifetime. **Resolve with `false`** to signal "no more data" — the loader
1170
+ * stops watching and switches the optional canvas indicator to its
1171
+ * `'no-data'` state. Any other resolve value (including `undefined`) means
1172
+ * "keep watching for the next near-edge event".
1173
+ */
1174
+ onTrigger: () => void | Promise<unknown>;
1175
+ /**
1176
+ * - `'canvas'` (default): drive the chart's built-in canvas spinner via
1177
+ * {@link ChartInstance.setEdgeState}. Renders inside the chart area at
1178
+ * the data boundary.
1179
+ * - `'custom'`: skip the canvas indicator. Use the render-prop `children`
1180
+ * to draw your own DOM/SVG loader.
1181
+ */
1182
+ indicator?: 'canvas' | 'custom';
1183
+ /**
1184
+ * Optional render-prop. Receives the live edge state — render whatever
1185
+ * positioned overlay you want, or return `null`.
1186
+ */
1187
+ children?: (args: EdgeLoaderRenderArgs) => ReactNode;
1188
+ }
1189
+
1190
+ /** Argument shape passed to the {@link EdgeLoader} render-prop. */
1191
+ export declare interface EdgeLoaderRenderArgs {
1192
+ /**
1193
+ * CSS pixels in the chart's overlay coordinate space, anchored at the data
1194
+ * edge (`data.from` for `side='left'`, `data.to` for `side='right'`).
1195
+ * The overlay div is positioned with `inset: 0`, so this value can be used
1196
+ * directly as `style={{ left: x }}` or `transform: translateX(...)`.
1197
+ */
1198
+ x: number;
1199
+ side: EdgeSide;
1200
+ /** True between {@link EdgeLoaderProps.onTrigger} firing and its Promise resolving. */
1201
+ isLoading: boolean;
1202
+ /** Time coordinate (ms) of the data edge — convenient for "fetch history before T" requests. */
1203
+ boundaryTime: number;
1204
+ /** Becomes `false` after `onTrigger` resolves with the literal value `false`. */
1205
+ hasMore: boolean;
1206
+ }
1207
+
1105
1208
  /** Payload for {@link ChartOptions.onEdgeReached}. */
1106
- declare interface EdgeReachedInfo {
1209
+ export declare interface EdgeReachedInfo {
1107
1210
  side: EdgeSide;
1108
1211
  /** Time units the user pulled past the soft bound. */
1109
1212
  overshoot: number;
@@ -1112,7 +1215,7 @@ declare interface EdgeReachedInfo {
1112
1215
  }
1113
1216
 
1114
1217
  /** Which data side the user pulled past during a gesture. */
1115
- declare type EdgeSide = 'left' | 'right';
1218
+ export declare type EdgeSide = 'left' | 'right';
1116
1219
 
1117
1220
  /**
1118
1221
  * Host-controlled visual state for a chart edge:
@@ -1121,7 +1224,7 @@ declare type EdgeSide = 'left' | 'right';
1121
1224
  * - `no-data`: a dashed boundary line + "No more data" label appears at the data edge.
1122
1225
  * - `has-more`: reserved — currently behaves like `idle`. Use when more data exists but is not being fetched.
1123
1226
  */
1124
- declare type EdgeState = 'idle' | 'loading' | 'no-data' | 'has-more';
1227
+ export declare type EdgeState = 'idle' | 'loading' | 'no-data' | 'has-more';
1125
1228
 
1126
1229
  declare class EventEmitter<Events = Record<string, Listener>> {
1127
1230
  private listeners;
@@ -1215,6 +1318,19 @@ export declare interface InfoBarRenderContext {
1215
1318
  readonly isHover: boolean;
1216
1319
  }
1217
1320
 
1321
+ /**
1322
+ * `true` when the given `#rrggbb` background reads as dark — Rec. 601 luma
1323
+ * below the half-byte threshold (`< 128`). Used internally by
1324
+ * {@link createTheme} to flip default palette/contrast picks, and exported
1325
+ * for callers (docs UI chrome, host apps) that want to branch on theme
1326
+ * polarity without carrying their own copy of the heuristic.
1327
+ *
1328
+ * Falls through (`false`) for non-hex inputs (e.g. `transparent`,
1329
+ * `rgba(...)`, gradients) — the built-in presets all use plain hex on the
1330
+ * top-level `background`, so this is fine for the vast majority of cases.
1331
+ */
1332
+ export declare function isDarkBg(bg: string): boolean;
1333
+
1218
1334
  export declare const lavenderMist: ThemePreset;
1219
1335
 
1220
1336
  export declare function Legend({ items, position, mode, children }: LegendProps): JSX_2.Element | null;