waveform-analysis 0.1.78 → 0.1.79
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/README.md +4 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/components/interaction/zoomConstraints.ts +19 -18
package/package.json
CHANGED
|
@@ -53,20 +53,22 @@ function minimumPointSpan(
|
|
|
53
53
|
required: number,
|
|
54
54
|
): number {
|
|
55
55
|
if (required <= 1) return 0
|
|
56
|
-
let minimumSpan =
|
|
56
|
+
let minimumSpan = Number.POSITIVE_INFINITY
|
|
57
|
+
let hasData = false
|
|
57
58
|
for (const group of groups) {
|
|
58
59
|
const values = uniqueXValues(group, boundary)
|
|
59
60
|
if (!group.some((series) => (series.source?.length ?? series.points.length) > 0)) continue
|
|
60
|
-
|
|
61
|
+
hasData = true
|
|
62
|
+
if (values.length < required) continue
|
|
61
63
|
let groupSpan = Number.POSITIVE_INFINITY
|
|
62
64
|
for (let index = 0; index + required <= values.length; index += 1) {
|
|
63
65
|
groupSpan = Math.min(groupSpan, values[index + required - 1] - values[index])
|
|
64
66
|
}
|
|
65
67
|
const endpointTolerance =
|
|
66
68
|
Number.EPSILON * Math.max(1, Math.abs(boundary[0]), Math.abs(boundary[1])) * 16
|
|
67
|
-
minimumSpan = Math.
|
|
69
|
+
minimumSpan = Math.min(minimumSpan, groupSpan + endpointTolerance)
|
|
68
70
|
}
|
|
69
|
-
return minimumSpan
|
|
71
|
+
return Number.isFinite(minimumSpan) ? minimumSpan : hasData ? boundary[1] - boundary[0] : 0
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
export function resolveMinimumZoomSpan(
|
|
@@ -102,25 +104,25 @@ function expandToMinimumPoints(
|
|
|
102
104
|
if (required <= 0) return domain
|
|
103
105
|
const endpointTolerance =
|
|
104
106
|
Number.EPSILON * Math.max(1, Math.abs(boundary[0]), Math.abs(boundary[1])) * 16
|
|
105
|
-
let
|
|
107
|
+
let best: [number, number] | undefined
|
|
108
|
+
let bestSpan = Number.POSITIVE_INFINITY
|
|
109
|
+
let bestCenterDistance = Number.POSITIVE_INFINITY
|
|
110
|
+
let hasData = false
|
|
111
|
+
const requestedCenter = (domain[0] + domain[1]) / 2
|
|
106
112
|
for (const group of groups) {
|
|
107
113
|
const values = uniqueXValues(group, boundary)
|
|
108
114
|
if (!group.some((series) => (series.source?.length ?? series.points.length) > 0)) continue
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (visibleCount >= required)
|
|
114
|
-
let best: [number, number] | undefined
|
|
115
|
-
let bestSpan = Number.POSITIVE_INFINITY
|
|
116
|
-
let bestCenterDistance = Number.POSITIVE_INFINITY
|
|
117
|
-
const requestedCenter = (expanded[0] + expanded[1]) / 2
|
|
115
|
+
hasData = true
|
|
116
|
+
if (values.length < required) continue
|
|
117
|
+
const visibleCount = values.filter((value) => value >= domain[0] && value <= domain[1]).length
|
|
118
|
+
// Shared tracks need one supporting frame, rather than every frame.
|
|
119
|
+
if (visibleCount >= required) return domain
|
|
118
120
|
for (let index = 0; index + required <= values.length; index += 1) {
|
|
119
121
|
const candidate: [number, number] = [
|
|
120
|
-
Math.max(boundary[0], Math.min(
|
|
122
|
+
Math.max(boundary[0], Math.min(domain[0], values[index] - endpointTolerance)),
|
|
121
123
|
Math.min(
|
|
122
124
|
boundary[1],
|
|
123
|
-
Math.max(
|
|
125
|
+
Math.max(domain[1], values[index + required - 1] + endpointTolerance),
|
|
124
126
|
),
|
|
125
127
|
]
|
|
126
128
|
const span = candidate[1] - candidate[0]
|
|
@@ -131,9 +133,8 @@ function expandToMinimumPoints(
|
|
|
131
133
|
bestCenterDistance = centerDistance
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
|
-
expanded = best ?? [...boundary]
|
|
135
136
|
}
|
|
136
|
-
return
|
|
137
|
+
return best ?? (hasData ? [...boundary] : domain)
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
export function constrainZoomDomain(
|