@rfkit/charts 1.2.2 → 1.2.4

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/index.js CHANGED
@@ -7558,6 +7558,43 @@ function toggleSeriesMode(globalID, currentMode) {
7558
7558
  const nextMode = getNextMode(mode);
7559
7559
  setSeriesMode(globalID, nextMode);
7560
7560
  }
7561
+ function initSeriesSubscription(renderer) {
7562
+ const { globalID } = renderer.state;
7563
+ if (!globalID) {
7564
+ console.warn("[Series] globalID is required for series subscription");
7565
+ return null;
7566
+ }
7567
+ const subscriptions = [];
7568
+ subscriptions.push(subscribeToSeries(globalID, events_SeriesEventName.UPDATED, (data)=>{
7569
+ console.log("[Series\u8BA2\u9605] UPDATED\u4E8B\u4EF6\u6536\u5230:", {
7570
+ seriesName: data.seriesName,
7571
+ display: data.config.display,
7572
+ globalID: data.globalID
7573
+ });
7574
+ renderer.setSeries(data.config, true);
7575
+ console.log("[Series\u8BA2\u9605] \u8C03\u7528 draw()");
7576
+ renderer.state.chart?.draw();
7577
+ }));
7578
+ subscriptions.push(subscribeToSeries(globalID, events_SeriesEventName.MODE_CHANGED, ()=>{
7579
+ renderer.initSeries();
7580
+ }));
7581
+ subscriptions.push(subscribeToSeries(globalID, events_SeriesEventName.TYPE_OVERRIDE_CHANGED, ()=>{
7582
+ renderer.initSeries();
7583
+ }));
7584
+ subscriptions.push(subscribeToSeries(globalID, events_SeriesEventName.BATCH_UPDATED, (data)=>{
7585
+ data.configs.forEach((config)=>{
7586
+ renderer.setSeries(config, true);
7587
+ });
7588
+ renderer.state.chart?.draw();
7589
+ }));
7590
+ subscriptions.push(subscribeToSeries(globalID, events_SeriesEventName.RESET, ()=>{
7591
+ if (renderer.state.series) renderer.state.series = {};
7592
+ renderer.initSeries();
7593
+ }));
7594
+ return ()=>{
7595
+ for (const unsubscribe of subscriptions)unsubscribe();
7596
+ };
7597
+ }
7561
7598
  const chartTypeSeriesOverrides = new Map();
7562
7599
  function setChartTypeSeriesOverride(globalID, seriesName, type) {
7563
7600
  if (!chartTypeSeriesOverrides.has(globalID)) chartTypeSeriesOverrides.set(globalID, new Map());
@@ -7644,11 +7681,23 @@ function mergeSeriesConfig(config, existing) {
7644
7681
  }
7645
7682
  function updateSeries(globalID, config) {
7646
7683
  if (!config?.name) return;
7684
+ console.log("[updateSeries] \u5F00\u59CB\u66F4\u65B0:", {
7685
+ globalID,
7686
+ name: config.name,
7687
+ display: config.display
7688
+ });
7647
7689
  const manager = getSeriesManager(globalID);
7648
7690
  const existing = manager.getSeries(config.name);
7691
+ console.log('[updateSeries] existing:', existing);
7649
7692
  const finalConfig = mergeSeriesConfig(config, existing);
7693
+ console.log('[updateSeries] finalConfig:', finalConfig);
7650
7694
  if (existing) manager.removeSeries(config.name);
7651
7695
  manager.addSeries(finalConfig);
7696
+ console.log("[updateSeries] \u53D1\u5E03 UPDATED \u4E8B\u4EF6:", {
7697
+ globalID,
7698
+ seriesName: config.name,
7699
+ display: finalConfig.display
7700
+ });
7652
7701
  events_emitSeriesEvent(events_SeriesEventName.UPDATED, {
7653
7702
  globalID,
7654
7703
  seriesName: config.name,
@@ -10113,29 +10162,7 @@ class Spectrum {
10113
10162
  this.initSeriesSubscription();
10114
10163
  }
10115
10164
  initSeriesSubscription() {
10116
- if (!this.state.globalID) return;
10117
- const subscriptions = [];
10118
- subscriptions.push(subscribeToSeries(this.state.globalID, events_SeriesEventName.UPDATED, (data)=>{
10119
- this.setSeries(data.config, true);
10120
- }));
10121
- subscriptions.push(subscribeToSeries(this.state.globalID, events_SeriesEventName.MODE_CHANGED, ()=>{
10122
- this.initSeries();
10123
- }));
10124
- subscriptions.push(subscribeToSeries(this.state.globalID, events_SeriesEventName.TYPE_OVERRIDE_CHANGED, ()=>{
10125
- this.initSeries();
10126
- }));
10127
- subscriptions.push(subscribeToSeries(this.state.globalID, events_SeriesEventName.BATCH_UPDATED, (data)=>{
10128
- data.configs.forEach((config)=>{
10129
- this.setSeries(config, true);
10130
- });
10131
- }));
10132
- subscriptions.push(subscribeToSeries(this.state.globalID, events_SeriesEventName.RESET, ()=>{
10133
- this.state.series = {};
10134
- this.initSeries();
10135
- }));
10136
- this.seriesUnsubscribe = ()=>{
10137
- for (const unsubscribe of subscriptions)unsubscribe();
10138
- };
10165
+ this.seriesUnsubscribe = initSeriesSubscription(this) || void 0;
10139
10166
  }
10140
10167
  init() {
10141
10168
  const { id, renderRange } = this.state;
@@ -10214,10 +10241,17 @@ class Spectrum {
10214
10241
  const { chart, series, globalID } = this.state;
10215
10242
  const { name } = config;
10216
10243
  if (!chart || !name || !config) return;
10217
- const { type = type_GraphicType.Line, color = SERIES[name]?.color, thickness = 1, display = false } = {
10244
+ console.log("[Spectrum.setSeries] \u6536\u5230\u914D\u7F6E:", {
10245
+ name,
10246
+ display: config.display,
10247
+ skipEventEmit,
10248
+ currentDisplay: series[name]?.display
10249
+ });
10250
+ const merged = {
10218
10251
  ...series[name],
10219
10252
  ...config
10220
10253
  };
10254
+ const { type = type_GraphicType.Line, color = SERIES[name]?.color, thickness = 1, display = false } = merged;
10221
10255
  const c = {
10222
10256
  name,
10223
10257
  type,
@@ -10225,6 +10259,7 @@ class Spectrum {
10225
10259
  thickness,
10226
10260
  display
10227
10261
  };
10262
+ console.log("[Spectrum.setSeries] \u5408\u5E76\u540E\u7684\u914D\u7F6E:", c, "\u539Fmerged:", merged);
10228
10263
  series[name] = c;
10229
10264
  chart.setSeries(c);
10230
10265
  if (!skipEventEmit && globalID) try {
@@ -15628,7 +15663,7 @@ const Zoom_Zoom = ()=>{
15628
15663
  return null;
15629
15664
  };
15630
15665
  const Zoom = Zoom_Zoom;
15631
- const useMarkerPublish = ({ globalID })=>{
15666
+ const useMarkerPublish_useMarkerPublish = ({ globalID })=>{
15632
15667
  const handleMarkerPublish = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((e)=>{
15633
15668
  if (!globalID) return;
15634
15669
  switch(e.pstype){
@@ -15650,7 +15685,7 @@ const useMarkerPublish = ({ globalID })=>{
15650
15685
  handleMarkerPublish
15651
15686
  };
15652
15687
  };
15653
- const hooks_useMarkerPublish = useMarkerPublish;
15688
+ const useMarkerPublish = useMarkerPublish_useMarkerPublish;
15654
15689
  function useTemplateComparison() {
15655
15690
  const { state: { globalID, axisX: { frequencyFormat }, signal: { onChange } } } = useStore_useStore();
15656
15691
  const frequencyFormatRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(frequencyFormat);
@@ -16172,7 +16207,7 @@ const Spectrum_Chart_Chart = (props)=>{
16172
16207
  }
16173
16208
  });
16174
16209
  const handleSpectrumRule = useSpectrumRule();
16175
- const { handleMarkerPublish } = hooks_useMarkerPublish({
16210
+ const { handleMarkerPublish } = useMarkerPublish({
16176
16211
  globalID
16177
16212
  });
16178
16213
  hooks_usePublish({
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.2.2",
8
+ "version": "1.2.4",
9
9
  "private": false
10
10
  }
@@ -58,6 +58,7 @@ export declare function resetSeries(globalID: string): void;
58
58
  export declare function batchUpdateSeries(globalID: string, configs: PartialSeriesConfig[]): void;
59
59
  export * from './events';
60
60
  export * from './modes';
61
+ export * from './subscription';
61
62
  /**
62
63
  * 获取带有正确 GraphicType 的 series 配置
63
64
  * 优先级:ChartType 覆盖 > SeriesMode 配置 > 默认类型
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Series 订阅工具
3
+ * 提供可复用的 series 事件订阅函数
4
+ */
5
+ import type { SeriesConfig } from './index';
6
+ /**
7
+ * Series 渲染器接口
8
+ * 定义渲染器必须实现的方法
9
+ */
10
+ export interface SeriesRenderer {
11
+ state: {
12
+ globalID?: string;
13
+ chart?: {
14
+ draw: () => void;
15
+ };
16
+ series?: Record<string, unknown>;
17
+ };
18
+ setSeries: (config: SeriesConfig, skipEvent?: boolean) => void;
19
+ initSeries: () => void;
20
+ }
21
+ /**
22
+ * 初始化 Series 事件订阅
23
+ *
24
+ * @param renderer 渲染器实例(必须实现 SeriesRenderer 接口)
25
+ * @returns 取消订阅函数
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * class MyRender implements SeriesRenderer {
30
+ * private seriesUnsubscribe: (() => void) | null = null;
31
+ *
32
+ * constructor(props: any) {
33
+ * this.state = { chart: null, globalID: props.globalID };
34
+ * this.seriesUnsubscribe = initSeriesSubscription(this);
35
+ * }
36
+ *
37
+ * destroy() {
38
+ * this.seriesUnsubscribe?.();
39
+ * }
40
+ * }
41
+ * ```
42
+ */
43
+ export declare function initSeriesSubscription(renderer: SeriesRenderer): (() => void) | null;