Files
semantica/explorer/src/workspaces/GraphWorkspace/graphEntityShape.ts
T
438d8bc7af fix(explorer): address PR #503 review findings
- Extract ENTITY_SHAPE_ALIASES and classifyEntityShape into a shared
  graphEntityShape.ts utility — resolveEntityShape was duplicated with
  divergent signatures in useLoadGraph.ts and graphSceneState.ts; both
  now import from one place so aliases can never drift
- graphSceneState.resolveEntityShape falls back to classifyEntityShape
  for nodes created programmatically that bypass useLoadGraph
- Fix graphTheme.ts indentation around fullGraphStructure,
  fullGraphStructureLayer, and interaction — closing braces were at
  wrong indent levels making the nesting visually misleading
- Add comment on fullGraphStructureLayer.mode explaining it is
  intentionally "off" as a staged-rollout gate (flip to "auto" to enable
  cross-community canvas curve rendering)

Co-authored-by: Mohd Kaif <98801504+KaifAhmad1@users.noreply.github.com>
Co-authored-by: Zohaib Hassnain <109234410+ZohaibHassan16@users.noreply.github.com>
2026-04-27 22:21:41 +05:30

35 lines
1.2 KiB
TypeScript

import type { GraphEntityShapeVariant } from "./graphTheme";
export const ENTITY_SHAPE_ALIASES: Array<[GraphEntityShapeVariant, RegExp]> = [
["biomolecule", /\b(gene|protein|enzyme|receptor|target|transcript|rna|dna|mirna|biomolecule|peptide)\b/i],
["condition", /\b(disease|condition|phenotype|symptom|disorder|syndrome|diagnosis|pathology|trait)\b/i],
["compound", /\b(drug|chemical|compound|metabolite|molecule|small[_\s-]?molecule|ligand|therapeutic|medication|substance)\b/i],
["process", /\b(pathway|process|mechanism|function|ontology|biological[_\s-]?process|cellular[_\s-]?process|program|module)\b/i],
];
export function classifyEntityShape(
nodeType?: string,
semanticGroup?: string,
content?: string,
properties?: Record<string, unknown>,
): GraphEntityShapeVariant {
const values = [
nodeType,
semanticGroup,
content,
String(properties?.type ?? ""),
String(properties?.category ?? ""),
String(properties?.label ?? ""),
]
.filter((value) => typeof value === "string" && value.trim().length > 0)
.join(" ");
for (const [shape, pattern] of ENTITY_SHAPE_ALIASES) {
if (pattern.test(values)) {
return shape;
}
}
return "entity";
}