Skip to content

Commit

Permalink
fix diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
Fr0stbyteR committed Apr 27, 2024
1 parent 81debf4 commit eea6a22
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 29 deletions.
18 changes: 5 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -261315,10 +261315,10 @@ $( /*#__PURE__*/(0,_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MOD
* @returns {{ success: boolean; error?: Error }}
*/
updateDiagram = code => {
var svgs; // Diagram SVG as string
var strSvg; // Diagram SVG as string
editorDecoration = editor.deltaDecorations(editorDecoration, []);
try {
svgs = faustSvgDiagrams.from("FaustDSP", code, compileOptions.args.join(" "));
strSvg = faustSvgDiagrams.from("main", code, compileOptions.args.join(" "))["process.svg"];
} catch (e) {
/**
* Parse Faust-generated error message to locate the lines with error
Expand All @@ -261342,17 +261342,9 @@ $( /*#__PURE__*/(0,_babel_runtime_helpers_asyncToGenerator__WEBPACK_IMPORTED_MOD
}
// const $svg = $("#diagram-svg>svg");
// const curWidth = $svg.length ? $svg.width() : "100%"; // preserve current zoom
var mountSvg = svgStr => {
var svg = $(svgStr).filter("svg")[0];
$(svg).find(".link").each((i, e) => {
if (!e.onclick) return;
var fileName = e.onclick.toString().match(/'.+\/(.+)'/)[1];
e.onclick = () => mountSvg(svgs[fileName]);
});
var width = Math.min($("#diagram").width(), $("#diagram").height() / svg.height.baseVal.value * svg.width.baseVal.value);
$("#diagram-svg").empty().append(svg).children("svg").width(width); // replace svg;
};
mountSvg(svgs["process.svg"]);
var svg = $(strSvg).filter("svg")[0];
var width = Math.min($("#diagram").width(), $("#diagram").height() / svg.height.baseVal.value * svg.width.baseVal.value);
$("#diagram-svg").empty().append(svg).children("svg").width(width); // replace svg;
$("#diagram-default").hide(); // hide "No Diagram" info
clearError(); // Supress error shown
$("#diagram-svg").show(); // Show diagram div (if first time after opening page)
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/service-worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/service-worker.js.map

Large diffs are not rendered by default.

18 changes: 5 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ $(async () => {
* @returns {{ success: boolean; error?: Error }}
*/
const updateDiagram = (code: string): { success: boolean; error?: Error } => {
let svgs: Record<string, string>; // Diagram SVG as string
let strSvg: string; // Diagram SVG as string
editorDecoration = editor.deltaDecorations(editorDecoration, []);
try {
svgs = faustSvgDiagrams.from("FaustDSP", code, compileOptions.args.join(" "));
strSvg = faustSvgDiagrams.from("main", code, compileOptions.args.join(" "))["process.svg"];
} catch (e) {
/**
* Parse Faust-generated error message to locate the lines with error
Expand All @@ -246,17 +246,9 @@ $(async () => {
}
// const $svg = $("#diagram-svg>svg");
// const curWidth = $svg.length ? $svg.width() : "100%"; // preserve current zoom
const mountSvg = (svgStr: string) => {
const svg = $<SVGSVGElement>(svgStr).filter("svg")[0];
$(svg).find(".link").each((i, e) => {
if (!e.onclick) return;
const fileName = e.onclick.toString().match(/'.+\/(.+)'/)[1];
e.onclick = () => mountSvg(svgs[fileName]);
});
const width = Math.min($("#diagram").width(), $("#diagram").height() / svg.height.baseVal.value * svg.width.baseVal.value);
$("#diagram-svg").empty().append(svg).children("svg").width(width); // replace svg;
};
mountSvg(svgs["process.svg"]);
const svg = $<SVGSVGElement>(strSvg).filter("svg")[0];
const width = Math.min($("#diagram").width(), $("#diagram").height() / svg.height.baseVal.value * svg.width.baseVal.value);
$("#diagram-svg").empty().append(svg).children("svg").width(width); // replace svg;
$("#diagram-default").hide(); // hide "No Diagram" info
clearError(); // Supress error shown
$("#diagram-svg").show(); // Show diagram div (if first time after opening page)
Expand Down

0 comments on commit eea6a22

Please sign in to comment.