@platforma-sdk/model 1.68.5 → 1.68.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/columns/column_collection_builder.cjs +8 -2
- package/dist/columns/column_collection_builder.cjs.map +1 -1
- package/dist/columns/column_collection_builder.d.ts +14 -3
- package/dist/columns/column_collection_builder.d.ts.map +1 -1
- package/dist/columns/column_collection_builder.js +8 -2
- package/dist/columns/column_collection_builder.js.map +1 -1
- package/dist/columns/ctx_column_sources.d.ts +1 -1
- package/dist/columns/index.d.ts +1 -1
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.cjs +50 -50
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.cjs.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.d.ts +5 -10
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.d.ts.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.js +50 -50
- package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.js.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.cjs +16 -17
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.cjs.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.d.ts +4 -4
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.d.ts.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.js +16 -17
- package/dist/components/PlDataTable/createPlDataTable/discoverColumns.js.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/utils.cjs +8 -2
- package/dist/components/PlDataTable/createPlDataTable/utils.cjs.map +1 -1
- package/dist/components/PlDataTable/createPlDataTable/utils.js +8 -2
- package/dist/components/PlDataTable/createPlDataTable/utils.js.map +1 -1
- package/dist/components/PlDatasetSelector/filter_discovery.d.ts +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/labels/derive_distinct_labels.cjs +121 -50
- package/dist/labels/derive_distinct_labels.cjs.map +1 -1
- package/dist/labels/derive_distinct_labels.d.ts +30 -14
- package/dist/labels/derive_distinct_labels.d.ts.map +1 -1
- package/dist/labels/derive_distinct_labels.js +121 -50
- package/dist/labels/derive_distinct_labels.js.map +1 -1
- package/dist/labels/derive_distinct_tooltips.cjs +0 -10
- package/dist/labels/derive_distinct_tooltips.cjs.map +1 -1
- package/dist/labels/derive_distinct_tooltips.d.ts +2 -3
- package/dist/labels/derive_distinct_tooltips.d.ts.map +1 -1
- package/dist/labels/derive_distinct_tooltips.js +0 -10
- package/dist/labels/derive_distinct_tooltips.js.map +1 -1
- package/dist/labels/index.d.ts +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/package.json +4 -4
- package/src/columns/column_collection_builder.test.ts +0 -2
- package/src/columns/column_collection_builder.ts +26 -3
- package/src/components/PlDataTable/createPlDataTable/createPlDataTableV3.ts +90 -75
- package/src/components/PlDataTable/createPlDataTable/discoverColumns.ts +31 -34
- package/src/components/PlDataTable/createPlDataTable/utils.test.ts +1 -1
- package/src/components/PlDataTable/createPlDataTable/utils.ts +11 -4
- package/src/labels/derive_distinct_labels.test.ts +396 -52
- package/src/labels/derive_distinct_labels.ts +205 -103
- package/src/labels/derive_distinct_tooltips.test.ts +1 -22
- package/src/labels/derive_distinct_tooltips.ts +1 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive_distinct_labels.js","names":["isNil"],"sources":["../../src/labels/derive_distinct_labels.ts"],"sourcesContent":["import {\n Annotation,\n parseJson,\n readAnnotation,\n type PObjectSpec,\n type StringifiedJson,\n type Trace,\n} from \"@milaboratories/pl-model-common\";\nimport { throwError } from \"@milaboratories/helpers\";\nimport { isFunction, isNil } from \"es-toolkit\";\n\nexport type { Trace, TraceEntry } from \"@milaboratories/pl-model-common\";\n\nconst DISTANCE_PENALTY = 0.001;\nconst LABEL_TYPE = \"__LABEL__\";\nconst LABEL_TYPE_FULL = \"__LABEL__@1\";\n\n/** SDK-internal trace shape — adds fields used by this algorithm only, not part of the on-disk contract. */\ntype ExtendedTraceEntry = Trace[number] & {\n importance?: number;\n position?: \"prefix\" | \"suffix\";\n};\n\nexport type Entry =\n | PObjectSpec\n | {\n spec: PObjectSpec;\n /** Extra trace entries merged with the base trace from annotations. */\n extraTrace?: ExtendedTraceEntry[];\n /** Linker steps traversed to discover this column; used to append \"via $linkLabel\" to derived labels. */\n linkerPath?: { spec: PObjectSpec }[];\n };\n\nexport type DeriveLabelsOptions = {\n /** Separator to use between label parts (\" / \" by default) */\n separator?: string;\n /** If true, label will be added as suffix (at the end of the generated label). By default label added as a prefix. */\n addLabelAsSuffix?: boolean;\n /** Force inclusion of native column label */\n includeNativeLabel?: boolean;\n /** Trace elements list that will be forced to be included in the label. */\n forceTraceElements?: string[];\n /** Custom formatter for linker path suffix. Receives the array of linker labels from the full traversal chain,\n * the column spec, and the column index.\n * If returns undefined, no linker suffix is appended. By default labels are joined with \" > \" and prefixed with \"via \". */\n linkerLabelFormatter?: (\n linkerLabels: string[],\n spec: PObjectSpec,\n index: number,\n ) => string | undefined;\n};\n\nexport function deriveDistinctLabels(values: Entry[], options: DeriveLabelsOptions = {}): string[] {\n const forceTraceElements =\n options.forceTraceElements !== undefined && options.forceTraceElements.length > 0\n ? new Set(options.forceTraceElements)\n : undefined;\n const separator = options.separator ?? \" / \";\n\n // Collect per-entry linker suffixes before disambiguation\n const linkerSuffixes = values.map((v, i) => {\n const spec = \"spec\" in v && typeof v.spec === \"object\" ? v.spec : (v as PObjectSpec);\n const linkerLabels = extractLinkerLabels(v);\n if (linkerLabels.length === 0) return undefined;\n return isFunction(options.linkerLabelFormatter)\n ? options.linkerLabelFormatter(linkerLabels, spec, i)\n : `via ${linkerLabels.join(\" > \")}`;\n });\n\n // Phase 1: enrich each value with parsed trace\n const records = values.map((v) => enrichRecord(v, options));\n\n // Phase 2: collect global type statistics\n const stats = collectTypeStats(records);\n\n // Phase 3: classify types into main (present everywhere) and secondary\n const { mainTypes, secondaryTypes } = classifyTypes(stats, values.length);\n\n const build = (typeSet: Set<string>, force: boolean) =>\n buildLabels(records, typeSet, forceTraceElements, separator, force);\n\n if (mainTypes.length === 0) {\n if (secondaryTypes.length !== 0)\n throw new Error(\"Non-empty secondary types list while main types list is empty.\");\n\n return applyLinkerSuffixes(\n build(new Set(LABEL_TYPE_FULL), true) ??\n throwError(\"Failed to derive labels using native column labels\"),\n linkerSuffixes,\n );\n }\n\n // Phase 4: search for minimal type set that produces unique labels\n //\n // includedCount = 2\n // * *\n // T0 T1 T2 T3 T4 T5\n // *\n // additionalType = 3\n //\n // Resulting set: T0, T1, T3\n //\n let includedCount = 0;\n let additionalType = -1;\n while (includedCount < mainTypes.length) {\n const currentSet = new Set<string>();\n if (options.includeNativeLabel) currentSet.add(LABEL_TYPE_FULL);\n for (let i = 0; i < includedCount; ++i) currentSet.add(mainTypes[i]);\n if (additionalType >= 0) currentSet.add(mainTypes[additionalType]);\n\n const candidateResult = build(currentSet, false);\n if (candidateResult !== undefined && countUniqueLabels(candidateResult) === values.length) {\n const minimized = minimizeTypeSet(\n currentSet,\n records,\n stats,\n forceTraceElements,\n options,\n separator,\n );\n return applyLinkerSuffixes(\n build(minimized, false) ?? throwError(\"Failed to derive unique labels\"),\n linkerSuffixes,\n );\n }\n\n additionalType++;\n if (additionalType >= mainTypes.length) {\n includedCount++;\n additionalType = includedCount;\n }\n }\n\n // Fallback: include all types, then minimize\n const fallbackSet = new Set([...mainTypes, ...secondaryTypes]);\n const minimized = minimizeTypeSet(\n fallbackSet,\n records,\n stats,\n forceTraceElements,\n options,\n separator,\n );\n return applyLinkerSuffixes(\n build(minimized, true) ?? throwError(\"Failed to derive unique labels\"),\n linkerSuffixes,\n );\n}\n\n/** Apply pre-formatted linker suffixes to labels that have them. */\nfunction applyLinkerSuffixes(labels: string[], suffixes: (string | undefined)[]): string[] {\n return labels.map((label, i) => (isNil(suffixes[i]) ? label : `${label} ${suffixes[i]}`));\n}\n\n/** Extract linker labels from every step of the linkers path. */\nfunction extractLinkerLabels(entry: Entry): string[] {\n if (!(\"spec\" in entry) || typeof entry.spec !== \"object\") return [];\n const path = entry.linkerPath;\n if (path === undefined || path.length === 0) return [];\n const labels: string[] = [];\n for (const step of path) {\n const label = (\n readAnnotation(step.spec, Annotation.LinkLabel) ?? readAnnotation(step.spec, Annotation.Label)\n )?.trim();\n if (label !== undefined && label.length > 0) {\n labels.push(label);\n }\n }\n return labels;\n}\n\n// --- Pure helpers ---\ntype FullTraceEntry = ExtendedTraceEntry & { fullType: string; occurrenceIndex: number };\n\ntype EnrichedRecord = {\n fullTrace: FullTraceEntry[];\n};\n\nfunction extractSpecAndTrace(entry: Entry): {\n spec: PObjectSpec;\n extraTrace: ExtendedTraceEntry[] | undefined;\n linkerPath: { spec: PObjectSpec }[] | undefined;\n} {\n const isEnriched = \"spec\" in entry && typeof entry.spec === \"object\";\n return {\n spec: isEnriched ? entry.spec : (entry as PObjectSpec),\n extraTrace: isEnriched ? entry.extraTrace : undefined,\n linkerPath: isEnriched ? entry.linkerPath : undefined,\n };\n}\n\nfunction buildFullTrace(trace: ExtendedTraceEntry[]): FullTraceEntry[] {\n const result: FullTraceEntry[] = [];\n const occurrences = new Map<string, number>();\n\n for (let i = trace.length - 1; i >= 0; --i) {\n const entry = trace[i];\n const occurrenceIndex = (occurrences.get(entry.type) ?? 0) + 1;\n occurrences.set(entry.type, occurrenceIndex);\n result.push({\n ...entry,\n fullType: `${entry.type}@${occurrenceIndex}`,\n occurrenceIndex,\n });\n }\n\n result.reverse();\n return result;\n}\n\nfunction enrichRecord(value: Entry, options: DeriveLabelsOptions): EnrichedRecord {\n const { spec, extraTrace } = extractSpecAndTrace(value);\n\n const label = readAnnotation(spec, Annotation.Label);\n const traceStr = readAnnotation(spec, Annotation.Trace);\n const baseTrace = traceStr\n ? (parseJson(traceStr as StringifiedJson<ExtendedTraceEntry[]>) ?? [])\n : [];\n const prefixExtra = extraTrace?.filter((e) => e.position === \"prefix\") ?? [];\n const suffixExtra = extraTrace?.filter((e) => e.position !== \"prefix\") ?? [];\n const trace = [...prefixExtra, ...baseTrace, ...suffixExtra];\n\n if (label !== undefined) {\n const labelEntry = { label, type: LABEL_TYPE, importance: -2 };\n if (options.addLabelAsSuffix) trace.push(labelEntry);\n else trace.splice(0, 0, labelEntry);\n }\n\n return { fullTrace: buildFullTrace(trace) };\n}\n\ntype TypeStats = {\n importances: Map<string, number>;\n countByType: Map<string, number>;\n};\n\nfunction collectTypeStats(records: EnrichedRecord[]): TypeStats {\n const importances = new Map<string, number>();\n const countByType = new Map<string, number>();\n\n for (const record of records) {\n for (let i = 0; i < record.fullTrace.length; i++) {\n const { fullType, importance: rawImportance } = record.fullTrace[i];\n const importance = rawImportance ?? 0;\n const distance = (record.fullTrace.length - i) * DISTANCE_PENALTY;\n\n countByType.set(fullType, (countByType.get(fullType) ?? 0) + 1);\n importances.set(\n fullType,\n Math.max(importances.get(fullType) ?? Number.NEGATIVE_INFINITY, importance - distance),\n );\n }\n }\n\n return { importances, countByType };\n}\n\nfunction classifyTypes(\n stats: TypeStats,\n totalRecords: number,\n): { mainTypes: string[]; secondaryTypes: string[] } {\n const sorted = [...stats.importances].sort(([, i1], [, i2]) => i2 - i1);\n\n const mainTypes: string[] = [];\n const secondaryTypes: string[] = [];\n\n for (const [typeName] of sorted) {\n if (typeName.endsWith(\"@1\") || stats.countByType.get(typeName) === totalRecords)\n mainTypes.push(typeName);\n else secondaryTypes.push(typeName);\n }\n\n return { mainTypes, secondaryTypes };\n}\n\nfunction buildLabels(\n records: EnrichedRecord[],\n includedTypes: Set<string>,\n forceTraceElements: Set<string> | undefined,\n separator: string,\n force: boolean,\n): string[] | undefined {\n const result: string[] = [];\n\n for (const r of records) {\n const parts: string[] = [];\n for (const ft of r.fullTrace) {\n if (includedTypes.has(ft.fullType) || forceTraceElements?.has(ft.type)) {\n parts.push(ft.label);\n }\n }\n\n if (parts.length === 0) {\n if (!force) return undefined;\n result.push(\"Unlabeled\");\n continue;\n }\n\n result.push(parts.join(separator));\n }\n\n return result;\n}\n\nfunction countUniqueLabels(result: string[] | undefined): number {\n if (result === undefined) return 0;\n return new Set(result).size;\n}\n\nfunction minimizeTypeSet(\n typeSet: Set<string>,\n records: EnrichedRecord[],\n stats: TypeStats,\n forceTraceElements: Set<string> | undefined,\n options: DeriveLabelsOptions,\n separator: string,\n): Set<string> {\n const initialResult = buildLabels(records, typeSet, forceTraceElements, separator, false);\n if (initialResult === undefined) return typeSet;\n\n const targetCardinality = countUniqueLabels(initialResult);\n const result = new Set(typeSet);\n\n const removable = [...result]\n .filter(\n (t) =>\n !forceTraceElements?.has(t.split(\"@\")[0]) &&\n !(options.includeNativeLabel && t === LABEL_TYPE_FULL),\n )\n .sort((a, b) => (stats.importances.get(a) ?? 0) - (stats.importances.get(b) ?? 0));\n\n for (const typeToRemove of removable) {\n const candidate = new Set(result);\n candidate.delete(typeToRemove);\n const candidateResult = buildLabels(records, candidate, forceTraceElements, separator, false);\n if (candidateResult !== undefined && countUniqueLabels(candidateResult) >= targetCardinality) {\n result.delete(typeToRemove);\n }\n }\n\n return result;\n}\n"],"mappings":";;;;AAaA,MAAM,mBAAmB;AACzB,MAAM,aAAa;AACnB,MAAM,kBAAkB;AAqCxB,SAAgB,qBAAqB,QAAiB,UAA+B,EAAE,EAAY;CACjG,MAAM,qBACJ,QAAQ,uBAAuB,KAAA,KAAa,QAAQ,mBAAmB,SAAS,IAC5E,IAAI,IAAI,QAAQ,mBAAmB,GACnC,KAAA;CACN,MAAM,YAAY,QAAQ,aAAa;CAGvC,MAAM,iBAAiB,OAAO,KAAK,GAAG,MAAM;EAC1C,MAAM,OAAO,UAAU,KAAK,OAAO,EAAE,SAAS,WAAW,EAAE,OAAQ;EACnE,MAAM,eAAe,oBAAoB,EAAE;AAC3C,MAAI,aAAa,WAAW,EAAG,QAAO,KAAA;AACtC,SAAO,WAAW,QAAQ,qBAAqB,GAC3C,QAAQ,qBAAqB,cAAc,MAAM,EAA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A,KAAa,kBAAkB,gBAAgB,IAAI,kBACzE,QAAO,OAAO,aAAa;;AAI/B,QAAO"}
|
|
1
|
+
{"version":3,"file":"derive_distinct_labels.js","names":["isNil"],"sources":["../../src/labels/derive_distinct_labels.ts"],"sourcesContent":["import {\n Annotation,\n parseJson,\n readAnnotation,\n type AxisQualification,\n type PObjectId,\n type PObjectSpec,\n type StringifiedJson,\n type Trace,\n} from \"@milaboratories/pl-model-common\";\nimport { throwError } from \"@milaboratories/helpers\";\nimport { isFunction, isNil } from \"es-toolkit\";\nimport type { MatchQualifications } from \"../columns/column_collection_builder\";\n\nexport type { Trace, TraceEntry } from \"@milaboratories/pl-model-common\";\n\nconst DISTANCE_PENALTY = 0.001;\nconst LABEL_TYPE = \"__LABEL__\";\nconst LABEL_TYPE_FULL = \"__LABEL__@1\";\nconst LINKER_TYPE = \"__LINKER__\";\nconst LINKER_TYPE_FULL = \"__LINKER__@1\";\nconst HIT_QUAL_TYPE = \"__HIT_QUAL__\";\nconst ANCHOR_QUAL_TYPE_PREFIX = \"__ANCHOR_QUAL__:\";\n\nfunction isAnchorQualType(t: string): boolean {\n return t.startsWith(ANCHOR_QUAL_TYPE_PREFIX);\n}\n\nfunction isSyntheticType(t: string): boolean {\n return t === LINKER_TYPE || t === HIT_QUAL_TYPE || isAnchorQualType(t);\n}\n\n/** SDK-internal trace shape — adds fields used by this algorithm only, not part of the on-disk contract. */\ntype ExtendedTraceEntry = Trace[number] & {\n importance?: number;\n position?: \"prefix\" | \"suffix\";\n};\n\nexport type LinkerStep = {\n spec: PObjectSpec;\n qualifications?: AxisQualification[];\n};\n\nexport type Entry =\n | PObjectSpec\n | {\n spec: PObjectSpec;\n /** Extra trace entries merged with the base trace from annotations. */\n extraTrace?: ExtendedTraceEntry[];\n /** Linker steps traversed to discover this column; rendered as \"via …\" only when needed for uniqueness. */\n linkerPath?: LinkerStep[];\n /** Axis qualifications applied to the hit column / already-bound anchors; rendered as \"[…]\" suffixes. */\n qualifications?: MatchQualifications;\n };\n\n/**\n * Per-zone formatters. Each one receives raw inputs and returns the rendered text for that zone,\n * or `undefined` to suppress the zone entirely (no synthetic injection → no minimization, no render).\n */\nexport type DeriveLabelsFormatters = {\n /** Native column label. Default: identity. `undefined` → label entry not added (treated as if spec had no label). */\n native?: (label: string, spec: PObjectSpec, index: number) => string | undefined;\n /** Linker zone (whole \"via …\" piece). Receives step labels with step-quals already inlined.\n * Default: `via ${steps.join(\" > \")}`. */\n linker?: (linkerLabels: string[], spec: PObjectSpec, index: number) => string | undefined;\n /** Per-step linker qualifications inlined into the step base label.\n * Default: `[${formatQualifications(qs)}]`. `undefined` → step rendered without quals. */\n linkerStepQualification?: (\n qualifications: AxisQualification[],\n stepIndex: number,\n stepSpec: PObjectSpec,\n ) => string | undefined;\n /** Hit-axis qualifications block. Default: `[${formatQualifications(qs)}]`. */\n hitQualification?: (\n qualifications: AxisQualification[],\n spec: PObjectSpec,\n index: number,\n ) => string | undefined;\n /** Per-anchor qualifications block. Default: `[${anchorId}: ${formatQualifications(qs)}]`. */\n anchorQualification?: (\n anchorId: PObjectId,\n qualifications: AxisQualification[],\n spec: PObjectSpec,\n index: number,\n ) => string | undefined;\n};\n\nexport type DeriveLabelsOptions = {\n /** Separator to use between label parts (\" / \" by default). */\n separator?: string;\n /** If true, native label is appended at the end of the trace zone. By default it is prepended (label is the most important name). */\n addLabelAsSuffix?: boolean;\n /** Force inclusion of native column label even when not needed for uniqueness. */\n includeNativeLabel?: boolean;\n /** Trace types that must be included in the label. */\n forceTraceElements?: string[];\n /** Per-zone custom formatters. Returning `undefined` from any formatter suppresses the corresponding zone. */\n formatters?: DeriveLabelsFormatters;\n};\n\nexport function deriveDistinctLabels(values: Entry[], options: DeriveLabelsOptions = {}): string[] {\n const forceTraceElements =\n options.forceTraceElements !== undefined && options.forceTraceElements.length > 0\n ? new Set(options.forceTraceElements)\n : undefined;\n const separator = options.separator ?? \" / \";\n\n const records = values.map((v, i) => enrichRecord(v, i, options));\n const stats = collectTypeStats(records);\n\n const hasAnySynthetic = records.some((r) => r.fullTrace.some((ft) => isSyntheticType(ft.type)));\n const labelForced =\n (options.includeNativeLabel === true || hasAnySynthetic) &&\n stats.countByType.has(LABEL_TYPE_FULL);\n // Tied to labeled-step presence, not path presence: entries with a non-empty linkerPath\n // but no labeled steps contribute no LINKER_TYPE trace entry, so they do not count here.\n const linkerForced = stats.countByType.get(LINKER_TYPE_FULL) === values.length;\n\n const forcedSet = new Set<string>();\n if (labelForced) forcedSet.add(LABEL_TYPE_FULL);\n if (linkerForced) forcedSet.add(LINKER_TYPE_FULL);\n\n const { mainTypes, secondaryTypes } = classifyTypes(stats, values.length);\n\n const build = (typeSet: Set<string>, force: boolean) =>\n buildLabels(records, typeSet, forceTraceElements, separator, force);\n\n if (mainTypes.length === 0) {\n if (secondaryTypes.length !== 0)\n throw new Error(\"Non-empty secondary types list while main types list is empty.\");\n\n return (\n build(new Set([LABEL_TYPE_FULL]), true) ??\n throwError(\"Failed to derive labels using native column labels\")\n );\n }\n\n let includedCount = 0;\n let additionalType = -1;\n while (includedCount < mainTypes.length) {\n const currentSet = new Set<string>(forcedSet);\n for (let i = 0; i < includedCount; ++i) currentSet.add(mainTypes[i]);\n if (additionalType >= 0) currentSet.add(mainTypes[additionalType]);\n\n const candidateResult = build(currentSet, false);\n if (candidateResult !== undefined && countUniqueLabels(candidateResult) === values.length) {\n const minimized = minimizeTypeSet(\n currentSet,\n records,\n stats,\n forceTraceElements,\n forcedSet,\n separator,\n );\n return build(minimized, false) ?? throwError(\"Failed to derive unique labels\");\n }\n\n additionalType++;\n if (additionalType >= mainTypes.length) {\n includedCount++;\n additionalType = includedCount;\n }\n }\n\n const fallbackSet = new Set([...forcedSet, ...mainTypes, ...secondaryTypes]);\n const minimized = minimizeTypeSet(\n fallbackSet,\n records,\n stats,\n forceTraceElements,\n forcedSet,\n separator,\n );\n return build(minimized, true) ?? throwError(\"Failed to derive unique labels\");\n}\n\n// --- Pure helpers ---\ntype FullTraceEntry = ExtendedTraceEntry & { fullType: string; occurrenceIndex: number };\n\ntype EnrichedRecord = {\n fullTrace: FullTraceEntry[];\n};\n\nfunction extractEntryParts(entry: Entry): {\n spec: PObjectSpec;\n extraTrace: ExtendedTraceEntry[] | undefined;\n linkerPath: LinkerStep[] | undefined;\n qualifications: MatchQualifications | undefined;\n} {\n const isEnriched = \"spec\" in entry && typeof entry.spec === \"object\";\n if (!isEnriched) {\n return {\n spec: entry as PObjectSpec,\n extraTrace: undefined,\n linkerPath: undefined,\n qualifications: undefined,\n };\n }\n return {\n spec: entry.spec,\n extraTrace: entry.extraTrace,\n linkerPath: entry.linkerPath,\n qualifications: entry.qualifications,\n };\n}\n\nfunction formatQualification(q: AxisQualification): string {\n const ctx = q.contextDomain ?? {};\n const keys = Object.keys(ctx);\n if (keys.length === 0) return q.axis.name;\n const pairs = keys.map((k) => `${k}=${ctx[k]}`).join(\", \");\n return Object.prototype.hasOwnProperty.call(ctx, q.axis.name) ? pairs : `${q.axis.name} ${pairs}`;\n}\n\nfunction formatQualifications(qs: AxisQualification[]): string {\n return qs.map(formatQualification).join(\"; \");\n}\n\nfunction computeStepLabel(\n step: LinkerStep,\n stepIndex: number,\n formatters: DeriveLabelsFormatters | undefined,\n): string | undefined {\n const base = (\n readAnnotation(step.spec, Annotation.LinkLabel) ?? readAnnotation(step.spec, Annotation.Label)\n )?.trim();\n if (isNil(base) || base.length === 0) return undefined;\n if (step.qualifications === undefined || step.qualifications.length === 0) return base;\n const qualText = isFunction(formatters?.linkerStepQualification)\n ? formatters.linkerStepQualification(step.qualifications, stepIndex, step.spec)\n : `[${formatQualifications(step.qualifications)}]`;\n return isNil(qualText) ? base : `${base} ${qualText}`;\n}\n\nfunction buildFullTrace(trace: ExtendedTraceEntry[]): FullTraceEntry[] {\n const result: FullTraceEntry[] = [];\n const occurrences = new Map<string, number>();\n\n for (let i = trace.length - 1; i >= 0; --i) {\n const entry = trace[i];\n const occurrenceIndex = (occurrences.get(entry.type) ?? 0) + 1;\n occurrences.set(entry.type, occurrenceIndex);\n result.push({\n ...entry,\n fullType: `${entry.type}@${occurrenceIndex}`,\n occurrenceIndex,\n });\n }\n\n result.reverse();\n return result;\n}\n\nfunction enrichRecord(value: Entry, index: number, options: DeriveLabelsOptions): EnrichedRecord {\n const { spec, extraTrace, linkerPath, qualifications } = extractEntryParts(value);\n const formatters = options.formatters;\n\n const rawLabel = readAnnotation(spec, Annotation.Label);\n const traceStr = readAnnotation(spec, Annotation.Trace);\n const baseTrace = traceStr\n ? (parseJson(traceStr as StringifiedJson<ExtendedTraceEntry[]>) ?? [])\n : [];\n const prefixExtra = extraTrace?.filter((e) => e.position === \"prefix\") ?? [];\n const suffixExtra = extraTrace?.filter((e) => e.position !== \"prefix\") ?? [];\n const trace: ExtendedTraceEntry[] = [...prefixExtra, ...baseTrace, ...suffixExtra];\n\n if (!isNil(rawLabel)) {\n const label = isFunction(formatters?.native)\n ? formatters.native(rawLabel, spec, index)\n : rawLabel;\n if (!isNil(label)) {\n const labelEntry = { label, type: LABEL_TYPE, importance: -2 };\n if (options.addLabelAsSuffix === true) trace.push(labelEntry);\n else trace.splice(0, 0, labelEntry);\n }\n }\n\n if (linkerPath !== undefined && linkerPath.length > 0) {\n const stepLabels = linkerPath\n .map((step, i) => computeStepLabel(step, i, formatters))\n .filter((s): s is string => !isNil(s));\n if (stepLabels.length > 0) {\n const linkerText = isFunction(formatters?.linker)\n ? formatters.linker(stepLabels, spec, index)\n : `via ${stepLabels.join(\" > \")}`;\n if (!isNil(linkerText)) {\n trace.push({ type: LINKER_TYPE, label: linkerText, importance: -10 });\n }\n }\n }\n\n if (qualifications !== undefined) {\n for (const [anchorId, qs] of Object.entries(qualifications.forQueries)) {\n if (qs.length === 0) continue;\n const anchorText = isFunction(formatters?.anchorQualification)\n ? formatters.anchorQualification(anchorId as PObjectId, qs, spec, index)\n : `[${anchorId}: ${formatQualifications(qs)}]`;\n if (isNil(anchorText)) continue;\n trace.push({\n type: `${ANCHOR_QUAL_TYPE_PREFIX}${anchorId}`,\n label: anchorText,\n importance: -11,\n });\n }\n if (qualifications.forHit.length > 0) {\n const hitText = isFunction(formatters?.hitQualification)\n ? formatters.hitQualification(qualifications.forHit, spec, index)\n : `[${formatQualifications(qualifications.forHit)}]`;\n if (!isNil(hitText)) {\n trace.push({ type: HIT_QUAL_TYPE, label: hitText, importance: -12 });\n }\n }\n }\n\n return { fullTrace: buildFullTrace(trace) };\n}\n\ntype TypeStats = {\n importances: Map<string, number>;\n countByType: Map<string, number>;\n};\n\nfunction collectTypeStats(records: EnrichedRecord[]): TypeStats {\n const importances = new Map<string, number>();\n const countByType = new Map<string, number>();\n\n for (const record of records) {\n for (let i = 0; i < record.fullTrace.length; i++) {\n const { fullType, importance: rawImportance } = record.fullTrace[i];\n const importance = rawImportance ?? 0;\n const distance = (record.fullTrace.length - i) * DISTANCE_PENALTY;\n\n countByType.set(fullType, (countByType.get(fullType) ?? 0) + 1);\n importances.set(\n fullType,\n Math.max(importances.get(fullType) ?? Number.NEGATIVE_INFINITY, importance - distance),\n );\n }\n }\n\n return { importances, countByType };\n}\n\nfunction classifyTypes(\n stats: TypeStats,\n totalRecords: number,\n): { mainTypes: string[]; secondaryTypes: string[] } {\n const sorted = [...stats.importances].sort(([, i1], [, i2]) => i2 - i1);\n\n const mainTypes: string[] = [];\n const secondaryTypes: string[] = [];\n\n for (const [typeName] of sorted) {\n if (typeName.endsWith(\"@1\") || stats.countByType.get(typeName) === totalRecords)\n mainTypes.push(typeName);\n else secondaryTypes.push(typeName);\n }\n\n return { mainTypes, secondaryTypes };\n}\n\nfunction buildLabels(\n records: EnrichedRecord[],\n includedTypes: Set<string>,\n forceTraceElements: Set<string> | undefined,\n separator: string,\n force: boolean,\n): string[] | undefined {\n const result: string[] = [];\n\n for (const r of records) {\n const traceParts: string[] = [];\n const anchorParts: string[] = [];\n let linkerLabel: string | undefined;\n let hitLabel: string | undefined;\n\n for (const ft of r.fullTrace) {\n if (!(includedTypes.has(ft.fullType) || forceTraceElements?.has(ft.type))) continue;\n if (ft.type === LINKER_TYPE) linkerLabel = ft.label;\n else if (ft.type === HIT_QUAL_TYPE) hitLabel = ft.label;\n else if (isAnchorQualType(ft.type)) anchorParts.push(ft.label);\n else traceParts.push(ft.label);\n }\n\n const isEmpty =\n traceParts.length === 0 &&\n anchorParts.length === 0 &&\n linkerLabel === undefined &&\n hitLabel === undefined;\n\n if (isEmpty) {\n if (!force) return undefined;\n result.push(\"Unlabeled\");\n continue;\n }\n\n let label = traceParts.join(separator);\n const append = (part: string) => {\n label = label.length === 0 ? part : `${label} ${part}`;\n };\n if (linkerLabel !== undefined) append(linkerLabel);\n for (const a of anchorParts) append(a);\n if (hitLabel !== undefined) append(hitLabel);\n\n result.push(label);\n }\n\n return result;\n}\n\nfunction countUniqueLabels(result: string[] | undefined): number {\n if (result === undefined) return 0;\n return new Set(result).size;\n}\n\nfunction minimizeTypeSet(\n typeSet: Set<string>,\n records: EnrichedRecord[],\n stats: TypeStats,\n forceTraceElements: Set<string> | undefined,\n forcedSet: Set<string>,\n separator: string,\n): Set<string> {\n const initialResult = buildLabels(records, typeSet, forceTraceElements, separator, false);\n if (initialResult === undefined) return typeSet;\n\n const targetCardinality = countUniqueLabels(initialResult);\n const result = new Set(typeSet);\n\n const removable = [...result]\n .filter((t) => !forceTraceElements?.has(t.split(\"@\")[0]) && !forcedSet.has(t))\n .sort((a, b) => (stats.importances.get(a) ?? 0) - (stats.importances.get(b) ?? 0));\n\n for (const typeToRemove of removable) {\n const candidate = new Set(result);\n candidate.delete(typeToRemove);\n const candidateResult = buildLabels(records, candidate, forceTraceElements, separator, false);\n if (candidateResult !== undefined && countUniqueLabels(candidateResult) >= targetCardinality) {\n result.delete(typeToRemove);\n }\n }\n\n return result;\n}\n"],"mappings":";;;;AAgBA,MAAM,mBAAmB;AACzB,MAAM,aAAa;AACnB,MAAM,kBAAkB;AACxB,MAAM,cAAc;AACpB,MAAM,mBAAmB;AACzB,MAAM,gBAAgB;AACtB,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,YAAY,IAAI,EAAE,IAAI,GAAG;AAEpF,MAAK,MAAM,gBAAgB,WAAW;EACpC,MAAM,YAAY,IAAI,IAAI,OAAO;AACjC,YAAU,OAAO,aAAa;EAC9B,MAAM,kBAAkB,YAAY,SAAS,WAAW,oBAAoB,WAAW,MAAM;AAC7F,MAAI,oBAAoB,KAAA,KAAa,kBAAkB,gBAAgB,IAAI,kBACzE,QAAO,OAAO,aAAa;;AAI/B,QAAO"}
|
|
@@ -16,8 +16,6 @@ function formatTooltip(entry) {
|
|
|
16
16
|
if (anchors !== void 0) sections.push(anchors);
|
|
17
17
|
const hit = formatHit(entry.qualifications);
|
|
18
18
|
if (hit !== void 0) sections.push(hit);
|
|
19
|
-
const distinctive = formatDistinctive(entry.distinctiveQualifications);
|
|
20
|
-
if (distinctive !== void 0) sections.push(distinctive);
|
|
21
19
|
if (sections.length <= 1) return void 0;
|
|
22
20
|
return sections.join("\n\n");
|
|
23
21
|
}
|
|
@@ -61,14 +59,6 @@ function formatHit(q) {
|
|
|
61
59
|
if (rendered === void 0) return void 0;
|
|
62
60
|
return ["Hit column qualifications", `${BULLET_1}${rendered}`].join("\n");
|
|
63
61
|
}
|
|
64
|
-
function formatDistinctive(q) {
|
|
65
|
-
if ((0, es_toolkit.isNil)(q)) return void 0;
|
|
66
|
-
const bullets = [];
|
|
67
|
-
for (const id of Object.keys(q.forQueries)) for (const item of q.forQueries[id]) bullets.push(`${BULLET_1}${id}: ${formatQualification(item)}`);
|
|
68
|
-
for (const item of q.forHit) bullets.push(`${BULLET_1}hit: ${formatQualification(item)}`);
|
|
69
|
-
if (bullets.length === 0) return void 0;
|
|
70
|
-
return ["Distinctive (what separates this variant)", ...bullets].join("\n");
|
|
71
|
-
}
|
|
72
62
|
function formatAxisQualifications(qs) {
|
|
73
63
|
if (qs.length === 0) return void 0;
|
|
74
64
|
return qs.map(formatQualification).join("; ");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive_distinct_tooltips.cjs","names":["Annotation"],"sources":["../../src/labels/derive_distinct_tooltips.ts"],"sourcesContent":["import {\n Annotation,\n PObjectId,\n readAnnotation,\n type AxisQualification,\n type PColumnSpec,\n} from \"@milaboratories/pl-model-common\";\nimport { isNil } from \"es-toolkit\";\nimport type { MatchQualifications, MatchVariant } from \"../columns\";\n\nexport type TooltipEntry = {\n /** Main column spec — used for column-name fallback when no label. */\n spec: PColumnSpec;\n /**
|
|
1
|
+
{"version":3,"file":"derive_distinct_tooltips.cjs","names":["Annotation"],"sources":["../../src/labels/derive_distinct_tooltips.ts"],"sourcesContent":["import {\n Annotation,\n PObjectId,\n readAnnotation,\n type AxisQualification,\n type PColumnSpec,\n} from \"@milaboratories/pl-model-common\";\nimport { isNil } from \"es-toolkit\";\nimport type { MatchQualifications, MatchVariant } from \"../columns\";\n\nexport type TooltipEntry = {\n /** Main column spec — used for column-name fallback when no label. */\n spec: PColumnSpec;\n /** Qualifications carried by this variant. */\n qualifications?: MatchQualifications;\n /** Linker steps traversed to reach the hit column. */\n linkerPath?: MatchVariant[\"path\"];\n /** Position of this variant within the same physical column (1-based). */\n variantIndex?: number;\n /** Total variants for the same physical column. */\n variantCount?: number;\n};\n\n/** Format tooltip strings for each entry. Returns `undefined` when nothing useful. */\nexport function deriveDistinctTooltips(entries: TooltipEntry[]): (undefined | string)[] {\n return entries.map(formatTooltip);\n}\n\nfunction formatTooltip(entry: TooltipEntry): undefined | string {\n const sections: string[] = [];\n\n const header = formatHeader(entry);\n if (header !== undefined) sections.push(header);\n\n const origin = formatOriginPath(entry);\n if (origin !== undefined) sections.push(origin);\n\n const anchors = formatAnchors(entry.qualifications);\n if (anchors !== undefined) sections.push(anchors);\n\n const hit = formatHit(entry.qualifications);\n if (hit !== undefined) sections.push(hit);\n\n if (sections.length <= 1) return undefined;\n return sections.join(\"\\n\\n\");\n}\n\nconst BULLET_1 = \" • \";\nconst SUB_BULLET = \" \";\n\nfunction formatHeader(entry: TooltipEntry): undefined | string {\n const lines: string[] = [];\n if (entry.variantCount !== undefined && entry.variantCount > 1) {\n lines.push(`Variant: ${entry.variantIndex ?? \"?\"} of ${entry.variantCount}`);\n }\n return lines.join(\"\\n\");\n}\n\nfunction formatOriginPath(entry: TooltipEntry): undefined | string {\n const path = entry.linkerPath ?? [];\n if (path.length === 0) return undefined;\n\n const lines = [\"Origin path\"];\n path.forEach((step, i) => {\n const label =\n readAnnotation(step.linker.spec, Annotation.LinkLabel) ??\n readAnnotation(step.linker.spec, Annotation.Label) ??\n step.linker.spec.name;\n lines.push(`${BULLET_1}linker ${i + 1}: ${label}`);\n const qs = formatAxisQualifications(step.qualifications);\n if (qs !== undefined) lines.push(`${SUB_BULLET}qualifies: ${qs}`);\n });\n const hitName = readAnnotation(entry.spec, Annotation.Label) ?? entry.spec.name;\n lines.push(`${BULLET_1}hit column: ${hitName}`);\n return lines.join(\"\\n\");\n}\n\nfunction formatAnchors(q: undefined | MatchQualifications): undefined | string {\n if (isNil(q)) return undefined;\n const ids = Object.keys(q.forQueries);\n if (ids.length === 0) return undefined;\n\n const lines = [];\n for (const id of ids) {\n const item = q.forQueries[id as PObjectId];\n if (item.length === 0) continue;\n const rendered = formatAxisQualifications(item);\n lines.push(`${BULLET_1}${id}${rendered !== undefined ? ` ${rendered}` : \"\"}`);\n }\n return lines.length > 0\n ? [\"Anchors (bound via this variant)\"].concat(lines).join(\"\\n\")\n : undefined;\n}\n\nfunction formatHit(q: undefined | MatchQualifications): undefined | string {\n if (isNil(q) || q.forHit.length === 0) return undefined;\n const rendered = formatAxisQualifications(q.forHit);\n if (rendered === undefined) return undefined;\n return [\"Hit column qualifications\", `${BULLET_1}${rendered}`].join(\"\\n\");\n}\n\nfunction formatAxisQualifications(qs: AxisQualification[]): undefined | string {\n if (qs.length === 0) return undefined;\n return qs.map(formatQualification).join(\"; \");\n}\n\nfunction formatQualification(q: AxisQualification): string {\n const axisName = typeof q.axis === \"string\" ? q.axis : (q.axis.name ?? JSON.stringify(q.axis));\n const entries = Object.entries(q.contextDomain);\n if (entries.length === 0) return axisName;\n const kv = entries.map(([k, v]) => `${k}=${v}`).join(\", \");\n return `${axisName} context: ${kv}`;\n}\n"],"mappings":";;;;;AAwBA,SAAgB,uBAAuB,SAAiD;AACtF,QAAO,QAAQ,IAAI,cAAc;;AAGnC,SAAS,cAAc,OAAyC;CAC9D,MAAM,WAAqB,EAAE;CAE7B,MAAM,SAAS,aAAa,MAAM;AAClC,KAAI,WAAW,KAAA,EAAW,UAAS,KAAK,OAAO;CAE/C,MAAM,SAAS,iBAAiB,MAAM;AACtC,KAAI,WAAW,KAAA,EAAW,UAAS,KAAK,OAAO;CAE/C,MAAM,UAAU,cAAc,MAAM,eAAe;AACnD,KAAI,YAAY,KAAA,EAAW,UAAS,KAAK,QAAQ;CAEjD,MAAM,MAAM,UAAU,MAAM,eAAe;AAC3C,KAAI,QAAQ,KAAA,EAAW,UAAS,KAAK,IAAI;AAEzC,KAAI,SAAS,UAAU,EAAG,QAAO,KAAA;AACjC,QAAO,SAAS,KAAK,OAAO;;AAG9B,MAAM,WAAW;AACjB,MAAM,aAAa;AAEnB,SAAS,aAAa,OAAyC;CAC7D,MAAM,QAAkB,EAAE;AAC1B,KAAI,MAAM,iBAAiB,KAAA,KAAa,MAAM,eAAe,EAC3D,OAAM,KAAK,YAAY,MAAM,gBAAgB,IAAI,MAAM,MAAM,eAAe;AAE9E,QAAO,MAAM,KAAK,KAAK;;AAGzB,SAAS,iBAAiB,OAAyC;CACjE,MAAM,OAAO,MAAM,cAAc,EAAE;AACnC,KAAI,KAAK,WAAW,EAAG,QAAO,KAAA;CAE9B,MAAM,QAAQ,CAAC,cAAc;AAC7B,MAAK,SAAS,MAAM,MAAM;EACxB,MAAM,SAAA,GAAA,gCAAA,gBACW,KAAK,OAAO,MAAMA,gCAAAA,WAAW,UAAU,KAAA,GAAA,gCAAA,gBACvC,KAAK,OAAO,MAAMA,gCAAAA,WAAW,MAAM,IAClD,KAAK,OAAO,KAAK;AACnB,QAAM,KAAK,G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,EAAE,SAAS,WAAW,EAAE,OAAQ,EAAE,KAAK,QAAQ,KAAK,UAAU,EAAE,KAAK;CAC7F,MAAM,UAAU,OAAO,QAAQ,EAAE,cAAc;AAC/C,KAAI,QAAQ,WAAW,EAAG,QAAO;AAEjC,QAAO,GAAG,SAAS,YADR,QAAQ,KAAK,CAAC,GAAG,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,KAAK"}
|
|
@@ -3,9 +3,8 @@ import { PColumnSpec } from "@milaboratories/pl-model-common";
|
|
|
3
3
|
|
|
4
4
|
//#region src/labels/derive_distinct_tooltips.d.ts
|
|
5
5
|
type TooltipEntry = {
|
|
6
|
-
/** Main column spec — used for column-name fallback when no label. */spec: PColumnSpec; /**
|
|
7
|
-
qualifications?: MatchQualifications; /**
|
|
8
|
-
distinctiveQualifications?: MatchQualifications; /** Linker steps traversed to reach the hit column. */
|
|
6
|
+
/** Main column spec — used for column-name fallback when no label. */spec: PColumnSpec; /** Qualifications carried by this variant. */
|
|
7
|
+
qualifications?: MatchQualifications; /** Linker steps traversed to reach the hit column. */
|
|
9
8
|
linkerPath?: MatchVariant["path"]; /** Position of this variant within the same physical column (1-based). */
|
|
10
9
|
variantIndex?: number; /** Total variants for the same physical column. */
|
|
11
10
|
variantCount?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive_distinct_tooltips.d.ts","names":[],"sources":["../../src/labels/derive_distinct_tooltips.ts"],"mappings":";;;;KAUY,YAAA;wEAEV,IAAA,EAAM,WAAA,EAFI;EAIV,cAAA,GAAiB,mBAAA;EAEjB,
|
|
1
|
+
{"version":3,"file":"derive_distinct_tooltips.d.ts","names":[],"sources":["../../src/labels/derive_distinct_tooltips.ts"],"mappings":";;;;KAUY,YAAA;wEAEV,IAAA,EAAM,WAAA,EAFI;EAIV,cAAA,GAAiB,mBAAA;EAEjB,UAAA,GAAa,YAAA,UAFI;EAIjB,YAAA,WAFyB;EAIzB,YAAA;AAAA;;iBAIc,sBAAA,CAAuB,OAAA,EAAS,YAAA"}
|
|
@@ -15,8 +15,6 @@ function formatTooltip(entry) {
|
|
|
15
15
|
if (anchors !== void 0) sections.push(anchors);
|
|
16
16
|
const hit = formatHit(entry.qualifications);
|
|
17
17
|
if (hit !== void 0) sections.push(hit);
|
|
18
|
-
const distinctive = formatDistinctive(entry.distinctiveQualifications);
|
|
19
|
-
if (distinctive !== void 0) sections.push(distinctive);
|
|
20
18
|
if (sections.length <= 1) return void 0;
|
|
21
19
|
return sections.join("\n\n");
|
|
22
20
|
}
|
|
@@ -60,14 +58,6 @@ function formatHit(q) {
|
|
|
60
58
|
if (rendered === void 0) return void 0;
|
|
61
59
|
return ["Hit column qualifications", `${BULLET_1}${rendered}`].join("\n");
|
|
62
60
|
}
|
|
63
|
-
function formatDistinctive(q) {
|
|
64
|
-
if (isNil(q)) return void 0;
|
|
65
|
-
const bullets = [];
|
|
66
|
-
for (const id of Object.keys(q.forQueries)) for (const item of q.forQueries[id]) bullets.push(`${BULLET_1}${id}: ${formatQualification(item)}`);
|
|
67
|
-
for (const item of q.forHit) bullets.push(`${BULLET_1}hit: ${formatQualification(item)}`);
|
|
68
|
-
if (bullets.length === 0) return void 0;
|
|
69
|
-
return ["Distinctive (what separates this variant)", ...bullets].join("\n");
|
|
70
|
-
}
|
|
71
61
|
function formatAxisQualifications(qs) {
|
|
72
62
|
if (qs.length === 0) return void 0;
|
|
73
63
|
return qs.map(formatQualification).join("; ");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive_distinct_tooltips.js","names":[],"sources":["../../src/labels/derive_distinct_tooltips.ts"],"sourcesContent":["import {\n Annotation,\n PObjectId,\n readAnnotation,\n type AxisQualification,\n type PColumnSpec,\n} from \"@milaboratories/pl-model-common\";\nimport { isNil } from \"es-toolkit\";\nimport type { MatchQualifications, MatchVariant } from \"../columns\";\n\nexport type TooltipEntry = {\n /** Main column spec — used for column-name fallback when no label. */\n spec: PColumnSpec;\n /**
|
|
1
|
+
{"version":3,"file":"derive_distinct_tooltips.js","names":[],"sources":["../../src/labels/derive_distinct_tooltips.ts"],"sourcesContent":["import {\n Annotation,\n PObjectId,\n readAnnotation,\n type AxisQualification,\n type PColumnSpec,\n} from \"@milaboratories/pl-model-common\";\nimport { isNil } from \"es-toolkit\";\nimport type { MatchQualifications, MatchVariant } from \"../columns\";\n\nexport type TooltipEntry = {\n /** Main column spec — used for column-name fallback when no label. */\n spec: PColumnSpec;\n /** Qualifications carried by this variant. */\n qualifications?: MatchQualifications;\n /** Linker steps traversed to reach the hit column. */\n linkerPath?: MatchVariant[\"path\"];\n /** Position of this variant within the same physical column (1-based). */\n variantIndex?: number;\n /** Total variants for the same physical column. */\n variantCount?: number;\n};\n\n/** Format tooltip strings for each entry. Returns `undefined` when nothing useful. */\nexport function deriveDistinctTooltips(entries: TooltipEntry[]): (undefined | string)[] {\n return entries.map(formatTooltip);\n}\n\nfunction formatTooltip(entry: TooltipEntry): undefined | string {\n const sections: string[] = [];\n\n const header = formatHeader(entry);\n if (header !== undefined) sections.push(header);\n\n const origin = formatOriginPath(entry);\n if (origin !== undefined) sections.push(origin);\n\n const anchors = formatAnchors(entry.qualifications);\n if (anchors !== undefined) sections.push(anchors);\n\n const hit = formatHit(entry.qualifications);\n if (hit !== undefined) sections.push(hit);\n\n if (sections.length <= 1) return undefined;\n return sections.join(\"\\n\\n\");\n}\n\nconst BULLET_1 = \" • \";\nconst SUB_BULLET = \" \";\n\nfunction formatHeader(entry: TooltipEntry): undefined | string {\n const lines: string[] = [];\n if (entry.variantCount !== undefined && entry.variantCount > 1) {\n lines.push(`Variant: ${entry.variantIndex ?? \"?\"} of ${entry.variantCount}`);\n }\n return lines.join(\"\\n\");\n}\n\nfunction formatOriginPath(entry: TooltipEntry): undefined | string {\n const path = entry.linkerPath ?? [];\n if (path.length === 0) return undefined;\n\n const lines = [\"Origin path\"];\n path.forEach((step, i) => {\n const label =\n readAnnotation(step.linker.spec, Annotation.LinkLabel) ??\n readAnnotation(step.linker.spec, Annotation.Label) ??\n step.linker.spec.name;\n lines.push(`${BULLET_1}linker ${i + 1}: ${label}`);\n const qs = formatAxisQualifications(step.qualifications);\n if (qs !== undefined) lines.push(`${SUB_BULLET}qualifies: ${qs}`);\n });\n const hitName = readAnnotation(entry.spec, Annotation.Label) ?? entry.spec.name;\n lines.push(`${BULLET_1}hit column: ${hitName}`);\n return lines.join(\"\\n\");\n}\n\nfunction formatAnchors(q: undefined | MatchQualifications): undefined | string {\n if (isNil(q)) return undefined;\n const ids = Object.keys(q.forQueries);\n if (ids.length === 0) return undefined;\n\n const lines = [];\n for (const id of ids) {\n const item = q.forQueries[id as PObjectId];\n if (item.length === 0) continue;\n const rendered = formatAxisQualifications(item);\n lines.push(`${BULLET_1}${id}${rendered !== undefined ? ` ${rendered}` : \"\"}`);\n }\n return lines.length > 0\n ? [\"Anchors (bound via this variant)\"].concat(lines).join(\"\\n\")\n : undefined;\n}\n\nfunction formatHit(q: undefined | MatchQualifications): undefined | string {\n if (isNil(q) || q.forHit.length === 0) return undefined;\n const rendered = formatAxisQualifications(q.forHit);\n if (rendered === undefined) return undefined;\n return [\"Hit column qualifications\", `${BULLET_1}${rendered}`].join(\"\\n\");\n}\n\nfunction formatAxisQualifications(qs: AxisQualification[]): undefined | string {\n if (qs.length === 0) return undefined;\n return qs.map(formatQualification).join(\"; \");\n}\n\nfunction formatQualification(q: AxisQualification): string {\n const axisName = typeof q.axis === \"string\" ? q.axis : (q.axis.name ?? JSON.stringify(q.axis));\n const entries = Object.entries(q.contextDomain);\n if (entries.length === 0) return axisName;\n const kv = entries.map(([k, v]) => `${k}=${v}`).join(\", \");\n return `${axisName} context: ${kv}`;\n}\n"],"mappings":";;;;AAwBA,SAAgB,uBAAuB,SAAiD;AACtF,QAAO,QAAQ,IAAI,cAAc;;AAGnC,SAAS,cAAc,OAAyC;CAC9D,MAAM,WAAqB,EAAE;CAE7B,MAAM,SAAS,aAAa,MAAM;AAClC,KAAI,WAAW,KAAA,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"./derive_distinct_labels.js";
|
|
1
|
+
import { DeriveLabelsFormatters, DeriveLabelsOptions, Entry, LinkerStep, Trace, TraceEntry, deriveDistinctLabels } from "./derive_distinct_labels.js";
|
|
2
2
|
import { TooltipEntry, deriveDistinctTooltips } from "./derive_distinct_tooltips.js";
|
package/dist/package.cjs
CHANGED
package/dist/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/model",
|
|
3
|
-
"version": "1.68.
|
|
3
|
+
"version": "1.68.7",
|
|
4
4
|
"description": "Platforma.bio SDK / Block Model",
|
|
5
5
|
"files": [
|
|
6
6
|
"./dist/**/*",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"utility-types": "^3.11.0",
|
|
32
32
|
"zod": "~3.25.76",
|
|
33
33
|
"@milaboratories/helpers": "1.14.1",
|
|
34
|
+
"@milaboratories/pl-model-common": "1.36.1",
|
|
34
35
|
"@milaboratories/pl-error-like": "1.12.9",
|
|
35
36
|
"@milaboratories/pl-model-middle-layer": "1.18.6",
|
|
36
|
-
"@milaboratories/ptabler-expression-js": "1.2.16"
|
|
37
|
-
"@milaboratories/pl-model-common": "1.36.1"
|
|
37
|
+
"@milaboratories/ptabler-expression-js": "1.2.16"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@vitest/coverage-istanbul": "^4.1.3",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"vitest": "^4.1.3",
|
|
44
44
|
"@milaboratories/build-configs": "2.0.0",
|
|
45
45
|
"@milaboratories/pf-spec-driver": "1.3.5",
|
|
46
|
-
"@milaboratories/pf-driver": "1.4.1",
|
|
47
46
|
"@milaboratories/ts-builder": "1.3.2",
|
|
47
|
+
"@milaboratories/pf-driver": "1.4.1",
|
|
48
48
|
"@milaboratories/ts-configs": "1.2.3"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
@@ -404,8 +404,6 @@ describe("AnchoredColumnCollection", () => {
|
|
|
404
404
|
for (const v of col1Match.variants) {
|
|
405
405
|
expect(v.qualifications.forQueries).toBeDefined();
|
|
406
406
|
expect(v.qualifications.forHit).toBeDefined();
|
|
407
|
-
expect(v.distinctiveQualifications.forQueries).toBeDefined();
|
|
408
|
-
expect(v.distinctiveQualifications.forHit).toBeDefined();
|
|
409
407
|
// forQueries keys are a subset of anchor ids
|
|
410
408
|
for (const key of Object.keys(v.qualifications.forQueries)) {
|
|
411
409
|
expect([anchorSnap.id]).toContain(key);
|
|
@@ -55,6 +55,9 @@ export interface AnchoredColumnCollection extends Disposable {
|
|
|
55
55
|
|
|
56
56
|
/** Axis-aware column discovery. */
|
|
57
57
|
findColumns(options?: AnchoredFindColumnsOptions): ColumnMatch[];
|
|
58
|
+
|
|
59
|
+
/** Variant discovery with detailed mapping info for each hit. */
|
|
60
|
+
findColumnVariants(options?: AnchoredFindColumnsOptions): ColumnVariant[];
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
/** Controls axis matching behavior for anchored discovery. */
|
|
@@ -76,12 +79,22 @@ export interface ColumnMatch {
|
|
|
76
79
|
readonly variants: MatchVariant[];
|
|
77
80
|
}
|
|
78
81
|
|
|
82
|
+
export interface ColumnVariant<Id extends PObjectId = PObjectId> {
|
|
83
|
+
/** Column snapshot with anchored SUniversalPColumnId. */
|
|
84
|
+
readonly column: ColumnSnapshot<Id>;
|
|
85
|
+
/** Full qualifications needed for integration. */
|
|
86
|
+
readonly qualifications: MatchQualifications;
|
|
87
|
+
/** Linker steps traversed to reach this hit; empty for direct matches. */
|
|
88
|
+
readonly path: {
|
|
89
|
+
linker: ColumnSnapshot<PObjectId>;
|
|
90
|
+
qualifications: AxisQualification[];
|
|
91
|
+
}[];
|
|
92
|
+
}
|
|
93
|
+
|
|
79
94
|
/** A single mapping variant describing how a hit column can be integrated. */
|
|
80
95
|
export interface MatchVariant {
|
|
81
96
|
/** Full qualifications needed for integration. */
|
|
82
97
|
readonly qualifications: MatchQualifications;
|
|
83
|
-
/** Distinctive (minimal) qualifications needed for integration. */
|
|
84
|
-
readonly distinctiveQualifications: MatchQualifications;
|
|
85
98
|
/** Linker steps traversed to reach this hit; empty for direct matches. */
|
|
86
99
|
readonly path: {
|
|
87
100
|
linker: ColumnSnapshot<PObjectId>;
|
|
@@ -312,7 +325,6 @@ class AnchoredColumnCollectionImpl implements AnchoredColumnCollection, Disposab
|
|
|
312
325
|
const variants: MatchVariant[] = hit.mappingVariants.map((v) => ({
|
|
313
326
|
path,
|
|
314
327
|
qualifications: remapFromIdxToId(v.qualifications, anchors),
|
|
315
|
-
distinctiveQualifications: remapFromIdxToId(v.distinctiveQualifications, anchors),
|
|
316
328
|
}));
|
|
317
329
|
const existing = acc.get(origId);
|
|
318
330
|
return acc.set(
|
|
@@ -325,6 +337,17 @@ class AnchoredColumnCollectionImpl implements AnchoredColumnCollection, Disposab
|
|
|
325
337
|
|
|
326
338
|
return Array.from(byColumn.values());
|
|
327
339
|
}
|
|
340
|
+
|
|
341
|
+
findColumnVariants(options?: AnchoredFindColumnsOptions): ColumnVariant[] {
|
|
342
|
+
const matches = this.findColumns(options);
|
|
343
|
+
return matches.flatMap((match) =>
|
|
344
|
+
match.variants.map((variant) => ({
|
|
345
|
+
column: match.column,
|
|
346
|
+
path: variant.path,
|
|
347
|
+
qualifications: variant.qualifications,
|
|
348
|
+
})),
|
|
349
|
+
);
|
|
350
|
+
}
|
|
328
351
|
}
|
|
329
352
|
|
|
330
353
|
/**
|