rapid-spreadjs 1.0.87 → 1.0.88

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/index.esm.js CHANGED
@@ -8362,6 +8362,16 @@ const EChartsUtilsAll = {
8362
8362
  // 原始数据
8363
8363
  const xData = xDataArr[0];
8364
8364
  const yData = yDataArr[0];
8365
+ let yValIsAllNull = false;
8366
+ if (xData.length == 0 ||
8367
+ yData.length == 0 ||
8368
+ (!xData.some((x) => x != '' && x != '/' && x != null && x != undefined) &&
8369
+ !yData.some((x) => x != '' && x != '/' && x != null && x != undefined))) {
8370
+ yValIsAllNull = true;
8371
+ }
8372
+ if (xData.filter((x) => x == 0).length == xData.length || yData.filter((x) => x == 0).length == yData.length) {
8373
+ yValIsAllNull = true;
8374
+ }
8365
8375
  // 手动计算多项式回归系数(与Excel一致)
8366
8376
  function polynomialRegression(x, y, degree) {
8367
8377
  const n = x.length;
@@ -8428,20 +8438,23 @@ const EChartsUtilsAll = {
8428
8438
  }
8429
8439
  return coefficients;
8430
8440
  }
8431
- // 计算多项式回归系数(阶数为2)
8432
- const coefficients = polynomialRegression(xData, yData, 2);
8433
8441
  // 提取系数(与Excel一致)
8434
- const a = coefficients[2].toFixed(2);
8435
- const b = coefficients[1].toFixed(2);
8436
- const c = coefficients[0].toFixed(2);
8442
+ let a = '/', b = '/', c = '/';
8437
8443
  // 生成回归线的数据点
8438
- const regressionPoints = [];
8439
- const minX = Math.min(...xData);
8444
+ let regressionPoints = [];
8440
8445
  const maxX = Math.max(...xData);
8441
- const step = (maxX - minX) / 100;
8442
- for (let x = minX; x <= maxX; x += step) {
8443
- const y = a * x * x + b * x + parseFloat(c);
8444
- regressionPoints.push([x, y]);
8446
+ if (!yValIsAllNull) {
8447
+ // 计算多项式回归系数(阶数为2)
8448
+ const coefficients = polynomialRegression(xData, yData, 2);
8449
+ a = coefficients[2].toFixed(2);
8450
+ b = coefficients[1].toFixed(2);
8451
+ c = coefficients[0].toFixed(2);
8452
+ const minX = Math.min(...xData);
8453
+ const step = (maxX - minX) / 100;
8454
+ for (let x = minX; x <= maxX; x += step) {
8455
+ const y = parseFloat(a) * x * x + parseFloat(b) * x + parseFloat(c);
8456
+ regressionPoints.push([x, y]);
8457
+ }
8445
8458
  }
8446
8459
  // 输出方程
8447
8460
  if (chartExtJson != null) {
@@ -8458,13 +8471,6 @@ const EChartsUtilsAll = {
8458
8471
  sheet.setValue(chartExtJson.dwylHtbxC.row, chartExtJson.dwylHtbxC.col, c != 'NaN' ? c : '/');
8459
8472
  }
8460
8473
  }
8461
- let yValIsAllNull = false;
8462
- if (xData.length == 0 ||
8463
- yData.length == 0 ||
8464
- (!xData.some((x) => x != '' && x != '/' && x != null && x != undefined) &&
8465
- !yData.some((x) => x != '' && x != '/' && x != null && x != undefined))) {
8466
- yValIsAllNull = true;
8467
- }
8468
8474
  // 配置图表选项
8469
8475
  let option = {
8470
8476
  title: [