@forgecharts/sdk 1.5.69 → 1.5.70

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/internal.js CHANGED
@@ -100,6 +100,36 @@ function isGLBXDailyBreak(nowMs = Date.now()) {
100
100
  return weekday === "Mon" || weekday === "Tue" || weekday === "Wed" || weekday === "Thu";
101
101
  }
102
102
 
103
+ // src/core/cursorTime.ts
104
+ function cursorBucketTime(bars, transform, interval, x) {
105
+ const raw = transform.xToTime(x);
106
+ const tfSec = parseTfSeconds(interval) ?? 0;
107
+ const floored = tfSec > 0 ? Math.floor(raw / tfSec) * tfSec : raw;
108
+ if (!bars || bars.length === 0) return floored;
109
+ let lo = 0, hi = bars.length - 1;
110
+ while (lo < hi) {
111
+ const mid = lo + hi >>> 1;
112
+ if (bars[mid].time < raw) lo = mid + 1;
113
+ else hi = mid;
114
+ }
115
+ let nearest = lo;
116
+ let best = Math.abs(transform.timeToX(bars[lo].time) - x);
117
+ for (const i of [lo - 1, lo + 1]) {
118
+ if (i < 0 || i >= bars.length) continue;
119
+ const d = Math.abs(transform.timeToX(bars[i].time) - x);
120
+ if (d < best) {
121
+ best = d;
122
+ nearest = i;
123
+ }
124
+ }
125
+ const first = bars[0].time;
126
+ const last = bars[bars.length - 1].time;
127
+ const halfCol = bars.length > 1 ? Math.abs(transform.timeToX(bars[1].time) - transform.timeToX(first)) / 2 : Infinity;
128
+ const edgeX = raw > last ? transform.timeToX(last) : raw < first ? transform.timeToX(first) : null;
129
+ if (edgeX !== null && Math.abs(x - edgeX) > halfCol) return floored;
130
+ return bars[nearest].time;
131
+ }
132
+
103
133
  // src/core/CanvasLayer.ts
104
134
  var CanvasLayer = class {
105
135
  canvas;
@@ -4792,10 +4822,7 @@ var Chart = class {
4792
4822
  onCrosshairMove: (x, y) => {
4793
4823
  if (!this._crosshairEnabled) return;
4794
4824
  if (this._magnetMode === "off") {
4795
- const tfSec = _tfToSeconds(this._interval);
4796
- const rawTime = this._transform.xToTime(x);
4797
- const flooredTime = Math.floor(rawTime / tfSec) * tfSec;
4798
- this._crosshair.update(x, y, flooredTime);
4825
+ this._crosshair.update(x, y, this._cursorBucketTime(x));
4799
4826
  } else {
4800
4827
  const snap = this.snapXToBar(x);
4801
4828
  const sy = this._magnetMode === "snap-xy" ? snap.closeY ?? y : y;
@@ -4836,7 +4863,8 @@ var Chart = class {
4836
4863
  },
4837
4864
  onDrawPointerMove: (x, y) => {
4838
4865
  this._drawingCursorPt = {
4839
- time: this._transform.xToTime(x),
4866
+ // Bucket time, not raw: the label and the stored anchor agree.
4867
+ time: this._cursorBucketTime(x),
4840
4868
  price: this._transform.yToPrice(y)
4841
4869
  };
4842
4870
  this._dirty = true;
@@ -5109,9 +5137,19 @@ var Chart = class {
5109
5137
  closeY: this._transform.priceToY(bar.close)
5110
5138
  };
5111
5139
  }
5112
- const tfSec = _tfToSeconds(this._interval);
5113
- const rawTime = this._transform.xToTime(x);
5114
- return { x, time: Math.floor(rawTime / tfSec) * tfSec };
5140
+ return { x, time: this._cursorBucketTime(x) };
5141
+ }
5142
+ /** Bucket time for a cursor x see core/cursorTime.ts for the rule. */
5143
+ _cursorBucketTime(x) {
5144
+ let bars = null;
5145
+ for (const s of this._series) {
5146
+ const data = s.data();
5147
+ if (data.length > 0) {
5148
+ bars = data;
5149
+ break;
5150
+ }
5151
+ }
5152
+ return cursorBucketTime(bars, this._transform, this._interval, x);
5115
5153
  }
5116
5154
  _computeViewport() {
5117
5155
  return {
@@ -5588,7 +5626,7 @@ var Chart = class {
5588
5626
  const MAGNET_PX = 15;
5589
5627
  const t = this._transform;
5590
5628
  const price = t.yToPrice(y);
5591
- const time = t.xToTime(x);
5629
+ const time = this._cursorBucketTime(x);
5592
5630
  if (this._magnetMode === "off") return { time, price };
5593
5631
  let bestBar = null;
5594
5632
  let bestDist = SNAP_PX;
@@ -6297,7 +6335,16 @@ var PixiCrosshairRenderer = class {
6297
6335
  interval = "1h";
6298
6336
  /** IANA timezone for the time label. Falls back to UTC. */
6299
6337
  timezone = "UTC";
6300
- update(x, y) {
6338
+ /**
6339
+ * The time the chart computed for this cursor position — nearest bar, else
6340
+ * floored to the timeframe grid. This renderer must never derive its own:
6341
+ * it once did (raw xToTime), and every pointer style's time label showed
6342
+ * interpolated minute noise (10:02 on an hourly chart) on any timeframe
6343
+ * wider than the interpolation error.
6344
+ */
6345
+ _snapTime = null;
6346
+ update(x, y, snapTime) {
6347
+ this._snapTime = snapTime ?? null;
6301
6348
  this._x = x;
6302
6349
  this._y = y;
6303
6350
  }
@@ -6339,7 +6386,7 @@ var PixiCrosshairRenderer = class {
6339
6386
  this._priceLabel.text = priceText;
6340
6387
  this._priceLabel.x = pw + 4;
6341
6388
  this._priceLabel.y = y - this._priceLabel.height / 2;
6342
- const time = transform.xToTime(x);
6389
+ const time = this._snapTime ?? transform.xToTime(x);
6343
6390
  const timeText = this._formatTime(time);
6344
6391
  const tlw = DAILY_INTERVALS.has(this.interval) ? 120 : 170;
6345
6392
  const tlh = tsh - 4;
@@ -8736,11 +8783,11 @@ var PixiChart = class {
8736
8783
  onCrosshairMove: (x, y) => {
8737
8784
  if (!this._crosshairEnabled) return;
8738
8785
  if (this._magnetMode === "off") {
8739
- this._crosshairRenderer.update(x, y);
8786
+ this._crosshairRenderer.update(x, y, this._cursorBucketTime(x));
8740
8787
  } else {
8741
8788
  const snap = this.snapXToBar(x);
8742
8789
  const sy = this._magnetMode === "snap-xy" ? snap.closeY ?? y : y;
8743
- this._crosshairRenderer.update(snap.x, sy);
8790
+ this._crosshairRenderer.update(snap.x, sy, snap.time);
8744
8791
  }
8745
8792
  const ah = this._interaction.axisHover;
8746
8793
  if (ah !== this._lastAxisHover) {
@@ -8786,7 +8833,9 @@ var PixiChart = class {
8786
8833
  },
8787
8834
  onDrawPointerMove: (x, y) => {
8788
8835
  this._drawingCursorPt = {
8789
- time: this._transform.xToTime(x),
8836
+ // Bucket time, not raw: what the crosshair label shows is what a
8837
+ // drawing placed here will store.
8838
+ time: this._cursorBucketTime(x),
8790
8839
  price: this._transform.yToPrice(y)
8791
8840
  };
8792
8841
  this._layers.dirty.mark(3 /* Drawing */);
@@ -9353,6 +9402,18 @@ var PixiChart = class {
9353
9402
  setNativeCursorHidden(hidden) {
9354
9403
  this._interaction.setHideCursor(hidden);
9355
9404
  }
9405
+ /** Bucket time for a cursor x — see core/cursorTime.ts for the rule. */
9406
+ _cursorBucketTime(x) {
9407
+ let bars = null;
9408
+ for (const s of this._series) {
9409
+ const data = s.data();
9410
+ if (data.length > 0) {
9411
+ bars = data;
9412
+ break;
9413
+ }
9414
+ }
9415
+ return cursorBucketTime(bars, this._transform, this._interval, x);
9416
+ }
9356
9417
  snapXToBar(x) {
9357
9418
  const SNAP_PX = 20;
9358
9419
  let bars = null;
@@ -9396,7 +9457,7 @@ var PixiChart = class {
9396
9457
  closeY: t.priceToY(bar.close)
9397
9458
  };
9398
9459
  }
9399
- return { x, time: t.xToTime(x) };
9460
+ return { x, time: this._cursorBucketTime(x) };
9400
9461
  }
9401
9462
  setIndicatorsVisible(v) {
9402
9463
  this._indicatorsVisible = v;
@@ -25554,7 +25615,7 @@ var demonstrationTool = {
25554
25615
  };
25555
25616
 
25556
25617
  // src/version.ts
25557
- var FORGECHARTS_VERSION = "1.5.69" ;
25618
+ var FORGECHARTS_VERSION = "1.5.70" ;
25558
25619
 
25559
25620
  // src/compatibility.ts
25560
25621
  var MIN_KIT_API = 1;