chore!: change addSection header into D3Section

This commit is contained in:
Reda Al Sulais
2023-08-20 22:39:32 +03:00
parent 341db13279
commit d0c36c0de3
3 changed files with 5 additions and 7 deletions

View File

@@ -1,7 +1,5 @@
import { log } from '../../logger.js'; import { log } from '../../logger.js';
import { parseDirective as _parseDirective } from '../../directiveUtils.js'; import { parseDirective as _parseDirective } from '../../directiveUtils.js';
import { getConfig as commonGetConfig } from '../../config.js';
import { sanitizeText } from '../common/common.js';
import { import {
setAccTitle, setAccTitle,
getAccTitle, getAccTitle,
@@ -12,7 +10,7 @@ import {
clear as commonClear, clear as commonClear,
} from '../../commonDb.js'; } from '../../commonDb.js';
import type { ParseDirectiveDefinition } from '../../diagram-api/types.js'; import type { ParseDirectiveDefinition } from '../../diagram-api/types.js';
import type { PieFields, PieDB, Sections } from './pieTypes.js'; import type { PieFields, PieDB, Sections, D3Section } from './pieTypes.js';
import type { RequiredDeep } from 'type-fest'; import type { RequiredDeep } from 'type-fest';
import type { PieDiagramConfig } from '../../config.type.js'; import type { PieDiagramConfig } from '../../config.type.js';
import DEFAULT_CONFIG from '../../defaultConfig.js'; import DEFAULT_CONFIG from '../../defaultConfig.js';
@@ -41,8 +39,7 @@ const clear = (): void => {
commonClear(); commonClear();
}; };
const addSection = (label: string, value: number): void => { const addSection = ({ label, value }: D3Section): void => {
label = sanitizeText(label, commonGetConfig());
if (sections[label] === undefined) { if (sections[label] === undefined) {
sections[label] = value; sections[label] = value;
log.debug(`added new section: ${label}, with value: ${value}`); log.debug(`added new section: ${label}, with value: ${value}`);

View File

@@ -12,7 +12,8 @@ function populateDb(ast: Pie, db: PieDB) {
populateCommonDb(ast, db); populateCommonDb(ast, db);
db.setShowData(ast.showData); db.setShowData(ast.showData);
ast.sections.map((section: PieSection) => { ast.sections.map((section: PieSection) => {
db.addSection(section.label, section.value); const { label, value } = section;
db.addSection({ label, value });
}); });
} }

View File

@@ -56,7 +56,7 @@ export interface PieDB extends DiagramDB {
getAccDescription: () => string; getAccDescription: () => string;
// diagram db // diagram db
addSection: (label: string, value: number) => void; addSection: ({ label, value }: D3Section) => void;
getSections: () => Sections; getSections: () => Sections;
setShowData: (toggle: boolean) => void; setShowData: (toggle: boolean) => void;
getShowData: () => boolean; getShowData: () => boolean;