2 Commits

Author SHA1 Message Date
李启源
4268a64de2 chore(发布): 准备 v0.1.43
All checks were successful
Package component / package (push) Successful in 4m53s
2026-08-20 17:58:43 +08:00
李启源
df77715994 fix(坐标轴): 修复紧凑多道边界刻度重叠 2026-08-20 17:58:14 +08:00
3 changed files with 45 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "waveform-analysis",
"version": "0.1.42",
"version": "0.1.43",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/types/index.d.ts",

View File

@@ -135,9 +135,7 @@ export function buildTrackLayouts(options: BuildTrackLayoutsOptions): TrackLayou
(_, index) => axisStart + ((axisEnd - axisStart) * index) / (tickCount - 1),
)
const showAxisEnd = options.displayMode !== 'compact' || cell.row === 0
const visibleMajorTicks = showAxisEnd
? majorTicks
: majorTicks.filter((tick) => tick !== axisEnd)
const visibleMajorTicks = showAxisEnd ? majorTicks : majorTicks.slice(0, -1)
const tickValues = visibleMajorTicks
const { tickTextWidth } = axisTextMetrics(
scale.domain() as [number, number],

View File

@@ -72,6 +72,49 @@ describe('WaveformChart', () => {
expect(endTicks[3]).toHaveLength(0)
})
it('removes the later compact row top tick when the Y-axis end has a floating-point tail', async () => {
const yDomain: [number, number] = [-1, 0.2]
const calculatedAxisEnd =
yDomain[0] + ((yDomain[1] - yDomain[0]) * 4) / 4
expect(calculatedAxisEnd).not.toBe(yDomain[1])
const wrapper = await mountSizedChart(
{
kind: 'series',
series: [
{
name: 'top',
data: { kind: 'points', points: [{ x: 0, y: -0.8 }, { x: 1, y: 0.1 }] },
},
{
name: 'bottom',
data: { kind: 'points', points: [{ x: 0, y: -0.7 }, { x: 1, y: 0 }] },
},
],
},
{ displayMode: 'compact', grid: { rowCount: 2, columnCount: 1 }, yDomain },
)
const [topTrack, bottomTrack] = wrapper.findAll('.waveform-chart__track')
const ticksAt = (track: typeof topTrack, position: number) =>
track.findAll('.waveform-chart__axis--y .tick').filter((tick) => {
const match = tick.attributes('transform')?.match(/translate\(0,\s*([\d.]+)\)/)
return match ? Math.abs(Number(match[1]) - position) <= 1 : false
})
const topTrackHeight = Number(topTrack.attributes('data-track-height'))
expect(ticksAt(topTrack, 0)).toHaveLength(1)
expect(ticksAt(topTrack, 0)[0].text()).toBe('0.2')
expect(ticksAt(bottomTrack, 0)).toHaveLength(0)
expect(Number(bottomTrack.attributes('data-track-top'))).toBeCloseTo(
Number(topTrack.attributes('data-track-top')) + topTrackHeight,
6,
)
const boundaryLabels = [...ticksAt(topTrack, topTrackHeight), ...ticksAt(bottomTrack, 0)]
expect(boundaryLabels).toHaveLength(1)
})
it('prefixes one shared exponent to the largest visible tick on every compact Y axis', async () => {
const wrapper = await mountSizedChart(
{