cb9f0c389f
build / build (push) Successful in 1m10s
去掉看板个人月明细;十一卡悬停和键盘可读的真实统计范围、公式与排除数。 自然月独立计算;跨月周取周一所在月,保留旧周证据和已存周报正文。 验证:make verify;一次性PG全镜像套件-race;真实恢复数据7个月与周报calc_metrics对拍。 真实浏览器十一卡逐项悬停、Tab/Escape、30秒刷新、跨月周、390px和完整PNG通过。 没有写DobotAI源问答、触发付费模型、外发或应用新迁移。
729 lines
25 KiB
TypeScript
729 lines
25 KiB
TypeScript
import { createContext, useContext, useState } from 'react'
|
||
import type { ReactNode, Ref } from 'react'
|
||
import { dashboardStatisticsHelp } from './qaDashboardStatistics'
|
||
import type { QADashboardData, DashboardCount, DashboardRegion } from './qaDashboardData'
|
||
import type { QualityRate } from './qaQuality'
|
||
import { currentQAWeek } from './qaWeeks'
|
||
import { historicalTrend } from './qaHistoricalTrend'
|
||
import type { HistoricalPlotPoint } from './qaHistoricalTrend'
|
||
interface Box {
|
||
x: number
|
||
y: number
|
||
w: number
|
||
h: number
|
||
}
|
||
interface StatisticsTip {
|
||
id: string
|
||
box: Box
|
||
baseline: number
|
||
}
|
||
const StatisticsContext = createContext<{
|
||
definitions: Record<string, string>
|
||
show: (tip: StatisticsTip) => void
|
||
hide: (id: string) => void
|
||
active: string | null
|
||
} | null>(null)
|
||
const blue = '#3274e6',
|
||
ink = '#23344d',
|
||
muted = '#7a8799',
|
||
line = '#eaf0f7'
|
||
const colors = [blue, '#59a9f3', '#69c6bc', '#f3c25a', '#f39b6c', '#9b8ade', '#86b8a1', '#d6a3cf', '#8aacc9', '#c4cb76']
|
||
const number = (n: number) => new Intl.NumberFormat('zh-CN').format(n)
|
||
const pct = (n: number | null) => (n === null ? '—' : `${n.toFixed(1)}%`)
|
||
function wrap(value: string, width: number, size = 12): string[] {
|
||
const max = Math.max(2, width / size),
|
||
out: string[] = []
|
||
let row = '',
|
||
units = 0
|
||
for (const c of Array.from(value)) {
|
||
const next = c.charCodeAt(0) < 128 ? 0.57 : 1
|
||
if (row && units + next > max) {
|
||
out.push(row)
|
||
row = ''
|
||
units = 0
|
||
}
|
||
row += c
|
||
units += next
|
||
}
|
||
if (row || !out.length) out.push(row)
|
||
return out
|
||
}
|
||
function Text({
|
||
value,
|
||
x,
|
||
y,
|
||
width,
|
||
size = 12,
|
||
fill = ink,
|
||
weight = 400,
|
||
anchor = 'start',
|
||
}: {
|
||
value: string
|
||
x: number
|
||
y: number
|
||
width: number
|
||
size?: number
|
||
fill?: string
|
||
weight?: number
|
||
anchor?: 'start' | 'middle' | 'end'
|
||
}) {
|
||
return (
|
||
<text x={x} y={y} fontSize={size} fill={fill} fontWeight={weight} textAnchor={anchor}>
|
||
{wrap(value, width, size).map((row, i) => (
|
||
<tspan key={i} x={x} dy={i ? size * 1.35 : 0}>
|
||
{row}
|
||
</tspan>
|
||
))}
|
||
</text>
|
||
)
|
||
}
|
||
function Panel({
|
||
box,
|
||
title,
|
||
en,
|
||
id,
|
||
children,
|
||
tint = '#fff',
|
||
}: {
|
||
box: Box
|
||
title: string
|
||
en: string
|
||
id: string
|
||
children: ReactNode
|
||
tint?: string
|
||
}) {
|
||
const statistics = useContext(StatisticsContext),
|
||
hint = statistics?.definitions[id] ?? '',
|
||
baseline = box.w < 140 ? 59 : 25
|
||
return (
|
||
<g data-panel={id} transform={`translate(${box.x} ${box.y})`}>
|
||
<rect width={box.w} height={box.h} rx={7} fill={tint} />
|
||
<text x={16} y={25} fontSize={14} fontWeight={650} fill={ink}>
|
||
{title}
|
||
</text>
|
||
<text x={16} y={43} fontSize={10.5} fill={muted}>
|
||
{en}
|
||
</text>
|
||
{children}
|
||
<g
|
||
data-statistics-help={id}
|
||
role="button"
|
||
tabIndex={0}
|
||
aria-label={`${title}统计口径`}
|
||
aria-describedby={`qa-statistics-description-${id}`}
|
||
aria-expanded={statistics?.active === id}
|
||
style={{ cursor: 'help' }}
|
||
onMouseEnter={() => statistics?.show({ id, box, baseline })}
|
||
onMouseLeave={() => statistics?.hide(id)}
|
||
onFocus={() => statistics?.show({ id, box, baseline })}
|
||
onBlur={() => statistics?.hide(id)}
|
||
onClick={() => statistics?.show({ id, box, baseline })}
|
||
onKeyDown={(e) => {
|
||
if (e.key === 'Escape') statistics?.hide(id)
|
||
if (e.key === 'Enter' || e.key === ' ') {
|
||
e.preventDefault()
|
||
statistics?.show({ id, box, baseline })
|
||
}
|
||
}}
|
||
>
|
||
<desc id={`qa-statistics-description-${id}`}>{hint}</desc>
|
||
<rect x={box.w - 72} y={baseline - 17} width={62} height={24} rx={3} fill="transparent" />
|
||
<text x={box.w - 16} y={baseline} textAnchor="end" fontSize={10.5} fill={muted}>
|
||
统计口径
|
||
</text>
|
||
</g>
|
||
</g>
|
||
)
|
||
}
|
||
function Metric({
|
||
box,
|
||
value,
|
||
title,
|
||
en,
|
||
id,
|
||
tint,
|
||
color,
|
||
subtitle,
|
||
}: {
|
||
box: Box
|
||
value: number
|
||
title: string
|
||
en: string
|
||
id: string
|
||
tint: string
|
||
color: string
|
||
subtitle: string
|
||
}) {
|
||
const text = number(value),
|
||
size = Math.min(box.w < 220 ? 40 : 54, (box.w - 32) / (text.length * 0.62))
|
||
return (
|
||
<Panel box={box} title={title} en={en} id={id} tint={tint}>
|
||
<text x={16} y={box.h - 43} fontSize={size} fill={color} fontWeight={700} data-value={value}>
|
||
{text}
|
||
</text>
|
||
<text x={16} y={box.h - 17} fill={muted} fontSize={11}>
|
||
{subtitle}
|
||
</text>
|
||
</Panel>
|
||
)
|
||
}
|
||
function polar(cx: number, cy: number, r: number, degrees: number) {
|
||
const a = (degrees * Math.PI) / 180
|
||
return { x: cx + r * Math.cos(a), y: cy + r * Math.sin(a) }
|
||
}
|
||
function arc(cx: number, cy: number, r: number, start: number, end: number) {
|
||
const a = polar(cx, cy, r, start),
|
||
b = polar(cx, cy, r, end)
|
||
return `M ${a.x} ${a.y} A ${r} ${r} 0 ${end - start > 180 ? 1 : 0} 1 ${b.x} ${b.y}`
|
||
}
|
||
function Gauge({ box, rate, title, en, id }: { box: Box; rate: QualityRate; title: string; en: string; id: string }) {
|
||
const r = Math.min(42, box.w * 0.27),
|
||
cx = box.w / 2,
|
||
cy = 94,
|
||
d = arc(cx, cy, r, 135, 405)
|
||
return (
|
||
<Panel box={box} title={title} en={en} id={id}>
|
||
<title>{`${title}:${rate.numerator} / ${rate.denominator};分母为有效已评估记录`}</title>
|
||
<path d={d} fill="none" stroke="#e8ecf2" strokeWidth={8} strokeLinecap="round" />
|
||
{rate.percent !== null && rate.percent > 0 ? (
|
||
<path
|
||
d={d}
|
||
fill="none"
|
||
stroke={blue}
|
||
strokeWidth={8}
|
||
strokeLinecap="round"
|
||
pathLength={100}
|
||
strokeDasharray={`${rate.percent} 100`}
|
||
/>
|
||
) : null}
|
||
<text
|
||
x={cx}
|
||
y={cy + 6}
|
||
textAnchor="middle"
|
||
fontSize={box.w < 220 ? 22 : 27}
|
||
fontWeight={650}
|
||
fill={ink}
|
||
data-value={rate.percent ?? 'unknown'}
|
||
>
|
||
{pct(rate.percent)}
|
||
</text>
|
||
<text x={cx} y={box.h - 14} fontSize={11} fill={muted} textAnchor="middle">
|
||
{rate.denominator ? `${number(rate.numerator)} / ${number(rate.denominator)}` : '暂无有效分母'}
|
||
</text>
|
||
</Panel>
|
||
)
|
||
}
|
||
function pieHeight(points: DashboardCount[], w: number) {
|
||
const mobile = w < 500,
|
||
legendW = mobile ? w - 60 : w * 0.45
|
||
return Math.max(
|
||
mobile ? 270 : 300,
|
||
(mobile ? 225 : 65) + points.reduce((n, p) => n + Math.max(24, wrap(p.label, legendW - 85).length * 16 + 9), 0)
|
||
)
|
||
}
|
||
function Pie({ box, points }: { box: Box; points: DashboardCount[] }) {
|
||
const mobile = box.w < 500,
|
||
total = points.reduce((n, p) => n + p.count, 0),
|
||
legendW = mobile ? box.w - 32 : box.w * 0.47,
|
||
cx = mobile ? box.w / 2 : box.w * 0.76,
|
||
cy = mobile ? 135 : Math.max(155, box.h / 2),
|
||
radius = Math.min(mobile ? 73 : 112, box.w * (mobile ? 0.25 : 0.21))
|
||
let angle = -90,
|
||
legendY = mobile ? 236 : 76
|
||
return (
|
||
<Panel box={box} title="问题类型分布" en="Issue Type Distribution" id="issue-types">
|
||
{!total ? (
|
||
<text x={box.w / 2} y={box.h / 2} textAnchor="middle" fill={muted} fontSize={13}>
|
||
暂无分类记录
|
||
</text>
|
||
) : null}
|
||
{points.map((point, i) => {
|
||
const start = angle
|
||
angle += (point.count / total) * 360
|
||
const a = polar(cx, cy, radius, start),
|
||
b = polar(cx, cy, radius, angle)
|
||
const y = legendY
|
||
legendY += Math.max(24, wrap(point.label, legendW - 85).length * 16 + 9)
|
||
return (
|
||
<g key={point.label}>
|
||
{points.length === 1 ? (
|
||
<circle cx={cx} cy={cy} r={radius} fill={colors[i % colors.length]} />
|
||
) : (
|
||
<path
|
||
d={`M ${cx} ${cy} L ${a.x} ${a.y} A ${radius} ${radius} 0 ${angle - start > 180 ? 1 : 0} 1 ${b.x} ${b.y} Z`}
|
||
fill={colors[i % colors.length]}
|
||
stroke="#fff"
|
||
strokeWidth={1}
|
||
/>
|
||
)}
|
||
<title>{`${point.label}:${point.count}(${((point.count / total) * 100).toFixed(1)}%)`}</title>
|
||
<circle cx={22} cy={y - 4} r={4} fill={colors[i % colors.length]} />
|
||
<Text x={34} y={y} width={legendW - 91} value={point.label} size={11.5} />
|
||
<text x={legendW + 8} y={y} textAnchor="end" fill={ink} fontSize={11.5}>
|
||
{number(point.count)}
|
||
</text>
|
||
</g>
|
||
)
|
||
})}
|
||
</Panel>
|
||
)
|
||
}
|
||
function productRows(points: DashboardCount[], w: number) {
|
||
return points.map((p) => ({ point: p, lines: wrap(p.label, Math.max(70, w * 0.3), 11) }))
|
||
}
|
||
function productHeight(points: DashboardCount[], w: number) {
|
||
return Math.max(300, 75 + productRows(points, w).reduce((n, r) => n + Math.max(30, r.lines.length * 15 + 10), 0))
|
||
}
|
||
function Products({ box, points }: { box: Box; points: DashboardCount[] }) {
|
||
const left = Math.max(85, box.w * 0.32),
|
||
right = box.w - 58,
|
||
max = Math.max(1, ...points.map((p) => p.count))
|
||
let y = 78
|
||
return (
|
||
<Panel box={box} title="产品问题排行" en="Product Issue Ranking" id="products">
|
||
{points.length ? (
|
||
productRows(points, box.w).map(({ point, lines }) => {
|
||
const at = y
|
||
y += Math.max(30, lines.length * 15 + 10)
|
||
return (
|
||
<g key={point.label}>
|
||
<title>{`${point.label}:${point.count}`}</title>
|
||
<Text x={16} y={at + 2} width={left - 26} value={point.label} size={11} />
|
||
<rect
|
||
x={left}
|
||
y={at - 11}
|
||
width={Math.max(1, (point.count / max) * (right - left))}
|
||
height={15}
|
||
rx={2}
|
||
fill={blue}
|
||
/>
|
||
<text x={left + (point.count / max) * (right - left) + 5} y={at + 1} fontSize={11} fill={ink}>
|
||
{number(point.count)}
|
||
</text>
|
||
</g>
|
||
)
|
||
})
|
||
) : (
|
||
<text x={16} y={100} fill={muted} fontSize={13}>
|
||
暂无分类记录
|
||
</text>
|
||
)}
|
||
</Panel>
|
||
)
|
||
}
|
||
type PlotPoint = HistoricalPlotPoint
|
||
function Plot({
|
||
box,
|
||
title,
|
||
en,
|
||
id,
|
||
points,
|
||
percent = false,
|
||
monthly = false,
|
||
}: {
|
||
box: Box
|
||
title: string
|
||
en: string
|
||
id: string
|
||
points: PlotPoint[]
|
||
percent?: boolean
|
||
monthly?: boolean
|
||
}) {
|
||
const left = 44,
|
||
right = box.w - 22,
|
||
top = 74,
|
||
bottom = box.h - 47,
|
||
max = percent ? 100 : Math.max(4, Math.ceil(Math.max(0, ...points.map((p) => p.value ?? 0)) / 4) * 4),
|
||
x = (i: number) =>
|
||
points.length === 1 ? (left + right) / 2 : left + (i * (right - left)) / Math.max(1, points.length - 1),
|
||
y = (n: number) => bottom - (n / max) * (bottom - top)
|
||
const color = (source: PlotPoint['source']) =>
|
||
source === 'master_live_cumulative_v1' || source === 'master_live_calendar_month_v1'
|
||
? '#249c86'
|
||
: source === 'system_frozen'
|
||
? '#8b68c7'
|
||
: blue
|
||
const paths = [...new Set(points.map((p) => p.source))].map((source) => {
|
||
let path = '',
|
||
open = false
|
||
for (let i = 0; i < points.length; i++) {
|
||
const point = points[i]
|
||
if (point.value === null || point.source !== source) {
|
||
open = false
|
||
continue
|
||
}
|
||
path += `${open ? 'L' : 'M'} ${x(i)} ${y(point.value)} `
|
||
open = true
|
||
}
|
||
return { source, path }
|
||
})
|
||
const every = Math.max(1, Math.ceil(points.length / (box.w < 420 ? 5 : 8)))
|
||
const labelled = new Set<number>()
|
||
const label = (i: number) => {
|
||
if ((monthly || points[i]?.value !== null) && points[i] && [...labelled].every((k) => Math.abs(x(k) - x(i)) >= 52))
|
||
labelled.add(i)
|
||
}
|
||
label(0)
|
||
label(points.length - 1)
|
||
// Keep the first point of a new policy readable instead of forcing two adjacent labels at a boundary.
|
||
points.forEach((point, i) => {
|
||
if (i && points[i - 1]?.source !== point.source) label(i)
|
||
})
|
||
points.forEach((point, i) => {
|
||
if (points[i + 1]?.source !== point.source) label(i)
|
||
})
|
||
points.forEach((_, i) => {
|
||
if (i % every === 0) label(i)
|
||
})
|
||
return (
|
||
<Panel box={box} title={title} en={en} id={id}>
|
||
{Array.from({ length: 5 }, (_, i) => (
|
||
<g key={i}>
|
||
<line x1={left} x2={right} y1={y((max * i) / 4)} y2={y((max * i) / 4)} stroke={line} />
|
||
<text x={left - 9} y={y((max * i) / 4) + 4} textAnchor="end" fill={muted} fontSize={10}>
|
||
{(max * i) / 4}
|
||
{percent ? '%' : ''}
|
||
</text>
|
||
</g>
|
||
))}
|
||
{paths
|
||
.filter((p) => p.path)
|
||
.map((p, i) => (
|
||
<path
|
||
key={i}
|
||
d={p.path}
|
||
fill="none"
|
||
stroke={color(p.source)}
|
||
strokeWidth={2}
|
||
data-series={id}
|
||
data-series-source={p.source}
|
||
/>
|
||
))}
|
||
{points.map((point, i) => (
|
||
<g
|
||
key={point.label}
|
||
data-source={point.source}
|
||
data-week={point.week}
|
||
data-month={point.month}
|
||
data-value={point.value ?? undefined}
|
||
data-frozen={point.frozen === undefined ? undefined : point.frozen ? 'available' : 'missing'}
|
||
>
|
||
<title>{point.hint}</title>
|
||
{point.value !== null ? (
|
||
<>
|
||
<circle cx={x(i)} cy={y(point.value)} r={3} fill="#fff" stroke={color(point.source)} strokeWidth={1.5} />
|
||
{labelled.has(i) ? (
|
||
<text
|
||
x={x(i)}
|
||
y={Math.max(top - 9, y(point.value) - 9)}
|
||
fill={color(point.source)}
|
||
fontSize={10}
|
||
textAnchor="middle"
|
||
>
|
||
{percent ? `${point.value.toFixed(2)}%` : number(point.value)}
|
||
</text>
|
||
) : null}
|
||
</>
|
||
) : null}
|
||
{monthly && point.value === null ? (
|
||
<text x={x(i)} y={bottom - 9} textAnchor="middle" fill={muted} fontSize={11}>
|
||
—
|
||
</text>
|
||
) : null}
|
||
{labelled.has(i) ? (
|
||
<text x={x(i)} y={bottom + 22} textAnchor="middle" fill={muted} fontSize={10}>
|
||
{point.label}
|
||
</text>
|
||
) : null}
|
||
</g>
|
||
))}
|
||
{percent ? (
|
||
<text x={16} y={box.h - 7} fontSize={9} fill={muted}>
|
||
{monthly
|
||
? '自然月独立计算 · 当前有效结论 · 空分母留空'
|
||
: points.some((p) => p.source === 'master_live_cumulative_v1')
|
||
? '蓝:历史上报;紫:系统冻结;绿:总表累计'
|
||
: points.some((p) => p.source === 'user_provided_history')
|
||
? '蓝:用户提供(未提供分子/分母);紫:系统冻结'
|
||
: '缺失周留空;系统冻结与当前实时结果分开'}
|
||
</text>
|
||
) : null}
|
||
{!points.some((p) => p.value !== null) ? (
|
||
<text x={(left + right) / 2} y={(top + bottom) / 2} fill={muted} textAnchor="middle" fontSize={12}>
|
||
{percent ? '暂无冻结快照' : '暂无数据'}
|
||
</text>
|
||
) : null}
|
||
</Panel>
|
||
)
|
||
}
|
||
function regionalHeight(regions: DashboardRegion[], w: number) {
|
||
return Math.max(
|
||
290,
|
||
130 + regions.reduce((n, r) => n + Math.max(34, wrap(r.name, Math.max(70, w - 125), 11.5).length * 16 + 12), 0)
|
||
)
|
||
}
|
||
function RegionTable({
|
||
box,
|
||
regions,
|
||
frequency,
|
||
month,
|
||
}: {
|
||
box: Box
|
||
regions: DashboardRegion[]
|
||
frequency: boolean
|
||
month: string
|
||
}) {
|
||
const rows = [...regions].sort((a, b) => {
|
||
const av = frequency ? a.frequency : a.usage_coverage.percent,
|
||
bv = frequency ? b.frequency : b.usage_coverage.percent
|
||
return (bv ?? -1) - (av ?? -1) || a.name.localeCompare(b.name, 'zh-CN')
|
||
})
|
||
let y = 104
|
||
return (
|
||
<Panel
|
||
box={box}
|
||
title={frequency ? '区域平均使用频率' : '区域使用覆盖率'}
|
||
en={frequency ? 'Average usage frequency' : 'Usage coverage'}
|
||
id={frequency ? 'frequency' : 'usage-coverage'}
|
||
>
|
||
<rect x={10} y={57} width={box.w - 20} height={box.h - 68} rx={5} fill="#fff" stroke="#e4eaf2" />
|
||
<text x={19} y={77} fontSize={10.5} fill={muted}>
|
||
排名
|
||
</text>
|
||
<text x={58} y={77} fontSize={10.5} fill={muted}>
|
||
区域
|
||
</text>
|
||
<text x={box.w - 19} y={77} textAnchor="end" fontSize={10.5} fill={muted}>
|
||
{frequency ? '人均次数' : '使用覆盖率'}
|
||
</text>
|
||
<line x1={15} x2={box.w - 15} y1={85} y2={85} stroke={line} />
|
||
{rows.map((r, i) => {
|
||
const at = y,
|
||
value = frequency ? r.frequency : r.usage_coverage.percent
|
||
const h = Math.max(34, wrap(r.name, Math.max(70, box.w - 125), 11.5).length * 16 + 12)
|
||
y += h
|
||
return (
|
||
<g key={r.id}>
|
||
<title>{`${r.name};${month}月内提问 ${r.questions} 次;去重使用 ${r.users ?? '未知'} 人 / 通讯录归属 ${r.roster_people ?? '未知'} 人`}</title>
|
||
{i % 2 === 0 ? <rect x={11} y={at - 15} width={box.w - 22} height={h} fill="#f7faff" /> : null}
|
||
{value !== null && i < 3 ? (
|
||
<circle cx={30} cy={at - 4} r={9} fill={['#e9bd54', '#a8b6c9', '#dc9c73'][i]} />
|
||
) : null}
|
||
<text x={30} y={at} textAnchor="middle" fontSize={10.5} fill={value !== null && i < 3 ? '#fff' : muted}>
|
||
{value === null ? '—' : i + 1}
|
||
</text>
|
||
<Text x={53} y={at} width={Math.max(70, box.w - 125)} value={r.name} size={11.5} />
|
||
<text x={box.w - 19} y={at} textAnchor="end" fontSize={12} fill={ink}>
|
||
{value === null ? '—' : frequency ? value.toFixed(2) : `${value.toFixed(1)}%`}
|
||
</text>
|
||
</g>
|
||
)
|
||
})}
|
||
<text x={box.w - 17} y={box.h - 17} textAnchor="end" fontSize={9.5} fill={muted}>
|
||
{month}月累计
|
||
</text>
|
||
</Panel>
|
||
)
|
||
}
|
||
export function QADashboardDrawing({
|
||
data,
|
||
width,
|
||
svgRef,
|
||
}: {
|
||
data: QADashboardData
|
||
width: number
|
||
svgRef?: Ref<SVGSVGElement>
|
||
}) {
|
||
const [tip, setTip] = useState<StatisticsTip | null>(null)
|
||
const definitions = dashboardStatisticsHelp(data)
|
||
const w = Math.max(240, Math.round(width)),
|
||
pad = w < 700 ? 10 : 16,
|
||
gap = w < 700 ? 12 : 18,
|
||
inner = w - pad * 2,
|
||
mobile = w < 900,
|
||
unit = (inner - gap * 3) / 4,
|
||
week = currentQAWeek(new Date(data.week_start)),
|
||
filterLines = wrap(data.keyword ? `关键词:${data.keyword}` : '', inner - 16, 11),
|
||
heading = `${data.week_start.slice(0, 10)} 起的自然周${data.quality_period ? ` · 质量 ${data.quality_period.month} 月内累计` : ''} · 区域统计 ${new Date(Date.parse(data.month_start) + 8 * 3600000).toISOString().slice(0, 7)} 月累计`,
|
||
headingLines = (mobile ? [heading.split(' · ')[0], heading.split(' · ').slice(1).join(' · ')] : [heading]).flatMap(
|
||
(row) => wrap(row, inner - 16, 10.5)
|
||
),
|
||
filterY = 47 + headingLines.length * 14,
|
||
header = filterY + (data.keyword ? filterLines.length * 15 : 0) + 4,
|
||
metricH = mobile ? 154 : 166
|
||
const metrics: Box[] = Array.from({ length: 4 }, (_, i) =>
|
||
mobile
|
||
? {
|
||
x: pad + ((i % 2) * (inner + gap)) / 2,
|
||
y: header + Math.floor(i / 2) * (metricH + gap),
|
||
w: (inner - gap) / 2,
|
||
h: metricH,
|
||
}
|
||
: { x: pad + i * (unit + gap), y: header, w: unit, h: metricH }
|
||
)
|
||
let cursor = header + (mobile ? 2 * metricH + gap : metricH) + gap
|
||
const pieW = mobile ? inner : (inner - gap) * 0.54,
|
||
productW = mobile ? inner : inner - gap - pieW,
|
||
pieH = pieHeight(data.issue_types, pieW),
|
||
productsH = productHeight(data.products, productW),
|
||
row2H = Math.max(pieH, productsH)
|
||
const pie: Box = { x: pad, y: cursor, w: pieW, h: mobile ? pieH : row2H },
|
||
products: Box = {
|
||
x: mobile ? pad : pad + pieW + gap,
|
||
y: mobile ? cursor + pieH + gap : cursor,
|
||
w: productW,
|
||
h: mobile ? productsH : row2H,
|
||
}
|
||
cursor += mobile ? pieH + productsH + gap * 2 : row2H + gap
|
||
const trendW = mobile ? inner : unit * 2 + gap,
|
||
regionW = mobile ? inner : unit,
|
||
regionH = regionalHeight(data.regions, regionW),
|
||
row3H = Math.max(290, regionH)
|
||
const trend: Box = { x: pad, y: cursor, w: trendW, h: mobile ? 270 : row3H },
|
||
freq: Box = {
|
||
x: mobile ? pad : pad + trendW + gap,
|
||
y: mobile ? cursor + trend.h + gap : cursor,
|
||
w: regionW,
|
||
h: mobile ? regionH : row3H,
|
||
},
|
||
usage: Box = {
|
||
x: mobile ? pad : pad + trendW + regionW + gap * 2,
|
||
y: mobile ? cursor + trend.h + regionH + gap * 2 : cursor,
|
||
w: regionW,
|
||
h: mobile ? regionH : row3H,
|
||
}
|
||
cursor += mobile ? trend.h + regionH * 2 + gap * 3 : row3H + gap
|
||
const historyW = mobile ? inner : (inner - gap) / 2,
|
||
coverage: Box = { x: pad, y: cursor, w: historyW, h: 270 },
|
||
accuracy: Box = {
|
||
x: mobile ? pad : pad + historyW + gap,
|
||
y: mobile ? cursor + 270 + gap : cursor,
|
||
w: historyW,
|
||
h: 270,
|
||
},
|
||
height = mobile ? cursor + 540 + gap + pad : cursor + 270 + pad
|
||
const frozen = (correctness: boolean): PlotPoint[] => historicalTrend(data, correctness)
|
||
const month = new Date(Date.parse(data.month_start) + 8 * 3600000).toISOString().slice(0, 7)
|
||
const tipWidth = Math.min(334, inner),
|
||
tipLines = wrap(tip ? definitions[tip.id] : '', tipWidth - 26, 11.5),
|
||
tipHeight = tipLines.length * 15.525 + 26,
|
||
tipX = tip ? Math.max(pad, Math.min(w - pad - tipWidth, tip.box.x + tip.box.w - tipWidth - 10)) : 0,
|
||
tipY = tip ? Math.max(pad, Math.min(height - pad - tipHeight, tip.box.y + tip.baseline + 10)) : 0
|
||
return (
|
||
<StatisticsContext.Provider
|
||
value={{
|
||
definitions,
|
||
show: setTip,
|
||
hide: (id) => setTip((current) => (current?.id === id ? null : current)),
|
||
active: tip?.id ?? null,
|
||
}}
|
||
>
|
||
<svg
|
||
ref={svgRef}
|
||
className="qa-dashboard-svg"
|
||
xmlns="http://www.w3.org/2000/svg"
|
||
width="100%"
|
||
viewBox={`0 0 ${w} ${height}`}
|
||
role="group"
|
||
aria-label="完整十一项问题统计看板"
|
||
style={{
|
||
display: 'block',
|
||
fontFamily: 'Arial, "Noto Sans CJK SC", "Microsoft YaHei", sans-serif',
|
||
fontVariantNumeric: 'tabular-nums',
|
||
background: '#fff',
|
||
}}
|
||
>
|
||
<title>{`问题统计看板 · ${week.year}年第${week.week}周`}</title>
|
||
<rect width={w} height={height} fill="#fff" />
|
||
<text x={pad + 6} y={27} fontSize={mobile ? 17 : 21} fontWeight={700} fill={ink}>
|
||
问题统计看板
|
||
</text>
|
||
<text x={w - pad - 6} y={27} textAnchor="end" fontSize={12} fill={muted}>
|
||
{week.year} · W{String(week.week).padStart(2, '0')}
|
||
</text>
|
||
{headingLines.map((row, index) => (
|
||
<Text key={index} x={pad + 6} y={46 + index * 14} width={inner - 16} size={10.5} fill={muted} value={row} />
|
||
))}
|
||
{data.keyword ? (
|
||
<Text x={pad + 6} y={filterY} width={inner - 16} value={`关键词:${data.keyword}`} size={11} fill={muted} />
|
||
) : null}
|
||
<Metric
|
||
box={metrics[0]}
|
||
title="问题总数"
|
||
en="Total Issues"
|
||
id="total"
|
||
value={data.total_issues}
|
||
tint="#fff4e2"
|
||
color="#c69b00"
|
||
subtitle="所选周截止前累计"
|
||
/>
|
||
<Metric
|
||
box={metrics[1]}
|
||
title="本周新增"
|
||
en="New This week"
|
||
id="new-week"
|
||
value={data.new_this_week}
|
||
tint="#ececff"
|
||
color="#4056d6"
|
||
subtitle="所选自然周"
|
||
/>
|
||
<Gauge
|
||
box={metrics[2]}
|
||
title="覆盖率"
|
||
en={`Coverage Rate${data.quality_period ? ` · ${data.quality_period.month}` : ''}`}
|
||
id="coverage"
|
||
rate={data.monthly_quality?.coverage ?? data.quality.rates.coverage}
|
||
/>
|
||
<Gauge
|
||
box={metrics[3]}
|
||
title="正确率"
|
||
en={`Accuracy Rate${data.quality_period ? ` · ${data.quality_period.month}` : ''}`}
|
||
id="accuracy"
|
||
rate={data.monthly_quality?.correctness ?? data.quality.rates.correctness}
|
||
/>
|
||
<Pie box={pie} points={data.issue_types} />
|
||
<Products box={products} points={data.products} />
|
||
<Plot
|
||
box={trend}
|
||
title="问题趋势"
|
||
en="Issue Trend"
|
||
id="issue-trend"
|
||
points={data.daily.map((p) => ({ label: p.date.slice(5), value: p.count, hint: `${p.date}:${p.count} 条` }))}
|
||
/>
|
||
<RegionTable box={freq} regions={data.regions} frequency month={month} />
|
||
<RegionTable box={usage} regions={data.regions} frequency={false} month={month} />
|
||
<Plot
|
||
box={coverage}
|
||
title="覆盖率趋势"
|
||
en="Coverage Rate Trend"
|
||
id="coverage-trend"
|
||
points={frozen(false)}
|
||
monthly={!!data.quality_period}
|
||
percent
|
||
/>
|
||
<Plot
|
||
box={accuracy}
|
||
title="正确率趋势"
|
||
en="Accuracy Rate Trend"
|
||
id="accuracy-trend"
|
||
points={frozen(true)}
|
||
monthly={!!data.quality_period}
|
||
percent
|
||
/>
|
||
{tip ? (
|
||
<g
|
||
role="tooltip"
|
||
data-statistics-tooltip={tip.id}
|
||
pointerEvents="none"
|
||
transform={`translate(${tipX} ${tipY})`}
|
||
>
|
||
<rect x={2} y={3} width={tipWidth} height={tipHeight} rx={5} fill="#dce4ee" opacity={0.65} />
|
||
<rect width={tipWidth} height={tipHeight} rx={5} fill="#fff" stroke="#ccd8e8" />
|
||
<Text x={13} y={22} width={tipWidth - 26} size={11.5} value={definitions[tip.id]} />
|
||
</g>
|
||
) : null}
|
||
</svg>
|
||
</StatisticsContext.Provider>
|
||
)
|
||
}
|