From a61abd9784fe765d508bfe20bfa1194a9e8c0d56 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Thu, 6 Apr 2023 17:52:34 +0100 Subject: [PATCH] fix over stretched uml pdf. update normalizeContract algorithm. --- .../remix-ide/src/app/plugins/contractFlattener.tsx | 4 +++- apps/remix-ide/src/app/plugins/solidity-umlgen.tsx | 5 +++-- .../src/lib/logic/flattenerUtilities.ts | 12 ++++-------- .../src/lib/utilities/UmlDownloadStrategy.ts | 13 ++++++++----- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/contractFlattener.tsx b/apps/remix-ide/src/app/plugins/contractFlattener.tsx index 544a206363..b61915372d 100644 --- a/apps/remix-ide/src/app/plugins/contractFlattener.tsx +++ b/apps/remix-ide/src/app/plugins/contractFlattener.tsx @@ -51,7 +51,8 @@ export class ContractFlattener extends Plugin { async flattenContract (source: { sources: any, target: string }, filePath: string, data: { contracts: any, sources: any }): Promise { const appendage = '_flattened.sol' - const path = `${normalizeContractPath(filePath)}${appendage}` + const normalized = normalizeContractPath(filePath) + const path = `${normalized[normalized.length - 2]}${appendage}` const ast = data.sources let dependencyGraph let sorted @@ -69,6 +70,7 @@ export class ContractFlattener extends Plugin { } await this.call('fileManager', 'writeFile', path , result) _paq.push(['trackEvent', 'plugin', 'contractFlattener', 'flattenAContract']) + // clean up memory references & return result sorted = null sources = null dependencyGraph = null diff --git a/apps/remix-ide/src/app/plugins/solidity-umlgen.tsx b/apps/remix-ide/src/app/plugins/solidity-umlgen.tsx index 76d99c3c86..865fde147e 100644 --- a/apps/remix-ide/src/app/plugins/solidity-umlgen.tsx +++ b/apps/remix-ide/src/app/plugins/solidity-umlgen.tsx @@ -5,7 +5,7 @@ import React from 'react' import { RemixUiSolidityUmlGen } from '@remix-ui/solidity-uml-gen' import { ISolidityUmlGen, ThemeQualityType, ThemeSummary } from 'libs/remix-ui/solidity-uml-gen/src/types' import { RemixAppManager } from 'libs/remix-ui/plugin-manager/src/types' -import { concatSourceFiles, getDependencyGraph, normalizeContractPath } from 'libs/remix-ui/solidity-compiler/src/lib/logic/flattenerUtilities' +import { normalizeContractPath } from 'libs/remix-ui/solidity-compiler/src/lib/logic/flattenerUtilities' import { convertUmlClasses2Dot } from 'sol2uml/lib/converterClasses2Dot' import { convertAST2UmlClasses } from 'sol2uml/lib/converterAST2Classes' import vizRenderStringSync from '@aduh95/viz.js/sync' @@ -77,6 +77,8 @@ export class SolidityUmlGen extends ViewPlugin implements ISolidityUmlGen { this.currentlySelectedTheme = currentTheme.quality this.themeName = currentTheme.name let result = '' + const normalized = normalizeContractPath(file) + this.currentFile = normalized[normalized.length - 1] try { if (data.sources && Object.keys(data.sources).length > 1) { // we should flatten first as there are multiple asts result = await this.flattenContract(source, file, data) @@ -121,7 +123,6 @@ export class SolidityUmlGen extends ViewPlugin implements ISolidityUmlGen { generateCustomAction = async (action: customAction) => { this.triggerGenerateUml = true this.updatedSvg = this.updatedSvg.startsWith(' canvasHeight ? 'landscape' : 'portrait' ctx.scale(window.devicePixelRatio, window.devicePixelRatio) ctx.drawImage(img, 0, 0, Math.round(img.naturalWidth/scale), Math.round(img.naturalHeight/scale)) if (doc === null || doc === undefined) { const { default: jsPDF } = await import('jspdf') - doc = new jsPDF('landscape', 'px', [img.naturalHeight, img.naturalWidth], true) + doc = new jsPDF(orientation, 'px', [img.naturalHeight, img.naturalWidth], true) } const pageWidth = doc.internal.pageSize.getWidth() const pageHeight = doc.internal.pageSize.getHeight() doc.addImage(canvas.toDataURL('image/png',0.5), 'PNG', 0, 0, pageWidth, pageHeight) - doc.save(fileName.split('/')[1].split('.')[0].concat('.pdf')) + doc.save(`${fileName}.pdf`) } img.src = url doc = null @@ -58,7 +61,7 @@ class ImageUmlDownloadStrategy implements IUmlDownloadStrategy { ctx.drawImage(img, 0, 0, Math.round(img.naturalWidth/scale), Math.round(img.naturalHeight/scale)) const png = canvas.toDataURL('image/png') const a = document.createElement('a') - a.download = fileName.split('/')[1].split('.')[0].concat('.png') + a.download = `${fileName}.png` a.href = png a.click() }