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