Skip to content

Commit

Permalink
Merge pull request #1543 from mermaid-js/bug/1485_application_of_font…
Browse files Browse the repository at this point in the history
…_settings

#1485 Setting proper font settings in the root css
  • Loading branch information
knsv authored Jul 15, 2020
2 parents dc2f9c3 + fe5d9e4 commit 389afde
Show file tree
Hide file tree
Showing 13 changed files with 326 additions and 107 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/other/webpackUsage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ describe('Sequencediagram', () => {
cy.visit(url);
cy.get('body')
.find('svg')
.should('have.length', 2);
.should('have.length', 1);
});
});
40 changes: 33 additions & 7 deletions cypress/platform/bundle-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
import mermaid from '../../dist/mermaid.core'
import mermaid from '../../dist/mermaid.core';

const code = `graph LR
Power_Supply --> Transmitter_A
Power_Supply --> Transmitter_B
Transmitter_A --> D
Transmitter_B --> D`;

mermaid.initialize({
theme: 'forest',
gantt: { axisFormatter: [
['%Y-%m-%d', (d) => {
return d.getDay() === 1
}]
] }
})
fontFamily: '"Lucida Console", Monaco, monospace',
startOnLoad: false,
flowchart: {
htmlLabels: true
},
gantt: {
axisFormatter: [
[
'%Y-%m-%d',
d => {
return d.getDay() === 1;
}
]
]
}
});
mermaid.render(
'the-id-of-the-svg',
code,
svg => {
console.log(svg);
const elem = document.querySelector('#graph-to-be');
elem.innerHTML = svg;
}
// ,document.querySelector('#tmp')
);
27 changes: 11 additions & 16 deletions cypress/platform/webpackUsage.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
<!doctype html>
<html>

<head>
<style>
/* .mermaid {
font-family: "trebuchet ms", verdana, arial;;
} */
/* .mermaid {
font-family: 'arial';
} */
</style>
</head>
<body>
<div class="mermaid">
graph LR
A-->B
</div>
<div class="mermaid">
gantt
title A Gantt Diagram
dateFormat YYYY-MM-DD
section Section
A task :a1, 2014-01-01, 30d
Another task :after a1 , 20d
section Another
Task in sec :2014-01-12 , 12d
another task : 24d
</div>
<div id="graph-to-be"></div>
<script src="./bundle-test.js" charset="utf-8"></script>
</body>

Expand Down
151 changes: 121 additions & 30 deletions dist/mermaid.core.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mermaid.core.js.map

Large diffs are not rendered by default.

151 changes: 121 additions & 30 deletions dist/mermaid.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mermaid.js.map

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions dist/mermaid.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mermaid.min.js.map

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions docs/Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ theme , the CSS style sheet

## securityLevel

| Parameter | Description | Type | Required | Values |
| ------------- | --------------------------------- | ------ | -------- | ------------- |
| securitylevel | Level of trust for parsed diagram | String | Required | Strict, Loose |
| Parameter | Description | Type | Required | Values |
| ------------- | --------------------------------- | ------ | -------- | ------------------------- |
| securitylevel | Level of trust for parsed diagram | String | Required | Strict, Loose, antiscript |

\*\*Notes:

- **strict**: (**default**) tags in text are encoded, click functionality is disabeled
- **loose**: tags in text are allowed, click functionality is enabled
- **antiscript**: html tags in text are allowed, (only script element is removed), click functionality is enabled

## startOnLoad

Expand Down
20 changes: 12 additions & 8 deletions src/mermaidAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ const render = function(id, _txt, cb, container) {
}

// classDef
if (graphType === 'flowchart' || graphType === 'flowchart-v2') {
if (graphType === 'flowchart' || graphType === 'flowchart-v2' || graphType === 'graph') {
const classes = flowRenderer.getClasses(txt);
for (const className in classes) {
style += `\n.${className} > * { ${classes[className].styles.join(
Expand All @@ -289,13 +289,17 @@ const render = function(id, _txt, cb, container) {
style1.innerHTML = scope(style, `#${id}`);
svg.insertBefore(style1, firstChild);

const style2 = document.createElement('style');
const cs = window.getComputedStyle(svg);
style2.innerHTML = `#${id} {
color: ${cs.color};
font: ${cs.font};
}`;
svg.insertBefore(style2, firstChild);
// Verify that the generated svgs are ok before removing this

// const style2 = document.createElement('style');
// const cs = window.getComputedStyle(svg);
// style2.innerHTML = `#d${id} * {
// color: ${cs.color};
// // font: ${cs.font};
// // font-family: Arial;
// // font-size: 24px;
// }`;
// svg.insertBefore(style2, firstChild);

try {
switch (graphType) {
Expand Down
10 changes: 8 additions & 2 deletions src/themes/mermaid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

:root {
--mermaid-font-family: '"trebuchet ms", verdana, arial';
--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive;
// --mermaid-alt-font-family: '"Lucida Console", Monaco, monospace';
font-family: '"trebuchet ms", verdana, arial';
font-family: var(--mermaid-font-family);
font-size: 16px;
}

/* Classes common for multiple diagrams */
Expand Down Expand Up @@ -52,3 +53,8 @@
.marker.cross {
stroke: $lineColor;
}

svg {
font-family: var(--mermaid-font-family);
font-size: 24px;
}
5 changes: 5 additions & 0 deletions src/themes/pie.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@
font-family: 'trebuchet ms', verdana, arial;
font-family: var(--mermaid-font-family);
}
.legend text {
font-family: 'trebuchet ms', verdana, arial;
font-family: var(--mermaid-font-family);
font-size: 17px;
}

0 comments on commit 389afde

Please sign in to comment.