|
|
@@ -15,7 +15,6 @@ export interface TopDiagramChartLabels {
|
|
|
coverageAngle: string
|
|
|
}
|
|
|
|
|
|
-// 记录当前画布上的业务图元,避免误删
|
|
|
let currentObjects: any[] = []
|
|
|
|
|
|
function parseHex(color: string): [number, number, number] {
|
|
|
@@ -37,18 +36,33 @@ export function drawTopDiagram(
|
|
|
pal: ChartPalette
|
|
|
): void {
|
|
|
const { splMax, d1, d2, d3, hCov, vCov, dir } = p
|
|
|
+ console.log(p)
|
|
|
|
|
|
// 竖直安装时俯视图用水平指向角,反之亦然
|
|
|
const cov = dir === 'H' ? vCov : hCov
|
|
|
const maxD = Math.max(d1, d2, d3, 5) * 1.2
|
|
|
+ const isSymmetric = p.isSymmetric === true
|
|
|
|
|
|
- // JSXGraph 中,0° 是向右(X轴正方向),逆时针为正。
|
|
|
- // 为了对称,我们从 -cov/2 画到 +cov/2
|
|
|
const t6Rad = (cov / 2) * DEG
|
|
|
- const startAngle = -t6Rad
|
|
|
- const endAngle = t6Rad
|
|
|
const isFullCircle = cov >= 359.9
|
|
|
|
|
|
+ // 核心改动:定义所有需要绘制的扇区区间
|
|
|
+ const sectors: Array<{ start: number; end: number }> = []
|
|
|
+ if (isFullCircle) {
|
|
|
+ // 如果是全圆,左右画会重叠,直接画一个 0-360 度的扇区即可
|
|
|
+ sectors.push({ start: 0, end: Math.PI * 2 })
|
|
|
+ } else {
|
|
|
+ // 正向扇区
|
|
|
+ sectors.push({ start: -t6Rad, end: t6Rad })
|
|
|
+ // 如果开启对称,增加一个反方向的扇区(以 Y 轴为界镜像)
|
|
|
+ if (isSymmetric) {
|
|
|
+ sectors.push({
|
|
|
+ start: Math.PI - t6Rad,
|
|
|
+ end: Math.PI + t6Rad
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
board.suspendUpdate()
|
|
|
try {
|
|
|
// 1. 安全清理旧图元
|
|
|
@@ -62,7 +76,6 @@ export function drawTopDiagram(
|
|
|
attrs.withLabel = false
|
|
|
attrs.showInfobox = false
|
|
|
}
|
|
|
- // 核心修复:加入 fixed: true,彻底禁止拖拽
|
|
|
attrs.highlight = false
|
|
|
attrs.fixed = true
|
|
|
const obj = board.create(type as any, args, attrs)
|
|
|
@@ -73,7 +86,6 @@ export function drawTopDiagram(
|
|
|
|
|
|
// 2. 画极坐标网格 (同心圆和射线)
|
|
|
const gD = maxD / 5
|
|
|
- // 同心圆
|
|
|
for (let r = gD; r < maxD; r += gD) {
|
|
|
addObj('circle', [pt(0, 0), r], {
|
|
|
strokeColor: pal.border,
|
|
|
@@ -83,15 +95,17 @@ export function drawTopDiagram(
|
|
|
layer: 0
|
|
|
})
|
|
|
}
|
|
|
- // 横向与纵向基准轴线
|
|
|
+
|
|
|
+ // 横向基准轴线:如果开启对称,X 轴左侧也要相应延伸
|
|
|
addObj(
|
|
|
'segment',
|
|
|
[
|
|
|
- [-maxD * 0.1, 0],
|
|
|
+ [-maxD * (isSymmetric ? 1.1 : 0.1), 0],
|
|
|
[maxD * 1.1, 0]
|
|
|
],
|
|
|
{ strokeColor: pal.dim, strokeWidth: 1.5, lastArrow: true, layer: 1 }
|
|
|
)
|
|
|
+ // 纵向基准轴线
|
|
|
addObj(
|
|
|
'segment',
|
|
|
[
|
|
|
@@ -135,7 +149,7 @@ export function drawTopDiagram(
|
|
|
layer: 1
|
|
|
})
|
|
|
|
|
|
- // 3. 画 SPL 分层扇形背景(半透明雷达图效果)
|
|
|
+ // 3. 画 SPL 分层扇形背景
|
|
|
const layers = 24
|
|
|
const [br, bg, bb] = parseHex(pal.accent)
|
|
|
const splAtMaxD = splAt(maxD, p)
|
|
|
@@ -150,49 +164,56 @@ export function drawTopDiagram(
|
|
|
const spl = splAt(rMid, p)
|
|
|
const splRatio = Math.max(0, Math.min(1, (spl - splAtMaxD) / splRange))
|
|
|
const alpha = 0.08 + splRatio * 0.82
|
|
|
- const fillHex = `#${br.toString(16).padStart(2, '0')}${bg.toString(16).padStart(2, '0')}${bb.toString(16).padStart(2, '0')}`
|
|
|
+ const fillHex = `#${br.toString(16).padStart(2, '0')}${bg
|
|
|
+ .toString(16)
|
|
|
+ .padStart(2, '0')}${bb.toString(16).padStart(2, '0')}`
|
|
|
|
|
|
- const xCoords: number[] = []
|
|
|
- const yCoords: number[] = []
|
|
|
- for (let j = 0; j <= steps; j++) {
|
|
|
- const a = startAngle + ((endAngle - startAngle) * j) / steps
|
|
|
- xCoords.push(Math.cos(a) * rOuter)
|
|
|
- yCoords.push(Math.sin(a) * rOuter)
|
|
|
- }
|
|
|
- for (let j = steps; j >= 0; j--) {
|
|
|
- const a = startAngle + ((endAngle - startAngle) * j) / steps
|
|
|
- xCoords.push(Math.cos(a) * rInner)
|
|
|
- yCoords.push(Math.sin(a) * rInner)
|
|
|
- }
|
|
|
- xCoords.push(Math.cos(startAngle) * rOuter)
|
|
|
- yCoords.push(Math.sin(startAngle) * rOuter)
|
|
|
+ // 遍历扇区(如果有两个,就画两个一模一样的分层)
|
|
|
+ sectors.forEach((sec) => {
|
|
|
+ const xCoords: number[] = []
|
|
|
+ const yCoords: number[] = []
|
|
|
+ for (let j = 0; j <= steps; j++) {
|
|
|
+ const a = sec.start + ((sec.end - sec.start) * j) / steps
|
|
|
+ xCoords.push(Math.cos(a) * rOuter)
|
|
|
+ yCoords.push(Math.sin(a) * rOuter)
|
|
|
+ }
|
|
|
+ for (let j = steps; j >= 0; j--) {
|
|
|
+ const a = sec.start + ((sec.end - sec.start) * j) / steps
|
|
|
+ xCoords.push(Math.cos(a) * rInner)
|
|
|
+ yCoords.push(Math.sin(a) * rInner)
|
|
|
+ }
|
|
|
+ xCoords.push(Math.cos(sec.start) * rOuter)
|
|
|
+ yCoords.push(Math.sin(sec.start) * rOuter)
|
|
|
|
|
|
- addObj('curve', [xCoords, yCoords], {
|
|
|
- fillColor: fillHex,
|
|
|
- fillOpacity: alpha,
|
|
|
- strokeColor: 'none',
|
|
|
- layer: 2
|
|
|
+ addObj('curve', [xCoords, yCoords], {
|
|
|
+ fillColor: fillHex,
|
|
|
+ fillOpacity: alpha,
|
|
|
+ strokeColor: 'none',
|
|
|
+ layer: 2
|
|
|
+ })
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// 4. -6dB 边界虚线
|
|
|
if (!isFullCircle) {
|
|
|
- addObj(
|
|
|
- 'segment',
|
|
|
- [
|
|
|
- [0, 0],
|
|
|
- [maxD * Math.cos(startAngle), maxD * Math.sin(startAngle)]
|
|
|
- ],
|
|
|
- { strokeColor: pal.accent, dash: 2, layer: 3 }
|
|
|
- )
|
|
|
- addObj(
|
|
|
- 'segment',
|
|
|
- [
|
|
|
- [0, 0],
|
|
|
- [maxD * Math.cos(endAngle), maxD * Math.sin(endAngle)]
|
|
|
- ],
|
|
|
- { strokeColor: pal.accent, dash: 2, layer: 3 }
|
|
|
- )
|
|
|
+ sectors.forEach((sec) => {
|
|
|
+ addObj(
|
|
|
+ 'segment',
|
|
|
+ [
|
|
|
+ [0, 0],
|
|
|
+ [maxD * Math.cos(sec.start), maxD * Math.sin(sec.start)]
|
|
|
+ ],
|
|
|
+ { strokeColor: pal.accent, dash: 2, layer: 3 }
|
|
|
+ )
|
|
|
+ addObj(
|
|
|
+ 'segment',
|
|
|
+ [
|
|
|
+ [0, 0],
|
|
|
+ [maxD * Math.cos(sec.end), maxD * Math.sin(sec.end)]
|
|
|
+ ],
|
|
|
+ { strokeColor: pal.accent, dash: 2, layer: 3 }
|
|
|
+ )
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
// 5. 中心声轴(橙色粗线)
|
|
|
@@ -204,6 +225,17 @@ export function drawTopDiagram(
|
|
|
],
|
|
|
{ strokeColor: pal.accent, strokeWidth: 2.5, layer: 4 }
|
|
|
)
|
|
|
+ // 如果是对称覆盖,Y轴左侧的声轴也要画出来
|
|
|
+ if (isSymmetric) {
|
|
|
+ addObj(
|
|
|
+ 'segment',
|
|
|
+ [
|
|
|
+ [0, 0],
|
|
|
+ [-maxD, 0]
|
|
|
+ ],
|
|
|
+ { strokeColor: pal.accent, strokeWidth: 2.5, layer: 4 }
|
|
|
+ )
|
|
|
+ }
|
|
|
|
|
|
// 覆盖角标签(右上角)
|
|
|
if (!isFullCircle) {
|
|
|
@@ -220,19 +252,21 @@ export function drawTopDiagram(
|
|
|
const rings = [d1, d2, d3].sort((a, b) => a - b)
|
|
|
rings.forEach((r) => {
|
|
|
if (r > 0 && r <= maxD) {
|
|
|
- const xCoords: number[] = []
|
|
|
- const yCoords: number[] = []
|
|
|
- for (let j = 0; j <= steps; j++) {
|
|
|
- const a = startAngle + ((endAngle - startAngle) * j) / steps
|
|
|
- xCoords.push(Math.cos(a) * r)
|
|
|
- yCoords.push(Math.sin(a) * r)
|
|
|
- }
|
|
|
- addObj('curve', [xCoords, -yCoords], {
|
|
|
- strokeColor: pal.text,
|
|
|
- strokeWidth: 0.5,
|
|
|
- dash: 2,
|
|
|
- strokeOpacity: 0.3,
|
|
|
- layer: 3
|
|
|
+ sectors.forEach((sec) => {
|
|
|
+ const xCoords: number[] = []
|
|
|
+ const yCoords: number[] = []
|
|
|
+ for (let j = 0; j <= steps; j++) {
|
|
|
+ const a = sec.start + ((sec.end - sec.start) * j) / steps
|
|
|
+ xCoords.push(Math.cos(a) * r)
|
|
|
+ yCoords.push(Math.sin(a) * r)
|
|
|
+ }
|
|
|
+ addObj('curve', [xCoords, -yCoords], {
|
|
|
+ strokeColor: pal.text,
|
|
|
+ strokeWidth: 0.5,
|
|
|
+ dash: 2,
|
|
|
+ strokeOpacity: 0.3,
|
|
|
+ layer: 3
|
|
|
+ })
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
@@ -245,29 +279,38 @@ export function drawTopDiagram(
|
|
|
]
|
|
|
const sortedPts = [...pts].sort((a, b) => a.d - b.d)
|
|
|
|
|
|
+ // 如果是对称的,我们不仅要在正向(正 X 轴)画点,还要在反向(负 X 轴)画点
|
|
|
+ const xSigns = isSymmetric ? [1, -1] : [1]
|
|
|
+
|
|
|
sortedPts.forEach((ptDef, index) => {
|
|
|
- const x = ptDef.d
|
|
|
- if (x < 0 || x > maxD) return
|
|
|
+ const xBase = ptDef.d
|
|
|
+ if (xBase < 0 || xBase > maxD) return
|
|
|
|
|
|
- const spl = splAt(x, p)
|
|
|
+ const spl = splAt(xBase, p)
|
|
|
|
|
|
- // 画点
|
|
|
- addObj('point', [x, 0], {
|
|
|
- size: 4,
|
|
|
- fillColor: ptDef.c,
|
|
|
- strokeColor: pal.bg,
|
|
|
- strokeWidth: 1.5,
|
|
|
- layer: 4
|
|
|
- })
|
|
|
- const textY = maxD * 0.06
|
|
|
+ // 遍历符号(左右各画一份点与标签)
|
|
|
+ xSigns.forEach((sign) => {
|
|
|
+ const x = xBase * sign
|
|
|
|
|
|
- addObj('text', [x, textY - maxD * 0.03, ptDef.lbl], {
|
|
|
- fontSize: 10,
|
|
|
- color: ptDef.c,
|
|
|
- anchorX: 'center',
|
|
|
- anchorY: 'bottom',
|
|
|
- layer: 10
|
|
|
+ addObj('point', [x, 0], {
|
|
|
+ size: 4,
|
|
|
+ fillColor: ptDef.c,
|
|
|
+ strokeColor: pal.bg,
|
|
|
+ strokeWidth: 1.5,
|
|
|
+ layer: 4
|
|
|
+ })
|
|
|
+ const textY = maxD * 0.06
|
|
|
+
|
|
|
+ addObj('text', [x, textY - maxD * 0.03, ptDef.lbl], {
|
|
|
+ fontSize: 10,
|
|
|
+ color: ptDef.c,
|
|
|
+ anchorX: 'center',
|
|
|
+ anchorY: 'bottom',
|
|
|
+ layer: 10
|
|
|
+ })
|
|
|
})
|
|
|
+
|
|
|
+ // 画图例(统一画在左上角,只画一次)
|
|
|
addObj('point', [-maxD, maxD * (0.9 - 0.1 * index)], {
|
|
|
size: 4,
|
|
|
fillColor: ptDef.c,
|
|
|
@@ -280,7 +323,7 @@ export function drawTopDiagram(
|
|
|
[
|
|
|
-maxD + 1,
|
|
|
maxD * (0.86 - 0.1 * index),
|
|
|
- `${ptDef.lbl} : ${x.toFixed(1)} m, ${spl.toFixed(1)} dB`
|
|
|
+ `${ptDef.lbl} : ${xBase.toFixed(1)} m, ${spl.toFixed(1)} dB`
|
|
|
],
|
|
|
{
|
|
|
fontSize: 11,
|