MC-1765: Merge from AlanaV11 to pebr/neo-style

This commit is contained in:
Per Brolin
2024-06-19 09:53:06 +02:00
8 changed files with 204 additions and 45 deletions

View File

@@ -0,0 +1,158 @@
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Montserrat&display=swap" rel="stylesheet" />
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
/>
<link
href="https://cdn.jsdelivr.net/npm/@mdi/font@6.9.96/css/materialdesignicons.min.css"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css?family=Noto+Sans+SC&display=swap"
rel="stylesheet"
/>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Kalam:wght@300;400;700&display=swap"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=Caveat:wght@400..700&family=Kalam:wght@300;400;700&family=Rubik+Mono+One&display=swap"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=Kalam:wght@300;400;700&family=Rubik+Mono+One&display=swap"
rel="stylesheet"
/>
<style>
body {
/* background: rgb(221, 208, 208); */
background: #333;
font-family: 'Arial';
/* font-size: 18px !important; */
}
h1 {
color: grey;
}
.mermaid2 {
display: none;
}
.mermaid svg {
/* font-size: 18px !important; */
/* background-color: #efefef;
background-image: radial-gradient(#fff 51%, transparent 91%),
radial-gradient(#fff 51%, transparent 91%);
background-size: 20px 20px;
background-position:
0 0,
10px 10px;
background-repeat: repeat; */
}
.malware {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 150px;
background: red;
color: black;
display: flex;
display: flex;
justify-content: center;
align-items: center;
font-family: monospace;
font-size: 72px;
}
/* tspan {
font-size: 6px !important;
} */
</style>
</head>
<body>
<pre id="diagram" class="mermaid">
flowchart
A --> B & C
subgraph apa
D --> E
end
</pre
>
<pre id="diagram2" class="mermaid2">
flowchart LR
id1(Start)-->id2(Stop)
style id1 fill:#f9f,stroke:#333,stroke-width:4px
style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
</pre>
<pre id="diagram3" class="mermaid2">
flowchart LR
A:::foo & B:::bar --> C:::foobar
classDef foo stroke:#f00
classDef bar stroke:#0f0
classDef ash color:red
class C ash
style C stroke:#00f, fill:black
</pre>
<pre id="diagram4" class="mermaid2">
stateDiagram
A:::foo
B:::bar --> C:::foobar
classDef foo stroke:#f00
classDef bar stroke:#0f0
style C stroke:#00f, fill:black, color:white
</pre>
<script type="module">
import mermaid from './mermaid.esm.mjs';
import { layouts } from './mermaid-layout-elk.esm.mjs';
mermaid.registerLayoutLoaders(layouts);
mermaid.parseError = function (err, hash) {
console.error('Mermaid error: ', err);
};
window.callback = function () {
alert('A callback was triggered');
};
mermaid.initialize({
theme: 'neo-dark',
// handdrawnSeed: 12,
look: 'neo',
// 'elk.nodePlacement.strategy': 'NETWORK_SIMPLEX',
// layout: 'dagre',
// layout: 'elk',
// layout: 'fixed',
// htmlLabels: false,
flowchart: { titleTopMargin: 10 },
// fontFamily: 'Caveat',
// fontFamily: 'Kalam',
// fontFamily: 'courier',
fontFamily: 'arial',
sequence: {
actorFontFamily: 'courier',
noteFontFamily: 'courier',
messageFontFamily: 'courier',
},
fontSize: 12,
logLevel: 0,
securityLevel: 'loose',
});
function callback() {
alert('It worked');
}
mermaid.parseError = function (err, hash) {
console.error('In parse error:');
console.error(err);
};
</script>
</body>
</html>

View File

@@ -54,47 +54,38 @@
10px 10px; 10px 10px;
background-repeat: repeat; */ background-repeat: repeat; */
} }
.malware {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 150px;
background: red;
color: black;
display: flex;
display: flex;
justify-content: center;
align-items: center;
font-family: monospace;
font-size: 72px;
}
/* tspan {
font-size: 6px !important;
} */
</style> </style>
</head> </head>
<body> <body>
<pre id="diagram" class="mermaid"> <pre id="diagram" class="mermaid">
%%{init: {"look": "neo", "theme": "neo","fontFamily": "Arial"} }%%
flowchart flowchart
a_a(Aftonbladet) --> b_b[gorilla]:::apa --> c_c{chimp}:::apa -->a_a A[A really really really super long node] --> B & C
a_a --> c --> d_d --> c_c subgraph apa
classDef apa fill:#f9f,stroke:#333,stroke-width:4px; D --> E
class a_a apa; end
click a_a "http://www.aftonbladet.se" "bookmark"
click c_c callback "new tooltip"
</pre </pre
> >
<pre id="diagram2" class="mermaid"> <pre id="diagram" class="mermaid">
%%{init: {"look": "neo", "theme": "forest","fontFamily": "Arial", "themeVariables": {
"useGradient": true,
"gradientStart": '#fff',
"gradientStop": '#ccc'
}} }%%
stateDiagram-v2
stateId
</pre
>
<pre id="diagram2" class="mermaid2">
flowchart LR flowchart LR
id1(Start)-->id2(Stop) id1(Start)-->id2(Stop)
style id1 fill:#f9f,stroke:#333,stroke-width:4px style id1 fill:#f9f,stroke:#333,stroke-width:4px
style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5 style id2 fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5
</pre> </pre>
<pre id="diagram3" class="mermaid"> <pre id="diagram3" class="mermaid2">
flowchart LR flowchart LR
A:::foo & B:::bar --> C:::foobar A:::foo & B:::bar --> C:::foobar
classDef foo stroke:#f00 classDef foo stroke:#f00
@@ -105,9 +96,9 @@ flowchart LR
</pre> </pre>
<pre id="diagram4" class="mermaid"> <pre id="diagram4" class="mermaid2">
stateDiagram stateDiagram
A:::foo A:::foo
B:::bar --> C:::foobar B:::bar --> C:::foobar
classDef foo stroke:#f00 classDef foo stroke:#f00
classDef bar stroke:#0f0 classDef bar stroke:#0f0
@@ -126,15 +117,17 @@ flowchart LR
alert('A callback was triggered'); alert('A callback was triggered');
}; };
mermaid.initialize({ mermaid.initialize({
theme: 'neo', theme: 'forest',
// handdrawnSeed: 12, // handdrawnSeed: 12,
// look: 'handdrawn', look: 'neo',
// 'elk.nodePlacement.strategy': 'NETWORK_SIMPLEX', // 'elk.nodePlacement.strategy': 'NETWORK_SIMPLEX',
// layout: 'dagre', // layout: 'dagre',
// layout: 'elk', // layout: 'elk',
// layout: 'fixed', // layout: 'fixed',
// htmlLabels: false, // htmlLabels: false,
flowchart: { titleTopMargin: 10 }, flowchart: { titleTopMargin: 10 },
// fontFamily: 'Caveat', // fontFamily: 'Caveat',
// fontFamily: 'Kalam', // fontFamily: 'Kalam',
// fontFamily: 'courier', // fontFamily: 'courier',

View File

@@ -1979,7 +1979,7 @@ direction LR
mermaid.initialize({ mermaid.initialize({
handdrawn: false, handdrawn: false,
mergeEdges: true, mergeEdges: true,
layout: 'dagre', layout: 'elk',
flowchart: { titleTopMargin: 10 }, flowchart: { titleTopMargin: 10 },
// fontFamily: 'Caveat', // fontFamily: 'Caveat',
fontFamily: 'Kalam', fontFamily: 'Kalam',

View File

@@ -197,7 +197,7 @@ export const createUserStyles = (
svgId: string svgId: string
): string => { ): string => {
const userCSSstyles = createCssStyles(config, classDefs); const userCSSstyles = createCssStyles(config, classDefs);
const allStyles = getStyles(graphType, userCSSstyles, config.themeVariables); const allStyles = getStyles(graphType, userCSSstyles, config.themeVariables, svgId);
// Now turn all of the styles into a (compiled) string that starts with the id // Now turn all of the styles into a (compiled) string that starts with the id
// use the stylis library to compile the css, turn the results into a valid CSS string (serialize(...., stringify)) // use the stylis library to compile the css, turn the results into a valid CSS string (serialize(...., stringify))
@@ -534,7 +534,7 @@ function initialize(options: MermaidConfig = {}) {
const config = const config =
typeof options === 'object' ? configApi.setSiteConfig(options) : configApi.getSiteConfig(); typeof options === 'object' ? configApi.setSiteConfig(options) : configApi.getSiteConfig();
console.log('IPI config', config.themeVariables.useGradient);
setLogLevel(config.logLevel); setLogLevel(config.logLevel);
addDiagrams(); addDiagrams();
} }

View File

@@ -47,11 +47,13 @@ export const render = async (data4Layout: any, svg: any, element: any, positions
const { useGradient, gradientStart, gradientStop } = data4Layout.config.themeVariables; const { useGradient, gradientStart, gradientStop } = data4Layout.config.themeVariables;
// console.log('IPI data4Layout', svg.attr('id'));
if (useGradient) { if (useGradient) {
const gradient = svg.append('linearGradient'); const gradient = svg.append('linearGradient');
gradient gradient
.attr('id', 'gradient') .attr('id', svg.attr('id') + '-gradient')
.attr('gradientUnits', 'userSpaceOnUse') .attr('gradientUnits', 'userSpaceOnUse')
.attr('spreadMethod', 'pad'); .attr('spreadMethod', 'pad');

View File

@@ -51,10 +51,12 @@ export const createInnerCylinderPathD = (
export const cylinder = async (parent: SVGAElement, node: Node) => { export const cylinder = async (parent: SVGAElement, node: Node) => {
const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node)); const { shapeSvg, bbox } = await labelHelper(parent, node, getNodeClasses(node));
const w = bbox.width + node.padding; const labelPaddingX = node.look === 'neo' ? node.padding * 2 : node.padding;
const labelPaddingY = node.look === 'neo' ? node.padding * 1 : node.padding;
const w = bbox.width + labelPaddingY;
const rx = w / 2; const rx = w / 2;
const ry = rx / (2.5 + w / 50); const ry = rx / (2.5 + w / 50);
const h = bbox.height + ry + node.padding; const h = bbox.height + ry + labelPaddingX;
let cylinder: d3.Selection<SVGPathElement | SVGGElement, unknown, null, undefined>; let cylinder: d3.Selection<SVGPathElement | SVGGElement, unknown, null, undefined>;
const { cssStyles } = node; const { cssStyles } = node;

View File

@@ -73,7 +73,7 @@ describe('styles', () => {
addStylesForDiagram(diagramType, myTypeGetStylesFunc); addStylesForDiagram(diagramType, myTypeGetStylesFunc);
const styles = getStyles(diagramType, '', getConfig().themeVariables); const styles = getStyles(diagramType, '', getConfig().themeVariables, '');
await checkValidStylisCSSStyleSheet(styles); await checkValidStylisCSSStyleSheet(styles);
}); });
@@ -107,7 +107,8 @@ describe('styles', () => {
diagramId, diagramId,
'', '',
// @ts-expect-error This will probably be broken until we create a proper Themes type. // @ts-expect-error This will probably be broken until we create a proper Themes type.
themes[themeId].getThemeVariables() themes[themeId].getThemeVariables(),
''
); );
await checkValidStylisCSSStyleSheet(styles); await checkValidStylisCSSStyleSheet(styles);

View File

@@ -15,7 +15,8 @@ const getStyles = (
errorTextColor: string; errorTextColor: string;
lineColor: string; lineColor: string;
useGradient: boolean; useGradient: boolean;
} & FlowChartStyleOptions } & FlowChartStyleOptions,
svgId: string
) => { ) => {
let diagramStyles = ''; let diagramStyles = '';
if (type in themes && themes[type as keyof typeof themes]) { if (type in themes && themes[type as keyof typeof themes]) {
@@ -75,18 +76,19 @@ const getStyles = (
} }
[data-look="neo"].node rect, [data-look="neo"].cluster rect, [data-look="neo"].node polygon { [data-look="neo"].node rect, [data-look="neo"].cluster rect, [data-look="neo"].node polygon {
stroke: ${options.useGradient ? 'url(#gradient)' : options.nodeBorder}; stroke: ${options.useGradient ? 'url(' + svgId + '-gradient)' : options.nodeBorder};
filter: ${options.dropShadow}; filter: ${options.dropShadow};
} }
[data-look="neo"].node rect, [data-look="neo"].node circle, [data-look="neo"].node polygon {
stroke: ${options.useGradient ? 'url(#gradient)' : options.nodeBorder}; [data-look="neo"].node rect, [data-look="neo"].node circle, [data-look="neo"].node polygon , [data-look="neo"].node path {
stroke: ${options.useGradient ? 'url(' + svgId + '-gradient)' : options.nodeBorder};
filter: ${options.dropShadow}; filter: ${options.dropShadow};
} }
[data-look="neo"].node circle{ [data-look="neo"].node circle{
stroke: $(options.nodeBorder); stroke: $(options.nodeBorder);
stroke: ${options.useGradient ? 'url(#gradient)' : options.nodeBorder}; stroke: ${options.useGradient ? 'url(' + svgId + '-gradient)' : options.nodeBorder};
filter: ${options.dropShadow}; filter: ${options.dropShadow};
} }
@@ -98,7 +100,8 @@ const getStyles = (
[data-look="neo"].statediagram-cluster rect { [data-look="neo"].statediagram-cluster rect {
fill: ${options.compositeTitleBackground}; fill: ${options.compositeTitleBackground};
stroke: ${options.useGradient ? 'url(#gradient)' : options.nodeBorder}; stroke: ${options.useGradient ? 'url(' + svgId + '-gradient)' : options.nodeBorder};
//stroke: none;
stroke-width: 1px; stroke-width: 1px;
} }