# core/coordinators/figure.coordinator.ts

> 42 lines of code and 7 definitions.

Tree: GovLab Docs
Language: typescript
Layer: application
Canonical: https://banes-lab.com/anatomy/docs#file-docs-core-coordinators-figure-coordinator-ts
Source text: https://banes-lab.com/source/docs/core/coordinators/figure.coordinator.ts.txt

Listed in [core/coordinators](https://banes-lab.com/api/source/docs/core/coordinators.md), after [core/coordinators/drift.coordinator.ts](https://banes-lab.com/source/docs/core/coordinators/drift.coordinator.ts.md) and before [core/coordinators/index.coordinator.ts](https://banes-lab.com/source/docs/core/coordinators/index.coordinator.ts.md).

## Definitions

- `chartsAt` (lexical_declaration, line 14)
- `aggregateCharts` (lexical_declaration, line 18)
- `chartsPath` (lexical_declaration, line 10)
- `renderChartsFor` (lexical_declaration, line 36, exported)
- `pkg` (lexical_declaration, line 23)
- `content` (lexical_declaration, line 24)
- `context` (lexical_declaration, line 44, exported)

## Contained in

- [core/coordinators](https://banes-lab.com/anatomy/docs/folder-docs-core-coordinators.md)

## Uses

- [core/formatters/figure.formatter.ts](https://banes-lab.com/source/docs/core/formatters/figure.formatter.ts.md)

## Linked from

- [core/coordinators](https://banes-lab.com/anatomy/docs/folder-docs-core-coordinators.md)
- [core/formatters](https://banes-lab.com/anatomy/docs/folder-docs-core-formatters.md)

## Source

```typescript
import { diagramContextFor, loadPackage, packageName, scriptsOf, shapedContext } from "#core/factories/diagram.factory";
import { moduleDepsOf, workspaceRows } from "#core/converters/dependency.converter";
import type { Charts } from "#types/figure.types";
import type { ManifestModule } from "#types/manifest.types";
import { relativePath } from "@ssot/paths";
import { renderCharts } from "#core/formatters/figure.formatter";
import { resolve } from "node:path";
import { shapeOf } from "#core/classifiers/package.classifier";

const chartsPath = function chartsPath(moduleDir: string): string {
    return resolve(moduleDir, relativePath("moduleInfo.charts"));
};

const chartsAt = function chartsAt(moduleDir: string, content: string | null): Charts | null {
    return content === null ? null : { content, path: chartsPath(moduleDir) };
};

const aggregateCharts = function aggregateCharts(
    moduleDir: string,
    relPath: string,
    members: readonly ManifestModule[],
): Charts | null {
    const pkg = loadPackage(moduleDir);
    const content = renderCharts({
        codeGraph: null,
        keepIsolated: true,
        moduleDeps: moduleDepsOf(workspaceRows(members)),
        moduleName: packageName(pkg, relPath),
        typeGraph: { edges: [], nodes: [] },
        ...shapedContext(shapeOf(moduleDir, pkg)),
        ...scriptsOf(pkg),
    });
    return chartsAt(moduleDir, content);
};

export const renderChartsFor = async function renderChartsFor(
    moduleDir: string,
    relPath: string,
    members: readonly ManifestModule[] = [],
): Promise<Charts | null> {
    if (members.length > 0) {
        return aggregateCharts(moduleDir, relPath, members);
    }
    const context = await diagramContextFor(moduleDir, relPath);
    return context === null ? null : chartsAt(moduleDir, renderCharts(context));
};
```
