Added support for valueFormat directive - linting

This commit is contained in:
Knut Sveidqvist
2025-05-12 17:47:00 +02:00
parent 3e07a5acff
commit 66ce617bea
2 changed files with 15 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ import {
setAccTitle, setAccTitle,
setDiagramTitle, setDiagramTitle,
} from '../common/commonDb.js'; } from '../common/commonDb.js';
import type { TreemapDB, TreemapData, TreemapNode } from './types.js'; import type { TreemapDB, TreemapData, TreemapDiagramConfig, TreemapNode } from './types.js';
const defaultTreemapData: TreemapData = { const defaultTreemapData: TreemapData = {
nodes: [], nodes: [],
@@ -22,11 +22,15 @@ const defaultTreemapData: TreemapData = {
let outerNodes: TreemapNode[] = []; let outerNodes: TreemapNode[] = [];
let data: TreemapData = structuredClone(defaultTreemapData); let data: TreemapData = structuredClone(defaultTreemapData);
const getConfig = () => { const getConfig = (): Required<TreemapDiagramConfig> => {
// Use type assertion with unknown as intermediate step
const defaultConfig = DEFAULT_CONFIG as unknown as { treemap: Required<TreemapDiagramConfig> };
const userConfig = commonGetConfig() as unknown as { treemap?: Partial<TreemapDiagramConfig> };
return cleanAndMerge({ return cleanAndMerge({
...DEFAULT_CONFIG.treemap, ...defaultConfig.treemap,
...commonGetConfig().treemap, ...(userConfig.treemap ?? {}),
}); }) as Required<TreemapDiagramConfig>;
}; };
const getNodes = (): TreemapNode[] => data.nodes; const getNodes = (): TreemapNode[] => data.nodes;

View File

@@ -11,7 +11,9 @@ import { buildHierarchy } from './utils.js';
* @param ast - The Treemap AST * @param ast - The Treemap AST
*/ */
const populate = (ast: TreemapAst) => { const populate = (ast: TreemapAst) => {
populateCommonDb(ast, db); // We need to bypass the type checking for populateCommonDb
// eslint-disable-next-line @typescript-eslint/no-explicit-any
populateCommonDb(ast as any, db);
const items: { const items: {
level: number; level: number;
@@ -77,7 +79,7 @@ const populate = (ast: TreemapAst) => {
* @param item - The treemap item * @param item - The treemap item
* @returns The name of the item * @returns The name of the item
*/ */
const getItemName = (item: any): string => { const getItemName = (item: { name?: string | number }): string => {
return item.name ? String(item.name) : ''; return item.name ? String(item.name) : '';
}; };
@@ -85,7 +87,8 @@ export const parser: ParserDefinition = {
parse: async (text: string): Promise<void> => { parse: async (text: string): Promise<void> => {
try { try {
// Use a generic parse that accepts any diagram type // Use a generic parse that accepts any diagram type
const parseFunc = parse as (diagramType: string, text: string) => Promise<any>;
const parseFunc = parse as (diagramType: string, text: string) => Promise<TreemapAst>;
const ast = await parseFunc('treemap', text); const ast = await parseFunc('treemap', text);
log.debug('Treemap AST:', ast); log.debug('Treemap AST:', ast);
populate(ast); populate(ast);