Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/renderers/kit/src/zoom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {defineControls} from '@githubnext/projections-renderer-sdk/protocol'
import {openingFloorPx} from '@githubnext/projections-renderer-sdk/presentation'

/**
* Zoom actions the host draws for a scalable stage (see `useStageZoom`); pass
Expand Down Expand Up @@ -46,8 +47,14 @@ export {openingFloorPx} from '@githubnext/projections-renderer-sdk/presentation'
export {contentStart} from './content-start.js'
export type {ContentBox} from './content-start.js'

/** How far (as a share) a fit may fall below the floor and still open fitted: zooming a hair would only scroll a pixel. */
const floorSlack = 0.004
/**
* How far (CSS px) a fit's smallest text may fall below `openingFloorPx` and still open fitted: zooming a hair would
* only scroll a pixel. It is the built-in opening check's `floorTolerance` (`checks/frame/opening.ts` in the renderer
* testing package), which counts such a fit as at the floor, so the kit never opens zoomed where the check says fitted.
*/
const floorTolerancePx = 0.05
/** `floorTolerancePx` as a share of the fit's zoom to the floor. */
const floorSlack = floorTolerancePx / (openingFloorPx - floorTolerancePx)

/**
* The zoom multiple a stage fitted at `fit` opens at, given the scale `floor` at which its smallest text reaches
Expand Down
3 changes: 3 additions & 0 deletions packages/renderers/kit/test/layout.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,9 @@ test('a stage opens fitted unless that draws text below the floor, then at the f
assert.equal(openingZoom(1, floor), 1, 'text drawn at 12 px opens fitted')
assert.equal(openingZoom(floor, floor), 1, 'text exactly at the floor opens fitted')
assert.equal(openingZoom(floor * 0.999, floor), 1, 'a hair below the floor still opens fitted')
// graph/nuget-update at 390px: fitted text 7.956 px, within the opening check's tolerance, so it opens fitted.
assert.equal(openingZoom(floor / 1.005587, floor), 1, 'text within 0.05 px of the floor (the opening check tolerance) opens fitted')
assert.ok(openingZoom(floor * (7.9 / 8), floor) > 1, 'text further below the floor than the tolerance zooms to it')
assert.ok(Math.abs(openingZoom(0.2, floor) * 0.2 * 12 - 8) < 1e-4, 'a small fit opens where the smallest text is 8 px')
assert.equal(openingZoom(0.5, 0), 1, 'no text measured yet: fitted')
// The top row's leftmost box, 12 units clear, at the view's top left, never the empty room the bounds begin with.
Expand Down
2 changes: 1 addition & 1 deletion packages/renderers/testing/src/checks/frame/opening.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Skip, Passed, limit, label, type Checks} from '../support.js'

/** The frame a zoomable renderer must open fitted in: about a VS Code tab at full width, and a phone. */
const openingFrame = {height: 650, phoneHeight: 700}
/** Rounding slack in a measured text size, CSS px. */
/** Rounding slack in a measured text size, CSS px: the kit's `openingZoom` opens fitted within it too (its `floorTolerancePx`). */
const floorTolerance = 0.05
/**
* How far above the floor a canvas opened at it may draw its smallest visible text: the floor also counts text that
Expand Down
Loading