amanpal3/Dr-SKILLs / .agent/skills/archify
archify
UnverifiedCreate validated architecture, workflow, sequence, data-flow, lifecycle/state, ERD, class, tree, timeline, and waterfall diagrams as explorable standalone HTML with dark/light themes, motion and image/SVG/WebM export. Accept requirements or Mermaid; inspect repository evidence for code-backed diagrams. Use when visualizing systems, API calls, pipelines, schemas, histories, timings, or everyday steps, parts, relationships and states. Also turn an answer into a one-page explainer, with the conclusion first, structured panels, native diagrams and charts, when the user asks for a page, an explainer or an answer to share (做成一页, 用页面讲), or proactively when the user's rules opt in with an [archify explainer: ...] line. Not for dashboards.
renderers/shared/legend.mjs
View on GitHubimport { throwDiagnosticError } from './diagnostics.mjs';
import { rectsOverlap, segmentIntersectsRect } from './geometry.mjs';
import { esc, textUnits } from './utils.mjs';
import { translateMessage } from './i18n.mjs';
const DEFAULT_FONT_SIZE = 8;
const DEFAULT_ITEM_GAP = 22;
const DEFAULT_LINE_GAP = 22;
const DEFAULT_SWATCH_GAP = 8;
const TEXT_ADVANCE_EM = 0.62;
const INTERACTIVE_BADGE_ALLOWANCE = 21;
export function relationshipLegendObstacles(relations, { pointsFor, labelRectFor } = {}) {
const obstacles = [];
for (const [index, relation] of (Array.isArray(relations) ? relations : []).entries()) {
const points = typeof pointsFor === 'function' ? pointsFor(relation, index) : [];
const finitePoints = (Array.isArray(points) ? points : []).filter((point) => (
Array.isArray(point) && point.length === 2 && point.every(Number.isFinite)
));
for (let pointIndex = 0; pointIndex < finitePoints.length - 1; pointIndex += 1) {
obstacles.push({
kind: 'relationship-segment',
start: finitePoints[pointIndex],
end: finitePoints[pointIndex + 1],
});
}
const labelRect = typeof labelRectFor === 'function' ? labelRectFor(relation, index) : null;
if (labelRect && [labelRect.x, labelRect.y, labelRect.width, labelRect.height].every(Number.isFinite)) {
obstacles.push({ kind: 'relationship-label', ...labelRect });
}
}
return obstacles;
}
export function resolveLegend(config, catalog, presentKinds) {
const mode = config?.mode || 'auto';
if (mode === 'hidden') return [];
const present = presentKinds instanceof Set ? presentKinds : new Set(presentKinds || []);
const overrides = config?.entries || {};
return catalog.flatMap((catalogEntry) => {
const override = overrides[catalogEntry.kind] || {};
const selectedByMode = mode === 'all' || present.has(catalogEntry.kind);
const visible = override.visible === true || (selectedByMode && override.visible !== false);
if (!visible) return [];
return [{
...catalogEntry,
label: override.label || catalogEntry.label,
present: present.has(catalogEntry.kind),
interactive: catalogEntry.interactive !== false && present.has(catalogEntry.kind),
}];
});
}
// Labels render slightly larger than the layout font size; measure the
// rendered size so a long label cannot run into the next entry.
function renderedLegendFontSize(fontSize) {
return fontSize < 8 ? fontSize + 0.5 : fontSize + 2;
}
function measuredEntryWidth(entry, fontSize, swatchGap) {
const swatchWidth = entry.swatchWidth ?? 14;
return Math.ceil(
swatchWidth
+ swatchGap
+ textUnits(entry.label) * renderedLegendFontSize(fontSize) * TEXT_ADVANCE_EM
+ (entry.interactive ? INTERACTIVE_BADGE_ALLOWANCE : 0)
+ (entry.trailingWidth ?? 0),
);
}
// One pure footprint calculation owns both auto-viewBox sizing and final SVG
// placement. Callers must not maintain a second approximation of legend width
// or row count; that would make generated geometry disagree with validation.
export function legendFootprint(entries, {
width,
fontSize = DEFAULT_FONT_SIZE,
itemGap = DEFAULT_ITEM_GAP,
lineGap = DEFAULT_LINE_GAP,
swatchGap = DEFAULT_SWATCH_GAP,
} = {}) {
if (!entries.length) {
return { measured: [], rows: [], rowCount: 0, minWidth: 0, extraHeight: 0 };
}
const measured = entries.map((entry) => ({
...entry,
width: measuredEntryWidth(entry, fontSize, entry.swatchGap ?? swatchGap),
}));
const rows = [[]];
let cursor = 0;
for (const entry of measured) {
const row = rows.at(-1);
const required = (row.length ? itemGap : 0) + entry.width;
if (row.length && cursor + required > width) {
rows.push([entry]);
cursor = entry.width;
} else {
row.push(entry);
cursor += required;
}
}
return {
measured,
rows,
rowCount: rows.length,
minWidth: measured.reduce((width, entry) => Math.max(width, entry.width), 0),
extraHeight: (rows.length - 1) * lineGap,
};
}
export function measureLegend(entries, {
x,
baselineY,
width,
fontSize = DEFAULT_FONT_SIZE,
itemGap = DEFAULT_ITEM_GAP,
lineGap = DEFAULT_LINE_GAP,
swatchGap = DEFAULT_SWATCH_GAP,
minTitleY = 0,
obstacles = [],
unfit = 'error',
diagramType = 'diagram',
} = {}) {
if (!entries.length) return { entries: [], rowCount: 0, titleY: null };
const footprint = legendFootprint(entries, { width, fontSize, itemGap, lineGap, swatchGap });
const tooWide = footprint.measured.find((entry) => entry.width > width);
if (tooWide) {
if (unfit === 'hide') return null;
const message = `[legend/label-too-wide] ${diagramType} legend label for "${tooWide.kind}" needs ${tooWide.width}px but only ${width}px is available.`;
throwDiagnosticError(message, [{
code: 'legend/label-too-wide',
severity: 'error',
message,
subject: { diagramType, path: `/meta/legend/entries/${tooWide.kind}/label` },
evidence: { kind: tooWide.kind, measuredWidthPx: tooWide.width, availableWidthPx: width },
supportedFixes: ['shorten the legend label or use a wider viewBox'],
}]);
}
const titleY = baselineY - footprint.extraHeight - 20;
const legendTopY = titleY - 10;
if (legendTopY < minTitleY) {
if (unfit === 'hide') return null;
const message = `[legend/vertical-overflow] ${diagramType} legend needs ${footprint.rowCount} rows, which would start at y=${legendTopY} above the available legend band at y=${minTitleY}.`;
throwDiagnosticError(message, [{
code: 'legend/vertical-overflow',
severity: 'error',
message,
subject: { diagramType, path: '/meta/legend' },
evidence: { rowCount: footprint.rowCount, requiredTopY: legendTopY, availableTopY: minTitleY },
supportedFixes: ['shorten legend labels, hide nonessential entries, or use a wider viewBox'],
}]);
}
const positioned = [];
footprint.rows.forEach((row, rowIndex) => {
let entryX = x;
const baseline = baselineY - (footprint.rowCount - rowIndex - 1) * lineGap;
for (const entry of row) {
positioned.push({ ...entry, x: entryX, baseline, row: rowIndex });
entryX += entry.width + itemGap;
}
});
const legendRects = [
{ kind: 'title', x, y: legendTopY, width: 48, height: 14 },
...positioned.map((entry) => ({
kind: entry.kind,
x: entry.x,
y: entry.baseline - 10,
width: entry.width,
height: 14,
})),
];
const collision = legendRects.find((legendRect) => obstacles.some((obstacle) => (
Array.isArray(obstacle.start) && Array.isArray(obstacle.end)
? segmentIntersectsRect({ start: obstacle.start, end: obstacle.end }, legendRect)
: rectsOverlap(obstacle, legendRect)
)));
if (collision) {
if (unfit === 'hide') return null;
const message = `[legend/content-overlap] ${diagramType} legend entry "${collision.kind}" overlaps authored relationship geometry.`;
throwDiagnosticError(message, [{
code: 'legend/content-overlap',
severity: 'error',
message,
subject: { diagramType, path: '/meta/legend' },
evidence: { legendKind: collision.kind, legendRect: collision },
supportedFixes: ['shorten or hide legend entries, use a wider viewBox, or move the authored relationship route/label out of the legend band'],
}]);
}
return {
entries: positioned,
rowCount: footprint.rowCount,
titleY,
fontSize,
};
}
// `labelClass`/`labelWeight` let a renderer state that its legend labels are
// the same ink and weight as the value they describe; both default to the
// shared presentation, so callers that pass nothing keep their exact bytes.
export function renderLegend({ entries, layout, renderSwatch, locale, labelClass = 't-muted', labelWeight = 500 }) {
if (!entries.length) return '';
const measured = measureLegend(entries, layout);
if (!measured) return '';
const hasInteractiveEntries = measured.entries.some((entry) => entry.interactive);
const renderedFontSize = renderedLegendFontSize(measured.fontSize);
const rootAttributes = hasInteractiveEntries ? ' data-legend="" data-legend-bridge=""' : ' data-legend=""';
const parts = [
` <g${rootAttributes}>`,
` <text x="${layout.x}" y="${measured.titleY}" class="t-primary" font-size="12" font-weight="650">${esc(translateMessage(locale, 'legend.title'))}</text>`,
];
for (const entry of measured.entries) {
const interactive = entry.interactive
? ` data-legend-kind="${esc(entry.kind)}" data-legend-label="${esc(entry.label)}"`
: '';
parts.push(` <g data-legend-semantic-kind="${esc(entry.kind)}"${interactive} data-legend-x="${entry.x}" data-legend-baseline="${entry.baseline}" data-legend-width="${entry.width}">`);
parts.push(` ${renderSwatch(entry)}`);
parts.push(` <text x="${entry.x + (entry.swatchWidth ?? 14) + (entry.swatchGap ?? DEFAULT_SWATCH_GAP)}" y="${entry.baseline}" class="${labelClass}" font-size="${renderedFontSize}" font-weight="${labelWeight}">${esc(entry.label)}</text>`);
parts.push(' </g>');
}
parts.push(' </g>');
return parts.join('\n');
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |