Skip to content

Commit e4c8a1a

Browse files
committed
wip(spec): object-metric polarity key
Claude-Session: https://claude.ai/code/session_01JQwxbWhSYPUK8z26ntsh8g Co-authored-by: Claude <noreply@anthropic.com>
1 parent 753a14e commit e4c8a1a

1 file changed

Lines changed: 60 additions & 1 deletion

File tree

‎packages/spec/src/ui/component.zod.ts‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ import { ChartDrillDownSchema, ChartGroupBySchema } from './chart.zod';
8989
// [#21464] `object-metric.compareTo.kind` is the dashboard widget comparison's
9090
// own `kind` vocabulary, by reference — the executor's two kinds.
9191
import { DashboardWidgetSchema } from './dashboard.zod';
92+
// [#27347] `object-metric.polarity` is the dataset measure's own polarity
93+
// vocabulary, by reference — one spelling of which direction is good news.
94+
import { DatasetMeasurePolarity } from './dataset.zod';
9295
// [#21464] `object-metric.drillDown.report` is the report contract itself, by
9396
// reference (decision card #21704, fork 1, letter B): a joined report refuses a
9497
// block that binds no dataset, so a report this schema admits is one the drill
@@ -5615,6 +5618,16 @@ const ObjectMetricCompareToSchema = lazySchema(() => strictObject({
56155618
kind: DashboardWidgetSchema.shape.compareTo.unwrap().shape.kind,
56165619
}));
56175620

5621+
/**
5622+
* [#27347] A boolean "is higher better?" flag has no word for a tile where
5623+
* neither direction is good news, so the tile's polarity is the dataset
5624+
* measure's one key with three peer values.
5625+
*/
5626+
const OBJECT_METRIC_POLARITY_NOT_A_FLAG =
5627+
'a metric tile declares which direction is good news with `polarity`, not a boolean: '
5628+
+ "`polarity: 'higher'` (a rise is good), `polarity: 'lower'` (a fall is good: turnaround days, overdue "
5629+
+ "counts, cost) or `polarity: 'neutral'` (neither, the badge is drawn without a good or bad colour).";
5630+
56185631
/**
56195632
* `object-metric` (objectui's `ObjectMetricWidget`; read points recorded in
56205633
* `liveness/page.json`, row `regions`). The widget destructures every prop it
@@ -5627,7 +5640,23 @@ export const ObjectMetricPropsSchema = lazySchema(() => strictObject({
56275640
surface: 'this `object-metric`',
56285641
history: objectBlockHistory('object-metric'),
56295642
guidanceSets: COMPONENT_LEVEL_GUIDANCE,
5630-
aliases: FILTERS_TO_FILTER,
5643+
// [#27347] The dataset measure's near-misses for `polarity`, less its
5644+
// `direction` entry: on this tile `direction` is the static `trend` badge's
5645+
// arrow, so the bare word gets a prescription naming both keys instead.
5646+
aliases: {
5647+
...FILTERS_TO_FILTER,
5648+
betterWhen: 'polarity',
5649+
goodDirection: 'polarity',
5650+
trendDirection: 'polarity',
5651+
},
5652+
guidance: {
5653+
direction:
5654+
'`direction` is not a member of the tile: the arrow of a static badge goes INSIDE `trend` '
5655+
+ '(`trend: { value, direction }`), and which direction of change is good news is `polarity` '
5656+
+ "(`polarity: 'lower'` draws a rise red and a fall green).",
5657+
higherIsBetter: OBJECT_METRIC_POLARITY_NOT_A_FLAG,
5658+
lowerIsBetter: OBJECT_METRIC_POLARITY_NOT_A_FLAG,
5659+
},
56315660
}, {
56325661
objectName: z.string().optional()
56335662
.describe('Object this metric aggregates. Optional because the component-level `dataSource` binding can supply the object instead'),
@@ -5723,6 +5752,36 @@ export const ObjectMetricPropsSchema = lazySchema(() => strictObject({
57235752
*/
57245753
compareTo: ObjectMetricCompareToSchema.optional()
57255754
.describe("Period-over-period comparison `{ kind }` — `previousPeriod` or `previousYear`, shifting the date macros in the tile's own `filter`. `dimension` is refused: this tile never reads a dataset time dimension"),
5755+
/**
5756+
* [#27347] Which direction of change is good news for the tile's number —
5757+
* the dataset measure's {@link DatasetMeasurePolarity}, BY REFERENCE: one
5758+
* vocabulary and one spelling. This tile aggregates a field, not a dataset
5759+
* measure, so a measure's `polarity` has nothing to attach to here and the
5760+
* tile declares its own.
5761+
*
5762+
* Read points recorded in `liveness/page.json`, row `regions`:
5763+
* `ObjectMetricWidget` forwards it to `MetricWidget`, which colours the badge
5764+
* it draws by the rule the dataset-bound tile applies to its delta
5765+
* (`deltaToneClass`), so one KPI is drawn one way on either surface.
5766+
*
5767+
* A TOP-LEVEL key, not a `compareTo` member, because the badge it colours is
5768+
* `derivedTrend ?? trend`: the static `trend` badge was coloured by its
5769+
* `direction` alone too, so one key covers the computed and the static
5770+
* badge.
5771+
*
5772+
* - `higher`, and undeclared: a rise green, a fall red, the colours the tile
5773+
* always had.
5774+
* - `lower`: a fall green, a rise red. Turnaround, overdue counts, cost.
5775+
* - `neutral`: neither; the badge keeps its arrow and percentage, muted.
5776+
*
5777+
* The arrow always shows which way the NUMBER moved; polarity decides only
5778+
* the colour. Nothing infers a polarity from the aggregated field's name.
5779+
*/
5780+
polarity: DatasetMeasurePolarity.optional().describe(
5781+
'Which direction of change is good news: higher (rise green, fall red), lower (fall green, rise red) '
5782+
+ 'or neutral (no good/bad colour). Colours the trend badge, computed (`compareTo`) or static (`trend`); '
5783+
+ 'undeclared keeps rise green, fall red',
5784+
),
57265785
}));
57275786
/** Author state (ADR-0122: the bare name is the author state). */
57285787
export type ObjectMetricProps = z.input<typeof ObjectMetricPropsSchema>;

0 commit comments

Comments
 (0)