Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#33 refactor method (linting, readability) #180

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

warm-coolguy
Copy link
Member

@warm-coolguy warm-coolguy commented Sep 16, 2024

Summary

Improve readability of export implementation. Remove linting warning.

Instructions for local reproduction and review

Fiddle with export tool in snowbox to check some combinations. Snippet as reminder:

{
  export: {
    showPng: true,
    showJpg: true,
    showPdf: true,
    download: true,
  }
}

Relevant tickets, issues, et cetera

#33

@warm-coolguy warm-coolguy added the refactor Refactoring of previous code label Sep 16, 2024
@warm-coolguy warm-coolguy self-assigned this Sep 16, 2024
@warm-coolguy warm-coolguy changed the title refactor method (linting, readability) #33 refactor method (linting, readability) Sep 16, 2024
Copy link
Member

@dopenguin dopenguin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the past, we've added information regarding refactorings to the Changelog. I think some relevant entries should be added here as well
🏓 @warm-coolguy

const mapContext = mapCanvas.getContext('2d')
if (!mapContext) {
console.error(
'@polar/plugin-export: map does not of a 2d context, export failed.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'@polar/plugin-export: map does not of a 2d context, export failed.'
'@polar/plugin-export: map does not have a 2d context, export failed.'

Let's fix this while we are at it

matrix
)
mapContext.drawImage(canvas, 0, 0)
} else console.warn('@polar/plugin-export: canvas width is 0')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else console.warn('@polar/plugin-export: canvas width is 0')
} else console.warn('@polar/plugin-export: canvas width is 0.')

link.click()
document.body.removeChild(link)
}
if (download) downloadAsImage(src, type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I can' suggest it (deleted lines and such), here is what I would've anticipated:

if (
  (type === ExportFormat.JPG || type === ExportFormat.PNG) &&
  download
) {
  downloadAsImage(src, type)

jsPdf.addImage(src, 'JPEG', 0, 0, dim[0], dim[1])
// Reset original map size
map.setSize(size)
map.getView().setResolution(map.getView().getResolution())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must've been a reason for the variable beforehand. Are you sure, this doesn't change anything? map.getSize() is still set as a variable on the other hand.

Now that I think about it: What happens if neither the size of the map or the resolution is reset?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactoring of previous code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants