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.cjs.js +226 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +226 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/utils/echarts-all.d.ts +96 -0
- package/dist/utils/echarts.d.ts +4 -2
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -8370,6 +8370,220 @@ const EChartsUtilsAll = {
|
|
|
8370
8370
|
};
|
|
8371
8371
|
return option;
|
|
8372
8372
|
},
|
|
8373
|
+
/**
|
|
8374
|
+
* 单位压力与回弹变形关系曲线
|
|
8375
|
+
* @param config 折线配置
|
|
8376
|
+
* @param xDataArr x轴原始数据(二维数组)
|
|
8377
|
+
* @param yDataArr y轴原始数据(二维数组)
|
|
8378
|
+
* @returns 返回ECharts配置项
|
|
8379
|
+
*/
|
|
8380
|
+
chart430: (config, xDataArr, yDataArr, sheet) => {
|
|
8381
|
+
let lineData = JSON.parse(config.chartLinesJson);
|
|
8382
|
+
const chartExtJson = config.chartExtJson == null || config.chartExtJson == undefined ? null : JSON.parse(config.chartExtJson);
|
|
8383
|
+
let title = config.chartTitle, xName = config.chartXName, yName = config.chartYName, color = lineData[0].lineColor;
|
|
8384
|
+
// 原始数据
|
|
8385
|
+
const xData = xDataArr[0];
|
|
8386
|
+
const yData = yDataArr[0];
|
|
8387
|
+
// 手动计算多项式回归系数(与Excel一致)
|
|
8388
|
+
function polynomialRegression(x, y, degree) {
|
|
8389
|
+
const n = x.length;
|
|
8390
|
+
let Y = [];
|
|
8391
|
+
for (let i = 0; i < n; i++) {
|
|
8392
|
+
let row = [];
|
|
8393
|
+
for (let j = 0; j <= degree; j++) {
|
|
8394
|
+
row.push(Math.pow(x[i], j));
|
|
8395
|
+
}
|
|
8396
|
+
Y.push([y[i]]);
|
|
8397
|
+
}
|
|
8398
|
+
let XTX = [];
|
|
8399
|
+
for (let i = 0; i <= degree; i++) {
|
|
8400
|
+
XTX[i] = [];
|
|
8401
|
+
for (let j = 0; j <= degree; j++) {
|
|
8402
|
+
let sum = 0;
|
|
8403
|
+
for (let k = 0; k < n; k++) {
|
|
8404
|
+
sum += Math.pow(x[k], i + j);
|
|
8405
|
+
}
|
|
8406
|
+
XTX[i][j] = sum;
|
|
8407
|
+
}
|
|
8408
|
+
}
|
|
8409
|
+
let XTY = [];
|
|
8410
|
+
for (let i = 0; i <= degree; i++) {
|
|
8411
|
+
let sum = 0;
|
|
8412
|
+
for (let k = 0; k < n; k++) {
|
|
8413
|
+
sum += Math.pow(x[k], i) * y[k];
|
|
8414
|
+
}
|
|
8415
|
+
XTY[i] = sum;
|
|
8416
|
+
}
|
|
8417
|
+
let matrix = [];
|
|
8418
|
+
for (let i = 0; i <= degree; i++) {
|
|
8419
|
+
matrix[i] = [];
|
|
8420
|
+
for (let j = 0; j <= degree; j++) {
|
|
8421
|
+
matrix[i][j] = XTX[i][j];
|
|
8422
|
+
}
|
|
8423
|
+
matrix[i][degree + 1] = XTY[i];
|
|
8424
|
+
}
|
|
8425
|
+
for (let i = 0; i <= degree; i++) {
|
|
8426
|
+
let maxRow = i;
|
|
8427
|
+
for (let k = i + 1; k <= degree; k++) {
|
|
8428
|
+
if (Math.abs(matrix[k][i]) > Math.abs(matrix[maxRow][i])) {
|
|
8429
|
+
maxRow = k;
|
|
8430
|
+
}
|
|
8431
|
+
}
|
|
8432
|
+
[matrix[i], matrix[maxRow]] = [matrix[maxRow], matrix[i]];
|
|
8433
|
+
const divisor = matrix[i][i];
|
|
8434
|
+
for (let j = i; j <= degree + 1; j++) {
|
|
8435
|
+
matrix[i][j] /= divisor;
|
|
8436
|
+
}
|
|
8437
|
+
for (let k = i + 1; k <= degree; k++) {
|
|
8438
|
+
const factor = matrix[k][i];
|
|
8439
|
+
for (let j = i; j <= degree + 1; j++) {
|
|
8440
|
+
matrix[k][j] -= factor * matrix[i][j];
|
|
8441
|
+
}
|
|
8442
|
+
}
|
|
8443
|
+
}
|
|
8444
|
+
const coefficients = new Array(degree + 1);
|
|
8445
|
+
for (let i = degree; i >= 0; i--) {
|
|
8446
|
+
coefficients[i] = matrix[i][degree + 1];
|
|
8447
|
+
for (let j = i + 1; j <= degree; j++) {
|
|
8448
|
+
coefficients[i] -= matrix[i][j] * coefficients[j];
|
|
8449
|
+
}
|
|
8450
|
+
}
|
|
8451
|
+
return coefficients;
|
|
8452
|
+
}
|
|
8453
|
+
// 计算多项式回归系数(阶数为2)
|
|
8454
|
+
const coefficients = polynomialRegression(xData, yData, 2);
|
|
8455
|
+
// 提取系数(与Excel一致)
|
|
8456
|
+
const a = coefficients[2].toFixed(2);
|
|
8457
|
+
const b = coefficients[1].toFixed(2);
|
|
8458
|
+
const c = coefficients[0].toFixed(2);
|
|
8459
|
+
// 生成回归线的数据点
|
|
8460
|
+
const regressionPoints = [];
|
|
8461
|
+
const minX = Math.min(...xData);
|
|
8462
|
+
const maxX = Math.max(...xData);
|
|
8463
|
+
const step = (maxX - minX) / 100;
|
|
8464
|
+
for (let x = minX; x <= maxX; x += step) {
|
|
8465
|
+
const y = a * x * x + b * x + parseFloat(c);
|
|
8466
|
+
regressionPoints.push([x, y]);
|
|
8467
|
+
}
|
|
8468
|
+
// 输出方程
|
|
8469
|
+
if (chartExtJson != null) {
|
|
8470
|
+
if (chartExtJson.dwylHtbxGs != null && chartExtJson.dwylHtbxGs != undefined) {
|
|
8471
|
+
sheet.setValue(chartExtJson.dwylHtbxGs.row, chartExtJson.dwylHtbxGs.col, a != 'NaN' && b != 'NaN' && c != 'NaN' ? `Y=${a}X²+${b}X+${c}` : '/');
|
|
8472
|
+
}
|
|
8473
|
+
if (chartExtJson.dwylHtbxA != null && chartExtJson.dwylHtbxA != undefined) {
|
|
8474
|
+
sheet.setValue(chartExtJson.dwylHtbxA.row, chartExtJson.dwylHtbxA.col, a != 'NaN' ? a : '/');
|
|
8475
|
+
}
|
|
8476
|
+
if (chartExtJson.dwylHtbxB != null && chartExtJson.dwylHtbxB != undefined) {
|
|
8477
|
+
sheet.setValue(chartExtJson.dwylHtbxB.row, chartExtJson.dwylHtbxB.col, b != 'NaN' ? b : '/');
|
|
8478
|
+
}
|
|
8479
|
+
if (chartExtJson.dwylHtbxC != null && chartExtJson.dwylHtbxC != undefined) {
|
|
8480
|
+
sheet.setValue(chartExtJson.dwylHtbxC.row, chartExtJson.dwylHtbxC.col, c != 'NaN' ? c : '/');
|
|
8481
|
+
}
|
|
8482
|
+
}
|
|
8483
|
+
let yValIsAllNull = false;
|
|
8484
|
+
if (xData.length == 0 ||
|
|
8485
|
+
yData.length == 0 ||
|
|
8486
|
+
(!xData.some((x) => x != '' && x != '/' && x != null && x != undefined) &&
|
|
8487
|
+
!yData.some((x) => x != '' && x != '/' && x != null && x != undefined))) {
|
|
8488
|
+
yValIsAllNull = true;
|
|
8489
|
+
}
|
|
8490
|
+
// 配置图表选项
|
|
8491
|
+
let option = {
|
|
8492
|
+
title: [
|
|
8493
|
+
{
|
|
8494
|
+
show: true,
|
|
8495
|
+
text: title,
|
|
8496
|
+
top: 2,
|
|
8497
|
+
textStyle: {
|
|
8498
|
+
fontSize: 12,
|
|
8499
|
+
fontWeight: 'normal',
|
|
8500
|
+
},
|
|
8501
|
+
},
|
|
8502
|
+
{
|
|
8503
|
+
show: true,
|
|
8504
|
+
text: xName,
|
|
8505
|
+
left: 'center',
|
|
8506
|
+
bottom: 0,
|
|
8507
|
+
textStyle: {
|
|
8508
|
+
fontSize: 12,
|
|
8509
|
+
fontWeight: 'normal',
|
|
8510
|
+
},
|
|
8511
|
+
},
|
|
8512
|
+
],
|
|
8513
|
+
grid: {
|
|
8514
|
+
top: 25,
|
|
8515
|
+
left: 25,
|
|
8516
|
+
right: 15,
|
|
8517
|
+
bottom: 20,
|
|
8518
|
+
containLabel: true,
|
|
8519
|
+
},
|
|
8520
|
+
xAxis: {
|
|
8521
|
+
type: 'value',
|
|
8522
|
+
nameLocation: 'end',
|
|
8523
|
+
nameTextStyle: {
|
|
8524
|
+
fontSize: 14,
|
|
8525
|
+
padding: [10, 0, 0, 0],
|
|
8526
|
+
},
|
|
8527
|
+
interval: 0.05, // 设置刻度间隔为0.05
|
|
8528
|
+
min: 0,
|
|
8529
|
+
max: maxX + 0.05,
|
|
8530
|
+
},
|
|
8531
|
+
yAxis: {
|
|
8532
|
+
type: 'value',
|
|
8533
|
+
name: yName,
|
|
8534
|
+
nameGap: !yValIsAllNull ? 30 : 5,
|
|
8535
|
+
nameRotate: 90,
|
|
8536
|
+
nameLocation: 'middle',
|
|
8537
|
+
interval: 20,
|
|
8538
|
+
// 关键设置:确保y轴从0开始向下延伸
|
|
8539
|
+
min: 0, // 从0开始[4,5](@ref)
|
|
8540
|
+
max: Math.max(...yData) + 10, // 根据数据范围设置最大值
|
|
8541
|
+
axisLine: {
|
|
8542
|
+
lineStyle: {
|
|
8543
|
+
color: '#333',
|
|
8544
|
+
},
|
|
8545
|
+
},
|
|
8546
|
+
},
|
|
8547
|
+
tooltip: {
|
|
8548
|
+
trigger: 'axis',
|
|
8549
|
+
formatter: function (params) {
|
|
8550
|
+
if (params.length > 1) {
|
|
8551
|
+
return `单位压力: ${params[0].value[0]} MPa<br/>回弹变形: ${params[0].value[1]} (1/1000mm)`;
|
|
8552
|
+
}
|
|
8553
|
+
else {
|
|
8554
|
+
return `趋势线<br/>单位压力: ${params[0].value[0]} MPa<br/>预测回弹变形: ${params[0].value[1].toFixed(2)} (1/1000mm)`;
|
|
8555
|
+
}
|
|
8556
|
+
},
|
|
8557
|
+
},
|
|
8558
|
+
series: [
|
|
8559
|
+
{
|
|
8560
|
+
name: '原始数据',
|
|
8561
|
+
type: 'scatter',
|
|
8562
|
+
data: xData.map((x, i) => [x, yData[i]]),
|
|
8563
|
+
symbolSize: 5,
|
|
8564
|
+
itemStyle: {
|
|
8565
|
+
color: color,
|
|
8566
|
+
},
|
|
8567
|
+
},
|
|
8568
|
+
{
|
|
8569
|
+
name: '多项式趋势线',
|
|
8570
|
+
type: 'line',
|
|
8571
|
+
data: regressionPoints,
|
|
8572
|
+
symbol: 'none',
|
|
8573
|
+
lineStyle: {
|
|
8574
|
+
color: color,
|
|
8575
|
+
width: 1,
|
|
8576
|
+
type: 'dashed',
|
|
8577
|
+
},
|
|
8578
|
+
smooth: 0.3,
|
|
8579
|
+
tooltip: {
|
|
8580
|
+
trigger: 'item',
|
|
8581
|
+
},
|
|
8582
|
+
},
|
|
8583
|
+
],
|
|
8584
|
+
};
|
|
8585
|
+
return option;
|
|
8586
|
+
},
|
|
8373
8587
|
};
|
|
8374
8588
|
|
|
8375
8589
|
/**
|
|
@@ -8383,8 +8597,9 @@ const EChartsUtils = {
|
|
|
8383
8597
|
* @param sheet 工作表对象
|
|
8384
8598
|
* @param config 折线配置
|
|
8385
8599
|
* @param isHideChart 是否隐藏图表
|
|
8600
|
+
* @param isConsoleData 是否输出各个数据
|
|
8386
8601
|
*/
|
|
8387
|
-
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) {
|
|
8602
|
+
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) {
|
|
8388
8603
|
if (config.chartIdStr && config.chartIdStr.length > 0) {
|
|
8389
8604
|
config.chartId = config.chartIdStr;
|
|
8390
8605
|
}
|
|
@@ -8472,8 +8687,9 @@ const EChartsUtils = {
|
|
|
8472
8687
|
* @param sheet 工作表对象
|
|
8473
8688
|
* @param config 图表配置
|
|
8474
8689
|
* @param isHideChart 是否隐藏图表
|
|
8690
|
+
* @param isConsoleData 是否输出各个数据
|
|
8475
8691
|
*/
|
|
8476
|
-
initChart: (spread, sheet, config, isHideChart = false) => {
|
|
8692
|
+
initChart: (spread, sheet, config, isHideChart = false, isConsoleData = false) => {
|
|
8477
8693
|
// 此时可能ECharts所在的div还没有渲染(如浮动元素还没有在可视区域的时候是不会创建的)
|
|
8478
8694
|
if (document.getElementById(config.chartId + '_ec') == null) {
|
|
8479
8695
|
return null;
|
|
@@ -8541,6 +8757,11 @@ const EChartsUtils = {
|
|
|
8541
8757
|
useDirtyRect: false,
|
|
8542
8758
|
});
|
|
8543
8759
|
}
|
|
8760
|
+
if (isConsoleData) {
|
|
8761
|
+
console.log('config:', config);
|
|
8762
|
+
console.log('xDataArr:', xDataArr);
|
|
8763
|
+
console.log('yDataArr:', yDataArr);
|
|
8764
|
+
}
|
|
8544
8765
|
let option;
|
|
8545
8766
|
if (config.chartType == 10) {
|
|
8546
8767
|
option = EChartsUtilsAll.chart10(config, xDataArr, yDataArr, sheet);
|
|
@@ -8626,6 +8847,9 @@ const EChartsUtils = {
|
|
|
8626
8847
|
else if (config.chartType == 410) {
|
|
8627
8848
|
option = EChartsUtilsAll.chart410(config, xDataArr, yDataArr, sheet);
|
|
8628
8849
|
}
|
|
8850
|
+
else if (config.chartType == 430) {
|
|
8851
|
+
option = EChartsUtilsAll.chart430(config, xDataArr, yDataArr, sheet);
|
|
8852
|
+
}
|
|
8629
8853
|
if (option && typeof option === 'object') {
|
|
8630
8854
|
//如果是隐藏的图表,则需要禁用ECharts的动画效果
|
|
8631
8855
|
//原因是:如果ECharts使用了动画效果,图表渲染完成可能需要0.5秒,但是在导出ECharts统计图为图片的场景下时,可能在图表还没有渲染完成(动画效果还没结束)前就要获取图像了,此时可能就会造成获取到的图像内容丢失的情况
|