Pushing fix for broken themeVariable functionality

This commit is contained in:
ashishj
2023-01-19 20:30:11 +01:00
parent ca22e85e55
commit be818ad57f
9 changed files with 47 additions and 39 deletions

View File

@@ -84,8 +84,8 @@
: The first metal objects are made in Britain.Some other nice things happen. it is a good time to be alive. : The first metal objects are made in Britain.Some other nice things happen. it is a good time to be alive.
</pre> </pre>
<pre id="diagram" class="mermaid"> <pre id="diagram" class="mermaid2">
%%{init: { 'logLevel': 'debug', 'theme': 'default', 'timeline': {'disableMulticolor':false} } }%% %%{'init': { 'logLevel': 'debug', 'theme': 'default', 'timeline': {'disableMulticolor':false} } }%%
timeline timeline
title History of Social Media Platform title History of Social Media Platform
2002 : LinkedIn 2002 : LinkedIn
@@ -97,10 +97,10 @@
2010 : Pinterest 2010 : Pinterest
</pre> </pre>
<pre id="diagram" class="mermaid"> <pre id="diagram" class="mermaid">
%%{init: { 'logLevel': 'debug', 'theme': 'default', 'themeVariables': { %%{init: { 'logLevel': 'debug', 'theme': 'base', 'themeVariables': {
'cScale0': '#ffffff', 'cScale0': '#ff0000',
'cScale1': '#00ff00', 'cScale1': '#00ff00',
'cScale2': '#0000ff', 'cScale2': '#ff0000'
} } }%% } } }%%
timeline timeline
title History of Social Media Platform title History of Social Media Platform
@@ -112,6 +112,25 @@
2008s : Instagram 2008s : Instagram
2010 : Pinterest 2010 : Pinterest
</pre> </pre>
<pre id="diagram" class="mermaid">
%%{init: { 'logLevel': 'debug', 'theme': 'default' , 'themeVariables': {
'cScale0': '#ff0000',
'cScale1': '#00ff00',
'cScale2': '#0000ff'
} } }%%
timeline
title History of Social Media Platform
2002 : LinkedIn
2004 : Facebook : Google
2005 : Youtube
2006 : Twitter
2007 : Tumblr
2008 : Instagram
2010 : Pinterest
</pre>
<pre id="diagram" class="mermaid2"> <pre id="diagram" class="mermaid2">
timeline timeline
title History of Social Media Platform title History of Social Media Platform

View File

@@ -58,8 +58,7 @@ export const injectUtils = (
_commonDb: any, _commonDb: any,
_parseDirective: any _parseDirective: any
) => { ) => {
_log.info('Mermaid utils injected into timeline-diagram'); _log.debug('Mermaid utils injected into timeline-diagram');
_log.info('123 ' , _parseDirective);
log.trace = _log.trace; log.trace = _log.trace;
log.debug = _log.debug; log.debug = _log.debug;
log.info = _log.info; log.info = _log.info;

View File

@@ -519,7 +519,7 @@ export const drawNode = function (elem, node, fullSection, conf) {
'class', 'class',
(node.class ? node.class + ' ' : '') + (node.class ? node.class + ' ' : '') +
'timeline-node ' + 'timeline-node ' +
(section < 0 ? 'section-root' : 'section-' + section) ('section-' + section)
); );
const bkgElem = nodeElem.append('g'); const bkgElem = nodeElem.append('g');

View File

@@ -90,7 +90,7 @@ const compileTasks = function () {
} }
return allProcessed; return allProcessed;
}; };
log.info('456 parseDirective',parseDirective);
export default { export default {
clear, clear,
getCommonDb, getCommonDb,

View File

@@ -1,8 +1,6 @@
// @ts-nocheck TODO: fix file // @ts-nocheck TODO: fix file
import { select } from 'd3'; import { select } from 'd3';
import svgDraw from './svgDraw'; import svgDraw from './svgDraw';
import addSVGAccessibilityFields from '../../accessibility';
import { log, getConfig, setupGraphViewbox } from './mermaidUtils'; import { log, getConfig, setupGraphViewbox } from './mermaidUtils';
export const setConf = function (cnf) { export const setConf = function (cnf) {
@@ -17,15 +15,14 @@ export const draw = function (text, id, version, diagObj) {
//1. Fetch the configuration //1. Fetch the configuration
const conf = getConfig(); const conf = getConfig();
const LEFT_MARGIN = conf.leftMargin?conf.leftMargin:50; const LEFT_MARGIN = conf.leftMargin?conf.leftMargin:50;
//log conf
log.info('conf', conf);
//2. Clear the diagram db before parsing //2. Clear the diagram db before parsing
diagObj.db.clear(); diagObj.db.clear();
//3. Parse the diagram text //3. Parse the diagram text
diagObj.parser.parse(text + '\n'); diagObj.parser.parse(text + '\n');
log.info('timeline', diagObj.db); log.debug('timeline', diagObj.db);
const securityLevel = conf.securityLevel; const securityLevel = conf.securityLevel;
// Handle root and Document for when rendering in sandbox mode // Handle root and Document for when rendering in sandbox mode
@@ -45,17 +42,14 @@ export const draw = function (text, id, version, diagObj) {
//4. Fetch the diagram data //4. Fetch the diagram data
const tasks = diagObj.db.getTasks(); const tasks = diagObj.db.getTasks();
const title = diagObj.db.getCommonDb().getDiagramTitle(); const title = diagObj.db.getCommonDb().getDiagramTitle();
log.debug('task',tasks);
//log tasks
log.info(tasks);
//5. Initialize the diagram //5. Initialize the diagram
svgDraw.initGraphics(svg); svgDraw.initGraphics(svg);
// fetch Sections // fetch Sections
const sections = diagObj.db.getSections(); const sections = diagObj.db.getSections();
// log sections log.debug('sections', sections);
log.info(sections);
let maxSectionHeight = 0; let maxSectionHeight = 0;
let maxTaskHeight = 0; let maxTaskHeight = 0;
@@ -81,14 +75,14 @@ export const draw = function (text, id, version, diagObj) {
maxHeight: maxSectionHeight, maxHeight: maxSectionHeight,
}; };
const sectionHeight = svgDraw.getVirtualNodeHeight(svg, sectionNode, conf); const sectionHeight = svgDraw.getVirtualNodeHeight(svg, sectionNode, conf);
log.info('sectionHeight before draw', sectionHeight); log.debug('sectionHeight before draw', sectionHeight);
maxSectionHeight = Math.max(maxSectionHeight, sectionHeight +20); maxSectionHeight = Math.max(maxSectionHeight, sectionHeight +20);
}); });
//tasks length and maxEventCount //tasks length and maxEventCount
let maxEventCount = 0; let maxEventCount = 0;
let maxEventLineLength = 0; let maxEventLineLength = 0;
log.info('tasks.length', tasks.length); log.debug('tasks.length', tasks.length);
//calculate max task height //calculate max task height
// for loop till tasks.length // for loop till tasks.length
for (const [i, task] of tasks.entries()) { for (const [i, task] of tasks.entries()) {
@@ -102,7 +96,7 @@ export const draw = function (text, id, version, diagObj) {
maxHeight: maxTaskHeight, maxHeight: maxTaskHeight,
}; };
const taskHeight = svgDraw.getVirtualNodeHeight(svg, taskNode, conf); const taskHeight = svgDraw.getVirtualNodeHeight(svg, taskNode, conf);
log.info('taskHeight before draw', taskHeight); log.debug('taskHeight before draw', taskHeight);
maxTaskHeight = Math.max(maxTaskHeight, taskHeight + 20); maxTaskHeight = Math.max(maxTaskHeight, taskHeight + 20);
//calculate maxEventCount //calculate maxEventCount
@@ -126,8 +120,8 @@ export const draw = function (text, id, version, diagObj) {
} }
log.info('maxSectionHeight before draw', maxSectionHeight); log.debug('maxSectionHeight before draw', maxSectionHeight);
log.info('maxTaskHeight before draw', maxTaskHeight); log.debug('maxTaskHeight before draw', maxTaskHeight);
if (sections && sections.length > 0) { if (sections && sections.length > 0) {
sections.forEach((section) => { sections.forEach((section) => {
@@ -140,11 +134,10 @@ export const draw = function (text, id, version, diagObj) {
padding: 20, padding: 20,
maxHeight: maxSectionHeight, maxHeight: maxSectionHeight,
}; };
//log section node log.debug('sectionNode', sectionNode);
log.info('sectionNode', sectionNode);
const sectionNodeWrapper = svg.append('g'); const sectionNodeWrapper = svg.append('g');
const node = svgDraw.drawNode(sectionNodeWrapper, sectionNode, sectionNumber, conf); const node = svgDraw.drawNode(sectionNodeWrapper, sectionNode, sectionNumber, conf);
log.info('sectionNode output', node); log.debug('sectionNode output', node);
sectionNodeWrapper.attr( sectionNodeWrapper.attr(
'transform', 'transform',
@@ -177,7 +170,7 @@ export const draw = function (text, id, version, diagObj) {
// Get BBox of the diagram // Get BBox of the diagram
const box = svg.node().getBBox(); const box = svg.node().getBBox();
log.info('bounds', box); log.debug('bounds', box);
if (title) { if (title) {
svg svg
@@ -223,14 +216,13 @@ export const drawTasks = function (diagram, tasks, sectionColor, masterX, master
maxHeight: maxTaskHeight, maxHeight: maxTaskHeight,
}; };
//log task node log.debug('taskNode', taskNode);
log.info('taskNode', taskNode);
// create task wrapper // create task wrapper
const taskWrapper = diagram.append('g').attr('class', 'taskWrapper'); const taskWrapper = diagram.append('g').attr('class', 'taskWrapper');
const node = svgDraw.drawNode(taskWrapper, taskNode, sectionColor, conf); const node = svgDraw.drawNode(taskWrapper, taskNode, sectionColor, conf);
const taskHeight = node.height; const taskHeight = node.height;
//log task height //log task height
log.info('taskHeight after draw', taskHeight); log.debug('taskHeight after draw', taskHeight);
taskWrapper.attr( taskWrapper.attr(
'transform', 'transform',
`translate(${masterX}, ${masterY})` `translate(${masterX}, ${masterY})`
@@ -294,7 +286,7 @@ export const drawEvents = function (diagram, events, sectionColor, masterX, mast
}; };
//log task node //log task node
log.info('eventNode', eventNode); log.debug('eventNode', eventNode);
// create event wrapper // create event wrapper
const eventWrapper = diagram.append('g').attr('class', 'eventWrapper'); const eventWrapper = diagram.append('g').attr('class', 'eventWrapper');
const node = svgDraw.drawNode(eventWrapper, eventNode, sectionColor, conf) const node = svgDraw.drawNode(eventWrapper, eventNode, sectionColor, conf)

View File

@@ -51,8 +51,6 @@ export const registerDiagram = (
addStylesForDiagram(id, diagram.styles); addStylesForDiagram(id, diagram.styles);
if (diagram.injectUtils) { if (diagram.injectUtils) {
console.log('parseDirective', parseDirective);
diagram.injectUtils(log, setLogLevel, getConfig, sanitizeText, setupGraphViewbox,getCommonDb(),parseDirective); diagram.injectUtils(log, setLogLevel, getConfig, sanitizeText, setupGraphViewbox,getCommonDb(),parseDirective);
} }
}; };

View File

@@ -8,7 +8,7 @@ import { directiveSanitizer } from './utils';
let currentDirective: { type?: string; args?: any } | undefined = {}; let currentDirective: { type?: string; args?: any } | undefined = {};
export const parseDirective = function (p: any, statement: string, context: string, type: string): void { export const parseDirective = function (p: any, statement: string, context: string, type: string): void {
log.info('parseDirective is being called', statement, context, type); log.debug('parseDirective is being called', statement, context, type);
try { try {
if (statement !== undefined) { if (statement !== undefined) {
statement = statement.trim(); statement = statement.trim();

View File

@@ -140,7 +140,7 @@ mermaid.initialize({
let us look at same example, where we have disabled the multiColor option. let us look at same example, where we have disabled the multiColor option.
```mermaid-example ```mermaid-example
%%{init: { 'logLevel': 'debug', 'theme': 'base', 'timeline': {'disableMulticolor': true}}%% %%{init: { 'logLevel': 'debug', 'theme': 'base', 'timeline': {'disableMulticolor': true}}}%%
timeline timeline
title History of Social Media Platform title History of Social Media Platform
2002 : LinkedIn 2002 : LinkedIn
@@ -164,7 +164,7 @@ Now let's override the default values for the `cScale0` to `cScale2` variables:
%%{init: { 'logLevel': 'debug', 'theme': 'default' , 'themeVariables': { %%{init: { 'logLevel': 'debug', 'theme': 'default' , 'themeVariables': {
'cScale0': '#ff0000', 'cScale0': '#ff0000',
'cScale1': '#00ff00', 'cScale1': '#00ff00',
'cScale2': '#0000ff', 'cScale2': '#0000ff'
} } }%% } } }%%
timeline timeline
title History of Social Media Platform title History of Social Media Platform

View File

@@ -122,6 +122,7 @@ class Theme {
updateColors() { updateColors() {
/* Color Scale */ /* Color Scale */
/* Each color-set will have a background, a foreground and a border color */ /* Each color-set will have a background, a foreground and a border color */
this.cScale0 = this.cScale0 || this.primaryColor; this.cScale0 = this.cScale0 || this.primaryColor;
this.cScale1 = this.cScale1 || this.secondaryColor; this.cScale1 = this.cScale1 || this.secondaryColor;
this.cScale2 = this.cScale2 || this.tertiaryColor; this.cScale2 = this.cScale2 || this.tertiaryColor;
@@ -138,10 +139,9 @@ class Theme {
this['cScalePeer' + 2] = this['cScalePeer' + 2] || darken(this.tertiaryColor, 40); this['cScalePeer' + 2] = this['cScalePeer' + 2] || darken(this.tertiaryColor, 40);
for (let i = 0; i < this.THEME_COLOR_LIMIT; i++) { for (let i = 0; i < this.THEME_COLOR_LIMIT; i++) {
// Setup the peer color for the set, useful for borders // Setup the peer color for the set, useful for borders
this['cScale' + i] = darken(this['cScale' + i], 10); this['cScale' + i] = darken(this['cScale' + i], 10);
this['cScalePeer' + i] = this['cScalePeer' + i] || darken(this['cScale' + i], 25); this['cScalePeer' + i] = this['cScalePeer' + i] || darken(this['cScale' + i], 25);
} }
// Setup the inverted color for the set // Setup the inverted color for the set
for (let i = 0; i < this.THEME_COLOR_LIMIT; i++) { for (let i = 0; i < this.THEME_COLOR_LIMIT; i++) {
this['cScaleInv' + i] = this['cScaleInv' + i] || adjust(this['cScale' + i], { h: 180 }); this['cScaleInv' + i] = this['cScaleInv' + i] || adjust(this['cScale' + i], { h: 180 });