{"version":3,"file":"peer_links.cjs","names":["readAnnotation","Annotation","canonicalizeAxisId","ResultPoolColumnsProvider","uniq"],"sources":["../../src/columns/peer_links.ts"],"sourcesContent":["import {\n  Annotation,\n  canonicalizeAxisId,\n  readAnnotation,\n  type AxisId,\n  type CanonicalizedJson,\n  type PColumnSpec,\n} from \"@milaboratories/pl-model-common\";\nimport { uniq } from \"es-toolkit\";\nimport { ResultPoolColumnsProvider } from \"./column_providers\";\n\nexport type DatasetAxes = Set<CanonicalizedJson<AxisId>>;\n\n/** Main axes of the datasets: the second axis of every column marked `pl7.app/isAnchor`. */\nexport function collectDatasetAxes(specs: PColumnSpec[]): DatasetAxes {\n  return new Set(\n    specs.flatMap((spec) => {\n      const main = spec.axesSpec[1];\n      return readAnnotation(spec, Annotation.IsAnchor) === \"true\" && main !== undefined\n        ? [canonicalizeAxisId(main)]\n        : [];\n    }),\n  );\n}\n\n/** {@link collectDatasetAxes} over the result pool. */\nexport function getResultPoolDatasetAxes(): DatasetAxes {\n  return collectDatasetAxes(\n    ResultPoolColumnsProvider()\n      .getColumns()\n      .map((c) => c.getSpec()),\n  );\n}\n\n/**\n * Labels of the peer links on a linker path. A peer link joins two datasets' main axes, e.g. one\n * clonotype to another, so the columns behind it describe a different clonotype than the row.\n */\nexport function findPeerLinks(linkers: PColumnSpec[], datasetAxes: DatasetAxes): string[] {\n  return uniq(\n    linkers.flatMap((l) => {\n      const peer = l.axesSpec.every((a) => datasetAxes.has(canonicalizeAxisId(a)));\n      const label = readAnnotation(l, Annotation.LinkLabel) ?? readAnnotation(l, Annotation.Label);\n      return peer && label ? [label] : [];\n    }),\n  );\n}\n\n/** Hover text for the link icon. */\nexport function describePeerLinks(links: string[]): string {\n  return `Reached via ${links.join(\", then \")}`;\n}\n\n/** Moves peer-linked items after the others, keeping the order within each group. */\nexport function peerLinkedLast<T>(items: T[], isPeerLinked: (item: T) => boolean): T[] {\n  return [...items.filter((i) => !isPeerLinked(i)), ...items.filter(isPeerLinked)];\n}\n"],"mappings":";;;;;;AAcA,SAAgB,mBAAmB,OAAmC;CACpE,OAAO,IAAI,IACT,MAAM,SAAS,SAAS;EACtB,MAAM,OAAO,KAAK,SAAS;EAC3B,QAAA,GAAOA,gCAAAA,eAAAA,CAAe,MAAMC,gCAAAA,WAAW,QAAQ,MAAM,UAAU,SAAS,KAAA,IACpE,EAAA,GAACC,gCAAAA,mBAAAA,CAAmB,IAAI,CAAC,IACzB,CAAC;CACP,CAAC,CACH;AACF;;AAGA,SAAgB,2BAAwC;CACtD,OAAO,mBACLC,kBAAAA,0BAA0B,CAAC,CACxB,WAAW,CAAC,CACZ,KAAK,MAAM,EAAE,QAAQ,CAAC,CAC3B;AACF;;;;;AAMA,SAAgB,cAAc,SAAwB,aAAoC;CACxF,QAAA,GAAOC,WAAAA,KAAAA,CACL,QAAQ,SAAS,MAAM;EACrB,MAAM,OAAO,EAAE,SAAS,OAAO,MAAM,YAAY,KAAA,GAAIF,gCAAAA,mBAAAA,CAAmB,CAAC,CAAC,CAAC;EAC3E,MAAM,SAAA,GAAQF,gCAAAA,eAAAA,CAAe,GAAGC,gCAAAA,WAAW,SAAS,MAAA,GAAKD,gCAAAA,eAAAA,CAAe,GAAGC,gCAAAA,WAAW,KAAK;EAC3F,OAAO,QAAQ,QAAQ,CAAC,KAAK,IAAI,CAAC;CACpC,CAAC,CACH;AACF;;AAGA,SAAgB,kBAAkB,OAAyB;CACzD,OAAO,eAAe,MAAM,KAAK,SAAS;AAC5C;;AAGA,SAAgB,eAAkB,OAAY,cAAyC;CACrF,OAAO,CAAC,GAAG,MAAM,QAAQ,MAAM,CAAC,aAAa,CAAC,CAAC,GAAG,GAAG,MAAM,OAAO,YAAY,CAAC;AACjF"}