Skip to content

Commit 5309d0d

Browse files
committed
feat: frequency add handle
1 parent c7e30b2 commit 5309d0d

File tree

2 files changed

+65
-11
lines changed

2 files changed

+65
-11
lines changed

src/pages/Feature/D3/DataDemo.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ const Frequency = () => {
9797
// 创建主组用于内容绘制
9898
const mainGroup = svg.append('g').attr('transform', `translate(${margin.left},${margin.top})`);
9999

100+
// 将频率标记组添加到最底层
101+
const frequencyMarkerGroup = svg.append('g').attr('class', 'frequency-markers').style('pointer-events', 'none');
102+
100103
// 创建等距比例尺
101104
const xScale: any = d3
102105
.scalePoint()
@@ -557,6 +560,57 @@ const Frequency = () => {
557560
return leftPos + (rightPos - leftPos) * progress;
558561
};
559562

563+
// const targetFrequencyRange = [1000000, 140000000];
564+
const targetFrequencyRange: any = [];
565+
566+
// 如果是第一个类型组,添加频率标记
567+
if (targetFrequencyRange.length > 0) {
568+
const startX = getXPosition(targetFrequencyRange[0]);
569+
const endX = getXPosition(targetFrequencyRange[1]);
570+
571+
if (startX !== null && endX !== null) {
572+
// 添加范围背景
573+
frequencyMarkerGroup
574+
.append('rect')
575+
.attr('x', startX) // 从顶部开始
576+
.attr('y', 0) // 从顶部开始
577+
.attr('width', endX - startX) // 到底部结束
578+
.attr('height', totalHeight - margin.bottom) // 到底部结束
579+
.attr('fill', 'green')
580+
.attr('opacity', 0.1)
581+
.style('pointer-events', 'none');
582+
583+
// 添加标记线
584+
[startX, endX].forEach((x) => {
585+
frequencyMarkerGroup
586+
.append('line')
587+
.attr('x1', x) // 从顶部开始
588+
.attr('y1', 0) // 从顶部开始
589+
.attr('x2', x) // 到底部结束
590+
.attr('y2', totalHeight - margin.bottom) // 到底部结束
591+
.attr('stroke', 'green')
592+
.attr('stroke-width', 2)
593+
.style('pointer-events', 'none');
594+
});
595+
596+
// // 添加频率标签
597+
// [
598+
// { x: startX, freq: targetFrequencyRange[0], align: 'start' },
599+
// { x: endX, freq: targetFrequencyRange[1], align: 'end' }
600+
// ].forEach(({ x, freq, align }) => {
601+
// mainGroup
602+
// .append('text')
603+
// .attr('x', x)
604+
// .attr('y', -margin.top - 10)
605+
// .attr('text-anchor', align)
606+
// .attr('fill', 'green')
607+
// .attr('font-size', '12px')
608+
// .text(formatFrequency(freq))
609+
// .style('pointer-events', 'none');
610+
// });
611+
}
612+
}
613+
560614
// 绘制频率块
561615
typeData.ranges.forEach((freq: any, i: any) => {
562616
const startX = getXPosition(freq.range[0]);

src/pages/Feature/D3/components/DataUnit.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ export const data: any = [
3535
status: '正常',
3636
},
3737
},
38-
{
39-
frequencyName: '设备A',
40-
range: [35000, 140000000], // 35kHz-140MHz
41-
color: '#4299e1',
42-
slashStyle: { forward: true, backward: false },
43-
customInfo: {
44-
description: '测试设备',
45-
power: '10W',
46-
status: '正常',
47-
},
48-
},
38+
// {
39+
// frequencyName: '设备A',
40+
// range: [35000, 140000000], // 35kHz-140MHz
41+
// color: '#4299e1',
42+
// slashStyle: { forward: true, backward: false },
43+
// customInfo: {
44+
// description: '测试设备',
45+
// power: '10W',
46+
// status: '正常',
47+
// },
48+
// },
4949
{
5050
frequencyName: '设备B',
5151
range: [90000000, 140000000], // 90MHz-140MHz

0 commit comments

Comments
 (0)