rapid-spreadjs 1.0.105 → 1.0.106

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 CHANGED
@@ -8882,10 +8882,10 @@ const EChartsUtilsAll = {
8882
8882
  // 输出x轴内插值
8883
8883
  if (chartExtJson != null) {
8884
8884
  if (chartExtJson.tghcclYxkj5 != null && chartExtJson.tghcclYxkj5 != undefined) {
8885
- sheet.setValue(chartExtJson.tghcclYxkj5.row, chartExtJson.tghcclYxkj5.col, xAtY5 ? xAtY5 : '/');
8885
+ sheet.setValue(chartExtJson.tghcclYxkj5.row, chartExtJson.tghcclYxkj5.col, xAtY5 ? EChartsUtilsComm.getRound(xAtY5, 0.001) : '/');
8886
8886
  }
8887
8887
  if (chartExtJson.tghcclYxkj10 != null && chartExtJson.tghcclYxkj10 != undefined) {
8888
- sheet.setValue(chartExtJson.tghcclYxkj10.row, chartExtJson.tghcclYxkj10.col, xAtY10 ? xAtY10 : '/');
8888
+ sheet.setValue(chartExtJson.tghcclYxkj10.row, chartExtJson.tghcclYxkj10.col, xAtY10 ? EChartsUtilsComm.getRound(xAtY10, 0.001) : '/');
8889
8889
  }
8890
8890
  }
8891
8891
  // 配置图表选项
@@ -9014,7 +9014,7 @@ const EChartsUtilsAll = {
9014
9014
  },
9015
9015
  markPoint: {
9016
9016
  symbol: 'circle', // 使用简单的圆点作为标记
9017
- symbolSize: 8, // 标记点大小
9017
+ symbolSize: 1, // 标记点大小
9018
9018
  data: [
9019
9019
  {
9020
9020
  name: 'y=5',
@@ -9132,6 +9132,221 @@ const EChartsUtilsAll = {
9132
9132
  };
9133
9133
  return option;
9134
9134
  },
9135
+ /**
9136
+ * 温度-针入度曲线
9137
+ * @param config 折线配置
9138
+ * @param xDataArr x轴原始数据(二维数组)
9139
+ * @param yDataArr y轴原始数据(二维数组)
9140
+ * @returns 返回ECharts配置项
9141
+ */
9142
+ chart490: (config, xDataArr, yDataArr, sheet) => {
9143
+ let lineData = JSON.parse(config.chartLinesJson);
9144
+ const chartExtJson = config.chartExtJson == null || config.chartExtJson == undefined ? null : JSON.parse(config.chartExtJson);
9145
+ let title = config.chartTitle, xName = config.chartXName, yName = config.chartYName, color = lineData[0].lineColor;
9146
+ // 原始数据
9147
+ const xData = xDataArr[0];
9148
+ const yData = yDataArr[0];
9149
+ // 手动计算线性回归参数
9150
+ function linearRegression(x, y) {
9151
+ const n = x.length;
9152
+ const xMean = x.reduce((sum, val) => sum + val, 0) / n;
9153
+ const yMean = y.reduce((sum, val) => sum + val, 0) / n;
9154
+ let numerator = 0;
9155
+ let denominator = 0;
9156
+ for (let i = 0; i < n; i++) {
9157
+ numerator += (x[i] - xMean) * (y[i] - yMean);
9158
+ denominator += (x[i] - xMean) * (x[i] - xMean);
9159
+ }
9160
+ const slope = numerator / denominator;
9161
+ const intercept = yMean - slope * xMean;
9162
+ return { slope, intercept };
9163
+ }
9164
+ function calculateRSquared(x, y, slope, intercept) {
9165
+ const n = x.length;
9166
+ const yMean = y.reduce((sum, val) => sum + val, 0) / n;
9167
+ let totalSumOfSquares = 0;
9168
+ let residualSumOfSquares = 0;
9169
+ for (let i = 0; i < n; i++) {
9170
+ totalSumOfSquares += Math.pow(y[i] - yMean, 2);
9171
+ const yPredicted = slope * x[i] + intercept;
9172
+ residualSumOfSquares += Math.pow(y[i] - yPredicted, 2);
9173
+ }
9174
+ return 1 - residualSumOfSquares / totalSumOfSquares;
9175
+ }
9176
+ const logYData = yData.map((y) => Math.log10(y));
9177
+ const regressionParams = linearRegression(xData, logYData);
9178
+ const rSquared = calculateRSquared(xData, logYData, regressionParams.slope, regressionParams.intercept);
9179
+ // document.getElementById('formulaDisplay').innerHTML = `公式: log<sub>10</sub>(y) = ${regressionParams.slope.toFixed(
9180
+ // 4
9181
+ // )}x + ${regressionParams.intercept.toFixed(4)}<br> R² = ${rSquared.toFixed(4)}`;
9182
+ let yValIsAllNull = false;
9183
+ if (xData.length == 0 ||
9184
+ yData.length == 0 ||
9185
+ (!xData.some((x) => x != '' && x != '/' && x != null && x != undefined) &&
9186
+ !yData.some((x) => x != '' && x != '/' && x != null && x != undefined))) {
9187
+ yValIsAllNull = true;
9188
+ }
9189
+ if (xData.filter((x) => x == 0).length == xData.length || yData.filter((x) => x == 0).length == yData.length) {
9190
+ yValIsAllNull = true;
9191
+ }
9192
+ // 1. 定义期望显示网格线的Y轴数值(在对数空间中是均匀的,对应实际空间中的特定值)
9193
+ const customGridLines = yValIsAllNull ? [] : [30, 70, 100, 150, 200];
9194
+ // 2. 为markLine准备数据
9195
+ const markLineData = customGridLines.map((value) => ({
9196
+ yAxis: value, // 标记线的位置(实际值)
9197
+ label: {
9198
+ show: true,
9199
+ formatter: '{c}', // 显示数值
9200
+ },
9201
+ lineStyle: {
9202
+ color: '#e0e0e0',
9203
+ width: 1,
9204
+ type: 'solid',
9205
+ },
9206
+ }));
9207
+ // 输出x轴内插值
9208
+ if (chartExtJson != null) {
9209
+ if (chartExtJson.wdzrdXlA != null && chartExtJson.wdzrdXlA != undefined) {
9210
+ sheet.setValue(chartExtJson.wdzrdXlA.row, chartExtJson.wdzrdXlA.col, regressionParams.slope ? EChartsUtilsComm.getRound(regressionParams.slope, 0.0001) : '/');
9211
+ }
9212
+ if (chartExtJson.wdzrdCsB != null && chartExtJson.wdzrdCsB != undefined) {
9213
+ sheet.setValue(chartExtJson.wdzrdCsB.row, chartExtJson.wdzrdCsB.col, regressionParams.intercept ? EChartsUtilsComm.getRound(regressionParams.intercept, 0.0001) : '/');
9214
+ }
9215
+ if (chartExtJson.wdzrdXsR != null && chartExtJson.wdzrdXsR != undefined) {
9216
+ sheet.setValue(chartExtJson.wdzrdXsR.row, chartExtJson.wdzrdXsR.col, rSquared ? EChartsUtilsComm.getRound(rSquared, 0.0001) : '/');
9217
+ }
9218
+ }
9219
+ const option = {
9220
+ title: [
9221
+ {
9222
+ show: true,
9223
+ text: title,
9224
+ left: 'center',
9225
+ top: 2,
9226
+ textStyle: {
9227
+ fontSize: 14,
9228
+ fontWeight: 'normal',
9229
+ },
9230
+ },
9231
+ {
9232
+ show: true,
9233
+ text: xName,
9234
+ left: 'center',
9235
+ bottom: 0,
9236
+ textStyle: {
9237
+ fontSize: 12,
9238
+ fontWeight: 'normal',
9239
+ },
9240
+ },
9241
+ ],
9242
+ grid: {
9243
+ top: 25,
9244
+ left: yValIsAllNull ? 20 : 40,
9245
+ right: 15,
9246
+ bottom: 20,
9247
+ containLabel: true,
9248
+ },
9249
+ xAxis: {
9250
+ type: 'value',
9251
+ name: xName,
9252
+ min: Math.min(...xData),
9253
+ //max: 35
9254
+ },
9255
+ yAxis: {
9256
+ type: 'log',
9257
+ name: yName,
9258
+ nameLocation: 'middle', // 名称居中显示
9259
+ nameGap: yValIsAllNull ? 5 : 25, // 名称与轴线的距离
9260
+ logBase: 10,
9261
+ min: 10,
9262
+ min: function (value) {
9263
+ // 确保最小值不会太小
9264
+ return Math.max(1, Math.pow(10, Math.floor(Math.log10(value.min))));
9265
+ },
9266
+ max: function (value) {
9267
+ const maxValue = value.max;
9268
+ // 处理特殊情况
9269
+ if (maxValue <= 0)
9270
+ return 100;
9271
+ // 计算对数值
9272
+ const logValue = Math.log10(maxValue);
9273
+ const exponent = Math.floor(logValue);
9274
+ const fraction = logValue - exponent;
9275
+ // 根据小数部分决定如何取整
9276
+ let maxExponent;
9277
+ if (fraction < 0.3) {
9278
+ maxExponent = exponent + 0.3; // 使用5倍关系
9279
+ }
9280
+ else if (fraction < 0.7) {
9281
+ maxExponent = exponent + 1; // 使用10倍关系
9282
+ }
9283
+ else {
9284
+ maxExponent = exponent + 1.5; // 使用30倍关系,为大数据留更多空间
9285
+ }
9286
+ return Math.pow(10, maxExponent);
9287
+ },
9288
+ // 关键步骤:抑制默认的y轴网格线和部分标签,让markLine主导
9289
+ splitLine: {
9290
+ show: false, // 隐藏y轴默认的网格线
9291
+ },
9292
+ axisLabel: {
9293
+ show: false,
9294
+ // 可以控制只显示某些主要刻度,或者也设为false完全自定义
9295
+ // interval: 0,
9296
+ // 或者使用formatter精细控制,这里我们先展示默认标签
9297
+ },
9298
+ zlevel: 1,
9299
+ minorSplitLine: { show: false }, // 隐藏次要网格线
9300
+ },
9301
+ series: [
9302
+ {
9303
+ name: '原始数据',
9304
+ type: 'scatter',
9305
+ data: xData.map((x, i) => [x, yData[i]]),
9306
+ symbolSize: 6,
9307
+ zlevel: 4,
9308
+ itemStyle: { color: color },
9309
+ },
9310
+ {
9311
+ name: '趋势线',
9312
+ type: 'line',
9313
+ data: (() => {
9314
+ const minX = Math.min(...xData);
9315
+ const maxX = Math.max(...xData);
9316
+ const trendlineData = [];
9317
+ for (let x = minX; x <= maxX; x += 0.5) {
9318
+ const logY = regressionParams.slope * x + regressionParams.intercept;
9319
+ const y = Math.pow(10, logY);
9320
+ trendlineData.push([x, y]);
9321
+ }
9322
+ return trendlineData;
9323
+ })(),
9324
+ showSymbol: false,
9325
+ lineStyle: { color: color, width: 1 },
9326
+ // 关键修改:提升趋势线的绘制层级,确保它显示在网格线之上
9327
+ zlevel: 5, // 这个值大于网格线所在的层级即可
9328
+ },
9329
+ {
9330
+ // 关键步骤:添加一个透明的系列,专门用于承载markLine
9331
+ name: '自定义网格线',
9332
+ type: 'line',
9333
+ data: [], // 没有实际数据点
9334
+ markLine: {
9335
+ symbol: 'none', // 线条两端不显示符号
9336
+ lineStyle: { color: '#e0e0e0', width: 1, type: 'solid' },
9337
+ label: {
9338
+ show: true,
9339
+ position: 'start',
9340
+ formatter: '{c}', // 标签显示数值
9341
+ },
9342
+ data: markLineData, // 使用我们自定义的网格线数据
9343
+ },
9344
+ silent: true, // 此系列不响应鼠标事件
9345
+ },
9346
+ ],
9347
+ };
9348
+ return option;
9349
+ },
9135
9350
  };
9136
9351
 
9137
9352
  /**
@@ -9404,6 +9619,9 @@ const EChartsUtils = {
9404
9619
  else if (config.chartType == 470) {
9405
9620
  option = EChartsUtilsAll.chart470(config, xDataArr, yDataArr, sheet);
9406
9621
  }
9622
+ else if (config.chartType == 490) {
9623
+ option = EChartsUtilsAll.chart490(config, xDataArr, yDataArr, sheet);
9624
+ }
9407
9625
  if (option && typeof option === 'object') {
9408
9626
  //如果是隐藏的图表,则需要禁用ECharts的动画效果
9409
9627
  //原因是:如果ECharts使用了动画效果,图表渲染完成可能需要0.5秒,但是在导出ECharts统计图为图片的场景下时,可能在图表还没有渲染完成(动画效果还没结束)前就要获取图像了,此时可能就会造成获取到的图像内容丢失的情况