@pipsend/charts 1.2.1 → 1.2.2

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.
@@ -17076,6 +17076,20 @@ class DraggablePriceLine {
17076
17076
  this._private__setupInteractionHandlers();
17077
17077
  }
17078
17078
  }
17079
+ /**
17080
+ * Resolve the effective title: formatTitle(price) wins over the static title.
17081
+ */
17082
+ _private__resolveTitle() {
17083
+ if (this._private__options.formatTitle) {
17084
+ try {
17085
+ return this._private__options.formatTitle(this._private__options.price);
17086
+ }
17087
+ catch (error) {
17088
+ console.error('Error in formatTitle:', error);
17089
+ }
17090
+ }
17091
+ return this._private__options.title || '';
17092
+ }
17079
17093
  _private__createPriceLine() {
17080
17094
  this._private__originalColor = this._private__options.color;
17081
17095
  this._private__priceLine = this._private__series.createPriceLine({
@@ -17084,7 +17098,7 @@ class DraggablePriceLine {
17084
17098
  lineWidth: this._private__options.lineWidth,
17085
17099
  lineStyle: this._private__options.lineStyle,
17086
17100
  axisLabelVisible: this._private__options.axisLabelVisible,
17087
- title: this._private__options.title || '',
17101
+ title: this._private__resolveTitle(),
17088
17102
  });
17089
17103
  }
17090
17104
  _private__setupInteractionHandlers() {
@@ -17125,22 +17139,28 @@ class DraggablePriceLine {
17125
17139
  // Prevenir que el gráfico se mueva mientras arrastramos la línea
17126
17140
  e.preventDefault();
17127
17141
  e.stopPropagation();
17142
+ return;
17128
17143
  }
17129
- else {
17130
- // Solo mostrar hover si está en el área del gráfico
17131
- if (!this._private__isInChartArea(e)) {
17132
- this._private__setHoverState(false);
17133
- return;
17134
- }
17135
- const price = this._private__getPriceFromY(e.clientY);
17136
- if (this._private__isOnLine(e, price)) {
17137
- this._private__container.style.cursor = this._private__options.draggable ? 'ns-resize' : 'pointer';
17138
- this._private__setHoverState(true);
17139
- }
17140
- else {
17144
+ // Hover state — only mutate cursor for transitions involving THIS line.
17145
+ // Multiple lines can share the same chart element listener (one per line).
17146
+ // Blindly resetting the cursor here would clobber another line's drag/hover.
17147
+ if (!this._private__isInChartArea(e)) {
17148
+ if (this._private__isHovering) {
17141
17149
  this._private__container.style.cursor = 'default';
17142
17150
  this._private__setHoverState(false);
17143
17151
  }
17152
+ return;
17153
+ }
17154
+ const price = this._private__getPriceFromY(e.clientY);
17155
+ const onThisLine = this._private__isOnLine(e, price);
17156
+ if (onThisLine) {
17157
+ this._private__container.style.cursor = this._private__options.draggable ? 'ns-resize' : 'pointer';
17158
+ this._private__setHoverState(true);
17159
+ }
17160
+ else if (this._private__isHovering) {
17161
+ // Only revert when actually leaving — don't override another line's cursor.
17162
+ this._private__container.style.cursor = 'default';
17163
+ this._private__setHoverState(false);
17144
17164
  }
17145
17165
  };
17146
17166
  const handleMouseUp = (e) => {
@@ -17188,7 +17208,8 @@ class DraggablePriceLine {
17188
17208
  this._private__options.onDragEnd(this._private__options.price);
17189
17209
  }
17190
17210
  }
17191
- else {
17211
+ else if (this._private__isHovering) {
17212
+ this._private__container.style.cursor = 'default';
17192
17213
  this._private__setHoverState(false);
17193
17214
  }
17194
17215
  this._private__mouseDownOnLine = false;
@@ -17286,11 +17307,16 @@ class DraggablePriceLine {
17286
17307
  _private__updatePrice(newPrice) {
17287
17308
  this._private__options.price = newPrice;
17288
17309
  if (this._private__priceLine) {
17289
- this._private__priceLine.applyOptions({ price: newPrice });
17310
+ // Re-resolve title so formatTitle reflects the new price.
17311
+ this._private__priceLine.applyOptions({
17312
+ price: newPrice,
17313
+ title: this._private__resolveTitle(),
17314
+ });
17290
17315
  }
17291
17316
  }
17292
17317
  /**
17293
- * Update the price line options
17318
+ * Update the price line options. Any subset of options can be passed.
17319
+ * Title is recomputed from `formatTitle` if available, otherwise from `title`.
17294
17320
  */
17295
17321
  applyOptions(options) {
17296
17322
  this._private__options = { ...this._private__options, ...options };
@@ -17298,14 +17324,36 @@ class DraggablePriceLine {
17298
17324
  if (options.color) {
17299
17325
  this._private__originalColor = options.color;
17300
17326
  }
17301
- if (this._private__priceLine && options.price !== undefined) {
17302
- this._private__priceLine.applyOptions({
17303
- price: options.price,
17304
- color: options.color,
17305
- lineWidth: options.lineWidth,
17306
- lineStyle: options.lineStyle,
17307
- title: options.title,
17308
- });
17327
+ if (!this._private__priceLine)
17328
+ return;
17329
+ // Apply visual options. Any field not in `options` is left untouched on the
17330
+ // underlying price line, except `title` which we always re-resolve so that
17331
+ // formatTitle stays in sync with whatever changed.
17332
+ const patch = {
17333
+ title: this._private__resolveTitle(),
17334
+ };
17335
+ if (options.price !== undefined)
17336
+ patch.price = options.price;
17337
+ if (options.color !== undefined)
17338
+ patch.color = options.color;
17339
+ if (options.lineWidth !== undefined)
17340
+ patch.lineWidth = options.lineWidth;
17341
+ if (options.lineStyle !== undefined)
17342
+ patch.lineStyle = options.lineStyle;
17343
+ this._private__priceLine.applyOptions(patch);
17344
+ }
17345
+ /**
17346
+ * Set the title directly. Use this for updates that don't depend on the
17347
+ * line's price (e.g. live PnL on a fixed entry line). Bypasses formatTitle.
17348
+ */
17349
+ setTitle(text) {
17350
+ this._private__options.title = text;
17351
+ // If a formatter is set we still write the static title to options, but
17352
+ // the visual title comes from the formatter on the next price update.
17353
+ // To make this call effective immediately, we override the rendered title
17354
+ // here unconditionally.
17355
+ if (this._private__priceLine) {
17356
+ this._private__priceLine.applyOptions({ title: text });
17309
17357
  }
17310
17358
  }
17311
17359
  /**
@@ -17315,7 +17363,7 @@ class DraggablePriceLine {
17315
17363
  return this._private__options.price;
17316
17364
  }
17317
17365
  /**
17318
- * Set price programmatically
17366
+ * Set price programmatically. Triggers formatTitle if configured.
17319
17367
  */
17320
17368
  setPrice(price) {
17321
17369
  this._private__updatePrice(price);
@@ -17438,6 +17486,7 @@ function createTradingLine(series, chart, options) {
17438
17486
  onDragMove: options.onDragMove,
17439
17487
  onDragEnd: options.onDragEnd,
17440
17488
  onClick: options.onClick,
17489
+ formatTitle: options.formatTitle,
17441
17490
  };
17442
17491
  return new DraggablePriceLine(chart, series, lineOptions);
17443
17492
  }