fix(server): 修正档案成绩趋势图 y 轴坐标字符串拼接

This commit is contained in:
2026-08-07 16:38:09 +08:00
parent 5b5ffb5b9e
commit 5f9566e26d
2 changed files with 15 additions and 1 deletions

View File

@@ -0,0 +1,14 @@
import { renderScoreTrendChart } from './archive-report.exam';
describe('renderScoreTrendChart', () => {
it('places the first y-axis label 4px below the top gridline using numeric addition', () => {
const html = renderScoreTrendChart([
{ examType: '文化', score: 60, examDate: '2026-01-01' },
{ examType: '文化', score: 90, examDate: '2026-02-01' },
{ examType: '文化', score: 70, examDate: '2026-03-01' },
] as never);
expect(html).toContain('y="154.0"');
expect(html).not.toContain('y="150.04"');
});
});

View File

@@ -146,7 +146,7 @@ export function renderScoreTrendChart(exams: ExamScore[]): string {
for (let i = 0; i <= ySteps; i++) {
const val = minScore + (scoreRange * i) / ySteps;
const y = scaleY(val);
yLabels += `<text x="${pad.left - 6}" y="${y.toFixed(1) + 4}" text-anchor="end" fill="#667085" font-size="10">${val.toFixed(0)}</text>`;
yLabels += `<text x="${pad.left - 6}" y="${(y + 4).toFixed(1)}" text-anchor="end" fill="#667085" font-size="10">${val.toFixed(0)}</text>`;
if (i > 0) {
yLabels += `<line x1="${pad.left}" y1="${y.toFixed(1)}" x2="${w - pad.right}" y2="${y.toFixed(1)}" stroke="#eaf3fd" stroke-width="1"/>`;
}