@rfkit/charts 1.3.1 → 1.3.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.
@@ -1,3 +1,20 @@
1
+ /**
2
+ * 集成 @rfkit/spectrum-analyzer 的峰值检测能力
3
+ *
4
+ * 改造要点:
5
+ * 1. 优先使用 SpectrumAnalyzer 预处理好的峰值数据(realData.peaks.peaks)
6
+ * 2. 如果没有预处理数据,回退到本地计算(findTopPeaks/findMaxPeak)
7
+ * 3. 保持向后兼容,现有功能不受影响
8
+ *
9
+ * 性能提升:
10
+ * - 消除 updateByData 中的重复峰值计算(每次数据更新都调用)
11
+ * - 峰值检测在 SpectrumAnalyzer 的重采样过程中完成,零额外开销
12
+ *
13
+ * 数据来源:
14
+ * - realData.peaks.peaks[0] = 主峰
15
+ * - realData.peaks.peaks[1] = 次峰
16
+ * - realData.peaks.peaks[n] = 第 n+1 峰(可扩展)
17
+ */
1
18
  import { MarkerEventType } from '../../../config';
2
19
  import type { MarkerType, SetMarker } from '../../../types';
3
20
  interface UseMarkersProps {
@@ -41,6 +58,7 @@ export declare const useMarkers: (props: UseMarkersProps) => {
41
58
  }) => string;
42
59
  resetHover: () => void;
43
60
  toggleMainSecondaryPeaks: () => void;
61
+ toggleMainPeak: () => void;
44
62
  moveToAdjacentPeak: (direction: "left" | "right", markerId: string) => void;
45
63
  setState: import("react").Dispatch<import("react").SetStateAction<MarkerState>>;
46
64
  };
@@ -11,6 +11,8 @@ export declare const MARKER_SELECTION_CHANGE: (id: string, func?: RecursiveFunct
11
11
  selectedId: string | null;
12
12
  }]>) => (...args: any[]) => void;
13
13
  export type MarkerCommand = {
14
+ type: 'main-peak';
15
+ } | {
14
16
  type: 'main-secondary-peaks';
15
17
  } | {
16
18
  type: 'left-peak';
package/index.d.ts CHANGED
@@ -7,5 +7,5 @@ RecursiveObject, // 递归对象 后期会删除
7
7
  Render, Reset, SegmentsOriginal, SeriesConfig, SetAntennaFactor, SetChannels, SetMarker, SetSegments, SetSeries, SetSpectrumBandwidth, SpectrumBandwidth, SpectrumExtraData, StationInfoType } from './types';
8
8
  export { HeatmapCaptureType, MarkerMode } from './types';
9
9
  export { SignalDataType } from './types/store';
10
- export { formatFrequencyUnit, formatFrequencyUnitFromHz, formatFrequencyUnitFromMHz } from './utils';
11
10
  export type { FrequencyUnitResult } from './utils';
11
+ export { formatFrequencyUnit, formatFrequencyUnitFromHz, formatFrequencyUnitFromMHz } from './utils';
package/index.js CHANGED
@@ -10812,6 +10812,10 @@ const Markers_Switch_Switch = ()=>{
10812
10812
  label: "\u53F3\u5CF0\u503C",
10813
10813
  disabled: !hasSelectedMarker
10814
10814
  },
10815
+ {
10816
+ value: 'main-peak',
10817
+ label: "\u4E3B\u5CF0\u503C"
10818
+ },
10815
10819
  {
10816
10820
  value: 'main-secondary-peaks',
10817
10821
  label: "\u4E3B\u6B21\u5CF0\u503C"
@@ -10834,6 +10838,11 @@ const Markers_Switch_Switch = ()=>{
10834
10838
  selectedId: selectedMarkerId
10835
10839
  });
10836
10840
  break;
10841
+ case 'main-peak':
10842
+ if (globalID) MARKER_COMMAND(globalID)({
10843
+ type: 'main-peak'
10844
+ });
10845
+ break;
10837
10846
  case 'main-secondary-peaks':
10838
10847
  if (globalID) MARKER_COMMAND(globalID)({
10839
10848
  type: 'main-secondary-peaks'
@@ -14030,6 +14039,7 @@ const useMarkers = (props)=>{
14030
14039
  onChange
14031
14040
  ]);
14032
14041
  const mainSecondaryPrevSelectedRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
14042
+ const mainPeakPrevSelectedRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
14033
14043
  const toggleMainSecondaryPeaks = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
14034
14044
  setState((prevState)=>{
14035
14045
  const hasMainSecondary = prevState.markers.some((m)=>'mainSecondary' === m.peakTracking);
@@ -14110,6 +14120,76 @@ const useMarkers = (props)=>{
14110
14120
  globalID,
14111
14121
  onChange
14112
14122
  ]);
14123
+ const toggleMainPeak = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
14124
+ setState((prevState)=>{
14125
+ const hasMainPeak = prevState.markers.some((m)=>'mainSecondary' === m.peakTracking && 0 === m.peakRank);
14126
+ if (hasMainPeak) {
14127
+ const nextMarkers = prevState.markers.filter((m)=>!('mainSecondary' === m.peakTracking && 0 === m.peakRank));
14128
+ const restoreId = mainPeakPrevSelectedRef.current;
14129
+ if (restoreId) {
14130
+ const idx = nextMarkers.findIndex((m)=>m.id === restoreId);
14131
+ if (-1 !== idx) nextMarkers[idx] = {
14132
+ ...nextMarkers[idx],
14133
+ select: true
14134
+ };
14135
+ }
14136
+ mainPeakPrevSelectedRef.current = null;
14137
+ setTimeout(()=>{
14138
+ onChange?.(constants_MarkerEventType.Update, nextMarkers);
14139
+ }, 0);
14140
+ return {
14141
+ ...prevState,
14142
+ markers: nextMarkers
14143
+ };
14144
+ }
14145
+ const globalState = getGlobalStoreState(globalID);
14146
+ const maxCount = globalState.marker.maxCount;
14147
+ const availableSlots = maxCount - prevState.markers.length;
14148
+ if (availableSlots < 1) return prevState;
14149
+ mainPeakPrevSelectedRef.current = prevState.markers.find((m)=>m.select)?.id ?? null;
14150
+ const markerId = createGUID();
14151
+ const markerColor = markerColors[prevState.colorIndex % 20];
14152
+ const info = formatMarker({
14153
+ left: 50,
14154
+ id: markerId,
14155
+ color: markerColor,
14156
+ select: false,
14157
+ peak: true,
14158
+ peakTracking: 'mainSecondary',
14159
+ peakRank: 0,
14160
+ frequency: 0,
14161
+ hover: false
14162
+ });
14163
+ const newMarker = {
14164
+ ...info,
14165
+ id: markerId,
14166
+ color: markerColor,
14167
+ select: false,
14168
+ peak: true,
14169
+ peakTracking: 'mainSecondary',
14170
+ peakRank: 0,
14171
+ hover: false
14172
+ };
14173
+ const nextMarkers = [
14174
+ ...prevState.markers,
14175
+ newMarker
14176
+ ].map((m)=>formatMarker(m, {
14177
+ data: dataRef.current
14178
+ }));
14179
+ setTimeout(()=>{
14180
+ onChange?.(constants_MarkerEventType.Update, nextMarkers);
14181
+ }, 0);
14182
+ return {
14183
+ ...prevState,
14184
+ markers: nextMarkers,
14185
+ colorIndex: prevState.colorIndex + 1
14186
+ };
14187
+ });
14188
+ }, [
14189
+ formatMarker,
14190
+ globalID,
14191
+ onChange
14192
+ ]);
14113
14193
  const moveToAdjacentPeak = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((direction, markerId)=>{
14114
14194
  setState((prevState)=>{
14115
14195
  const target = prevState.markers.find((m)=>m.id === markerId);
@@ -14180,6 +14260,7 @@ const useMarkers = (props)=>{
14180
14260
  handleHover,
14181
14261
  resetHover,
14182
14262
  toggleMainSecondaryPeaks,
14263
+ toggleMainPeak,
14183
14264
  moveToAdjacentPeak,
14184
14265
  setState
14185
14266
  };
@@ -14368,7 +14449,7 @@ const Markers = ({ id })=>{
14368
14449
  const EID = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>getEID(id), [
14369
14450
  id
14370
14451
  ]);
14371
- const { markers, createMarker, updateMarkerAttribute, resetMarkers, updateByData, handleHover, resetHover, toggleMainSecondaryPeaks, moveToAdjacentPeak } = useMarkers({
14452
+ const { markers, createMarker, updateMarkerAttribute, resetMarkers, updateByData, handleHover, resetHover, toggleMainSecondaryPeaks, toggleMainPeak, moveToAdjacentPeak } = useMarkers({
14372
14453
  id,
14373
14454
  globalID,
14374
14455
  display,
@@ -14475,6 +14556,7 @@ const Markers = ({ id })=>{
14475
14556
  if (globalID && id) MARKER_COMMAND(globalID, (cmd)=>{
14476
14557
  if (!cmd?.type) return;
14477
14558
  if ('main-secondary-peaks' === cmd.type) return void toggleMainSecondaryPeaks();
14559
+ if ('main-peak' === cmd.type) return void toggleMainPeak();
14478
14560
  if ('left-peak' === cmd.type) return void moveToAdjacentPeak('left', cmd.selectedId);
14479
14561
  if ('right-peak' === cmd.type) return void moveToAdjacentPeak('right', cmd.selectedId);
14480
14562
  });
@@ -14482,7 +14564,8 @@ const Markers = ({ id })=>{
14482
14564
  globalID,
14483
14565
  id,
14484
14566
  moveToAdjacentPeak,
14485
- toggleMainSecondaryPeaks
14567
+ toggleMainSecondaryPeaks,
14568
+ toggleMainPeak
14486
14569
  ]);
14487
14570
  if (!show) return null;
14488
14571
  return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(Zoom_ZoomOffsetContainer, {
package/package.json CHANGED
@@ -5,6 +5,6 @@
5
5
  "types": "index.d.ts",
6
6
  "author": "Hxgh",
7
7
  "license": "MIT",
8
- "version": "1.3.1",
8
+ "version": "1.3.2",
9
9
  "private": false
10
10
  }