rapid-spreadjs 1.0.84 → 1.0.86

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
@@ -8348,6 +8348,220 @@ const EChartsUtilsAll = {
8348
8348
  };
8349
8349
  return option;
8350
8350
  },
8351
+ /**
8352
+ * 单位压力与回弹变形关系曲线
8353
+ * @param config 折线配置
8354
+ * @param xDataArr x轴原始数据(二维数组)
8355
+ * @param yDataArr y轴原始数据(二维数组)
8356
+ * @returns 返回ECharts配置项
8357
+ */
8358
+ chart430: (config, xDataArr, yDataArr, sheet) => {
8359
+ let lineData = JSON.parse(config.chartLinesJson);
8360
+ const chartExtJson = config.chartExtJson == null || config.chartExtJson == undefined ? null : JSON.parse(config.chartExtJson);
8361
+ let title = config.chartTitle, xName = config.chartXName, yName = config.chartYName, color = lineData[0].lineColor;
8362
+ // 原始数据
8363
+ const xData = xDataArr[0];
8364
+ const yData = yDataArr[0];
8365
+ // 手动计算多项式回归系数(与Excel一致)
8366
+ function polynomialRegression(x, y, degree) {
8367
+ const n = x.length;
8368
+ let Y = [];
8369
+ for (let i = 0; i < n; i++) {
8370
+ let row = [];
8371
+ for (let j = 0; j <= degree; j++) {
8372
+ row.push(Math.pow(x[i], j));
8373
+ }
8374
+ Y.push([y[i]]);
8375
+ }
8376
+ let XTX = [];
8377
+ for (let i = 0; i <= degree; i++) {
8378
+ XTX[i] = [];
8379
+ for (let j = 0; j <= degree; j++) {
8380
+ let sum = 0;
8381
+ for (let k = 0; k < n; k++) {
8382
+ sum += Math.pow(x[k], i + j);
8383
+ }
8384
+ XTX[i][j] = sum;
8385
+ }
8386
+ }
8387
+ let XTY = [];
8388
+ for (let i = 0; i <= degree; i++) {
8389
+ let sum = 0;
8390
+ for (let k = 0; k < n; k++) {
8391
+ sum += Math.pow(x[k], i) * y[k];
8392
+ }
8393
+ XTY[i] = sum;
8394
+ }
8395
+ let matrix = [];
8396
+ for (let i = 0; i <= degree; i++) {
8397
+ matrix[i] = [];
8398
+ for (let j = 0; j <= degree; j++) {
8399
+ matrix[i][j] = XTX[i][j];
8400
+ }
8401
+ matrix[i][degree + 1] = XTY[i];
8402
+ }
8403
+ for (let i = 0; i <= degree; i++) {
8404
+ let maxRow = i;
8405
+ for (let k = i + 1; k <= degree; k++) {
8406
+ if (Math.abs(matrix[k][i]) > Math.abs(matrix[maxRow][i])) {
8407
+ maxRow = k;
8408
+ }
8409
+ }
8410
+ [matrix[i], matrix[maxRow]] = [matrix[maxRow], matrix[i]];
8411
+ const divisor = matrix[i][i];
8412
+ for (let j = i; j <= degree + 1; j++) {
8413
+ matrix[i][j] /= divisor;
8414
+ }
8415
+ for (let k = i + 1; k <= degree; k++) {
8416
+ const factor = matrix[k][i];
8417
+ for (let j = i; j <= degree + 1; j++) {
8418
+ matrix[k][j] -= factor * matrix[i][j];
8419
+ }
8420
+ }
8421
+ }
8422
+ const coefficients = new Array(degree + 1);
8423
+ for (let i = degree; i >= 0; i--) {
8424
+ coefficients[i] = matrix[i][degree + 1];
8425
+ for (let j = i + 1; j <= degree; j++) {
8426
+ coefficients[i] -= matrix[i][j] * coefficients[j];
8427
+ }
8428
+ }
8429
+ return coefficients;
8430
+ }
8431
+ // 计算多项式回归系数(阶数为2)
8432
+ const coefficients = polynomialRegression(xData, yData, 2);
8433
+ // 提取系数(与Excel一致)
8434
+ const a = coefficients[2].toFixed(2);
8435
+ const b = coefficients[1].toFixed(2);
8436
+ const c = coefficients[0].toFixed(2);
8437
+ // 生成回归线的数据点
8438
+ const regressionPoints = [];
8439
+ const minX = Math.min(...xData);
8440
+ 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]);
8445
+ }
8446
+ // 输出方程
8447
+ if (chartExtJson != null) {
8448
+ if (chartExtJson.dwylHtbxGs != null && chartExtJson.dwylHtbxGs != undefined) {
8449
+ sheet.setValue(chartExtJson.dwylHtbxGs.row, chartExtJson.dwylHtbxGs.col, a != 'NaN' && b != 'NaN' && c != 'NaN' ? `Y=${a}X²+${b}X+${c}` : '/');
8450
+ }
8451
+ if (chartExtJson.dwylHtbxA != null && chartExtJson.dwylHtbxA != undefined) {
8452
+ sheet.setValue(chartExtJson.dwylHtbxA.row, chartExtJson.dwylHtbxA.col, a != 'NaN' ? a : '/');
8453
+ }
8454
+ if (chartExtJson.dwylHtbxB != null && chartExtJson.dwylHtbxB != undefined) {
8455
+ sheet.setValue(chartExtJson.dwylHtbxB.row, chartExtJson.dwylHtbxB.col, b != 'NaN' ? b : '/');
8456
+ }
8457
+ if (chartExtJson.dwylHtbxC != null && chartExtJson.dwylHtbxC != undefined) {
8458
+ sheet.setValue(chartExtJson.dwylHtbxC.row, chartExtJson.dwylHtbxC.col, c != 'NaN' ? c : '/');
8459
+ }
8460
+ }
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
+ // 配置图表选项
8469
+ let option = {
8470
+ title: [
8471
+ {
8472
+ show: true,
8473
+ text: title,
8474
+ top: 2,
8475
+ textStyle: {
8476
+ fontSize: 12,
8477
+ fontWeight: 'normal',
8478
+ },
8479
+ },
8480
+ {
8481
+ show: true,
8482
+ text: xName,
8483
+ left: 'center',
8484
+ bottom: 0,
8485
+ textStyle: {
8486
+ fontSize: 12,
8487
+ fontWeight: 'normal',
8488
+ },
8489
+ },
8490
+ ],
8491
+ grid: {
8492
+ top: 25,
8493
+ left: 25,
8494
+ right: 15,
8495
+ bottom: 20,
8496
+ containLabel: true,
8497
+ },
8498
+ xAxis: {
8499
+ type: 'value',
8500
+ nameLocation: 'end',
8501
+ nameTextStyle: {
8502
+ fontSize: 14,
8503
+ padding: [10, 0, 0, 0],
8504
+ },
8505
+ interval: 0.05, // 设置刻度间隔为0.05
8506
+ min: 0,
8507
+ max: maxX + 0.05,
8508
+ },
8509
+ yAxis: {
8510
+ type: 'value',
8511
+ name: yName,
8512
+ nameGap: !yValIsAllNull ? 30 : 5,
8513
+ nameRotate: 90,
8514
+ nameLocation: 'middle',
8515
+ interval: 20,
8516
+ // 关键设置:确保y轴从0开始向下延伸
8517
+ min: 0, // 从0开始[4,5](@ref)
8518
+ max: Math.max(...yData) + 10, // 根据数据范围设置最大值
8519
+ axisLine: {
8520
+ lineStyle: {
8521
+ color: '#333',
8522
+ },
8523
+ },
8524
+ },
8525
+ tooltip: {
8526
+ trigger: 'axis',
8527
+ formatter: function (params) {
8528
+ if (params.length > 1) {
8529
+ return `单位压力: ${params[0].value[0]} MPa<br/>回弹变形: ${params[0].value[1]} (1/1000mm)`;
8530
+ }
8531
+ else {
8532
+ return `趋势线<br/>单位压力: ${params[0].value[0]} MPa<br/>预测回弹变形: ${params[0].value[1].toFixed(2)} (1/1000mm)`;
8533
+ }
8534
+ },
8535
+ },
8536
+ series: [
8537
+ {
8538
+ name: '原始数据',
8539
+ type: 'scatter',
8540
+ data: xData.map((x, i) => [x, yData[i]]),
8541
+ symbolSize: 5,
8542
+ itemStyle: {
8543
+ color: color,
8544
+ },
8545
+ },
8546
+ {
8547
+ name: '多项式趋势线',
8548
+ type: 'line',
8549
+ data: regressionPoints,
8550
+ symbol: 'none',
8551
+ lineStyle: {
8552
+ color: color,
8553
+ width: 1,
8554
+ type: 'dashed',
8555
+ },
8556
+ smooth: 0.3,
8557
+ tooltip: {
8558
+ trigger: 'item',
8559
+ },
8560
+ },
8561
+ ],
8562
+ };
8563
+ return option;
8564
+ },
8351
8565
  };
8352
8566
 
8353
8567
  /**
@@ -8361,8 +8575,9 @@ const EChartsUtils = {
8361
8575
  * @param sheet 工作表对象
8362
8576
  * @param config 折线配置
8363
8577
  * @param isHideChart 是否隐藏图表
8578
+ * @param isConsoleData 是否输出各个数据
8364
8579
  */
8365
- create: (GC_1, spread_1, sheet_1, config_1, ...args_1) => __awaiter(void 0, [GC_1, spread_1, sheet_1, config_1, ...args_1], void 0, function* (GC, spread, sheet, config, isHideChart = false) {
8580
+ create: (GC_1, spread_1, sheet_1, config_1, ...args_1) => __awaiter(void 0, [GC_1, spread_1, sheet_1, config_1, ...args_1], void 0, function* (GC, spread, sheet, config, isHideChart = false, isConsoleData = false) {
8366
8581
  if (config.chartIdStr && config.chartIdStr.length > 0) {
8367
8582
  config.chartId = config.chartIdStr;
8368
8583
  }
@@ -8450,8 +8665,9 @@ const EChartsUtils = {
8450
8665
  * @param sheet 工作表对象
8451
8666
  * @param config 图表配置
8452
8667
  * @param isHideChart 是否隐藏图表
8668
+ * @param isConsoleData 是否输出各个数据
8453
8669
  */
8454
- initChart: (spread, sheet, config, isHideChart = false) => {
8670
+ initChart: (spread, sheet, config, isHideChart = false, isConsoleData = false) => {
8455
8671
  // 此时可能ECharts所在的div还没有渲染(如浮动元素还没有在可视区域的时候是不会创建的)
8456
8672
  if (document.getElementById(config.chartId + '_ec') == null) {
8457
8673
  return null;
@@ -8519,6 +8735,11 @@ const EChartsUtils = {
8519
8735
  useDirtyRect: false,
8520
8736
  });
8521
8737
  }
8738
+ if (isConsoleData) {
8739
+ console.log('config:', config);
8740
+ console.log('xDataArr:', xDataArr);
8741
+ console.log('yDataArr:', yDataArr);
8742
+ }
8522
8743
  let option;
8523
8744
  if (config.chartType == 10) {
8524
8745
  option = EChartsUtilsAll.chart10(config, xDataArr, yDataArr, sheet);
@@ -8604,6 +8825,9 @@ const EChartsUtils = {
8604
8825
  else if (config.chartType == 410) {
8605
8826
  option = EChartsUtilsAll.chart410(config, xDataArr, yDataArr, sheet);
8606
8827
  }
8828
+ else if (config.chartType == 430) {
8829
+ option = EChartsUtilsAll.chart430(config, xDataArr, yDataArr, sheet);
8830
+ }
8607
8831
  if (option && typeof option === 'object') {
8608
8832
  //如果是隐藏的图表,则需要禁用ECharts的动画效果
8609
8833
  //原因是:如果ECharts使用了动画效果,图表渲染完成可能需要0.5秒,但是在导出ECharts统计图为图片的场景下时,可能在图表还没有渲染完成(动画效果还没结束)前就要获取图像了,此时可能就会造成获取到的图像内容丢失的情况