/
pieDb.js
79 lines (69 loc) · 1.61 KB
/
pieDb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { log } from '../../logger';
import mermaidAPI from '../../mermaidAPI';
import * as configApi from '../../config';
import common from '../common/common';
import {
setTitle,
getTitle,
getAccDescription,
setAccDescription,
clear as commonClear,
} from '../../commonDb';
let sections = {};
let title = '';
let description = '';
let showData = false;
export const parseDirective = function (statement, context, type) {
mermaidAPI.parseDirective(this, statement, context, type);
};
const addSection = function (id, value) {
id = common.sanitizeText(id, configApi.getConfig());
if (typeof sections[id] === 'undefined') {
sections[id] = value;
log.debug('Added new section :', id);
}
};
const getSections = () => sections;
const setShowData = function (toggle) {
showData = toggle;
};
const getShowData = function () {
return showData;
};
const cleanupValue = function (value) {
if (value.substring(0, 1) === ':') {
value = value.substring(1).trim();
return Number(value.trim());
} else {
return Number(value.trim());
}
};
const clear = function () {
sections = {};
title = '';
showData = false;
commonClear();
};
export const setPieTitle = function (txt) {
let sanitizedText = common.sanitizeText(txt, configApi.getConfig());
title = sanitizedText;
};
export const getPieTitle = function () {
return title;
};
export default {
parseDirective,
getConfig: () => configApi.getConfig().pie,
addSection,
getSections,
cleanupValue,
clear,
setTitle,
getTitle,
setPieTitle,
getPieTitle,
setShowData,
getShowData,
getAccDescription,
setAccDescription,
};