fix over stretched uml pdf. update normalizeContract algorithm.

pull/3602/head
Joseph Izang 2 years ago
parent 2534f4efdf
commit 6b6ed9b23e
  1. 4
      apps/remix-ide/src/app/plugins/contractFlattener.tsx
  2. 5
      apps/remix-ide/src/app/plugins/solidity-umlgen.tsx
  3. 12
      libs/remix-ui/solidity-compiler/src/lib/logic/flattenerUtilities.ts
  4. 13
      libs/remix-ui/solidity-uml-gen/src/lib/utilities/UmlDownloadStrategy.ts

@ -51,7 +51,8 @@ export class ContractFlattener extends Plugin {
async flattenContract (source: { sources: any, target: string },
filePath: string, data: { contracts: any, sources: any }): Promise<string> {
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

@ -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('<?xml') ? '' : this.updatedSvg
this.currentFile = action.path[0].split('/')[1]
_paq.push(['trackEvent', 'solidityumlgen', 'activated'])
await this.generateUml(action.path[0])
}

@ -168,9 +168,9 @@ function _resolvePathArray(parts) {
return res;
}
export function normalizeContractPath(contractPath: string): string {
let paths = contractPath.split('/')
let filename = paths[paths.length - 1].split('.')[0]
export function normalizeContractPath(contractPath: string): string[] {
const paths = contractPath.split('/')
const filename = paths[paths.length - 1].split('.')[0]
let folders = ''
for (let i = 0; i < paths.length - 1; i++) {
if(i !== paths.length -1) {
@ -178,9 +178,5 @@ export function normalizeContractPath(contractPath: string): string {
}
}
const resultingPath = `${folders}${filename}`
// cleanup variables
paths = null
filename = null
folders = null
return resultingPath
return [folders,resultingPath, filename]
}

@ -18,20 +18,23 @@ class PdfUmlDownloadStrategy implements IUmlDownloadStrategy {
canvas.height = img.naturalHeight
const ctx = canvas.getContext('2d')
const scale = window.devicePixelRatio*1
canvas.style.width = `${Math.round(img.naturalWidth/scale)}`.concat('px')
canvas.style.height = `${Math.round(img.naturalHeight/scale)}`.concat('px')
const canvasWidth = Math.round(img.naturalWidth/scale)
const canvasHeight = Math.round(img.naturalHeight/scale)
canvas.style.width = `${canvasWidth}px`
canvas.style.height = `${canvasHeight}px`
canvas.style.margin = '0'
canvas.style.padding = '0'
const orientation = canvasWidth > 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()
}

Loading…
Cancel
Save