fix: 让显影参数覆盖完整范围
This commit is contained in:
+2
-2
@@ -74,10 +74,10 @@ app.innerHTML = `
|
||||
<label class="control" for="retention-control">
|
||||
<span class="control__heading">
|
||||
<span>显影</span>
|
||||
<output id="retention-value">14%</output>
|
||||
<output id="retention-value">15%</output>
|
||||
</span>
|
||||
<span class="control__hint">留下多少原文词语</span>
|
||||
<input id="retention-control" type="range" min="5" max="40" value="14" />
|
||||
<input id="retention-control" type="range" min="0" max="100" value="15" />
|
||||
</label>
|
||||
|
||||
<label class="control" for="volume-control">
|
||||
|
||||
@@ -36,6 +36,14 @@ describe('selectKeywords', () => {
|
||||
|
||||
expect(candidates.some((candidate) => candidate.selected)).toBe(true)
|
||||
})
|
||||
|
||||
it('显影 0% 不保留词语,100% 保留全部候选词', () => {
|
||||
const hidden = selectKeywords(SOURCE, 0, 1)
|
||||
const revealed = selectKeywords(SOURCE, 100, 1)
|
||||
|
||||
expect(hidden.some((candidate) => candidate.selected)).toBe(false)
|
||||
expect(revealed.every((candidate) => candidate.selected)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('generateMosaic', () => {
|
||||
|
||||
+7
-7
@@ -345,13 +345,13 @@ export function selectKeywords(
|
||||
return candidates
|
||||
}
|
||||
|
||||
const desiredCount = Math.min(
|
||||
candidates.length,
|
||||
Math.max(
|
||||
candidates.length >= 4 ? 2 : 1,
|
||||
Math.round(candidates.length * (retention / 100)),
|
||||
),
|
||||
)
|
||||
const desiredCount =
|
||||
retention <= 0
|
||||
? 0
|
||||
: Math.min(
|
||||
candidates.length,
|
||||
Math.max(1, Math.ceil(candidates.length * (retention / 100))),
|
||||
)
|
||||
const ranked = [...candidates].sort(
|
||||
(left, right) => right.score - left.score || left.start - right.start,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user