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,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var reactKlinecharts = require('react-klinecharts');
3
+ var klinecharts = require('klinecharts');
4
4
 
5
5
  var __defProp = Object.defineProperty;
6
6
  var __export = (target, all) => {
@@ -55,7 +55,7 @@ function getRayLine(coordinates, bounding) {
55
55
  } else if (coordinates[0].x > coordinates[1].x) {
56
56
  coordinate = {
57
57
  x: 0,
58
- y: reactKlinecharts.utils.getLinearYFromCoordinates(coordinates[0], coordinates[1], {
58
+ y: klinecharts.utils.getLinearYFromCoordinates(coordinates[0], coordinates[1], {
59
59
  x: 0,
60
60
  y: coordinates[0].y
61
61
  })
@@ -63,7 +63,7 @@ function getRayLine(coordinates, bounding) {
63
63
  } else {
64
64
  coordinate = {
65
65
  x: bounding.width,
66
- y: reactKlinecharts.utils.getLinearYFromCoordinates(coordinates[0], coordinates[1], {
66
+ y: klinecharts.utils.getLinearYFromCoordinates(coordinates[0], coordinates[1], {
67
67
  x: bounding.width,
68
68
  y: coordinates[0].y
69
69
  })
@@ -89,7 +89,7 @@ var arrow = {
89
89
  createPointFigures: ({ coordinates }) => {
90
90
  if (coordinates.length > 1) {
91
91
  const flag = coordinates[1].x > coordinates[0].x ? 0 : 1;
92
- const kb = reactKlinecharts.utils.getLinearSlopeIntercept(coordinates[0], coordinates[1]);
92
+ const kb = klinecharts.utils.getLinearSlopeIntercept(coordinates[0], coordinates[1]);
93
93
  let offsetAngle;
94
94
  if (kb) {
95
95
  offsetAngle = Math.atan(kb[0]) + Math.PI * flag;
@@ -331,7 +331,7 @@ var fibonacciSpiral = {
331
331
  if (coordinates.length > 1) {
332
332
  const startRadius = getDistance(coordinates[0], coordinates[1]) / Math.sqrt(24);
333
333
  const flag = coordinates[1].x > coordinates[0].x ? 0 : 1;
334
- const kb = reactKlinecharts.utils.getLinearSlopeIntercept(coordinates[0], coordinates[1]);
334
+ const kb = klinecharts.utils.getLinearSlopeIntercept(coordinates[0], coordinates[1]);
335
335
  let offsetAngle;
336
336
  if (kb) {
337
337
  offsetAngle = Math.atan(kb[0]) + Math.PI * flag;
@@ -994,7 +994,10 @@ var parallelChannel_default = parallelChannel;
994
994
  // src/overlays/longPosition.ts
995
995
  var longPosition = {
996
996
  name: "longPosition",
997
- totalStep: 3,
997
+ // totalStep 4 → the user places 3 points interactively (entry, target, stop).
998
+ // With the previous value of 3, only 2 points were captured and the stop was
999
+ // always a hardcoded 40px offset, so R/R was meaningless.
1000
+ totalStep: 4,
998
1001
  needDefaultPointFigure: true,
999
1002
  needDefaultXAxisFigure: true,
1000
1003
  needDefaultYAxisFigure: true,
@@ -1103,7 +1106,10 @@ var longPosition_default = longPosition;
1103
1106
  // src/overlays/shortPosition.ts
1104
1107
  var shortPosition = {
1105
1108
  name: "shortPosition",
1106
- totalStep: 3,
1109
+ // totalStep 4 → the user places 3 points interactively (entry, target, stop).
1110
+ // With the previous value of 3, only 2 points were captured and the stop was
1111
+ // always a hardcoded 40px offset, so R/R was meaningless.
1112
+ totalStep: 4,
1107
1113
  needDefaultPointFigure: true,
1108
1114
  needDefaultXAxisFigure: true,
1109
1115
  needDefaultYAxisFigure: true,
@@ -1232,8 +1238,10 @@ var measure = {
1232
1238
  const endPoint = overlay.points[1];
1233
1239
  const startCoord = coordinates[0];
1234
1240
  const endCoord = coordinates[1];
1235
- const diff = endPoint.value - startPoint.value;
1236
- const percent = (diff / startPoint.value * 100).toFixed(2);
1241
+ const startValue = startPoint.value ?? 0;
1242
+ const endValue = endPoint.value ?? 0;
1243
+ const diff = endValue - startValue;
1244
+ const percent = startValue !== 0 ? (diff / startValue * 100).toFixed(2) : "0.00";
1237
1245
  const bars = Math.abs(
1238
1246
  (endPoint.dataIndex ?? 0) - (startPoint.dataIndex ?? 0)
1239
1247
  );
@@ -1286,7 +1294,7 @@ var measure = {
1286
1294
  {
1287
1295
  type: "line",
1288
1296
  attrs: { coordinates: [startCoord, endCoord] },
1289
- styles: { color: strokeColor, style: "dash" }
1297
+ styles: { color: strokeColor, style: "dashed" }
1290
1298
  },
1291
1299
  ...textFigures
1292
1300
  ];
@@ -1342,7 +1350,7 @@ function rdp(points, epsilon) {
1342
1350
  }
1343
1351
  return result;
1344
1352
  }
1345
- reactKlinecharts.registerFigure({
1353
+ klinecharts.registerFigure({
1346
1354
  name: "brush_path",
1347
1355
  draw: (ctx, attrs, styles) => {
1348
1356
  const { coordinates } = attrs;
@@ -1862,8 +1870,9 @@ var ichimoku = {
1862
1870
  if (index >= kijunPeriod - 1) {
1863
1871
  item.kijun = highLowAvg(dataList, index - kijunPeriod + 1, index);
1864
1872
  }
1865
- if (index + offset < dataList.length) {
1866
- item.chikou = dataList[index + offset].close;
1873
+ const chikouIndex = index - offset;
1874
+ if (chikouIndex >= 0) {
1875
+ item.chikou = dataList[chikouIndex].close;
1867
1876
  }
1868
1877
  const prevIndex = index - offset;
1869
1878
  if (prevIndex >= 0) {
@@ -2003,7 +2012,7 @@ var pivotPoints = {
2003
2012
  let dayLow = Infinity;
2004
2013
  let dayClose = 0;
2005
2014
  return dataList.map((kLineData) => {
2006
- const date = new Date(kLineData.timestamp).toLocaleDateString();
2015
+ const date = new Date(kLineData.timestamp).toISOString().slice(0, 10);
2007
2016
  if (date !== lastDate) {
2008
2017
  if (lastDate !== "") {
2009
2018
  lastP = (dayHigh + dayLow + dayClose) / 3;
@@ -2057,11 +2066,20 @@ var rsiTv = {
2057
2066
  const maPeriod = indicator.calcParams[1];
2058
2067
  const closes = dataList.map((d) => d.close);
2059
2068
  const rsiValues = TA_default.rsi(closes, rsiPeriod);
2060
- const nonNullRsi = rsiValues.map((v) => v ?? 0);
2061
- const maValues = TA_default.sma(nonNullRsi, maPeriod);
2069
+ const rsiMa = new Array(rsiValues.length).fill(null);
2070
+ for (let i = 0; i < rsiValues.length; i++) {
2071
+ if (rsiValues[i] === null) continue;
2072
+ const valid = [];
2073
+ for (let j = i; j >= 0 && valid.length < maPeriod; j--) {
2074
+ if (rsiValues[j] !== null) valid.push(rsiValues[j]);
2075
+ }
2076
+ if (valid.length === maPeriod) {
2077
+ rsiMa[i] = valid.reduce((a, b) => a + b, 0) / maPeriod;
2078
+ }
2079
+ }
2062
2080
  return dataList.map((_, i) => {
2063
2081
  const rsi = rsiValues[i];
2064
- const rsi_ma = rsi !== null && maValues[i] !== null ? maValues[i] : null;
2082
+ const rsi_ma = rsi !== null ? rsiMa[i] : null;
2065
2083
  return { rsi, rsi_ma };
2066
2084
  });
2067
2085
  },
@@ -2283,7 +2301,7 @@ var vwap = {
2283
2301
  let cumulativePriceVolume = 0;
2284
2302
  let lastDate = "";
2285
2303
  return dataList.map((kLineData) => {
2286
- const date = new Date(kLineData.timestamp).toLocaleDateString();
2304
+ const date = new Date(kLineData.timestamp).toISOString().slice(0, 10);
2287
2305
  if (date !== lastDate) {
2288
2306
  cumulativeVolume = 0;
2289
2307
  cumulativePriceVolume = 0;
@@ -2416,7 +2434,7 @@ var depthOverlay = {
2416
2434
  const maxBarPx = bounding.width * maxBarFraction;
2417
2435
  const askColor = d.askColor ?? "rgba(239,83,80,0.25)";
2418
2436
  const bidColor = d.bidColor ?? "rgba(38,166,154,0.25)";
2419
- const maxQty = d.maxQty || 1;
2437
+ const maxQty = d.maxQty ?? 1;
2420
2438
  const figures = [];
2421
2439
  for (const row of d.rows) {
2422
2440
  const y = yAxis.convertToPixel(row.price);
@@ -2443,19 +2461,134 @@ var depthOverlay = {
2443
2461
  };
2444
2462
  var depthOverlay_default = depthOverlay;
2445
2463
 
2464
+ // src/extensions/overlays/alertLine.ts
2465
+ var DEFAULT_FONT_FAMILY2 = "Helvetica Neue, Arial, sans-serif";
2466
+ var DEFAULT_COLOR = "#ff9800";
2467
+ var BELL_MARK = "\u{1F514}";
2468
+ var alertLine = {
2469
+ name: "alertLine",
2470
+ totalStep: 2,
2471
+ needDefaultPointFigure: false,
2472
+ needDefaultXAxisFigure: false,
2473
+ needDefaultYAxisFigure: false,
2474
+ createYAxisFigures: ({ chart, overlay, coordinates }) => {
2475
+ if (coordinates.length < 1) return [];
2476
+ const y = coordinates[0].y;
2477
+ const price = overlay.points[0]?.value;
2478
+ if (price == null) return [];
2479
+ const d = overlay.extendData ?? {};
2480
+ const color = d.color ?? DEFAULT_COLOR;
2481
+ const m = d.mark;
2482
+ const precision = chart.getSymbol()?.pricePrecision ?? 2;
2483
+ return [
2484
+ {
2485
+ type: "text",
2486
+ attrs: {
2487
+ x: 0,
2488
+ y,
2489
+ text: price.toFixed(precision),
2490
+ align: "left",
2491
+ baseline: "middle"
2492
+ },
2493
+ styles: {
2494
+ color: m?.color ?? "#ffffff",
2495
+ size: m?.font?.size ?? 11,
2496
+ family: m?.font?.family ?? DEFAULT_FONT_FAMILY2,
2497
+ weight: m?.font?.weight ?? "bold",
2498
+ paddingLeft: m?.padding?.x ?? 4,
2499
+ paddingRight: m?.padding?.x ?? 4,
2500
+ paddingTop: m?.padding?.y ?? 4,
2501
+ paddingBottom: m?.padding?.y ?? 4,
2502
+ backgroundColor: m?.bg ?? color,
2503
+ borderRadius: m?.borderRadius ?? 2
2504
+ }
2505
+ }
2506
+ ];
2507
+ },
2508
+ createPointFigures: ({ chart, coordinates, bounding, overlay }) => {
2509
+ if (coordinates.length < 1) return [];
2510
+ const y = coordinates[0].y;
2511
+ const d = overlay.extendData ?? {};
2512
+ const color = d.color ?? DEFAULT_COLOR;
2513
+ const ln = d.line;
2514
+ const figures = [
2515
+ {
2516
+ type: "line",
2517
+ attrs: {
2518
+ coordinates: [
2519
+ { x: 0, y },
2520
+ { x: bounding.width, y }
2521
+ ]
2522
+ },
2523
+ styles: {
2524
+ style: ln?.style ?? "dashed",
2525
+ color,
2526
+ size: ln?.width ?? 1,
2527
+ dashedValue: ln?.dashedValue ?? [4, 2]
2528
+ }
2529
+ }
2530
+ ];
2531
+ const price = overlay.points[0]?.value;
2532
+ const precision = chart.getSymbol()?.pricePrecision ?? 2;
2533
+ const baseText = d.text ?? (price != null ? price.toFixed(precision) : "");
2534
+ const showBell = d.showBell ?? true;
2535
+ const text = baseText ? showBell ? `${BELL_MARK} ${baseText}` : baseText : showBell ? BELL_MARK : "";
2536
+ if (text) {
2537
+ const lb = d.label;
2538
+ figures.push({
2539
+ type: "text",
2540
+ ignoreEvent: true,
2541
+ attrs: {
2542
+ x: lb?.offset?.x ?? 8,
2543
+ y: y - (lb?.offset?.y ?? 3),
2544
+ text,
2545
+ align: "left",
2546
+ baseline: "bottom"
2547
+ },
2548
+ styles: {
2549
+ color: lb?.color ?? color,
2550
+ size: lb?.font?.size ?? 11,
2551
+ family: lb?.font?.family ?? DEFAULT_FONT_FAMILY2,
2552
+ weight: lb?.font?.weight ?? "normal",
2553
+ paddingLeft: lb?.padding?.x ?? 0,
2554
+ paddingRight: lb?.padding?.x ?? 0,
2555
+ paddingTop: lb?.padding?.y ?? 0,
2556
+ paddingBottom: lb?.padding?.y ?? 0,
2557
+ backgroundColor: lb?.bg ?? "transparent",
2558
+ borderRadius: lb?.borderRadius ?? 0
2559
+ }
2560
+ });
2561
+ }
2562
+ return figures;
2563
+ },
2564
+ performEventPressedMove: ({ points, performPoint }) => {
2565
+ points[0].value = performPoint.value;
2566
+ }
2567
+ };
2568
+ var alertLine_default = alertLine;
2569
+
2446
2570
  // src/extensions/index.ts
2447
2571
  var overlays = Object.values(overlays_exports);
2572
+ var featureOverlays = [orderLine_default, depthOverlay_default, alertLine_default];
2448
2573
  var indicators = Object.values(indicators_exports);
2449
2574
  var registered = false;
2450
2575
  function registerExtensions() {
2451
2576
  if (registered) return;
2452
- overlays.forEach((overlay) => reactKlinecharts.registerOverlay(overlay));
2453
- indicators.forEach((indicator) => reactKlinecharts.registerIndicator(indicator));
2577
+ overlays.forEach((overlay) => klinecharts.registerOverlay(overlay));
2578
+ featureOverlays.forEach((overlay) => klinecharts.registerOverlay(overlay));
2579
+ indicators.forEach((indicator) => klinecharts.registerIndicator(indicator));
2454
2580
  registered = true;
2455
2581
  }
2582
+ var alertLineRegistered = false;
2583
+ function ensureAlertLineRegistered() {
2584
+ if (alertLineRegistered) return;
2585
+ klinecharts.registerOverlay(alertLine_default);
2586
+ alertLineRegistered = true;
2587
+ }
2456
2588
 
2457
2589
  exports.TA_default = TA_default;
2458
2590
  exports.abcd_default = abcd_default;
2591
+ exports.alertLine_default = alertLine_default;
2459
2592
  exports.anyWaves_default = anyWaves_default;
2460
2593
  exports.arrow_default = arrow_default;
2461
2594
  exports.bollTv_default = bollTv_default;
@@ -2465,6 +2598,8 @@ exports.circle_default = circle_default;
2465
2598
  exports.depthOverlay_default = depthOverlay_default;
2466
2599
  exports.eightWaves_default = eightWaves_default;
2467
2600
  exports.elliottWave_default = elliottWave_default;
2601
+ exports.ensureAlertLineRegistered = ensureAlertLineRegistered;
2602
+ exports.featureOverlays = featureOverlays;
2468
2603
  exports.fibRetracement_default = fibRetracement_default;
2469
2604
  exports.fibonacciCircle_default = fibonacciCircle_default;
2470
2605
  exports.fibonacciExtension_default = fibonacciExtension_default;
@@ -2497,5 +2632,5 @@ exports.threeWaves_default = threeWaves_default;
2497
2632
  exports.triangle_default = triangle_default;
2498
2633
  exports.vwap_default = vwap_default;
2499
2634
  exports.xabcd_default = xabcd_default;
2500
- //# sourceMappingURL=chunk-UJNJH3BS.cjs.map
2501
- //# sourceMappingURL=chunk-UJNJH3BS.cjs.map
2635
+ //# sourceMappingURL=chunk-LGYYJ2GP.cjs.map
2636
+ //# sourceMappingURL=chunk-LGYYJ2GP.cjs.map