@pipsend/charts 2.2.1 → 2.3.1

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/typings.d.ts CHANGED
@@ -378,6 +378,8 @@ export declare class DrawingToolsManager {
378
378
  private _pointerDownHandler;
379
379
  private _pointerUpHandler;
380
380
  private _pointerCancelHandler;
381
+ private _lostCaptureHandler;
382
+ private _windowPointerUpHandler;
381
383
  private _pointerId;
382
384
  /** A press that grabbed a tool already selected it; its click must not undo that. */
383
385
  private _gestureHandled;
@@ -529,6 +531,8 @@ export declare class DrawingToolsManager {
529
531
  private _findToolByExternalId;
530
532
  private _handlePointerDown;
531
533
  private _handlePointerUp;
534
+ /** Ends the drag when capture is lost without a pointerup ever arriving. */
535
+ private _handleLostPointerCapture;
532
536
  /**
533
537
  * Pane element of a tool's series. The engine asserts the series has a pane,
534
538
  * so the lookup is guarded.
@@ -1111,6 +1115,97 @@ export declare class PositionCalculator {
1111
1115
  */
1112
1116
  getPipConfig(): PipConfig;
1113
1117
  }
1118
+ /**
1119
+ * A group of trading levels — entry, take profit and stop loss — drawn as one
1120
+ * unit: a line per level, a label carrying size and P&L, and a connector that
1121
+ * ties the three together.
1122
+ *
1123
+ * Input is not handled here. Every trading line on a chart shares a single
1124
+ * TradingLineController, which is what guarantees that one gesture moves one
1125
+ * level, and that a position line and a plain draggable price line on the same
1126
+ * chart do not fight over the pointer.
1127
+ */
1128
+ export declare class PositionLine implements ISeriesPrimitive, ControllableLine {
1129
+ private readonly _chart;
1130
+ private readonly _series;
1131
+ private readonly _id;
1132
+ private readonly _paneView;
1133
+ private readonly _paneViews;
1134
+ private readonly _axisViews;
1135
+ private readonly _colorParser;
1136
+ private readonly _labelLayout;
1137
+ private _options;
1138
+ private _theme;
1139
+ private _requestUpdate?;
1140
+ private _attached;
1141
+ private _hoveredLevel;
1142
+ private _hoveredPart;
1143
+ private _dragLevel;
1144
+ private _priceBeforeDrag;
1145
+ constructor(chart: IChartApi, series: ISeriesApi<SeriesType>, options: PositionLineOptions);
1146
+ attached(param: SeriesAttachedParameter): void;
1147
+ detached(): void;
1148
+ paneViews(): readonly IPrimitivePaneView[];
1149
+ priceAxisViews(): readonly ISeriesPrimitiveAxisView[];
1150
+ updateAllViews(): void;
1151
+ hitTest(x: number, y: number): PrimitiveHoveredItem | null;
1152
+ id(): string;
1153
+ paneIndex(): number;
1154
+ setHoveredPart(part: string | null): void;
1155
+ setHovered(hovered: boolean): void;
1156
+ isDraggable(): boolean;
1157
+ isClickable(): boolean;
1158
+ priceAt(paneY: number): number | null;
1159
+ /**
1160
+ * Where the level being dragged actually sits. The controller measures the
1161
+ * pointer against it so the level moves by what the pointer moved, instead
1162
+ * of jumping to sit under it — which matters most when the label has been
1163
+ * fanned away from its own line.
1164
+ */
1165
+ dragAnchorY(): number | null;
1166
+ beginDrag(): void;
1167
+ dragTo(price: number): void;
1168
+ commitDrag(): void;
1169
+ cancelDrag(): void;
1170
+ click(): void;
1171
+ /**
1172
+ * Updates the group. Any subset of options can be passed; the levels given
1173
+ * are merged into the current ones, and a level set to `undefined` is
1174
+ * removed.
1175
+ */
1176
+ applyOptions(options: PositionLineUpdate): void;
1177
+ /**
1178
+ * Moves one level to a new price, recomputing its text when the level has a
1179
+ * `formatText`.
1180
+ *
1181
+ * Ignored for a level the user is currently dragging — the gesture owns the
1182
+ * price until it reports back through
1183
+ * {@link PositionLineOptions.onDragEnd} or
1184
+ * {@link PositionLineOptions.onDragCancel}.
1185
+ */
1186
+ setPrice(level: PositionLineLevel, price: number): void;
1187
+ /**
1188
+ * Replaces one level's label text. Use this for text that changes on its own
1189
+ * — a ticking P&L on a fixed entry — rather than with the price.
1190
+ */
1191
+ setText(level: PositionLineLevel, text: string): void;
1192
+ /**
1193
+ * The current price of each level that is present.
1194
+ */
1195
+ prices(): Partial<Record<PositionLineLevel, number>>;
1196
+ options(): PositionLineOptions;
1197
+ /**
1198
+ * Removes the group from the chart and releases its share of the input
1199
+ * controller.
1200
+ */
1201
+ remove(): void;
1202
+ requestUpdate(): void;
1203
+ /** Reads back the label the price axis should draw for a level. */
1204
+ private _axisLabel;
1205
+ private _levelOptions;
1206
+ private _applyPrice;
1207
+ private _buildRendererData;
1208
+ }
1114
1209
  /**
1115
1210
  * Gestor de marcadores de posiciones de trading
1116
1211
  */
@@ -2272,6 +2367,26 @@ export declare function createOptionsChart(container: string | HTMLElement, opti
2272
2367
  export declare function createParallelChannelTool(context: DrawingContext, options: ParallelChannelToolOptions): ParallelChannelTool;
2273
2368
  export declare function createPitchforkTool(context: DrawingContext, options: PitchforkToolOptions): PitchforkTool;
2274
2369
  export declare function createPolygonTool(context: DrawingContext, options: PolygonToolOptions): PolygonTool;
2370
+ /**
2371
+ * Creates a position line group: entry, take profit and stop loss drawn as one
2372
+ * interactive unit.
2373
+ *
2374
+ * @param series - The series the levels are priced against.
2375
+ * @param chart - The chart the series belongs to.
2376
+ * @param options - The levels and their style.
2377
+ *
2378
+ * @example
2379
+ * ```js
2380
+ * const position = createPositionLine(candleSeries, chart, {
2381
+ * entry: { price: 4306.79, badge: '1', formatText: () => '+ 2.32 USD' },
2382
+ * takeProfit: { price: 4349.58, badge: '1', text: '+ 42.79 USD' },
2383
+ * stopLoss: { price: 4266.06, badge: '1', text: '- 40.73 USD' },
2384
+ * onClose: (level) => console.log('close', level),
2385
+ * onDragEnd: (level, price) => console.log(level, 'moved to', price),
2386
+ * });
2387
+ * ```
2388
+ */
2389
+ export declare function createPositionLine(series: ISeriesApi<SeriesType>, chart: IChartApi, options: PositionLineOptions): PositionLine;
2275
2390
  /**
2276
2391
  * Crea un gestor de marcadores de posiciones de trading
2277
2392
  *
@@ -3247,6 +3362,18 @@ export interface ControllableLine {
3247
3362
  isDraggable(): boolean;
3248
3363
  isClickable(): boolean;
3249
3364
  setHovered(hovered: boolean): void;
3365
+ /**
3366
+ * Optional. A line whose hit test names sub-parts — a label, a close button —
3367
+ * is told which one the pointer is over, so `isDraggable`, `isClickable` and
3368
+ * `click` can answer for that part rather than for the line as a whole.
3369
+ */
3370
+ setHoveredPart?(part: string | null): void;
3371
+ /**
3372
+ * Optional. Where the thing being dragged currently sits, in pane
3373
+ * coordinates. When a line reports it, the drag keeps the distance between
3374
+ * the pointer and that point instead of snapping the line under the cursor.
3375
+ */
3376
+ dragAnchorY?(): number | null;
3250
3377
  priceAt(paneY: number): number | null;
3251
3378
  beginDrag(): void;
3252
3379
  dragTo(price: number): void;
@@ -6034,6 +6161,189 @@ export interface PolygonVertex {
6034
6161
  time: Time;
6035
6162
  price: number;
6036
6163
  }
6164
+ /**
6165
+ * Configuration for one level (entry, take profit or stop loss) of a position.
6166
+ */
6167
+ export interface PositionLineLevelOptions {
6168
+ /**
6169
+ * The price the level sits at.
6170
+ */
6171
+ price: number;
6172
+ /**
6173
+ * The text inside the label, for example `+ 42.79 USD`.
6174
+ */
6175
+ text?: string;
6176
+ /**
6177
+ * The text of the badge on the left of the label, for example the position
6178
+ * size. Hidden when empty.
6179
+ */
6180
+ badge?: string;
6181
+ /**
6182
+ * Fills the badge with {@link PositionLineLevelOptions.color} instead of
6183
+ * drawing it outlined.
6184
+ *
6185
+ * @defaultValue `true` for the entry, `false` otherwise
6186
+ */
6187
+ badgeFilled?: boolean;
6188
+ /**
6189
+ * The colour of the line, the label's border and its text.
6190
+ */
6191
+ color?: string;
6192
+ /**
6193
+ * @defaultValue `1`
6194
+ */
6195
+ lineWidth?: LineWidth;
6196
+ /**
6197
+ * @defaultValue `LineStyle.Solid` for the entry, `LineStyle.Dashed` otherwise
6198
+ */
6199
+ lineStyle?: LineStyle;
6200
+ /**
6201
+ * Lets the user drag the level to a new price.
6202
+ *
6203
+ * @defaultValue `true`
6204
+ */
6205
+ draggable?: boolean;
6206
+ /**
6207
+ * Shows the close button on the right of the label.
6208
+ *
6209
+ * @defaultValue `true`
6210
+ */
6211
+ closable?: boolean;
6212
+ /**
6213
+ * Shows the price label on the price axis.
6214
+ *
6215
+ * @defaultValue `true`
6216
+ */
6217
+ axisLabelVisible?: boolean;
6218
+ /**
6219
+ * Computes {@link PositionLineLevelOptions.text} from the level's current
6220
+ * price. Called on every price change, which is what keeps a live P&L in
6221
+ * step with a drag.
6222
+ */
6223
+ formatText?: (price: number) => string;
6224
+ }
6225
+ /**
6226
+ * Configuration for a position line group.
6227
+ */
6228
+ export interface PositionLineOptions {
6229
+ /**
6230
+ * The entry level. Always drawn.
6231
+ */
6232
+ entry: PositionLineLevelOptions;
6233
+ /**
6234
+ * The take profit level. Omit for a position without one.
6235
+ */
6236
+ takeProfit?: PositionLineLevelOptions;
6237
+ /**
6238
+ * The stop loss level. Omit for a position without one.
6239
+ */
6240
+ stopLoss?: PositionLineLevelOptions;
6241
+ /**
6242
+ * @defaultValue `true`
6243
+ */
6244
+ visible?: boolean;
6245
+ /**
6246
+ * Draws the vertical line joining the levels, with a handle on each of them.
6247
+ *
6248
+ * @defaultValue `true`
6249
+ */
6250
+ connectorVisible?: boolean;
6251
+ /**
6252
+ * Distance in pixels between the right edge of the pane and the connector.
6253
+ *
6254
+ * @defaultValue `56`
6255
+ */
6256
+ rightOffset?: number;
6257
+ /**
6258
+ * Overrides for the shared visual style.
6259
+ */
6260
+ theme?: Partial<PositionLineTheme>;
6261
+ /**
6262
+ * Fires when the user starts dragging a level.
6263
+ */
6264
+ onDragStart?: (level: PositionLineLevel, price: number) => void;
6265
+ /**
6266
+ * Fires continuously while a level is being dragged.
6267
+ */
6268
+ onDragMove?: (level: PositionLineLevel, price: number) => void;
6269
+ /**
6270
+ * Fires once the drag is released. A drag that was cancelled does not report.
6271
+ */
6272
+ onDragEnd?: (level: PositionLineLevel, price: number) => void;
6273
+ /**
6274
+ * Fires when a drag ends without committing — the pointer left the chart, or
6275
+ * Escape was pressed. Together with {@link PositionLineOptions.onDragEnd} it
6276
+ * guarantees every gesture that started is reported as finished, which is
6277
+ * what callers need to pause work while a level is under the cursor.
6278
+ */
6279
+ onDragCancel?: (level: PositionLineLevel, price: number) => void;
6280
+ /**
6281
+ * Fires when the close button of a level is clicked.
6282
+ */
6283
+ onClose?: (level: PositionLineLevel) => void;
6284
+ /**
6285
+ * Fires on a click on a level's label or line that did not drag.
6286
+ */
6287
+ onClick?: (level: PositionLineLevel, price: number) => void;
6288
+ }
6289
+ /**
6290
+ * Visual style shared by every level of a position line group.
6291
+ */
6292
+ export interface PositionLineTheme {
6293
+ /**
6294
+ * The label's fill. Defaults to the chart's own background, so the label
6295
+ * stays readable on light and dark themes alike.
6296
+ */
6297
+ background?: string;
6298
+ /**
6299
+ * The label's text colour. Defaults to the level's colour.
6300
+ */
6301
+ textColor?: string;
6302
+ /**
6303
+ * The text colour used inside a filled badge.
6304
+ */
6305
+ badgeTextColor: string;
6306
+ /**
6307
+ * Corner radius of the label, in pixels.
6308
+ */
6309
+ borderRadius: number;
6310
+ /**
6311
+ * Border width of the label, in pixels.
6312
+ */
6313
+ borderWidth: number;
6314
+ /**
6315
+ * Horizontal padding inside each cell of the label, in pixels.
6316
+ */
6317
+ paddingX: number;
6318
+ /**
6319
+ * Vertical padding inside the label, in pixels.
6320
+ */
6321
+ paddingY: number;
6322
+ /**
6323
+ * Font size of the label. Defaults to the chart's layout font size.
6324
+ */
6325
+ fontSize?: number;
6326
+ /**
6327
+ * Font family of the label. Defaults to the chart's layout font family.
6328
+ */
6329
+ fontFamily?: string;
6330
+ /**
6331
+ * Opacity applied to the label's fill, between 0 and 1. The default is
6332
+ * opaque: the label carries a price and a P&L, and candles showing through
6333
+ * it make those harder to read.
6334
+ */
6335
+ backgroundOpacity: number;
6336
+ }
6337
+ /**
6338
+ * The shape {@link PositionLine.applyOptions} takes: every field optional, and
6339
+ * a level given as a patch rather than as a whole. A level set to `undefined`
6340
+ * is removed; a level that is not mentioned is left alone.
6341
+ */
6342
+ export interface PositionLineUpdate extends Partial<Omit<PositionLineOptions, "entry" | "takeProfit" | "stopLoss">> {
6343
+ entry?: Partial<PositionLineLevelOptions>;
6344
+ takeProfit?: Partial<PositionLineLevelOptions>;
6345
+ stopLoss?: Partial<PositionLineLevelOptions>;
6346
+ }
6037
6347
  /**
6038
6348
  * Opciones para el gestor de posiciones
6039
6349
  */
@@ -6625,6 +6935,31 @@ export interface SeriesMarkerBase<TimeType> {
6625
6935
  * Required when using {@link SeriesMarkerPricePosition} position type.
6626
6936
  */
6627
6937
  price?: number;
6938
+ /**
6939
+ * The colour of the marker's text.
6940
+ *
6941
+ * For the `tag` shape the text sits on top of {@link SeriesMarkerBase.color},
6942
+ * so this defaults to white. Other shapes draw the text in `color`.
6943
+ */
6944
+ textColor?: string;
6945
+ /**
6946
+ * The colour of the marker's outline. Only used by the `tag` shape.
6947
+ *
6948
+ * @defaultValue no outline
6949
+ */
6950
+ borderColor?: string;
6951
+ /**
6952
+ * The width of the marker's outline in pixels. Only used by the `tag` shape.
6953
+ *
6954
+ * @defaultValue `1` when {@link SeriesMarkerBase.borderColor} is set
6955
+ */
6956
+ borderWidth?: number;
6957
+ /**
6958
+ * The corner radius of the `tag` shape's bubble in pixels.
6959
+ *
6960
+ * @defaultValue `6`
6961
+ */
6962
+ borderRadius?: number;
6628
6963
  }
6629
6964
  export interface SeriesMarkerPrice<TimeType> extends SeriesMarkerBase<TimeType> {
6630
6965
  /**
@@ -7707,6 +8042,14 @@ export type OverlayPriceScaleOptions = Omit<PriceScaleOptions, "visible" | "auto
7707
8042
  */
7708
8043
  export type PercentageFormatterFn = (percentageValue: number) => string;
7709
8044
  export type PitchforkPart = "pivot" | "upper" | "lower" | "body";
8045
+ /**
8046
+ * The three levels a position line group can show.
8047
+ */
8048
+ export type PositionLineLevel = "entry" | "takeProfit" | "stopLoss";
8049
+ /**
8050
+ * The parts of a level that respond to the pointer.
8051
+ */
8052
+ export type PositionLinePart = "line" | "body" | "close";
7710
8053
  /**
7711
8054
  * Tipo de posición de trading
7712
8055
  */
@@ -7775,8 +8118,12 @@ export type SeriesMarkerPosition = SeriesMarkerBarPosition | SeriesMarkerPricePo
7775
8118
  export type SeriesMarkerPricePosition = "atPriceTop" | "atPriceBottom" | "atPriceMiddle";
7776
8119
  /**
7777
8120
  * Represents the shape of a series marker.
8121
+ *
8122
+ * `tag` draws the text inside a rounded bubble with a pointer aimed at the
8123
+ * anchor, which is what trading platforms use for BUY/SELL callouts. The other
8124
+ * shapes draw the text next to the shape instead.
7778
8125
  */
7779
- export type SeriesMarkerShape = "circle" | "square" | "arrowUp" | "arrowDown";
8126
+ export type SeriesMarkerShape = "circle" | "square" | "arrowUp" | "arrowDown" | "tag";
7780
8127
  /**
7781
8128
  * The visual stacking order for the markers within the chart.
7782
8129
  *
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.2.1",
2
+ "version": "2.3.1",
3
3
  "name": "@pipsend/charts",
4
4
  "author": "Pipsend",
5
5
  "license": "SEE LICENSE IN LICENSE",