Skip to content
Merged
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: 4 additions & 7 deletions docs/builtins/renderers/graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,10 @@ The card options show facts the extraction keeps in `data` on the canvas:
changed icon crossfades with the card's step; the diff shows the After icon
and lists the change with the card's other field changes.

- **Size by** draws a bar along each card's top edge, from its leading corner in
the card's color, as long as the square root of a numeric field's share of the
largest value, so the heavy parts of a graph stand out while every card keeps
one width and the cards line up in columns. The number itself, compact
(`12K`), is at the right of the card's kind line, and the legend says what the
bar means (`Top bar: tokens`). A changed value's bar grows or shrinks with its
card's step.
- **Size by** shows a numeric field's value on each card, compact (`12K`), at
the right of the card's kind line, and the legend says what the number is
(`Number on each card: tokens`). Every card keeps one width, so the cards line
up in columns. A changed value crossfades with its card's step.
- **Badges** draws a field's values as small monospace pills under each card's
label: each item of a list, a string or number itself, and a `true` boolean as
the field's name. The card grows a row for each row of badges.
Expand Down
23 changes: 0 additions & 23 deletions docs/reference/renderer-kit.md
Original file line number Diff line number Diff line change
Expand Up @@ -3350,28 +3350,6 @@ variedWords(within: false | true): string

How a varied value relates to its tolerance, in words: `within tolerance` or `beyond tolerance (volatile)`.

### `WeightShare`

```ts
interface WeightShare
```

A row's weight as a share of the heaviest row's, by revision (see `weightShares`).

| Member | Signature | Description |
|---|---|---|
| `after` | `"after"?: number` | The share in the After revision, between 0 and 1; none when it has no positive weight there. |
| `before` | `"before"?: number` | The share in the Before revision, between 0 and 1; none when it has no positive weight there. |

### `weightShares`

```ts
weightShares(rows: Array<EntityChange<Entity>>, weight: { (entity: Entity): number | undefined }): Map<string, WeightShare>
```

Each weighed row's weight in each revision as the square root of its share of the heaviest weight of either, so
area-like differences read without the heaviest dwarfing the rest. Rows without a positive weight have none.

### `Window`

```ts
Expand Down Expand Up @@ -3812,7 +3790,6 @@ Everything but the renderer props is optional; the defaults draw every entity as
| `syntheticAction` | `"syntheticAction"?: undefined \| { (entity: Entity): undefined \| { "expanded"?: false \| true; "label": string } }` | A synthetic card's accessible name and, for one that opens or closes a group of cards, whether that group is open (`aria-expanded`). Defaults to `Show` and the card's label. |
| `viewport` | `"viewport": undefined \| { "height": number; "width": number }` | The frame's width and the host window's height, CSS px, as the host last reported them; undefined until then. |
| `visibleIds` | `"visibleIds"?: ReadonlySet<string> \| undefined` | Entity rows to present, for example after a search; defaults to every row. |
| `weight` | `"weight"?: undefined \| { (entity: Entity): number \| undefined }` | A card's weight, such as its lines of code: a gauge along the card's top edge from its leading corner, as long as the square root of its share of the heaviest row's weight (see `weightShares`), in its accent's paint, so the heavy parts of a graph stand out while every card keeps the graph's one width and the cards line up in columns. Rows without a positive weight have no gauge. Pass a stable function. |

### `graphEntityLimit`

Expand Down
7 changes: 3 additions & 4 deletions packages/renderers/graph/browser/architecture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,16 @@ test('a definition can give cards a subtitle, size them by a number and add word
// The subtitle wraps to the card's one width, a line per tspan.
await expect(server.locator('.node-subtitle')).toContainText(/Serves the\s*server/)
await expect(server.locator('.node-detail')).toHaveText('9K')
// Every card keeps one width; the heavier card's gauge along its top edge is longer.
// Every card keeps one width, and the number is its only mark of size: no bar along its top edge.
const width = async (card: typeof server) => Number(await card.locator('.node-surface').getAttribute('width'))
expect(await width(server)).toBe(await width(store))
const gauge = async (card: typeof server) => (await card.locator('.node-gauge').boundingBox())?.width ?? 0
expect(await gauge(server)).toBeGreaterThan(await gauge(store))
await expect(renderer.frame.locator('.node-gauge')).toHaveCount(0)
// Labels are words, in sans; badges are code, in monospace; subtitles are sans.
await expect(server.locator('.node-badge-text')).toHaveText(['property tests', 'network', 'filesystem'])
await expect(server.locator('.node-badge-text').first()).not.toHaveAttribute('data-projections-identifier')
await expect(server.locator('.node-badge-text').nth(1)).toHaveAttribute('data-projections-identifier', '')
await expect(server.locator('.node-subtitle')).not.toHaveAttribute('data-projections-identifier')
await expect.poll(async () => (await renderer.state()).legend?.items.at(-1)).toEqual({label: 'Top bar: lines'})
await expect.poll(async () => (await renderer.state()).legend?.items.at(-1)).toEqual({label: 'Number on each card: lines'})
})

test("a field naming icons draws each before its card's kind, crossfades a changed one and ignores unknown names", async ({page}) => {
Expand Down
1 change: 0 additions & 1 deletion packages/renderers/graph/src/fact-graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export function FactGraph(
accent={facts.accent}
subtitle={facts.subtitle}
icon={facts.icon}
weight={facts.weight}
detail={facts.detail ?? canvas.detail}
relationshipColor={facts.relationshipColor}
/>
Expand Down
6 changes: 2 additions & 4 deletions packages/renderers/graph/src/facts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export interface CardFacts {
subtitle?: (entity: Entity) => string | undefined
/** The card icon a field names (`cardIconNames`), before the card's kind line. */
icon?: (entity: Entity) => string | undefined
weight?: (entity: Entity) => number | undefined
/** The size field's number, compact (`12K`), at the right of a card's kind line. */
Comment thread
agorischek marked this conversation as resolved.
Resolved
detail?: (entity: Entity) => string | undefined
accent?: (entity: Entity) => CardAccent | undefined
Expand Down Expand Up @@ -85,8 +84,8 @@ export function cardFacts(model: ComparisonModel, options: CardFactOptions): Car
if (entry.category.key.startsWith('card:')) cardItems.push({label: entry.category.label, ...entry.swatch})
// The title names what colors the cards (a field's name verbatim); relationship kinds are lines, which say what they are.
const title = colorBy ? (field ?? 'Kind') : options.kinds.length ? 'Relationships' : 'Cards'
// What a card's gauge means has no swatch: it is said in words.
const sizeItems: LegendItem[] = sizeField === undefined ? [] : [{label: `Top bar: ${sizeField}`}]
// What the number on each card is has no swatch: it is said in words.
const sizeItems: LegendItem[] = sizeField === undefined ? [] : [{label: `Number on each card: ${sizeField}`}]
const items = [...cardItems, ...edgeItems, ...sizeItems]
// Highlights first, then labels and badges on pills, then the quiet tags.
const badgeParts: ((entity: Entity) => CardBadge[])[] = []
Expand All @@ -102,7 +101,6 @@ export function cardFacts(model: ComparisonModel, options: CardFactOptions): Car
...(sizeField === undefined
? {}
: {
weight: (entity: Entity) => numberValue(entity, sizeField),
detail: (entity: Entity) => {
const value = numberValue(entity, sizeField)
return value === undefined ? undefined : compact.format(value)
Expand Down
2 changes: 1 addition & 1 deletion packages/renderers/graph/src/facts/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function factControls(fields: FactFields, kinds: readonly string[]): Rend
controls.push({
id: 'sizeBy',
label: 'Size by',
description: "Make each card wider the larger a data field's number is, and show the number",
description: "Show a data field's number on each card, compact (12K)",
type: 'choice',
...group,
default: 'none',
Expand Down
6 changes: 2 additions & 4 deletions packages/renderers/graph/test/facts.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,9 @@ test('a numeric field sizes cards and a text field is their subtitle', () => {
const [engineCard, host, helper] = sized.entities
assert.equal(facts.subtitle(engineCard), 'The shared engine')
assert.equal(facts.subtitle(helper), undefined)
assert.equal(facts.weight(engineCard), 23000)
assert.equal(facts.weight(helper), undefined)
// The number reads compact at the right of the kind line, and the legend says what the width means.
// The number reads compact at the right of the kind line, and the legend says what it is.
assert.deepEqual([facts.detail(engineCard), facts.detail(host), facts.detail(helper)], ['23K', '900', undefined])
assert.deepEqual(facts.legend, {title: 'Cards', items: [{label: 'Top bar: code'}]})
assert.deepEqual(facts.legend, {title: 'Cards', items: [{label: 'Number on each card: code'}]})
})

test('labels are worded badges, before the code badges', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/renderers/kit/src/diff-card/lines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export function writeKindLine(card: CardLines, kind: KindLine): void {
if (kind.detail !== undefined) writeDetail(card, kind, detailBeside)
}

function writeDetail(card: CardLines, kind: KindLine, beside: boolean): void {
/** Writes a kind line's detail: beside the kind's last line, or on lines of its own under what is written so far. */
export function writeDetail(card: CardLines, kind: KindLine, beside: boolean): void {
const detailLine = (spans: DiffCardSpan[], beside: boolean) =>
card.lines.push({
x: beside ? card.cardWidth - diffCardMetrics.textInset - card.reserve : card.left,
Expand Down
5 changes: 4 additions & 1 deletion packages/renderers/kit/src/diff-card/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {cardIconRoom} from '../card-icons.js'
import {svgStatusWidth} from '../svg-status.js'
import {cardFooterHeight, cardHeight} from '../layout.js'
import {wrapText} from '../wrap.js'
import {nextLine, writeFields, writeKindLine} from './lines.js'
import {nextLine, writeDetail, writeFields, writeKindLine} from './lines.js'
import type {CardLines, KindLine} from './lines.js'
import {diffCardMetrics} from './metrics.js'
import type {DiffCardInput, DiffCardText} from './metrics.js'
Expand Down Expand Up @@ -108,6 +108,9 @@ export function diffCardText(input: DiffCardInput): DiffCardText {
})
})
})
// A file has no kind line: its detail (a size, a version) takes a line of its own under its path.
const fileDetail = file ? kindLine(input) : undefined
if (fileDetail?.detail !== undefined) writeDetail(card, fileDetail, false)
writeFields(card, input.fields ?? [])
return {lines: card.lines, width: cardWidth, height: Math.max(cardHeight(entity.kind), card.y + m.bottom + cardFooterHeight)}
}
37 changes: 0 additions & 37 deletions packages/renderers/kit/src/graph-canvas/weight.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/renderers/kit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export * from './summary.js'
export {cardBox, drawnEdge} from './graph-canvas/edges.js'
export {badgeMetrics, badgeText, placeBadges} from './graph-canvas/badges.js'
export type {CardAccent, CardBadge} from './graph-canvas/badges.js'
export {weightShares} from './graph-canvas/weight.js'
export type {WeightShare} from './graph-canvas/weight.js'
export * from './controls.js'
export * from './table.js'
export * from './table-controls.js'
Expand Down
12 changes: 3 additions & 9 deletions packages/renderers/kit/src/react/graph-canvas/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import {expanderMetrics} from './entity-card.js'
import {badgeCardWidth, badgeGrowth} from '../../graph-canvas/badges.js'
import {fanInWidths} from '../../graph-canvas/fan-in.js'
import {subtitleGrowth} from './subtitle.js'
import {weightShares} from '../../graph-canvas/weight.js'
import type {WeightShare} from '../../graph-canvas/weight.js'

/**
* The room a row's card keeps at the right of its kind line for its expander, when it has one (see `EntityCard`): on
Expand Down Expand Up @@ -123,9 +121,9 @@ export function GraphCanvas(props: GraphCanvasProps) {
const width = Math.max(cardWidthRange.min, badgeWidth, ...model.entities.map(row => card(row).width))
return new Map(model.entities.map(row => [row.id, card(row, width)]))
}, [diff, model, fields, textScale, badgeWidth, icon])
// Hubs grow so the relationships into them keep apart (see `fanInWidths`); a card's weight is its gauge, not its
// width, so the cards keep one width and line up in columns (see `weightShares`).
const {weight, subtitle} = props
// Hubs grow so the relationships into them keep apart (see `fanInWidths`); otherwise the cards keep one width and
// line up in columns.
const {subtitle} = props
const widths = useMemo(() => {
if (cards) return fanInWidths(model, new Map([...cards].map(([id, card]) => [id, card.width])), orientation)
const {kindLine, detail, prose, describeStatus} = text.current
Expand All @@ -138,7 +136,6 @@ export function GraphCanvas(props: GraphCanvasProps) {
)
return fanInWidths(model, new Map(model.entities.map(row => [row.id, width] as const)), orientation)
}, [cards, model, comparing, textScale, badgeWidth, orientation, icon])
const shares = useMemo(() => (weight ? weightShares(model.entities, weight) : undefined), [weight, model])
// Cards grow for their badge rows and their subtitle's lines.
const badgeRows = useMemo(
() => (badges ? badgeGrowth(model.entities, badges, widths, textScale) : undefined),
Expand Down Expand Up @@ -210,7 +207,6 @@ export function GraphCanvas(props: GraphCanvasProps) {
textScale,
badgeGrowth: badgeRows,
subtitleGrowth: subtitleRows,
weightShares: shares,
}
: last
drawn.current = shown
Expand All @@ -226,7 +222,6 @@ export function GraphCanvas(props: GraphCanvasProps) {
textScale={shown.textScale}
badgeGrowth={shown.badgeGrowth}
subtitleGrowth={shown.subtitleGrowth}
weightShares={shown.weightShares}
/>
) : (
<div className="graph-container">
Expand All @@ -251,5 +246,4 @@ interface Drawn {
textScale: number
badgeGrowth: ReadonlyMap<string, number> | undefined
subtitleGrowth: ReadonlyMap<string, number> | undefined
weightShares: ReadonlyMap<string, WeightShare> | undefined
}
10 changes: 6 additions & 4 deletions packages/renderers/kit/src/react/graph-canvas/card-lines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ export function cardLinesLayout(node: TransitionNode, entity: Entity, drawing: D
const labelY = top + (fileNode ? cardTextMetrics.firstBaseline : cardTextMetrics.labelBaseline)
const prose = props.prose?.(entity) ?? false
const labelFont = prose ? {} : identifier
// Text longer than the card holds ends in an ellipsis, and the card's tooltip has it whole.
const labelRoom = Math.floor((textRight - textLeft) / cardTextWidth('x', prose ? 'label' : 'mono', textScale))
const details = [node.before, node.after].map(side => (side ? props.detail?.(side) : undefined))
const shownDetails = details.map(text => (text ? detailText(text) : undefined))
const detailWidth = Math.max(0, ...shownDetails.map(text => (text ? cardTextWidth(text, 'mono', textScale) : 0)))
// Text longer than the card holds ends in an ellipsis, and the card's tooltip has it whole. A file has no kind line,
// so its detail sits at the right of its path, which leaves it room.
const besideLabel = fileNode && detailWidth ? cardTextMetrics.detailGap + detailWidth : 0
const labelRoom = Math.floor((textRight - textLeft - besideLabel) / cardTextWidth('x', prose ? 'label' : 'mono', textScale))
const kindLine = kindOf(entity) ?? entityKindLine(entity.kind)
const note = kindNote(kindOf(entity), entity.confidence === 'inferred')
const kindRoom =
Expand Down Expand Up @@ -100,7 +102,7 @@ export function CardLines({node, text}: {node: TransitionNode; text: CardLinesLa
return (
<>
{!fileNode && <KindLine kind={kindLine} text={kindShown} note={note} x={kindLeft} y={kindY} />}
{!fileNode && <CardDetail node={node} text={text} />}
<CardDetail node={node} text={text} />
{relabeled ? (
// The old name rises out as the new one rises in.
[node.before!, node.after!].map((item, index) => (
Expand All @@ -124,7 +126,7 @@ export function CardLines({node, text}: {node: TransitionNode; text: CardLinesLa
)
}

/** The detail at the right of a card's kind line; when it differs between revisions, the two crossfade. */
/** The detail at the right of a card's kind line (a file's path line); when it differs between revisions, the two crossfade. */
function CardDetail({node, text}: {node: TransitionNode; text: CardLinesLayout}) {
const {textRight, kindY, details, shownDetails} = text
return details[0] !== details[1] && node.before && node.after
Expand Down
9 changes: 4 additions & 5 deletions packages/renderers/kit/src/react/graph-canvas/drawing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {FieldLine} from '../../diff/lines.js'
import type {KindLineText} from '../../card-text.js'
import type {GraphCanvasProps} from './props.js'
import {badgeText} from '../../graph-canvas/badges.js'
import type {WeightShare} from '../../graph-canvas/weight.js'

export type LaidOutGraphProps = GraphCanvasProps & {
transition: GraphTransition
Expand All @@ -23,8 +22,6 @@ export type LaidOutGraphProps = GraphCanvasProps & {
badgeGrowth: ReadonlyMap<string, number> | undefined
/** How much each card grows for its subtitle (see `GraphCanvasProps.subtitle`). */
subtitleGrowth: ReadonlyMap<string, number> | undefined
/** Each weighed card's share of the heaviest weight, drawn as its gauge (see `GraphCanvasProps.weight`). */
weightShares: ReadonlyMap<string, WeightShare> | undefined
}

export interface Drawing {
Expand All @@ -33,6 +30,8 @@ export interface Drawing {
diff: boolean
/** How far a change border is inset into its card (see `emphasisInset`). */
inset: number
/** A plain card's border width, `--stroke`, in layout units. */
stroke: number
kindOf(entity: Entity): KindLineText | undefined
statusOf(node: TransitionNode): StatusPart[] | undefined
/** A card's or boundary's accessible name. */
Expand All @@ -45,7 +44,7 @@ export interface Drawing {
receded(id: string): boolean
}

export function drawing(props: LaidOutGraphProps, diff: boolean, inset: number): Drawing {
export function drawing(props: LaidOutGraphProps, diff: boolean, inset: number, stroke = 1): Drawing {
const {onSelect, comparing} = props
const kindOf = (entity: Entity) => props.kindLine?.(entity)
const statusOf = (node: TransitionNode) => props.describeStatus?.(node)
Expand Down Expand Up @@ -80,7 +79,7 @@ export function drawing(props: LaidOutGraphProps, diff: boolean, inset: number):
}
const mark = (change: ChangeClassification | TransitionNode, emphasis: number) =>
diff ? {...changeMark(change), style: {'--emphasis': emphasis} as CSSProperties} : {}
return {props, diff, inset, kindOf, statusOf, label, mark, select, receded}
return {props, diff, inset, stroke, kindOf, statusOf, label, mark, select, receded}
}

/** A relationship's change in its accessible name: which endpoints a rewired one's route has. */
Expand Down
Loading
Loading