@rfkit/charts 1.0.93 → 1.0.94
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/README.md +1 -0
- package/config/constants.d.ts +1 -0
- package/config/setting.d.ts +1 -0
- package/engine/type.d.ts +2 -1
- package/index.js +105 -28
- package/modules/Spectrum/render.d.ts +22 -11
- package/package.json +1 -1
- package/types/publish.d.ts +1 -0
package/README.md
CHANGED
package/config/constants.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const SERIES: {
|
|
|
4
4
|
maxData: import("./setting").LineConfig;
|
|
5
5
|
avgData: import("./setting").LineConfig;
|
|
6
6
|
threshold: import("./setting").LineConfig;
|
|
7
|
+
template: import("./setting").LineConfig;
|
|
7
8
|
};
|
|
8
9
|
export declare const SERIES_NAMES: string[];
|
|
9
10
|
export declare const REAL_DATA_NAME: string;
|
package/config/setting.d.ts
CHANGED
package/engine/type.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -3586,6 +3586,13 @@ const defaultConfig = {
|
|
|
3586
3586
|
thickness: 1,
|
|
3587
3587
|
label: "\u95E8\u9650\u503C",
|
|
3588
3588
|
display: false
|
|
3589
|
+
},
|
|
3590
|
+
template: {
|
|
3591
|
+
name: 'template',
|
|
3592
|
+
color: '#eb5b5b',
|
|
3593
|
+
thickness: 1,
|
|
3594
|
+
label: "\u6A21\u677F",
|
|
3595
|
+
display: false
|
|
3589
3596
|
}
|
|
3590
3597
|
},
|
|
3591
3598
|
gradient: {
|
|
@@ -5350,21 +5357,24 @@ var type_GraphicType = /*#__PURE__*/ function(GraphicType) {
|
|
|
5350
5357
|
GraphicType["Line"] = "line";
|
|
5351
5358
|
GraphicType["Stepline"] = "stepline";
|
|
5352
5359
|
GraphicType["Bar"] = "bar";
|
|
5360
|
+
GraphicType["Area"] = "area";
|
|
5353
5361
|
return GraphicType;
|
|
5354
5362
|
}({});
|
|
5355
5363
|
function hexToRGBA(hexColor, alpha) {
|
|
5356
5364
|
const hexRegex = /^#([A-Fa-f0-9]{3}){1,2}$/;
|
|
5357
5365
|
if (!hexRegex.test(hexColor)) throw new Error('Invalid hex color format');
|
|
5358
5366
|
const hex = hexColor.replace('#', '');
|
|
5359
|
-
let r
|
|
5367
|
+
let r;
|
|
5368
|
+
let g;
|
|
5369
|
+
let b;
|
|
5360
5370
|
if (3 === hex.length) {
|
|
5361
|
-
r = parseInt(hex[0] + hex[0], 16);
|
|
5362
|
-
g = parseInt(hex[1] + hex[1], 16);
|
|
5363
|
-
b = parseInt(hex[2] + hex[2], 16);
|
|
5371
|
+
r = Number.parseInt(hex[0] + hex[0], 16);
|
|
5372
|
+
g = Number.parseInt(hex[1] + hex[1], 16);
|
|
5373
|
+
b = Number.parseInt(hex[2] + hex[2], 16);
|
|
5364
5374
|
} else if (6 === hex.length) {
|
|
5365
|
-
r = parseInt(hex.substring(0, 2), 16);
|
|
5366
|
-
g = parseInt(hex.substring(2, 4), 16);
|
|
5367
|
-
b = parseInt(hex.substring(4, 6), 16);
|
|
5375
|
+
r = Number.parseInt(hex.substring(0, 2), 16);
|
|
5376
|
+
g = Number.parseInt(hex.substring(2, 4), 16);
|
|
5377
|
+
b = Number.parseInt(hex.substring(4, 6), 16);
|
|
5368
5378
|
} else throw new Error('Invalid hex color length');
|
|
5369
5379
|
const a = 'number' == typeof alpha ? Math.round(255 * Math.max(0, Math.min(1, alpha))) : 255;
|
|
5370
5380
|
return {
|
|
@@ -5742,6 +5752,56 @@ class Series extends engine_Engine {
|
|
|
5742
5752
|
ctx.fill();
|
|
5743
5753
|
}
|
|
5744
5754
|
}
|
|
5755
|
+
if (type === type_GraphicType.Area) {
|
|
5756
|
+
let points = [];
|
|
5757
|
+
const { r, g, b } = hexToRGBA(color);
|
|
5758
|
+
const drawAreaAndStepline = (pointsToDraw)=>{
|
|
5759
|
+
if (0 === pointsToDraw.length) return;
|
|
5760
|
+
const [firstX, firstY] = pointsToDraw[0];
|
|
5761
|
+
const [lastX, lastY] = pointsToDraw[pointsToDraw.length - 1];
|
|
5762
|
+
const endX = Math.round(lastX + per);
|
|
5763
|
+
ctx.beginPath();
|
|
5764
|
+
ctx.moveTo(firstX, 0);
|
|
5765
|
+
ctx.lineTo(firstX, firstY);
|
|
5766
|
+
for(let j = 1; j < pointsToDraw.length; j++){
|
|
5767
|
+
const [_, prevY] = pointsToDraw[j - 1];
|
|
5768
|
+
const [currX, currY] = pointsToDraw[j];
|
|
5769
|
+
ctx.lineTo(currX, prevY);
|
|
5770
|
+
ctx.lineTo(currX, currY);
|
|
5771
|
+
}
|
|
5772
|
+
ctx.lineTo(endX, lastY);
|
|
5773
|
+
ctx.lineTo(endX, 0);
|
|
5774
|
+
ctx.closePath();
|
|
5775
|
+
const gradient = ctx.createLinearGradient(0, 0, 0, height);
|
|
5776
|
+
gradient.addColorStop(0, `rgba(${r}, ${g}, ${b}, 0)`);
|
|
5777
|
+
gradient.addColorStop(1, `rgba(${r}, ${g}, ${b}, 0.5)`);
|
|
5778
|
+
ctx.fillStyle = gradient;
|
|
5779
|
+
ctx.fill();
|
|
5780
|
+
ctx.beginPath();
|
|
5781
|
+
ctx.moveTo(firstX, firstY);
|
|
5782
|
+
for(let j = 1; j < pointsToDraw.length; j++){
|
|
5783
|
+
const [_, prevY] = pointsToDraw[j - 1];
|
|
5784
|
+
const [currX, currY] = pointsToDraw[j];
|
|
5785
|
+
ctx.lineTo(currX, prevY);
|
|
5786
|
+
ctx.lineTo(currX, currY);
|
|
5787
|
+
}
|
|
5788
|
+
ctx.lineTo(endX, lastY);
|
|
5789
|
+
ctx.lineWidth = thickness;
|
|
5790
|
+
ctx.strokeStyle = color;
|
|
5791
|
+
ctx.stroke();
|
|
5792
|
+
};
|
|
5793
|
+
for(let i = 0; i < len; i += 1){
|
|
5794
|
+
const value = data[i];
|
|
5795
|
+
if (void 0 === value || Number.isNaN(value)) {
|
|
5796
|
+
drawAreaAndStepline(points);
|
|
5797
|
+
points = [];
|
|
5798
|
+
} else points.push([
|
|
5799
|
+
Math.round(i * per),
|
|
5800
|
+
Math.round((value - min) / rangeY * height)
|
|
5801
|
+
]);
|
|
5802
|
+
}
|
|
5803
|
+
drawAreaAndStepline(points);
|
|
5804
|
+
}
|
|
5745
5805
|
if (type === type_GraphicType.Bar) if (orientation === type_OrientationType.Horizontal) {
|
|
5746
5806
|
const h = height / len;
|
|
5747
5807
|
const hh = Math.round(h);
|
|
@@ -7158,6 +7218,9 @@ const AxisYSpectrum = (props)=>{
|
|
|
7158
7218
|
const spectrum = AxisYSpectrum;
|
|
7159
7219
|
const passThroughSeries = (globalID, series)=>subscription_openData(`passThroughSeries-${globalID}`, series, {});
|
|
7160
7220
|
class Spectrum {
|
|
7221
|
+
state;
|
|
7222
|
+
useRangeAutoFocus;
|
|
7223
|
+
firstRenderAutoFocus;
|
|
7161
7224
|
constructor(props){
|
|
7162
7225
|
this.state = {
|
|
7163
7226
|
chart: null,
|
|
@@ -7167,8 +7230,10 @@ class Spectrum {
|
|
|
7167
7230
|
renderRange: RANGE_DEFAULT,
|
|
7168
7231
|
interval: 1,
|
|
7169
7232
|
series: {},
|
|
7233
|
+
globalID: '',
|
|
7170
7234
|
...props
|
|
7171
7235
|
};
|
|
7236
|
+
this.firstRenderAutoFocus = false;
|
|
7172
7237
|
this.init();
|
|
7173
7238
|
}
|
|
7174
7239
|
init() {
|
|
@@ -7182,6 +7247,11 @@ class Spectrum {
|
|
|
7182
7247
|
this.setSeries(JSON.parse(JSON.stringify(config)));
|
|
7183
7248
|
return config;
|
|
7184
7249
|
});
|
|
7250
|
+
this.setSeries({
|
|
7251
|
+
...SERIES.template,
|
|
7252
|
+
type: type_GraphicType.Area,
|
|
7253
|
+
display: true
|
|
7254
|
+
});
|
|
7185
7255
|
this.useRangeAutoFocus = ()=>{
|
|
7186
7256
|
useRangeAutoFocus(this.state.globalID)();
|
|
7187
7257
|
};
|
|
@@ -7193,7 +7263,7 @@ class Spectrum {
|
|
|
7193
7263
|
for(let i = 0; i < s.length; i += 1){
|
|
7194
7264
|
const [name] = s[i];
|
|
7195
7265
|
const data = d[name];
|
|
7196
|
-
if (data && constants_SERIES_NAMES.includes(name)) {
|
|
7266
|
+
if (data && (constants_SERIES_NAMES.includes(name) || 'template' === name)) {
|
|
7197
7267
|
chart.render({
|
|
7198
7268
|
name,
|
|
7199
7269
|
data
|
|
@@ -7202,15 +7272,13 @@ class Spectrum {
|
|
|
7202
7272
|
}
|
|
7203
7273
|
}
|
|
7204
7274
|
}
|
|
7205
|
-
if (extraData) {
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
|
|
7209
|
-
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
});
|
|
7213
|
-
}
|
|
7275
|
+
if (extraData) for (const [name, { outputData }] of extraData){
|
|
7276
|
+
const seriesConfig = series[name];
|
|
7277
|
+
if (outputData) chart.render({
|
|
7278
|
+
...seriesConfig,
|
|
7279
|
+
name,
|
|
7280
|
+
data: outputData
|
|
7281
|
+
});
|
|
7214
7282
|
}
|
|
7215
7283
|
}
|
|
7216
7284
|
updateMainSeries(data) {
|
|
@@ -13216,6 +13284,7 @@ function useSpectrumAnalyzer(props) {
|
|
|
13216
13284
|
const extraOutputData = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(new Map());
|
|
13217
13285
|
const occupancyData = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(new Float32Array());
|
|
13218
13286
|
const totalOccupancyData = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(0);
|
|
13287
|
+
const templateData = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(new Float32Array());
|
|
13219
13288
|
const { series, updateSeries, resetSeries } = useSeries();
|
|
13220
13289
|
const getExtraData = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((data)=>{
|
|
13221
13290
|
const len = srcIndexCache.current?.length;
|
|
@@ -13246,10 +13315,6 @@ function useSpectrumAnalyzer(props) {
|
|
|
13246
13315
|
outputData: getExtraData(data),
|
|
13247
13316
|
originalData: data
|
|
13248
13317
|
});
|
|
13249
|
-
tools(globalIDRef.current, constants_ModuleType.Spectrum)({
|
|
13250
|
-
pstype: constants_PSType.Render,
|
|
13251
|
-
extraData: extraOutputData.current
|
|
13252
|
-
});
|
|
13253
13318
|
const db = withDatabase(globalIDRef.current);
|
|
13254
13319
|
db.spectrumExtra = extraOutputData.current;
|
|
13255
13320
|
}
|
|
@@ -13277,6 +13342,17 @@ function useSpectrumAnalyzer(props) {
|
|
|
13277
13342
|
}, [
|
|
13278
13343
|
getExtraData
|
|
13279
13344
|
]);
|
|
13345
|
+
const updateTemplateData = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((data)=>{
|
|
13346
|
+
if (!data) return;
|
|
13347
|
+
if (globalIDRef.current) {
|
|
13348
|
+
templateData.current = new Float32Array(data);
|
|
13349
|
+
updateSpectrum({
|
|
13350
|
+
template: getExtraData(templateData.current)
|
|
13351
|
+
});
|
|
13352
|
+
}
|
|
13353
|
+
}, [
|
|
13354
|
+
getExtraData
|
|
13355
|
+
]);
|
|
13280
13356
|
const updateStationInfo = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((data)=>{
|
|
13281
13357
|
if (!data) return;
|
|
13282
13358
|
if (globalIDRef.current) dispatch({
|
|
@@ -13294,7 +13370,8 @@ function useSpectrumAnalyzer(props) {
|
|
|
13294
13370
|
const updateSpectrum = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((renderData)=>{
|
|
13295
13371
|
tools(globalIDRef.current, constants_ModuleType.Spectrum)({
|
|
13296
13372
|
pstype: constants_PSType.Render,
|
|
13297
|
-
data: renderData
|
|
13373
|
+
data: renderData,
|
|
13374
|
+
extraData: extraOutputData.current
|
|
13298
13375
|
});
|
|
13299
13376
|
}, [
|
|
13300
13377
|
srcIndexCache
|
|
@@ -13361,9 +13438,8 @@ function useSpectrumAnalyzer(props) {
|
|
|
13361
13438
|
data: getExtraData(occupancyData.current),
|
|
13362
13439
|
totalOccupancy: totalOccupancyData.current
|
|
13363
13440
|
});
|
|
13364
|
-
if (
|
|
13365
|
-
|
|
13366
|
-
extraData: extraOutputData.current
|
|
13441
|
+
if (templateData.current && templateData.current.length > 0) updateSpectrum({
|
|
13442
|
+
template: getExtraData(templateData.current)
|
|
13367
13443
|
});
|
|
13368
13444
|
}
|
|
13369
13445
|
}, [
|
|
@@ -13384,9 +13460,9 @@ function useSpectrumAnalyzer(props) {
|
|
|
13384
13460
|
db.spectrumExtra = getDefaultData().spectrumExtra;
|
|
13385
13461
|
if (haveSeries) resetSeries();
|
|
13386
13462
|
extraOutputData.current.clear();
|
|
13387
|
-
|
|
13388
|
-
|
|
13389
|
-
|
|
13463
|
+
templateData.current = null;
|
|
13464
|
+
updateSpectrum({
|
|
13465
|
+
template: void 0
|
|
13390
13466
|
});
|
|
13391
13467
|
}, 1);
|
|
13392
13468
|
}, [
|
|
@@ -13406,6 +13482,7 @@ function useSpectrumAnalyzer(props) {
|
|
|
13406
13482
|
if (e.extraData) updateExtraData(e.extraData);
|
|
13407
13483
|
if (e.data) analyzer.current.process(e);
|
|
13408
13484
|
if (e.maxData) analyzer.current.setMaxData(e.maxData);
|
|
13485
|
+
if (e.template) updateTemplateData(e.template);
|
|
13409
13486
|
break;
|
|
13410
13487
|
case constants_PSType.Heatmap:
|
|
13411
13488
|
if (e.data) {
|
|
@@ -1,36 +1,47 @@
|
|
|
1
|
+
import { Series } from '../../engine';
|
|
1
2
|
import type { SeriesConfig } from '../../types';
|
|
2
|
-
export declare const passThroughSeries: (globalID: string, series?:
|
|
3
|
+
export declare const passThroughSeries: (globalID: string, series?: Record<string, SeriesConfig>) => any;
|
|
4
|
+
interface SpectrumState {
|
|
5
|
+
chart: Series | null;
|
|
6
|
+
autoranging: boolean;
|
|
7
|
+
prevAutoRangeTime: number;
|
|
8
|
+
id: string;
|
|
9
|
+
renderRange: [number, number];
|
|
10
|
+
interval: number;
|
|
11
|
+
series: Record<string, SeriesConfig>;
|
|
12
|
+
globalID: string;
|
|
13
|
+
}
|
|
3
14
|
export default class Spectrum {
|
|
4
|
-
|
|
5
|
-
|
|
15
|
+
state: SpectrumState;
|
|
16
|
+
useRangeAutoFocus: () => void;
|
|
17
|
+
firstRenderAutoFocus: boolean;
|
|
18
|
+
constructor(props: Record<string, unknown>);
|
|
6
19
|
init(): void;
|
|
7
20
|
/**
|
|
8
21
|
* 更新数据
|
|
9
22
|
* TODO:可以自定义线
|
|
10
23
|
*/
|
|
11
|
-
updateSeries(d: {
|
|
12
|
-
[x: string]: any;
|
|
13
|
-
[x: number]: any;
|
|
14
|
-
}, extraData?: Map<string, {
|
|
24
|
+
updateSeries(d: Record<string | number, Float32Array>, extraData?: Map<string, {
|
|
15
25
|
outputData: Float32Array;
|
|
16
26
|
originalData: Float32Array;
|
|
17
27
|
}>): void;
|
|
18
28
|
updateMainSeries(data: {
|
|
19
|
-
length:
|
|
20
|
-
at: (arg0: number) => undefined;
|
|
29
|
+
length: number;
|
|
30
|
+
at: (arg0: number) => number | undefined;
|
|
21
31
|
}): void;
|
|
22
32
|
/**
|
|
23
33
|
* 更新参数
|
|
24
34
|
*/
|
|
25
|
-
updateParams(params:
|
|
35
|
+
updateParams(params: Record<string, unknown>): void;
|
|
26
36
|
/**
|
|
27
37
|
* 设置线信息
|
|
28
38
|
*/
|
|
29
39
|
setSeries(config: SeriesConfig): void;
|
|
30
40
|
setDisabledClearRect(disabledClearRect: boolean): void;
|
|
31
|
-
setRange(renderRange?:
|
|
41
|
+
setRange(renderRange?: [number, number]): void;
|
|
32
42
|
zoom(): void;
|
|
33
43
|
reset(): void;
|
|
34
44
|
resize(): void;
|
|
35
45
|
clear(): void;
|
|
36
46
|
}
|
|
47
|
+
export {};
|
package/package.json
CHANGED