From 93ae9269cc88fba3ac272cc109a0821d15463113 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 14:26:25 +0200 Subject: [PATCH 01/22] feat: schema-driven stations for every data transformation step in the catalog (rebased onto current origin/master; conflicts resolved in favour of the merged 2026-11-10 studio feedback round copy) --- docs/context/architecture.md | 2 + docs/context/module-index.md | 4 +- e2e/studio.ts | 13 +- ...-transformation-step-columns.utils.spec.ts | 40 ++ .../data-transformation-step-columns.utils.ts | 78 ++++ ...ata-transformation-step-form.utils.spec.ts | 150 ++++++ .../data-transformation-step-form.utils.ts | 440 ++++++++++++++++++ ...ric-data-transformation-step.component.css | 209 +++++++++ ...ic-data-transformation-step.component.html | 172 +++++++ ...data-transformation-step.component.spec.ts | 122 +++++ ...eric-data-transformation-step.component.ts | 199 ++++++++ .../statistic-analysis-panel.component.html | 308 +++++++----- ...statistic-analysis-panel.component.spec.ts | 97 +++- .../statistic-analysis-panel.component.ts | 283 +++++++++-- .../statistic-analysis-panel.pipeline.spec.ts | 130 +++++- .../experiment-studio.service.spec.ts | 120 +++++ src/app/services/experiment-studio.service.ts | 80 +++- 17 files changed, 2262 insertions(+), 185 deletions(-) create mode 100644 src/app/core/data-transformation-step-columns.utils.spec.ts create mode 100644 src/app/core/data-transformation-step-columns.utils.ts create mode 100644 src/app/core/data-transformation-step-form.utils.spec.ts create mode 100644 src/app/core/data-transformation-step-form.utils.ts create mode 100644 src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.css create mode 100644 src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.html create mode 100644 src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.spec.ts create mode 100644 src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.ts diff --git a/docs/context/architecture.md b/docs/context/architecture.md index 26f4be5da..185ae8de9 100644 --- a/docs/context/architecture.md +++ b/docs/context/architecture.md @@ -69,6 +69,8 @@ flowchart TD - The app uses Angular Signals heavily for feature state. - `ExperimentStudioService` is the main orchestration layer for selected data models, datasets, variables, covariates, filters, algorithm configuration, run/save flows, preview calls, edit hydration, and sessionStorage persistence. - Transformation (derived-column) state is an ordered `appliedTransformations: TransformationStep[]` signal on that service — not a keyed map. Singletons (`missing_values_handler`, outlier, longitudinal) stay in the preprocessing config; column creators (`categorical_column_creator`, `kmeans_cluster_creator`, `pca_column_creator`) live only in the ordered list and emit in list order after the singletons. Creator output codes come from `new_column_names` (never a legacy `code` field). There is no `pca_with_transformation` algorithm; PCA component scores are created with `pca_column_creator`. +- Pipeline stages follow what a step does to the data. **Preprocessing** edits a variable in place and keeps its meaning and range: `missing_values_handler`, `outlier_winsorizer`, `global_imputer`, `global_winsorizer`. **Data transformation** creates a column or changes what a variable means (range, scale, type, row layout): `kmeans_cluster_creator`, `pca_column_creator`, `categorical_column_creator`, `variable_transformer`, `variable_scaler`, `longitudinal_transformer`, `ordinal_encoder`, `one_hot_encoder`, `missing_indicator`, `outlier_detector` (default `flag` adds a column; `drop` and `set_missing` edit in place, noted on the station). `stepStage` in `core/data-transformation-step-form.utils.ts` is the single classification; a step the engine adds later lands in Data transformation until listed there. The endpoint (`/specifications/preprocessing`), the step machine ids and the request key `preprocessing` are the engine contract and keep their names. +- Catalog steps with no dedicated station (everything in `/specifications/preprocessing` except the missing-values, outlier winsorizer, longitudinal, transformer and scaler singletons and the three column creators) render through `generic-data-transformation-step`, a form built from the step's parameter schema by `core/data-transformation-step-form.utils.ts` (field kinds, payload building, trimming to the selection); the panel mounts each one in the stage `stepStage` names, so the component serves both families. They are singletons in the applied config like the others; the panel carries them over whenever another card applies, the service drops them from a request once the loaded catalog lacks them, and a missing indicator is ordered ahead of the missing-values step. Columns they add (`missing_indicator`, `outlier_detector` flag, `one_hot_encoder`) and variables they drop are derived from their parameters by `core/data-transformation-step-columns.utils.ts` and feed the algorithm role pool. - `ExperimentsDashboardService` owns paged experiment list state, filtering, sharing, renaming, deletion, and result fetches. - `ErrorService` shares global feature errors through a `BehaviorSubject`. diff --git a/docs/context/module-index.md b/docs/context/module-index.md index bdc4f92d6..c30574733 100644 --- a/docs/context/module-index.md +++ b/docs/context/module-index.md @@ -42,11 +42,11 @@ Notes: Stored historical experiment payloads may depend on legacy algorithm keys ## `src/app/pages/experiment-studio` Purpose: Experiment composition workflow. -Key files: `experiment-studio.component.*`, `variables-panel/*`, `statistic-analysis-panel/*` (including `pca-column-source` / `kmeans-cluster-source`), `algorithm-panel/*`, `execution-panel/*` (result view + docked setup summary), `stepper/*`, `shared/*`, `guide/*`. +Key files: `experiment-studio.component.*`, `variables-panel/*`, `statistic-analysis-panel/*` (including `pca-column-source` / `kmeans-cluster-source` / `generic-data-transformation-step`), `algorithm-panel/*`, `execution-panel/*` (result view + docked setup summary), `stepper/*`, `shared/*`, `guide/*`. Used by: `/experiment-studio` route and dashboard edit flows. Rules: Keep page-specific UI here; use `ExperimentStudioService` for shared selection/run state. Transformation cards append to `appliedTransformations` in creation order; each creator step names outputs with `new_column_names`. Do not reintroduce `pca_with_transformation`. Tests: Component specs live near components; e2e covers PCA then K-means then logistic regression payload order in `e2e/experiment-studio.flows.spec.ts`. -Notes: Browser validation often requires a backend with data models, algorithms, and authenticated user state. PCA/K-means creators need the aggregation server in the preprocessing catalog. +Notes: Browser validation often requires a backend with data models, algorithms, and authenticated user state. PCA/K-means creators need the aggregation server in the step catalog (`/specifications/preprocessing`). ## `src/app/pages/experiment-studio/visualisations` Purpose: Chart/table rendering for algorithm outputs, histograms, metadata browsers, and auto-rendered results. diff --git a/e2e/studio.ts b/e2e/studio.ts index 146d6b767..6b5a42dd4 100644 --- a/e2e/studio.ts +++ b/e2e/studio.ts @@ -125,6 +125,14 @@ export async function collapsePreprocessing(page: Page) { if (await open.isVisible()) await open.click(); } +/** Same for the Data transformation step, where the longitudinal comparison lives. */ +export async function collapseTransformation(page: Page) { + const section = page.locator('[data-guide="analysis-transformation"]'); + const open = section.locator('.pipeline-node-toggle[aria-expanded="true"]'); + await expect(open.or(section.getByRole('list', { name: 'Data transformation steps' }))).toBeVisible(); + if (await open.isVisible()) await open.click(); +} + export async function openMissingValues(page: Page) { await page.getByRole('button', { name: 'Customize rules' }).click(); const missing = page.locator('app-station-card', { hasText: 'Missing Values' }); @@ -172,12 +180,13 @@ export async function openLongitudinalAge(page: Page) { } export async function applyLongitudinalStrategy(page: Page, label: string) { - await page.getByRole('button', { name: 'Customize rules' }).click(); + // The longitudinal comparison changes what the variable means, so it is a data transformation. + await page.getByRole('button', { name: /Add longitudinal comparison/ }).click(); const card = page.locator('app-station-card', { hasText: 'Longitudinal Transformation' }); await card.getByRole('button', { name: /^Age/ }).click(); await card.locator('select').last().selectOption({ label }); await card.getByRole('button', { name: 'Apply', exact: true }).click(); - await collapsePreprocessing(page); + await collapseTransformation(page); await expect(page.getByText('Baseline vs Month 12')).toBeVisible(); } diff --git a/src/app/core/data-transformation-step-columns.utils.spec.ts b/src/app/core/data-transformation-step-columns.utils.spec.ts new file mode 100644 index 000000000..b5ed6e67b --- /dev/null +++ b/src/app/core/data-transformation-step-columns.utils.spec.ts @@ -0,0 +1,40 @@ +import { describe, expect, it } from 'vitest'; +import { stepColumnEffect } from './data-transformation-step-columns.utils'; + +const sources = new Map([ + ['age', { code: 'age', label: 'Age' }], + ['sex', { code: 'sex', label: 'Sex', enumerations: [{ code: 'M', label: 'Male' }, { code: 'F', label: 'Female' }, { code: 'X', label: 'Other' }] }], +]); + +describe('stepColumnEffect', () => { + it('names indicator columns after the variable and the suffix, with the engine default', () => { + expect(stepColumnEffect('missing_indicator', { variables: ['age'] }, sources).created) + .toEqual([{ code: 'age_missing', label: 'Age (missing)' }]); + expect(stepColumnEffect('missing_indicator', { variables: ['age'], suffix: '_na' }, sources).created[0].code).toBe('age_na'); + }); + + it('adds outlier flag columns only for the flag action', () => { + const strategies = { age: 'zscore' }; + expect(stepColumnEffect('outlier_detector', { strategies }, sources).created).toEqual([{ code: 'age_outlier', label: 'Age (outlier)' }]); + expect(stepColumnEffect('outlier_detector', { strategies, action: 'flag', suffix: '_o' }, sources).created[0].code).toBe('age_o'); + expect(stepColumnEffect('outlier_detector', { strategies, action: 'drop' }, sources).created).toEqual([]); + expect(stepColumnEffect('outlier_detector', { strategies, action: 'set_missing' }, sources).created).toEqual([]); + }); + + it('one-hot encodes sorted levels, dropping the reference level and the original by default', () => { + const effect = stepColumnEffect('one_hot_encoder', { variables: ['sex'] }, sources); + expect(effect.created.map((c) => c.code)).toEqual(['sex_M', 'sex_X']); + expect(effect.created[0].label).toBe('Sex: Male'); + expect(effect.dropped).toEqual(['sex']); + }); + + it('keeps every level and the original when asked to', () => { + const effect = stepColumnEffect('one_hot_encoder', { variables: ['sex'], drop_first: false, drop_original: false }, sources); + expect(effect.created.map((c) => c.code)).toEqual(['sex_F', 'sex_M', 'sex_X']); + expect(effect.dropped).toEqual([]); + }); + + it('has no column effect for other steps', () => { + expect(stepColumnEffect('global_winsorizer', { variables: ['age'] }, sources)).toEqual({ created: [], dropped: [] }); + }); +}); diff --git a/src/app/core/data-transformation-step-columns.utils.ts b/src/app/core/data-transformation-step-columns.utils.ts new file mode 100644 index 000000000..de81c1f73 --- /dev/null +++ b/src/app/core/data-transformation-step-columns.utils.ts @@ -0,0 +1,78 @@ +/** + * Columns the schema-driven catalog steps add to, or remove from, the data. Their request + * parameters name them (`suffix`, the encoder's levels), so the studio can offer them as + * assignable variables and hide the ones a step drops. + */ + +export interface CreatedStepColumn { + code: string; + label: string; +} + +export interface StepColumnEffect { + created: CreatedStepColumn[]; + /** Source variables the step removes from the data. */ + dropped: string[]; +} + +interface SourceVariable { + code: string; + label?: string; + enumerations?: Array<{ code: string; label?: string }>; +} + +const NO_EFFECT: StepColumnEffect = { created: [], dropped: [] }; + +function strings(value: unknown): string[] { + return Array.isArray(value) ? value.map((item) => String(item)) : []; +} + +/** The columns a step adds and the variables it drops, from its applied parameters. */ +export function stepColumnEffect( + name: string, + parameters: Record, + sources: ReadonlyMap, +): StepColumnEffect { + const labelOf = (code: string) => sources.get(code)?.label || code; + + if (name === 'missing_indicator') { + const suffix = typeof parameters['suffix'] === 'string' ? parameters['suffix'] : '_missing'; + return { + created: strings(parameters['variables']).map((code) => ({ + code: `${code}${suffix}`, + label: `${labelOf(code)} (missing)`, + })), + dropped: [], + }; + } + + if (name === 'outlier_detector') { + // Only the default `flag` action adds columns; `drop` removes rows and `set_missing` edits values. + if (parameters['action'] !== undefined && parameters['action'] !== 'flag') return NO_EFFECT; + const suffix = typeof parameters['suffix'] === 'string' ? parameters['suffix'] : '_outlier'; + const strategies = (parameters['strategies'] ?? {}) as Record; + return { + created: Object.keys(strategies).sort().map((code) => ({ + code: `${code}${suffix}`, + label: `${labelOf(code)} (outlier)`, + })), + dropped: [], + }; + } + + if (name === 'one_hot_encoder') { + const dropFirst = parameters['drop_first'] !== false; + const dropOriginal = parameters['drop_original'] !== false; + const variables = strings(parameters['variables']); + const created: CreatedStepColumn[] = []; + for (const code of variables) { + const levels = [...(sources.get(code)?.enumerations ?? [])].sort((a, b) => (a.code < b.code ? -1 : a.code > b.code ? 1 : 0)); + for (const level of dropFirst ? levels.slice(1) : levels) { + created.push({ code: `${code}_${level.code}`, label: `${labelOf(code)}: ${level.label || level.code}` }); + } + } + return { created, dropped: dropOriginal ? variables : [] }; + } + + return NO_EFFECT; +} diff --git a/src/app/core/data-transformation-step-form.utils.spec.ts b/src/app/core/data-transformation-step-form.utils.spec.ts new file mode 100644 index 000000000..22c4aac7e --- /dev/null +++ b/src/app/core/data-transformation-step-form.utils.spec.ts @@ -0,0 +1,150 @@ +import { describe, expect, it } from 'vitest'; +import { RawPreprocessingStep } from '../models/backend-algorithms.model'; +import { + buildStepParameters, + defaultStepValues, + filterStepParameters, + isGenericCatalogStep, + stepFields, + stepValuesFromParameters, + summarizeStepParameters, + unsupportedRequiredFields, + isPreprocessingSingleton, + isTransformationSingleton, + stepNote, + stepStage, +} from './data-transformation-step-form.utils'; + +const param = (extra: Record) => ({ + label: 'L', desc: 'D', types: ['text'], required: false, multiple: false, default: null, + enums: null, dict_keys_enums: null, dict_values_type: null, dict_values_enums: null, min: null, max: null, + ...extra, +}); + +/** Assumed shape of the engine's outlier detector step. */ +const outlierDetector = { + name: 'outlier_detector', label: 'Outlier Detector', desc: 'Flags outliers.', + parameters: { + strategies: param({ + types: ['dict'], required: true, + dict_keys_enums: { type: 'input_var_names', source: ['variables'] }, + dict_values_enums: { type: 'list', source: ['zscore', 'robust'] }, + }), + threshold: param({ types: ['real'], default: 3, min: 0 }), + }, +} as unknown as RawPreprocessingStep; + +const indicator = { + name: 'missing_indicator', label: 'Missing Indicator', desc: 'Adds indicator columns.', + parameters: { + variables: param({ types: ['text'], required: true, multiple: true }), + new_column_names: param({ types: ['text'], required: true, multiple: true }), + sparse: param({ types: ['bool'], default: false }), + }, +} as unknown as RawPreprocessingStep; + +describe('preprocessing step form utils', () => { + it('leaves the dedicated singletons and the creators to their own stations', () => { + for (const name of ['missing_values_handler', 'outlier_winsorizer', 'longitudinal_transformer', + 'variable_transformer', 'variable_scaler', 'categorical_column_creator', 'kmeans_cluster_creator', 'pca_column_creator']) { + expect(isGenericCatalogStep(name)).toBe(false); + } + expect(isGenericCatalogStep('outlier_detector')).toBe(true); + expect(isGenericCatalogStep('missing_indicator')).toBe(true); + }); + + it('derives field kinds from the parameter schema', () => { + expect(stepFields(outlierDetector).map((f) => [f.key, f.kind, f.itemKind, f.required])) + .toEqual([['strategies', 'variable-map', 'enum', true], ['threshold', 'real', 'real', false]]); + expect(stepFields(indicator).map((f) => [f.key, f.kind])) + .toEqual([['variables', 'variables'], ['new_column_names', 'list'], ['sparse', 'bool']]); + }); + + it('builds a per-variable map payload with a number parameter', () => { + const fields = stepFields(outlierDetector); + const values = { ...defaultStepValues(fields), strategies: { age: 'zscore', mmse: 'robust', gone: 'zscore', blank: '' }, threshold: '2.5' }; + const { parameters, errors } = buildStepParameters(fields, values, new Set(['age', 'mmse', 'blank'])); + expect(errors).toEqual({}); + expect(parameters).toEqual({ strategies: { age: 'zscore', mmse: 'robust' }, threshold: 2.5 }); + }); + + it('sends the schema default and omits an emptied optional number', () => { + const fields = stepFields(outlierDetector); + expect(defaultStepValues(fields)['threshold']).toBe('3'); + const cleared = buildStepParameters(fields, { strategies: { age: 'zscore' }, threshold: '' }, null); + expect(cleared.parameters).toEqual({ strategies: { age: 'zscore' } }); + }); + + it('reports a required field left empty and bad numbers instead of guessing', () => { + const fields = stepFields(outlierDetector); + expect(buildStepParameters(fields, defaultStepValues(fields), null).errors['strategies']).toMatch(/required/); + expect(buildStepParameters(fields, { strategies: { a: 'zscore' }, threshold: '-1' }, null).errors['threshold']).toMatch(/at least 0/); + expect(buildStepParameters(fields, { strategies: { a: 'zscore' }, threshold: 'x' }, null).errors['threshold']).toMatch(/number/); + }); + + it('builds variable lists, name lists and booleans', () => { + const fields = stepFields(indicator); + const values = { variables: ['age', 'mmse'], new_column_names: 'age_na, mmse_na', sparse: true }; + expect(buildStepParameters(fields, values, new Set(['age', 'mmse'])).parameters) + .toEqual({ variables: ['age', 'mmse'], new_column_names: ['age_na', 'mmse_na'], sparse: true }); + // A deselected variable drops out of the list; with none left the required list is an error. + expect(buildStepParameters(fields, values, new Set(['x'])).errors['variables']).toMatch(/required/); + }); + + it('round-trips applied parameters into the form', () => { + const fields = stepFields(indicator); + const parameters = { variables: ['age'], new_column_names: ['age_na'], sparse: false }; + expect(buildStepParameters(fields, stepValuesFromParameters(fields, parameters), null).parameters).toEqual(parameters); + }); + + it('trims variable-bound parameters to the selection and drops a step left without any', () => { + const fields = stepFields(outlierDetector); + const params = { strategies: { age: 'zscore', mmse: 'robust' }, threshold: 3 }; + expect(filterStepParameters(fields, params, new Set(['age']))).toEqual({ strategies: { age: 'zscore' }, threshold: 3 }); + expect(filterStepParameters(fields, params, new Set(['other']))).toBeNull(); + }); + + it('marks required parameters it cannot edit', () => { + const spec = { name: 'x', label: 'X', desc: '', parameters: { reusable_preprocessing: param({ types: ['dict'], required: true }) } } as unknown as RawPreprocessingStep; + expect(unsupportedRequiredFields(stepFields(spec)).map((f) => f.key)).toEqual(['reusable_preprocessing']); + }); + + it('summarizes parameters with variable labels', () => { + expect(summarizeStepParameters({ strategies: { age: 'zscore' }, threshold: 3, variables: ['mmse'] }, { age: 'Age', mmse: 'MMSE' })) + .toEqual(['Age: zscore', 'threshold: 3', 'variables: MMSE']); + }); +}); + +describe('pipeline stage of each catalog step', () => { + // In place and the same meaning and range: Preprocessing. A new column or a changed meaning: Data transformation. + const PREPROCESSING = ['missing_values_handler', 'outlier_winsorizer', 'global_imputer', 'global_winsorizer']; + const TRANSFORMATION = [ + 'kmeans_cluster_creator', 'pca_column_creator', 'categorical_column_creator', 'longitudinal_transformer', + 'variable_transformer', 'variable_scaler', 'missing_indicator', 'outlier_detector', 'one_hot_encoder', 'ordinal_encoder', + ]; + + it('puts the in-place steps in Preprocessing and every other catalog step in Data transformation', () => { + for (const name of PREPROCESSING) expect(stepStage(name), name).toBe('preprocessing'); + for (const name of TRANSFORMATION) expect(stepStage(name), name).toBe('transformation'); + expect(PREPROCESSING.length + TRANSFORMATION.length).toBe(14); + }); + + it('keeps the column creators out of both singleton groups', () => { + for (const name of ['kmeans_cluster_creator', 'pca_column_creator', 'categorical_column_creator']) { + expect(isTransformationSingleton(name)).toBe(false); + expect(isPreprocessingSingleton(name)).toBe(false); + } + expect(isTransformationSingleton('variable_scaler')).toBe(true); + expect(isPreprocessingSingleton('global_imputer')).toBe(true); + }); + + it('files a step the engine adds later under Data transformation until it is classified', () => { + expect(stepStage('some_future_step')).toBe('transformation'); + }); + + it('explains the outlier detector and the missing indicator, whose position the stage rule does not cover', () => { + expect(stepNote('outlier_detector')).toMatch(/Drop and Set missing edit the data in place/); + expect(stepNote('missing_indicator')).toMatch(/before missing values/); + expect(stepNote('one_hot_encoder')).toBe(''); + }); +}); diff --git a/src/app/core/data-transformation-step-form.utils.ts b/src/app/core/data-transformation-step-form.utils.ts new file mode 100644 index 000000000..5ce65d6b7 --- /dev/null +++ b/src/app/core/data-transformation-step-form.utils.ts @@ -0,0 +1,440 @@ +/** + * Catalog-driven editor model for pipeline steps that have no dedicated station. + * + * Every step the engine lists in `/services/specifications/preprocessing` (the endpoint keeps that + * name) must be selectable and configurable. Steps with a bespoke station (missing values, outlier + * winsorizer, longitudinal, transformer, scaler and the column creators) keep it; every other step + * gets a form built from its parameter schema, and its payload is built here so it matches the + * schema exactly. + * + * The studio sorts the steps into two stages by what they do to the data: + * - Preprocessing tweaks an existing variable in place and keeps its meaning and range + * (missing values, clipping outliers). + * - Data transformation creates a new column, or changes what a variable means (its range, scale + * or type), so analyses read a different quantity than the one that was collected. + */ + +import { RawParameter, RawPreprocessingStep } from '../models/backend-algorithms.model'; +import { CREATOR_NAMES, CreatorName } from './transformation-steps.utils'; + +/** Singleton steps that own a dedicated station. Their requests are built by the panel. */ +export const DEDICATED_SINGLETON_STEPS: ReadonlySet = new Set([ + 'missing_values_handler', + 'outlier_winsorizer', + 'longitudinal_transformer', + 'variable_transformer', + 'variable_scaler', +]); + +/** The pipeline stage a step belongs to; see the file header for the rule. */ +export type StepStage = 'preprocessing' | 'transformation'; + +/** + * Steps edited in place that keep the variable's meaning and range: the Preprocessing stage. + * Every other step creates a column or changes a variable's meaning, range or type and belongs to + * the Data transformation stage. A step the engine adds later lands in Data transformation until it + * is classified here, because most new steps derive features. + */ +const PREPROCESSING_STEPS: ReadonlySet = new Set([ + 'missing_values_handler', + 'outlier_winsorizer', + 'global_imputer', + 'global_winsorizer', +]); + +export function stepStage(name: string): StepStage { + return PREPROCESSING_STEPS.has(name) ? 'preprocessing' : 'transformation'; +} + +/** + * Singleton steps of the Data transformation stage: every non-creator step outside the + * Preprocessing stage. The three column creators are an ordered list of their own. + */ +export function isTransformationSingleton(name: string): boolean { + return !CREATOR_NAMES.has(name as CreatorName) && stepStage(name) === 'transformation'; +} + +/** Singleton steps of the Preprocessing stage: edited in place, same meaning and range. */ +export function isPreprocessingSingleton(name: string): boolean { + return !CREATOR_NAMES.has(name as CreatorName) && stepStage(name) === 'preprocessing'; +} + +/** + * One line shown on a station when its position needs explaining: the stage rule does not cover + * every setting of the step, or the run order differs from the order of the stages. + */ +const STEP_NOTES: Readonly> = { + missing_indicator: 'Runs before missing values are handled, so it sees the gaps that were in the data.', + outlier_detector: + 'Flag adds a 0/1 column and keeps every value. Drop and Set missing edit the data in place instead (rows removed or values blanked).', +}; + +export function stepNote(name: string): string { + return STEP_NOTES[name] ?? ''; +} + +/** True when a catalog step is rendered by the generic, schema-driven station. */ +export function isGenericCatalogStep(name: string): boolean { + return !DEDICATED_SINGLETON_STEPS.has(name) && !CREATOR_NAMES.has(name as CreatorName); +} + +/** Which selected variables a step can act on. Unlisted steps accept any and let the engine validate. */ +export type StepVariableScope = 'any' | 'numerical' | 'categorical'; + +const STEP_VARIABLE_SCOPE: Readonly> = { + outlier_detector: 'numerical', + global_winsorizer: 'numerical', + one_hot_encoder: 'categorical', + ordinal_encoder: 'categorical', +}; + +export function stepVariableScope(name: string): StepVariableScope { + return STEP_VARIABLE_SCOPE[name] ?? 'any'; +} + +/** + * Generic steps that must run before the missing-values steps: a missing indicator placed after + * an imputation or drop would flag nothing. Everything else keeps its stored order. + */ +export const STEPS_BEFORE_IMPUTATION: ReadonlySet = new Set(['missing_indicator']); + +export type StepFieldKind = + | 'enum' + | 'text' + | 'int' + | 'real' + | 'bool' + /** Free list of values, typed in as comma separated text. */ + | 'list' + /** A subset of the selected variables, sent as a list of codes. */ + | 'variables' + /** One value per selected variable, sent as `{code: value}`. */ + | 'variable-map' + /** Needs a dedicated editor (reusable fitted recipes, filter rules, ...). */ + | 'unsupported'; + +export interface StepField { + key: string; + label: string; + description: string; + kind: StepFieldKind; + required: boolean; + /** Scalar kind of each item of a list / each value of a variable map. */ + itemKind: 'enum' | 'text' | 'int' | 'real' | 'bool'; + options: string[]; + min: number | null; + max: number | null; + defaultValue: unknown; +} + +/** Form state: strings for text-like inputs, booleans, string lists, or code→string maps. */ +export type StepFormValues = Record; + +/** Parameter names that hold variable codes rather than free text. */ +const VARIABLE_LIST_KEYS = new Set(['variables', 'columns', 'features', 'variable_names']); + +function toBool(value: unknown): boolean { + return value === true || value === 'true' || value === 'True'; +} + +function toNumber(value: unknown): number | null { + if (value === null || value === undefined || value === '') return null; + const n = Number(value); + return Number.isFinite(n) ? n : null; +} + +function listOptions(definition: { type?: string; source?: unknown } | undefined | null): string[] { + if (!definition || definition.type !== 'list' || !Array.isArray(definition.source)) return []; + return definition.source.map((item) => String(item)); +} + +function scalarKind(type: string | undefined): StepField['itemKind'] { + switch ((type ?? 'text').toLowerCase()) { + case 'int': + return 'int'; + case 'real': + case 'float': + return 'real'; + case 'bool': + case 'boolean': + return 'bool'; + default: + return 'text'; + } +} + +function buildField(key: string, raw: RawParameter): StepField { + const type = String(raw.types?.[0] ?? 'text').toLowerCase(); + const options = listOptions(raw.enums); + const base = { + key, + label: raw.label || key, + description: raw.desc || '', + required: raw.required === true || raw.required === 'true', + options, + min: toNumber(raw.min), + max: toNumber(raw.max), + defaultValue: raw.default ?? raw.default_value ?? null, + }; + const multiple = raw.multiple === true || raw.multiple === 'true'; + + if (type === 'dict') { + const keys = raw.dict_keys_enums; + const valueOptions = listOptions(raw.dict_values_enums); + const keyedByVariable = keys?.type === 'input_var_names' || keys?.type === 'variables'; + if (!keyedByVariable) return { ...base, kind: 'unsupported', itemKind: 'text', options: [] }; + const valueType = scalarKind(raw.dict_values_type === 'boolean' ? 'bool' : raw.dict_values_type); + return { + ...base, + kind: 'variable-map', + itemKind: valueOptions.length ? 'enum' : valueType, + options: valueOptions, + }; + } + + const itemKind: StepField['itemKind'] = options.length ? 'enum' : scalarKind(type); + if (type === 'filter' || type === 'json' || raw.enums?.type === 'fixed_var_CDE_enums' && multiple) { + return { ...base, kind: 'unsupported', itemKind: 'text', options: [] }; + } + if (multiple) { + const namesVariables = raw.enums?.type === 'input_var_names' || raw.enums?.type === 'variables'; + return { + ...base, + kind: namesVariables || VARIABLE_LIST_KEYS.has(key) ? 'variables' : 'list', + itemKind, + }; + } + if (itemKind === 'enum') return { ...base, kind: 'enum', itemKind }; + return { ...base, kind: itemKind, itemKind }; +} + +/** The fields of a step, in schema order. */ +export function stepFields(spec: RawPreprocessingStep | null | undefined): StepField[] { + const parameters = spec?.parameters ?? {}; + return Object.entries(parameters).map(([key, raw]) => buildField(key, raw as RawParameter)); +} + +/** A required field this form cannot fill in blocks Apply: the engine would reject the step. */ +export function unsupportedRequiredFields(fields: StepField[]): StepField[] { + return fields.filter((field) => field.kind === 'unsupported' && field.required); +} + +/** Empty form: schema defaults for scalar fields, nothing selected for the rest. */ +export function defaultStepValues(fields: StepField[]): StepFormValues { + const values: StepFormValues = {}; + for (const field of fields) { + switch (field.kind) { + case 'bool': + values[field.key] = field.defaultValue === null ? false : toBool(field.defaultValue); + break; + case 'variables': + values[field.key] = []; + break; + case 'variable-map': + values[field.key] = {}; + break; + case 'list': + values[field.key] = Array.isArray(field.defaultValue) ? field.defaultValue.join(', ') : ''; + break; + case 'unsupported': + break; + default: + values[field.key] = field.defaultValue === null || field.defaultValue === undefined + ? '' + : String(field.defaultValue); + } + } + return values; +} + +function parseScalar( + kind: StepField['itemKind'], + raw: unknown, + field: StepField, + label: string, + errors: Record, +): string | number | boolean | null { + const text = typeof raw === 'string' ? raw.trim() : raw; + if (kind === 'bool') return toBool(text); + if (text === '' || text === null || text === undefined) return null; + if (kind === 'int' || kind === 'real') { + const n = Number(text); + if (!Number.isFinite(n)) { + errors[field.key] = `${label} must be a number.`; + return null; + } + if (kind === 'int' && !Number.isInteger(n)) { + errors[field.key] = `${label} must be a whole number.`; + return null; + } + if (field.min !== null && n < field.min) { + errors[field.key] = `${label} must be at least ${field.min}.`; + return null; + } + if (field.max !== null && n > field.max) { + errors[field.key] = `${label} must be at most ${field.max}.`; + return null; + } + return n; + } + return String(text); +} + +export interface BuiltStepParameters { + parameters: Record; + errors: Record; +} + +/** + * The request parameters of a step from its form state. Empty optional fields are left out so + * the engine's own defaults apply; a required field left empty is an error, never a guess. + */ +export function buildStepParameters( + fields: StepField[], + values: StepFormValues, + selectedCodes: ReadonlySet | null = null, +): BuiltStepParameters { + const parameters: Record = {}; + const errors: Record = {}; + + for (const field of fields) { + const raw = values[field.key]; + const missing = `${field.label} is required.`; + switch (field.kind) { + case 'unsupported': + break; + case 'bool': + // A boolean is always a decision, so it is sent. + parameters[field.key] = toBool(raw); + break; + case 'variables': { + const codes = (Array.isArray(raw) ? raw : []).map(String) + .filter((code) => !selectedCodes || selectedCodes.has(code)); + if (codes.length) parameters[field.key] = codes; + else if (field.required) errors[field.key] = missing; + break; + } + case 'list': { + const items = String(raw ?? '').split(',').map((item) => item.trim()).filter(Boolean); + const parsed = items + .map((item) => parseScalar(field.itemKind, item, field, field.label, errors)) + .filter((item) => item !== null); + if (parsed.length) parameters[field.key] = parsed; + else if (field.required && !errors[field.key]) errors[field.key] = missing; + break; + } + case 'variable-map': { + const map: Record = {}; + for (const [code, entry] of Object.entries((raw ?? {}) as Record)) { + if (selectedCodes && !selectedCodes.has(code)) continue; + const value = parseScalar(field.itemKind, entry, field, `${field.label} (${code})`, errors); + if (value !== null && value !== '') map[code] = value; + } + if (Object.keys(map).length) parameters[field.key] = map; + else if (field.required) errors[field.key] = missing; + break; + } + default: { + const value = parseScalar(field.kind === 'enum' ? 'text' : field.itemKind, raw, field, field.label, errors); + if (value !== null && value !== '') parameters[field.key] = value; + else if (field.required && !errors[field.key]) errors[field.key] = missing; + } + } + } + return { parameters, errors }; +} + +/** Form state for a saved/applied step: the inverse of `buildStepParameters`. */ +export function stepValuesFromParameters( + fields: StepField[], + parameters: Record | null | undefined, +): StepFormValues { + const values = defaultStepValues(fields); + if (!parameters) return values; + for (const field of fields) { + const raw = parameters[field.key]; + if (raw === undefined || raw === null) { + if (field.kind !== 'bool') continue; + } + switch (field.kind) { + case 'bool': + values[field.key] = raw === undefined || raw === null ? values[field.key] : toBool(raw); + break; + case 'variables': + values[field.key] = Array.isArray(raw) ? raw.map(String) : []; + break; + case 'list': + values[field.key] = Array.isArray(raw) ? raw.join(', ') : ''; + break; + case 'variable-map': + values[field.key] = raw && typeof raw === 'object' && !Array.isArray(raw) + ? Object.fromEntries(Object.entries(raw as Record).map(([k, v]) => [k, String(v)])) + : {}; + break; + case 'unsupported': + break; + default: + values[field.key] = String(raw); + } + } + return values; +} + +/** + * Keep a step's variable-bound parameters on the variables still selected. Returns null when a + * required variable parameter ends up empty, so the step leaves the request instead of failing it. + */ +export function filterStepParameters( + fields: StepField[], + parameters: Record, + allowedCodes: ReadonlySet, +): Record | null { + const next: Record = { ...parameters }; + for (const field of fields) { + const raw = parameters[field.key]; + if (field.kind === 'variables' && Array.isArray(raw)) { + const kept = raw.filter((code) => allowedCodes.has(String(code))); + if (kept.length) next[field.key] = kept; + else { + delete next[field.key]; + if (field.required) return null; + } + } + if (field.kind === 'variable-map' && raw && typeof raw === 'object' && !Array.isArray(raw)) { + const kept = Object.fromEntries( + Object.entries(raw as Record).filter(([code]) => allowedCodes.has(code)), + ); + if (Object.keys(kept).length) next[field.key] = kept; + else { + delete next[field.key]; + if (field.required) return null; + } + } + } + return next; +} + +function humanize(text: string): string { + return text.replace(/_/g, ' '); +} + +/** Readable lines of a step's parameters for the run summary, with variable labels. */ +export function summarizeStepParameters( + parameters: Record | null | undefined, + labelMap: Record = {}, +): string[] { + const lines: string[] = []; + for (const [key, value] of Object.entries(parameters ?? {})) { + if (value === null || value === undefined || value === '') continue; + if (Array.isArray(value)) { + lines.push(`${humanize(key)}: ${value.map((item) => labelMap[String(item)] ?? String(item)).join(', ')}`); + } else if (typeof value === 'object') { + for (const [code, entry] of Object.entries(value as Record)) { + lines.push(`${labelMap[code] ?? code}: ${humanize(String(entry))}`); + } + } else { + lines.push(`${humanize(key)}: ${humanize(String(value))}`); + } + } + return lines; +} diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.css b/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.css new file mode 100644 index 000000000..1250dcf72 --- /dev/null +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.css @@ -0,0 +1,209 @@ +:host { + display: block; +} + +.btn-add-dashed { + width: 100%; + box-sizing: border-box; + display: inline-flex; + align-items: center; + justify-content: center; + gap: 7px; + padding: 12px 16px; + background: color-mix(in srgb, var(--primary-color) 2.5%, white); + border: 1.5px dashed color-mix(in srgb, var(--primary-color) 30%, transparent); + border-radius: var(--radius-md, 8px); + color: var(--primary-color); + font-family: inherit; + font-size: 0.84rem; + font-weight: 650; + cursor: pointer; + transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease; +} + +.btn-add-dashed:hover { + background: color-mix(in srgb, var(--primary-color) 7%, white); + border-color: var(--primary-color); + box-shadow: 0 2px 8px rgba(43, 51, 233, 0.08); +} + +.btn-add-dashed:focus-visible, +.btn-remove-step-node:focus-visible, +.doc-toggle:focus-visible, +.step-quick button:focus-visible { + outline: 2px solid var(--color-focus); + outline-offset: 2px; +} + +.btn-remove-step-node, +.doc-toggle { + display: inline-flex; + align-items: center; + gap: 5px; + padding: 6px 10px; + background: transparent; + border: 0; + color: var(--text-muted); + border-radius: 999px; + font-family: inherit; + font-size: 0.74rem; + font-weight: 600; + cursor: pointer; + transition: all 0.15s ease; +} + +.btn-remove-step-node:hover { + color: #991b1b; + background: color-mix(in srgb, var(--danger) 8%, white); +} + +.doc-toggle:hover { + color: var(--primary-color); + background: color-mix(in srgb, var(--primary-color) 6%, white); +} + +.doc-panel { + margin: 0 0 14px; + padding-left: 12px; + border-left: 2px solid color-mix(in srgb, var(--primary-color) 30%, transparent); + color: var(--text-main); + font-size: 0.8rem; + line-height: 1.5; + white-space: pre-line; +} + +.step-note { + margin: 0 0 14px; + color: var(--text-muted); + font-size: 0.8rem; + line-height: 1.5; +} + +.step-form { + display: grid; + gap: 14px; + padding: 4px 0; +} + +.step-control { + display: grid; + gap: 6px; + max-width: 320px; + color: #1e293b; + font-size: 0.78rem; + font-weight: 700; +} + +.step-control small, +.step-fieldset small, +.step-check small { + color: var(--text-muted); + font-size: 0.72rem; + font-weight: 500; +} + +.step-control em, +.step-fieldset em { + color: var(--danger); + font-style: normal; +} + +.step-input, +.step-select { + width: 100%; + box-sizing: border-box; + min-height: 34px; + border: 1px solid rgba(43, 51, 233, 0.15); + background: rgba(255, 255, 255, 0.9); + color: var(--text-main); + border-radius: 8px; + padding: 6px 9px; + font-size: 0.8rem; + transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease; +} + +.step-input:focus-visible, +.step-select:focus-visible { + outline: none; + border-color: var(--primary-color); + box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-color) 18%, transparent); + background: var(--card-bg); +} + +.step-fieldset { + display: grid; + gap: 8px; + margin: 0; + padding: 0; + border: 0; + min-width: 0; +} + +.step-fieldset legend { + padding: 0; + margin-bottom: 4px; + color: #1e293b; + font-size: 0.78rem; + font-weight: 700; +} + +.step-quick { + display: flex; + flex-wrap: wrap; + gap: 6px; +} + +.step-quick button { + padding: 4px 10px; + border: 1px solid rgba(43, 51, 233, 0.2); + border-radius: 999px; + background: transparent; + color: var(--primary-color); + font-family: inherit; + font-size: 0.72rem; + font-weight: 600; + cursor: pointer; +} + +.step-quick button:hover { + background: color-mix(in srgb, var(--primary-color) 7%, white); +} + +.step-variable-list { + display: grid; + gap: 6px; + max-height: 320px; + overflow-y: auto; +} + +.step-row { + display: grid; + grid-template-columns: minmax(120px, 1fr) minmax(140px, 240px); + align-items: center; + gap: 12px; + font-size: 0.8rem; + color: var(--text-main); +} + +.step-check { + display: flex; + align-items: center; + gap: 8px; + font-size: 0.8rem; + color: var(--text-main); +} + +.step-error { + color: #991b1b; + font-size: 0.76rem; + font-weight: 600; +} + +.step-feedback { + padding: 12px 16px; + font-size: 0.8rem; + background: rgba(255, 186, 8, 0.12); + border: 1px solid rgba(255, 186, 8, 0.35); + border-radius: var(--radius-md, 8px); + color: #92400e; +} diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.html b/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.html new file mode 100644 index 000000000..5066741d9 --- /dev/null +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.html @@ -0,0 +1,172 @@ +@if (!shown()) { + +} @else { + + @if (isApplied()) { + + } + @if (spec().documentation) { + + } + @if (spec().documentation && docOpen()) { +
{{ spec().documentation }}
+ } + @if (note()) { +

{{ note() }}

+ } + + @if (blockedFields().length) { + + } @else { +
+ @for (field of fields(); track field.key) { + @switch (field.kind) { + @case ('enum') { + + } + @case ('bool') { + + } + @case ('int') { + + } + @case ('real') { + + } + @case ('list') { + + } + @case ('variables') { +
+ {{ field.label }}@if (field.required) {} + @if (field.description) {{{ field.description }}} +
+ + +
+
+ @for (variable of variables(); track variable.code) { + + } +
+
+ } + @case ('variable-map') { +
+ {{ field.label }}@if (field.required) {} + @if (field.description) {{{ field.description }}} + @if (field.itemKind === 'enum') { +
+ @for (option of field.options; track option) { + + } + +
+ } +
+ @for (variable of variables(); track variable.code) { + + } +
+
+ } + @default { + + } + } + @if (showErrors() && errors()[field.key]) { + + } + } + @if (variables().length === 0) { +
Select variables before configuring this step.
+ } +
+ } + + +
+} diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.spec.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.spec.ts new file mode 100644 index 000000000..4f7058ff1 --- /dev/null +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.spec.ts @@ -0,0 +1,122 @@ +import { provideZonelessChangeDetection } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { describe, expect, it, beforeEach } from 'vitest'; +import { RawPreprocessingStep } from '../../../../models/backend-algorithms.model'; +import { GenericDataTransformationStepComponent } from './generic-data-transformation-step.component'; + +const param = (extra: Record) => ({ + label: 'L', desc: '', types: ['text'], required: false, multiple: false, default: null, + enums: null, dict_keys_enums: null, dict_values_type: null, dict_values_enums: null, min: null, max: null, + ...extra, +}); + +/** Assumed engine shape: per-variable detection mode plus a threshold. */ +const detector = { + name: 'outlier_detector', label: 'Outlier Detector', desc: 'Flags outliers.', documentation: 'Flags values far from the centre.', + parameters: { + strategies: param({ + label: 'Detection mode', types: ['dict'], required: true, + dict_keys_enums: { type: 'input_var_names', source: ['variables'] }, + dict_values_enums: { type: 'list', source: ['zscore', 'robust'] }, + }), + threshold: param({ label: 'Threshold', types: ['real'], default: 3, min: 0 }), + }, +} as unknown as RawPreprocessingStep; + +const VARIABLES = [{ code: 'age', label: 'Age', type: 'real' }, { code: 'mmse', label: 'MMSE', type: 'real' }]; + +describe('GenericDataTransformationStepComponent', () => { + let fixture: ComponentFixture; + let applied: Record[]; + let removed: number; + let el: HTMLElement; + + async function settle() { + fixture.detectChanges(); + await fixture.whenStable(); + fixture.detectChanges(); + } + + beforeEach(async () => { + TestBed.configureTestingModule({ + imports: [GenericDataTransformationStepComponent], + providers: [provideZonelessChangeDetection()], + }); + fixture = TestBed.createComponent(GenericDataTransformationStepComponent); + el = fixture.nativeElement; + applied = []; + removed = 0; + fixture.componentInstance.applyStep.subscribe((value) => applied.push(value)); + fixture.componentInstance.removeStep.subscribe(() => removed++); + fixture.componentRef.setInput('spec', detector); + fixture.componentRef.setInput('variables', VARIABLES); + await settle(); + }); + + it('shows only the add row until the step is opened or applied', () => { + expect(el.querySelector('.btn-add-dashed')?.textContent).toContain('Outlier Detector'); + expect(el.querySelector('app-station-card')).toBeNull(); + }); + + it('opens the station from the add row and asks the panel to open it', async () => { + const opened: boolean[] = []; + fixture.componentInstance.openChange.subscribe((open) => opened.push(open)); + (el.querySelector('.btn-add-dashed') as HTMLButtonElement).click(); + await settle(); + expect(opened).toEqual([true]); + expect(el.querySelector('app-station-card')).not.toBeNull(); + }); + + it('applies the schema-shaped payload built from the form', async () => { + fixture.componentRef.setInput('open', true); + await settle(); + const select = el.querySelector('select[data-variable="age"]') as HTMLSelectElement; + select.value = 'zscore'; + select.dispatchEvent(new Event('change')); + const threshold = el.querySelector('input[data-param="threshold"]') as HTMLInputElement; + threshold.value = '2.5'; + threshold.dispatchEvent(new Event('input')); + await settle(); + + const buttons = Array.from(el.querySelectorAll('app-station-action-bar button')) as HTMLButtonElement[]; + buttons.find((b) => b.textContent?.includes('Apply'))!.click(); + expect(applied).toEqual([{ strategies: { age: 'zscore' }, threshold: 2.5 }]); + }); + + it('blocks Apply and names the missing required field', async () => { + fixture.componentRef.setInput('open', true); + await settle(); + // Only the threshold is touched, so the required per-variable mode is still empty. + const threshold = el.querySelector('input[data-param="threshold"]') as HTMLInputElement; + threshold.value = '4'; + threshold.dispatchEvent(new Event('input')); + await settle(); + const buttons = Array.from(el.querySelectorAll('app-station-action-bar button')) as HTMLButtonElement[]; + buttons.find((b) => b.textContent?.includes('Apply'))!.click(); + await settle(); + expect(applied).toEqual([]); + expect(el.querySelector('.step-error')?.textContent).toContain('required'); + }); + + it('hydrates from the applied parameters and removes the step', async () => { + fixture.componentRef.setInput('applied', { strategies: { mmse: 'robust' }, threshold: 2 }); + fixture.componentRef.setInput('open', true); + await settle(); + expect((el.querySelector('select[data-variable="mmse"]') as HTMLSelectElement).value).toBe('robust'); + expect((el.querySelector('input[data-param="threshold"]') as HTMLInputElement).value).toBe('2'); + expect(el.querySelector('.preprocessing-state-chip')?.textContent).toContain('Applied'); + (el.querySelector('.btn-remove-step-node') as HTMLButtonElement).click(); + expect(removed).toBe(1); + }); + + it('flags a required parameter it cannot edit instead of sending a broken step', async () => { + const recipeStep = { + name: 'x_step', label: 'X Step', desc: 'Needs a recipe.', + parameters: { reusable_preprocessing: param({ types: ['dict'], required: true, label: 'Fitted recipe' }) }, + } as unknown as RawPreprocessingStep; + fixture.componentRef.setInput('spec', recipeStep); + fixture.componentRef.setInput('open', true); + await settle(); + expect(el.querySelector('.step-feedback')?.textContent).toContain('fitted recipe'); + }); +}); diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.ts new file mode 100644 index 000000000..c35b93e61 --- /dev/null +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.ts @@ -0,0 +1,199 @@ +import { ChangeDetectionStrategy, Component, computed, effect, input, output, signal, untracked } from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { RawPreprocessingStep } from '../../../../models/backend-algorithms.model'; +import { + StepField, + StepFormValues, + buildStepParameters, + stepFields, + stepNote, + stepStage, + stepValuesFromParameters, + unsupportedRequiredFields, +} from '../../../../core/data-transformation-step-form.utils'; +import { StationActionBarComponent } from '../../shared/station-action-bar/station-action-bar.component'; +import { StationCardComponent } from '../../shared/station-card/station-card.component'; + +/** A selected variable as the panel hands it over: only the code, label and type are read. */ +interface StepVariable { + code: string; + label?: string; + name?: string; + type?: string; +} + +/** + * Station for any step the engine lists in its catalog that has no dedicated station. It renders + * both families, in-place preprocessing (global imputer, global winsorizer) and data + * transformation (new columns or changed meaning); the panel places each in its own stage. + * The form is built from the step's parameter schema and the request parameters are built by + * `buildStepParameters`, so the payload matches the engine's specification. + * Apply and Remove are reported to the panel, which owns the applied pipeline config. + */ +@Component({ + selector: 'app-generic-data-transformation-step', + imports: [FormsModule, StationCardComponent, StationActionBarComponent], + templateUrl: './generic-data-transformation-step.component.html', + styleUrl: './generic-data-transformation-step.component.css', + host: { '[attr.data-step]': 'spec().name' }, + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class GenericDataTransformationStepComponent { + readonly spec = input.required(); + /** Variables the step may act on: the experiment's selected, non-derived variables. */ + readonly variables = input([]); + /** Parameters in the applied config, or null when the step is not part of the run. */ + readonly applied = input | null>(null); + readonly open = input(false); + readonly busy = input(false); + + readonly openChange = output(); + readonly applyStep = output>(); + readonly removeStep = output(); + + protected readonly note = computed(() => stepNote(this.spec().name)); + protected readonly icon = computed(() => + stepStage(this.spec().name) === 'transformation' ? 'fas fa-code-branch' : 'fas fa-sliders', + ); + protected readonly fields = computed(() => stepFields(this.spec())); + protected readonly blockedFields = computed(() => unsupportedRequiredFields(this.fields())); + protected readonly values = signal({}); + protected readonly started = signal(false); + protected readonly showErrors = signal(false); + protected readonly docOpen = signal(false); + + /** Content key of the applied parameters, so an unrelated config change keeps the draft. */ + private readonly appliedKey = computed(() => JSON.stringify(this.applied())); + private readonly codes = computed(() => new Set(this.variables().map((variable) => variable.code))); + private readonly built = computed(() => buildStepParameters(this.fields(), this.values(), this.codes())); + + protected readonly errors = computed(() => this.built().errors); + protected readonly isApplied = computed(() => this.applied() !== null); + /** The station is drawn once it is applied or the user opened it; otherwise only the add row. */ + protected readonly shown = computed(() => this.isApplied() || this.started()); + + /** 1 when the form differs from what is applied (an incomplete form counts as a change). */ + protected readonly pendingCount = computed(() => { + const draft = JSON.stringify(this.built().parameters); + const applied = JSON.stringify(this.applied() ?? {}); + if (!this.isApplied() && Object.keys(this.built().parameters).length === 0) return 0; + return draft === applied ? 0 : 1; + }); + + protected readonly statusLabel = computed(() => { + if (this.pendingCount() > 0) return 'Not applied'; + return this.isApplied() ? 'Applied' : 'Not set'; + }); + protected readonly statusTone = computed<'applied' | 'pending' | 'default'>(() => + this.pendingCount() > 0 ? 'pending' : this.isApplied() ? 'applied' : 'default', + ); + + constructor() { + // The form follows the applied config: a hydrated saved experiment, a Discard, or a change + // of the selection that trims the applied step all land here. + effect(() => { + this.appliedKey(); + const fields = this.fields(); + untracked(() => this.values.set(stepValuesFromParameters(fields, this.applied()))); + }); + effect(() => { + if (this.open()) untracked(() => this.started.set(true)); + }); + } + + protected add(): void { + this.started.set(true); + this.openChange.emit(true); + } + + protected toggle(): void { + this.openChange.emit(!this.open()); + } + + protected toggleDoc(): void { + this.docOpen.update((open) => !open); + } + + protected variableLabel(variable: StepVariable): string { + return variable.label || variable.name || variable.code; + } + + protected optionLabel(option: string): string { + return option.replace(/_/g, ' '); + } + + protected scalar(field: StepField): string { + const value = this.values()[field.key]; + return typeof value === 'string' ? value : ''; + } + + protected flag(field: StepField): boolean { + return this.values()[field.key] === true; + } + + protected setValue(field: StepField, value: unknown): void { + this.values.update((values) => ({ ...values, [field.key]: value })); + } + + protected isSelected(field: StepField, code: string): boolean { + const value = this.values()[field.key]; + return Array.isArray(value) && value.includes(code); + } + + protected toggleVariable(field: StepField, code: string): void { + const value = this.values()[field.key]; + const current = Array.isArray(value) ? (value as string[]) : []; + this.setValue(field, current.includes(code) ? current.filter((item) => item !== code) : [...current, code]); + } + + protected selectAllVariables(field: StepField): void { + this.setValue(field, this.variables().map((variable) => variable.code)); + } + + protected clearVariables(field: StepField): void { + this.setValue(field, []); + } + + protected mapValue(field: StepField, code: string): string { + const map = this.values()[field.key] as Record | undefined; + return map?.[code] ?? ''; + } + + protected setMapValue(field: StepField, code: string, value: string): void { + const map = { ...((this.values()[field.key] as Record | undefined) ?? {}) }; + if (value === '' || value === null || value === undefined) delete map[code]; + else map[code] = value; + this.setValue(field, map); + } + + /** Set every selected variable to one value (the batch shortcut of the per-variable steps). */ + protected setAllMapValues(field: StepField, value: string): void { + this.setValue(field, Object.fromEntries(this.variables().map((variable) => [variable.code, value]))); + } + + protected discard(): void { + this.showErrors.set(false); + this.values.set(stepValuesFromParameters(this.fields(), this.applied())); + } + + protected commitOrClose(): void { + if (this.pendingCount() === 0) { + this.openChange.emit(false); + return; + } + if (this.blockedFields().length) return; + if (Object.keys(this.errors()).length) { + this.showErrors.set(true); + return; + } + this.showErrors.set(false); + this.applyStep.emit(this.built().parameters); + } + + protected remove(): void { + this.started.set(false); + this.showErrors.set(false); + this.removeStep.emit(); + this.openChange.emit(false); + } +} diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html index f652f2be8..268843912 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html @@ -622,7 +622,7 @@

- Decide what happens to missing values, and optionally cap outliers. + Decide what happens to missing values, and optionally cap outliers. Every variable keeps its meaning and range.
@@ -695,44 +695,20 @@

-

- } - @if (!scalerSubNodeApplied && scalerStepAvailable) { + @for (spec of genericStepsOf('preprocessing'); track spec.name) { + @if (!isGenericStepApplied(spec.name)) {
-
} - @if (isLongitudinalModel && !expStudioService.appliedPreprocessingConfig()?.['longitudinal_transformer']) { -
- - -
} } @@ -1307,8 +1283,167 @@
Values that would be capped · per data } + @for (spec of genericStepsOf('preprocessing'); track spec.name) { + + } + + + +
+
+ +
+
+ + } + + + + + + +
+
+
+
+
+Step 4 · Optional +

+ Create new variables or change what a variable means — for example, group MMSE scores into ‘impaired’ and ‘normal’, or put values on a common scale. +
+
+
+ + {{ transformationBadgeLabel }} + + @if (isStepAdded('transformation')) { + + } + +
+
+ + + @if (!sectionOpen().transformation) { +
+ @for (node of appliedTransformationSubNodes; track node.id) { +
+ + +
+ } @if (!transformSubNodeApplied && transformStepAvailable) { - +
+ } + @if (!scalerSubNodeApplied && scalerStepAvailable) { +
+ + +
+ } + @for (spec of genericStepsOf('transformation'); track spec.name) { + @if (!isGenericStepApplied(spec.name)) { +
+ + +
+ } + } + @if (isLongitudinalModel && !expStudioService.appliedPreprocessingConfig()?.['longitudinal_transformer']) { +
+ + +
+ } +
+ + +
+ + } + + @if (isStepAdded('transformation')) { +
+ @if (sectionOpen().transformation) { + + } +
+
+ + @if (!transformSubNodeApplied && transformStepAvailable) { + @@ -1454,7 +1589,7 @@

{{ variableLabel(variable) }}

} @if (!scalerSubNodeApplied && scalerStepAvailable) { - @@ -1660,14 +1795,14 @@

{{ variableLabel(variable) }}

@if (preprocessingVariables.length > 0) {
-
-
-
-
- -
-
-
- } -
- - - - - -
-
-
-
-
-Step 4 · Optional -

- Create a new variable from rules — for example, group MMSE scores into ‘impaired’ and ‘normal’. -
-
-
- - {{ transformationBadgeLabel }} - - @if (isStepAdded('transformation')) { - - } - -
-
- - - @if (!sectionOpen().transformation) { -
- @for (node of appliedTransformationSubNodes; track node.id) { -
- - -
+ @for (spec of genericStepsOf('transformation'); track spec.name) { + } -
- - -
-
- } - @if (isStepAdded('transformation')) { -
- @if (sectionOpen().transformation) { - - } -
-
+ @@ -2172,6 +2229,9 @@

You have unapplied changes

} {{ preprocessingVariables.length }} variables · {{ expStudioService.selectedDatasets().length }} datasets {{ terminalPreprocessingLine }} + @if (terminalTransformationLine) { + {{ terminalTransformationLine }} + }
@@ -115,14 +115,17 @@
} + @if (isDependent(field) && rowsFor(field).length === 0) { + Appears for the variables set to constant above. + }
- @for (variable of variables(); track variable.code) { + @for (variable of rowsFor(field); track variable.code) {
} @else {
diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.spec.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.spec.ts index 3ae65cac3..f402f22fb 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.spec.ts +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.spec.ts @@ -3242,6 +3242,60 @@ describe('StatisticAnalysisPanelComponent', () => { }); }); + describe('quantile transform settings', () => { + const age = { code: 'age', label: 'Age', type: 'real' }; + + beforeEach(() => { + (mockExpService.selectedVariables as any).set([age]); + component.pendingTransformStrategies = {}; + component.appliedTransformStrategies = {}; + }); + + it('shows n_quantiles only while a quantile transform is chosen', () => { + component.onTransformStrategyChange(age, 'log1p'); + expect(component.transformUsesQuantiles).toBe(false); + component.onTransformStrategyChange(age, 'quantile_normal'); + expect(component.transformUsesQuantiles).toBe(true); + }); + + it('sends n_quantiles with a quantile transform and leaves it out for the others', () => { + component.onTransformStrategyChange(age, 'quantile_uniform'); + component.onTransformNQuantilesChange('21'); + expect((component as any).buildTransformPreprocessingConfig(false, new Set(['age']))) + .toEqual({ strategies: { age: 'quantile_uniform' }, n_quantiles: 21 }); + + component.onTransformStrategyChange(age, 'log1p'); + expect((component as any).buildTransformPreprocessingConfig(false, new Set(['age']))) + .toEqual({ strategies: { age: 'log1p' } }); + }); + + it('treats a value below 2 or a fraction as an error and sends the engine default', () => { + component.onTransformStrategyChange(age, 'quantile_uniform'); + for (const bad of ['1', '2.5', 'x']) { + component.onTransformNQuantilesChange(bad); + expect(component.transformNQuantilesError).toMatch(/at least 2/); + expect((component as any).buildTransformPreprocessingConfig(false, new Set(['age']))) + .toEqual({ strategies: { age: 'quantile_uniform' } }); + } + component.onTransformNQuantilesChange(''); + expect(component.transformNQuantilesError).toBe(''); + }); + + it('applies n_quantiles with the card and counts it as a pending change', () => { + component.onTransformStrategyChange(age, 'quantile_normal'); + (component as any).prepStepOps['transform'].commit(); + expect(component.hasPendingTransformChanges).toBe(false); + + component.onTransformNQuantilesChange('21'); + expect(component.hasPendingTransformChanges).toBe(true); + (component as any).prepStepOps['transform'].commit(); + expect(component.appliedTransformNQuantiles).toBe(21); + expect(component.hasPendingTransformChanges).toBe(false); + (component as any).prepStepOps['transform'].reset(); + expect(component.pendingTransformNQuantiles).toBe('21'); + }); + }); + describe('cohort retention strip', () => { it('shows the retention strip only when both raw and processed summaries are loaded', () => new Promise((done) => { const { age } = configureRawSummary(); diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts index 1d3fadddb..cfcda9898 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts @@ -372,6 +372,9 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { /** Full desired state per variable (null = no transform); hydration copies `applied` into it. */ pendingTransformStrategies: Record = {}; appliedTransformStrategies: Record = {}; + /** `n_quantiles` of the quantile transforms, as the text input binds it; '' = engine default (100). */ + pendingTransformNQuantiles = ''; + appliedTransformNQuantiles: number | null = null; pendingScalerStrategies: Record = {}; appliedScalerStrategies: Record = {}; /** `feature_range` for minmax, as the two text inputs the editor binds; null = default. */ @@ -516,6 +519,8 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { this.appliedScalerStrategies = {}; this.pendingScalerFeatureRange = ['', '']; this.appliedScalerFeatureRange = null; + this.pendingTransformNQuantiles = ''; + this.appliedTransformNQuantiles = null; this.appliedLongitudinalEnabled = false; this.longitudinalVisit1 = ''; this.longitudinalVisit2 = ''; @@ -657,6 +662,8 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { if (step === 'transform') { this.pendingTransformStrategies = {}; this.appliedTransformStrategies = {}; + this.pendingTransformNQuantiles = ''; + this.appliedTransformNQuantiles = null; } else { this.pendingScalerStrategies = {}; this.appliedScalerStrategies = {}; @@ -2883,12 +2890,14 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { }, transform: { pending: () => this.pendingTransformChangeCount, - validate: () => ({}), + validate: (): Record => (this.transformNQuantilesError ? { __n_quantiles__: this.transformNQuantilesError } : {}), commit: () => { this.appliedTransformStrategies = this.cleanStrategyMap(this.pendingTransformStrategies); + this.appliedTransformNQuantiles = this.parseNQuantiles(this.pendingTransformNQuantiles); }, reset: () => { this.pendingTransformStrategies = { ...this.appliedTransformStrategies }; + this.pendingTransformNQuantiles = this.appliedTransformNQuantiles === null ? '' : String(this.appliedTransformNQuantiles); }, }, scaler: { @@ -3059,6 +3068,33 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { return this.pendingScalerStrategies[variable.code] ?? null; } + onTransformNQuantilesChange(value: string): void { + this.pendingTransformNQuantiles = value === null || value === undefined ? '' : String(value); + this.updatePreprocessingStatus(); + this.emitProgressState(); + } + + /** True while a quantile transform is chosen: only then does `n_quantiles` matter. */ + get transformUsesQuantiles(): boolean { + const codes = new Set(this.outlierPreprocessingVariables.map((variable) => variable.code)); + return Object.entries(this.pendingTransformStrategies) + .some(([code, strategy]) => codes.has(code) && (strategy === 'quantile_uniform' || strategy === 'quantile_normal')); + } + + /** Whole number >= 2, or null (empty = engine default). */ + private parseNQuantiles(raw: string): number | null { + const text = String(raw ?? '').trim(); + if (!text) return null; + const n = Number(text); + return Number.isInteger(n) && n >= 2 ? n : null; + } + + get transformNQuantilesError(): string { + const text = String(this.pendingTransformNQuantiles ?? '').trim(); + if (!text || !this.transformUsesQuantiles) return ''; + return this.parseNQuantiles(text) === null ? 'Number of quantiles must be a whole number of at least 2.' : ''; + } + onScalerStrategyChange(variable: VariableRow, strategy: ScalerStrategy | null): void { this.pendingScalerStrategies = { ...this.pendingScalerStrategies, @@ -3099,9 +3135,13 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { const range = applied ? this.appliedScalerFeatureRange : this.parseFeatureRange(this.pendingScalerFeatureRange); const source = step === 'transform' ? transformStrategies : scalerStrategies; const codes = this.outlierPreprocessingVariables.map((v) => v.code); + const nQuantiles = applied ? this.appliedTransformNQuantiles : this.parseNQuantiles(this.pendingTransformNQuantiles); return JSON.stringify({ strategies: Object.fromEntries(codes.sort().map((code) => [code, source[code] ?? null])), ...(step === 'scaler' ? { featureRange: range } : {}), + ...(step === 'transform' && Object.values(source).some((v) => v === 'quantile_uniform' || v === 'quantile_normal') + ? { nQuantiles } + : {}), }); } @@ -4792,7 +4832,11 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { const strategies = Object.fromEntries( Object.entries(source).filter(([code]) => allowedCodes.has(code)) ); - return Object.keys(strategies).length ? { strategies } : null; + if (!Object.keys(strategies).length) return null; + // `n_quantiles` only matters to the quantile methods; without one it stays out of the request. + const nQuantiles = applied ? this.appliedTransformNQuantiles : this.parseNQuantiles(this.pendingTransformNQuantiles); + const usesQuantiles = Object.values(strategies).some((strategy) => strategy === 'quantile_uniform' || strategy === 'quantile_normal'); + return usesQuantiles && nQuantiles !== null ? { strategies, n_quantiles: nQuantiles } : { strategies }; } private buildScalerPreprocessingConfig( @@ -5053,6 +5097,10 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { }; this.appliedTransformStrategies = hydrateStrategies('variable_transformer', this.isTransformStrategy); this.pendingTransformStrategies = { ...this.appliedTransformStrategies }; + const transformHolder = preprocessing['variable_transformer'] as { n_quantiles?: unknown } | undefined; + const storedQuantiles = Number(transformHolder?.n_quantiles); + this.appliedTransformNQuantiles = Number.isInteger(storedQuantiles) && storedQuantiles >= 2 ? storedQuantiles : null; + this.pendingTransformNQuantiles = this.appliedTransformNQuantiles === null ? '' : String(this.appliedTransformNQuantiles); this.appliedScalerStrategies = hydrateStrategies('variable_scaler', this.isScalerStrategy); this.pendingScalerStrategies = { ...this.appliedScalerStrategies }; const scalerHolder = preprocessing['variable_scaler'] as { feature_range?: unknown } | undefined; diff --git a/src/app/services/experiment-studio.service.spec.ts b/src/app/services/experiment-studio.service.spec.ts index 3747e812d..d8daeecb2 100644 --- a/src/app/services/experiment-studio.service.spec.ts +++ b/src/app/services/experiment-studio.service.spec.ts @@ -1107,6 +1107,20 @@ describe('ExperimentStudioService', () => { }); }); + it('drops the transformer step when filtering leaves no strategy, not just n_quantiles', () => { + service.selectedDataModel.set(mockDataModel); + service.setSelectedDatasets(['ds1']); + const applied = { + variable_transformer: { strategies: { bmi: 'quantile_normal' }, n_quantiles: 21 }, + }; + + const body = service.buildRequestBody('histogram', ['age'], null, null, null, null, applied); + + expect(body.analysis.preprocessing).toEqual(preprocessingSteps({ + missing_values_handler: { strategies: { age: 'drop' } }, + })); + }); + it('drops the scaler step when filtering leaves no strategy, not just feature_range', () => { service.selectedDataModel.set(mockDataModel); service.setSelectedDatasets(['ds1']); diff --git a/src/app/services/experiment-studio.service.ts b/src/app/services/experiment-studio.service.ts index a622011b9..69fb3223a 100644 --- a/src/app/services/experiment-studio.service.ts +++ b/src/app/services/experiment-studio.service.ts @@ -1508,7 +1508,10 @@ export class ExperimentStudioService { allowed, ['strategies'] ); - if (next) filtered['variable_transformer'] = next; + // Like the scaler: a lone step-level parameter (`n_quantiles`) must not keep the step alive. + if (next && Object.keys((next['strategies'] as Record) ?? {}).length > 0) { + filtered['variable_transformer'] = next; + } } const scaler = preprocessing['variable_scaler']; From 9d6ffe66fd151e91b25989ad9538491043eaa05f Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 09:56:08 +0200 Subject: [PATCH 03/22] contracts: 2026-11-11_add-step-picker-ux --- e2e/experiment-studio.flows.spec.ts | 3 +- e2e/studio.ts | 32 +- src/app/core/step-picker.utils.spec.ts | 138 ++++++ src/app/core/step-picker.utils.ts | 48 +++ .../step-picker/step-picker.component.css | 210 +++++++++ .../step-picker/step-picker.component.html | 0 .../step-picker/step-picker.component.spec.ts | 152 +++++++ .../step-picker/step-picker.component.ts | 39 ++ ...data-transformation-step.component.spec.ts | 26 +- ...statistic-analysis-panel.component.spec.ts | 40 +- .../statistic-analysis-panel.component.ts | 48 +++ .../statistic-analysis-panel.pipeline.spec.ts | 294 +++++++++---- ...tistic-analysis-panel.stage-picker.spec.ts | 408 ++++++++++++++++++ 13 files changed, 1313 insertions(+), 125 deletions(-) create mode 100644 src/app/core/step-picker.utils.spec.ts create mode 100644 src/app/core/step-picker.utils.ts create mode 100644 src/app/pages/experiment-studio/shared/step-picker/step-picker.component.css create mode 100644 src/app/pages/experiment-studio/shared/step-picker/step-picker.component.html create mode 100644 src/app/pages/experiment-studio/shared/step-picker/step-picker.component.spec.ts create mode 100644 src/app/pages/experiment-studio/shared/step-picker/step-picker.component.ts create mode 100644 src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.stage-picker.spec.ts diff --git a/e2e/experiment-studio.flows.spec.ts b/e2e/experiment-studio.flows.spec.ts index d30814ada..e7fa8a617 100644 --- a/e2e/experiment-studio.flows.spec.ts +++ b/e2e/experiment-studio.flows.spec.ts @@ -12,6 +12,7 @@ import { applyLongitudinalStrategy, applyMeanImputationToAll, applyOutlierChoice, + pickStep, assignRole, clearRole, collapsePreprocessing, @@ -249,7 +250,7 @@ test.describe('preprocessing', () => { test('batch actions set every numerical variable', async ({ page, api }) => { await openAgeAndSex(page); await applyMeanImputationToAll(page); - await page.locator('button:visible').filter({ hasText: /Add outlier/ }).first().click(); + await pickStep(page, 'preprocessing', 'outlier_winsorizer'); const outlier = page.locator('app-station-card', { hasText: 'Outlier Handling' }); await outlier.getByRole('button', { name: 'Batch' }).click(); await page.getByRole('menuitem', { name: 'Enable for all numerical' }).click(); diff --git a/e2e/studio.ts b/e2e/studio.ts index 6b5a42dd4..4114534f6 100644 --- a/e2e/studio.ts +++ b/e2e/studio.ts @@ -150,10 +150,21 @@ export async function applyMeanImputationToAll(page: Page) { await expect(missing).toContainText(/Mean imputation|Applied/); } +/** + * Pick a step from a stage's add-step menu: the rail's while the stage is collapsed, the stage's + * own once it is open. `step` is the engine's step name, e.g. `outlier_winsorizer`. + */ +export async function pickStep(page: Page, stage: 'preprocessing' | 'transformation', step: string) { + const picker = page.locator(`[data-guide="analysis-${stage}"] app-step-picker:visible`).first(); + const trigger = picker.locator('.step-picker-trigger'); + if ((await trigger.getAttribute('aria-expanded')) !== 'true') await trigger.click(); + await picker.locator(`.step-picker-option[data-step="${step}"]`).click(); +} + /** Enable outlier capping for every numerical variable, optionally picking a method and tail. */ export async function applyOutlierChoice(page: Page, method?: string, clip?: string) { await page.getByRole('button', { name: 'Customize rules' }).click(); - await page.locator('button:visible').filter({ hasText: /Add outlier/ }).first().click(); + await pickStep(page, 'preprocessing', 'outlier_winsorizer'); const outlier = page.locator('app-station-card', { hasText: 'Outlier Handling' }); await outlier.getByRole('button', { name: 'Batch' }).click(); await page.getByRole('menuitem', { name: 'Enable for all numerical' }).click(); @@ -181,7 +192,7 @@ export async function openLongitudinalAge(page: Page) { export async function applyLongitudinalStrategy(page: Page, label: string) { // The longitudinal comparison changes what the variable means, so it is a data transformation. - await page.getByRole('button', { name: /Add longitudinal comparison/ }).click(); + await pickStep(page, 'transformation', 'longitudinal_transformer'); const card = page.locator('app-station-card', { hasText: 'Longitudinal Transformation' }); await card.getByRole('button', { name: /^Age/ }).click(); await card.locator('select').last().selectOption({ label }); @@ -215,8 +226,7 @@ export async function applyFilters(page: Page, { female = false } = {}) { } export async function addNominalColumn(page: Page, code: string, category: string, fallback: string) { - await page.getByTitle('Add and open a derived column').click(); - await page.getByRole('button', { name: /Nominal column from rules/ }).click(); + await pickStep(page, 'transformation', 'categorical_column_creator'); await page.getByPlaceholder('e.g. mrs_good_outcome').fill(code); await page.getByRole('button', { name: /Add the first category/ }).click(); await page.getByPlaceholder('Enumeration value').fill(category); @@ -229,10 +239,10 @@ export async function addNominalColumn(page: Page, code: string, category: strin await expect(page.getByText('Sex is Female')).toBeVisible(); } -/** `stepAdded`: the transformation step is already open (another column was added first). */ +/** `stepAdded` is kept for the callers: the add-step menu is the same whether the stage is open or not. */ export async function addKMeansColumn(page: Page, { stepAdded = false } = {}) { - if (!stepAdded) await page.getByTitle('Add and open a derived column').click(); - await page.getByRole('button', { name: /K-means cluster column/ }).click(); + void stepAdded; + await pickStep(page, 'transformation', 'kmeans_cluster_creator'); const source = page.locator('app-kmeans-cluster-source'); await source.getByRole('button', { name: 'Run K-means report' }).click(); await expect(source.getByText('Cluster 0')).toBeVisible(); @@ -247,8 +257,8 @@ export async function addKMeansColumn(page: Page, { stepAdded = false } = {}) { * `stepAdded`: transformation stage already open with the type chooser visible. */ export async function addPcaColumns(page: Page, { stepAdded = false } = {}) { - if (!stepAdded) await page.getByTitle('Add and open a derived column').click(); - await page.getByRole('button', { name: /PCA component columns/ }).click(); + void stepAdded; + await pickStep(page, 'transformation', 'pca_column_creator'); const source = page.locator('app-pca-column-source'); await source.getByRole('button', { name: 'Fit on selected variables' }).click(); await source.getByRole('button', { name: 'Add component columns' }).click(); @@ -260,8 +270,8 @@ export async function addPcaColumns(page: Page, { stepAdded = false } = {}) { * Deselects every other numerical option in the fit pool. */ export async function addKMeansOnColumns(page: Page, columns: string[], { stepAdded = false } = {}) { - if (!stepAdded) await page.getByTitle('Add and open a derived column').click(); - await page.getByRole('button', { name: /K-means cluster column/ }).click(); + void stepAdded; + await pickStep(page, 'transformation', 'kmeans_cluster_creator'); const source = page.locator('app-kmeans-cluster-source').last(); await source.getByRole('button', { name: 'Fit on selected variables' }).click(); const keep = new Set(columns); diff --git a/src/app/core/step-picker.utils.spec.ts b/src/app/core/step-picker.utils.spec.ts new file mode 100644 index 000000000..c1e76a614 --- /dev/null +++ b/src/app/core/step-picker.utils.spec.ts @@ -0,0 +1,138 @@ +import { describe, expect, it } from 'vitest'; +import { stepIcon, stepPickerGroups } from './step-picker.utils'; + +describe('stepIcon', () => { + it('gives every known step its own icon', () => { + expect(stepIcon('outlier_winsorizer')).toBe('fas fa-line-chart'); + expect(stepIcon('global_imputer')).toBe('fas fa-fill-drip'); + expect(stepIcon('global_winsorizer')).toBe('fas fa-compress'); + expect(stepIcon('variable_transformer')).toBe('fas fa-arrow-up-right-dots'); + expect(stepIcon('variable_scaler')).toBe('fas fa-ruler-horizontal'); + expect(stepIcon('one_hot_encoder')).toBe('fas fa-table-columns'); + expect(stepIcon('ordinal_encoder')).toBe('fas fa-arrow-down-1-9'); + expect(stepIcon('missing_indicator')).toBe('fas fa-flag'); + expect(stepIcon('outlier_detector')).toBe('fas fa-magnifying-glass-chart'); + expect(stepIcon('longitudinal_transformer')).toBe('fas fa-code-compare'); + }); + + it('falls back to the branch icon for a step it does not know', () => { + expect(stepIcon('a_step_the_engine_adds_later')).toBe('fas fa-code-branch'); + }); +}); + +describe('stepPickerGroups', () => { + it('returns no group when nothing can be added', () => { + expect(stepPickerGroups([])).toEqual([]); + }); + + it('sorts the preprocessing steps into missing values, then outliers', () => { + const groups = stepPickerGroups([ + { name: 'outlier_winsorizer' }, + { name: 'global_imputer', label: 'Global Imputer', desc: 'Impute missing values in place.' }, + { name: 'global_winsorizer', label: 'Global Winsorizer', desc: 'Clip numerical variables.' }, + ]); + + expect(groups.map((group) => [group.key, group.label])).toEqual([ + ['missing', 'Fill missing values'], + ['outliers', 'Cap outliers'], + ]); + expect(groups[0].options.map((option) => option.id)).toEqual(['global_imputer']); + // Inside a group the steps keep the order they were given in. + expect(groups[1].options.map((option) => option.id)).toEqual(['outlier_winsorizer', 'global_winsorizer']); + }); + + it('sorts the transformation steps by purpose, in a fixed order', () => { + const groups = stepPickerGroups([ + { name: 'kmeans_cluster_creator', label: 'K-means cluster column', desc: 'Group records.' }, + { name: 'longitudinal_transformer' }, + { name: 'outlier_detector', label: 'Outlier Detector', desc: 'Detect outliers.' }, + { name: 'ordinal_encoder', label: 'Ordinal Encoder', desc: 'Integer codes.' }, + { name: 'variable_scaler' }, + { name: 'missing_indicator', label: 'Missing Indicator', desc: 'Flag gaps.' }, + { name: 'one_hot_encoder', label: 'One-Hot Encoder', desc: 'Dummy columns.' }, + { name: 'variable_transformer' }, + { name: 'categorical_column_creator', label: 'Nominal column from rules', desc: 'Name categories.' }, + { name: 'pca_column_creator', label: 'PCA component columns', desc: 'Project.' }, + ]); + + expect(groups.map((group) => [group.key, group.label])).toEqual([ + ['reshape', 'Reshape and scale'], + ['encode', 'Encode categories'], + ['flag', 'Flag records'], + ['visits', 'Compare visits'], + ['create', 'Create a column'], + ]); + expect(groups.map((group) => group.options.map((option) => option.id))).toEqual([ + ['variable_scaler', 'variable_transformer'], + ['ordinal_encoder', 'one_hot_encoder'], + ['outlier_detector', 'missing_indicator'], + ['longitudinal_transformer'], + ['kmeans_cluster_creator', 'categorical_column_creator', 'pca_column_creator'], + ]); + }); + + it('names the steps that own a station exactly as their station is titled', () => { + const options = stepPickerGroups([ + { name: 'outlier_winsorizer' }, + { name: 'variable_transformer' }, + { name: 'variable_scaler' }, + { name: 'longitudinal_transformer' }, + ]).flatMap((group) => group.options); + + expect(options.map((option) => option.title)).toEqual([ + 'Outlier Handling', + 'Variable Transforms', + 'Variable Scaling', + 'Longitudinal Transformation', + ]); + expect(options[0]).toEqual({ + id: 'outlier_winsorizer', + icon: 'fas fa-line-chart', + title: 'Outlier Handling', + subtitle: 'Cap extreme values so a few outliers do not skew results. Numerical variables only.', + }); + expect(options[1].subtitle).toBe( + 'Reshape skewed values with log, square root, Yeo-Johnson or quantile. Numerical variables only.', + ); + expect(options[2].subtitle).toBe( + 'Bring numerical variables to a comparable range: standard, robust, min-max or max absolute.', + ); + expect(options[3].subtitle).toBe('Compare two visits per variable. Required for two-visit pathologies.'); + }); + + it('takes the title and description of a catalog step from the engine', () => { + const [group] = stepPickerGroups([ + { name: 'one_hot_encoder', label: 'One-Hot Encoder', desc: 'Create 0/1 dummy columns from categorical variables.' }, + ]); + + expect(group.options).toEqual([{ + id: 'one_hot_encoder', + icon: 'fas fa-table-columns', + title: 'One-Hot Encoder', + subtitle: 'Create 0/1 dummy columns from categorical variables.', + }]); + }); + + it('prefers the icon handed in with the step', () => { + const [group] = stepPickerGroups([ + { name: 'kmeans_cluster_creator', label: 'K-means cluster column', desc: 'Group records.', icon: 'fas fa-diagram-project' }, + ]); + + expect(group.options[0].icon).toBe('fas fa-diagram-project'); + }); + + it('keeps a step it does not know, under its own name, in a last group', () => { + const groups = stepPickerGroups([ + { name: 'brand_new_step' }, + { name: 'variable_scaler' }, + ]); + + expect(groups.map((group) => [group.key, group.label])).toEqual([ + ['reshape', 'Reshape and scale'], + ['other', 'More steps'], + ]); + expect(groups[1].options).toEqual([ + { id: 'brand_new_step', icon: 'fas fa-code-branch', title: 'brand_new_step', subtitle: '' }, + ]); + }); +}); diff --git a/src/app/core/step-picker.utils.ts b/src/app/core/step-picker.utils.ts new file mode 100644 index 000000000..f60ab394d --- /dev/null +++ b/src/app/core/step-picker.utils.ts @@ -0,0 +1,48 @@ +/** + * The "Add a step" menu of the Preprocessing and Data transformation stages. + * + * A stage used to list one dashed row per step it could still add. With every step of the engine's + * catalog on offer that list grew to nine rows, so the stage now shows one add row that opens a + * menu, and the menu sorts the steps by what the user wants to do with the data. + */ + +/** One step of the menu. `id` is the engine's step name; the panel maps it to the station to open. */ +export interface StepPickerOption { + id: string; + icon: string; + title: string; + subtitle: string; +} + +/** Steps that serve the same purpose, under one plain-language label. */ +export interface StepPickerGroup { + key: string; + label: string; + options: StepPickerOption[]; +} + +/** + * A step the stage can still add. `label` and `desc` come from the engine's catalog and are used + * for the steps this file has no copy for; `icon` overrides the icon of `stepIcon`. + */ +export interface StepCandidate { + name: string; + label?: string; + desc?: string; + icon?: string; +} + +/** Font Awesome classes of a pipeline step, by engine name. Unlisted names get the branch icon. */ +export function stepIcon(name: string): string { + void name; + throw new Error('not implemented'); +} + +/** + * The menu for the given steps: one group per purpose, in a fixed order, each holding its steps in + * the order they were given. A group without a step is left out. + */ +export function stepPickerGroups(candidates: StepCandidate[]): StepPickerGroup[] { + void candidates; + throw new Error('not implemented'); +} diff --git a/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.css b/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.css new file mode 100644 index 000000000..4903a7d02 --- /dev/null +++ b/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.css @@ -0,0 +1,210 @@ +/* The add row of a pipeline stage. Closed it wears the dashed edge of the rail's other "add" + rows (Filtering's "Add condition"), so it reads as the next node of the flow. Open, the row + becomes the header of one card and the steps list under it as an index: the purpose on the + left, the steps that serve it on the right. Rows, not tiles - nine identical boxes were the + problem this replaces. */ +:host { + display: block; + flex: 1; + min-width: 0; +} + +.step-picker { + margin-bottom: 6px; + border: 1px dashed color-mix(in srgb, var(--primary-color) 25%, transparent); + border-radius: var(--radius-md, 8px); + transition: border-color 0.15s ease; +} + +.step-picker:hover, +.step-picker.is-open { + border-style: solid; + border-color: color-mix(in srgb, var(--primary-color) 45%, transparent); +} + +.step-picker.is-open { + background: var(--card-bg, #ffffff); +} + +.step-picker-trigger { + display: flex; + align-items: center; + gap: 10px; + box-sizing: border-box; + width: 100%; + padding: 10px 12px; + background: transparent; + border: 0; + border-radius: calc(var(--radius-md, 8px) - 1px); + font-family: inherit; + color: inherit; + text-align: left; + cursor: pointer; +} + +.step-picker:not(.is-open) .step-picker-trigger:hover { + background: color-mix(in srgb, var(--primary-color) 7%, white); +} + +.step-picker.is-open .step-picker-trigger { + background: var(--studio-card-header-bg, #f8fbff); + border-bottom: 1px solid var(--border-color, rgba(43, 51, 233, 0.1)); + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; +} + +.step-picker-trigger:focus-visible, +.step-picker-option:focus-visible { + outline: 2px solid var(--primary-color); + outline-offset: -2px; +} + +.step-picker-plus { + flex-shrink: 0; + width: 16px; + color: var(--primary-color); + font-size: 0.7rem; + text-align: center; +} + +.step-picker-text { + display: flex; + flex-direction: column; + gap: 1px; + min-width: 0; +} + +.step-picker-label { + font-size: 0.8rem; + font-weight: 650; + line-height: 1.3; + color: var(--primary-color); +} + +.step-picker-hint { + font-size: 0.72rem; + line-height: 1.35; + color: var(--text-muted); +} + +.step-picker-chevron { + flex-shrink: 0; + margin-left: auto; + font-size: 0.68rem; + color: var(--text-muted); + transition: transform 0.15s ease; +} + +.step-picker.is-open .step-picker-chevron { + transform: rotate(180deg); +} + +.step-picker-menu { + padding: 2px 12px 4px; + animation: step-picker-reveal 0.14s ease-out; +} + +@keyframes step-picker-reveal { + from { + opacity: 0; + transform: translateY(-4px); + } +} + +/* One purpose per band: its label in a fixed left column, its steps beside it. */ +.step-picker-group { + display: grid; + grid-template-columns: 148px minmax(0, 1fr); + column-gap: 12px; + padding: 6px 0; +} + +.step-picker-group + .step-picker-group { + border-top: 1px solid var(--border-color, rgba(43, 51, 233, 0.1)); +} + +.step-picker-group-label { + padding-top: 7px; + font-size: 0.74rem; + font-weight: 600; + line-height: 1.35; + color: var(--text-muted); +} + +.step-picker-options { + display: flex; + flex-direction: column; + gap: 2px; + min-width: 0; +} + +.step-picker-option { + display: flex; + align-items: flex-start; + gap: 10px; + box-sizing: border-box; + width: 100%; + padding: 6px 8px; + background: transparent; + border: 0; + border-radius: var(--radius-sm, 4px); + font-family: inherit; + color: inherit; + text-align: left; + cursor: pointer; +} + +.step-picker-option:hover { + background: var(--tint-nav-hover, #e5ebfa); +} + +.step-picker-option > i { + flex-shrink: 0; + width: 16px; + margin-top: 3px; + color: var(--primary-color); + font-size: 0.82rem; + text-align: center; +} + +.step-picker-option-text { + display: flex; + flex-direction: column; + gap: 1px; + min-width: 0; +} + +.step-picker-option-title { + font-size: 0.8rem; + font-weight: 650; + line-height: 1.3; + color: var(--text-main); +} + +/* The description is the part a clinician reads to choose, so it wraps instead of being cut. */ +.step-picker-option-subtitle { + font-size: 0.72rem; + line-height: 1.4; + color: var(--text-muted); +} + +@media (max-width: 640px) { + .step-picker-group { + grid-template-columns: minmax(0, 1fr); + } + + .step-picker-group-label { + padding: 0 8px 2px; + } +} + +@media (prefers-reduced-motion: reduce) { + .step-picker, + .step-picker-chevron { + transition: none; + } + + .step-picker-menu { + animation: none; + } +} diff --git a/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.html b/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.html new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.spec.ts b/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.spec.ts new file mode 100644 index 000000000..5b6febe47 --- /dev/null +++ b/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.spec.ts @@ -0,0 +1,152 @@ +import { Component, provideZonelessChangeDetection, signal } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { StepPickerGroup } from '../../../../core/step-picker.utils'; +import { StepPickerComponent } from './step-picker.component'; + +const GROUPS: StepPickerGroup[] = [ + { + key: 'reshape', + label: 'Reshape and scale', + options: [ + { id: 'variable_transformer', icon: 'fas fa-arrow-up-right-dots', title: 'Variable Transforms', subtitle: 'Reshape skewed values.' }, + { id: 'variable_scaler', icon: 'fas fa-ruler-horizontal', title: 'Variable Scaling', subtitle: 'Bring variables to a comparable range.' }, + ], + }, + { + key: 'encode', + label: 'Encode categories', + options: [ + { id: 'one_hot_encoder', icon: 'fas fa-table-columns', title: 'One-Hot Encoder', subtitle: 'Create 0/1 dummy columns.' }, + ], + }, +]; + +@Component({ + imports: [StepPickerComponent], + template: ` + + `, +}) +class HostComponent { + readonly groups = signal(GROUPS); + readonly startOpen = signal(false); + readonly picked: string[] = []; +} + +describe('StepPickerComponent', () => { + let fixture: ComponentFixture; + let host: HostComponent; + let el: HTMLElement; + + const trigger = () => el.querySelector('.step-picker-trigger') as HTMLButtonElement | null; + const options = () => Array.from(el.querySelectorAll('.step-picker-option')) as HTMLButtonElement[]; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HostComponent], + providers: [provideZonelessChangeDetection()], + }); + fixture = TestBed.createComponent(HostComponent); + host = fixture.componentInstance; + el = fixture.nativeElement; + fixture.detectChanges(); + }); + + it('shows one closed add row that says what it adds', () => { + expect(trigger()).not.toBeNull(); + expect(trigger()!.getAttribute('type')).toBe('button'); + expect(trigger()!.getAttribute('aria-expanded')).toBe('false'); + expect(el.querySelector('.step-picker-label')?.textContent?.trim()).toBe('Add a transformation step'); + expect(el.querySelector('.step-picker-hint')?.textContent?.trim()) + .toBe('Reshape values, encode categories, flag records or create columns.'); + // Closed, the steps themselves are not on screen: that is the whole point of the row. + expect(el.querySelector('.step-picker-menu')).toBeNull(); + expect(options()).toEqual([]); + expect(el.querySelector('.step-picker')?.classList.contains('is-open')).toBe(false); + }); + + it('opens the menu from the add row, one labelled group per purpose', () => { + trigger()!.click(); + fixture.detectChanges(); + + expect(trigger()!.getAttribute('aria-expanded')).toBe('true'); + expect(el.querySelector('.step-picker')?.classList.contains('is-open')).toBe(true); + const groups = Array.from(el.querySelectorAll('.step-picker-group')) as HTMLElement[]; + expect(groups.map((group) => group.dataset['group'])).toEqual(['reshape', 'encode']); + expect(groups.map((group) => group.querySelector('.step-picker-group-label')?.textContent?.trim())) + .toEqual(['Reshape and scale', 'Encode categories']); + expect(groups.map((group) => group.querySelectorAll('.step-picker-option').length)).toEqual([2, 1]); + }); + + it('shows each step with its icon, name and full description', () => { + trigger()!.click(); + fixture.detectChanges(); + + expect(options().map((option) => option.dataset['step'])) + .toEqual(['variable_transformer', 'variable_scaler', 'one_hot_encoder']); + const encoder = options()[2]; + expect(encoder.getAttribute('type')).toBe('button'); + expect(encoder.querySelector('i')?.className).toContain('fa-table-columns'); + expect(encoder.querySelector('.step-picker-option-title')?.textContent?.trim()).toBe('One-Hot Encoder'); + expect(encoder.querySelector('.step-picker-option-subtitle')?.textContent?.trim()).toBe('Create 0/1 dummy columns.'); + }); + + it('reports the picked step once and closes the menu', () => { + trigger()!.click(); + fixture.detectChanges(); + + options()[1].click(); + fixture.detectChanges(); + + expect(host.picked).toEqual(['variable_scaler']); + expect(trigger()!.getAttribute('aria-expanded')).toBe('false'); + expect(options()).toEqual([]); + }); + + it('starts open when the parent asks for it, and still folds from the add row', () => { + host.startOpen.set(true); + fixture.detectChanges(); + + expect(trigger()!.getAttribute('aria-expanded')).toBe('true'); + expect(options().length).toBe(3); + + trigger()!.click(); + fixture.detectChanges(); + + expect(trigger()!.getAttribute('aria-expanded')).toBe('false'); + expect(options()).toEqual([]); + }); + + it('closes on Escape without picking anything', () => { + trigger()!.click(); + fixture.detectChanges(); + + options()[0].dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })); + fixture.detectChanges(); + + expect(trigger()!.getAttribute('aria-expanded')).toBe('false'); + expect(host.picked).toEqual([]); + }); + + it('leaves the hint line out when there is no hint', () => { + const bare = TestBed.createComponent(StepPickerComponent); + bare.componentRef.setInput('groups', GROUPS); + bare.detectChanges(); + + expect((bare.nativeElement as HTMLElement).querySelector('.step-picker-label')?.textContent?.trim()).toBe('Add a step'); + expect((bare.nativeElement as HTMLElement).querySelector('.step-picker-hint')).toBeNull(); + }); + + it('renders nothing when there is no step left to add', () => { + host.groups.set([]); + fixture.detectChanges(); + + expect(el.querySelector('.step-picker')).toBeNull(); + expect(trigger()).toBeNull(); + }); +}); diff --git a/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.ts b/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.ts new file mode 100644 index 000000000..a6ac2e2b9 --- /dev/null +++ b/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.ts @@ -0,0 +1,39 @@ +import { ChangeDetectionStrategy, Component, input, model, output } from '@angular/core'; +import { StepPickerGroup, StepPickerOption } from '../../../../core/step-picker.utils'; + +/** + * The one "add" row of a pipeline stage. Closed, it is a single dashed row on the stage's rail; + * opened, it lists every step the stage can still add, grouped by purpose (see + * `core/step-picker.utils.ts`). It only reports the pick: the panel opens the station. + */ +@Component({ + selector: 'app-step-picker', + templateUrl: './step-picker.component.html', + styleUrl: './step-picker.component.css', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class StepPickerComponent { + /** The menu. With no group the picker renders nothing. */ + readonly groups = input([]); + /** The action on the add row, e.g. "Add a preprocessing step". */ + readonly label = input('Add a step'); + /** One plain sentence under the label saying what kind of steps the menu holds. */ + readonly hint = input(''); + /** Whether the menu is shown. The picker toggles it itself; a parent may also set it. */ + readonly open = model(false); + /** The `id` of the picked option. */ + readonly pick = output(); + + protected toggle(): void { + throw new Error('not implemented'); + } + + protected choose(option: StepPickerOption): void { + void option; + throw new Error('not implemented'); + } + + protected close(): void { + throw new Error('not implemented'); + } +} diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.spec.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.spec.ts index 4f7058ff1..91626b149 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.spec.ts +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.spec.ts @@ -53,20 +53,32 @@ describe('GenericDataTransformationStepComponent', () => { await settle(); }); - it('shows only the add row until the step is opened or applied', () => { - expect(el.querySelector('.btn-add-dashed')?.textContent).toContain('Outlier Detector'); + it('draws nothing until the step is opened or applied: the stage menu is what adds it', () => { expect(el.querySelector('app-station-card')).toBeNull(); + expect(el.querySelector('.btn-add-dashed')).toBeNull(); + expect(el.textContent?.trim()).toBe(''); + // An idle step takes no room either: the stage lays its stations out with a gap. + expect(getComputedStyle(el).display).toBe('none'); }); - it('opens the station from the add row and asks the panel to open it', async () => { - const opened: boolean[] = []; - fixture.componentInstance.openChange.subscribe((open) => opened.push(open)); - (el.querySelector('.btn-add-dashed') as HTMLButtonElement).click(); + it('draws the station once the panel opens it, and keeps it on screen when it is folded', async () => { + fixture.componentRef.setInput('open', true); + await settle(); + expect(el.querySelector('app-station-card')).not.toBeNull(); + expect(el.querySelector('.btn-add-dashed')).toBeNull(); + expect(getComputedStyle(el).display).toBe('block'); + + fixture.componentRef.setInput('open', false); await settle(); - expect(opened).toEqual([true]); expect(el.querySelector('app-station-card')).not.toBeNull(); }); + it('uses the step\'s own icon on the station', async () => { + fixture.componentRef.setInput('open', true); + await settle(); + expect(el.querySelector('app-station-card i.fa-magnifying-glass-chart')).not.toBeNull(); + }); + it('applies the schema-shaped payload built from the form', async () => { fixture.componentRef.setInput('open', true); await settle(); diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.spec.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.spec.ts index f402f22fb..689523d49 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.spec.ts +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.spec.ts @@ -216,6 +216,26 @@ describe('StatisticAnalysisPanelComponent', () => { fixture.detectChanges(); } + /** + * The steps the opened Transformation stage's add-step menu offers. Opens the menu first when + * it is closed: it folds once the stage has a card to show. + */ + function transformationMenuOptions(): HTMLButtonElement[] { + const picker = workflowSection('Transformation').querySelector('.pipeline-node-body app-step-picker'); + const trigger = picker?.querySelector('.step-picker-trigger') as HTMLButtonElement | null; + if (!picker || !trigger) return []; + if (trigger.getAttribute('aria-expanded') !== 'true') { + trigger.click(); + fixture.detectChanges(); + } + return Array.from(picker.querySelectorAll('.step-picker-option')) as HTMLButtonElement[]; + } + + /** The column creators among them: one option per creator the deployment exposes. */ + function creatorOptions(): HTMLButtonElement[] { + return transformationMenuOptions().filter((option) => option.dataset['step']?.endsWith('_creator')); + } + function openStation(step: 'filters' | 'setup' | 'transformation'): HTMLElement { component.addStep(step); fixture.detectChanges(); @@ -747,10 +767,8 @@ describe('StatisticAnalysisPanelComponent', () => { expect(workflowSection('Preprocessing').querySelectorAll('.station-action-bar:has(.station-action-preview)').length).toBe(1); expect(workflowSection('Transformation').querySelector('.station-card-footer .station-action-preview')).toBeNull(); - // The K-means station is opened from the chooser's dashed row, like the categorical draft. - const addKmeans = Array.from( - workflowSection('Transformation').querySelectorAll('.transformation-chooser .pipeline-subnode-content') - ).find((button) => button.textContent?.includes('K-means')) as HTMLButtonElement; + // The K-means station is added from the stage's add-step menu, like the categorical draft. + const addKmeans = creatorOptions().find((button) => button.textContent?.includes('K-means')) as HTMLButtonElement; addKmeans.click(); fixture.detectChanges(); @@ -2520,13 +2538,10 @@ describe('StatisticAnalysisPanelComponent', () => { Array.from( workflowSection('Transformation').querySelectorAll('.transformation-graph .btn-remove-step-node') ) as HTMLButtonElement[]; - const chooserRows = () => - Array.from( - workflowSection('Transformation').querySelectorAll('.transformation-chooser .pipeline-subnode-content') - ) as HTMLButtonElement[]; + const chooserRows = () => creatorOptions(); openStation('transformation'); - // Nothing chosen yet: the stage is the type chooser, with no column card. + // Nothing chosen yet: the stage is its add-step menu, with no column card. expect(cards().length).toBe(0); expect(chooserRows().length).toBe(2); @@ -3928,11 +3943,8 @@ describe('StatisticAnalysisPanelComponent', () => { openStation('transformation'); fixture.detectChanges(); - const titles = Array.from( - workflowSection('Transformation').querySelectorAll( - '.transformation-chooser .pipeline-subnode-title', - ), - ).map((el) => el.textContent?.trim()); + const titles = transformationMenuOptions() + .map((option) => option.querySelector('.step-picker-option-title')?.textContent?.trim()); expect(titles.some((title) => /pca/i.test(title ?? ''))).toBe(false); expect(titles).toContain('Nominal column from rules'); expect(titles).toContain('K-means cluster column'); diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts index cfcda9898..1b805970e 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts @@ -95,6 +95,7 @@ import { summarizeStepParameters, } from '../../../core/data-transformation-step-form.utils'; import { GenericDataTransformationStepComponent } from './generic-data-transformation-step/generic-data-transformation-step.component'; +import { StepPickerGroup } from '../../../core/step-picker.utils'; type TabKey = 'Statistics' | 'Charts' | 'Histogram'; type SummaryKind = 'source' | 'raw' | 'processed'; @@ -944,6 +945,53 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { else this.addPreprocessingSubNode(`step:${name}`); } + // ---- Add-step menu (app-step-picker): one add row per stage instead of one dashed row per step ---- + + /** + * The Variable Transforms and Variable Scaling stations the user opened this visit. A station + * is drawn once its step is applied or it was opened here; until then the step is only an + * option of the add-step menu. + */ + readonly startedStations = signal>({ transform: false, scaler: false }); + + /** + * The steps a stage's add-step menu offers, grouped by purpose (`stepPickerGroups`). + * The collapsed rail offers every step the run does not hold yet. With `inStage` (the menu + * inside the opened stage) a step whose station is already on screen is left out as well. + */ + addableSteps(stage: 'preprocessing' | 'transformation', inStage = false): StepPickerGroup[] { + void stage; + void inStage; + throw new Error('not implemented'); + } + + /** + * A pick in an add-step menu, by engine step name: opens the stage on that step's station. + * A column creator adds its card. Nothing is written to the request. + */ + pickStep(name: string): void { + void name; + throw new Error('not implemented'); + } + + /** Whether the Variable Transforms station is drawn: the step is applied, or was opened this visit. */ + get transformStationShown(): boolean { + throw new Error('not implemented'); + } + + /** Same for the Variable Scaling station. */ + get scalerStationShown(): boolean { + throw new Error('not implemented'); + } + + /** + * Whether the opened Data transformation stage shows its add-step menu unfolded: only while the + * stage has nothing else to show (no card, no applied step, no opened station). + */ + get transformationPickerOpen(): boolean { + throw new Error('not implemented'); + } + /** Catalog steps of one stage, in catalog order. */ genericStepsOf(stage: 'preprocessing' | 'transformation'): RawPreprocessingStep[] { return this.genericSteps.filter((spec) => stepStage(spec.name) === stage); diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.pipeline.spec.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.pipeline.spec.ts index ef37ec081..1d7f72b4b 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.pipeline.spec.ts +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.pipeline.spec.ts @@ -55,10 +55,11 @@ describe('StatisticAnalysisPanelComponent pipeline presence', () => { return (fixture.nativeElement as HTMLElement).querySelector(`[data-guide="${stage}"]`) as HTMLElement; } - /** The collapsed rail rows, split into what runs and what the rail offers to add. */ + /** + * The collapsed rail rows: `live` is what runs, `ghost` is the dashed row that adds a step. + * A stage has one add row at most; it holds the add-step menu (see `railOptions`). + */ function railRows(card: HTMLElement): { live: HTMLElement[]; ghost: HTMLElement[] } { - // Scoped to the rail: the opened Transformation stage keeps its own ghost rows in the - // type chooser, which is part of the stage graph rather than of the overview. const rows = Array.from(card.querySelectorAll('.pipeline-subnodes-tree .pipeline-subnode-item')) as HTMLElement[]; return { live: rows.filter((row) => !row.classList.contains('is-ghost')), @@ -66,6 +67,31 @@ describe('StatisticAnalysisPanelComponent pipeline presence', () => { }; } + /** The add row of a collapsed stage's rail, or null when the stage has nothing left to add. */ + function railTrigger(card: HTMLElement): HTMLButtonElement | null { + return card.querySelector('.pipeline-subnodes-tree app-step-picker .step-picker-trigger'); + } + + /** The steps the rail's add-step menu offers. Opens the menu first when it is closed. */ + function railOptions(card: HTMLElement): HTMLButtonElement[] { + const trigger = railTrigger(card); + if (!trigger) return []; + if (trigger.getAttribute('aria-expanded') !== 'true') { + trigger.click(); + fixture.detectChanges(); + } + return Array.from(card.querySelectorAll('.pipeline-subnodes-tree app-step-picker .step-picker-option')) as HTMLButtonElement[]; + } + + /** Engine names of the steps the rail's add-step menu offers, in menu order. */ + function railSteps(card: HTMLElement): (string | undefined)[] { + return railOptions(card).map((option) => option.dataset['step']); + } + + function railOption(card: HTMLElement, step: string): HTMLButtonElement | undefined { + return railOptions(card).find((option) => option.dataset['step'] === step); + } + beforeEach(async () => { mockExpService = createSpyObj('ExperimentStudioService', [ 'loadDescriptiveOverview', @@ -335,20 +361,20 @@ describe('StatisticAnalysisPanelComponent pipeline presence', () => { }); /** - * The dashed rail row is the whole add flow: it opens the station already narrowed to that - * sub-step, so a stage never has to be expanded just to reach a control. + * The rail's add row is the whole add flow: its menu opens the station already narrowed to + * that sub-step, so a stage never has to be expanded just to reach a control. */ it('adds a preprocessing sub-step from the collapsed rail without writing the request', () => { (mockExpService.selectedVariables as any).set([age]); fixture.detectChanges(); expect(pipelineCard('analysis-preprocessing').querySelector('.pipeline-node-body')).toBeNull(); - const rows = railRows(pipelineCard('analysis-preprocessing')); - const outlierGhost = rows.ghost.find((row) => row.textContent?.includes('Add outlier clipping')); - expect(outlierGhost).toBeTruthy(); + const outlierOption = railOption(pipelineCard('analysis-preprocessing'), 'outlier_winsorizer'); + expect(outlierOption).toBeTruthy(); + expect(outlierOption!.textContent).toContain('Outlier Handling'); mockExpService.setAppliedDescriptivePreprocessing.mockClear(); - (outlierGhost!.querySelector('button') as HTMLButtonElement).click(); + outlierOption!.click(); fixture.detectChanges(); expect(component.sectionOpen().setup).toBe(true); @@ -357,7 +383,8 @@ describe('StatisticAnalysisPanelComponent pipeline presence', () => { expect(component.preprocessingStepOpen.missing).toBe(false); expect(pipelineCard('analysis-preprocessing').querySelector('.pipeline-node-body')).toBeTruthy(); expect(mockExpService.setAppliedDescriptivePreprocessing).not.toHaveBeenCalled(); - expect(railRows(pipelineCard('analysis-preprocessing')).ghost.some((row) => row.textContent?.includes('Add outlier clipping'))).toBe(false); + // The stage is open now, so its rail (and the rail's add row) is gone. + expect(railTrigger(pipelineCard('analysis-preprocessing'))).toBeNull(); }); /** @@ -369,9 +396,7 @@ describe('StatisticAnalysisPanelComponent pipeline presence', () => { (mockExpService.selectedVariables as any).set([age]); fixture.detectChanges(); - const rail = railRows(pipelineCard('analysis-preprocessing')); - const outlierGhost = rail.ghost.find((row) => row.textContent?.includes('Add outlier clipping'))!; - (outlierGhost.querySelector('button') as HTMLButtonElement).click(); + railOption(pipelineCard('analysis-preprocessing'), 'outlier_winsorizer')!.click(); fixture.detectChanges(); expect(component.pendingChangeCount).toBe(0); @@ -387,18 +412,17 @@ describe('StatisticAnalysisPanelComponent pipeline presence', () => { // never consumed the one control that adds the step back. component.collapseStep('setup'); fixture.detectChanges(); - const rows = railRows(pipelineCard('analysis-preprocessing')); - expect(rows.live.length).toBe(1); - expect(rows.ghost.some((row) => row.textContent?.includes('Add outlier clipping'))).toBe(true); + expect(railRows(pipelineCard('analysis-preprocessing')).live.length).toBe(1); + const outlierOption = railOption(pipelineCard('analysis-preprocessing'), 'outlier_winsorizer'); + expect(outlierOption).toBeTruthy(); - const outlierRow = rows.ghost.find((row) => row.textContent?.includes('Add outlier clipping'))!; - (outlierRow.querySelector('button') as HTMLButtonElement).click(); + outlierOption!.click(); fixture.detectChanges(); expect(component.sectionOpen().setup).toBe(true); expect(component.preprocessingStepOpen.outlier).toBe(true); }); - it('opens the transformation stage from the collapsed rail without inventing a column', () => { + it('adds a column creator from the collapsed rail in one click', () => { seedAppliedConfig({ categorical_column_creator: [{ new_column_names: ['mrs_good_outcome'], @@ -409,34 +433,28 @@ describe('StatisticAnalysisPanelComponent pipeline presence', () => { (mockExpService.selectedVariables as any).set([age]); fixture.detectChanges(); - const rows = railRows(pipelineCard('analysis-transformation')); - expect(rows.live.map((row) => row.textContent)).toEqual([expect.stringMatching('mrs_good_outcome')]); - // Singleton transformation steps (transforms, scaling) are offered here too, ahead of the derived column. - expect(rows.ghost.map((row) => row.textContent?.trim())).toEqual([ - expect.stringMatching('Add variable transforms'), - expect.stringMatching('Add variable scaling'), - expect.stringMatching('Add derived column'), - ]); + const card = () => pipelineCard('analysis-transformation'); + expect(railRows(card()).live.map((row) => row.textContent)).toEqual([expect.stringMatching('mrs_good_outcome')]); + // Opening the menu is a read: it lists the steps and creates nothing. mockExpService.upsertTransformation.mockClear(); - (rows.ghost[2].querySelector('button') as HTMLButtonElement).click(); + expect(railSteps(card())).toEqual([ + 'variable_transformer', + 'variable_scaler', + 'categorical_column_creator', + 'kmeans_cluster_creator', + ]); + expect(mockExpService.upsertTransformation).not.toHaveBeenCalled(); + expect(component.sectionOpen().transformation).toBe(false); + + // The creators sit in the menu themselves: no second chooser between the rail and the card. + railOption(card(), 'kmeans_cluster_creator')!.click(); fixture.detectChanges(); expect(component.sectionOpen().transformation).toBe(true); - // The dashed row only opens the stage now: the graph holds the stored column, and the - // stage's own blank draft stays off screen until a type is chosen. - const graphCards = () => (fixture.nativeElement as HTMLElement) - .querySelectorAll('[data-guide="analysis-transformation"] .transformation-graph app-station-card'); - const blankCards = () => component.transformationDrafts.filter((draft) => !draft.code.trim() && !draft.rules.length).length; - expect(graphCards().length).toBe(1); - expect(blankCards()).toBe(0); - - component.addTransformationSubNode(); - fixture.detectChanges(); - expect(component.transformationDrafts.length).toBe(1); - expect(graphCards().length).toBe(1); - expect(blankCards()).toBe(0); - expect(mockExpService.upsertTransformation).not.toHaveBeenCalled(); + expect(mockExpService.upsertTransformation).toHaveBeenCalledTimes(1); + expect(component.cards().map((step) => step.name)).toEqual(['categorical_column_creator', 'kmeans_cluster_creator']); + expect(card().querySelectorAll('.transformation-graph app-station-card').length).toBe(2); }); it('lists one sub-node per applied preprocessing step with its summary', () => { @@ -474,15 +492,14 @@ describe('StatisticAnalysisPanelComponent pipeline presence', () => { expect(component.appliedTransformationSubNodes.map((n) => n.id)).toEqual(['transform', 'scaler']); }); - it('offers transform and scaler ghost rows while they hold no strategies', () => { + it('offers transforms and scaling in the transformation menu while they hold no strategies', () => { (mockExpService.selectedVariables as any).set([age]); fixture.detectChanges(); - const texts = railRows(pipelineCard('analysis-transformation')).ghost.map((row) => row.textContent ?? ''); - expect(texts.some((t) => t.includes('Add variable transforms'))).toBe(true); - expect(texts.some((t) => t.includes('Add variable scaling'))).toBe(true); - const preprocessingTexts = railRows(pipelineCard('analysis-preprocessing')).ghost.map((row) => row.textContent ?? ''); - expect(preprocessingTexts.some((t) => t.includes('Add variable transforms'))).toBe(false); + const steps = railSteps(pipelineCard('analysis-transformation')); + expect(steps).toContain('variable_transformer'); + expect(steps).toContain('variable_scaler'); + expect(railSteps(pipelineCard('analysis-preprocessing'))).not.toContain('variable_transformer'); }); describe('catalog steps without a dedicated station', () => { @@ -503,20 +520,37 @@ describe('StatisticAnalysisPanelComponent pipeline presence', () => { (mockExpService.selectedVariables as any).set([age]); }); - it('offers a rail ghost row for each listed step', () => { + it('offers each listed step in the menu of the stage it belongs to', () => { fixture.detectChanges(); // A missing indicator adds a column, so it is a data transformation. - const { ghost } = railRows(pipelineCard('analysis-transformation')); - expect(ghost.some((row) => (row.textContent ?? '').includes('Add Missing Indicator'))).toBe(true); - expect(railRows(pipelineCard('analysis-preprocessing')).ghost.some((row) => (row.textContent ?? '').includes('Add Missing Indicator'))).toBe(false); + const option = railOption(pipelineCard('analysis-transformation'), 'missing_indicator'); + expect(option?.textContent).toContain('Missing Indicator'); + expect(option?.textContent).toContain('Add a column flagging missing values.'); + expect(railSteps(pipelineCard('analysis-preprocessing'))).not.toContain('missing_indicator'); }); - it('offers an add row in the data transformation stage until the step is started', () => { - component.addStep('transformation'); + it('opens the station of a listed step from the rail menu without writing the request', () => { + fixture.detectChanges(); + mockExpService.setAppliedDescriptivePreprocessing.mockClear(); + + railOption(pipelineCard('analysis-transformation'), 'missing_indicator')!.click(); fixture.detectChanges(); - expect(fixture.nativeElement.querySelector('app-generic-data-transformation-step[data-step="missing_indicator"] .btn-add-dashed')).not.toBeNull(); + expect(component.sectionOpen().transformation).toBe(true); + expect(component.genericStepOpen()['missing_indicator']).toBe(true); + expect(fixture.nativeElement.querySelector('app-generic-data-transformation-step[data-step="missing_indicator"] app-station-card')).not.toBeNull(); + expect(mockExpService.setAppliedDescriptivePreprocessing).not.toHaveBeenCalled(); + }); + + it('draws an applied step as a rail node with its own icon and drops it from the menu', () => { + seedAppliedConfig({ missing_indicator: { variables: ['age'], suffix: '_na' } }); + fixture.detectChanges(); + fixture.detectChanges(); + + const node = component.appliedTransformationSubNodes.find((candidate) => candidate.id === 'step:missing_indicator'); + expect(node?.icon).toBe('fas fa-flag'); + expect(railSteps(pipelineCard('analysis-transformation'))).not.toContain('missing_indicator'); }); it('restores an applied step as a rail node and an open-able station', () => { @@ -596,9 +630,9 @@ describe('StatisticAnalysisPanelComponent pipeline presence', () => { expect(component.appliedPreprocessingSubNodes.map((n) => n.id)).toEqual(['missing']); expect(component.appliedTransformationSingletonNodes).toEqual([]); const card = pipelineCard('analysis-transformation'); - const { ghost } = railRows(card); - expect(ghost.some((row) => row.textContent?.includes('Add variable transforms'))).toBe(false); - expect(ghost.some((row) => row.textContent?.includes('Add variable scaling'))).toBe(false); + const steps = railSteps(card); + expect(steps).not.toContain('variable_transformer'); + expect(steps).not.toContain('variable_scaler'); expect(card.textContent).not.toContain('Variable Transforms'); expect(card.textContent).not.toContain('Variable Scaling'); }); @@ -741,9 +775,8 @@ describe('StatisticAnalysisPanelComponent pipeline presence', () => { expect(overview.map((item) => item.textContent)).toEqual([ expect.stringMatching('mrs_good_outcome'), expect.stringMatching('mrs_bad_outcome'), - expect.stringMatching('Add variable transforms'), - expect.stringMatching('Add variable scaling'), - expect.stringMatching('Add derived column'), + // One add row, whatever the number of steps it can add. + expect.stringMatching('Add a transformation step'), ]); }); @@ -805,7 +838,7 @@ describe('StatisticAnalysisPanelComponent pipeline presence', () => { expect(section.querySelector('.pipeline-node-toggle')?.getAttribute('aria-expanded'), guide).toBe('false'); } expect(root.querySelector('[data-guide="analysis-filtering"]')?.textContent).toContain('Add condition'); - expect(root.querySelector('[data-guide="analysis-transformation"]')?.textContent).toContain('Add derived column'); + expect(root.querySelector('[data-guide="analysis-transformation"]')?.textContent).toContain('Add a transformation step'); }); it('opens and folds every step from its title button', () => { @@ -998,36 +1031,6 @@ describe('StatisticAnalysisPanelComponent pipeline presence', () => { expect(component.isStepAdded('transformation')).toBe(true); }); - it('opens a new transformation stage on the type chooser', () => { - component.addStep('transformation'); - fixture.detectChanges(); - - const graphCards = () => (fixture.nativeElement as HTMLElement).querySelectorAll( - '[data-guide="analysis-transformation"] .transformation-graph app-station-card'); - const chooserRows = () => Array.from( - (fixture.nativeElement as HTMLElement).querySelectorAll( - '[data-guide="analysis-transformation"] .transformation-chooser .pipeline-subnode-content') - ) as HTMLButtonElement[]; - - expect(component.transformationChooserOnly).toBe(true); - expect(graphCards().length).toBe(0); - expect(chooserRows().length).toBe(2); - - chooserRows()[0].click(); - fixture.detectChanges(); - - expect(graphCards().length).toBe(1); - expect(component.transformationChooserOnly).toBe(false); - - const kmeansRow = chooserRows().find((row) => row.textContent?.includes('K-means')) as HTMLButtonElement; - kmeansRow.click(); - fixture.detectChanges(); - - expect(graphCards().length).toBe(2); - // Chooser always lists every creator in the specs (repeated cards are allowed). - expect(chooserRows().length).toBe(2); - }); - it('counts pending preprocessing changes in the badge and apply label', () => { const pending = vi.spyOn(component, 'pendingPreprocessingChangeCount', 'get').mockReturnValue(2); const missingPending = vi.spyOn(component, 'pendingMissingChangeCount', 'get').mockReturnValue(2); @@ -1331,4 +1334,111 @@ describe('StatisticAnalysisPanelComponent pipeline presence', () => { expect(config['outlier_winsorizer']).toBeUndefined(); }); }); + + /** + * A stage used to draw one dashed row per step it could still add: nine rows once the whole + * catalog was on offer. The rail now ends in a single add row whose menu holds every step, + * grouped by what the user wants to do. + */ + describe('add-step menu on the collapsed rail', () => { + const step = (name: string, label: string) => ({ + name, + label, + desc: `${label} description.`, + parameters: { + variables: { label: 'Variables', desc: '', types: ['text'], required: true, multiple: true }, + }, + }); + const catalog = [ + step('global_imputer', 'Global Imputer'), + step('global_winsorizer', 'Global Winsorizer'), + step('one_hot_encoder', 'One-Hot Encoder'), + step('ordinal_encoder', 'Ordinal Encoder'), + step('missing_indicator', 'Missing Indicator'), + step('outlier_detector', 'Outlier Detector'), + ]; + + beforeEach(() => { + mockExpService.genericCatalogSteps.mockReturnValue(catalog as never); + mockExpService.catalogStepSpec.mockImplementation(((name: string) => + catalog.find((candidate) => candidate.name === name) ?? null) as never); + (mockExpService.selectedVariables as any).set([age]); + fixture.detectChanges(); + }); + + it('ends each rail in one closed add row, however many steps the stage can add', () => { + for (const [stage, label] of [ + ['analysis-preprocessing', 'Add a preprocessing step'], + ['analysis-transformation', 'Add a transformation step'], + ] as const) { + const card = pipelineCard(stage); + expect(railRows(card).ghost.length, stage).toBe(1); + expect(railRows(card).ghost[0].querySelector('.pipeline-subnode-dot'), stage).not.toBeNull(); + expect(railTrigger(card)?.textContent, stage).toContain(label); + expect(railTrigger(card)?.getAttribute('aria-expanded'), stage).toBe('false'); + expect(card.querySelectorAll('.step-picker-option').length, stage).toBe(0); + } + // Missing values is the only live row; the steps to add are inside the menu. + expect(railRows(pipelineCard('analysis-preprocessing')).live.length).toBe(1); + expect(railRows(pipelineCard('analysis-transformation')).live.length).toBe(0); + }); + + it('says what kind of steps each menu holds', () => { + expect(railTrigger(pipelineCard('analysis-preprocessing'))?.textContent) + .toContain('Fill or cap values. Every variable keeps its meaning.'); + expect(railTrigger(pipelineCard('analysis-transformation'))?.textContent) + .toContain('Reshape values, encode categories, flag records or create columns.'); + }); + + it('groups the preprocessing steps by purpose', () => { + const card = pipelineCard('analysis-preprocessing'); + railOptions(card); + const groups = Array.from(card.querySelectorAll('.step-picker-group')) as HTMLElement[]; + + expect(groups.map((group) => group.dataset['group'])).toEqual(['missing', 'outliers']); + expect(groups.map((group) => Array.from(group.querySelectorAll('.step-picker-option')).map((option) => (option as HTMLElement).dataset['step']))) + .toEqual([['global_imputer'], ['outlier_winsorizer', 'global_winsorizer']]); + }); + + it('groups the transformation steps by purpose, column creators last', () => { + const card = pipelineCard('analysis-transformation'); + railOptions(card); + const groups = Array.from(card.querySelectorAll('.step-picker-group')) as HTMLElement[]; + + expect(groups.map((group) => group.dataset['group'])).toEqual(['reshape', 'encode', 'flag', 'create']); + expect(groups.map((group) => Array.from(group.querySelectorAll('.step-picker-option')).map((option) => (option as HTMLElement).dataset['step']))) + .toEqual([ + ['variable_transformer', 'variable_scaler'], + ['one_hot_encoder', 'ordinal_encoder'], + ['missing_indicator', 'outlier_detector'], + ['categorical_column_creator', 'kmeans_cluster_creator'], + ]); + }); + + it('shows a creator with the name and icon of the card it adds', () => { + const option = railOption(pipelineCard('analysis-transformation'), 'kmeans_cluster_creator')!; + + expect(option.querySelector('.step-picker-option-title')?.textContent?.trim()).toBe('K-means cluster column'); + expect(option.querySelector('i')?.className).toContain('fa-diagram-project'); + }); + + it('offers the longitudinal comparison only for a longitudinal data model', () => { + expect(railSteps(pipelineCard('analysis-transformation'))).not.toContain('longitudinal_transformer'); + + (mockExpService.selectedDataModel as any).set({ code: 'Stroke', version: '3.7', variables: [], longitudinal: true }); + fixture.detectChanges(); + + const card = pipelineCard('analysis-transformation'); + expect(railSteps(card)).toContain('longitudinal_transformer'); + expect((card.querySelector('.step-picker-group[data-group="visits"]') as HTMLElement | null)?.textContent) + .toContain('Longitudinal Transformation'); + }); + + it('keeps the rail caption free of the old dashed-row wording', () => { + const caption = pipelineCard('analysis-preprocessing').querySelector('.pipeline-subnodes-caption')?.textContent ?? ''; + + expect(caption).toContain('These steps run in this order'); + expect(caption).not.toContain('dashed'); + }); + }); }); diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.stage-picker.spec.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.stage-picker.spec.ts new file mode 100644 index 000000000..0ea3fcdf5 --- /dev/null +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.stage-picker.spec.ts @@ -0,0 +1,408 @@ +import type { MockedObject } from 'vitest'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { of } from 'rxjs'; +import { provideZonelessChangeDetection, signal } from '@angular/core'; +import { provideEchartsCore } from 'ngx-echarts'; +import { StatisticAnalysisPanelComponent } from './statistic-analysis-panel.component'; +import { ExperimentStudioService } from '../../../services/experiment-studio.service'; +import { ExperimentsDashboardService } from '../../../services/experiments-dashboard.service'; +import { ChartBuilderService } from '../visualisations/charts/chart-builder.service'; +import { PdfExportService } from '../../../services/pdf-export.service'; +import { createSpyObj } from '../../../testing/spy-obj.testing'; + +/** + * Contract: an opened stage draws the stations of the steps that are applied or were opened + * this visit, and nothing else. Every step it could still add sits behind one add row at the + * end of the stage, the same add-step menu the collapsed rail ends in. No dashed "Add ..." + * button per step, and no separate chooser for the column creators. + */ +describe('StatisticAnalysisPanelComponent add-step menu in an opened stage', () => { + let component: StatisticAnalysisPanelComponent; + let fixture: ComponentFixture; + let mockExpService: MockedObject; + + const age = { code: 'age', label: 'Age', type: 'real' }; + + /** Round-trips the applied config the way the real service does. */ + function seedAppliedConfig(config: Record | null): void { + (mockExpService.appliedPreprocessingConfig as any).set(config); + mockExpService.getAppliedDescriptivePreprocessing.mockReturnValue(config as never); + // Mirror creators into the ordered store when the seed carries them. Singleton-only + // writes (Apply preprocessing) must not wipe transformation steps already in the store. + const hasCreators = !!config && ( + 'categorical_column_creator' in config + || 'kmeans_cluster_creator' in config + || 'pca_column_creator' in config + ); + if (!hasCreators) return; + const steps: { id: string; name: string; parameters: Record }[] = []; + const categorical = config?.['categorical_column_creator']; + for (const parameters of Array.isArray(categorical) ? categorical : categorical ? [categorical] : []) { + steps.push({ id: crypto.randomUUID(), name: 'categorical_column_creator', parameters: parameters as Record }); + } + const kmeans = config?.['kmeans_cluster_creator']; + if (kmeans && typeof kmeans === 'object') { + steps.push({ id: 'kmeans-seed', name: 'kmeans_cluster_creator', parameters: kmeans as Record }); + } + const pca = config?.['pca_column_creator']; + if (pca && typeof pca === 'object') { + steps.push({ id: crypto.randomUUID(), name: 'pca_column_creator', parameters: pca as Record }); + } + (mockExpService.appliedTransformations as any).set(steps); + } + + /** A stage card of the pipeline canvas, as rendered. */ + function pipelineCard(stage: 'analysis-preprocessing' | 'analysis-transformation'): HTMLElement { + return (fixture.nativeElement as HTMLElement).querySelector(`[data-guide="${stage}"]`) as HTMLElement; + } + + /** + * The add-step menu of a stage: the rail's while the stage is collapsed, the stage's own once + * the stage is open. + */ + function menuTrigger(card: HTMLElement, where: 'rail' | 'stage'): HTMLButtonElement | null { + const scope = where === 'rail' ? '.pipeline-subnodes-tree' : '.pipeline-node-body'; + return card.querySelector(`${scope} app-step-picker .step-picker-trigger`); + } + + /** The steps a menu offers. Opens the menu first when it is closed. */ + function menuOptions(card: HTMLElement, where: 'rail' | 'stage'): HTMLButtonElement[] { + const trigger = menuTrigger(card, where); + if (!trigger) return []; + if (trigger.getAttribute('aria-expanded') !== 'true') { + trigger.click(); + fixture.detectChanges(); + } + const scope = where === 'rail' ? '.pipeline-subnodes-tree' : '.pipeline-node-body'; + return Array.from(card.querySelectorAll(`${scope} app-step-picker .step-picker-option`)) as HTMLButtonElement[]; + } + + /** Engine names of the steps a menu offers, in menu order. */ + function menuSteps(card: HTMLElement, where: 'rail' | 'stage'): (string | undefined)[] { + return menuOptions(card, where).map((option) => option.dataset['step']); + } + + function pick(card: HTMLElement, where: 'rail' | 'stage', step: string): void { + const option = menuOptions(card, where).find((candidate) => candidate.dataset['step'] === step); + expect(option, `menu option ${step}`).toBeTruthy(); + option!.click(); + fixture.detectChanges(); + } + + /** Titles of the stations an opened stage draws, top to bottom. */ + function stationTitles(card: HTMLElement): string[] { + return Array.from(card.querySelectorAll('.preprocessing-shell .station-card-title')) + .map((title) => title.textContent?.trim() ?? ''); + } + + beforeEach(async () => { + mockExpService = createSpyObj('ExperimentStudioService', [ + 'loadDescriptiveOverview', + 'loadOutlierReportPreview', + 'getAlgorithmResults', + 'getDatasetLabelMap', + 'setDataExclusionWarnings', + 'clearDataExclusionWarnings', + 'setAppliedDescriptivePreprocessing', + 'getAppliedDescriptivePreprocessing', + 'setFilters', + 'setFilterLogic', + 'filterVariableCodes', + 'buildTransformationDescribePreprocessing', + 'transformationSourceCodesForInput', + 'requestDatasets', + 'requestFilters', + 'getActiveDataModelCode', + 'upsertTransformation', + 'removeTransformation', + 'clearTransformations', + 'transformationDependents', + 'outputsInUse', + 'availableCreatorNames', + 'hasPreprocessingSpec', + 'catalogLoaded', + 'genericCatalogSteps', + 'genericStepDroppedCodes', + 'catalogStepSpec', + ], { + selectedVariables: signal([]), + selectedFilters: signal([]), + selectedDatasets: signal(['dataset-a']), + selectedDataModel: signal({ code: 'Stroke', version: '3.7', variables: [] }), + unavailableVariables: signal(new Map()), + filterLogic: signal(null), + editingExistingExperiment: () => false, + appliedPreprocessingConfig: signal | null>(null), + appliedTransformations: signal([] as { id: string; name: string; parameters: Record }[]), + backendAlgorithms: signal({}) + }); + mockExpService.loadDescriptiveOverview.mockReturnValue(of({ result: { featurewise: [] } })); + mockExpService.loadOutlierReportPreview.mockReturnValue(of({ result: { featurewise: [] } })); + mockExpService.getAlgorithmResults.mockReturnValue(of({ result: { histogram: [] } })); + mockExpService.getAppliedDescriptivePreprocessing.mockReturnValue(null); + mockExpService.getDatasetLabelMap.mockReturnValue({ 'dataset-a': 'Dataset A' }); + mockExpService.availableCreatorNames.mockReturnValue([ + 'categorical_column_creator', + 'kmeans_cluster_creator', + ]); + mockExpService.hasPreprocessingSpec.mockImplementation((name: string) => + ['categorical_column_creator', 'kmeans_cluster_creator', 'variable_transformer', 'variable_scaler'].includes(name), + ); + mockExpService.catalogLoaded.mockReturnValue(true); + mockExpService.genericCatalogSteps.mockReturnValue([]); + mockExpService.genericStepDroppedCodes.mockReturnValue([]); + mockExpService.catalogStepSpec.mockReturnValue(null); + mockExpService.transformationDependents.mockReturnValue([]); + mockExpService.outputsInUse.mockReturnValue([]); + mockExpService.upsertTransformation.mockImplementation((step: any) => { + const current = [...(mockExpService.appliedTransformations() as any[])]; + const index = current.findIndex((existing) => existing.id === step.id); + const next = index === -1 + ? [...current, step] + : current.map((existing, i) => (i === index ? step : existing)); + (mockExpService.appliedTransformations as any).set(next); + return true; + }); + mockExpService.clearTransformations.mockImplementation(() => + (mockExpService.appliedTransformations as any).set([])); + mockExpService.removeTransformation.mockImplementation((id: string) => { + (mockExpService.appliedTransformations as any).set( + (mockExpService.appliedTransformations() as any[]).filter((step) => step.id !== id), + ); + }); + mockExpService.requestDatasets.mockReturnValue(['dataset-a']); + mockExpService.requestFilters.mockReturnValue(null); + mockExpService.getActiveDataModelCode.mockReturnValue('Stroke:3.7'); + mockExpService.buildTransformationDescribePreprocessing.mockImplementation((singletons: any) => { + const steps: { name: string; parameters: Record }[] = []; + if (singletons && typeof singletons === 'object') { + for (const [name, parameters] of Object.entries(singletons)) { + if (parameters && typeof parameters === 'object') { + steps.push({ name, parameters: parameters as Record }); + } + } + } + for (const step of mockExpService.appliedTransformations() as any[]) { + if (Array.isArray(step.parameters?.new_column_names) + && step.parameters.new_column_names.some((n: unknown) => String(n ?? '').trim())) { + steps.push({ name: step.name, parameters: step.parameters }); + } + } + return steps.length ? steps : null; + }); + mockExpService.transformationSourceCodesForInput.mockReturnValue([]); + // Mirrors the real collector: a group walks its rules, a condition is its field. + mockExpService.filterVariableCodes.mockImplementation((logic: any) => { + const codes = new Set(); + const walk = (node: any) => { + if (!node) return; + if (Array.isArray(node.rules)) { + node.rules.forEach(walk); + } else if (node.field || node.id) { + codes.add(String(node.field ?? node.id)); + } + }; + walk(logic); + return [...codes]; + }); + mockExpService.setAppliedDescriptivePreprocessing.mockImplementation((config: unknown) => + seedAppliedConfig(config as Record | null)); + + await TestBed.configureTestingModule({ + imports: [StatisticAnalysisPanelComponent], + providers: [ + provideZonelessChangeDetection(), + provideEchartsCore({ echarts: () => import('echarts') }), + { provide: ExperimentStudioService, useValue: mockExpService }, + { provide: ExperimentsDashboardService, useValue: { listKMeansExperiments: () => of([]), listPcaExperiments: () => of([]) } }, + { provide: ChartBuilderService, useValue: (() => { const s = createSpyObj('ChartBuilderService', ['getChartsForAlgorithm']); s.getChartsForAlgorithm.mockReturnValue([]); return s; })() }, + { provide: PdfExportService, useValue: createSpyObj('PdfExportService', ['exportDescriptiveStatisticsPdf']) } + ] + }).compileComponents(); + + fixture = TestBed.createComponent(StatisticAnalysisPanelComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + describe('data transformation', () => { + const card = () => pipelineCard('analysis-transformation'); + const graphCards = () => card().querySelectorAll('.transformation-graph app-station-card'); + const creators = () => menuSteps(card(), 'stage').filter((step) => step?.endsWith('_creator')); + + beforeEach(() => { + (mockExpService.selectedVariables as any).set([age]); + fixture.detectChanges(); + }); + + it('opens an empty stage on its unfolded menu, column creators included', () => { + component.addStep('transformation'); + fixture.detectChanges(); + + // Nothing to show yet, so the stage asks instead of making the user hunt for the row. + expect(component.transformationChooserOnly).toBe(true); + expect(component.transformationPickerOpen).toBe(true); + expect(menuTrigger(card(), 'stage')?.getAttribute('aria-expanded')).toBe('true'); + expect(menuTrigger(card(), 'stage')?.textContent).toContain('Add a transformation step'); + expect(graphCards().length).toBe(0); + expect(creators()).toEqual(['categorical_column_creator', 'kmeans_cluster_creator']); + + pick(card(), 'stage', 'categorical_column_creator'); + + expect(graphCards().length).toBe(1); + expect(component.transformationChooserOnly).toBe(false); + // The stage has a card to show now, so the menu folds back into its add row. + expect(component.transformationPickerOpen).toBe(false); + expect(menuTrigger(card(), 'stage')?.getAttribute('aria-expanded')).toBe('false'); + + pick(card(), 'stage', 'kmeans_cluster_creator'); + + expect(graphCards().length).toBe(2); + // Every creator stays on offer: a stage may hold several columns of one kind. + expect(creators()).toEqual(['categorical_column_creator', 'kmeans_cluster_creator']); + }); + + it('has no separate chooser for the column creators', () => { + component.addStep('transformation'); + fixture.detectChanges(); + + expect(card().querySelector('.transformation-chooser')).toBeNull(); + expect(card().querySelectorAll('.pipeline-node-body app-step-picker').length).toBe(1); + }); + + it('opens the Variable Transforms station from the menu before anything is applied', () => { + mockExpService.setAppliedDescriptivePreprocessing.mockClear(); + + pick(card(), 'rail', 'variable_transformer'); + + expect(component.sectionOpen().transformation).toBe(true); + expect(component.transformStationShown).toBe(true); + expect(component.scalerStationShown).toBe(false); + expect(stationTitles(card())).toEqual(['Variable Transforms']); + expect(card().querySelector('.preprocessing-shell .station-card')?.classList.contains('is-open')).toBe(true); + // Opening a station is a read: the request is untouched until Apply. + expect(mockExpService.setAppliedDescriptivePreprocessing).not.toHaveBeenCalled(); + }); + + it('keeps the menu folded when the stage opens on a station', () => { + pick(card(), 'rail', 'variable_transformer'); + + expect(component.transformationPickerOpen).toBe(false); + expect(menuTrigger(card(), 'stage')?.getAttribute('aria-expanded')).toBe('false'); + expect(card().querySelectorAll('.pipeline-node-body .step-picker-option').length).toBe(0); + }); + + it('leaves a step out of the stage menu while its station is on screen', () => { + pick(card(), 'rail', 'variable_transformer'); + + const steps = menuSteps(card(), 'stage'); + expect(steps).not.toContain('variable_transformer'); + expect(steps).toContain('variable_scaler'); + }); + + it('adds Variable Scaling from the stage menu and opens only that station', () => { + pick(card(), 'rail', 'variable_transformer'); + pick(card(), 'stage', 'variable_scaler'); + + expect(stationTitles(card())).toEqual(['Variable Transforms', 'Variable Scaling']); + expect(component.preprocessingStepOpen.scaler).toBe(true); + expect(component.preprocessingStepOpen.transform).toBe(false); + expect(menuSteps(card(), 'stage')).toEqual(['categorical_column_creator', 'kmeans_cluster_creator']); + }); + + it('hands an untouched station back to the menu when its step is removed', () => { + pick(card(), 'rail', 'variable_transformer'); + + component.removePreprocessingSubNode('transform'); + fixture.detectChanges(); + + expect(component.transformStationShown).toBe(false); + expect(stationTitles(card())).toEqual([]); + expect(menuSteps(card(), 'stage')).toContain('variable_transformer'); + }); + + it('keeps the menu folded when the stage already holds an applied step', () => { + seedAppliedConfig({ variable_scaler: { strategies: { age: 'standard' } } }); + fixture.detectChanges(); + + component.addStep('transformation'); + fixture.detectChanges(); + + expect(stationTitles(card())).toEqual(['Variable Scaling']); + expect(component.transformationPickerOpen).toBe(false); + expect(menuTrigger(card(), 'stage')?.getAttribute('aria-expanded')).toBe('false'); + expect(menuSteps(card(), 'stage')).not.toContain('variable_scaler'); + }); + + it('lists a catalog step in the stage menu until its station is on screen', () => { + const indicator = { + name: 'missing_indicator', + label: 'Missing Indicator', + desc: 'Add a column flagging missing values.', + parameters: { + variables: { label: 'Variables', desc: '', types: ['text'], required: true, multiple: true }, + suffix: { label: 'Column suffix', desc: '', types: ['text'], required: false, default: '_missing' }, + }, + }; + mockExpService.genericCatalogSteps.mockReturnValue([indicator] as never); + mockExpService.catalogStepSpec.mockImplementation(((name: string) => + name === 'missing_indicator' ? indicator : null) as never); + component.addStep('transformation'); + fixture.detectChanges(); + + const station = () => card().querySelector('app-generic-data-transformation-step[data-step="missing_indicator"] app-station-card'); + expect(station()).toBeNull(); + expect(menuSteps(card(), 'stage')).toContain('missing_indicator'); + + pick(card(), 'stage', 'missing_indicator'); + + expect(station()).not.toBeNull(); + expect(component.genericStepOpen()['missing_indicator']).toBe(true); + expect(menuSteps(card(), 'stage')).not.toContain('missing_indicator'); + }); + }); + + describe('preprocessing', () => { + const card = () => pipelineCard('analysis-preprocessing'); + + beforeEach(() => { + (mockExpService.selectedVariables as any).set([age]); + fixture.detectChanges(); + component.addStep('setup'); + fixture.detectChanges(); + }); + + it('ends the opened stage in a folded menu: Missing Values is always there to show', () => { + expect(stationTitles(card())).toEqual(['Missing Values']); + expect(menuTrigger(card(), 'stage')?.getAttribute('aria-expanded')).toBe('false'); + expect(menuTrigger(card(), 'stage')?.textContent).toContain('Add a preprocessing step'); + expect(menuSteps(card(), 'stage')).toEqual(['outlier_winsorizer']); + }); + + it('adds Outlier Handling from the stage menu without writing the request', () => { + mockExpService.setAppliedDescriptivePreprocessing.mockClear(); + + pick(card(), 'stage', 'outlier_winsorizer'); + + expect(component.userEnabledOutliers()).toBe(true); + expect(stationTitles(card())).toEqual(['Missing Values', 'Outlier Handling']); + expect(component.preprocessingStepOpen.outlier).toBe(true); + expect(component.preprocessingStepOpen.missing).toBe(false); + expect(mockExpService.setAppliedDescriptivePreprocessing).not.toHaveBeenCalled(); + // Nothing is left to add, so the add row is gone too. + expect(menuTrigger(card(), 'stage')).toBeNull(); + }); + }); + + it('draws no dashed add button in an opened stage', () => { + (mockExpService.selectedVariables as any).set([age]); + fixture.detectChanges(); + component.addStep('setup'); + component.addStep('transformation'); + fixture.detectChanges(); + + for (const stage of ['analysis-preprocessing', 'analysis-transformation'] as const) { + expect(pipelineCard(stage).querySelectorAll('.pipeline-node-body .btn-add-dashed').length, stage).toBe(0); + } + }); +}); From 6960605b0f329e66f035bf9a53d3e2ff1c80e257 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 10:23:26 +0200 Subject: [PATCH 04/22] contracts: 2026-11-11_summary-preview-triage-ux # Conflicts: # src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts --- src/app/core/summary-rail.utils.spec.ts | 76 +++++++ src/app/core/summary-rail.utils.ts | 60 ++++++ .../statistic-analysis-panel.component.ts | 46 +++++ .../statistic-analysis-panel.results.css | 12 ++ ...tistic-analysis-panel.summary-rail.spec.ts | 193 ++++++++++++++++++ ...istic-analysis-panel.summary-table.spec.ts | 82 ++++++++ .../summary-workspace.testing.ts | 119 +++++++++++ src/styles.css | 69 +++++++ 8 files changed, 657 insertions(+) create mode 100644 src/app/core/summary-rail.utils.spec.ts create mode 100644 src/app/core/summary-rail.utils.ts create mode 100644 src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.summary-rail.spec.ts create mode 100644 src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.summary-table.spec.ts create mode 100644 src/app/pages/experiment-studio/statistic-analysis-panel/summary-workspace.testing.ts diff --git a/src/app/core/summary-rail.utils.spec.ts b/src/app/core/summary-rail.utils.spec.ts new file mode 100644 index 000000000..df80d6e90 --- /dev/null +++ b/src/app/core/summary-rail.utils.spec.ts @@ -0,0 +1,76 @@ +import { orderByMissing, railCountLabel, railStep, visibleSummaryColumns } from './summary-rail.utils'; + +describe('summary rail utils', () => { + describe('railCountLabel', () => { + it('names the count when nothing is hidden', () => { + expect(railCountLabel(3, 3)).toBe('3 variables'); + expect(railCountLabel(1, 1)).toBe('1 variable'); + }); + + it('says how many of the total the search leaves', () => { + expect(railCountLabel(2, 5)).toBe('2 of 5 variables'); + expect(railCountLabel(1, 4)).toBe('1 of 4 variables'); + expect(railCountLabel(0, 5)).toBe('0 of 5 variables'); + }); + }); + + describe('orderByMissing', () => { + const shares: Record = { a: 0.1, b: 0.5, c: null, d: 0.5, e: 0 }; + const shareOf = (item: string) => shares[item]; + + it('puts the largest share first, keeps ties in place and unpriced items last', () => { + expect(orderByMissing(['a', 'b', 'c', 'd', 'e'], shareOf)).toEqual(['b', 'd', 'a', 'e', 'c']); + }); + + it('returns a new array and leaves the input alone', () => { + const input = ['a', 'b']; + const output = orderByMissing(input, shareOf); + expect(output).toEqual(['b', 'a']); + expect(input).toEqual(['a', 'b']); + expect(output).not.toBe(input); + }); + }); + + describe('railStep', () => { + it('moves one row and stops at the ends', () => { + expect(railStep('ArrowDown', 0, 3)).toBe(1); + expect(railStep('ArrowDown', 2, 3)).toBe(2); + expect(railStep('ArrowUp', 2, 3)).toBe(1); + expect(railStep('ArrowUp', 0, 3)).toBe(0); + }); + + it('jumps to the first and last row', () => { + expect(railStep('Home', 2, 3)).toBe(0); + expect(railStep('End', 0, 3)).toBe(2); + }); + + it('starts at the first row when nothing is selected', () => { + expect(railStep('ArrowDown', -1, 3)).toBe(0); + expect(railStep('ArrowUp', -1, 3)).toBe(0); + }); + + it('ignores other keys and an empty rail', () => { + expect(railStep('Enter', 0, 3)).toBeNull(); + expect(railStep('a', 0, 3)).toBeNull(); + expect(railStep('ArrowDown', 0, 0)).toBeNull(); + }); + }); + + describe('visibleSummaryColumns', () => { + const isRollup = (column: string) => column === 'all'; + + it('drops the pooled column beside a single dataset', () => { + expect(visibleSummaryColumns(['a', 'all'], isRollup)).toEqual(['a']); + expect(visibleSummaryColumns(['all', 'a'], isRollup)).toEqual(['a']); + }); + + it('keeps the pooled column beside two or more datasets', () => { + expect(visibleSummaryColumns(['a', 'b', 'all'], isRollup)).toEqual(['a', 'b', 'all']); + }); + + it('keeps the pooled column when it is the only one', () => { + expect(visibleSummaryColumns(['all'], isRollup)).toEqual(['all']); + expect(visibleSummaryColumns([], isRollup)).toEqual([]); + }); + }); +}); diff --git a/src/app/core/summary-rail.utils.ts b/src/app/core/summary-rail.utils.ts new file mode 100644 index 000000000..0588be5ac --- /dev/null +++ b/src/app/core/summary-rail.utils.ts @@ -0,0 +1,60 @@ +/** + * Pure helpers for the shared data summary (the variable rail and the statistics table that + * every Data Handling stage previews its records with). No Angular, no DOM. + */ + +/** Rail order: the order the variables were selected in, or most missing first. */ +export type RailOrder = 'selection' | 'missing'; + +/** + * Header text of the rail. `shown` is the number of variables the search leaves, `total` the + * number in the summary. + * - shown === total: "1 variable", "3 variables" + * - otherwise: "2 of 5 variables", "1 of 4 variables", "0 of 5 variables" + */ +export function railCountLabel(shown: number, total: number): string { + void shown; + void total; + throw new Error('not implemented'); +} + +/** + * A new array ordered by missing share, largest first. `shareOf` returns the share (0..1) or + * null when the item has no statistics; null items go last. Items with the same share keep + * their original order. The input array is not changed. + */ +export function orderByMissing(items: readonly T[], shareOf: (item: T) => number | null): T[] { + void items; + void shareOf; + throw new Error('not implemented'); +} + +/** + * Where a key press moves the rail selection. `index` is the selected row (-1 when none), + * `count` the number of rows. Returns the new index, or null when the key is not a rail key + * or the rail is empty. + * - ArrowDown: index + 1, stops at the last row (no wrap) + * - ArrowUp: index - 1, stops at the first row (no wrap) + * - Home: 0, End: count - 1 + */ +export function railStep(key: string, index: number, count: number): number | null { + void key; + void index; + void count; + throw new Error('not implemented'); +} + +/** + * Columns the statistics table draws. The pooled "all datasets" column repeats the only + * dataset column when a single dataset is selected, so it is dropped then. It stays when two + * or more dataset columns sit beside it, and when it is the only column there is. + * Order is preserved. + */ +export function visibleSummaryColumns( + columns: readonly string[], + isRollup: (column: string) => boolean, +): string[] { + void columns; + void isRollup; + throw new Error('not implemented'); +} diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts index 1b805970e..ca2da17e7 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts @@ -96,6 +96,7 @@ import { } from '../../../core/data-transformation-step-form.utils'; import { GenericDataTransformationStepComponent } from './generic-data-transformation-step/generic-data-transformation-step.component'; import { StepPickerGroup } from '../../../core/step-picker.utils'; +import { RailOrder } from '../../../core/summary-rail.utils'; type TabKey = 'Statistics' | 'Charts' | 'Histogram'; type SummaryKind = 'source' | 'raw' | 'processed'; @@ -413,6 +414,12 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { raw: '', processed: '', }; + /** Rail order per summary surface; the "Missing" column header of the rail toggles it. */ + statisticsSort: Record = { + source: 'selection', + raw: 'selection', + processed: 'selection', + }; isExporting = false; isLoading = true; readonly sectionOpen = signal>({ @@ -2092,6 +2099,45 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { return !!selected && this.statisticBlockKey(selected) === this.statisticBlockKey(block); } + // ---- Summary rail and table (helpers in core/summary-rail.utils.ts) + + /** Rail header text: "4 variables", or "1 of 4 variables" while the search hides some. */ + statisticsCountLabel(kind: SummaryKind): string { + void kind; + throw new Error('not implemented'); + } + + /** Switches the rail between selection order and most missing first. */ + toggleStatisticsSort(kind: SummaryKind): void { + void kind; + throw new Error('not implemented'); + } + + /** Empties the rail search of one surface. */ + clearStatisticsSearch(kind: SummaryKind): void { + void kind; + throw new Error('not implemented'); + } + + /** Rail rows in the order they are drawn: the numerical group, then the categorical group. */ + railBlocks(kind: SummaryKind): PivotBlock[] { + void kind; + throw new Error('not implemented'); + } + + /** Arrow keys, Home and End walk the rail: select the row and move focus to it. */ + onStatisticRailKeydown(kind: SummaryKind, event: KeyboardEvent): void { + void kind; + void event; + throw new Error('not implemented'); + } + + /** Columns the statistics table draws for a block (no pooled column beside a single dataset). */ + summaryColumns(block: PivotBlock): string[] { + void block; + throw new Error('not implemented'); + } + statisticBlockVariable(block: PivotBlock): VariableRow | null { return this.variableForBlock(block); } diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.results.css b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.results.css index 7b30d8662..a88290ec3 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.results.css +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.results.css @@ -250,6 +250,18 @@ button:disabled { border-radius: 0; } +/* Sized to its content. Stretched over the whole pane, a one-dataset table put + each value about 600px from its label. --summary-cols is the number of value + columns the template draws; without it (other tables that share this + wrapper) both rules fall back to the old full-width, 620px-minimum layout. */ +.statistics-table-wrapper { + max-width: min(100%, calc(240px + var(--summary-cols, 99) * 220px)); +} + +.statistics-table-wrapper .statistics-table { + min-width: min(620px, calc(200px + var(--summary-cols, 3) * 140px)); +} + /* Explicit tints, not --studio-card-header-bg: the studio sets that token to white, which flattened the header and section rows into the body. */ .statistics-table-wrapper .statistics-table th { diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.summary-rail.spec.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.summary-rail.spec.ts new file mode 100644 index 000000000..63e8ec711 --- /dev/null +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.summary-rail.spec.ts @@ -0,0 +1,193 @@ +import { SummaryPanelHarness, createSummaryPanel } from './summary-workspace.testing'; + +/** + * Contract: the variable rail of the shared data summary is a triage tool. It says how many + * variables it lists, sorts them by missing share on request, can be walked with the arrow + * keys, and a search that matches nothing never removes the search field. + */ +describe('StatisticAnalysisPanelComponent summary rail', () => { + let harness: SummaryPanelHarness; + + const variables = [ + { code: 'age', label: 'Age', type: 'real' }, + { code: 'bmi', label: 'BMI', type: 'real' }, + { code: 'mmse', label: 'MMSE', type: 'real' }, + { code: 'sex', label: 'Sex', type: 'nominal' }, + ]; + + // Missing share: Age 0%, BMI 60%, MMSE 20%, Sex 10%. + const featurewise = ['all datasets', 'dataset-a'].flatMap((dataset) => [ + { dataset, variable: 'age', data: { num_dtps: 10, num_na: 0, num_total: 10, mean: 71 } }, + { dataset, variable: 'bmi', data: { num_dtps: 4, num_na: 6, num_total: 10, mean: 24 } }, + { dataset, variable: 'mmse', data: { num_dtps: 8, num_na: 2, num_total: 10, mean: 27 } }, + { dataset, variable: 'sex', data: { counts: { female: 5, male: 4 }, num_dtps: 9, num_na: 1, num_total: 10 } }, + ]); + + const rail = () => harness.workspace().querySelector('.statistics-browser') as HTMLElement; + const rows = () => Array.from(rail().querySelectorAll('.statistics-variable-btn')) as HTMLButtonElement[]; + const names = () => rows().map((row) => (row.querySelector('span')?.textContent ?? '').trim()); + const row = (name: string) => rows()[names().indexOf(name)]; + const heading = () => (harness.workspace().querySelector('.summary-detail-toolbar h4')?.textContent ?? '').trim(); + const searchInput = () => rail().querySelector('input[type="search"]') as HTMLInputElement; + + function search(text: string): void { + const input = searchInput(); + input.value = text; + input.dispatchEvent(new Event('input', { bubbles: true })); + harness.fixture.detectChanges(); + } + + function press(target: HTMLElement, key: string): KeyboardEvent { + const event = new KeyboardEvent('keydown', { key, bubbles: true, cancelable: true }); + target.dispatchEvent(event); + harness.fixture.detectChanges(); + return event; + } + + beforeEach(async () => { + harness = await createSummaryPanel({ featurewise, variables }); + }); + + it('renders the fixture: numerical rows, then categorical rows', () => { + expect(names()).toEqual(['Age', 'BMI', 'MMSE', 'Sex']); + expect(heading()).toContain('Age'); + }); + + describe('header', () => { + it('says how many variables the rail lists', () => { + const header = rail().querySelector('.statistics-browser-header') as HTMLElement; + expect(header.textContent).toContain('4 variables'); + expect(header.textContent).not.toContain('shown'); + }); + + it('says how many of the total a search leaves', () => { + search('mm'); + expect(names()).toEqual(['MMSE']); + expect(rail().querySelector('.statistics-browser-header')?.textContent).toContain('1 of 4 variables'); + }); + }); + + describe('search that matches nothing', () => { + it('keeps the search field on screen and names the search text', () => { + const input = searchInput(); + search('zzz'); + + expect(rows().length).toBe(0); + expect(input.isConnected).toBe(true); + expect(searchInput()).toBe(input); + expect(rail().querySelector('.statistics-browser-header')?.textContent).toContain('0 of 4 variables'); + const noMatch = harness.workspace().querySelector('.statistics-no-match') as HTMLElement; + expect(noMatch).toBeTruthy(); + expect(noMatch.textContent).toContain('No variable matches'); + expect(noMatch.textContent).toContain('zzz'); + }); + + it('offers one button that clears the search and brings every variable back', () => { + search('zzz'); + const clear = harness.workspace().querySelector('.statistics-no-match .statistics-search-clear') as HTMLButtonElement; + expect(clear).toBeTruthy(); + expect(clear.textContent).toContain('Clear search'); + + clear.click(); + harness.fixture.detectChanges(); + + expect(harness.component.statisticsSearch['source']).toBe(''); + expect(names()).toEqual(['Age', 'BMI', 'MMSE', 'Sex']); + expect(harness.workspace().querySelector('.statistics-no-match')).toBeNull(); + }); + }); + + describe('order by missing values', () => { + const sortButton = () => rail().querySelector('.statistics-browser-header .statistics-sort-btn') as HTMLButtonElement; + + it('starts in selection order with the sort button not pressed', () => { + expect(sortButton()).toBeTruthy(); + expect(sortButton().textContent).toContain('Missing'); + expect(sortButton().getAttribute('aria-pressed')).toBe('false'); + }); + + it('puts the most missing variable first inside each group, and toggles back', () => { + sortButton().click(); + harness.fixture.detectChanges(); + + expect(sortButton().getAttribute('aria-pressed')).toBe('true'); + expect(names()).toEqual(['BMI', 'MMSE', 'Age', 'Sex']); + + sortButton().click(); + harness.fixture.detectChanges(); + + expect(sortButton().getAttribute('aria-pressed')).toBe('false'); + expect(names()).toEqual(['Age', 'BMI', 'MMSE', 'Sex']); + }); + + it('keeps the selected variable selected when the order changes', () => { + row('MMSE').click(); + harness.fixture.detectChanges(); + sortButton().click(); + harness.fixture.detectChanges(); + + expect(heading()).toContain('MMSE'); + expect(row('MMSE').classList.contains('active')).toBe(true); + }); + }); + + describe('keyboard', () => { + it('marks the selected row for assistive technology', () => { + expect(row('Age').getAttribute('aria-current')).toBe('true'); + expect(row('BMI').getAttribute('aria-current')).toBeNull(); + }); + + it('ArrowDown selects the next row, shows it and moves focus to it', () => { + row('Age').focus(); + const event = press(row('Age'), 'ArrowDown'); + + expect(event.defaultPrevented).toBe(true); + expect(heading()).toContain('BMI'); + expect(row('BMI').classList.contains('active')).toBe(true); + expect(document.activeElement).toBe(row('BMI')); + }); + + it('walks from the numerical group into the categorical group and back', () => { + row('MMSE').click(); + harness.fixture.detectChanges(); + + press(row('MMSE'), 'ArrowDown'); + expect(heading()).toContain('Sex'); + expect(document.activeElement).toBe(row('Sex')); + + press(row('Sex'), 'ArrowUp'); + expect(heading()).toContain('MMSE'); + }); + + it('stops at the ends, and Home and End jump to them', () => { + press(row('Age'), 'ArrowUp'); + expect(heading()).toContain('Age'); + + press(row('Age'), 'End'); + expect(heading()).toContain('Sex'); + + press(row('Sex'), 'ArrowDown'); + expect(heading()).toContain('Sex'); + + press(row('Sex'), 'Home'); + expect(heading()).toContain('Age'); + }); + + it('follows the order on screen after sorting', () => { + (rail().querySelector('.statistics-sort-btn') as HTMLButtonElement).click(); + harness.fixture.detectChanges(); + // Sorted numerical rows: BMI, MMSE, Age. In selection order MMSE is followed by Sex. + row('MMSE').click(); + harness.fixture.detectChanges(); + + press(row('MMSE'), 'ArrowDown'); + expect(heading()).toContain('Age'); + }); + + it('leaves other keys alone', () => { + const event = press(row('Age'), 'a'); + expect(event.defaultPrevented).toBe(false); + expect(heading()).toContain('Age'); + }); + }); +}); diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.summary-table.spec.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.summary-table.spec.ts new file mode 100644 index 000000000..b9fb5eafd --- /dev/null +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.summary-table.spec.ts @@ -0,0 +1,82 @@ +import { SummaryPanelHarness, createSummaryPanel } from './summary-workspace.testing'; + +/** + * Contract: the statistics table of the shared data summary does not repeat itself. With one + * dataset the pooled "All datasets" column is a copy of the dataset column, so it is not + * drawn; with two or more it stays. The wrapper publishes the column count so the stylesheet + * can size the table to its content. + */ +describe('StatisticAnalysisPanelComponent summary table', () => { + let harness: SummaryPanelHarness; + + const variables = [{ code: 'age', label: 'Age', type: 'real' }]; + const ageRow = (dataset: string) => ({ + dataset, + variable: 'age', + data: { num_dtps: 10, num_na: 0, num_total: 10, mean: 71, std: 4, min: 60, q1: 65, q2: 71, q3: 77, max: 90 }, + }); + + const wrapper = () => harness.workspace().querySelector('.statistics-table-wrapper') as HTMLElement; + const headers = () => + Array.from(wrapper().querySelectorAll('thead th')).map((cell) => (cell.textContent ?? '').trim()); + const groupRow = () => wrapper().querySelector('tr.statistics-metric-group td') as HTMLTableCellElement; + const bodyRow = (metric: string) => + (Array.from(wrapper().querySelectorAll('tbody tr')) as HTMLTableRowElement[]) + .find((tr) => (tr.querySelector('.metric-cell')?.textContent ?? '').trim() === metric) as HTMLTableRowElement; + + describe('one dataset', () => { + beforeEach(async () => { + harness = await createSummaryPanel({ + variables, + featurewise: [ageRow('dataset-a'), ageRow('all datasets')], + }); + }); + + it('draws the dataset column only', () => { + expect(headers()).toEqual(['Metric', 'Dataset A']); + expect(wrapper().querySelector('.statistics-col-rollup')).toBeNull(); + expect(bodyRow('Mean').querySelectorAll('td').length).toBe(2); + }); + + it('spans the group headings over the drawn columns', () => { + expect(groupRow().getAttribute('colspan')).toBe('2'); + }); + + it('publishes the column count to the stylesheet', () => { + expect(wrapper().style.getPropertyValue('--summary-cols').trim()).toBe('1'); + }); + + it('leaves the block itself complete, so exports keep the pooled column', () => { + const block = harness.component.selectedStatisticBlock('source')!; + expect(block.columns).toEqual(['dataset-a', 'all datasets']); + expect(harness.component.summaryColumns(block)).toEqual(['dataset-a']); + }); + }); + + describe('two datasets', () => { + beforeEach(async () => { + harness = await createSummaryPanel({ + variables, + datasetLabels: { 'dataset-a': 'Dataset A', 'dataset-b': 'Dataset B' }, + featurewise: [ageRow('dataset-a'), ageRow('dataset-b'), ageRow('all datasets')], + }); + }); + + it('keeps the pooled column beside the datasets', () => { + expect(headers()).toEqual(['Metric', 'Dataset A', 'Dataset B', 'All datasets']); + expect(wrapper().querySelectorAll('thead th.statistics-col-rollup').length).toBe(1); + expect(bodyRow('Mean').querySelectorAll('td').length).toBe(4); + }); + + it('spans the group headings and publishes the column count', () => { + expect(groupRow().getAttribute('colspan')).toBe('4'); + expect(wrapper().style.getPropertyValue('--summary-cols').trim()).toBe('3'); + }); + }); + + it('keeps the pooled column when it is the only column of a block', async () => { + harness = await createSummaryPanel({ variables, featurewise: [ageRow('all datasets')] }); + + expect(headers()).toEqual(['Metric', 'All datasets']); + }); +}); diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/summary-workspace.testing.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/summary-workspace.testing.ts new file mode 100644 index 000000000..a1c78a216 --- /dev/null +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/summary-workspace.testing.ts @@ -0,0 +1,119 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { of } from 'rxjs'; +import { provideZonelessChangeDetection, signal } from '@angular/core'; +import { provideEchartsCore } from 'ngx-echarts'; +import { StatisticAnalysisPanelComponent } from './statistic-analysis-panel.component'; +import { ExperimentStudioService } from '../../../services/experiment-studio.service'; +import { ExperimentsDashboardService } from '../../../services/experiments-dashboard.service'; +import { ChartBuilderService } from '../visualisations/charts/chart-builder.service'; +import { PdfExportService } from '../../../services/pdf-export.service'; +import { createSpyObj } from '../../../testing/spy-obj.testing'; + +export interface SummaryPanelHarness { + fixture: ComponentFixture; + component: StatisticAnalysisPanelComponent; + /** The step 1 "Raw data" preview: the shared summary workspace with kind 'source'. */ + workspace: () => HTMLElement; +} + +/** + * Renders the panel with a mocked describe response and opens the step 1 preview, so a spec + * can query the shared summary workspace (variable rail, toolbar, statistics table). + */ +export async function createSummaryPanel(options: { + featurewise: unknown[]; + variables: Array<{ code: string; label: string; type: string }>; + datasetLabels?: Record; +}): Promise { + const datasetLabels = options.datasetLabels ?? { 'dataset-a': 'Dataset A' }; + const service = createSpyObj('ExperimentStudioService', [ + 'loadDescriptiveOverview', + 'loadOutlierReportPreview', + 'getAlgorithmResults', + 'getDatasetLabelMap', + 'setDataExclusionWarnings', + 'clearDataExclusionWarnings', + 'setAppliedDescriptivePreprocessing', + 'getAppliedDescriptivePreprocessing', + 'setFilters', + 'setFilterLogic', + 'filterVariableCodes', + 'buildTransformationDescribePreprocessing', + 'transformationSourceCodesForInput', + 'requestDatasets', + 'requestFilters', + 'getActiveDataModelCode', + 'upsertTransformation', + 'removeTransformation', + 'clearTransformations', + 'transformationDependents', + 'outputsInUse', + 'availableCreatorNames', + 'hasPreprocessingSpec', + 'catalogLoaded', + 'genericCatalogSteps', + 'genericStepDroppedCodes', + 'catalogStepSpec', + ], { + selectedVariables: signal([]), + selectedFilters: signal([]), + selectedDatasets: signal(Object.keys(datasetLabels)), + selectedDataModel: signal({ code: 'Stroke', version: '3.7', variables: [] }), + unavailableVariables: signal(new Map()), + filterLogic: signal(null), + editingExistingExperiment: () => false, + appliedPreprocessingConfig: signal | null>(null), + appliedTransformations: signal([] as { id: string; name: string; parameters: Record }[]), + backendAlgorithms: signal({}), + }); + const mock = service as any; + mock.loadDescriptiveOverview.mockReturnValue(of({ result: { featurewise: options.featurewise } })); + mock.loadOutlierReportPreview.mockReturnValue(of({ result: { featurewise: [] } })); + mock.getAlgorithmResults.mockReturnValue(of({ result: { histogram: [] } })); + mock.getAppliedDescriptivePreprocessing.mockReturnValue(null); + mock.getDatasetLabelMap.mockReturnValue(datasetLabels); + mock.availableCreatorNames.mockReturnValue([]); + mock.hasPreprocessingSpec.mockReturnValue(false); + mock.catalogLoaded.mockReturnValue(true); + mock.genericCatalogSteps.mockReturnValue([]); + mock.genericStepDroppedCodes.mockReturnValue([]); + mock.catalogStepSpec.mockReturnValue(null); + mock.transformationDependents.mockReturnValue([]); + mock.outputsInUse.mockReturnValue([]); + mock.requestDatasets.mockReturnValue(Object.keys(datasetLabels)); + mock.requestFilters.mockReturnValue(null); + mock.getActiveDataModelCode.mockReturnValue('Stroke:3.7'); + mock.buildTransformationDescribePreprocessing.mockReturnValue(null); + mock.transformationSourceCodesForInput.mockReturnValue([]); + mock.filterVariableCodes.mockReturnValue([]); + + const chartBuilder = createSpyObj('ChartBuilderService', ['getChartsForAlgorithm']); + (chartBuilder as any).getChartsForAlgorithm.mockReturnValue([]); + + await TestBed.configureTestingModule({ + imports: [StatisticAnalysisPanelComponent], + providers: [ + provideZonelessChangeDetection(), + provideEchartsCore({ echarts: () => import('echarts') }), + { provide: ExperimentStudioService, useValue: service }, + { provide: ExperimentsDashboardService, useValue: { listKMeansExperiments: () => of([]), listPcaExperiments: () => of([]) } }, + { provide: ChartBuilderService, useValue: chartBuilder }, + { provide: PdfExportService, useValue: createSpyObj('PdfExportService', ['exportDescriptiveStatisticsPdf']) }, + ], + }).compileComponents(); + + const fixture = TestBed.createComponent(StatisticAnalysisPanelComponent); + const component = fixture.componentInstance; + fixture.detectChanges(); + mock.selectedVariables.set(options.variables); + fixture.detectChanges(); + if (!component.sectionOpen().source) component.toggleSourcePreview(); + fixture.detectChanges(); + + return { + fixture, + component, + workspace: () => + (fixture.nativeElement as HTMLElement).querySelector('[data-guide="analysis-source-summary"]') as HTMLElement, + }; +} diff --git a/src/styles.css b/src/styles.css index fafeafdf9..756348007 100644 --- a/src/styles.css +++ b/src/styles.css @@ -817,6 +817,75 @@ select:required:valid { text-transform: uppercase; } +/* Rail header = the list's column headings: what is listed on the left, the + number every row is ranked on at the right. The right heading is a button, + the way a table column sorts: it puts the most missing variable first. Both + read in sentence case; the group titles under them keep the small caps. */ +.statistics-browser-header .statistics-rail-count { + color: var(--text-main); + font-size: 0.8rem; + font-weight: 600; + letter-spacing: 0; + text-transform: none; + font-variant-numeric: tabular-nums; +} + +.statistics-sort-btn { + display: inline-flex; + align-items: center; + gap: 5px; + margin-left: auto; + /* Pulls the label onto the percentage column below it. */ + margin-right: -4px; + padding: 3px 8px; + border: 1px solid transparent; + border-radius: 999px; + background: transparent; + color: var(--text-muted); + font: inherit; + font-size: 0.72rem; + font-weight: 700; + line-height: 1.3; + cursor: pointer; + transition: background 0.14s var(--ease-standard), + color 0.14s var(--ease-standard); +} + +.statistics-sort-btn i { + font-size: 0.68rem; + opacity: 0.5; +} + +.statistics-sort-btn:hover { + background: color-mix(in srgb, var(--primary-color) 6%, transparent); + color: var(--primary-color); +} + +.statistics-sort-btn[aria-pressed='true'] { + border-color: color-mix(in srgb, var(--primary-color) 22%, transparent); + background: color-mix(in srgb, var(--primary-color) 9%, transparent); + color: var(--primary-color); +} + +.statistics-sort-btn[aria-pressed='true'] i { + opacity: 1; +} + +/* Keyboard hint. It takes its line all the time and only becomes visible while + focus is inside the list, so the foot under it never jumps. */ +.statistics-rail-hint { + margin: 8px 0 0; + padding-left: 12px; + color: var(--text-muted); + font-size: 0.7rem; + line-height: 1.3; + visibility: hidden; +} + +.statistics-variable-list:focus-within + .statistics-rail-hint { + visibility: visible; +} + .statistics-variable-btn > span { color: var(--text-main); font-size: 0.86rem; From be2c98154d07000e2340ccdfa7f91f28d80d1124 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 10:33:38 +0200 Subject: [PATCH 05/22] task(01-step-picker-catalog): Add-step menu model: icons and purpose groups --- src/app/core/step-picker.utils.ts | 81 +++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 4 deletions(-) diff --git a/src/app/core/step-picker.utils.ts b/src/app/core/step-picker.utils.ts index f60ab394d..21a52f3a0 100644 --- a/src/app/core/step-picker.utils.ts +++ b/src/app/core/step-picker.utils.ts @@ -33,9 +33,67 @@ export interface StepCandidate { } /** Font Awesome classes of a pipeline step, by engine name. Unlisted names get the branch icon. */ +const ICONS: Readonly> = { + outlier_winsorizer: 'fas fa-line-chart', + global_imputer: 'fas fa-fill-drip', + global_winsorizer: 'fas fa-compress', + variable_transformer: 'fas fa-arrow-up-right-dots', + variable_scaler: 'fas fa-ruler-horizontal', + one_hot_encoder: 'fas fa-table-columns', + ordinal_encoder: 'fas fa-arrow-down-1-9', + missing_indicator: 'fas fa-flag', + outlier_detector: 'fas fa-magnifying-glass-chart', + longitudinal_transformer: 'fas fa-code-compare', +}; + +const FALLBACK_ICON = 'fas fa-code-branch'; + export function stepIcon(name: string): string { - void name; - throw new Error('not implemented'); + return ICONS[name] ?? FALLBACK_ICON; +} + +/** Menu copy for the steps whose station has a hand-written title and subtitle. */ +const COPY: Readonly> = { + outlier_winsorizer: { + title: 'Outlier Handling', + subtitle: 'Cap extreme values so a few outliers do not skew results. Numerical variables only.', + }, + variable_transformer: { + title: 'Variable Transforms', + subtitle: 'Reshape skewed values with log, square root, Yeo-Johnson or quantile. Numerical variables only.', + }, + variable_scaler: { + title: 'Variable Scaling', + subtitle: 'Bring numerical variables to a comparable range: standard, robust, min-max or max absolute.', + }, + longitudinal_transformer: { + title: 'Longitudinal Transformation', + subtitle: 'Compare two visits per variable. Required for two-visit pathologies.', + }, +}; + +/** Steps that serve the same purpose, in the order the menu shows the groups. */ +const GROUP_TABLE: ReadonlyArray<{ key: string; label: string; steps: readonly string[] }> = [ + { key: 'missing', label: 'Fill missing values', steps: ['global_imputer'] }, + { key: 'outliers', label: 'Cap outliers', steps: ['outlier_winsorizer', 'global_winsorizer'] }, + { key: 'reshape', label: 'Reshape and scale', steps: ['variable_transformer', 'variable_scaler'] }, + { key: 'encode', label: 'Encode categories', steps: ['one_hot_encoder', 'ordinal_encoder'] }, + { key: 'flag', label: 'Flag records', steps: ['missing_indicator', 'outlier_detector'] }, + { key: 'visits', label: 'Compare visits', steps: ['longitudinal_transformer'] }, + { key: 'create', label: 'Create a column', steps: ['categorical_column_creator', 'kmeans_cluster_creator', 'pca_column_creator'] }, +]; + +/** Where a step named in no group ends up. */ +const OTHER_GROUP: { key: string; label: string } = { key: 'other', label: 'More steps' }; + +function toOption(candidate: StepCandidate): StepPickerOption { + const copy = COPY[candidate.name]; + return { + id: candidate.name, + icon: candidate.icon ?? stepIcon(candidate.name), + title: copy?.title ?? candidate.label ?? candidate.name, + subtitle: copy?.subtitle ?? candidate.desc ?? '', + }; } /** @@ -43,6 +101,21 @@ export function stepIcon(name: string): string { * the order they were given. A group without a step is left out. */ export function stepPickerGroups(candidates: StepCandidate[]): StepPickerGroup[] { - void candidates; - throw new Error('not implemented'); + const options = candidates.map(toOption); + + const groups: StepPickerGroup[] = []; + for (const { key, label, steps } of GROUP_TABLE) { + const groupOptions = options.filter((option) => steps.includes(option.id)); + if (groupOptions.length > 0) { + groups.push({ key, label, options: groupOptions }); + } + } + + const grouped = new Set(GROUP_TABLE.flatMap((group) => group.steps)); + const other = options.filter((option) => !grouped.has(option.id)); + if (other.length > 0) { + groups.push({ key: OTHER_GROUP.key, label: OTHER_GROUP.label, options: other }); + } + + return groups; } From f803bac0970eca883970194decbdc9321615cd42 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 10:32:30 +0200 Subject: [PATCH 06/22] task(02-step-picker-component): `app-step-picker`: the add row and its grouped menu --- .../step-picker/step-picker.component.html | 34 +++++++++++++++++++ .../step-picker/step-picker.component.ts | 8 ++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.html b/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.html index e69de29bb..82231e942 100644 --- a/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.html +++ b/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.html @@ -0,0 +1,34 @@ +@if (groups().length) { +
+ + @if (open()) { +
+ @for (group of groups(); track group.key) { +
+ +
+ @for (option of group.options; track option.id) { + + } +
+
+ } +
+ } +
+} diff --git a/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.ts b/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.ts index a6ac2e2b9..04b65cdf1 100644 --- a/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.ts +++ b/src/app/pages/experiment-studio/shared/step-picker/step-picker.component.ts @@ -25,15 +25,15 @@ export class StepPickerComponent { readonly pick = output(); protected toggle(): void { - throw new Error('not implemented'); + this.open.update((value) => !value); } protected choose(option: StepPickerOption): void { - void option; - throw new Error('not implemented'); + this.close(); + this.pick.emit(option.id); } protected close(): void { - throw new Error('not implemented'); + this.open.set(false); } } From b7e5860f2f1241ea2b30239a89aaec63d287b4a4 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 10:37:24 +0200 Subject: [PATCH 07/22] task(03-rail-add-step-menu): Collapsed stage rails: one add row with a grouped menu # Conflicts: # src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts --- .../statistic-analysis-panel.component.html | 103 +++--------------- .../statistic-analysis-panel.component.ts | 54 +++++++-- 2 files changed, 60 insertions(+), 97 deletions(-) diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html index 8f53ec5cb..6bbbeae89 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html @@ -660,7 +660,7 @@

-

- } - @for (spec of genericStepsOf('preprocessing'); track spec.name) { - @if (!isGenericStepApplied(spec.name)) { -
- - +
} - } } @@ -1365,71 +1343,16 @@

+ } - @if (!scalerSubNodeApplied && scalerStepAvailable) { -
- - -
- } - @for (spec of genericStepsOf('transformation'); track spec.name) { - @if (!isGenericStepApplied(spec.name)) { -
- - -
- } - } - @if (isLongitudinalModel && !expStudioService.appliedPreprocessingConfig()?.['longitudinal_transformer']) { -
- - -
- } -
- - -
} diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts index ca2da17e7..fc150f22e 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts @@ -95,8 +95,14 @@ import { summarizeStepParameters, } from '../../../core/data-transformation-step-form.utils'; import { GenericDataTransformationStepComponent } from './generic-data-transformation-step/generic-data-transformation-step.component'; -import { StepPickerGroup } from '../../../core/step-picker.utils'; import { RailOrder } from '../../../core/summary-rail.utils'; +import { + StepCandidate, + StepPickerGroup, + stepIcon, + stepPickerGroups, +} from '../../../core/step-picker.utils'; +import { StepPickerComponent } from '../shared/step-picker/step-picker.component'; type TabKey = 'Statistics' | 'Charts' | 'Histogram'; type SummaryKind = 'source' | 'raw' | 'processed'; @@ -313,7 +319,7 @@ export interface DescriptiveProgressState { @Component({ selector: 'app-statistic-analysis-panel', - imports: [ChartRendererComponent, HistogramComponent, FormsModule, NgTemplateOutlet, FilterConfigModalComponent, StationActionBarComponent, StationCardComponent, KMeansClusterSourceComponent, PcaColumnSourceComponent, GenericDataTransformationStepComponent], + imports: [ChartRendererComponent, HistogramComponent, FormsModule, NgTemplateOutlet, FilterConfigModalComponent, StationActionBarComponent, StationCardComponent, KMeansClusterSourceComponent, PcaColumnSourceComponent, GenericDataTransformationStepComponent, StepPickerComponent], templateUrl: './statistic-analysis-panel.component.html', // Order is the cascade: shell + pipeline canvas, then preprocessing stations, // then shared controls / result surfaces + responsive overrides. Concatenated in this order. @@ -784,7 +790,7 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { if (!parameters || typeof parameters !== 'object' || Array.isArray(parameters)) continue; nodes.push({ id: `step:${spec.name}`, - icon: stage === 'transformation' ? 'fas fa-code-branch' : 'fas fa-sliders', + icon: stepIcon(spec.name), title: spec.label || spec.name, subtitle: summarizeStepParameters(parameters as Record).join(' · ') || 'Configured', statusLabel: 'Applied', @@ -967,9 +973,31 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { * inside the opened stage) a step whose station is already on screen is left out as well. */ addableSteps(stage: 'preprocessing' | 'transformation', inStage = false): StepPickerGroup[] { - void stage; void inStage; - throw new Error('not implemented'); + const candidates: StepCandidate[] = []; + if (stage === 'preprocessing') { + if (!this.outlierSubNodeApplied) candidates.push({ name: 'outlier_winsorizer' }); + } else { + if (this.transformStepAvailable && !this.transformSubNodeApplied) candidates.push({ name: 'variable_transformer' }); + if (this.scalerStepAvailable && !this.scalerSubNodeApplied) candidates.push({ name: 'variable_scaler' }); + } + for (const spec of this.genericStepsOf(stage).filter((spec) => !this.isGenericStepApplied(spec.name))) { + candidates.push({ name: spec.name, label: spec.label, desc: spec.desc }); + } + if (stage === 'transformation') { + if (this.isLongitudinalModel && !this.expStudioService.appliedPreprocessingConfig()?.['longitudinal_transformer']) { + candidates.push({ name: 'longitudinal_transformer' }); + } + for (const kind of this.chooserCreators()) { + candidates.push({ + name: kind, + label: CREATOR_CHOOSER_COPY[kind].title, + desc: CREATOR_CHOOSER_COPY[kind].subtitle, + icon: CREATOR_CHOOSER_COPY[kind].icon, + }); + } + } + return stepPickerGroups(candidates); } /** @@ -977,8 +1005,20 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { * A column creator adds its card. Nothing is written to the request. */ pickStep(name: string): void { - void name; - throw new Error('not implemented'); + if (name === 'outlier_winsorizer') { + this.addPreprocessingSubNode('outlier'); + } else if (name === 'variable_transformer') { + this.addTransformationSubNode('transform'); + } else if (name === 'variable_scaler') { + this.addTransformationSubNode('scaler'); + } else if (name === 'longitudinal_transformer') { + this.addTransformationSubNode('longitudinal'); + } else if (this.chooserCreators().includes(name as CreatorName)) { + if (!this.sectionOpen().transformation) this.addStep('transformation'); + this.chooseTransformation(name as CreatorName); + } else { + this.addGenericStep(name); + } } /** Whether the Variable Transforms station is drawn: the step is applied, or was opened this visit. */ From 1a8ecdc03a28622e33d7a794d75fe7b3b212815a Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 12:05:44 +0200 Subject: [PATCH 08/22] task(04-stage-add-step-menu): Opened stages: stations only, plus one add-step menu --- ...ric-data-transformation-step.component.css | 27 ++-------- ...ic-data-transformation-step.component.html | 7 +-- ...eric-data-transformation-step.component.ts | 13 ++--- .../statistic-analysis-panel.component.css | 36 ------------- .../statistic-analysis-panel.component.html | 53 ++++++------------- .../statistic-analysis-panel.component.ts | 27 ++++++---- 6 files changed, 41 insertions(+), 122 deletions(-) diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.css b/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.css index 1250dcf72..ef325fc7d 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.css +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.css @@ -2,32 +2,11 @@ display: block; } -.btn-add-dashed { - width: 100%; - box-sizing: border-box; - display: inline-flex; - align-items: center; - justify-content: center; - gap: 7px; - padding: 12px 16px; - background: color-mix(in srgb, var(--primary-color) 2.5%, white); - border: 1.5px dashed color-mix(in srgb, var(--primary-color) 30%, transparent); - border-radius: var(--radius-md, 8px); - color: var(--primary-color); - font-family: inherit; - font-size: 0.84rem; - font-weight: 650; - cursor: pointer; - transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease; -} - -.btn-add-dashed:hover { - background: color-mix(in srgb, var(--primary-color) 7%, white); - border-color: var(--primary-color); - box-shadow: 0 2px 8px rgba(43, 51, 233, 0.08); +/* An idle step draws nothing and takes no room in the stage's flex gap. */ +:host(.is-idle) { + display: none; } -.btn-add-dashed:focus-visible, .btn-remove-step-node:focus-visible, .doc-toggle:focus-visible, .step-quick button:focus-visible { diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.html b/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.html index bc02de880..af440144d 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.html +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/generic-data-transformation-step/generic-data-transformation-step.component.html @@ -1,9 +1,4 @@ -@if (!shown()) { - -} @else { +@if (shown()) { (); protected readonly note = computed(() => stepNote(this.spec().name)); - protected readonly icon = computed(() => - stepStage(this.spec().name) === 'transformation' ? 'fas fa-code-branch' : 'fas fa-sliders', - ); + protected readonly icon = computed(() => stepIcon(this.spec().name)); protected readonly fields = computed(() => stepFields(this.spec())); protected readonly blockedFields = computed(() => unsupportedRequiredFields(this.fields())); protected readonly values = signal({}); @@ -107,11 +105,6 @@ export class GenericDataTransformationStepComponent { }); } - protected add(): void { - this.started.set(true); - this.openChange.emit(true); - } - protected toggle(): void { this.openChange.emit(!this.open()); } diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.css b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.css index c2b32d8fa..c3f8d1e08 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.css +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.css @@ -660,42 +660,6 @@ box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05); } -/* Add-on action: the button is the dashed target itself (full width), so the - hover elevation lands on the thing the user is about to click. */ -.btn-add-dashed { - width: 100%; - box-sizing: border-box; - display: inline-flex; - align-items: center; - justify-content: center; - gap: 7px; - padding: 12px 16px; - background: color-mix(in srgb, var(--primary-color) 2.5%, white); - border: 1.5px dashed color-mix(in srgb, var(--primary-color) 30%, transparent); - border-radius: var(--radius-md, 8px); - color: var(--primary-color); - font-family: inherit; - font-size: 0.84rem; - font-weight: 650; - cursor: pointer; - transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease; -} - -.btn-add-dashed:hover { - background: color-mix(in srgb, var(--primary-color) 7%, white); - border-color: var(--primary-color); - box-shadow: 0 2px 8px rgba(43, 51, 233, 0.08); -} - -.btn-add-dashed:focus-visible { - outline: 2px solid var(--color-focus); - outline-offset: 2px; -} - -.btn-add-dashed i { - font-size: 0.78rem; -} - /* Terminal Card */ .pipeline-terminal-card { display: grid; diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html index 6bbbeae89..b79da6244 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html @@ -960,12 +960,7 @@
Dataset coverage
- @if (!showOutliersSection) { - - } @else { + @if (showOutliersSection) { Values that would be capped · per data (applyStep)="applyGenericStep(spec.name, $event)" (removeStep)="removeGenericStep(spec.name)"> } + @if (addableSteps('preprocessing', true).length) { + + } @@ -1365,12 +1367,7 @@

- } @else if (transformSubNodeApplied) { + @if (transformStationShown) { {{ variableLabel(variable) }}

} - @if (!scalerSubNodeApplied && scalerStepAvailable) { - - } @else if (scalerSubNodeApplied) { + @if (scalerStationShown) { {{ variableLabel(variable) }}

} -
- @if (transformationChooserOnly) { -

Choose the kind of column to add. You can add more afterwards.

- } -
- @for (kind of chooserCreators(); track kind) { -
- -
- } -
-
+ diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts index fc150f22e..98b3c9641 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts @@ -506,6 +506,7 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { this.processedSummaryKey = ''; this.sectionOpen.update((open) => ({ ...open, setup: false, processed: false })); } else if (step === 'transformation') { + this.startedStations.set({ transform: false, scaler: false }); this.resetTransformation(); this.resetTransformationSingletons(); this.sectionOpen.update((open) => ({ ...open, transformation: false })); @@ -673,6 +674,7 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { /** Drop one transform/scaler sub-step entirely and persist the request config without it. */ removePreprocessingSubNode(step: 'transform' | 'scaler'): void { + this.startedStations.update((state) => ({ ...state, [step]: false })); if (step === 'transform') { this.pendingTransformStrategies = {}; this.appliedTransformStrategies = {}; @@ -917,6 +919,9 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { this.genericStepOpen.set(Object.fromEntries(this.genericSteps.map((spec) => [spec.name, spec.name === target]))); } if (subNode === 'outlier') this.userEnabledOutliers.set(true); + if (subNode === 'transform' || subNode === 'scaler') { + this.startedStations.update((state) => ({ ...state, [subNode]: true })); + } this.cdr.markForCheck(); } @@ -973,19 +978,18 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { * inside the opened stage) a step whose station is already on screen is left out as well. */ addableSteps(stage: 'preprocessing' | 'transformation', inStage = false): StepPickerGroup[] { - void inStage; const candidates: StepCandidate[] = []; if (stage === 'preprocessing') { - if (!this.outlierSubNodeApplied) candidates.push({ name: 'outlier_winsorizer' }); + if (inStage ? !this.showOutliersSection : !this.outlierSubNodeApplied) candidates.push({ name: 'outlier_winsorizer' }); } else { - if (this.transformStepAvailable && !this.transformSubNodeApplied) candidates.push({ name: 'variable_transformer' }); - if (this.scalerStepAvailable && !this.scalerSubNodeApplied) candidates.push({ name: 'variable_scaler' }); + if (this.transformStepAvailable && !(inStage ? this.transformStationShown : this.transformSubNodeApplied)) candidates.push({ name: 'variable_transformer' }); + if (this.scalerStepAvailable && !(inStage ? this.scalerStationShown : this.scalerSubNodeApplied)) candidates.push({ name: 'variable_scaler' }); } - for (const spec of this.genericStepsOf(stage).filter((spec) => !this.isGenericStepApplied(spec.name))) { + for (const spec of this.genericStepsOf(stage).filter((spec) => !this.isGenericStepApplied(spec.name) && !(inStage && this.genericStepOpen()[spec.name]))) { candidates.push({ name: spec.name, label: spec.label, desc: spec.desc }); } if (stage === 'transformation') { - if (this.isLongitudinalModel && !this.expStudioService.appliedPreprocessingConfig()?.['longitudinal_transformer']) { + if (!inStage && this.isLongitudinalModel && !this.expStudioService.appliedPreprocessingConfig()?.['longitudinal_transformer']) { candidates.push({ name: 'longitudinal_transformer' }); } for (const kind of this.chooserCreators()) { @@ -1023,12 +1027,12 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { /** Whether the Variable Transforms station is drawn: the step is applied, or was opened this visit. */ get transformStationShown(): boolean { - throw new Error('not implemented'); + return this.transformStepAvailable && (this.transformSubNodeApplied || this.startedStations().transform); } /** Same for the Variable Scaling station. */ get scalerStationShown(): boolean { - throw new Error('not implemented'); + return this.scalerStepAvailable && (this.scalerSubNodeApplied || this.startedStations().scaler); } /** @@ -1036,7 +1040,12 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { * stage has nothing else to show (no card, no applied step, no opened station). */ get transformationPickerOpen(): boolean { - throw new Error('not implemented'); + return this.transformationChooserOnly + && this.appliedTransformationSingletonNodes.length === 0 + && !this.startedStations().transform + && !this.startedStations().scaler + && !Object.values(this.genericStepOpen()).some(Boolean) + && !this.isLongitudinalModel; } /** Catalog steps of one stage, in catalog order. */ From da20b60290c1456f6fabb0617159a6b697716af2 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 12:00:35 +0200 Subject: [PATCH 09/22] task(01-summary-rail-utils): Pure helpers for the data summary rail and table --- src/app/core/summary-rail.utils.ts | 55 +++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/src/app/core/summary-rail.utils.ts b/src/app/core/summary-rail.utils.ts index 0588be5ac..cc73606e4 100644 --- a/src/app/core/summary-rail.utils.ts +++ b/src/app/core/summary-rail.utils.ts @@ -13,9 +13,10 @@ export type RailOrder = 'selection' | 'missing'; * - otherwise: "2 of 5 variables", "1 of 4 variables", "0 of 5 variables" */ export function railCountLabel(shown: number, total: number): string { - void shown; - void total; - throw new Error('not implemented'); + if (shown === total) { + return total === 1 ? '1 variable' : `${total} variables`; + } + return `${shown} of ${total} variables`; } /** @@ -24,9 +25,24 @@ export function railCountLabel(shown: number, total: number): string { * their original order. The input array is not changed. */ export function orderByMissing(items: readonly T[], shareOf: (item: T) => number | null): T[] { - void items; - void shareOf; - throw new Error('not implemented'); + return items + .map((item, index) => ({ item, index, share: shareOf(item) })) + .sort((a, b) => { + if (a.share === null && b.share === null) { + return a.index - b.index; + } + if (a.share === null) { + return 1; + } + if (b.share === null) { + return -1; + } + if (b.share !== a.share) { + return b.share - a.share; + } + return a.index - b.index; + }) + .map(({ item }) => item); } /** @@ -38,10 +54,21 @@ export function orderByMissing(items: readonly T[], shareOf: (item: T) => num * - Home: 0, End: count - 1 */ export function railStep(key: string, index: number, count: number): number | null { - void key; - void index; - void count; - throw new Error('not implemented'); + if (count <= 0) { + return null; + } + switch (key) { + case 'ArrowDown': + return Math.min(index + 1, count - 1); + case 'ArrowUp': + return Math.max(index - 1, 0); + case 'Home': + return 0; + case 'End': + return count - 1; + default: + return null; + } } /** @@ -54,7 +81,9 @@ export function visibleSummaryColumns( columns: readonly string[], isRollup: (column: string) => boolean, ): string[] { - void columns; - void isRollup; - throw new Error('not implemented'); + const datasetColumns = columns.filter((column) => !isRollup(column)); + if (datasetColumns.length === 1) { + return datasetColumns; + } + return [...columns]; } From d27d7d869826680e9ecdf192e457f521a52cf26f Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 12:07:12 +0200 Subject: [PATCH 10/22] task(02-summary-rail-triage): Variable rail of the data summary: count, sort by missing, arrow keys, search that never dead-ends # Conflicts: # src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts --- .../statistic-analysis-panel.component.html | 33 +++++++++++------ .../statistic-analysis-panel.component.ts | 37 ++++++++++++------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html index b79da6244..fd78aecc9 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html @@ -63,23 +63,31 @@

Data Handling Pipeline

@if (!summary.isLoading) {
@if (summary.data.length > 0) { - @if (filteredStatisticBlocks(kind).length > 0) {
- } @else { -
- -

No variables match the current search.

- Clear the search field to show all statistics. -
- } } @else {
diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts index 98b3c9641..41ec9df7c 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts @@ -95,7 +95,12 @@ import { summarizeStepParameters, } from '../../../core/data-transformation-step-form.utils'; import { GenericDataTransformationStepComponent } from './generic-data-transformation-step/generic-data-transformation-step.component'; -import { RailOrder } from '../../../core/summary-rail.utils'; +import { + RailOrder, + orderByMissing, + railCountLabel, + railStep, +} from '../../../core/summary-rail.utils'; import { StepCandidate, StepPickerGroup, @@ -2125,7 +2130,9 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { } statisticBlocks(kind: SummaryKind, type: StatisticVariableType): PivotBlock[] { - return this.filteredStatisticBlocks(kind).filter((block) => this.statisticBlockType(kind, block) === type); + const blocks = this.filteredStatisticBlocks(kind).filter((block) => this.statisticBlockType(kind, block) === type); + if (this.statisticsSort[kind] !== 'missing') return blocks; + return orderByMissing(blocks, (block) => this.blockCoverage(block)?.share ?? null); } selectStatisticBlock(kind: SummaryKind, block: PivotBlock): void { @@ -2152,33 +2159,37 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { /** Rail header text: "4 variables", or "1 of 4 variables" while the search hides some. */ statisticsCountLabel(kind: SummaryKind): string { - void kind; - throw new Error('not implemented'); + return railCountLabel(this.filteredStatisticBlocks(kind).length, this.getSummary(kind).data.length); } /** Switches the rail between selection order and most missing first. */ toggleStatisticsSort(kind: SummaryKind): void { - void kind; - throw new Error('not implemented'); + this.statisticsSort[kind] = this.statisticsSort[kind] === 'missing' ? 'selection' : 'missing'; + this.cdr.markForCheck(); } /** Empties the rail search of one surface. */ clearStatisticsSearch(kind: SummaryKind): void { - void kind; - throw new Error('not implemented'); + this.statisticsSearch[kind] = ''; + this.cdr.markForCheck(); } /** Rail rows in the order they are drawn: the numerical group, then the categorical group. */ railBlocks(kind: SummaryKind): PivotBlock[] { - void kind; - throw new Error('not implemented'); + return [...this.statisticBlocks(kind, 'numeric'), ...this.statisticBlocks(kind, 'nominal')]; } /** Arrow keys, Home and End walk the rail: select the row and move focus to it. */ onStatisticRailKeydown(kind: SummaryKind, event: KeyboardEvent): void { - void kind; - void event; - throw new Error('not implemented'); + const blocks = this.railBlocks(kind); + const index = blocks.findIndex((block) => this.isStatisticBlockSelected(kind, block)); + const next = railStep(event.key, index, blocks.length); + if (next === null) return; + event.preventDefault(); + this.selectStatisticBlock(kind, blocks[next]); + const list = event.currentTarget as HTMLElement; + list.querySelectorAll('.statistics-variable-btn')[next]?.focus(); + this.cdr.markForCheck(); } /** Columns the statistics table draws for a block (no pooled column beside a single dataset). */ From 68e5cbca425cce4a4162e4b4ce42c74462c7aca6 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 12:08:35 +0200 Subject: [PATCH 11/22] task(03-summary-table-columns): Statistics table: no duplicate "All datasets" column, sized to its columns # Conflicts: # src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts --- .../statistic-analysis-panel.component.html | 8 ++++---- .../statistic-analysis-panel.component.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html index fd78aecc9..449a8e350 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.html @@ -218,12 +218,12 @@

{{ selectedBlock.name }} @if (selectedBlock.code) { @if (summary.activeTab === 'Statistics') { -
+
- @for (ds of selectedBlock.columns; track ds) { + @for (ds of summaryColumns(selectedBlock); track ds) { @@ -234,12 +234,12 @@

{{ selectedBlock.name }} @if (selectedBlock.code) { -

+ } - @for (ds of selectedBlock.columns; track ds) { + @for (ds of summaryColumns(selectedBlock); track ds) { } diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts index 41ec9df7c..f63f4a137 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.component.ts @@ -100,6 +100,7 @@ import { orderByMissing, railCountLabel, railStep, + visibleSummaryColumns, } from '../../../core/summary-rail.utils'; import { StepCandidate, @@ -2194,8 +2195,7 @@ export class StatisticAnalysisPanelComponent implements OnDestroy { /** Columns the statistics table draws for a block (no pooled column beside a single dataset). */ summaryColumns(block: PivotBlock): string[] { - void block; - throw new Error('not implemented'); + return visibleSummaryColumns(block.columns, (column) => this.isRollupColumn(column)); } statisticBlockVariable(block: PivotBlock): VariableRow | null { From 68f89bfbdda09396103dd0ea94076306974a5813 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 11:03:14 +0200 Subject: [PATCH 12/22] contracts: 2026-11-11_variable-browser-views-polish --- .../experiment-studio-guide.component.spec.ts | 3 +- .../variables-panel.columns.spec.ts | 113 +++++++++++ .../variables-panel.layout.spec.ts | 96 ++++++++++ .../bubble-chart/bubble-chart.component.ts | 8 + .../bubble-chart/bubble-chart.trail.spec.ts | 93 +++++++++ .../bubble-chart/bubble-label-layout.spec.ts | 164 ++++++++++++++++ .../bubble-chart/bubble-label-layout.ts | 44 +++++ .../bubble-chart/zoomable-circle-packing.ts | 8 +- .../collapsible-tree-browser.component.ts | 12 ++ .../collapsible-tree-readability.spec.ts | 179 ++++++++++++++++++ .../collapsible-tree-renderer.ts | 19 ++ .../metadata-browser-labels.ts | 9 + .../ontology-tree-browser.component.spec.ts | 2 +- .../ontology-tree-browser.component.ts | 30 +++ .../ontology-tree-browser.quantities.spec.ts | 110 +++++++++++ .../ontology-tree-browser.subtree.spec.ts | 136 +++++++++++++ 16 files changed, 1023 insertions(+), 3 deletions(-) create mode 100644 src/app/pages/experiment-studio/variables-panel/variables-panel.columns.spec.ts create mode 100644 src/app/pages/experiment-studio/variables-panel/variables-panel.layout.spec.ts create mode 100644 src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-chart.trail.spec.ts create mode 100644 src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-label-layout.spec.ts create mode 100644 src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-label-layout.ts create mode 100644 src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-readability.spec.ts create mode 100644 src/app/pages/experiment-studio/visualisations/metadata-browser/metadata-browser-labels.ts create mode 100644 src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.quantities.spec.ts create mode 100644 src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.subtree.spec.ts diff --git a/src/app/pages/experiment-studio/guide/experiment-studio-guide.component.spec.ts b/src/app/pages/experiment-studio/guide/experiment-studio-guide.component.spec.ts index dbb668602..f7d8f2ea9 100644 --- a/src/app/pages/experiment-studio/guide/experiment-studio-guide.component.spec.ts +++ b/src/app/pages/experiment-studio/guide/experiment-studio-guide.component.spec.ts @@ -748,7 +748,8 @@ describe('ExperimentStudioGuideComponent', () => { expect(exploreStep?.allowTargetInteraction).toBe(true); expect(exploreStep?.body).toContain('Map'); expect(exploreStep?.body).toContain('List'); - expect(exploreStep?.body).toContain('Graph'); + expect(exploreStep?.body).toContain('Tree'); + expect(exploreStep?.body).not.toContain('Graph'); expect(exploreStep?.body).toContain('Next'); expect(exploreStep?.interactionSelectors).toBeUndefined(); expect(steps.some((step: any) => step.id === 'explore-variable-visualizations')).toBe(false); diff --git a/src/app/pages/experiment-studio/variables-panel/variables-panel.columns.spec.ts b/src/app/pages/experiment-studio/variables-panel/variables-panel.columns.spec.ts new file mode 100644 index 000000000..39ce59462 --- /dev/null +++ b/src/app/pages/experiment-studio/variables-panel/variables-panel.columns.spec.ts @@ -0,0 +1,113 @@ +import { ChangeDetectorRef, provideZonelessChangeDetection, signal } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { of } from 'rxjs'; +import { page } from 'vitest/browser'; +import { ErrorService } from '../../../services/error.service'; +import { ExperimentStudioService } from '../../../services/experiment-studio.service'; +import { CsvExportService } from '../../../services/csv-export.service'; +import { PdfExportService } from '../../../services/pdf-export.service'; +import { ExperimentStudioGuideStateService } from '../guide/experiment-studio-guide-state.service'; +import { VariablesPanelComponent } from './variables-panel.component'; + +/** Renders the real template at a desktop width, where the step is two columns. */ +describe('VariablesPanelComponent columns', () => { + let fixture: ComponentFixture; + let component: VariablesPanelComponent; + let selectedVariables: ReturnType>; + + const sex = { label: 'Sex', code: 'sex', type: 'nominal' }; + const tree = { + label: 'IST', + code: 'ist', + children: [{ label: 'Demographics', code: 'demographics', children: [sex] }], + }; + + const query = (selector: string): HTMLElement => fixture.nativeElement.querySelector(selector); + const select = (node: unknown): void => { + component.selectedNode = node; + fixture.debugElement.injector.get(ChangeDetectorRef).markForCheck(); + fixture.detectChanges(); + }; + + beforeAll(async () => { + await page.viewport(1400, 900); + }); + + beforeEach(() => { + selectedVariables = signal([]); + TestBed.configureTestingModule({ + imports: [VariablesPanelComponent], + providers: [ + provideZonelessChangeDetection(), + { + provide: ExperimentStudioService, + useValue: { + selectedDataModel: signal(null), + selectedVariables, + selectedDatasets: signal(['dataset-a']), + availableGroupedAlgorithms: signal([]), + getAllDataModels: vi.fn().mockReturnValue(of([])), + categorizeDataModels: vi.fn().mockReturnValue({ crossSectional: [], longitudinal: [] }), + getAlgorithmResults: vi.fn().mockReturnValue(of({ result: { histogram: [] } })), + getDatasetLabelMap: vi.fn().mockReturnValue({ 'dataset-a': 'Dataset A' }), + setVariables: vi.fn(), + setSelectedDatasets: vi.fn(), + addVariableAndEnrich: vi.fn(), + clearSelectionsForDataModelChange: vi.fn(), + editingExistingExperiment: () => false, + unavailableVariables: signal>(new Map()), + }, + }, + { + provide: ExperimentStudioGuideStateService, + useValue: { activeStepId: signal(null), setSelectedHierarchyNode: vi.fn() }, + }, + { provide: ErrorService, useValue: {} }, + { provide: PdfExportService, useValue: { exportHistogramPdf: vi.fn() } }, + { provide: CsvExportService, useValue: { exportHistogramCsv: vi.fn() } }, + ], + }); + localStorage.removeItem('metadata_browser_mode'); + + fixture = TestBed.createComponent(VariablesPanelComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + // Loading an empty model list clears the view on init, so the tree goes in afterwards. + component.d3Data = tree; + fixture.debugElement.injector.get(ChangeDetectorRef).markForCheck(); + fixture.detectChanges(); + }); + + it('puts the variables of the experiment above the inspector', () => { + const pool = query('.right-column .pool-card'); + const inspector = query('.right-column #histogram-graph'); + + expect(pool.compareDocumentPosition(inspector) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(); + }); + + it('keeps a large pool from pushing the inspector down the page', () => { + selectedVariables.set( + Array.from({ length: 40 }, (_, index) => ({ code: `var_${index}`, label: `Variable number ${index}`, type: 'real' })) + ); + fixture.detectChanges(); + + expect(fixture.nativeElement.querySelectorAll('.pool-chip').length).toBe(40); + expect(query('.pool-card').getBoundingClientRect().height).toBeLessThanOrEqual(220); + }); + + it('ends the browser card and the details column on the same line', () => { + const browser = query('.bubble-chart-section').getBoundingClientRect(); + const details = query('.right-column').getBoundingClientRect(); + + expect(details.left).toBeGreaterThan(browser.right); // side by side, not stacked + expect(Math.abs(browser.bottom - details.bottom)).toBeLessThanOrEqual(1); + }); + + it('draws attention to Add for a variable, not for a whole group', () => { + select(sex); + expect(query('.selection-toggle-btn').classList.contains('pulse-hint--variable')).toBe(true); + + select(tree); + expect(query('.selection-toggle-btn').classList.contains('pulse-hint--variable')).toBe(false); + }); +}); diff --git a/src/app/pages/experiment-studio/variables-panel/variables-panel.layout.spec.ts b/src/app/pages/experiment-studio/variables-panel/variables-panel.layout.spec.ts new file mode 100644 index 000000000..9653e3951 --- /dev/null +++ b/src/app/pages/experiment-studio/variables-panel/variables-panel.layout.spec.ts @@ -0,0 +1,96 @@ +import { ChangeDetectorRef, provideZonelessChangeDetection, signal } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { of } from 'rxjs'; +import { ErrorService } from '../../../services/error.service'; +import { ExperimentStudioService } from '../../../services/experiment-studio.service'; +import { CsvExportService } from '../../../services/csv-export.service'; +import { PdfExportService } from '../../../services/pdf-export.service'; +import { ExperimentStudioGuideStateService } from '../guide/experiment-studio-guide-state.service'; +import { HistogramGraphComponent } from './histogram-graph/histogram-graph.component'; +import { VariablesPanelComponent } from './variables-panel.component'; + +/** Renders the real template (the logic spec next to this file blanks it). */ +describe('VariablesPanelComponent data exploration layout', () => { + let fixture: ComponentFixture; + let component: VariablesPanelComponent; + + const tree = { + label: 'IST', + code: 'ist', + children: [ + { label: 'Demographics', code: 'demographics', children: [{ label: 'Sex', code: 'sex', type: 'nominal' }] }, + ], + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [VariablesPanelComponent], + providers: [ + provideZonelessChangeDetection(), + { + provide: ExperimentStudioService, + useValue: { + selectedDataModel: signal(null), + selectedVariables: signal([]), + selectedDatasets: signal(['dataset-a']), + availableGroupedAlgorithms: signal([]), + getAllDataModels: vi.fn().mockReturnValue(of([])), + categorizeDataModels: vi.fn().mockReturnValue({ crossSectional: [], longitudinal: [] }), + getAlgorithmResults: vi.fn().mockReturnValue(of({ result: { histogram: [] } })), + getDatasetLabelMap: vi.fn().mockReturnValue({ 'dataset-a': 'Dataset A' }), + setVariables: vi.fn(), + setSelectedDatasets: vi.fn(), + addVariableAndEnrich: vi.fn(), + clearSelectionsForDataModelChange: vi.fn(), + editingExistingExperiment: () => false, + unavailableVariables: signal>(new Map()), + }, + }, + { + provide: ExperimentStudioGuideStateService, + useValue: { activeStepId: signal(null), setSelectedHierarchyNode: vi.fn() }, + }, + { provide: ErrorService, useValue: {} }, + { provide: PdfExportService, useValue: { exportHistogramPdf: vi.fn() } }, + { provide: CsvExportService, useValue: { exportHistogramCsv: vi.fn() } }, + ], + }); + localStorage.removeItem('metadata_browser_mode'); + + fixture = TestBed.createComponent(VariablesPanelComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + // Loading an empty model list clears the view on init, so the tree goes in afterwards. + component.d3Data = tree; + fixture.debugElement.injector.get(ChangeDetectorRef).markForCheck(); + fixture.detectChanges(); + }); + + it('names each browser view next to its icon', () => { + const names = Array.from(fixture.nativeElement.querySelectorAll('.metadata-mode-btn span')) as HTMLElement[]; + + expect(names.map((name) => name.textContent?.trim())).toEqual(['Map', 'List', 'Tree']); + for (const name of names) { + expect(getComputedStyle(name).display).not.toBe('none'); + } + }); + + it('draws the group overview as horizontal bars so group names stay readable', () => { + component.selectedNode = tree; + component.groupHistogramData.set({ bins: ['Demographics'], counts: [1], variableName: 'IST' }); + fixture.detectChanges(); + + const chart = fixture.debugElement.query(By.directive(HistogramGraphComponent)); + expect(chart).not.toBeNull(); + expect((chart.componentInstance as HistogramGraphComponent).horizontal()).toBe(true); + }); + + it('tells the user how to add a first variable without naming one view', () => { + const empty = fixture.nativeElement.querySelector('.pool-card .parameter-empty') as HTMLElement; + + expect(empty.textContent).toContain('No variables yet'); + expect(empty.textContent).toContain('Add'); + expect(empty.textContent?.toLowerCase()).not.toContain('map'); + }); +}); diff --git a/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-chart.component.ts b/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-chart.component.ts index 2fd16dd2f..01bffffe0 100644 --- a/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-chart.component.ts +++ b/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-chart.component.ts @@ -75,6 +75,8 @@ export class BubbleChartComponent implements OnInit, OnChanges, AfterViewInit, O readonly error = signal(null); // Holds the current error message + /** Root-to-focus path of the group the map is zoomed into; drives the location trail. */ + readonly focusPath = signal>([]); readonly COLORBLIND_PALETTE = { ...DEFAULT_BUBBLE_COLORS }; colors: { @@ -153,6 +155,12 @@ export class BubbleChartComponent implements OnInit, OnChanges, AfterViewInit, O this.stopObservingSize?.(); } + /** Trail crumb click: zoom out to the crumb at `depth` (0 is the data model). */ + zoomToTrailDepth(depth: number): void { + void depth; + throw new Error('not implemented'); + } + renderChart(): void { if (!this.viewReady) return; const container = this.chartCanvas?.nativeElement diff --git a/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-chart.trail.spec.ts b/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-chart.trail.spec.ts new file mode 100644 index 000000000..ceef8cc67 --- /dev/null +++ b/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-chart.trail.spec.ts @@ -0,0 +1,93 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { provideZonelessChangeDetection, signal } from '@angular/core'; +import { BubbleChartComponent } from './bubble-chart.component'; +import { ExperimentStudioGuideStateService } from '../../guide/experiment-studio-guide-state.service'; + +describe('BubbleChartComponent location trail', () => { + let fixture: ComponentFixture; + + const crumbs = (): HTMLButtonElement[] => + Array.from(fixture.nativeElement.querySelectorAll('.map-trail .map-trail-crumb')); + const crumbLabels = (): string[] => crumbs().map((crumb) => crumb.textContent?.trim() ?? ''); + + /** Waits for the zoom animation: polls until the trail reads as expected. */ + const waitForTrail = async (expected: string[]): Promise => { + const deadline = Date.now() + 3000; + while (Date.now() < deadline) { + fixture.detectChanges(); + if (JSON.stringify(crumbLabels()) === JSON.stringify(expected)) return; + await new Promise((resolve) => setTimeout(resolve, 50)); + } + expect(crumbLabels()).toEqual(expected); + }; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [BubbleChartComponent], + providers: [ + provideZonelessChangeDetection(), + { + provide: ExperimentStudioGuideStateService, + useValue: { + activeStepId: signal(null), + expectedTutorialCovariate: signal(null), + matchesTutorialCovariate: () => false, + }, + }, + ], + }).compileComponents(); + + fixture = TestBed.createComponent(BubbleChartComponent); + fixture.componentRef.setInput('d3Data', { + label: 'IST', + code: 'ist', + children: [ + { + label: 'Demographics', + children: [ + { code: 'sex', label: 'Sex', type: 'text' }, + { code: 'age_value', label: 'Age', type: 'real' }, + ], + }, + { + label: 'Outcome', + children: [{ code: 'dead', label: 'Dead', type: 'text' }], + }, + ], + }); + fixture.detectChanges(); + }); + + it('starts with the data model as the only, current location', async () => { + await waitForTrail(['IST']); + + const trail = fixture.nativeElement.querySelector('.map-trail') as HTMLElement; + expect(trail.getAttribute('aria-label')).toBe('Map location'); + expect(crumbs()[0].getAttribute('aria-current')).toBe('location'); + expect(crumbs()[0].disabled).toBe(true); + }); + + it('adds the group to the trail after zooming into it', async () => { + await waitForTrail(['IST']); + const groups = Array.from(fixture.nativeElement.querySelectorAll('circle.group')) as SVGCircleElement[]; + const demographics = groups.find((circle) => (circle as any).__data__?.data?.label === 'Demographics')!; + + demographics.dispatchEvent(new MouseEvent('click', { bubbles: true })); + + await waitForTrail(['IST', 'Demographics']); + expect(crumbs()[0].disabled).toBe(false); + expect(crumbs()[0].getAttribute('aria-current')).toBeNull(); + expect(crumbs()[1].getAttribute('aria-current')).toBe('location'); + }); + + it('zooms back out when an earlier crumb is clicked', async () => { + await waitForTrail(['IST']); + const groups = Array.from(fixture.nativeElement.querySelectorAll('circle.group')) as SVGCircleElement[]; + groups[0].dispatchEvent(new MouseEvent('click', { bubbles: true })); + await waitForTrail(['IST', (groups[0] as any).__data__.data.label]); + + crumbs()[0].click(); + + await waitForTrail(['IST']); + }); +}); diff --git a/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-label-layout.spec.ts b/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-label-layout.spec.ts new file mode 100644 index 000000000..94003203d --- /dev/null +++ b/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-label-layout.spec.ts @@ -0,0 +1,164 @@ +import { + BUBBLE_LABEL_CHAR_WIDTH, + GROUP_LABEL_WIDTH_RATIO, + LEAF_LABEL_WIDTH_RATIO, + fitBubbleLabel, + pickVisibleLabels, +} from './bubble-label-layout'; +import { createZoomableCirclePacking } from './zoomable-circle-packing'; + +const LONG_LABEL = 'Predicted risk (IST prognostic model)'; + +describe('fitBubbleLabel', () => { + it('keeps a short label on one line without an ellipsis', () => { + const fit = fitBubbleLabel('Demographics', 120, true); + + expect(fit?.lines).toEqual(['Demographics']); + }); + + it('returns null when the circle is too small to carry text', () => { + expect(fitBubbleLabel('Demographics', 12, true)).toBeNull(); + expect(fitBubbleLabel('Sex', 8, false)).toBeNull(); + }); + + it('wraps a long group label on at most two lines that fit the circle', () => { + const radius = 60; + const fit = fitBubbleLabel(LONG_LABEL, radius, true)!; + + expect(fit).not.toBeNull(); + expect(fit.lines.length).toBeLessThanOrEqual(2); + for (const line of fit.lines) { + expect(line.length * fit.fontSize * BUBBLE_LABEL_CHAR_WIDTH).toBeLessThanOrEqual(radius * GROUP_LABEL_WIDTH_RATIO); + } + expect(fit.lines[0].startsWith('Predicted')).toBe(true); + expect(fit.lines[fit.lines.length - 1].endsWith('…')).toBe(true); + }); + + it('lets a variable label use three lines', () => { + const radius = 40; + const fit = fitBubbleLabel('Systolic blood pressure at randomisation', radius, false)!; + + expect(fit).not.toBeNull(); + expect(fit.lines.length).toBe(3); + for (const line of fit.lines) { + expect(line.length * fit.fontSize * BUBBLE_LABEL_CHAR_WIDTH).toBeLessThanOrEqual(radius * LEAF_LABEL_WIDTH_RATIO); + } + }); + + it('scales the font with the circle inside a readable range', () => { + const small = fitBubbleLabel('Stroke', 40, true)!; + const large = fitBubbleLabel('Stroke', 300, true)!; + const leaf = fitBubbleLabel('Sex', 26, false)!; + + expect(small.fontSize).toBeGreaterThanOrEqual(11); + expect(large.fontSize).toBeLessThanOrEqual(14); + expect(large.fontSize).toBeGreaterThan(small.fontSize); + expect(leaf.fontSize).toBeGreaterThanOrEqual(9); + expect(leaf.fontSize).toBeLessThanOrEqual(12); + }); +}); + +describe('pickVisibleLabels', () => { + const box = (x: number, y: number, priority: number) => ({ x, y, width: 100, height: 20, priority }); + + it('keeps every label when nothing overlaps', () => { + expect(pickVisibleLabels([box(0, 0, 1), box(0, 40, 2), box(200, 0, 3)])).toEqual([true, true, true]); + }); + + it('hides the lower priority label of an overlapping pair', () => { + expect(pickVisibleLabels([box(0, 0, 1), box(50, 10, 5)])).toEqual([false, true]); + }); + + it('keeps a label whose only overlap is with a label that was already hidden', () => { + // A overlaps B, B overlaps C, A and C are apart: B goes, C stays. + expect(pickVisibleLabels([box(0, 0, 3), box(80, 0, 2), box(160, 0, 1)])).toEqual([true, false, true]); + }); + + it('treats boxes that only touch as not overlapping', () => { + expect(pickVisibleLabels([box(0, 0, 1), box(100, 0, 2)])).toEqual([true, true]); + }); +}); + +describe('bubble chart labels on a crowded map', () => { + let container: HTMLDivElement; + let chart: ReturnType; + + const groupNames = [ + 'Clinical assessment at admission', + 'Death and survival within the trial', + 'Hospitalization and discharge', + LONG_LABEL, + 'Complications within 14 days', + 'Acute treatment and trial allocation', + 'Prestroke characteristics', + 'Follow-up at 6 months', + 'Demographics and event', + 'Admission imaging before randomisation', + 'Stroke characteristics', + 'Neurological deficits at admission', + ]; + + beforeEach(() => { + container = document.createElement('div'); + container.style.width = '420px'; + container.style.height = '420px'; + document.body.appendChild(container); + + chart = createZoomableCirclePacking( + { + label: 'IST', + code: 'ist', + children: groupNames.map((label, groupIndex) => ({ + label, + code: `group_${groupIndex}`, + children: Array.from({ length: 2 + (groupIndex % 3) }, (_, leafIndex) => ({ + code: `var_${groupIndex}_${leafIndex}`, + label: `Variable ${groupIndex}-${leafIndex}`, + type: 'real', + value: 1, + })), + })), + }, + container, + () => undefined, + () => undefined, + ); + }); + + afterEach(() => { + chart.destroy?.(); + container.remove(); + }); + + const visibleLabels = (): SVGTextElement[] => + Array.from(container.querySelectorAll('g.label-group')) + .filter((group) => group.style.display !== 'none') + .map((group) => group.querySelector('text')) + .filter((text): text is SVGTextElement => !!text); + + it('draws group labels at a size that fits their circle', () => { + const labels = visibleLabels(); + + expect(labels.length).toBeGreaterThan(0); + for (const text of labels) { + expect(parseFloat(text.style.fontSize)).toBeLessThanOrEqual(14); + expect(text.querySelectorAll('tspan').length).toBeLessThanOrEqual(2); + } + }); + + it('never draws two labels on top of each other', () => { + const rects = visibleLabels().map((text) => text.getBoundingClientRect()); + const overlaps: string[] = []; + + rects.forEach((a, i) => { + rects.slice(i + 1).forEach((b, offset) => { + const overlapX = Math.min(a.right, b.right) - Math.max(a.left, b.left); + const overlapY = Math.min(a.bottom, b.bottom) - Math.max(a.top, b.top); + if (overlapX > 1 && overlapY > 1) overlaps.push(`${i} over ${i + 1 + offset}`); + }); + }); + + expect(rects.length).toBeGreaterThan(0); + expect(overlaps).toEqual([]); + }); +}); diff --git a/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-label-layout.ts b/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-label-layout.ts new file mode 100644 index 000000000..26ab8e845 --- /dev/null +++ b/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-label-layout.ts @@ -0,0 +1,44 @@ +/** Text of one bubble label after it was fitted to its circle. */ +export interface BubbleLabelFit { + lines: string[]; + fontSize: number; +} + +/** Screen box a label takes, used to drop labels that would overlap. */ +export interface BubbleLabelBox { + x: number; + y: number; + width: number; + height: number; + /** Higher wins when two boxes overlap. The renderer passes the circle radius. */ + priority: number; +} + +/** Average glyph width as a share of the font size. */ +export const BUBBLE_LABEL_CHAR_WIDTH = 0.6; +/** Line height as a share of the font size. */ +export const BUBBLE_LABEL_LINE_HEIGHT = 1.2; +/** Share of the radius a group label may span (it sits in the top band of the circle). */ +export const GROUP_LABEL_WIDTH_RATIO = 1.4; +/** Share of the radius a variable label may span (it sits on the centre line). */ +export const LEAF_LABEL_WIDTH_RATIO = 1.7; + +/** + * Wraps and truncates a label so it stays inside a circle of `radius` screen pixels. + * Returns null when the circle is too small to carry any readable text. + */ +export function fitBubbleLabel(label: string, radius: number, isGroup: boolean): BubbleLabelFit | null { + void label; + void radius; + void isGroup; + throw new Error('not implemented'); +} + +/** + * Decides which labels stay visible. Result index matches the input index. + * A box is hidden when it overlaps a kept box of higher priority. + */ +export function pickVisibleLabels(boxes: BubbleLabelBox[]): boolean[] { + void boxes; + throw new Error('not implemented'); +} diff --git a/src/app/pages/experiment-studio/visualisations/bubble-chart/zoomable-circle-packing.ts b/src/app/pages/experiment-studio/visualisations/bubble-chart/zoomable-circle-packing.ts index c43f919d3..766760ee7 100644 --- a/src/app/pages/experiment-studio/visualisations/bubble-chart/zoomable-circle-packing.ts +++ b/src/app/pages/experiment-studio/visualisations/bubble-chart/zoomable-circle-packing.ts @@ -153,6 +153,8 @@ export function createZoomableCirclePacking( zoomToNode: (d: any) => void; refreshColors: (opts?: any) => void; resetZoom: () => void; + /** Zooms out to the ancestor of the focused group at `depth` (0 is the root). */ + zoomToDepth: (depth: number) => void; destroy?: () => void; } { @@ -191,7 +193,7 @@ export function createZoomableCirclePacking( if (!container) { console.error('No container provided'); - return { zoomToNode: () => { }, refreshColors: () => { }, resetZoom: () => { } }; + return { zoomToNode: () => { }, refreshColors: () => { }, resetZoom: () => { }, zoomToDepth: () => { } }; } container.innerHTML = ''; @@ -602,6 +604,10 @@ export function createZoomableCirclePacking( zoom(null, root); } }, + zoomToDepth: (depth: number) => { + void depth; + throw new Error('not implemented'); + }, destroy: () => { tooltip.remove(); } diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.ts b/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.ts index 2f5094eb7..242ac3af3 100644 --- a/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.ts +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.ts @@ -108,6 +108,18 @@ export class CollapsibleTreeBrowserComponent implements AfterViewInit, OnDestroy }); } + zoomIn(): void { + throw new Error('not implemented'); + } + + zoomOut(): void { + throw new Error('not implemented'); + } + + fitTree(): void { + throw new Error('not implemented'); + } + ngOnDestroy(): void { this.renderer?.destroy(); this.stopObservingSize?.(); diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-readability.spec.ts b/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-readability.spec.ts new file mode 100644 index 000000000..c067448e8 --- /dev/null +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-readability.spec.ts @@ -0,0 +1,179 @@ +import { provideZonelessChangeDetection } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import * as d3 from 'd3'; +import { D3HierarchyNode } from '../../../../../models/data-model.interface'; +import { CollapsibleTreeBrowserComponent } from './collapsible-tree-browser.component'; +import { + MIN_READABLE_SCALE, + cloneNode, + createCollapsibleTree, + fitTransform, + initializeCollapse, +} from './collapsible-tree-renderer'; + +/** 12 groups of 4 variables: 48 rows when every group is open. */ +const wideModel: D3HierarchyNode = { + label: 'IST', + code: 'ist', + children: Array.from({ length: 12 }, (_, groupIndex) => ({ + label: `Group ${groupIndex}`, + code: `group_${groupIndex}`, + children: Array.from({ length: 4 }, (_, leafIndex) => ({ + label: `Variable ${groupIndex}-${leafIndex}`, + code: `var_${groupIndex}_${leafIndex}`, + type: 'real', + })), + })), +}; + +const smallModel: D3HierarchyNode = { + label: 'Stroke', + code: 'stroke', + children: [ + { label: 'Demographics', code: 'demographics', children: [{ label: 'Sex', code: 'sex', type: 'nominal' }] }, + { label: 'Vitals', code: 'vitals', children: [{ label: 'Glucose', code: 'glucose', type: 'real' }] }, + ], +}; + +const wait = (ms: number): Promise => new Promise((resolve) => setTimeout(resolve, ms)); + +const layerScale = (host: HTMLElement): number => { + const transform = host.querySelector('.collapsible-tree-layer')?.getAttribute('transform') ?? ''; + const match = /scale\(([\d.]+)/.exec(transform); + return match ? Number(match[1]) : NaN; +}; + +describe('collapsible tree first view', () => { + it('opens only the first level when the second level would not fit the view', () => { + const root = d3.hierarchy(cloneNode(wideModel), (node) => node.children) as any; + + initializeCollapse(root); + + expect(root.children.length).toBe(12); + for (const group of root.children) { + expect(group.children).toBeUndefined(); + expect(group._children.length).toBe(4); + } + }); + + it('keeps the second level open for a small model', () => { + const root = d3.hierarchy(cloneNode(smallModel), (node) => node.children) as any; + + initializeCollapse(root); + + expect(root.children[0].children.length).toBe(1); + }); +}); + +describe('fitTransform', () => { + it('centres a tree that fits and never magnifies past 1.15', () => { + const transform = fitTransform({ width: 1000, height: 600 }, { width: 400, height: 200 }); + + expect(transform.k).toBe(1.15); + expect(transform.x).toBeCloseTo((1000 - 400 * 1.15) / 2); + expect(transform.y).toBeCloseTo((600 - 200 * 1.15) / 2); + }); + + it('scales a slightly larger tree down to fit', () => { + const transform = fitTransform({ width: 800, height: 500 }, { width: 900, height: 400 }); + + expect(transform.k).toBeCloseTo((800 / 900) * 0.92); + }); + + it('stops shrinking at the readable scale and anchors the tree to the top left', () => { + const transform = fitTransform({ width: 700, height: 500 }, { width: 1200, height: 3000 }); + + expect(MIN_READABLE_SCALE).toBe(0.75); + expect(transform.k).toBe(MIN_READABLE_SCALE); + expect(transform.x).toBe(18); + expect(transform.y).toBe(18); + }); +}); + +describe('collapsible tree rendering', () => { + let container: HTMLDivElement; + + beforeEach(() => { + container = document.createElement('div'); + container.style.width = '700px'; + container.style.height = '500px'; + document.body.appendChild(container); + }); + + afterEach(() => container.remove()); + + const create = (model: D3HierarchyNode) => + createCollapsibleTree(model, container, { onNodeClick: () => undefined, onNodeDoubleClick: () => undefined }); + + it('opens a large model at a readable scale', async () => { + const renderer = create(wideModel); + await wait(450); + + expect(layerScale(container)).toBeGreaterThanOrEqual(MIN_READABLE_SCALE); + renderer.destroy(); + }); + + it('describes a group without zero counts or the "groups/items" wording', () => { + const renderer = create(wideModel); + const meta = Array.from(container.querySelectorAll('g.group-node text.node-meta')).map((node) => node.textContent); + + expect(meta[0]).toBe('12 groups, 48 variables'); + expect(meta[1]).toBe('4 variables'); + renderer.destroy(); + }); + + it('zooms by a factor on request', async () => { + const renderer = create(smallModel); + await wait(450); + const before = layerScale(container); + + renderer.zoomBy(1.25); + await wait(450); + + expect(layerScale(container)).toBeCloseTo(before * 1.25, 2); + renderer.destroy(); + }); +}); + +describe('CollapsibleTreeBrowserComponent view controls', () => { + let fixture: ComponentFixture; + + const control = (label: string): HTMLButtonElement => + fixture.nativeElement.querySelector(`.tree-controls button[aria-label="${label}"]`); + + beforeEach(async () => { + TestBed.configureTestingModule({ + imports: [CollapsibleTreeBrowserComponent], + providers: [provideZonelessChangeDetection()], + }); + fixture = TestBed.createComponent(CollapsibleTreeBrowserComponent); + fixture.componentRef.setInput('data', smallModel); + fixture.detectChanges(); + await wait(450); + }); + + it('offers zoom in, zoom out and fit as labelled buttons', () => { + expect(control('Zoom in')).not.toBeNull(); + expect(control('Zoom out')).not.toBeNull(); + expect(control('Fit tree to view')).not.toBeNull(); + }); + + it('zooms the tree and fits it back', async () => { + const fitted = layerScale(fixture.nativeElement); + + control('Zoom out').click(); + await wait(450); + const zoomedOut = layerScale(fixture.nativeElement); + expect(zoomedOut).toBeLessThan(fitted); + + control('Zoom in').click(); + await wait(450); + expect(layerScale(fixture.nativeElement)).toBeGreaterThan(zoomedOut); + + control('Zoom out').click(); + await wait(450); + control('Fit tree to view').click(); + await wait(450); + expect(layerScale(fixture.nativeElement)).toBeCloseTo(fitted, 2); + }); +}); diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-renderer.ts b/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-renderer.ts index 6357fa5e5..85ec052af 100644 --- a/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-renderer.ts +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-renderer.ts @@ -17,6 +17,8 @@ export interface CollapsibleTreeRenderer { refreshSelection: (options?: CollapsibleTreeSelectionOptions) => void; setUnavailableVariables: (unavailable: UnavailableVariablesMap | null | undefined) => void; fitView: () => void; + /** Multiplies the current zoom by `factor`, keeping the view centre fixed. */ + zoomBy: (factor: number) => void; resize: () => void; destroy: () => void; } @@ -369,6 +371,10 @@ export function createCollapsibleTree( refreshSelection, setUnavailableVariables, fitView, + zoomBy: (factor: number) => { + void factor; + throw new Error('not implemented'); + }, resize, destroy: () => { cancelPendingAutoFit(); @@ -396,6 +402,19 @@ export function createCollapsibleTree( } } +/** Smallest scale the automatic fit may pick: below it node text is unreadable. */ +export const MIN_READABLE_SCALE = 0.75; + +/** Zoom transform that fits the tree in the view without shrinking text below the readable scale. */ +export function fitTransform( + bounds: { width: number; height: number }, + treeSize: { width: number; height: number } +): { x: number; y: number; k: number } { + void bounds; + void treeSize; + throw new Error('not implemented'); +} + export function cloneNode(node: D3HierarchyNode): RenderNode { return { ...node, diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/metadata-browser-labels.ts b/src/app/pages/experiment-studio/visualisations/metadata-browser/metadata-browser-labels.ts new file mode 100644 index 000000000..fcbd99980 --- /dev/null +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/metadata-browser-labels.ts @@ -0,0 +1,9 @@ +/** + * One-line summary of what a group holds, without zero counts: + * "4 groups, 21 variables", "2 variables", "1 group, 1 variable", "No variables". + */ +export function groupContentsLabel(groupCount: number, variableCount: number): string { + void groupCount; + void variableCount; + throw new Error('not implemented'); +} diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.spec.ts b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.spec.ts index 8baf597fa..ecfc4cb58 100644 --- a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.spec.ts +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.spec.ts @@ -163,7 +163,7 @@ describe('OntologyTreeBrowserComponent', () => { component.selectGroup(vitals); fixture.detectChanges(); - expect(component.contentsPaneSubtitle()).toBe('1 group · 1 variable'); + expect(component.contentsPaneSubtitle()).toBe('1 group, 1 variable'); // Child groups stay listed and clickable even when the group has no // direct variables. const groupRow = fixture.nativeElement.querySelector('button.content-row.group-row') as HTMLElement; diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.ts b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.ts index e0e44a611..87af4b002 100644 --- a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.ts +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.ts @@ -29,6 +29,15 @@ import { pathForGroup, } from '../metadata-browser-normalizer'; +/** Most variables of nested groups the contents pane lists before it asks the user to narrow down. */ +export const SUBTREE_VARIABLE_LIMIT = 200; + +/** A variable of a nested group, with the group names between the selected group and the variable. */ +export interface SubtreeVariableRow { + variable: NormalizedVariableNode; + path: string; +} + interface TreeRow { group: NormalizedGroupNode; depth: number; @@ -118,6 +127,15 @@ export class OntologyTreeBrowserComponent { return `${this.pluralize(group.directGroupCount, 'group')} · ${this.pluralize(group.totalVariableCount, 'variable')}`; }); + /** Variables of the selected group's nested groups (not its direct ones), capped at the limit. */ + readonly subtreeRows = computed(() => { + throw new Error('not implemented'); + }); + /** How many nested variables the cap left out; 0 when all are listed. */ + readonly subtreeOverflow = computed(() => { + throw new Error('not implemented'); + }); + readonly pluralize = pluralize; constructor() { @@ -264,6 +282,18 @@ export class OntologyTreeBrowserComponent { return unavailable ? `${variable.label}\n${unavailable}` : variable.label; } + /** Variables of the group's whole subtree that are already in the experiment pool. */ + pooledCount(group: NormalizedGroupNode): number { + void group; + throw new Error('not implemented'); + } + + /** Width (0-100) of the group's size bar: its variable count against the largest listed sibling. */ + shareOf(group: NormalizedGroupNode): number { + void group; + throw new Error('not implemented'); + } + treePadding(depth: number): number { return 10 + depth * 16; } diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.quantities.spec.ts b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.quantities.spec.ts new file mode 100644 index 000000000..f2f165a4f --- /dev/null +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.quantities.spec.ts @@ -0,0 +1,110 @@ +import { provideZonelessChangeDetection } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { D3HierarchyNode } from '../../../../../models/data-model.interface'; +import { groupContentsLabel } from '../metadata-browser-labels'; +import { OntologyTreeBrowserComponent } from './ontology-tree-browser.component'; + +describe('groupContentsLabel', () => { + it('names groups and variables with their plurals', () => { + expect(groupContentsLabel(4, 21)).toBe('4 groups, 21 variables'); + expect(groupContentsLabel(1, 1)).toBe('1 group, 1 variable'); + }); + + it('leaves out a zero group count', () => { + expect(groupContentsLabel(0, 2)).toBe('2 variables'); + expect(groupContentsLabel(0, 1)).toBe('1 variable'); + }); + + it('says when a group holds nothing', () => { + expect(groupContentsLabel(0, 0)).toBe('No variables'); + }); +}); + +describe('OntologyTreeBrowserComponent quantities', () => { + const glucose: D3HierarchyNode = { label: 'Glucose', code: 'glucose', type: 'real' }; + const model: D3HierarchyNode = { + label: 'Stroke 3.7', + code: 'Stroke', + children: [ + { + label: 'Demographics', + code: 'demographics', + children: [ + { label: 'Sex', code: 'sex', type: 'nominal' }, + { label: 'Age', code: 'age', type: 'real' }, + ], + }, + { + label: 'Vitals', + code: 'vitals', + children: [{ label: 'Metabolic', code: 'metabolic', children: [glucose] }], + }, + ], + }; + + let fixture: ComponentFixture; + + const groupRow = (label: string): HTMLElement => + (Array.from(fixture.nativeElement.querySelectorAll('button.content-row.group-row')) as HTMLElement[]) + .find((row) => row.querySelector('.row-label')?.textContent?.trim() === label)!; + const treeRow = (label: string): HTMLElement => + (Array.from(fixture.nativeElement.querySelectorAll('button.tree-row')) as HTMLElement[]) + .find((row) => row.querySelector('.tree-label')?.textContent?.trim() === label)!; + const text = (element: Element | null): string => element?.textContent?.trim() ?? ''; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [OntologyTreeBrowserComponent], + providers: [provideZonelessChangeDetection()], + }); + fixture = TestBed.createComponent(OntologyTreeBrowserComponent); + fixture.componentRef.setInput('data', model); + fixture.detectChanges(); + }); + + it('describes each listed group without zero counts', () => { + expect(text(groupRow('Demographics').querySelector('.row-meta'))).toBe('2 variables'); + expect(text(groupRow('Vitals').querySelector('.row-meta'))).toBe('1 group, 1 variable'); + }); + + it('draws a size bar per group, scaled to the largest listed group', () => { + const fill = (label: string): string => + (groupRow(label).querySelector('.row-share .row-share-fill') as HTMLElement).style.width; + + expect(fill('Demographics')).toBe('100%'); + expect(fill('Vitals')).toBe('50%'); + }); + + it('heads the two lists in sentence case', () => { + const titles = (): string[] => + (Array.from(fixture.nativeElement.querySelectorAll('.content-section-title')) as HTMLElement[]).map( + (title) => text(title) + ); + expect(titles()[0]).toBe('Groups'); + expect(titles()).not.toContain('Child groups'); + + groupRow('Demographics').click(); + fixture.detectChanges(); + expect(titles()).toEqual(['Variables']); + }); + + it('shows no pool progress while nothing was added', () => { + expect(text(treeRow('Vitals').querySelector('.tree-count'))).toBe('1'); + expect(treeRow('Vitals').querySelector('.tree-count.has-pool')).toBeNull(); + expect(groupRow('Vitals').querySelector('.row-pool')).toBeNull(); + }); + + it('shows how many variables of each group are already in the experiment', () => { + fixture.componentRef.setInput('poolVariables', [glucose]); + fixture.detectChanges(); + + expect(text(treeRow('Stroke 3.7').querySelector('.tree-count'))).toBe('1/3'); + expect(text(treeRow('Vitals').querySelector('.tree-count'))).toBe('1/1'); + expect(treeRow('Vitals').querySelector('.tree-count.has-pool')).not.toBeNull(); + expect(text(treeRow('Demographics').querySelector('.tree-count'))).toBe('2'); + expect(treeRow('Demographics').querySelector('.tree-count.has-pool')).toBeNull(); + + expect(text(groupRow('Vitals').querySelector('.row-pool'))).toBe('1 added'); + expect(groupRow('Demographics').querySelector('.row-pool')).toBeNull(); + }); +}); diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.subtree.spec.ts b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.subtree.spec.ts new file mode 100644 index 000000000..4a8776140 --- /dev/null +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.subtree.spec.ts @@ -0,0 +1,136 @@ +import { provideZonelessChangeDetection } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { D3HierarchyNode } from '../../../../../models/data-model.interface'; +import { OntologyTreeBrowserComponent, SUBTREE_VARIABLE_LIMIT } from './ontology-tree-browser.component'; + +describe('OntologyTreeBrowserComponent nested variables', () => { + const glucose: D3HierarchyNode = { label: 'Glucose', code: 'glucose', type: 'real' }; + const model: D3HierarchyNode = { + label: 'Stroke 3.7', + code: 'Stroke', + children: [ + { + label: 'Demographics', + code: 'demographics', + children: [ + { label: 'Sex', code: 'sex', type: 'nominal' }, + { label: 'Age', code: 'age', type: 'real' }, + ], + }, + { + label: 'Vitals', + code: 'vitals', + children: [{ label: 'Metabolic', code: 'metabolic', children: [glucose] }], + }, + ], + }; + + let fixture: ComponentFixture; + let component: OntologyTreeBrowserComponent; + + const text = (element: Element | null): string => element?.textContent?.trim() ?? ''; + const variableRows = (): HTMLElement[] => + Array.from(fixture.nativeElement.querySelectorAll('button.content-row.variable-row')); + const variableRow = (label: string): HTMLElement => + variableRows().find((row) => text(row.querySelector('.row-label')) === label)!; + const titles = (): string[] => + (Array.from(fixture.nativeElement.querySelectorAll('.content-section-title')) as HTMLElement[]).map(text); + const openGroup = (code: string): void => { + component.selectGroup(Object.values(component.index().groupsById).find((group) => group.code === code)!); + fixture.detectChanges(); + }; + const render = (data: D3HierarchyNode): void => { + fixture = TestBed.createComponent(OntologyTreeBrowserComponent); + component = fixture.componentInstance; + fixture.componentRef.setInput('data', data); + fixture.detectChanges(); + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [OntologyTreeBrowserComponent], + providers: [provideZonelessChangeDetection()], + }); + }); + + it('lists the variables of nested groups under the group list, each with its path', () => { + render(model); + + expect(titles()).toEqual(['Groups', 'In subgroups']); + expect(variableRows().map((row) => text(row.querySelector('.row-label'))).sort()).toEqual(['Age', 'Glucose', 'Sex']); + expect(text(variableRow('Sex').querySelector('.row-path'))).toBe('Demographics'); + expect(text(variableRow('Glucose').querySelector('.row-path'))).toBe('Vitals / Metabolic'); + }); + + it('writes the path from the selected group down, not from the root', () => { + render(model); + openGroup('vitals'); + + expect(text(variableRow('Glucose').querySelector('.row-path'))).toBe('Metabolic'); + }); + + it('adds no nested section or path to a group that only holds variables', () => { + render(model); + openGroup('demographics'); + + expect(titles()).toEqual(['Variables']); + expect(fixture.nativeElement.querySelector('.row-path')).toBeNull(); + }); + + it('keeps the pane on the current group when a nested variable is picked', () => { + render(model); + const selected: D3HierarchyNode[] = []; + component.selectedNodeChange.subscribe((node) => selected.push(node)); + + variableRow('Glucose').click(); + fixture.detectChanges(); + // The panel echoes the selection back as the highlighted node. + fixture.componentRef.setInput('highlightNode', glucose); + fixture.detectChanges(); + + expect(selected).toEqual([glucose]); + expect(component.selectedGroup().code).toBe('Stroke'); + expect(variableRow('Glucose').classList.contains('selected')).toBe(true); + }); + + it('still opens the containing group for a variable highlighted from outside', () => { + render(model); + + fixture.componentRef.setInput('highlightNode', glucose); + fixture.detectChanges(); + + expect(component.selectedGroup().code).toBe('metabolic'); + }); + + it('adds a nested variable to the pool from its row', () => { + render(model); + const toggled: D3HierarchyNode[] = []; + component.variablePoolToggle.subscribe((node) => toggled.push(node)); + + (variableRow('Glucose').querySelector('.row-add') as HTMLElement).click(); + + expect(toggled).toEqual([glucose]); + }); + + it('caps a very long nested list and says how many variables it left out', () => { + render({ + label: 'Big model', + code: 'big', + children: [ + { + label: 'Everything', + code: 'everything', + children: Array.from({ length: SUBTREE_VARIABLE_LIMIT + 5 }, (_, index) => ({ + label: `Variable ${index}`, + code: `var_${index}`, + type: 'real', + })), + }, + ], + }); + + expect(SUBTREE_VARIABLE_LIMIT).toBe(200); + expect(variableRows().length).toBe(SUBTREE_VARIABLE_LIMIT); + expect(text(fixture.nativeElement.querySelector('.subtree-more'))).toContain('5 more'); + }); +}); From f80695f34f949cd013773d75ebef5ae851c16615 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 11:33:33 +0200 Subject: [PATCH 13/22] task(03-list-quantities): List view: honest counts, size bars and pool progress --- .../metadata-browser-labels.ts | 12 ++++-- .../ontology-tree-browser.component.css | 43 ++++++++++++++++--- .../ontology-tree-browser.component.html | 26 +++++++++-- .../ontology-tree-browser.component.ts | 34 ++++++++++++--- 4 files changed, 95 insertions(+), 20 deletions(-) diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/metadata-browser-labels.ts b/src/app/pages/experiment-studio/visualisations/metadata-browser/metadata-browser-labels.ts index fcbd99980..656cd59f9 100644 --- a/src/app/pages/experiment-studio/visualisations/metadata-browser/metadata-browser-labels.ts +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/metadata-browser-labels.ts @@ -1,9 +1,15 @@ +import { pluralize } from '../../../../core/result-label.utils'; + /** * One-line summary of what a group holds, without zero counts: * "4 groups, 21 variables", "2 variables", "1 group, 1 variable", "No variables". */ export function groupContentsLabel(groupCount: number, variableCount: number): string { - void groupCount; - void variableCount; - throw new Error('not implemented'); + if (groupCount === 0 && variableCount === 0) { + return 'No variables'; + } + if (groupCount === 0) { + return pluralize(variableCount, 'variable'); + } + return `${pluralize(groupCount, 'group')}, ${pluralize(variableCount, 'variable')}`; } diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.css b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.css index 1819966e4..00373a49a 100644 --- a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.css +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.css @@ -58,7 +58,9 @@ align-items: center; gap: 7px; width: 100%; - min-height: 34px; + min-height: 36px; + padding-top: 4px; + padding-bottom: 4px; border: 0; border-bottom: 1px solid rgba(241, 245, 249, 0.9); background: transparent; @@ -155,6 +157,7 @@ overflow: hidden; font-size: 0.78rem; font-weight: 650; + line-height: 1.25; white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; @@ -167,16 +170,28 @@ background: #f1f5f9; color: var(--text-muted); font-size: 0.68rem; - font-weight: 800; + font-weight: 700; + font-variant-numeric: tabular-nums; +} + +.tree-count.has-pool, +.row-pool { + background: #fff4d6; + color: #78350f; +} + +.row-pool { + padding: 1px 6px; + border-radius: 999px; + font-size: 0.68rem; + font-weight: 700; } .content-section-title { padding: 12px 12px 6px; color: #64748b; - font-size: 0.68rem; - font-weight: 800; - letter-spacing: 0.03em; - text-transform: uppercase; + font-size: 0.74rem; + font-weight: 700; } .content-row { @@ -230,6 +245,22 @@ -webkit-line-clamp: 2; } +.row-share { + display: block; + height: 3px; + margin-top: 5px; + border-radius: 999px; + background: #e2e8f0; + max-width: 220px; +} + +.row-share-fill { + display: block; + height: 100%; + border-radius: inherit; + background: var(--primary-light); +} + .type-badge { display: inline-flex; align-items: center; diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.html b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.html index 5f54bc729..d3db6c290 100644 --- a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.html +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.html @@ -25,7 +25,21 @@ } {{ row.group.label }} - {{ row.group.totalVariableCount }} + + @if (pooledCount(row.group) > 0) { + {{ pooledCount(row.group) }}/{{ row.group.totalVariableCount }} + } @else { + {{ row.group.totalVariableCount }} + } + } @@ -42,20 +56,24 @@ } @if (selectedChildGroups().length) { -
Child groups
+
Groups
@for (group of selectedChildGroups(); track group.id) { } } @if (selectedVariables().length) { -
Direct variables
+
Variables
@for (variable of selectedVariables(); track variable.id) { + } +
diff --git a/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-chart.component.ts b/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-chart.component.ts index 01bffffe0..f0d4189d5 100644 --- a/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-chart.component.ts +++ b/src/app/pages/experiment-studio/visualisations/bubble-chart/bubble-chart.component.ts @@ -61,6 +61,7 @@ export class BubbleChartComponent implements OnInit, OnChanges, AfterViewInit, O private lastHighlighted: any = null; private zoomToNodeFn!: (d: any) => void; + private zoomToDepthFn?: (depth: number) => void; private viewReady = false; private refreshColorsFn!: (options?: { selectedVariables?: any[]; @@ -157,8 +158,7 @@ export class BubbleChartComponent implements OnInit, OnChanges, AfterViewInit, O /** Trail crumb click: zoom out to the crumb at `depth` (0 is the data model). */ zoomToTrailDepth(depth: number): void { - void depth; - throw new Error('not implemented'); + this.zoomToDepthFn?.(depth); } renderChart(): void { @@ -181,7 +181,7 @@ export class BubbleChartComponent implements OnInit, OnChanges, AfterViewInit, O const rect = container.getBoundingClientRect(); this.renderedSize = { width: Math.floor(rect.width), height: Math.floor(rect.height) }; - const { zoomToNode, refreshColors, destroy } = createZoomableCirclePacking( + const { zoomToNode, zoomToDepth, refreshColors, destroy } = createZoomableCirclePacking( this.d3Data(), container, node => this.selectedNodeChange.emit(node), @@ -190,9 +190,11 @@ export class BubbleChartComponent implements OnInit, OnChanges, AfterViewInit, O ...this.buildRefreshOptions(), onAnimationStart: () => this.isAnimating = true, onAnimationEnd: () => this.isAnimating = false, + onFocusChange: (path) => this.focusPath.set(path), } ); this.zoomToNodeFn = zoomToNode; + this.zoomToDepthFn = zoomToDepth; this.refreshColorsFn = refreshColors; this.destroyFn = destroy; diff --git a/src/app/pages/experiment-studio/visualisations/bubble-chart/zoomable-circle-packing.ts b/src/app/pages/experiment-studio/visualisations/bubble-chart/zoomable-circle-packing.ts index 8c990eb94..24f4ea230 100644 --- a/src/app/pages/experiment-studio/visualisations/bubble-chart/zoomable-circle-packing.ts +++ b/src/app/pages/experiment-studio/visualisations/bubble-chart/zoomable-circle-packing.ts @@ -99,7 +99,7 @@ export const DEFAULT_BUBBLE_COLORS: BubbleColorConfig = { variable: '#ffba08', // MIP golden yellow covariate: '#bba66f', // MIP tan/beige filter: '#483300', // MIP dark brown - selected: '#3f6078', // MIP steel blue + selected: '#2b33e9', // MIP primary blue groupStart: '#c8d5f0', // Light pale blue groupEnd: '#3340e8', // Deep blue }; @@ -440,7 +440,7 @@ export function createZoomableCirclePacking( .attr('fill-opacity', (d: any) => leafFillOpacity(d)) .attr('stroke', (d: any) => { if (isTutorialTarget(d)) return '#15803d'; - if (d === selectedDataNode) return '#000'; + if (d === selectedDataNode) return '#1b21a3'; if (d.children) return 'rgba(0,0,0,0.08)'; return 'rgba(0,0,0,0.12)'; }) @@ -641,8 +641,13 @@ export function createZoomableCirclePacking( } }, zoomToDepth: (depth: number) => { - void depth; - throw new Error('not implemented'); + let target: any = focus; + while (target.depth > depth && target.parent) { + target = target.parent; + } + if (target !== focus) { + zoom(null, target); + } }, destroy: () => { tooltip.remove(); From 5e3dcb401f7f988844aa51dab7337136f9e74d69 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 11:41:19 +0200 Subject: [PATCH 16/22] task(04-tree-readable-view): Graph view: open readable, stay readable, with view controls --- .../collapsible-tree-browser.component.css | 54 ++++++++++++++----- .../collapsible-tree-browser.component.html | 5 ++ .../collapsible-tree-browser.component.ts | 6 +-- .../collapsible-tree-renderer.ts | 42 +++++++++------ 4 files changed, 76 insertions(+), 31 deletions(-) diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.css b/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.css index 8bd80c108..7e858473c 100644 --- a/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.css +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.css @@ -9,8 +9,7 @@ flex-direction: column; height: 100%; min-height: 0; - background: - linear-gradient(180deg, rgba(248, 250, 252, 0.92), rgba(255, 255, 255, 0.96)); + background: var(--bg-neutral); color: var(--text-main); } @@ -43,20 +42,51 @@ width: 100%; height: 100%; cursor: grab; - background: - linear-gradient(rgba(226, 232, 240, 0.48) 1px, transparent 1px), - linear-gradient(90deg, rgba(226, 232, 240, 0.48) 1px, transparent 1px); - background-size: 28px 28px; } :host ::ng-deep .collapsible-tree-svg:active { cursor: grabbing; } +.tree-controls { + position: absolute; + right: 12px; + bottom: 12px; + display: flex; + flex-direction: column; + border: 1px solid var(--studio-card-border); + border-radius: var(--radius-md); + background: var(--card-bg); + box-shadow: var(--studio-card-shadow); + overflow: hidden; +} + +.tree-controls button { + display: inline-flex; + align-items: center; + justify-content: center; + width: 32px; + height: 32px; + padding: 0; + border: 0; + background: transparent; + color: var(--text-muted); + cursor: pointer; +} + +.tree-controls button:hover { + color: var(--primary-color); + background: var(--tint-nav-hover); +} + +.tree-controls button + button { + border-top: 1px solid var(--studio-card-border); +} + :host ::ng-deep .tree-link { fill: none; stroke: #cbd5e1; - stroke-width: 1.7px; + stroke-width: 1.25px; } :host ::ng-deep .collapsible-node { @@ -127,15 +157,15 @@ :host ::ng-deep .node-label { fill: var(--text-main); - font-size: 11px; - font-weight: 760; + font-size: 12px; + font-weight: 600; pointer-events: none; } :host ::ng-deep .node-meta { - fill: #64748b; - font-size: 9px; - font-weight: 620; + fill: var(--text-muted); + font-size: 10px; + font-weight: 500; pointer-events: none; } diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.html b/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.html index 7d04dc10a..8b3467f14 100644 --- a/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.html +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.html @@ -1,6 +1,11 @@
+
+ + + +
@if (error()) {
{{ error() }}
} diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.ts b/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.ts index 242ac3af3..c4742e925 100644 --- a/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.ts +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-browser.component.ts @@ -109,15 +109,15 @@ export class CollapsibleTreeBrowserComponent implements AfterViewInit, OnDestroy } zoomIn(): void { - throw new Error('not implemented'); + this.renderer?.zoomBy(1.25); } zoomOut(): void { - throw new Error('not implemented'); + this.renderer?.zoomBy(0.8); } fitTree(): void { - throw new Error('not implemented'); + this.renderer?.fitView(); } ngOnDestroy(): void { diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-renderer.ts b/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-renderer.ts index 85ec052af..5d3be65e4 100644 --- a/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-renderer.ts +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/collapsible-tree-browser/collapsible-tree-renderer.ts @@ -6,6 +6,7 @@ import { unavailableDatasetsFor, unavailableVariableTooltip, } from '../../../../../core/variable-availability.utils'; +import { groupContentsLabel } from '../metadata-browser-labels'; interface CollapsibleTreeSelectionOptions { selectedVariables?: D3HierarchyNode[]; @@ -270,16 +271,11 @@ export function createCollapsibleTree( }; const fitView = (): void => { - const scale = Math.min( - 1.15, - Math.max(0.35, Math.min(bounds.width / Math.max(treeSize.width, 1), bounds.height / Math.max(treeSize.height, 1)) * 0.92) - ); - const translateX = Math.max(18, (bounds.width - treeSize.width * scale) / 2); - const translateY = Math.max(18, (bounds.height - treeSize.height * scale) / 2); + const { x, y, k } = fitTransform(bounds, treeSize); svg .transition() .duration(duration) - .call(zoom.transform, d3.zoomIdentity.translate(translateX, translateY).scale(scale)); + .call(zoom.transform, d3.zoomIdentity.translate(x, y).scale(k)); }; const cancelPendingAutoFit = (): void => { @@ -372,8 +368,7 @@ export function createCollapsibleTree( setUnavailableVariables, fitView, zoomBy: (factor: number) => { - void factor; - throw new Error('not implemented'); + svg.transition().duration(duration).call(zoom.scaleBy, factor); }, resize, destroy: () => { @@ -410,9 +405,16 @@ export function fitTransform( bounds: { width: number; height: number }, treeSize: { width: number; height: number } ): { x: number; y: number; k: number } { - void bounds; - void treeSize; - throw new Error('not implemented'); + const k = Math.min( + 1.15, + Math.max( + MIN_READABLE_SCALE, + Math.min(bounds.width / Math.max(treeSize.width, 1), bounds.height / Math.max(treeSize.height, 1)) * 0.92 + ) + ); + const x = Math.max(18, (bounds.width - treeSize.width * k) / 2); + const y = Math.max(18, (bounds.height - treeSize.height * k) / 2); + return { x, y, k }; } export function cloneNode(node: D3HierarchyNode): RenderNode { @@ -436,13 +438,21 @@ export function focalPointForExpandedGroup(node: TreeDatum): { x: number; y: num }; } -export function initializeCollapse(root: TreeDatum): void { +export function initializeCollapse(root: TreeDatum, maxOpenRows = 14): void { root.descendants().forEach((node) => { if (node.depth > 1 && node.children) { node._children = node.children as TreeDatum[]; node.children = undefined; } }); + if (root.descendants().filter((node) => node.depth === 2).length > maxOpenRows) { + root.descendants().forEach((node) => { + if (node.depth === 1 && node.children) { + node._children = node.children as TreeDatum[]; + node.children = undefined; + } + }); + } } export function findHierarchyNode(root: TreeDatum, target: D3HierarchyNode): TreeDatum | null { @@ -541,9 +551,9 @@ function nodeMeta(node: TreeDatum): string { const type = normalizeString(node.data.type); return type || 'Variable'; } - const variableCount = countVariables(node); - const childCount = (node.children?.length ?? 0) + (node._children?.length ?? 0); - return `${childCount} groups/items · ${variableCount} variables`; + const kids = [...(node.children ?? []), ...(node._children ?? [])] as TreeDatum[]; + const groupCount = kids.filter((child) => hasChildren(child)).length; + return groupContentsLabel(groupCount, countVariables(node)); } function countVariables(node: TreeDatum): number { From 0ebc077024e47730e74a89f6372af0ec5ae47e7a Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 11:43:48 +0200 Subject: [PATCH 17/22] task(05-exploration-layout): Data exploration layout: named views, readable group chart, clear first step --- .../guide/experiment-studio-guide.content.ts | 2 +- .../selected-variables.component.html | 2 +- .../variables-panel.component.css | 19 ++++++++----------- .../variables-panel.component.html | 2 +- .../variables-panel.component.ts | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/app/pages/experiment-studio/guide/experiment-studio-guide.content.ts b/src/app/pages/experiment-studio/guide/experiment-studio-guide.content.ts index e76557146..0d65a9c40 100644 --- a/src/app/pages/experiment-studio/guide/experiment-studio-guide.content.ts +++ b/src/app/pages/experiment-studio/guide/experiment-studio-guide.content.ts @@ -87,7 +87,7 @@ export const EXPERIMENT_STUDIO_GUIDE_STEPS: ExperimentStudioGuideStep[] = [ id: 'variable-selection', section: 'Explore', title: 'Explore Variable Views', - body: 'Browse variables in Map, List, or Graph — try switching modes here, or press Next. Charts and details appear on the right.', + body: 'Browse variables in Map, List, or Tree — try switching modes here, or press Next. Charts and details appear on the right.', selector: '[data-guide="variable-selection"]', allowTargetInteraction: true, }, diff --git a/src/app/pages/experiment-studio/variables-panel/selected-variables/selected-variables.component.html b/src/app/pages/experiment-studio/variables-panel/selected-variables/selected-variables.component.html index c0e8a8803..1002698d1 100644 --- a/src/app/pages/experiment-studio/variables-panel/selected-variables/selected-variables.component.html +++ b/src/app/pages/experiment-studio/variables-panel/selected-variables/selected-variables.component.html @@ -13,7 +13,7 @@
@if (variables().length === 0) { -

No variables yet. Pick one in the map and choose Add.

+

No variables yet. Select a variable in the browser, then choose Add.

} @else {
@for (variable of variables(); track variable.code ?? variable.label) { diff --git a/src/app/pages/experiment-studio/variables-panel/variables-panel.component.css b/src/app/pages/experiment-studio/variables-panel/variables-panel.component.css index b4a549304..eb364434b 100644 --- a/src/app/pages/experiment-studio/variables-panel/variables-panel.component.css +++ b/src/app/pages/experiment-studio/variables-panel/variables-panel.component.css @@ -249,14 +249,6 @@ box-shadow: none; } -.metadata-mode-btn { - padding: 5px 10px; -} - -.metadata-mode-btn span { - display: none; -} - .visualization-parameters-row { display: grid; grid-template-columns: minmax(0, 55fr) minmax(0, 45fr); @@ -336,7 +328,7 @@ --segment-gap: 2px; position: relative; display: grid; - grid-template-columns: repeat(3, 36px); + grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--segment-gap); flex: 0 0 auto; padding: var(--segment-pad); @@ -382,9 +374,14 @@ display: inline-flex; align-items: center; justify-content: center; - width: 36px; + width: auto; height: 28px; - padding: 0; + padding: 0 12px; + gap: 6px; + font: inherit; + font-size: 0.78rem; + font-weight: 600; + white-space: nowrap; border: 0; border-radius: 999px; background: transparent; diff --git a/src/app/pages/experiment-studio/variables-panel/variables-panel.component.html b/src/app/pages/experiment-studio/variables-panel/variables-panel.component.html index e75cbd8a3..348f01489 100644 --- a/src/app/pages/experiment-studio/variables-panel/variables-panel.component.html +++ b/src/app/pages/experiment-studio/variables-panel/variables-panel.component.html @@ -304,7 +304,7 @@

No variable selected

Click a variable in the browser to see its chart and details.

} @else if (groupHistogramData()) { - + } @else if (histogramData()) { } diff --git a/src/app/pages/experiment-studio/variables-panel/variables-panel.component.ts b/src/app/pages/experiment-studio/variables-panel/variables-panel.component.ts index 4eef209b4..d505a1096 100644 --- a/src/app/pages/experiment-studio/variables-panel/variables-panel.component.ts +++ b/src/app/pages/experiment-studio/variables-panel/variables-panel.component.ts @@ -85,7 +85,7 @@ export class VariablesPanelComponent implements OnDestroy { }, { value: 'collapsible', - label: 'Graph', + label: 'Tree', icon: 'fas fa-project-diagram', title: 'Interactive collapsible hierarchy diagram', }, From 17ec1b67babc75a15b0f18d5c842baf01fd816cf Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 11:45:01 +0200 Subject: [PATCH 18/22] task(07-list-subtree-variables): List view: reach nested variables without drilling down --- .../ontology-tree-browser.component.css | 12 ++++++ .../ontology-tree-browser.component.html | 23 +++++++++-- .../ontology-tree-browser.component.ts | 40 ++++++++++++++++++- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.css b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.css index 00373a49a..7756a8a93 100644 --- a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.css +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.css @@ -234,6 +234,11 @@ -webkit-line-clamp: 2; } +.row-path { + color: var(--text-muted); + font-size: 0.68rem; +} + .row-meta, .row-description { overflow: hidden; @@ -280,6 +285,13 @@ font-size: 0.8rem; } +.subtree-more { + margin: 0; + padding: 10px 12px; + color: var(--text-muted); + font-size: 0.76rem; +} + @media (max-width: 1000px) { .ontology-layout { grid-template-columns: 1fr; diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.html b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.html index d3db6c290..482c149bb 100644 --- a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.html +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.html @@ -51,7 +51,7 @@ {{ contentsPaneSubtitle() }}
- @if (!selectedChildGroups().length && !selectedVariables().length) { + @if (!selectedChildGroups().length && !selectedVariables().length && !subtreeRows().length) {
No child groups or direct variables.
} @@ -75,6 +75,21 @@ @if (selectedVariables().length) {
Variables
@for (variable of selectedVariables(); track variable.id) { + + } + } + + @if (subtreeRows().length > 0) { +
In subgroups
+ @for (row of subtreeRows(); track row.variable.id) { + + } + @if (subtreeOverflow() > 0) { +

{{ subtreeOverflow() }} more. Open a group or use search to narrow the list.

+ } + } + + - } - } +
diff --git a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.ts b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.ts index 20702d9c5..fd2af2ea2 100644 --- a/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.ts +++ b/src/app/pages/experiment-studio/visualisations/metadata-browser/ontology-tree-browser/ontology-tree-browser.component.ts @@ -10,6 +10,7 @@ import { output, signal, } from '@angular/core'; +import { NgTemplateOutlet } from '@angular/common'; import { D3HierarchyNode } from '../../../../../models/data-model.interface'; import { EMPTY_UNAVAILABLE_VARIABLES, @@ -21,6 +22,7 @@ import { NormalizedGroupNode, NormalizedVariableNode, } from '../metadata-browser.model'; +import { pluralize } from '../../../../../core/result-label.utils'; import { groupContentsLabel } from '../metadata-browser-labels'; import { findGroupByNode, @@ -54,6 +56,7 @@ const EMPTY_METADATA_TREE: D3HierarchyNode = { @Component({ selector: 'app-ontology-tree-browser', + imports: [NgTemplateOutlet], templateUrl: './ontology-tree-browser.component.html', styleUrl: './ontology-tree-browser.component.css', changeDetection: ChangeDetectionStrategy.OnPush, @@ -69,6 +72,7 @@ export class OntologyTreeBrowserComponent { readonly variablePoolToggle = output(); @ViewChildren('treeRowButton') private treeRowButtons?: QueryList>; + private keptVariableId: string | null = null; readonly selectedGroupId = signal(null); readonly selectedVariableId = signal(null); @@ -145,16 +149,35 @@ export class OntologyTreeBrowserComponent { return counts; }); + /** Variables of nested groups under the selected group, with the path after that group. */ + private readonly subtreeMatches = computed(() => { + const G = this.selectedGroup(); + const index = this.index(); + const matches: SubtreeVariableRow[] = []; + for (const id of index.variableIds) { + const variable = index.variablesById[id]; + if (variable.parentGroupId !== G.id && variable.pathGroupIds.includes(G.id)) { + const path = variable.pathGroupIds + .slice(variable.pathGroupIds.indexOf(G.id) + 1) + .map((id) => index.groupsById[id].label) + .join(' / '); + matches.push({ variable, path }); + } + } + return matches; + }); /** Variables of the selected group's nested groups (not its direct ones), capped at the limit. */ readonly subtreeRows = computed(() => { - throw new Error('not implemented'); + // ponytail: hard cap, virtual scroll if models with thousands of variables need the full list + return this.subtreeMatches().slice(0, SUBTREE_VARIABLE_LIMIT); }); /** How many nested variables the cap left out; 0 when all are listed. */ readonly subtreeOverflow = computed(() => { - throw new Error('not implemented'); + return this.subtreeMatches().length - this.subtreeRows().length; }); readonly groupContentsLabel = groupContentsLabel; + readonly pluralize = pluralize; constructor() { effect(() => { @@ -177,6 +200,7 @@ export class OntologyTreeBrowserComponent { } selectGroup(group: NormalizedGroupNode): void { + this.keptVariableId = null; this.selectedGroupId.set(group.id); this.selectedVariableId.set(null); this.expandPathToGroup(group.id); @@ -184,6 +208,14 @@ export class OntologyTreeBrowserComponent { } selectVariable(variable: NormalizedVariableNode): void { + const selectedGroup = this.selectedGroup(); + if (variable.parentGroupId !== selectedGroup.id && variable.pathGroupIds.includes(selectedGroup.id)) { + this.selectedVariableId.set(variable.id); + this.keptVariableId = variable.id; + this.selectedNodeChange.emit(variable.original); + return; + } + this.keptVariableId = null; this.selectedGroupId.set(variable.parentGroupId); this.selectedVariableId.set(variable.id); this.expandPathToGroup(variable.parentGroupId); @@ -322,6 +354,10 @@ export class OntologyTreeBrowserComponent { const index = this.index(); const variable = findVariableByNode(index, node); if (variable) { + if (variable.id === this.keptVariableId) { + this.selectedVariableId.set(variable.id); + return; + } this.selectedGroupId.set(variable.parentGroupId); this.selectedVariableId.set(variable.id); this.expandPathToGroup(variable.parentGroupId); From 38481a63a15ac4ebc5c5b3d0bbb6ef956db5b249 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 11:45:53 +0200 Subject: [PATCH 19/22] task(06-exploration-columns): Data exploration columns: pool first, level bottoms, Add hint for variables only --- .../selected-variables.component.css | 2 ++ .../variables-panel.component.css | 10 +++++----- .../variables-panel.component.html | 16 ++++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/app/pages/experiment-studio/variables-panel/selected-variables/selected-variables.component.css b/src/app/pages/experiment-studio/variables-panel/selected-variables/selected-variables.component.css index 2ea3542ed..1f24a19ef 100644 --- a/src/app/pages/experiment-studio/variables-panel/selected-variables/selected-variables.component.css +++ b/src/app/pages/experiment-studio/variables-panel/selected-variables/selected-variables.component.css @@ -258,6 +258,8 @@ .pool-card-body { padding: 12px 16px 14px; + max-height: 120px; + overflow-y: auto; } .pool-chip { diff --git a/src/app/pages/experiment-studio/variables-panel/variables-panel.component.css b/src/app/pages/experiment-studio/variables-panel/variables-panel.component.css index eb364434b..dc64a5c4d 100644 --- a/src/app/pages/experiment-studio/variables-panel/variables-panel.component.css +++ b/src/app/pages/experiment-studio/variables-panel/variables-panel.component.css @@ -253,7 +253,7 @@ display: grid; grid-template-columns: minmax(0, 55fr) minmax(0, 45fr); gap: 24px; - align-items: start; + align-items: stretch; } .bubble-column { @@ -264,7 +264,7 @@ width: 100%; height: auto; align-items: stretch; - align-self: start; + align-self: stretch; container-type: inline-size; container-name: bubble-column; } @@ -275,7 +275,7 @@ gap: 16px; min-width: 0; width: 100%; - align-self: start; + align-self: stretch; } /* Left: bubble chart “canvas” */ @@ -286,7 +286,7 @@ z-index: 1; width: 100%; max-width: 100%; - flex-grow: 0; + flex: 1 1 auto; min-height: 0; height: auto; display: flex; @@ -477,7 +477,7 @@ } .histogram-panel { - flex: 0 0 auto; + flex: 1 1 auto; position: relative; display: flex; flex-direction: column; diff --git a/src/app/pages/experiment-studio/variables-panel/variables-panel.component.html b/src/app/pages/experiment-studio/variables-panel/variables-panel.component.html index 348f01489..c6310d355 100644 --- a/src/app/pages/experiment-studio/variables-panel/variables-panel.component.html +++ b/src/app/pages/experiment-studio/variables-panel/variables-panel.component.html @@ -153,6 +153,13 @@
From 4e4146b693075b7cebf6c25b7f35196670ff50a9 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 12:56:07 +0200 Subject: [PATCH 20/22] fix: dead-code check ignores exports used only by spec helpers (*.testing.ts) --- scripts/check-dead-code.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/check-dead-code.mjs b/scripts/check-dead-code.mjs index 23b6723d8..6b657ca11 100644 --- a/scripts/check-dead-code.mjs +++ b/scripts/check-dead-code.mjs @@ -65,7 +65,8 @@ const countIn = (haystack, name) => { const DECL = /^\s*export\s+(?:declare\s+)?(?:abstract\s+)?(?:async\s+)?(const|let|var|function|class|interface|type|enum)\s+([A-Za-z0-9_$]+)/; const deadExports = []; const appSources = ts.filter((p) => !p.endsWith('.spec.ts')); -for (const p of appSources) { +// `*.testing.ts` files exist for specs, so an export only specs import is not dead. +for (const p of appSources.filter((q) => !q.endsWith('.testing.ts'))) { const text = read(p); for (const line of text.split('\n')) { const m = DECL.exec(line); From 33ddd900de8f3793fd015165994494bf29557285 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 12:58:38 +0200 Subject: [PATCH 21/22] test: e2e helper finds the study chip, not the bubble map's location crumb --- e2e/studio.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/e2e/studio.ts b/e2e/studio.ts index 4114534f6..e980c80fe 100644 --- a/e2e/studio.ts +++ b/e2e/studio.ts @@ -6,7 +6,8 @@ export async function openNewStudio(page: Page) { await page.goto('/experiments-dashboard'); await page.getByRole('button', { name: 'New experiment' }).click(); await expect(page).toHaveURL(/\/experiment-studio\/?$/); - await expect(page.getByRole('button', { name: /Dementia/ })).toBeVisible(); + // The study chip, not the bubble map's "Dementia" location crumb. + await expect(page.locator('.study-context-chip', { hasText: /Dementia/ })).toBeVisible(); } export async function addVariable(page: Page, label: string) { From 915b8c12409aed6f9dc9e5bcb27994f907a73962 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Wed, 11 Nov 2026 14:05:47 +0200 Subject: [PATCH 22/22] test: fix spec mocks and align copy with merged content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add missing genericCatalogSteps / genericStepDroppedCodes mocks to the three specs brought in by origin/master (they predated those service methods; the component calls them unconditionally). - Pipeline header copy and Raw-data subtitle follow master's wording ('Get your selected data…', 'descriptive statistics of your unprocessed selected variables') — the integration branch had already rewritten the header, so the stranded specs never matched either copy. - Remove the 'Otherwise' fallback row from the categorical card (and its '+ fallback' suffix): records matching no rule get no value. This matches the intent statement in transformation-open.spec.ts and the behavior the integration branch chose (7c799ce). --- .../statistic-analysis-panel.copy-layout.spec.ts | 4 ++++ .../statistic-analysis-panel.summary-split.spec.ts | 4 ++++ .../statistic-analysis-panel.transformation-open.spec.ts | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.copy-layout.spec.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.copy-layout.spec.ts index 1ee52a593..9b27b5866 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.copy-layout.spec.ts +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.copy-layout.spec.ts @@ -44,6 +44,8 @@ describe('StatisticAnalysisPanelComponent copy and step layout', () => { 'hasPreprocessingSpec', 'catalogLoaded', 'stepOutputNames', + 'genericCatalogSteps', + 'genericStepDroppedCodes', ], { selectedVariables: signal([]), selectedFilters: signal([]), @@ -92,6 +94,8 @@ describe('StatisticAnalysisPanelComponent copy and step layout', () => { ['categorical_column_creator', 'kmeans_cluster_creator'].includes(name), ); mockExpService.catalogLoaded.mockReturnValue(true); + mockExpService.genericCatalogSteps.mockReturnValue([]); + mockExpService.genericStepDroppedCodes.mockReturnValue([]); mockExpService.transformationDependents.mockReturnValue([]); mockExpService.outputsInUse.mockReturnValue([]); mockExpService.upsertTransformation.mockImplementation((step: any) => { diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.summary-split.spec.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.summary-split.spec.ts index 862157c1c..13e46e838 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.summary-split.spec.ts +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.summary-split.spec.ts @@ -44,6 +44,8 @@ describe('StatisticAnalysisPanelComponent summary chart splits', () => { 'hasPreprocessingSpec', 'catalogLoaded', 'stepOutputNames', + 'genericCatalogSteps', + 'genericStepDroppedCodes', ], { selectedVariables: signal([]), selectedFilters: signal([]), @@ -92,6 +94,8 @@ describe('StatisticAnalysisPanelComponent summary chart splits', () => { ['categorical_column_creator', 'kmeans_cluster_creator'].includes(name), ); mockExpService.catalogLoaded.mockReturnValue(true); + mockExpService.genericCatalogSteps.mockReturnValue([]); + mockExpService.genericStepDroppedCodes.mockReturnValue([]); mockExpService.transformationDependents.mockReturnValue([]); mockExpService.outputsInUse.mockReturnValue([]); mockExpService.upsertTransformation.mockImplementation((step: any) => { diff --git a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.transformation-open.spec.ts b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.transformation-open.spec.ts index b56bf57df..486c9d7c2 100644 --- a/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.transformation-open.spec.ts +++ b/src/app/pages/experiment-studio/statistic-analysis-panel/statistic-analysis-panel.transformation-open.spec.ts @@ -44,6 +44,8 @@ describe('StatisticAnalysisPanelComponent transformation card open state', () => 'hasPreprocessingSpec', 'catalogLoaded', 'stepOutputNames', + 'genericCatalogSteps', + 'genericStepDroppedCodes', ], { selectedVariables: signal([]), selectedFilters: signal([]), @@ -92,6 +94,8 @@ describe('StatisticAnalysisPanelComponent transformation card open state', () => ['categorical_column_creator', 'kmeans_cluster_creator'].includes(name), ); mockExpService.catalogLoaded.mockReturnValue(true); + mockExpService.genericCatalogSteps.mockReturnValue([]); + mockExpService.genericStepDroppedCodes.mockReturnValue([]); mockExpService.transformationDependents.mockReturnValue([]); mockExpService.outputsInUse.mockReturnValue([]); mockExpService.upsertTransformation.mockImplementation((step: any) => {
Metric {{ datasetLabel(ds) }} {{ groupLabel }}{{ groupLabel }}
{{ r.metric }}{{ displayNumber(r.values[ds]) }}@if (missingShareNote(selectedBlock, r, ds); as share) {{{ share }}}