2026-07-20 10:21:30 +08:00
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import { computed } from 'vue'
|
|
|
|
|
|
import { formatTooltipNumber, formatTooltipTime } from '../../utils'
|
|
|
|
|
|
import type { WaveformPoint } from '../data/types'
|
|
|
|
|
|
|
|
|
|
|
|
interface SeriesPoint {
|
|
|
|
|
|
trackIndex: number
|
|
|
|
|
|
name: string
|
2026-08-17 10:14:44 +08:00
|
|
|
|
shotNo?: string
|
2026-07-20 10:21:30 +08:00
|
|
|
|
color: string
|
|
|
|
|
|
unit?: string
|
|
|
|
|
|
point: WaveformPoint
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
|
/** 是否显示 */
|
|
|
|
|
|
visible: boolean
|
|
|
|
|
|
/** 鼠标位置 */
|
|
|
|
|
|
position: { x: number; y: number }
|
|
|
|
|
|
/** 时间单位 */
|
|
|
|
|
|
timeUnit: 's' | 'ms'
|
|
|
|
|
|
/** 悬浮的点 */
|
|
|
|
|
|
hoveredPoint: WaveformPoint | null
|
|
|
|
|
|
/** 所有系列的悬浮点 */
|
|
|
|
|
|
seriesPoints: SeriesPoint[]
|
|
|
|
|
|
/** 容器宽度 */
|
|
|
|
|
|
containerWidth: number
|
|
|
|
|
|
/** 容器高度 */
|
|
|
|
|
|
containerHeight: number
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const props = defineProps<Props>()
|
|
|
|
|
|
|
2026-07-20 17:57:52 +08:00
|
|
|
|
const tooltipGap = 12
|
|
|
|
|
|
const containerPadding = 8
|
2026-08-08 10:43:39 +08:00
|
|
|
|
const tooltipPlacementWidth = 238
|
2026-08-17 10:14:44 +08:00
|
|
|
|
const tooltipMaxWidth = 560
|
2026-08-08 10:43:39 +08:00
|
|
|
|
const tooltipHorizontalPadding = 20
|
|
|
|
|
|
const tooltipLineHeight = 20
|
|
|
|
|
|
|
|
|
|
|
|
function estimateLineCount(text: string, width: number): number {
|
|
|
|
|
|
const contentWidth = Math.max(1, width - tooltipHorizontalPadding - 14)
|
|
|
|
|
|
const charactersPerLine = Math.max(1, Math.floor(contentWidth / 7.2))
|
|
|
|
|
|
return Math.max(1, Math.ceil([...text].length / charactersPerLine))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function formatSeriesText(seriesPoint: SeriesPoint): string {
|
2026-08-17 10:14:44 +08:00
|
|
|
|
const timeText = formatTooltipTime(props.hoveredPoint?.x ?? seriesPoint.point.x, props.timeUnit)
|
|
|
|
|
|
return `${seriesPoint.shotNo?.trim() || '未配置炮号'}: ${seriesPoint.name}${
|
|
|
|
|
|
seriesPoint.unit ? `(${seriesPoint.unit})` : ''
|
|
|
|
|
|
} (x:${timeText} y:${formatTooltipNumber(seriesPoint.point.y)})`
|
2026-08-08 10:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-17 10:14:44 +08:00
|
|
|
|
function estimateTooltipHeight(width: number): number {
|
2026-08-08 10:43:39 +08:00
|
|
|
|
const seriesLines = props.seriesPoints.reduce(
|
|
|
|
|
|
(total, seriesPoint) => total + estimateLineCount(formatSeriesText(seriesPoint), width),
|
|
|
|
|
|
0,
|
|
|
|
|
|
)
|
2026-08-17 10:14:44 +08:00
|
|
|
|
return 16 + tooltipLineHeight * seriesLines + 5
|
2026-08-08 10:43:39 +08:00
|
|
|
|
}
|
2026-07-20 17:57:52 +08:00
|
|
|
|
|
2026-07-20 10:21:30 +08:00
|
|
|
|
const tooltipStyle = computed(() => {
|
|
|
|
|
|
if (!props.visible || !props.hoveredPoint) return { display: 'none' }
|
|
|
|
|
|
|
2026-07-20 17:57:52 +08:00
|
|
|
|
const rightPlacement = props.position.x + tooltipGap
|
2026-08-08 10:43:39 +08:00
|
|
|
|
const leftPlacement = props.position.x - tooltipGap - tooltipPlacementWidth
|
|
|
|
|
|
const rightAvailableWidth = props.containerWidth - containerPadding - rightPlacement
|
|
|
|
|
|
const leftAvailableWidth = props.position.x - tooltipGap - containerPadding
|
|
|
|
|
|
const availableWidth = Math.max(
|
|
|
|
|
|
1,
|
|
|
|
|
|
Math.min(tooltipMaxWidth, props.containerWidth - containerPadding * 2),
|
|
|
|
|
|
)
|
2026-07-20 17:57:52 +08:00
|
|
|
|
const horizontalStyle =
|
2026-08-08 10:43:39 +08:00
|
|
|
|
rightPlacement + tooltipPlacementWidth <= props.containerWidth - containerPadding
|
|
|
|
|
|
? {
|
|
|
|
|
|
left: `${rightPlacement}px`,
|
|
|
|
|
|
maxWidth: `${Math.min(tooltipMaxWidth, rightAvailableWidth)}px`,
|
|
|
|
|
|
}
|
2026-07-20 17:57:52 +08:00
|
|
|
|
: leftPlacement >= containerPadding
|
2026-08-08 10:43:39 +08:00
|
|
|
|
? {
|
|
|
|
|
|
right: `${props.containerWidth - props.position.x + tooltipGap}px`,
|
|
|
|
|
|
maxWidth: `${Math.min(tooltipMaxWidth, leftAvailableWidth)}px`,
|
|
|
|
|
|
}
|
|
|
|
|
|
: { left: `${containerPadding}px`, maxWidth: `${availableWidth}px` }
|
|
|
|
|
|
|
|
|
|
|
|
const maxWidth = Number.parseFloat(horizontalStyle.maxWidth)
|
2026-07-20 10:21:30 +08:00
|
|
|
|
return {
|
2026-07-20 17:57:52 +08:00
|
|
|
|
...horizontalStyle,
|
2026-08-08 10:43:39 +08:00
|
|
|
|
top: `${Math.max(
|
|
|
|
|
|
8,
|
|
|
|
|
|
Math.min(
|
|
|
|
|
|
props.position.y - 18,
|
2026-08-17 10:14:44 +08:00
|
|
|
|
props.containerHeight - estimateTooltipHeight(maxWidth) - 8,
|
2026-08-08 10:43:39 +08:00
|
|
|
|
),
|
|
|
|
|
|
)}px`,
|
2026-07-20 10:21:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
2026-07-20 17:57:52 +08:00
|
|
|
|
|
2026-07-20 10:21:30 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-if="visible && hoveredPoint"
|
|
|
|
|
|
class="waveform-tooltip waveform-chart__tooltip"
|
|
|
|
|
|
:style="tooltipStyle"
|
|
|
|
|
|
>
|
|
|
|
|
|
<span
|
|
|
|
|
|
v-for="seriesPoint in seriesPoints"
|
|
|
|
|
|
:key="`${seriesPoint.trackIndex}-${seriesPoint.name}`"
|
|
|
|
|
|
class="waveform-tooltip__series waveform-chart__tooltip-series"
|
|
|
|
|
|
>
|
|
|
|
|
|
<i :style="{ backgroundColor: seriesPoint.color }" />
|
2026-08-08 10:43:39 +08:00
|
|
|
|
<span class="waveform-tooltip__series-content">
|
2026-08-17 10:14:44 +08:00
|
|
|
|
<span class="waveform-tooltip__series-label">{{ seriesPoint.shotNo?.trim() || '未配置炮号' }}: {{
|
|
|
|
|
|
seriesPoint.name
|
|
|
|
|
|
}}<template v-if="seriesPoint.unit">({{ seriesPoint.unit }})</template></span>
|
|
|
|
|
|
<span class="waveform-tooltip__value">(x:{{ formatTooltipTime(hoveredPoint.x, timeUnit) }} y:{{
|
|
|
|
|
|
formatTooltipNumber(seriesPoint.point.y)
|
|
|
|
|
|
}})</span>
|
2026-07-20 10:21:30 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.waveform-tooltip {
|
2026-07-20 17:57:52 +08:00
|
|
|
|
box-sizing: border-box;
|
2026-07-20 10:21:30 +08:00
|
|
|
|
position: absolute;
|
|
|
|
|
|
z-index: 2;
|
|
|
|
|
|
display: grid;
|
2026-08-17 10:14:44 +08:00
|
|
|
|
gap: 2px;
|
2026-08-08 10:43:39 +08:00
|
|
|
|
width: max-content;
|
2026-08-17 10:14:44 +08:00
|
|
|
|
max-width: min(560px, calc(100% - 16px));
|
|
|
|
|
|
padding: 9px 12px;
|
|
|
|
|
|
color: #505050;
|
|
|
|
|
|
font: 14px/1.35 Arial, sans-serif;
|
2026-07-20 10:21:30 +08:00
|
|
|
|
pointer-events: none;
|
|
|
|
|
|
background: #fff;
|
2026-08-17 10:14:44 +08:00
|
|
|
|
border: 1px solid #e3e7eb;
|
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
box-shadow: 0 3px 10px rgb(16 24 40 / 15%);
|
2026-07-20 10:21:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.waveform-tooltip__series {
|
|
|
|
|
|
display: grid;
|
2026-08-08 10:43:39 +08:00
|
|
|
|
grid-template-columns: 8px minmax(0, 1fr);
|
2026-07-20 10:21:30 +08:00
|
|
|
|
gap: 6px;
|
2026-08-08 10:43:39 +08:00
|
|
|
|
align-items: start;
|
2026-07-20 10:21:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.waveform-tooltip__series i {
|
2026-08-08 10:43:39 +08:00
|
|
|
|
flex: 0 0 auto;
|
2026-07-20 10:21:30 +08:00
|
|
|
|
width: 8px;
|
|
|
|
|
|
height: 8px;
|
2026-08-08 10:43:39 +08:00
|
|
|
|
margin-top: 4px;
|
2026-07-20 10:21:30 +08:00
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-08 10:43:39 +08:00
|
|
|
|
.waveform-tooltip__series-content {
|
2026-08-17 10:14:44 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-wrap: nowrap;
|
|
|
|
|
|
gap: 12px;
|
|
|
|
|
|
align-items: baseline;
|
|
|
|
|
|
min-width: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.waveform-tooltip__series-label {
|
|
|
|
|
|
flex: 1 1 auto;
|
2026-08-08 10:43:39 +08:00
|
|
|
|
min-width: 0;
|
2026-08-17 10:14:44 +08:00
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.waveform-tooltip__value {
|
|
|
|
|
|
flex: 0 0 auto;
|
|
|
|
|
|
white-space: nowrap;
|
2026-08-08 10:43:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-20 10:21:30 +08:00
|
|
|
|
.waveform-tooltip__series strong {
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
}
|
2026-07-20 17:57:52 +08:00
|
|
|
|
|
2026-07-23 11:59:27 +08:00
|
|
|
|
.waveform-tooltip__value {
|
2026-08-17 10:14:44 +08:00
|
|
|
|
color: #555;
|
2026-07-23 11:59:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-20 17:57:52 +08:00
|
|
|
|
.waveform-tooltip__series small {
|
|
|
|
|
|
color: #667085;
|
|
|
|
|
|
}
|
2026-07-20 10:21:30 +08:00
|
|
|
|
</style>
|