react-klinecharts-ui 0.6.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);
@@ -2556,15 +2574,15 @@ var indicators = Object.values(indicators_exports);
2556
2574
  var registered = false;
2557
2575
  function registerExtensions() {
2558
2576
  if (registered) return;
2559
- overlays.forEach((overlay) => reactKlinecharts.registerOverlay(overlay));
2560
- featureOverlays.forEach((overlay) => reactKlinecharts.registerOverlay(overlay));
2561
- 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));
2562
2580
  registered = true;
2563
2581
  }
2564
2582
  var alertLineRegistered = false;
2565
2583
  function ensureAlertLineRegistered() {
2566
2584
  if (alertLineRegistered) return;
2567
- reactKlinecharts.registerOverlay(alertLine_default);
2585
+ klinecharts.registerOverlay(alertLine_default);
2568
2586
  alertLineRegistered = true;
2569
2587
  }
2570
2588
 
@@ -2614,5 +2632,5 @@ exports.threeWaves_default = threeWaves_default;
2614
2632
  exports.triangle_default = triangle_default;
2615
2633
  exports.vwap_default = vwap_default;
2616
2634
  exports.xabcd_default = xabcd_default;
2617
- //# sourceMappingURL=chunk-FSHI2ZDB.cjs.map
2618
- //# sourceMappingURL=chunk-FSHI2ZDB.cjs.map
2635
+ //# sourceMappingURL=chunk-LGYYJ2GP.cjs.map
2636
+ //# sourceMappingURL=chunk-LGYYJ2GP.cjs.map