waveform-analysis 0.1.42 → 0.1.46
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.
- package/dist/index.cjs +1 -1
- package/dist/index.js +163 -161
- package/dist/style.css +1 -1
- package/dist/types/components/core/constants.d.ts +2 -2
- package/dist/types/components/core/types.d.ts +2 -1
- package/dist/types/components/core/yAxisConstants.d.ts +2 -2
- package/dist/types/components/interaction/WaveformTooltip.vue.d.ts +1 -1
- package/package.json +1 -1
- package/src/App.test.ts +2 -7
- package/src/components/WaveformChart.css +1 -1
- package/src/components/core/constants.ts +3 -3
- package/src/components/core/layout.test.ts +3 -3
- package/src/components/core/layout.ts +2 -2
- package/src/components/core/trackLayoutBuilder.ts +3 -5
- package/src/components/core/types.ts +2 -1
- package/src/components/core/useWaveformChartController.ts +1 -0
- package/src/components/core/yAxisConstants.ts +2 -2
- package/src/components/interaction/WaveformHoverHost.vue +3 -1
- package/src/components/interaction/WaveformTooltip.test.ts +23 -0
- package/src/components/interaction/WaveformTooltip.vue +9 -6
- package/src/components/interaction/useWaveformHover.ts +19 -14
- package/src/components/rendering/WaveformHoverLayer.vue +5 -11
- package/src/components/rendering/WaveformTrackAxes.vue +5 -4
- package/src/components/waveformChartCases/compactAndSharedHover.test.ts +43 -0
- package/src/components/waveformChartCases/dataLifecycle.test.ts +1 -1
- package/src/components/waveformChartCases/frameGridAndFormatting.test.ts +10 -0
- package/src/components/waveformChartCases/incompleteDataHover.test.ts +67 -0
- package/src/components/waveformChartCases/layoutAndDomains.test.ts +5 -5
- package/src/components/waveformChartCases/legendVisibility.test.ts +1 -1
- package/src/components/waveformChartCases/multiAxisAndPagination.test.ts +1 -1
- package/src/data/simulatedWaveforms.test.ts +7 -2
- package/src/data/simulatedWaveforms.ts +12 -7
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { flushPromises } from '@vue/test-utils'
|
|
2
|
+
import { describe, expect, it } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import { flushAnimationFrames } from '../../test/setup'
|
|
5
|
+
import { mountSizedChart } from '../../test/waveformChart'
|
|
6
|
+
|
|
7
|
+
describe('WaveformChart incomplete data hover', () => {
|
|
8
|
+
it('keeps the shared crosshair at the query time and marks out-of-range series unavailable', async () => {
|
|
9
|
+
const wrapper = await mountSizedChart(
|
|
10
|
+
{
|
|
11
|
+
kind: 'series',
|
|
12
|
+
series: [
|
|
13
|
+
{
|
|
14
|
+
name: '完整数据',
|
|
15
|
+
data: {
|
|
16
|
+
kind: 'points',
|
|
17
|
+
points: [
|
|
18
|
+
{ x: -1, y: 1 },
|
|
19
|
+
{ x: -0.5, y: 2 },
|
|
20
|
+
{ x: 1, y: 3 },
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: '从零开始',
|
|
26
|
+
data: {
|
|
27
|
+
kind: 'points',
|
|
28
|
+
points: [
|
|
29
|
+
{ x: 0, y: 10 },
|
|
30
|
+
{ x: 1, y: 20 },
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
{ displayMode: 'separated' },
|
|
37
|
+
)
|
|
38
|
+
const overlay = wrapper.get('.waveform-chart__overlay--shared')
|
|
39
|
+
const overlayWidth = Number(overlay.attributes('width'))
|
|
40
|
+
Object.defineProperty(overlay.element, 'getBoundingClientRect', {
|
|
41
|
+
value: () => ({ left: 0, top: 0, width: overlayWidth, height: 290 }),
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
overlay.element.dispatchEvent(
|
|
45
|
+
new MouseEvent('pointermove', {
|
|
46
|
+
clientX: overlayWidth / 4,
|
|
47
|
+
clientY: 120,
|
|
48
|
+
bubbles: true,
|
|
49
|
+
}),
|
|
50
|
+
)
|
|
51
|
+
flushAnimationFrames()
|
|
52
|
+
await flushPromises()
|
|
53
|
+
|
|
54
|
+
const crosshairPositions = wrapper
|
|
55
|
+
.findAll('.waveform-chart__crosshair line')
|
|
56
|
+
.map((line) => Number(line.attributes('x1')))
|
|
57
|
+
expect(crosshairPositions).toHaveLength(2)
|
|
58
|
+
expect(crosshairPositions[0]).toBeCloseTo(overlayWidth / 4)
|
|
59
|
+
expect(crosshairPositions[1]).toBeCloseTo(overlayWidth / 4)
|
|
60
|
+
const tooltipRows = wrapper.findAll('.waveform-chart__tooltip-series')
|
|
61
|
+
expect(tooltipRows).toHaveLength(2)
|
|
62
|
+
expect(tooltipRows[0].text()).toContain('(x:-500 y:2)')
|
|
63
|
+
expect(tooltipRows[1].text()).toContain('无数据')
|
|
64
|
+
expect(tooltipRows[1].text()).not.toContain('x:')
|
|
65
|
+
expect(wrapper.emitted('point-hover')?.at(-1)).toEqual([{ x: -0.5, y: 2 }])
|
|
66
|
+
})
|
|
67
|
+
})
|
|
@@ -53,10 +53,10 @@ describe('WaveformChart', () => {
|
|
|
53
53
|
tracks[0].get('.waveform-chart__y-axis-label-bg').attributes('x'),
|
|
54
54
|
)
|
|
55
55
|
|
|
56
|
-
expect(labelX).toBe(-
|
|
57
|
-
expect(labelBackgroundX).toBe(labelX -
|
|
58
|
-
expect(Number(wrapper.attributes('data-chart-left-margin'))).toBe(
|
|
59
|
-
expect(secondLeft - firstWidth).toBeGreaterThanOrEqual(
|
|
56
|
+
expect(labelX).toBe(-62)
|
|
57
|
+
expect(labelBackgroundX).toBe(labelX - 6)
|
|
58
|
+
expect(Number(wrapper.attributes('data-chart-left-margin'))).toBe(80)
|
|
59
|
+
expect(secondLeft - firstWidth).toBeGreaterThanOrEqual(72)
|
|
60
60
|
})
|
|
61
61
|
|
|
62
62
|
it('keeps a tick-only gutter when channel labels are empty', async () => {
|
|
@@ -82,7 +82,7 @@ describe('WaveformChart', () => {
|
|
|
82
82
|
const secondLeft = Number(tracks[1].attributes('data-track-left'))
|
|
83
83
|
|
|
84
84
|
expect(wrapper.findAll('.waveform-chart__y-axis-label')).toHaveLength(0)
|
|
85
|
-
expect(Number(wrapper.attributes('data-chart-left-margin'))).toBe(
|
|
85
|
+
expect(Number(wrapper.attributes('data-chart-left-margin'))).toBe(80)
|
|
86
86
|
expect(secondLeft - firstWidth).toBeGreaterThanOrEqual(60)
|
|
87
87
|
})
|
|
88
88
|
|
|
@@ -343,7 +343,7 @@ describe('WaveformChart', () => {
|
|
|
343
343
|
const secondLeft = Number(tracks[1].attributes('data-track-left'))
|
|
344
344
|
const labelX = Number(tracks[1].attributes('data-y-axis-label-x'))
|
|
345
345
|
|
|
346
|
-
expect(secondLeft - (firstLeft + firstWidth)).toBeGreaterThanOrEqual(Math.abs(labelX) +
|
|
346
|
+
expect(secondLeft - (firstLeft + firstWidth)).toBeGreaterThanOrEqual(Math.abs(labelX) + 6)
|
|
347
347
|
expect(tracks[1].find('.waveform-chart__y-axis-label-bg').exists()).toBe(true)
|
|
348
348
|
}
|
|
349
349
|
})
|
|
@@ -21,8 +21,13 @@ describe('simulated waveform data', () => {
|
|
|
21
21
|
first.series.forEach((series) => {
|
|
22
22
|
expect(series.data.kind).toBe('points')
|
|
23
23
|
if (series.data.kind !== 'points') return
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
if (series.id === 'simulated-step') {
|
|
25
|
+
expect(series.data.points).toHaveLength(500)
|
|
26
|
+
expect(series.data.points.every((point) => point.x >= 0)).toBe(true)
|
|
27
|
+
} else {
|
|
28
|
+
expect(series.data.points).toHaveLength(1_000)
|
|
29
|
+
expect(series.data.points[0]?.x).toBe(-5)
|
|
30
|
+
}
|
|
26
31
|
expect(series.data.points.at(-1)?.x).toBe(5)
|
|
27
32
|
series.data.points.forEach((point) => {
|
|
28
33
|
expect(Number.isFinite(point.x)).toBe(true)
|
|
@@ -17,6 +17,7 @@ interface SimulatedSeriesDefinition extends Pick<
|
|
|
17
17
|
> {
|
|
18
18
|
signal: SignalGenerator
|
|
19
19
|
errors?: ErrorGenerator
|
|
20
|
+
minimumX?: number
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
function createSeededNoise(seed: number) {
|
|
@@ -100,6 +101,7 @@ const seriesDefinitions: SimulatedSeriesDefinition[] = [
|
|
|
100
101
|
unit: 'V',
|
|
101
102
|
lineType: 'linear',
|
|
102
103
|
pointType: 'none',
|
|
104
|
+
minimumX: 0,
|
|
103
105
|
signal: (time) => (time < 0 ? 0 : 1 - Math.exp(-time * 2.4)),
|
|
104
106
|
},
|
|
105
107
|
{
|
|
@@ -128,12 +130,15 @@ export function createSimulatedWaveformData(): WaveformData {
|
|
|
128
130
|
const noise = createSeededNoise(0x5eed1234)
|
|
129
131
|
return {
|
|
130
132
|
kind: 'series',
|
|
131
|
-
series: seriesDefinitions.map(({ signal, errors, ...series }) =>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
series: seriesDefinitions.map(({ signal, errors, minimumX, ...series }) => {
|
|
134
|
+
const points = createPoints(signal, noise, errors)
|
|
135
|
+
return {
|
|
136
|
+
...series,
|
|
137
|
+
data: {
|
|
138
|
+
kind: 'points' as const,
|
|
139
|
+
points: minimumX === undefined ? points : points.filter((point) => point.x >= minimumX),
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
}),
|
|
138
143
|
}
|
|
139
144
|
}
|