waveform-analysis 0.1.41 → 0.1.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,7 @@ import {
11
11
 
12
12
  import type { AnnotationSeriesCandidate } from '../annotation'
13
13
  import type { useWaveformAnnotationInteraction } from '../annotation'
14
+ import type { NormalizedWaveformGridOptions } from './grid'
14
15
  import type { DisplaySeries, DisplayTrack, TrackLayout } from './types'
15
16
  import type { ResolvedWaveformChartProps, WaveformChartEmit } from './waveformChartTypes'
16
17
  import { constrainZoomDomain, transformForDomain } from '../interaction/zoomConstraints'
@@ -33,7 +34,7 @@ interface LifecycleContext {
33
34
  currentPage: Ref<number>
34
35
  pageCount: ComputedRef<number>
35
36
  pagedTracks: ComputedRef<Array<DisplayTrack | undefined>>
36
- gridOptions: ComputedRef<{ rowCount: number; columnCount: number }>
37
+ gridOptions: ComputedRef<NormalizedWaveformGridOptions>
37
38
  chartSeries: ComputedRef<DisplaySeries[]>
38
39
  chartTracks: ComputedRef<DisplayTrack[]>
39
40
  trackLayouts: ComputedRef<TrackLayout[]>
@@ -220,6 +221,7 @@ export function useWaveformChartLifecycle(context: LifecycleContext) {
220
221
  currentPage,
221
222
  () => gridOptions.value.rowCount,
222
223
  () => gridOptions.value.columnCount,
224
+ () => gridOptions.value.fillIncompleteLastRow,
223
225
  activeInteractionMode,
224
226
  ],
225
227
  async () => {
@@ -239,20 +241,28 @@ export function useWaveformChartLifecycle(context: LifecycleContext) {
239
241
  },
240
242
  )
241
243
 
242
- watch([pageCount, () => props.grid?.rowCount, () => props.grid?.columnCount], () => {
243
- const previousPage = currentPage.value
244
- currentPage.value =
245
- currentPage.value > pageCount.value
246
- ? pageCount.value
247
- : currentPage.value !== 1
248
- ? 1
249
- : currentPage.value
250
- if (previousPage !== currentPage.value) {
251
- emit('page-change', currentPage.value, pageCount.value)
252
- }
253
- clearHover()
254
- void nextTick(configureZoom)
255
- })
244
+ watch(
245
+ [
246
+ pageCount,
247
+ () => props.grid?.rowCount,
248
+ () => props.grid?.columnCount,
249
+ () => props.grid?.fillIncompleteLastRow,
250
+ ],
251
+ () => {
252
+ const previousPage = currentPage.value
253
+ currentPage.value =
254
+ currentPage.value > pageCount.value
255
+ ? pageCount.value
256
+ : currentPage.value !== 1
257
+ ? 1
258
+ : currentPage.value
259
+ if (previousPage !== currentPage.value) {
260
+ emit('page-change', currentPage.value, pageCount.value)
261
+ }
262
+ clearHover()
263
+ void nextTick(configureZoom)
264
+ },
265
+ )
256
266
 
257
267
  watch(activeInteractionMode, () => {
258
268
  editorSeriesOptions.value = []
@@ -72,6 +72,49 @@ describe('WaveformChart', () => {
72
72
  expect(endTicks[3]).toHaveLength(0)
73
73
  })
74
74
 
75
+ it('removes the later compact row top tick when the Y-axis end has a floating-point tail', async () => {
76
+ const yDomain: [number, number] = [-1, 0.2]
77
+ const calculatedAxisEnd =
78
+ yDomain[0] + ((yDomain[1] - yDomain[0]) * 4) / 4
79
+ expect(calculatedAxisEnd).not.toBe(yDomain[1])
80
+
81
+ const wrapper = await mountSizedChart(
82
+ {
83
+ kind: 'series',
84
+ series: [
85
+ {
86
+ name: 'top',
87
+ data: { kind: 'points', points: [{ x: 0, y: -0.8 }, { x: 1, y: 0.1 }] },
88
+ },
89
+ {
90
+ name: 'bottom',
91
+ data: { kind: 'points', points: [{ x: 0, y: -0.7 }, { x: 1, y: 0 }] },
92
+ },
93
+ ],
94
+ },
95
+ { displayMode: 'compact', grid: { rowCount: 2, columnCount: 1 }, yDomain },
96
+ )
97
+
98
+ const [topTrack, bottomTrack] = wrapper.findAll('.waveform-chart__track')
99
+ const ticksAt = (track: typeof topTrack, position: number) =>
100
+ track.findAll('.waveform-chart__axis--y .tick').filter((tick) => {
101
+ const match = tick.attributes('transform')?.match(/translate\(0,\s*([\d.]+)\)/)
102
+ return match ? Math.abs(Number(match[1]) - position) <= 1 : false
103
+ })
104
+ const topTrackHeight = Number(topTrack.attributes('data-track-height'))
105
+
106
+ expect(ticksAt(topTrack, 0)).toHaveLength(1)
107
+ expect(ticksAt(topTrack, 0)[0].text()).toBe('0.2')
108
+ expect(ticksAt(bottomTrack, 0)).toHaveLength(0)
109
+ expect(Number(bottomTrack.attributes('data-track-top'))).toBeCloseTo(
110
+ Number(topTrack.attributes('data-track-top')) + topTrackHeight,
111
+ 6,
112
+ )
113
+
114
+ const boundaryLabels = [...ticksAt(topTrack, topTrackHeight), ...ticksAt(bottomTrack, 0)]
115
+ expect(boundaryLabels).toHaveLength(1)
116
+ })
117
+
75
118
  it('prefixes one shared exponent to the largest visible tick on every compact Y axis', async () => {
76
119
  const wrapper = await mountSizedChart(
77
120
  {
@@ -0,0 +1,95 @@
1
+ import { flushPromises } from '@vue/test-utils'
2
+ import { describe, expect, it } from 'vitest'
3
+
4
+ import { gridSeries, mountSizedChart } from '../../test/waveformChart'
5
+
6
+ function geometry(track: { attributes: (name: string) => string | undefined }) {
7
+ return {
8
+ left: Number(track.attributes('data-track-left')),
9
+ top: Number(track.attributes('data-track-top')),
10
+ width: Number(track.attributes('data-track-width')),
11
+ height: Number(track.attributes('data-track-height')),
12
+ }
13
+ }
14
+
15
+ describe('WaveformChart incomplete grid rows', () => {
16
+ it.each(['independent', 'separated', 'compact'] as const)(
17
+ 'fills an incomplete two by two row in %s mode',
18
+ async (displayMode) => {
19
+ const wrapper = await mountSizedChart(gridSeries(3), {
20
+ displayMode,
21
+ grid: { rowCount: 2, columnCount: 2, fillIncompleteLastRow: true },
22
+ })
23
+ const tracks = wrapper.findAll('.waveform-chart__track')
24
+ const first = geometry(tracks[0]!)
25
+ const last = geometry(tracks[2]!)
26
+
27
+ expect(tracks).toHaveLength(3)
28
+ expect(wrapper.findAll('.waveform-chart__track--empty')).toHaveLength(0)
29
+ expect(wrapper.findAll('.waveform-chart__grid-slot-placeholder')).toHaveLength(0)
30
+ expect(last.left).toBe(0)
31
+ expect(last.width).toBeGreaterThan(first.width * 1.8)
32
+ expect(last.top).toBeGreaterThan(first.top)
33
+ if (displayMode === 'independent') {
34
+ const overlays = wrapper.findAll('.waveform-chart__overlay--independent')
35
+ expect(overlays).toHaveLength(3)
36
+ expect(Number(overlays[2]?.attributes('width'))).toBe(last.width)
37
+ } else {
38
+ expect(wrapper.findAll('.waveform-chart__overlay--shared')).toHaveLength(1)
39
+ }
40
+ },
41
+ )
42
+
43
+ it('removes unused one-column rows and redistributes chart height', async () => {
44
+ const base = await mountSizedChart(gridSeries(3), {
45
+ displayMode: 'independent',
46
+ grid: { rowCount: 4, columnCount: 1 },
47
+ })
48
+ const filled = await mountSizedChart(gridSeries(3), {
49
+ displayMode: 'independent',
50
+ grid: { rowCount: 4, columnCount: 1, fillIncompleteLastRow: true },
51
+ })
52
+ const baseFirst = geometry(base.findAll('.waveform-chart__track')[0]!)
53
+ const filledTracks = filled.findAll('.waveform-chart__track')
54
+ const filledFirst = geometry(filledTracks[0]!)
55
+ const filledLast = geometry(filledTracks[2]!)
56
+
57
+ expect(filledTracks).toHaveLength(3)
58
+ expect(filledFirst.height).toBeGreaterThan(baseFirst.height)
59
+ expect(filledLast.top + filledLast.height).toBeGreaterThan(baseFirst.height * 3)
60
+ })
61
+
62
+ it('keeps the final two tracks evenly distributed in a two by three grid', async () => {
63
+ const wrapper = await mountSizedChart(gridSeries(5), {
64
+ displayMode: 'separated',
65
+ grid: { rowCount: 2, columnCount: 3, fillIncompleteLastRow: true },
66
+ })
67
+ const tracks = wrapper.findAll('.waveform-chart__track').map(geometry)
68
+
69
+ expect(tracks).toHaveLength(5)
70
+ expect(tracks[3]?.left).toBe(0)
71
+ expect(tracks[3]?.width).toBeCloseTo(tracks[4]?.width ?? 0)
72
+ expect(tracks[4]?.left).toBeGreaterThan((tracks[3]?.width ?? 0) + 1)
73
+ })
74
+
75
+ it('keeps full pages unchanged and fills a partial second page', async () => {
76
+ const data = gridSeries(5)
77
+ const standard = await mountSizedChart(data, {
78
+ displayMode: 'separated',
79
+ grid: { rowCount: 2, columnCount: 2 },
80
+ })
81
+ const filled = await mountSizedChart(data, {
82
+ displayMode: 'separated',
83
+ grid: { rowCount: 2, columnCount: 2, fillIncompleteLastRow: true },
84
+ })
85
+ const standardFirstPage = standard.findAll('.waveform-chart__track').map(geometry)
86
+ expect(filled.findAll('.waveform-chart__track').map(geometry)).toEqual(standardFirstPage)
87
+
88
+ await filled.get('.ant-pagination-next button').trigger('click')
89
+ await flushPromises()
90
+ const secondPage = filled.findAll('.waveform-chart__track').map(geometry)
91
+ expect(secondPage).toHaveLength(1)
92
+ expect(secondPage[0]?.left).toBe(0)
93
+ expect(secondPage[0]?.width).toBeGreaterThan(standardFirstPage[0]?.width ?? 0)
94
+ })
95
+ })