@forgecharts/sdk 1.5.22 → 1.5.24

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
@@ -7773,6 +7773,9 @@ function orderRoleLabel(role) {
7773
7773
  function isDraggableRole(role) {
7774
7774
  return role === "stop_loss" || role === "take_profit" || role === "limit" || role === "stop";
7775
7775
  }
7776
+ function isTerminal(status) {
7777
+ return status === "cancelled" || status === "rejected" || status === "expired" || status === "filled";
7778
+ }
7776
7779
  var LINE_H = 15;
7777
7780
  var LABEL_GAP = 6;
7778
7781
  var LABEL_PAD = 6;
@@ -8037,33 +8040,37 @@ var PixiTradingRenderer = class {
8037
8040
  labelIdx = this._drawLabel(String(pos.entryPrice), plotWidth + 4, y, labelIdx, labelStyle);
8038
8041
  this._positionHitZones.push({ id: pos.id, x: pillX, y: boxY, w: pillW, h: LINE_H });
8039
8042
  const linked = pos.linkedOrderIds ?? [];
8040
- const hasTp = linked.some((id) => id.endsWith("-tp"));
8041
- const hasSl = linked.some((id) => id.endsWith("-sl"));
8043
+ const hasTp = linked.some((id) => id.endsWith("-tp")) || orders.some((o) => (o.role === "take_profit" || o.role === "limit") && !isTerminal(o.status));
8044
+ const hasSl = linked.some((id) => id.endsWith("-sl")) || orders.some((o) => (o.role === "stop_loss" || o.role === "stop") && !isTerminal(o.status));
8042
8045
  const entrySide = pos.side === "long" ? "buy" : "sell";
8043
- if (!hasTp) {
8044
- const tpY = y - PILL_H / 2;
8045
- this._boxGfx.roundRect(PILL_TP_X, tpY, PILL_W, PILL_H, PILL_R).fill({ color: TP_PILL_COLOR, alpha: 0.85 });
8046
- labelIdx = this._drawLabel("TP", PILL_TP_X + PILL_W / 2, y, labelIdx, pillLabelStyle, true);
8046
+ let pillCursor = pillX - 4;
8047
+ if (!hasSl) {
8048
+ const slX = pillCursor - PILL_W;
8049
+ const slY = y - PILL_H / 2;
8050
+ this._boxGfx.roundRect(slX, slY, PILL_W, PILL_H, PILL_R).fill({ color: SL_PILL_COLOR, alpha: 0.85 });
8051
+ labelIdx = this._drawLabel("SL", slX + PILL_W / 2, y, labelIdx, pillLabelStyle, true);
8047
8052
  this._pillHitZones.push({
8048
- kind: "tp",
8053
+ kind: "sl",
8049
8054
  entryOrderId: pos.id,
8050
8055
  entrySide,
8051
- x: PILL_TP_X,
8052
- y: tpY,
8056
+ x: slX,
8057
+ y: slY,
8053
8058
  w: PILL_W,
8054
8059
  h: PILL_H
8055
8060
  });
8061
+ pillCursor = slX - 4;
8056
8062
  }
8057
- if (!hasSl) {
8058
- const slY = y - PILL_H / 2;
8059
- this._boxGfx.roundRect(PILL_SL_X, slY, PILL_W, PILL_H, PILL_R).fill({ color: SL_PILL_COLOR, alpha: 0.85 });
8060
- labelIdx = this._drawLabel("SL", PILL_SL_X + PILL_W / 2, y, labelIdx, pillLabelStyle, true);
8063
+ if (!hasTp) {
8064
+ const tpX = pillCursor - PILL_W;
8065
+ const tpY = y - PILL_H / 2;
8066
+ this._boxGfx.roundRect(tpX, tpY, PILL_W, PILL_H, PILL_R).fill({ color: TP_PILL_COLOR, alpha: 0.85 });
8067
+ labelIdx = this._drawLabel("TP", tpX + PILL_W / 2, y, labelIdx, pillLabelStyle, true);
8061
8068
  this._pillHitZones.push({
8062
- kind: "sl",
8069
+ kind: "tp",
8063
8070
  entryOrderId: pos.id,
8064
8071
  entrySide,
8065
- x: PILL_SL_X,
8066
- y: slY,
8072
+ x: tpX,
8073
+ y: tpY,
8067
8074
  w: PILL_W,
8068
8075
  h: PILL_H
8069
8076
  });
@@ -9356,30 +9363,40 @@ var PixiChart = class {
9356
9363
  setTradingOrders(orders) {
9357
9364
  this._tradingOrders = orders;
9358
9365
  this._layers.dirty.mark(4 /* TradingOverlay */);
9359
- const hasDraggable = orders.some(
9360
- (o) => (o.role === "stop_loss" || o.role === "take_profit") && o.status !== "cancelled" && o.status !== "filled"
9361
- );
9362
- if (hasDraggable) {
9363
- this._interaction.setOrderLineHitTest(
9364
- (x, y) => this._tradingRenderer.hitTestDraggableOrder(x, y)
9365
- );
9366
- } else {
9367
- this._interaction.setOrderLineHitTest(null);
9368
- }
9369
- const hasEntryWithoutBracket = orders.some(
9370
- (o) => o.role === "entry" && !o.groupId && o.status !== "cancelled" && o.status !== "filled" && o.status !== "rejected"
9371
- );
9372
- if (hasEntryWithoutBracket) {
9373
- this._interaction.setPillHitTest(
9374
- (x, y) => this._tradingRenderer.hitTestPill(x, y)
9375
- );
9376
- } else {
9377
- this._interaction.setPillHitTest(null);
9378
- }
9366
+ this._refreshTradingHitTests();
9379
9367
  }
9380
9368
  setTradingPositions(positions) {
9381
9369
  this._tradingPositions = positions;
9382
9370
  this._layers.dirty.mark(4 /* TradingOverlay */);
9371
+ this._refreshTradingHitTests();
9372
+ }
9373
+ /**
9374
+ * (Re)register the trading hit tests against current orders AND positions.
9375
+ *
9376
+ * Was inline in setTradingOrders and keyed on hardcoded roles, which left
9377
+ * both interactions half-wired:
9378
+ *
9379
+ * - the drag hit test required a 'stop_loss'/'take_profit' order, so
9380
+ * working limit and stop lines rendered a drag handle they could not
9381
+ * actually be grabbed by
9382
+ * - the pill hit test required an ORDER with role 'entry' and no groupId,
9383
+ * but the pills are drawn on POSITIONS, so they were never grabbable
9384
+ *
9385
+ * Both now derive from the same predicates the renderer draws with.
9386
+ */
9387
+ _refreshTradingHitTests() {
9388
+ const hasDraggable = this._tradingOrders.some(
9389
+ (o) => isDraggableRole(o.role) && o.status !== "cancelled" && o.status !== "filled"
9390
+ );
9391
+ this._interaction.setOrderLineHitTest(
9392
+ hasDraggable ? (x, y) => this._tradingRenderer.hitTestDraggableOrder(x, y) : null
9393
+ );
9394
+ const hasPillSource = this._tradingPositions.some((p) => p.status === "open") || this._tradingOrders.some(
9395
+ (o) => o.role === "entry" && !o.groupId && o.status !== "cancelled" && o.status !== "filled" && o.status !== "rejected"
9396
+ );
9397
+ this._interaction.setPillHitTest(
9398
+ hasPillSource ? (x, y) => this._tradingRenderer.hitTestPill(x, y) : null
9399
+ );
9383
9400
  }
9384
9401
  setContractSwitches(switches) {
9385
9402
  this._timeScale.contractSwitches = switches;