kd-lane-chart-v3 0.1.0 → 0.1.2

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/esm/index.js CHANGED
@@ -7489,12 +7489,6 @@ const _sfc_main$2 = {
7489
7489
  this.scheduleConnectAllCharts = debounce(() => {
7490
7490
  this.connectAllCharts();
7491
7491
  }, 50);
7492
- this.getCssVar = (key) => {
7493
- if (!this.cssVarCache[key]) {
7494
- this.cssVarCache[key] = getCssVariable(key);
7495
- }
7496
- return this.cssVarCache[key];
7497
- };
7498
7492
  },
7499
7493
  mounted() {
7500
7494
  this.showDateTime = Object.prototype.hasOwnProperty.call(
@@ -8349,7 +8343,7 @@ const _sfc_main$2 = {
8349
8343
  // 获取默认的泳道图表选项
8350
8344
  getDefaultLaneChartOption() {
8351
8345
  const option = {
8352
- backgroundColor: this.getCssVar("--kd-lane-container-item-bg"),
8346
+ backgroundColor: getCssVariable("--kd-lane-container-item-bg"),
8353
8347
  grid: {
8354
8348
  top: 0,
8355
8349
  left: 2,
@@ -8375,7 +8369,7 @@ const _sfc_main$2 = {
8375
8369
  showMinLine: false,
8376
8370
  showMaxLine: false,
8377
8371
  lineStyle: {
8378
- color: this.getCssVar("--kd-lane-container-item-line-color"),
8372
+ color: getCssVariable("--kd-lane-container-item-line-color"),
8379
8373
  type: "dashed"
8380
8374
  }
8381
8375
  },
@@ -8402,7 +8396,7 @@ const _sfc_main$2 = {
8402
8396
  showMinLine: false,
8403
8397
  showMaxLine: false,
8404
8398
  lineStyle: {
8405
- color: this.getCssVar("--kd-lane-container-item-line-color"),
8399
+ color: getCssVariable("--kd-lane-container-item-line-color"),
8406
8400
  type: "dashed"
8407
8401
  }
8408
8402
  },
@@ -8413,7 +8407,7 @@ const _sfc_main$2 = {
8413
8407
  axisLabel: {
8414
8408
  show: false,
8415
8409
  fontSize: 12,
8416
- color: this.getCssVar("--default-text-color")
8410
+ color: getCssVariable("--default-text-color")
8417
8411
  },
8418
8412
  axisTick: {
8419
8413
  show: false
@@ -8440,8 +8434,8 @@ const _sfc_main$2 = {
8440
8434
  axis: "y",
8441
8435
  snap: true,
8442
8436
  label: {
8443
- backgroundColor: `${this.getCssVar("--kd-lane-container-border-color")}99`,
8444
- color: `${this.getCssVar("--default-text-color")}`,
8437
+ backgroundColor: `${getCssVariable("--kd-lane-container-border-color")}99`,
8438
+ color: `${getCssVariable("--default-text-color")}`,
8445
8439
  show: true,
8446
8440
  formatter: (params) => {
8447
8441
  var _a;
@@ -8459,10 +8453,10 @@ const _sfc_main$2 = {
8459
8453
  },
8460
8454
  confine: true,
8461
8455
  // appendTo: document.querySelector('.kd-curve-2d-container'),
8462
- backgroundColor: this.getCssVar("--tooltip-bg-color"),
8456
+ backgroundColor: getCssVariable("--tooltip-bg-color"),
8463
8457
  borderWidth: 0,
8464
8458
  textStyle: {
8465
- color: this.getCssVar("--default-text-color")
8459
+ color: getCssVariable("--default-text-color")
8466
8460
  },
8467
8461
  formatter: (series) => {
8468
8462
  var _a;
@@ -8727,7 +8721,7 @@ const _sfc_main$2 = {
8727
8721
  showMinLine: false,
8728
8722
  showMaxLine: false,
8729
8723
  lineStyle: {
8730
- color: this.getCssVar(
8724
+ color: getCssVariable(
8731
8725
  "--kd-lane-container-item-line-color"
8732
8726
  ),
8733
8727
  type: "dashed"
@@ -8738,7 +8732,7 @@ const _sfc_main$2 = {
8738
8732
  axisLabel: {
8739
8733
  show: false,
8740
8734
  fontSize: 12,
8741
- color: this.getCssVar("--default-text-color")
8735
+ color: getCssVariable("--default-text-color")
8742
8736
  },
8743
8737
  axisPointer: { show: hasValidLineData },
8744
8738
  interval: unifiedInterval
@@ -8773,7 +8767,7 @@ const _sfc_main$2 = {
8773
8767
  hideOverlap: true,
8774
8768
  height: 14,
8775
8769
  verticalAlign: "middle",
8776
- color: this.getCssVar("--default-text-color"),
8770
+ color: getCssVariable("--default-text-color"),
8777
8771
  overflow: "truncate",
8778
8772
  rich: {
8779
8773
  center: {
@@ -8846,13 +8840,13 @@ const _sfc_main$2 = {
8846
8840
  )
8847
8841
  };
8848
8842
  }
8849
- const groupSeriesData = this.generateSeriesDataCached(
8843
+ let groupSeriesData = this.generateSeriesDataCached(
8850
8844
  group,
8851
8845
  lineInfo,
8852
8846
  axisKey,
8853
8847
  paramCodeMap
8854
8848
  );
8855
- const groupAllSeriesData = this.generateAllSeriesDataCached(
8849
+ let groupAllSeriesData = this.generateAllSeriesDataCached(
8856
8850
  group,
8857
8851
  lineInfo,
8858
8852
  axisKey,
@@ -8877,7 +8871,7 @@ const _sfc_main$2 = {
8877
8871
  showMaxLine: false,
8878
8872
  showMinLine: false,
8879
8873
  lineStyle: {
8880
- color: this.getCssVar(
8874
+ color: getCssVariable(
8881
8875
  "--kd-lane-container-item-line-color"
8882
8876
  ),
8883
8877
  type: "dashed"
@@ -8929,7 +8923,7 @@ const _sfc_main$2 = {
8929
8923
  this.addAreaStyleToSeries(
8930
8924
  baseSeries,
8931
8925
  lineInfo,
8932
- groupSeriesData,
8926
+ groupAllSeriesData,
8933
8927
  min
8934
8928
  );
8935
8929
  const rangeAreaSeries = this.addRangeAreaToSeries(
@@ -9102,6 +9096,49 @@ const _sfc_main$2 = {
9102
9096
  }
9103
9097
  }
9104
9098
  },
9099
+ /**
9100
+ * LTTB 降采样算法
9101
+ * @param {Array<[number, number]>} data 原始数据 [[x,y], [x,y]]
9102
+ * @param {number} threshold 采样后最大点数(建议 600 ~ 1200)
9103
+ * @returns {Array<[number, number]>} 抽稀后数据
9104
+ */
9105
+ lttb(data, threshold) {
9106
+ if (threshold >= data.length || threshold === 0) {
9107
+ return [...data];
9108
+ }
9109
+ if (threshold === 1) {
9110
+ return [data[0]];
9111
+ }
9112
+ const output = [];
9113
+ const dataLength = data.length;
9114
+ const bucketSize = (dataLength - 2) / (threshold - 2);
9115
+ output.push(data[0]);
9116
+ let prevIndex = 0;
9117
+ for (let i = 0; i < threshold - 2; i++) {
9118
+ const bucketStart = 1 + Math.floor((i + 0) * bucketSize);
9119
+ const bucketEnd = 1 + Math.floor((i + 1) * bucketSize);
9120
+ const nextBucketMidIdx = Math.floor((i + 1.5) * bucketSize);
9121
+ let maxArea = -1;
9122
+ let maxAreaIndex = bucketStart;
9123
+ const pointA = data[prevIndex];
9124
+ const pointC = data[Math.min(nextBucketMidIdx, dataLength - 1)];
9125
+ for (let j = bucketStart; j < bucketEnd; j++) {
9126
+ const pointB = data[j];
9127
+ const area = Math.abs(
9128
+ (pointA[0] - pointC[0]) * (pointB[1] - pointA[1]) - (pointA[0] - pointB[0]) * (pointC[1] - pointA[1])
9129
+ );
9130
+ if (area > maxArea) {
9131
+ maxArea = area;
9132
+ maxAreaIndex = j;
9133
+ }
9134
+ }
9135
+ output.push(data[maxAreaIndex]);
9136
+ prevIndex = maxAreaIndex;
9137
+ }
9138
+ output.push(data[dataLength - 1]);
9139
+ console.log(output, "output");
9140
+ return output;
9141
+ },
9105
9142
  // 生成泳道图表数据
9106
9143
  generateSeriesData(data, lineInfo, axisKey) {
9107
9144
  return data.map((item) => {
@@ -9122,7 +9159,7 @@ const _sfc_main$2 = {
9122
9159
  }
9123
9160
  }
9124
9161
  }
9125
- return [value, +item[axisKey]];
9162
+ return [value, +item[axisKey], item.timestamp];
9126
9163
  });
9127
9164
  },
9128
9165
  generateSeriesDataCached(data, lineInfo, axisKey, paramCodeMap) {
@@ -9140,7 +9177,7 @@ const _sfc_main$2 = {
9140
9177
  }
9141
9178
  }
9142
9179
  }
9143
- return [value, +item[axisKey]];
9180
+ return [value, +item[axisKey], item.timestamp];
9144
9181
  });
9145
9182
  },
9146
9183
  generateAllSeriesDataCached(data, lineInfo, axisKey, paramCodeMap) {
@@ -9833,72 +9870,51 @@ const _sfc_main$2 = {
9833
9870
  }
9834
9871
  },
9835
9872
  findBoundaryPointPair(currentPoint) {
9836
- const chartRef = this.getChartRefByLaneId(currentPoint.laneId);
9837
- if (!chartRef || !chartRef.chart) {
9838
- return { topPoint: null, bottomPoint: null };
9839
- }
9840
- const option = chartRef.chart.getOption();
9841
9873
  let topPoint = null;
9842
9874
  let bottomPoint = null;
9843
- for (let i = 0; i < option.series.length; i++) {
9844
- const series = option.series[i];
9845
- if (series.type !== "scatter") continue;
9846
- const data = series.data || [];
9847
- for (let j = 0; j < data.length; j++) {
9848
- const point = data[j];
9849
- if (!point || !point.value) continue;
9850
- if (point.lineId === currentPoint.lineId && point.paramId === currentPoint.paramId) {
9851
- if (point.type === "top") {
9852
- topPoint = point;
9853
- } else if (point.type === "bottom") {
9854
- bottomPoint = point;
9855
- }
9856
- }
9857
- }
9858
- }
9859
- if (currentPoint.type === "top" && topPoint) {
9860
- const nextPoint = option.series.filter((s) => s.type === "scatter").flatMap((s) => s.data || []).find(
9861
- (p) => p && p.value && p.lineId === currentPoint.lineId && p.paramId === currentPoint.paramId && p.type === "bottom" && p.originalIndex > currentPoint.originalIndex
9862
- );
9863
- if (nextPoint) {
9864
- bottomPoint = nextPoint;
9865
- } else {
9866
- bottomPoint = this.findBoundaryPointFromRealTimeData(
9867
- currentPoint,
9868
- "bottom"
9869
- );
9870
- }
9871
- } else if (currentPoint.type === "bottom" && bottomPoint) {
9872
- const prevPoint = option.series.filter((s) => s.type === "scatter").flatMap((s) => s.data || []).find(
9873
- (p) => p && p.value && p.lineId === currentPoint.lineId && p.paramId === currentPoint.paramId && p.type === "top" && p.originalIndex < currentPoint.originalIndex
9875
+ if (currentPoint.type === "top") {
9876
+ topPoint = currentPoint;
9877
+ bottomPoint = this.findBoundaryPointFromRealTimeData(
9878
+ currentPoint,
9879
+ "bottom"
9874
9880
  );
9875
- if (prevPoint) {
9876
- topPoint = prevPoint;
9877
- } else {
9878
- topPoint = this.findBoundaryPointFromRealTimeData(currentPoint, "top");
9879
- }
9881
+ } else if (currentPoint.type === "bottom") {
9882
+ bottomPoint = currentPoint;
9883
+ topPoint = this.findBoundaryPointFromRealTimeData(currentPoint, "top");
9880
9884
  }
9881
9885
  return { topPoint, bottomPoint };
9882
9886
  },
9883
9887
  findBoundaryPointFromRealTimeData(currentPoint, targetType) {
9884
- const axisKey = this.currentToolBarConfig.axisTypeList && this.currentToolBarConfig.axisTypeList[this.formCache.axisType] || (this.formCache.axisType === "time" ? "time" : "depth");
9888
+ const axisType = this.formCache.axisType;
9889
+ const axisKey = this.currentToolBarConfig.axisTypeList && this.currentToolBarConfig.axisTypeList[axisType] || (axisType === "time" ? "time" : "depth");
9885
9890
  const currentYValue = currentPoint.value[1];
9886
9891
  const paramId = currentPoint.paramId;
9892
+ const hasTimestamp = axisType === "depth" && this.realTimeData.length > 0 && this.realTimeData[0] && Object.prototype.hasOwnProperty.call(this.realTimeData[0], "timestamp");
9887
9893
  let searchStartIndex = -1;
9888
- const tolerance = this.formCache.axisType === "depth" ? 0.01 : 1e3;
9894
+ const tolerance = axisType === "depth" ? 0.01 : 1e3;
9889
9895
  for (let i = 0; i < this.realTimeData.length; i++) {
9890
9896
  const item = this.realTimeData[i];
9891
9897
  let itemYValue = item[axisKey];
9892
- if (this.formCache.axisType !== "depth") {
9898
+ if (axisType !== "depth") {
9893
9899
  itemYValue = this.toMillisecondTimestamp(itemYValue);
9894
9900
  } else {
9895
9901
  itemYValue = Number(itemYValue);
9896
9902
  }
9897
- if (Math.abs(itemYValue - currentYValue) < tolerance) {
9898
- searchStartIndex = i;
9899
- break;
9903
+ if (hasTimestamp) {
9904
+ const itemTimestamp = this.toMillisecondTimestamp(item.timestamp);
9905
+ const pointTimestamp = currentPoint.timestamp ? this.toMillisecondTimestamp(currentPoint.timestamp) : null;
9906
+ if (Math.abs(itemYValue - currentYValue) < tolerance && (!pointTimestamp || itemTimestamp === pointTimestamp)) {
9907
+ searchStartIndex = i;
9908
+ break;
9909
+ }
9910
+ } else {
9911
+ if (Math.abs(itemYValue - currentYValue) < tolerance) {
9912
+ searchStartIndex = i;
9913
+ break;
9914
+ }
9900
9915
  }
9901
9916
  }
9917
+ console.log("searchStartIndex", searchStartIndex);
9902
9918
  if (searchStartIndex === -1) return null;
9903
9919
  let boundaryPoint = null;
9904
9920
  if (targetType === "bottom") {
@@ -9907,17 +9923,18 @@ const _sfc_main$2 = {
9907
9923
  const value = item[paramId];
9908
9924
  if (value !== null && value !== void 0 && value !== "" && Number.isFinite(+value)) {
9909
9925
  let itemYValue = item[axisKey];
9910
- if (this.formCache.axisType !== "depth") {
9926
+ if (axisType !== "depth") {
9911
9927
  itemYValue = this.toMillisecondTimestamp(itemYValue);
9912
9928
  } else {
9913
9929
  itemYValue = Number(itemYValue);
9914
9930
  }
9915
9931
  boundaryPoint = {
9916
- value: [value, itemYValue],
9932
+ value: [value, itemYValue, item.timestamp],
9917
9933
  lineId: currentPoint.lineId,
9918
9934
  paramId,
9919
9935
  type: "bottom",
9920
- originalIndex: i
9936
+ originalIndex: i,
9937
+ timestamp: hasTimestamp ? item.timestamp : void 0
9921
9938
  };
9922
9939
  break;
9923
9940
  }
@@ -9925,17 +9942,18 @@ const _sfc_main$2 = {
9925
9942
  if (!boundaryPoint) {
9926
9943
  const lastItem = this.realTimeData[this.realTimeData.length - 1];
9927
9944
  let lastYValue = lastItem[axisKey];
9928
- if (this.formCache.axisType !== "depth") {
9945
+ if (axisType !== "depth") {
9929
9946
  lastYValue = this.toMillisecondTimestamp(lastYValue);
9930
9947
  } else {
9931
9948
  lastYValue = Number(lastYValue);
9932
9949
  }
9933
9950
  boundaryPoint = {
9934
- value: [lastItem[paramId], lastYValue],
9951
+ value: [lastItem[paramId], lastYValue, lastItem.timestamp],
9935
9952
  lineId: currentPoint.lineId,
9936
9953
  paramId,
9937
9954
  type: "bottom",
9938
- originalIndex: this.realTimeData.length - 1
9955
+ originalIndex: this.realTimeData.length - 1,
9956
+ timestamp: hasTimestamp ? lastItem.timestamp : void 0
9939
9957
  };
9940
9958
  }
9941
9959
  } else {
@@ -9944,17 +9962,18 @@ const _sfc_main$2 = {
9944
9962
  const value = item[paramId];
9945
9963
  if (value !== null && value !== void 0 && value !== "" && Number.isFinite(+value)) {
9946
9964
  let itemYValue = item[axisKey];
9947
- if (this.formCache.axisType !== "depth") {
9965
+ if (axisType !== "depth") {
9948
9966
  itemYValue = this.toMillisecondTimestamp(itemYValue);
9949
9967
  } else {
9950
9968
  itemYValue = Number(itemYValue);
9951
9969
  }
9952
9970
  boundaryPoint = {
9953
- value: [value, itemYValue],
9971
+ value: [value, itemYValue, item.timestamp],
9954
9972
  lineId: currentPoint.lineId,
9955
9973
  paramId,
9956
9974
  type: "top",
9957
- originalIndex: i
9975
+ originalIndex: i,
9976
+ timestamp: hasTimestamp ? item.timestamp : void 0
9958
9977
  };
9959
9978
  break;
9960
9979
  }
@@ -9962,17 +9981,18 @@ const _sfc_main$2 = {
9962
9981
  if (!boundaryPoint) {
9963
9982
  const firstItem = this.realTimeData[0];
9964
9983
  let firstYValue = firstItem[axisKey];
9965
- if (this.formCache.axisType !== "depth") {
9984
+ if (axisType !== "depth") {
9966
9985
  firstYValue = this.toMillisecondTimestamp(firstYValue);
9967
9986
  } else {
9968
9987
  firstYValue = Number(firstYValue);
9969
9988
  }
9970
9989
  boundaryPoint = {
9971
- value: [firstItem[paramId], firstYValue],
9990
+ value: [firstItem[paramId], firstYValue, firstItem.timestamp],
9972
9991
  lineId: currentPoint.lineId,
9973
9992
  paramId,
9974
9993
  type: "top",
9975
- originalIndex: 0
9994
+ originalIndex: 0,
9995
+ timestamp: hasTimestamp ? firstItem.timestamp : void 0
9976
9996
  };
9977
9997
  }
9978
9998
  }
@@ -10376,13 +10396,15 @@ const _sfc_main$2 = {
10376
10396
  }
10377
10397
  if (seriesData.length > 0) {
10378
10398
  const firstValidPoint = seriesData.find(
10379
- (point) => Number.isFinite(+point[0])
10399
+ (point) => {
10400
+ return Number.isFinite(+point.value[0]);
10401
+ }
10380
10402
  );
10381
10403
  if (firstValidPoint) {
10382
- seriesData.unshift([min, firstValidPoint[1]]);
10404
+ seriesData.unshift([min, firstValidPoint.value[1]]);
10383
10405
  const lastValidPoint = seriesData[seriesData.length - 1];
10384
- if (lastValidPoint && Number.isFinite(+lastValidPoint[0])) {
10385
- seriesData.push([min, lastValidPoint[1]]);
10406
+ if (lastValidPoint && Number.isFinite(+lastValidPoint.value[0])) {
10407
+ seriesData.push([min, lastValidPoint.value[1]]);
10386
10408
  }
10387
10409
  }
10388
10410
  }
@@ -10603,6 +10625,7 @@ const _sfc_main$2 = {
10603
10625
  const formattedBoundaryPoints = boundaryPoints.map(
10604
10626
  (bp) => ({
10605
10627
  value: bp.data,
10628
+ timestamp: bp.data[2],
10606
10629
  type: bp.type,
10607
10630
  originalIndex: bp.originalIndex,
10608
10631
  lineId: lineInfo.lineId,
@@ -10948,7 +10971,8 @@ const _sfc_main$2 = {
10948
10971
  this.$nextTick(() => {
10949
10972
  this.updateLanesChartOption();
10950
10973
  });
10951
- }
10974
+ },
10975
+ immediate: true
10952
10976
  },
10953
10977
  windowSize: {
10954
10978
  handler(newVal) {
@@ -11317,7 +11341,7 @@ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
11317
11341
  ])
11318
11342
  ], 512);
11319
11343
  }
11320
- const chartContainer = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$2], ["__scopeId", "data-v-d90c5e39"]]);
11344
+ const chartContainer = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$2], ["__scopeId", "data-v-4fbcd1bb"]]);
11321
11345
  const _sfc_main$1 = {
11322
11346
  name: "ParameterPanel",
11323
11347
  props: {