react-klinecharts-ui 0.5.0 → 1.0.0

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.
@@ -1,4 +1,4 @@
1
- import { registerFigure, utils, registerOverlay, registerIndicator } from 'react-klinecharts';
1
+ import { registerFigure, utils, registerOverlay, registerIndicator } from 'klinecharts';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __export = (target, all) => {
@@ -992,7 +992,10 @@ var parallelChannel_default = parallelChannel;
992
992
  // src/overlays/longPosition.ts
993
993
  var longPosition = {
994
994
  name: "longPosition",
995
- totalStep: 3,
995
+ // totalStep 4 → the user places 3 points interactively (entry, target, stop).
996
+ // With the previous value of 3, only 2 points were captured and the stop was
997
+ // always a hardcoded 40px offset, so R/R was meaningless.
998
+ totalStep: 4,
996
999
  needDefaultPointFigure: true,
997
1000
  needDefaultXAxisFigure: true,
998
1001
  needDefaultYAxisFigure: true,
@@ -1101,7 +1104,10 @@ var longPosition_default = longPosition;
1101
1104
  // src/overlays/shortPosition.ts
1102
1105
  var shortPosition = {
1103
1106
  name: "shortPosition",
1104
- totalStep: 3,
1107
+ // totalStep 4 → the user places 3 points interactively (entry, target, stop).
1108
+ // With the previous value of 3, only 2 points were captured and the stop was
1109
+ // always a hardcoded 40px offset, so R/R was meaningless.
1110
+ totalStep: 4,
1105
1111
  needDefaultPointFigure: true,
1106
1112
  needDefaultXAxisFigure: true,
1107
1113
  needDefaultYAxisFigure: true,
@@ -1230,8 +1236,10 @@ var measure = {
1230
1236
  const endPoint = overlay.points[1];
1231
1237
  const startCoord = coordinates[0];
1232
1238
  const endCoord = coordinates[1];
1233
- const diff = endPoint.value - startPoint.value;
1234
- const percent = (diff / startPoint.value * 100).toFixed(2);
1239
+ const startValue = startPoint.value ?? 0;
1240
+ const endValue = endPoint.value ?? 0;
1241
+ const diff = endValue - startValue;
1242
+ const percent = startValue !== 0 ? (diff / startValue * 100).toFixed(2) : "0.00";
1235
1243
  const bars = Math.abs(
1236
1244
  (endPoint.dataIndex ?? 0) - (startPoint.dataIndex ?? 0)
1237
1245
  );
@@ -1284,7 +1292,7 @@ var measure = {
1284
1292
  {
1285
1293
  type: "line",
1286
1294
  attrs: { coordinates: [startCoord, endCoord] },
1287
- styles: { color: strokeColor, style: "dash" }
1295
+ styles: { color: strokeColor, style: "dashed" }
1288
1296
  },
1289
1297
  ...textFigures
1290
1298
  ];
@@ -1860,8 +1868,9 @@ var ichimoku = {
1860
1868
  if (index >= kijunPeriod - 1) {
1861
1869
  item.kijun = highLowAvg(dataList, index - kijunPeriod + 1, index);
1862
1870
  }
1863
- if (index + offset < dataList.length) {
1864
- item.chikou = dataList[index + offset].close;
1871
+ const chikouIndex = index - offset;
1872
+ if (chikouIndex >= 0) {
1873
+ item.chikou = dataList[chikouIndex].close;
1865
1874
  }
1866
1875
  const prevIndex = index - offset;
1867
1876
  if (prevIndex >= 0) {
@@ -2001,7 +2010,7 @@ var pivotPoints = {
2001
2010
  let dayLow = Infinity;
2002
2011
  let dayClose = 0;
2003
2012
  return dataList.map((kLineData) => {
2004
- const date = new Date(kLineData.timestamp).toLocaleDateString();
2013
+ const date = new Date(kLineData.timestamp).toISOString().slice(0, 10);
2005
2014
  if (date !== lastDate) {
2006
2015
  if (lastDate !== "") {
2007
2016
  lastP = (dayHigh + dayLow + dayClose) / 3;
@@ -2055,11 +2064,20 @@ var rsiTv = {
2055
2064
  const maPeriod = indicator.calcParams[1];
2056
2065
  const closes = dataList.map((d) => d.close);
2057
2066
  const rsiValues = TA_default.rsi(closes, rsiPeriod);
2058
- const nonNullRsi = rsiValues.map((v) => v ?? 0);
2059
- const maValues = TA_default.sma(nonNullRsi, maPeriod);
2067
+ const rsiMa = new Array(rsiValues.length).fill(null);
2068
+ for (let i = 0; i < rsiValues.length; i++) {
2069
+ if (rsiValues[i] === null) continue;
2070
+ const valid = [];
2071
+ for (let j = i; j >= 0 && valid.length < maPeriod; j--) {
2072
+ if (rsiValues[j] !== null) valid.push(rsiValues[j]);
2073
+ }
2074
+ if (valid.length === maPeriod) {
2075
+ rsiMa[i] = valid.reduce((a, b) => a + b, 0) / maPeriod;
2076
+ }
2077
+ }
2060
2078
  return dataList.map((_, i) => {
2061
2079
  const rsi = rsiValues[i];
2062
- const rsi_ma = rsi !== null && maValues[i] !== null ? maValues[i] : null;
2080
+ const rsi_ma = rsi !== null ? rsiMa[i] : null;
2063
2081
  return { rsi, rsi_ma };
2064
2082
  });
2065
2083
  },
@@ -2281,7 +2299,7 @@ var vwap = {
2281
2299
  let cumulativePriceVolume = 0;
2282
2300
  let lastDate = "";
2283
2301
  return dataList.map((kLineData) => {
2284
- const date = new Date(kLineData.timestamp).toLocaleDateString();
2302
+ const date = new Date(kLineData.timestamp).toISOString().slice(0, 10);
2285
2303
  if (date !== lastDate) {
2286
2304
  cumulativeVolume = 0;
2287
2305
  cumulativePriceVolume = 0;
@@ -2414,7 +2432,7 @@ var depthOverlay = {
2414
2432
  const maxBarPx = bounding.width * maxBarFraction;
2415
2433
  const askColor = d.askColor ?? "rgba(239,83,80,0.25)";
2416
2434
  const bidColor = d.bidColor ?? "rgba(38,166,154,0.25)";
2417
- const maxQty = d.maxQty || 1;
2435
+ const maxQty = d.maxQty ?? 1;
2418
2436
  const figures = [];
2419
2437
  for (const row of d.rows) {
2420
2438
  const y = yAxis.convertToPixel(row.price);
@@ -2441,17 +2459,131 @@ var depthOverlay = {
2441
2459
  };
2442
2460
  var depthOverlay_default = depthOverlay;
2443
2461
 
2462
+ // src/extensions/overlays/alertLine.ts
2463
+ var DEFAULT_FONT_FAMILY2 = "Helvetica Neue, Arial, sans-serif";
2464
+ var DEFAULT_COLOR = "#ff9800";
2465
+ var BELL_MARK = "\u{1F514}";
2466
+ var alertLine = {
2467
+ name: "alertLine",
2468
+ totalStep: 2,
2469
+ needDefaultPointFigure: false,
2470
+ needDefaultXAxisFigure: false,
2471
+ needDefaultYAxisFigure: false,
2472
+ createYAxisFigures: ({ chart, overlay, coordinates }) => {
2473
+ if (coordinates.length < 1) return [];
2474
+ const y = coordinates[0].y;
2475
+ const price = overlay.points[0]?.value;
2476
+ if (price == null) return [];
2477
+ const d = overlay.extendData ?? {};
2478
+ const color = d.color ?? DEFAULT_COLOR;
2479
+ const m = d.mark;
2480
+ const precision = chart.getSymbol()?.pricePrecision ?? 2;
2481
+ return [
2482
+ {
2483
+ type: "text",
2484
+ attrs: {
2485
+ x: 0,
2486
+ y,
2487
+ text: price.toFixed(precision),
2488
+ align: "left",
2489
+ baseline: "middle"
2490
+ },
2491
+ styles: {
2492
+ color: m?.color ?? "#ffffff",
2493
+ size: m?.font?.size ?? 11,
2494
+ family: m?.font?.family ?? DEFAULT_FONT_FAMILY2,
2495
+ weight: m?.font?.weight ?? "bold",
2496
+ paddingLeft: m?.padding?.x ?? 4,
2497
+ paddingRight: m?.padding?.x ?? 4,
2498
+ paddingTop: m?.padding?.y ?? 4,
2499
+ paddingBottom: m?.padding?.y ?? 4,
2500
+ backgroundColor: m?.bg ?? color,
2501
+ borderRadius: m?.borderRadius ?? 2
2502
+ }
2503
+ }
2504
+ ];
2505
+ },
2506
+ createPointFigures: ({ chart, coordinates, bounding, overlay }) => {
2507
+ if (coordinates.length < 1) return [];
2508
+ const y = coordinates[0].y;
2509
+ const d = overlay.extendData ?? {};
2510
+ const color = d.color ?? DEFAULT_COLOR;
2511
+ const ln = d.line;
2512
+ const figures = [
2513
+ {
2514
+ type: "line",
2515
+ attrs: {
2516
+ coordinates: [
2517
+ { x: 0, y },
2518
+ { x: bounding.width, y }
2519
+ ]
2520
+ },
2521
+ styles: {
2522
+ style: ln?.style ?? "dashed",
2523
+ color,
2524
+ size: ln?.width ?? 1,
2525
+ dashedValue: ln?.dashedValue ?? [4, 2]
2526
+ }
2527
+ }
2528
+ ];
2529
+ const price = overlay.points[0]?.value;
2530
+ const precision = chart.getSymbol()?.pricePrecision ?? 2;
2531
+ const baseText = d.text ?? (price != null ? price.toFixed(precision) : "");
2532
+ const showBell = d.showBell ?? true;
2533
+ const text = baseText ? showBell ? `${BELL_MARK} ${baseText}` : baseText : showBell ? BELL_MARK : "";
2534
+ if (text) {
2535
+ const lb = d.label;
2536
+ figures.push({
2537
+ type: "text",
2538
+ ignoreEvent: true,
2539
+ attrs: {
2540
+ x: lb?.offset?.x ?? 8,
2541
+ y: y - (lb?.offset?.y ?? 3),
2542
+ text,
2543
+ align: "left",
2544
+ baseline: "bottom"
2545
+ },
2546
+ styles: {
2547
+ color: lb?.color ?? color,
2548
+ size: lb?.font?.size ?? 11,
2549
+ family: lb?.font?.family ?? DEFAULT_FONT_FAMILY2,
2550
+ weight: lb?.font?.weight ?? "normal",
2551
+ paddingLeft: lb?.padding?.x ?? 0,
2552
+ paddingRight: lb?.padding?.x ?? 0,
2553
+ paddingTop: lb?.padding?.y ?? 0,
2554
+ paddingBottom: lb?.padding?.y ?? 0,
2555
+ backgroundColor: lb?.bg ?? "transparent",
2556
+ borderRadius: lb?.borderRadius ?? 0
2557
+ }
2558
+ });
2559
+ }
2560
+ return figures;
2561
+ },
2562
+ performEventPressedMove: ({ points, performPoint }) => {
2563
+ points[0].value = performPoint.value;
2564
+ }
2565
+ };
2566
+ var alertLine_default = alertLine;
2567
+
2444
2568
  // src/extensions/index.ts
2445
2569
  var overlays = Object.values(overlays_exports);
2570
+ var featureOverlays = [orderLine_default, depthOverlay_default, alertLine_default];
2446
2571
  var indicators = Object.values(indicators_exports);
2447
2572
  var registered = false;
2448
2573
  function registerExtensions() {
2449
2574
  if (registered) return;
2450
2575
  overlays.forEach((overlay) => registerOverlay(overlay));
2576
+ featureOverlays.forEach((overlay) => registerOverlay(overlay));
2451
2577
  indicators.forEach((indicator) => registerIndicator(indicator));
2452
2578
  registered = true;
2453
2579
  }
2580
+ var alertLineRegistered = false;
2581
+ function ensureAlertLineRegistered() {
2582
+ if (alertLineRegistered) return;
2583
+ registerOverlay(alertLine_default);
2584
+ alertLineRegistered = true;
2585
+ }
2454
2586
 
2455
- export { TA_default, abcd_default, anyWaves_default, arrow_default, bollTv_default, brush_default, cci_default, circle_default, depthOverlay_default, eightWaves_default, elliottWave_default, fibRetracement_default, fibonacciCircle_default, fibonacciExtension_default, fibonacciSegment_default, fibonacciSpeedResistanceFan_default, fibonacciSpiral_default, fiveWaves_default, gannBox_default, gannFan_default, hma_default, ichimoku_default, indicators, longPosition_default, maRibbon_default, macdTv_default, measure_default, orderLine_default, overlays, parallelChannel_default, parallelogram_default, pivotPoints_default, ray_default, rect_default, registerExtensions, rsiTv_default, shortPosition_default, stochastic_default, superTrend_default, threeWaves_default, triangle_default, vwap_default, xabcd_default };
2456
- //# sourceMappingURL=chunk-DTBNTO4M.js.map
2457
- //# sourceMappingURL=chunk-DTBNTO4M.js.map
2587
+ export { TA_default, abcd_default, alertLine_default, anyWaves_default, arrow_default, bollTv_default, brush_default, cci_default, circle_default, depthOverlay_default, eightWaves_default, elliottWave_default, ensureAlertLineRegistered, featureOverlays, fibRetracement_default, fibonacciCircle_default, fibonacciExtension_default, fibonacciSegment_default, fibonacciSpeedResistanceFan_default, fibonacciSpiral_default, fiveWaves_default, gannBox_default, gannFan_default, hma_default, ichimoku_default, indicators, longPosition_default, maRibbon_default, macdTv_default, measure_default, orderLine_default, overlays, parallelChannel_default, parallelogram_default, pivotPoints_default, ray_default, rect_default, registerExtensions, rsiTv_default, shortPosition_default, stochastic_default, superTrend_default, threeWaves_default, triangle_default, vwap_default, xabcd_default };
2588
+ //# sourceMappingURL=chunk-JD4NBJ5F.js.map
2589
+ //# sourceMappingURL=chunk-JD4NBJ5F.js.map