@rfkit/charts 1.1.13 → 1.1.15

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,25 +1,38 @@
1
+ interface CounterState {
2
+ id: string;
3
+ count: number;
4
+ all: string[];
5
+ include: string[];
6
+ markers: Record<string | number, unknown[]>;
7
+ }
8
+ interface CounterProps {
9
+ id?: string;
10
+ count?: number;
11
+ all?: string[];
12
+ include?: string[];
13
+ markers?: Record<string | number, unknown[]>;
14
+ }
1
15
  export default class Counter {
2
- [x: string]: any;
3
- constructor(props: any);
4
- add(): any;
5
- remove(no: any): boolean;
16
+ private state;
17
+ constructor(props?: CounterProps);
18
+ add(): string | false;
19
+ remove(no: string): boolean;
6
20
  clear(): void;
7
- destroy(cache: string | any[]): void;
21
+ destroy(cache: string[]): void;
8
22
  /**
9
23
  * 混合onChange,可能包含多个markers实例公用counter
10
24
  *
11
- * @memberof Counter
25
+ * @param id 实例ID
26
+ * @param markers 标记数组
27
+ * @param onChange 变更回调函数
28
+ * @param operationType 操作类型
12
29
  */
13
- onMixChange(id: string | number, markers: any, onChange: (arg0: any, arg1: any[]) => void): void;
14
30
  /**
15
31
  * 更新状态
16
32
  *
17
- * @param {*} p
18
- * @memberof Range
33
+ * @param p 状态更新参数
19
34
  */
20
- setState(p: {
21
- all: any;
22
- include: any;
23
- count: any;
24
- }): void;
35
+ setState(p: Partial<CounterState>): void;
36
+ onMixChange(id: string | number, markers: unknown[], onChange: (markers: unknown[], mix: unknown[], operationType?: string) => void, operationType?: string): void;
25
37
  }
38
+ export {};
@@ -39,7 +39,7 @@ export default class Markers {
39
39
  *
40
40
  * @memberof Markers
41
41
  */
42
- onChange(isDel?: boolean): void;
42
+ onChange(isDel?: boolean, operationType?: string): void;
43
43
  /**
44
44
  * 卸载计数器
45
45
  */
@@ -1,28 +1,35 @@
1
1
  /**
2
2
  * 处理唯一选中
3
3
  */
4
+ type SelecterCallback = (event: {
5
+ select: boolean;
6
+ parentID: string;
7
+ attribute: Record<string, unknown>;
8
+ }) => void;
9
+ interface MarkerAttribute {
10
+ select: boolean;
11
+ [key: string]: unknown;
12
+ }
4
13
  export default class Selecter {
5
- [x: string]: any;
14
+ private state;
6
15
  constructor();
7
16
  /**
8
17
  * 设置当前选中
9
18
  *
10
- * @param {*} parentID 实例的id
11
- * @param {*} id 被选中的marker的id
12
- * @returns
13
- * @memberof Select
19
+ * @param parentID 实例的id
20
+ * @param id 被选中的marker的id
21
+ * @param attribute 标记属性
14
22
  */
15
- set(parentID: string, id: any, attribute: {
16
- select: any;
17
- }): void;
23
+ set(parentID: string, id: string, attribute: MarkerAttribute): void;
18
24
  /**
19
25
  * 取消选中
20
- * @param {*} parentID
26
+ * @param parentID 实例的id
21
27
  */
22
- cancel(parentID: string | number): void;
28
+ cancel(parentID: string): void;
23
29
  /**
24
30
  * 订阅变更
25
- * @param {*} func
31
+ * @param func 回调函数
26
32
  */
27
- subscription(func: any): void;
33
+ subscription(func: SelecterCallback): void;
28
34
  }
35
+ export {};
@@ -53,10 +53,14 @@ export declare const setMarkerMove: (e: MarkerType, segments: SegmentsType, func
53
53
  */
54
54
  export declare const setMarkerBatchAdd: (e: {
55
55
  data: any;
56
+ clear?: boolean;
57
+ [key: string]: any;
56
58
  }, segments: SegmentsType, func: (arg0: {
57
59
  pstype: string;
58
60
  event: string;
59
61
  data: number[];
62
+ clear?: boolean;
63
+ [key: string]: any;
60
64
  }) => void) => void;
61
65
  /**
62
66
  * 峰值算法
@@ -71,7 +71,15 @@ export declare enum MarkerEventType {
71
71
  Add = "add",
72
72
  Del = "del",
73
73
  Reset = "reset",
74
- Move = "move"
74
+ Move = "move",
75
+ Clear = "clear",
76
+ Hover = "hover",
77
+ Update = "update",
78
+ Format = "format",
79
+ Dashed = "dashed",
80
+ Center = "center",
81
+ Ref = "ref",
82
+ Flow = "flow"
75
83
  }
76
84
  export declare enum ToolType {
77
85
  AxisX = "axisX",
package/index.js CHANGED
@@ -3904,6 +3904,14 @@ var constants_MarkerEventType = /*#__PURE__*/ function(MarkerEventType) {
3904
3904
  MarkerEventType["Del"] = "del";
3905
3905
  MarkerEventType["Reset"] = "reset";
3906
3906
  MarkerEventType["Move"] = "move";
3907
+ MarkerEventType["Clear"] = "clear";
3908
+ MarkerEventType["Hover"] = "hover";
3909
+ MarkerEventType["Update"] = "update";
3910
+ MarkerEventType["Format"] = "format";
3911
+ MarkerEventType["Dashed"] = "dashed";
3912
+ MarkerEventType["Center"] = "center";
3913
+ MarkerEventType["Ref"] = "ref";
3914
+ MarkerEventType["Flow"] = "flow";
3907
3915
  return MarkerEventType;
3908
3916
  }({});
3909
3917
  var constants_ToolType = /*#__PURE__*/ function(ToolType) {
@@ -8453,7 +8461,7 @@ const Board = ({ markers, heatmapMode, onChange })=>{
8453
8461
  e.stopPropagation();
8454
8462
  onChange({
8455
8463
  id: i.id,
8456
- event: 'flow'
8464
+ event: constants_MarkerEventType.Flow
8457
8465
  });
8458
8466
  }
8459
8467
  },
@@ -8500,7 +8508,7 @@ const Board = ({ markers, heatmapMode, onChange })=>{
8500
8508
  setActive(null);
8501
8509
  onChange({
8502
8510
  id: i.id,
8503
- event: 'del'
8511
+ event: constants_MarkerEventType.Del
8504
8512
  });
8505
8513
  },
8506
8514
  children: "x"
@@ -8625,20 +8633,21 @@ const Dot = ({ heatmapMode, markers })=>{
8625
8633
  };
8626
8634
  const Markers_Dot = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].memo(Dot);
8627
8635
  class Counter {
8628
- constructor(props){
8629
- this.setState({
8636
+ state;
8637
+ constructor(props = {}){
8638
+ this.state = {
8630
8639
  id: 'id',
8631
8640
  count: 10,
8632
8641
  all: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''),
8633
8642
  include: [],
8634
8643
  markers: {},
8635
8644
  ...props
8636
- });
8645
+ };
8637
8646
  }
8638
8647
  add() {
8639
8648
  const { all, include, count } = this.state;
8640
8649
  if (include.length >= count) return false;
8641
- const difference = all.filter((i)=>-1 === include.indexOf(i));
8650
+ const difference = all.filter((item)=>!include.includes(item));
8642
8651
  const atom = difference[0];
8643
8652
  if (atom) {
8644
8653
  include.push(atom);
@@ -8649,7 +8658,7 @@ class Counter {
8649
8658
  remove(no) {
8650
8659
  const { include } = this.state;
8651
8660
  if (!no || 0 === include.length) return false;
8652
- this.state.include = include.filter((i)=>i !== no);
8661
+ this.state.include = include.filter((item)=>item !== no);
8653
8662
  return true;
8654
8663
  }
8655
8664
  clear() {
@@ -8658,15 +8667,7 @@ class Counter {
8658
8667
  destroy(cache) {
8659
8668
  if (!cache || 0 === cache.length) return;
8660
8669
  const { include } = this.state;
8661
- this.state.include = include.filter((i)=>!cache.includes(i));
8662
- }
8663
- onMixChange(id, markers, onChange) {
8664
- this.state.markers[id] = JSON.parse(JSON.stringify(markers));
8665
- const mix = [];
8666
- Object.values(this.state.markers).forEach((i)=>{
8667
- mix.push(...i);
8668
- });
8669
- onChange?.(markers, mix);
8670
+ this.state.include = include.filter((item)=>!cache.includes(item));
8670
8671
  }
8671
8672
  setState(p) {
8672
8673
  this.state = {
@@ -8674,6 +8675,14 @@ class Counter {
8674
8675
  ...p
8675
8676
  };
8676
8677
  }
8678
+ onMixChange(id, markers, onChange, operationType) {
8679
+ this.state.markers[id] = JSON.parse(JSON.stringify(markers));
8680
+ const mix = [];
8681
+ Object.values(this.state.markers).forEach((markerArray)=>{
8682
+ mix.push(...markerArray);
8683
+ });
8684
+ onChange?.(markers, mix, operationType);
8685
+ }
8677
8686
  }
8678
8687
  const markerColors = getConfig('marker');
8679
8688
  const Markers_COMPONENT_KEY = constants_ToolType.Markers;
@@ -8749,7 +8758,7 @@ class Markers {
8749
8758
  }, 'update');
8750
8759
  info.peak = false;
8751
8760
  markers[index] = info;
8752
- this.onChange();
8761
+ this.onChange(false, constants_MarkerEventType.Move);
8753
8762
  }
8754
8763
  }
8755
8764
  });
@@ -8805,14 +8814,18 @@ class Markers {
8805
8814
  id: ee.id,
8806
8815
  select: true
8807
8816
  });
8808
- this.onChange();
8817
+ this.onChange(false, constants_MarkerEventType.Add);
8809
8818
  }
8810
8819
  }
8811
8820
  updateAttribute(attr) {
8812
8821
  const attribute = attr;
8813
8822
  const { markers, counter, selecter, id: parentID, onDel, heatmapMode } = this.state;
8814
- const { id, peak, select, event, data, refId } = attribute;
8823
+ const { id, peak, select, event, data, refId, clear } = attribute;
8815
8824
  if (event === constants_MarkerEventType.Add) {
8825
+ if (clear) {
8826
+ counter.clear();
8827
+ markers.splice(0, markers.length);
8828
+ }
8816
8829
  if (data?.length) for(let i = 0; i < data.length; i += 1)this.create({
8817
8830
  left: data[i]
8818
8831
  }, true);
@@ -8834,19 +8847,19 @@ class Markers {
8834
8847
  onDel();
8835
8848
  }
8836
8849
  }
8837
- if ('clear' === event) {
8850
+ if (event === constants_MarkerEventType.Clear) {
8838
8851
  markers.forEach((_, index)=>{
8839
8852
  counter.remove(markers[index].label);
8840
8853
  });
8841
8854
  markers.splice(0, markers.length);
8842
8855
  isDel = true;
8843
8856
  }
8844
- if ('dashed' === event) for(let index = 0; index < markers.length; index += 1){
8857
+ if (event === constants_MarkerEventType.Dashed) for(let index = 0; index < markers.length; index += 1){
8845
8858
  const item = markers[index];
8846
8859
  item.dashed = false;
8847
8860
  if (data.includes(item.id)) item.dashed = true;
8848
8861
  }
8849
- if ('center' === event) {
8862
+ if (event === constants_MarkerEventType.Center) {
8850
8863
  const index = markers.findIndex((i)=>i.id === id);
8851
8864
  const center = 50;
8852
8865
  if (index >= 0) {
@@ -8870,7 +8883,7 @@ class Markers {
8870
8883
  }
8871
8884
  }
8872
8885
  }
8873
- if ('format' === event) {
8886
+ if (event === constants_MarkerEventType.Format) {
8874
8887
  const index = markers.findIndex((i)=>i.id === id);
8875
8888
  const { left } = attribute;
8876
8889
  if (index >= 0 && void 0 !== left) markers[index] = this.formatMarker({
@@ -8878,7 +8891,7 @@ class Markers {
8878
8891
  left
8879
8892
  });
8880
8893
  }
8881
- if ('ref' === event) {
8894
+ if (event === constants_MarkerEventType.Ref) {
8882
8895
  const index = markers.findIndex((i)=>i.id === id);
8883
8896
  if (index >= 0) {
8884
8897
  markers[index].refId = refId;
@@ -8908,14 +8921,20 @@ class Markers {
8908
8921
  }
8909
8922
  }
8910
8923
  if (void 0 !== peak && true === peak) return void this.updateByData();
8911
- this.onChange(isDel);
8924
+ let operationType = constants_MarkerEventType.Update;
8925
+ if (event === constants_MarkerEventType.Add) operationType = constants_MarkerEventType.Add;
8926
+ else if (event === constants_MarkerEventType.Del) operationType = constants_MarkerEventType.Del;
8927
+ else if (event === constants_MarkerEventType.Clear) operationType = constants_MarkerEventType.Clear;
8928
+ else if (event === constants_MarkerEventType.Center) operationType = constants_MarkerEventType.Move;
8929
+ else if (event === constants_MarkerEventType.Format) operationType = constants_MarkerEventType.Move;
8930
+ this.onChange(isDel, operationType);
8912
8931
  }
8913
8932
  updateByData(data = this.state.data) {
8914
8933
  this.state.data = data;
8915
8934
  this.formatPeaks?.();
8916
8935
  const { markers } = this.state;
8917
8936
  this.state.markers = markers.map((marker)=>this.formatMarker(marker, 'update'));
8918
- this.onChange();
8937
+ this.onChange(false, constants_MarkerEventType.Update);
8919
8938
  }
8920
8939
  updateParams(e) {
8921
8940
  this.state = {
@@ -8927,7 +8946,7 @@ class Markers {
8927
8946
  const { show } = this.state;
8928
8947
  if (!show) this.reset();
8929
8948
  }
8930
- onChange(isDel = false) {
8949
+ onChange(isDel = false, operationType) {
8931
8950
  const { id, markers, onChange, counter } = this.state;
8932
8951
  if (!isDel) this.state.markers = markers.map((marker)=>{
8933
8952
  const { refId, frequency, level, timestamp } = marker;
@@ -8945,7 +8964,7 @@ class Markers {
8945
8964
  ...refData
8946
8965
  };
8947
8966
  });
8948
- if (markers.length || isDel) counter.onMixChange(id, markers, onChange);
8967
+ if (markers.length || isDel) counter.onMixChange(id, markers, onChange, operationType);
8949
8968
  }
8950
8969
  destroyCounter() {
8951
8970
  const { counter, labelCache } = this.state;
@@ -8959,12 +8978,12 @@ class Markers {
8959
8978
  hoverChange = item.hover;
8960
8979
  item.hover = false;
8961
8980
  }
8962
- if (hoverChange) this.onChange();
8981
+ if (hoverChange) this.onChange(false, constants_MarkerEventType.Reset);
8963
8982
  }
8964
8983
  reset() {
8965
8984
  this.state.markers = [];
8966
8985
  this.state.counter.clear();
8967
- this.onChange(true);
8986
+ this.onChange(true, constants_MarkerEventType.Reset);
8968
8987
  }
8969
8988
  }
8970
8989
  const MARKER_UPDATE_PARAMS = (id, func)=>subscription_createSubscriptionManager(`MARKER_UPDATE_PARAMS-${id}`, '0', func);
@@ -9021,7 +9040,7 @@ const setMarkerMove = (e, segments, func)=>{
9021
9040
  const left = (frequency - start) * 100 / width;
9022
9041
  func?.({
9023
9042
  pstype: constants_PSType.Marker,
9024
- event: 'format',
9043
+ event: constants_MarkerEventType.Format,
9025
9044
  id,
9026
9045
  left
9027
9046
  });
@@ -9029,7 +9048,7 @@ const setMarkerMove = (e, segments, func)=>{
9029
9048
  }
9030
9049
  };
9031
9050
  const setMarkerBatchAdd = (e, segments, func)=>{
9032
- const { data } = e;
9051
+ const { data, ...otherProps } = e;
9033
9052
  const seg = segments[0];
9034
9053
  if (data?.length && seg) {
9035
9054
  const { start, stop } = seg;
@@ -9038,11 +9057,12 @@ const setMarkerBatchAdd = (e, segments, func)=>{
9038
9057
  const r = [];
9039
9058
  for(let i = 0; i < data.length; i += 1){
9040
9059
  const frequency = data[i];
9041
- if (frequency < stop && frequency > start) r.push((frequency - start) * 100 / width);
9060
+ if (frequency <= stop && frequency >= start) r.push((frequency - start) * 100 / width);
9042
9061
  }
9043
9062
  func?.({
9063
+ ...otherProps,
9044
9064
  pstype: constants_PSType.Marker,
9045
- event: 'add',
9065
+ event: constants_MarkerEventType.Add,
9046
9066
  data: r
9047
9067
  });
9048
9068
  }
@@ -9153,7 +9173,7 @@ class FreeMarkers extends Markers {
9153
9173
  }
9154
9174
  }
9155
9175
  }
9156
- if (hoverChange) this.onChange();
9176
+ if (hoverChange) this.onChange(false, constants_MarkerEventType.Hover);
9157
9177
  }
9158
9178
  return isHover;
9159
9179
  }
@@ -9947,7 +9967,7 @@ class LineMarkers extends Markers {
9947
9967
  }
9948
9968
  }
9949
9969
  }
9950
- if (hoverChange) this.onChange();
9970
+ if (hoverChange) this.onChange(false, constants_MarkerEventType.Hover);
9951
9971
  }
9952
9972
  return isHover;
9953
9973
  }
@@ -9971,7 +9991,7 @@ class LineMarkers extends Markers {
9971
9991
  const attribute = attr;
9972
9992
  const { markers } = this.state;
9973
9993
  const { event, id } = attribute;
9974
- if ('flow' === event) {
9994
+ if (event === constants_MarkerEventType.Flow) {
9975
9995
  const index = markers.findIndex((i)=>i.id === id);
9976
9996
  markers[index].flow = {
9977
9997
  name: SERIES.realData.name,
@@ -9981,6 +10001,7 @@ class LineMarkers extends Markers {
9981
10001
  }
9982
10002
  }
9983
10003
  class Selecter {
10004
+ state;
9984
10005
  constructor(){
9985
10006
  this.state = {
9986
10007
  onChange: [],
@@ -10000,7 +10021,7 @@ class Selecter {
10000
10021
  }
10001
10022
  });
10002
10023
  this.state.marker[parentID] = id;
10003
- if (attribute.select) this.state.onChange.forEach((i)=>i?.({
10024
+ if (attribute.select) this.state.onChange.forEach((callback)=>callback?.({
10004
10025
  select: true,
10005
10026
  parentID,
10006
10027
  attribute
@@ -10011,7 +10032,7 @@ class Selecter {
10011
10032
  const { marker } = this.state;
10012
10033
  const all = Object.entries(marker).every(([, v])=>!v);
10013
10034
  if (all) {
10014
- this.state.onChange.forEach((i)=>i?.({
10035
+ this.state.onChange.forEach((callback)=>callback?.({
10015
10036
  select: false,
10016
10037
  parentID,
10017
10038
  attribute: {}
@@ -10027,13 +10048,15 @@ const Markers_Markers = ({ id, counter, selecter, heatmapMode = false })=>{
10027
10048
  const [markers, setMarkers] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)([]);
10028
10049
  const { state: { marker, axisX, axisY, zoom, segments, globalID }, dispatch } = useStore_useStore();
10029
10050
  const { show: markerShow, display, count, onChange, dot: { fixed }, selectMax } = marker;
10030
- const managerOnChange = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((e, mix)=>{
10051
+ const managerOnChange = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((e, mix, operationType)=>{
10031
10052
  const m = mix;
10032
10053
  setMarkers(JSON.parse(JSON.stringify(e)));
10033
10054
  m.heatmapMode = heatmapMode;
10055
+ m.operationType = operationType;
10034
10056
  onChange?.(m);
10035
10057
  }, [
10036
- onChange
10058
+ onChange,
10059
+ heatmapMode
10037
10060
  ]);
10038
10061
  const [manager] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(()=>new (heatmapMode ? FreeMarkers : LineMarkers)({
10039
10062
  id,
@@ -10158,7 +10181,7 @@ const Markers_Markers = ({ id, counter, selecter, heatmapMode = false })=>{
10158
10181
  manager?.updateAttribute({
10159
10182
  id: m.id,
10160
10183
  left: m.left,
10161
- event: 'format'
10184
+ event: constants_MarkerEventType.Format
10162
10185
  });
10163
10186
  }
10164
10187
  if ('ArrowRight' === key) {
@@ -10168,7 +10191,7 @@ const Markers_Markers = ({ id, counter, selecter, heatmapMode = false })=>{
10168
10191
  manager?.updateAttribute({
10169
10192
  id: m.id,
10170
10193
  left: m.left,
10171
- event: 'format'
10194
+ event: constants_MarkerEventType.Format
10172
10195
  });
10173
10196
  }
10174
10197
  }
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.1.13",
8
+ "version": "1.1.15",
9
9
  "private": false
10
10
  }
@@ -40,6 +40,7 @@ export interface SetMarker {
40
40
  event: MarkerEventType;
41
41
  data: number[];
42
42
  heatmapMode?: boolean;
43
+ clear?: boolean;
43
44
  }
44
45
  export interface SpectrumExtraData {
45
46
  [key: string]: Float32Array;