1
1
import os
2
2
3
+
3
4
def output_html (output_name : str , field_name : str , flowchart : str ) -> None :
4
5
"""
5
6
This function outputting flowchart as html.
@@ -17,12 +18,12 @@ def output_html(output_name: str, field_name: str, flowchart: str) -> None:
17
18
"""
18
19
19
20
# Three raw html code sections encapsulated in triple quotes """
20
- html_part_before_title = """<!DOCTYPE html>
21
+ html_part_before_title = """<!DOCTYPE html>
21
22
<html lang="en">
22
23
<head>
23
24
<meta charset="utf-8">
24
25
<title>"""
25
- html_part_after_title_before_code_block = """</title>
26
+ html_part_after_title_before_code_block = """</title>
26
27
<style type="text/css">
27
28
.end-element { fill : #FFCCFF; }
28
29
</style>
@@ -36,7 +37,7 @@ def output_html(output_name: str, field_name: str, flowchart: str) -> None:
36
37
var btn = document.getElementById("run"),
37
38
cd = document.getElementById("code"),
38
39
chart;
39
-
40
+
40
41
(btn.onclick = function () {
41
42
var code = cd.value;
42
43
@@ -66,11 +67,11 @@ def output_html(output_name: str, field_name: str, flowchart: str) -> None:
66
67
'scale': 1,
67
68
'symbols': {
68
69
'start': {
69
- 'font-size': 14,
70
+ 'font-size': 14,
70
71
'font-color': 'yellow',
71
72
'element-color': 'blue',
72
73
'fill': 'green',
73
- 'class': 'start-element'
74
+ 'class': 'start-element'
74
75
},
75
76
'inputoutput': {
76
77
'font-color': 'black',
@@ -89,11 +90,11 @@ def output_html(output_name: str, field_name: str, flowchart: str) -> None:
89
90
},
90
91
'condition': {
91
92
'font-color': 'red',
92
- 'element-color': 'black',
93
+ 'element-color': 'black',
93
94
'fill': 'yellow'
94
95
},
95
96
'end':{
96
- 'font-size': 20,
97
+ 'font-size': 20,
97
98
'class': 'end-element'
98
99
}
99
100
},
@@ -107,42 +108,42 @@ def output_html(output_name: str, field_name: str, flowchart: str) -> None:
107
108
'rejected' : { 'fill' : '#C45879', 'font-size' : 12, 'yes-text' : 'n/a', 'no-text' : 'REJECTED' }
108
109
}
109
110
});
110
- //create base64 encoding of SVG to generate download link for title(without html or htm).SVG
111
- var currentCanvasDIV = document.getElementById('canvas')
112
- var currentDrawSVG = currentCanvasDIV.innerHTML.replaceAll('ë','e');
111
+ //create base64 encoding of SVG to generate download link for title(without html or htm).SVG
112
+ var currentCanvasDIV = document.getElementById('canvas')
113
+ var currentDrawSVG = currentCanvasDIV.innerHTML.replaceAll('ë','e');
113
114
114
- const OUTsvgBASE64 = btoa(currentDrawSVG)
115
- doctitle = document.title.replace('.html','');
116
- doctitle = doctitle.replace('.htm','');
115
+ const OUTsvgBASE64 = btoa(currentDrawSVG)
116
+ doctitle = document.title.replace('.html','');
117
+ doctitle = doctitle.replace('.htm','');
117
118
118
119
119
- var currentCanvasDIV = document.getElementById('canvas')
120
- var currentDrawSVG = currentCanvasDIV.innerHTML.replaceAll('ë','e');
121
- svgSource = currentDrawSVG
122
- svgXML = currentDrawSVG;
123
- // Use SVG Height and Width from the SVG XML to set canvas size
124
- svgXMLsubstringHeight = svgXML.substring(svgXML.indexOf('height='), svgXML.indexOf('version='));
125
- svgXMLsubstringWidth = svgXML.substring(svgXML.indexOf('width='), svgXML.indexOf('xmlns='));
126
- HeightValue = svgXMLsubstringHeight.substring(svgXMLsubstringHeight.indexOf('"')+1,svgXMLsubstringHeight.lastIndexOf('"'));
127
- WidthValue = svgXMLsubstringWidth.substring(svgXMLsubstringWidth.indexOf('"')+1,svgXMLsubstringWidth.lastIndexOf('"'));
128
- HeightValueInt = Math.round(HeightValue)
129
- WidthValueInt = Math.round(WidthValue)
130
- // setup input for base64SvgToBase64Png
131
- let svgSrc = "data:image/svg+xml;base64,"+OUTsvgBASE64;
132
- var pngBase
133
- imageUtil.base64SvgToBase64Png(svgSrc, WidthValueInt, HeightValueInt).then(pngSrc => {
134
- pngBase = pngSrc
135
- // output download link for base64 PNG converted on download from base64
136
- var pngOutHtml = `<a href="${pngBase}" download="${doctitle}.png">PNG - Click here to download current rendered flowchart as ${doctitle}.png</a>`
137
- document.getElementById("pngbase64").innerHTML=pngOutHtml;
138
- });
139
- // output download link for base64 SVG converted on download from base64
140
- var svgOutHtml = `<a href="data:image/svg+xml;base64,${OUTsvgBASE64}" download=${doctitle}.svg>SVG - Click here to download current rendered flowchart as ${doctitle}.svg</a> `
141
- document.getElementById("svgbase64").innerHTML=svgOutHtml;
142
- })();
120
+ var currentCanvasDIV = document.getElementById('canvas')
121
+ var currentDrawSVG = currentCanvasDIV.innerHTML.replaceAll('ë','e');
122
+ svgSource = currentDrawSVG
123
+ svgXML = currentDrawSVG;
124
+ // Use SVG Height and Width from the SVG XML to set canvas size
125
+ svgXMLsubstringHeight = svgXML.substring(svgXML.indexOf('height='), svgXML.indexOf('version='));
126
+ svgXMLsubstringWidth = svgXML.substring(svgXML.indexOf('width='), svgXML.indexOf('xmlns='));
127
+ HeightValue = svgXMLsubstringHeight.substring(svgXMLsubstringHeight.indexOf('"')+1,svgXMLsubstringHeight.lastIndexOf('"'));
128
+ WidthValue = svgXMLsubstringWidth.substring(svgXMLsubstringWidth.indexOf('"')+1,svgXMLsubstringWidth.lastIndexOf('"'));
129
+ HeightValueInt = Math.round(HeightValue)
130
+ WidthValueInt = Math.round(WidthValue)
131
+ // setup input for base64SvgToBase64Png
132
+ let svgSrc = "data:image/svg+xml;base64,"+OUTsvgBASE64;
133
+ var pngBase
134
+ imageUtil.base64SvgToBase64Png(svgSrc, WidthValueInt, HeightValueInt).then(pngSrc => {
135
+ pngBase = pngSrc
136
+ // output download link for base64 PNG converted on download from base64
137
+ var pngOutHtml = `<a href="${pngBase}" download="${doctitle}.png">PNG - Click here to download current rendered flowchart as ${doctitle}.png</a>`
138
+ document.getElementById("pngbase64").innerHTML=pngOutHtml;
139
+ });
140
+ // output download link for base64 SVG converted on download from base64
141
+ var svgOutHtml = `<a href="data:image/svg+xml;base64,${OUTsvgBASE64}" download=${doctitle}.svg>SVG - Click here to download current rendered flowchart as ${doctitle}.svg</a> `
142
+ document.getElementById("svgbase64").innerHTML=svgOutHtml;
143
+ })();
143
144
144
- };
145
-
145
+ };
146
+
146
147
147
148
// derived from https://stackoverflow.com/a/64800570
148
149
// we need to use web browser canvas to generate a image. In this case png
@@ -156,7 +157,7 @@ def output_html(output_name: str, field_name: str, flowchart: str) -> None:
156
157
*/
157
158
imageUtil.base64SvgToBase64Png = function (originalBase64, width, height, secondTry) {
158
159
return new Promise(resolve => {
159
- let img = document.createElement('img');
160
+ let img = document.createElement('img');
160
161
img.onload = function () {
161
162
if (!secondTry && (img.naturalWidth === 0 || img.naturalHeight === 0)) {
162
163
let svgDoc = base64ToSvgDocument(originalBase64);
@@ -213,28 +214,28 @@ def output_html(output_name: str, field_name: str, flowchart: str) -> None:
213
214
}
214
215
</script>
215
216
216
- <script>
217
- function HelpText() {
218
- var x = document.getElementById("HelpTextBlock");
219
- if (x.style.display === "none") {
220
- x.style.display = "block";
221
- } else {
222
- x.style.display = "none";
223
- }
224
- }
225
- </script>
217
+ <script>
218
+ function HelpText() {
219
+ var x = document.getElementById("HelpTextBlock");
220
+ if (x.style.display === "none") {
221
+ x.style.display = "block";
222
+ } else {
223
+ x.style.display = "none";
224
+ }
225
+ }
226
+ </script>
226
227
</head>
227
228
<body>
228
229
<div><textarea id="code" style="width: 100%;" rows="11">"""
229
230
230
- html_part_after_code_block_remaining_html = """</textarea></div>
231
+ html_part_after_code_block_remaining_html = """</textarea></div>
231
232
<div><button id="run" type="button">Run</button> <button onclick="HelpText()">Format Help</button></div>
232
- <div id="HelpTextBlock" style="display:none"><br/>Conditions can also be redirected like cond(yes, bottom) or cond(yes, right)
233
+ <div id="HelpTextBlock" style="display:none"><br/>Conditions can also be redirected like cond(yes, bottom) or cond(yes, right)
233
234
... and the other symbols too... like sub1(right)<br/>
234
235
You can also tweak the <b>diagram.drawSVG('diagram', {});</b> script in this file for more changes<br/>
235
236
This is based on <a href="https://github.com/adrai/flowchart.js">flowchart.js on github</a> and <a href="http://flowchart.js.org">http://flowchart.js.org</a> more documentation can be found over there.
236
237
</div><br/><div id="svgbase64"></div>
237
- <div id="pngbase64"></div>
238
+ <div id="pngbase64"></div>
238
239
239
240
<div id="canvas"></div>
240
241
</body>
0 commit comments