waveform-analysis 0.1.57 → 0.1.59

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.
Files changed (54) hide show
  1. package/README.md +12 -7
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.js +752 -680
  4. package/dist/types/components/WaveformChart.vue.d.ts +2 -0
  5. package/dist/types/components/core/grid.d.ts +3 -0
  6. package/dist/types/components/core/trackPagination.d.ts +4 -0
  7. package/dist/types/components/core/useWaveformChartController.d.ts +3 -1
  8. package/dist/types/components/core/useWaveformChartLifecycle.d.ts +1 -2
  9. package/dist/types/components/core/useWaveformLayout.d.ts +2 -1
  10. package/dist/types/components/core/waveformChartTypes.d.ts +4 -1
  11. package/dist/types/components/data/types.d.ts +1 -1
  12. package/dist/types/components/index.d.ts +1 -1
  13. package/dist/types/components/interaction/useWaveformZoom.d.ts +2 -1
  14. package/dist/types/components/interaction/zoomEventPayload.d.ts +7 -0
  15. package/dist/types/core/rendering.d.ts +1 -1
  16. package/dist/types/core/renderingOptions.d.ts +1 -1
  17. package/dist/types/core/wasmSampling.d.ts +1 -1
  18. package/dist/types/core/workerSampling/multiresolution.d.ts +1 -1
  19. package/dist/types/core/workerSampling/protocol.d.ts +1 -1
  20. package/dist/types/core/workerSampling/repositoryDataset.d.ts +1 -1
  21. package/dist/types/core/workerSampling/repositorySupport.d.ts +1 -1
  22. package/dist/types/index.d.ts +1 -1
  23. package/dist/types/types/chart.d.ts +8 -0
  24. package/dist/types/types/index.d.ts +1 -1
  25. package/dist/types/utils/geometry.d.ts +1 -1
  26. package/dist/types/wasm/waveform_sampling_wasm.d.ts +74 -0
  27. package/dist/types/wasm/waveform_sampling_wasm_bg.wasm.d.ts +19 -0
  28. package/package.json +5 -4
  29. package/src/components/WaveformChartView.vue +3 -3
  30. package/src/components/core/grid.test.ts +3 -0
  31. package/src/components/core/grid.ts +4 -0
  32. package/src/components/core/trackPagination.ts +40 -0
  33. package/src/components/core/useWaveformChartController.ts +6 -1
  34. package/src/components/core/useWaveformChartLifecycle.ts +15 -9
  35. package/src/components/core/useWaveformLayout.ts +12 -9
  36. package/src/components/core/waveformChartTypes.ts +4 -0
  37. package/src/components/data/types.ts +1 -0
  38. package/src/components/index.ts +1 -0
  39. package/src/components/interaction/useWaveformViewport.ts +2 -0
  40. package/src/components/interaction/useWaveformZoom.ts +58 -61
  41. package/src/components/interaction/zoomEventPayload.ts +88 -0
  42. package/src/components/waveformChartCases/trackOrder.test.ts +62 -0
  43. package/src/components/waveformChartCases/zoomIntentAndDataRebind.test.ts +213 -0
  44. package/src/core/rendering.ts +1 -1
  45. package/src/core/renderingOptions.ts +1 -1
  46. package/src/core/workerSampling/multiresolution.ts +1 -1
  47. package/src/core/workerSampling/protocol.ts +1 -1
  48. package/src/core/workerSampling/repository.ts +1 -1
  49. package/src/core/workerSampling/repositoryDataset.ts +1 -1
  50. package/src/core/workerSampling/repositorySupport.ts +1 -1
  51. package/src/index.ts +1 -0
  52. package/src/types/chart.ts +9 -0
  53. package/src/types/index.ts +1 -0
  54. package/src/utils/geometry.ts +1 -1
@@ -0,0 +1,213 @@
1
+ import { flushPromises, mount } from '@vue/test-utils'
2
+ import { defineComponent, h, ref } from 'vue'
3
+ import { describe, expect, it, vi } from 'vitest'
4
+
5
+ import WaveformChart from '../WaveformChart.vue'
6
+ import type { WaveformData } from '../waveform'
7
+ import { resizeObservers } from '../../test/setup'
8
+ import { gridSeries, mountSizedChart } from '../../test/waveformChart'
9
+
10
+ function seriesWindow(ids: string[]) {
11
+ return {
12
+ kind: 'series' as const,
13
+ series: ids.map((id, index) => ({
14
+ id,
15
+ name: id,
16
+ data: {
17
+ kind: 'points' as const,
18
+ points: [
19
+ { x: 40, y: index },
20
+ { x: 50, y: index + 1 },
21
+ { x: 60, y: index + 2 },
22
+ ],
23
+ },
24
+ })),
25
+ }
26
+ }
27
+
28
+ function fullSeries(ids: string[]): WaveformData {
29
+ return {
30
+ kind: 'series',
31
+ series: ids.map((id, index) => ({
32
+ id,
33
+ name: id,
34
+ data: {
35
+ kind: 'points',
36
+ points: [
37
+ { x: 0, y: index },
38
+ { x: 50, y: index + 1 },
39
+ { x: 100, y: index + 2 },
40
+ ],
41
+ },
42
+ })),
43
+ }
44
+ }
45
+
46
+ function configureOverlay(overlay: ReturnType<typeof mount>['element']) {
47
+ const width = Number(overlay.getAttribute('width'))
48
+ const height = Number(overlay.getAttribute('height'))
49
+ Object.defineProperty(overlay, 'getBoundingClientRect', {
50
+ value: () => ({ left: 0, top: 0, width, height }),
51
+ })
52
+ return { width, height }
53
+ }
54
+
55
+ function dispatchWheel(overlay: Element, deltaY: number, width: number, height: number) {
56
+ overlay.dispatchEvent(
57
+ new WheelEvent('wheel', {
58
+ deltaY,
59
+ clientX: width / 2,
60
+ clientY: height / 2,
61
+ bubbles: true,
62
+ cancelable: true,
63
+ }),
64
+ )
65
+ }
66
+
67
+ describe('WaveformChart zoom intent and data rebind', () => {
68
+ it('keeps one shared wheel end after an immediate intent-driven data replacement', async () => {
69
+ vi.useFakeTimers()
70
+ try {
71
+ const data = ref<WaveformData>(fullSeries(['shared']))
72
+ const host = mount(
73
+ defineComponent({
74
+ setup() {
75
+ return () =>
76
+ h(WaveformChart, {
77
+ data: data.value,
78
+ displayMode: 'separated',
79
+ initialXDomain: [0, 100],
80
+ onZoomIntent: () => {
81
+ data.value = seriesWindow(['shared'])
82
+ },
83
+ })
84
+ },
85
+ }),
86
+ )
87
+ resizeObservers.at(-1)?.resize(800, 360)
88
+ await flushPromises()
89
+
90
+ const chart = host.findComponent(WaveformChart)
91
+ const overlay = chart.get('.waveform-chart__overlay')
92
+ const { width, height } = configureOverlay(overlay.element)
93
+ dispatchWheel(overlay.element, -4_000, width, height)
94
+
95
+ const firstIntent = chart.emitted('zoom-intent')?.[0]?.[0] as {
96
+ start: number
97
+ end: number
98
+ }
99
+ expect(firstIntent.end - firstIntent.start).toBeCloseTo(2.5)
100
+ expect(chart.emitted('zoom-change')).toBeUndefined()
101
+
102
+ await flushPromises()
103
+ dispatchWheel(overlay.element, 1_000, width, height)
104
+ await flushPromises()
105
+ await vi.advanceTimersByTimeAsync(199)
106
+ expect(chart.emitted('zoom-end')).toBeUndefined()
107
+
108
+ await vi.advanceTimersByTimeAsync(1)
109
+ await flushPromises()
110
+ const zoomEnd = chart.emitted('zoom-end')?.[0]?.[0] as { start: number; end: number }
111
+ expect(chart.emitted('zoom-intent')).toHaveLength(2)
112
+ expect(chart.emitted('zoom-end')).toHaveLength(1)
113
+ expect(zoomEnd.end - zoomEnd.start).toBeGreaterThan(firstIntent.end - firstIntent.start)
114
+ } finally {
115
+ vi.useRealTimers()
116
+ }
117
+ })
118
+
119
+ it('retains a pending independent wheel gesture by stable series identity', async () => {
120
+ vi.useFakeTimers()
121
+ try {
122
+ const data = ref<WaveformData>(fullSeries(['channel-a', 'channel-b']))
123
+ const host = mount(
124
+ defineComponent({
125
+ setup() {
126
+ return () =>
127
+ h(WaveformChart, {
128
+ data: data.value,
129
+ displayMode: 'independent',
130
+ grid: { rowCount: 1, columnCount: 2 },
131
+ initialXDomain: [0, 100],
132
+ onZoomIntent: () => {
133
+ data.value = seriesWindow(['channel-b', 'channel-a'])
134
+ },
135
+ })
136
+ },
137
+ }),
138
+ )
139
+ resizeObservers.at(-1)?.resize(800, 360)
140
+ await flushPromises()
141
+
142
+ const chart = host.findComponent(WaveformChart)
143
+ const overlay = chart.findAll('.waveform-chart__overlay--independent')[0]!
144
+ const { width, height } = configureOverlay(overlay.element)
145
+ dispatchWheel(overlay.element, -4_000, width, height)
146
+ await flushPromises()
147
+ await vi.advanceTimersByTimeAsync(200)
148
+ await flushPromises()
149
+
150
+ const zoomEnd = chart.emitted('zoom-end')?.[0]?.[0] as {
151
+ trackIndex: number
152
+ seriesIds: string[]
153
+ }
154
+ expect(chart.emitted('zoom-intent')?.[0]?.[0]).toMatchObject({
155
+ trackIndex: 0,
156
+ seriesIds: ['channel-a'],
157
+ gesture: 'wheel',
158
+ })
159
+ expect(zoomEnd).toMatchObject({ trackIndex: 1, seriesIds: ['channel-a'], gesture: 'wheel' })
160
+ } finally {
161
+ vi.useRealTimers()
162
+ }
163
+ })
164
+
165
+ it('emits box intent with the selected independent series', async () => {
166
+ const wrapper = await mountSizedChart(fullSeries(['series-a']), { initialXDomain: [0, 100] })
167
+ const overlay = wrapper.get('.waveform-chart__overlay--independent')
168
+ const { width, height } = configureOverlay(overlay.element)
169
+ const dispatchPointer = (type: string, clientX: number, clientY: number) => {
170
+ const event = new MouseEvent(type, { button: 0, clientX, clientY, bubbles: true })
171
+ Object.defineProperty(event, 'pointerId', { value: 11 })
172
+ overlay.element.dispatchEvent(event)
173
+ }
174
+
175
+ dispatchPointer('pointerdown', width * 0.25, height / 2)
176
+ dispatchPointer('pointermove', width * 0.75, height / 2)
177
+ dispatchPointer('pointerup', width * 0.75, height / 2)
178
+ await flushPromises()
179
+
180
+ expect(wrapper.emitted('zoom-intent')?.[0]?.[0]).toMatchObject({
181
+ trackIndex: 0,
182
+ seriesIds: ['series-a'],
183
+ gesture: 'box',
184
+ })
185
+ })
186
+
187
+ it('cancels pending wheel ends when reset or pagination changes the viewport', async () => {
188
+ vi.useFakeTimers()
189
+ try {
190
+ const reset = await mountSizedChart(fullSeries(['reset']), { initialXDomain: [0, 100] })
191
+ const resetOverlay = reset.get('.waveform-chart__overlay--independent')
192
+ const resetBounds = configureOverlay(resetOverlay.element)
193
+ dispatchWheel(resetOverlay.element, -4_000, resetBounds.width, resetBounds.height)
194
+ ;(reset.vm as unknown as { resetViewport: () => void }).resetViewport()
195
+ await vi.advanceTimersByTimeAsync(200)
196
+ expect(reset.emitted('zoom-end')).toBeUndefined()
197
+
198
+ const paged = await mountSizedChart(gridSeries(2), {
199
+ displayMode: 'independent',
200
+ grid: { rowCount: 1, columnCount: 1 },
201
+ })
202
+ const pageOverlay = paged.get('.waveform-chart__overlay--independent')
203
+ const pageBounds = configureOverlay(pageOverlay.element)
204
+ dispatchWheel(pageOverlay.element, -4_000, pageBounds.width, pageBounds.height)
205
+ await paged.get('.ant-pagination-next button').trigger('click')
206
+ await flushPromises()
207
+ await vi.advanceTimersByTimeAsync(200)
208
+ expect(paged.emitted('zoom-end')).toBeUndefined()
209
+ } finally {
210
+ vi.useRealTimers()
211
+ }
212
+ })
213
+ })
@@ -1,6 +1,6 @@
1
1
  import { bisector } from 'd3'
2
2
 
3
- import type { WaveformPoint } from '@/types'
3
+ import type { WaveformPoint } from '../types'
4
4
  import { resolveWaveformPointErrors } from './data'
5
5
  import type { ResolvedWaveformRenderingOptions } from './renderingOptions'
6
6
  import {
@@ -3,7 +3,7 @@ import type {
3
3
  WaveformSamplingMode,
4
4
  WaveformSamplingOptions,
5
5
  WaveformSamplingStrategy,
6
- } from '@/types'
6
+ } from '../types'
7
7
 
8
8
  export interface ResolvedWaveformSamplingOptions {
9
9
  mode: WaveformSamplingMode
@@ -1,4 +1,4 @@
1
- import type { WaveformPoint } from '@/types'
1
+ import type { WaveformPoint } from '../../types'
2
2
 
3
3
  import type { WorkerSamplingOutput } from './protocol'
4
4
 
@@ -6,7 +6,7 @@ import type {
6
6
  WaveformSamplingDiagnostics,
7
7
  WaveformSamplingMode,
8
8
  WaveformSamplingStrategy,
9
- } from '@/types'
9
+ } from '../../types'
10
10
  import type { WorkerSamplingDataset } from '../waveformPointSource'
11
11
 
12
12
  export const DEFAULT_WORKER_SAMPLING_AUTO_THRESHOLD = 1_000
@@ -1,4 +1,4 @@
1
- import type { WaveformPoint } from '@/types'
1
+ import type { WaveformPoint } from '../../types'
2
2
  import type { WorkerSamplingDataset } from '../waveformPointSource'
3
3
  import { javascriptSamplingBackend } from './javascriptBackend'
4
4
  import {
@@ -1,4 +1,4 @@
1
- import type { WaveformPoint } from '@/types'
1
+ import type { WaveformPoint } from '../../types'
2
2
  import type { WorkerSamplingDataset } from '../waveformPointSource'
3
3
  import type { WasmDatasetSamplingBackend } from '../wasmSampling'
4
4
  import { MultiResolutionSamplingIndex } from './multiresolution'
@@ -1,6 +1,6 @@
1
1
  import { bisector } from 'd3'
2
2
 
3
- import type { WaveformPoint } from '@/types'
3
+ import type { WaveformPoint } from '../../types'
4
4
  import {
5
5
  DEFAULT_WORKER_SAMPLING_AUTO_THRESHOLD,
6
6
  DEFAULT_WORKER_SAMPLING_MAX_POINTS_PER_PIXEL,
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ export type {
14
14
  WaveformOverlayMode,
15
15
  WaveformInteractionMode,
16
16
  WaveformXDomainStrategy,
17
+ WaveformZoomIntentPayload,
17
18
  WaveformZoomEndPayload,
18
19
  WaveformZoomResetPayload,
19
20
  WaveformAnnotationStyle,
@@ -49,6 +49,15 @@ export interface WaveformZoomEndPayload {
49
49
  gesture?: 'wheel' | 'box'
50
50
  }
51
51
 
52
+ /** Describes the X-axis viewport targeted by a user zoom gesture before rendering settles. */
53
+ export interface WaveformZoomIntentPayload {
54
+ start: number
55
+ end: number
56
+ gesture: 'wheel' | 'box'
57
+ trackIndex?: number
58
+ seriesIds?: string[]
59
+ }
60
+
52
61
  /** Identifies the viewport reset by a double-click gesture. */
53
62
  export interface WaveformZoomResetPayload {
54
63
  trackIndex?: number
@@ -9,6 +9,7 @@ export type {
9
9
  WaveformOverlayMode,
10
10
  WaveformInteractionMode,
11
11
  WaveformXDomainStrategy,
12
+ WaveformZoomIntentPayload,
12
13
  WaveformZoomEndPayload,
13
14
  WaveformZoomResetPayload,
14
15
  WaveformAnnotationStyle,
@@ -1,4 +1,4 @@
1
- import type { WaveformDisplayMode } from '@/types'
1
+ import type { WaveformDisplayMode } from '../types'
2
2
 
3
3
  /**
4
4
  * 轨道几何信息