Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
e6087ad2
Unverified
Commit
e6087ad2
authored
3 years ago
by
Noah Moss
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Ensure PNG cropping doesn't clip table content (#20448)
parent
308090f1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/pulse/render/png.clj
+5
-1
5 additions, 1 deletion
src/metabase/pulse/render/png.clj
test/metabase/pulse/render/png_test.clj
+9
-3
9 additions, 3 deletions
test/metabase/pulse/render/png_test.clj
with
14 additions
and
4 deletions
src/metabase/pulse/render/png.clj
+
5
−
1
View file @
e6087ad2
...
...
@@ -86,7 +86,11 @@
RenderingHints/VALUE_FRACTIONALMETRICS_ON
))))]
(
.createLayout
graphics-engine
dimension
)
(
let
[
image
(
.getImage
graphics-engine
)
content-width
(
int
(
.getMaximalWidth
(
.getViewport
graphics-engine
)))]
viewport
(
.getViewport
graphics-engine
)
;; CSSBox voodoo -- sometimes maximal width < minimal width, no idea why
content-width
(
max
(
int
(
.getMinimalWidth
viewport
))
(
int
(
.getMaximalWidth
viewport
)))]
;; Crop the image to the actual size of the rendered content so that tables don't have a ton of whitespace.
(
if
(
<
content-width
(
.getWidth
image
))
(
.getSubimage
image
0
0
content-width
(
.getHeight
image
))
image
)))))
...
...
This diff is collapsed.
Click to expand it.
test/metabase/pulse/render/png_test.clj
+
9
−
3
View file @
e6087ad2
...
...
@@ -23,11 +23,17 @@
(
s/one
#
"^Error registering fonts"
"message"
)]
(
first
messages
))))))))
(
def
^
:private
test-table-html
(
def
^
:private
test-table-html
-1
"<table><tr><th>Column 1</th><th>Column 2</th></tr><tr><td>Data</td><td>Data</td></tr></table>"
)
(
def
^
:private
test-table-html-2
"<html><body style=\"margin: 0; padding: 0; background-color: white;\"><p><div style=\"overflow-x: auto;\"><a href=\"http://localhost:3000/question/2\" rel=\"noopener noreferrer\" style=\"font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; display: block; text-decoration: none;\" target=\"_blank\"><div class=\"pulse-body\" style=\"display: block; margin: 16px;\"><div><table cellpadding=\"0\" cellspacing=\"0\" style=\"max-width: 100%; white-space: nowrap; padding-bottom: 8px; border-collapse: collapse; width: 1%;\"><thead><tr><th style=\"min-width: 42px; color: #949AAB; text-align: left; font-size: 12px; font-weight: 700; padding-right: 0.375em; padding-top: 20px; padding-left: 0.375em; padding-bottom: 5px; font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; height: 28px; border-bottom: 1px solid #EDF0F1;\">Test URL</th><th style=\"min-width: 42px; color: #949AAB; text-align: left; font-size: 12px; font-weight: 700; padding-right: 0.375em; padding-top: 20px; padding-left: 0.375em; padding-bottom: 5px; font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; height: 28px; border-bottom: 1px solid #EDF0F1;\">Another Column</th><th style=\"min-width: 42px; color: #949AAB; text-align: right; font-size: 12px; font-weight: 700; padding-right: 0.375em; padding-top: 20px; padding-left: 0.375em; padding-bottom: 5px; font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; height: 28px; border-bottom: 1px solid #EDF0F1;\">Test Version ID</th></tr></thead><tbody><tr style=\"color: #7C8381;\"><td style=\"color: #4C5773; text-align: left; font-size: 12px; font-weight: 700; padding-right: 0.375em; padding-left: 0.375em; font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; height: 28px; border-bottom: 1px solid #F0F0F04D;\">test.example.com</td><td style=\"color: #4C5773; text-align: left; font-size: 12px; font-weight: 700; padding-right: 0.375em; padding-left: 0.375em; font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; height: 28px; border-bottom: 1px solid #F0F0F04D;\">this-is-a-test-value</td><td style=\"color: #4C5773; text-align: right; font-size: 12px; font-weight: 700; padding-right: 0.375em; padding-left: 0.375em; font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; height: 28px; border-bottom: 1px solid #F0F0F04D;\">123</td></tr></tbody></table></div></div></a></div></p></body></html>"
)
(
deftest
table-width-test
(
testing
"The PNG of a table should be cropped to the width of its content"
(
let
[
png
(
@#
'png/render-to-png
test-table-html
1200
)]
(
let
[
png
(
@#
'png/render-to-png
test-table-html
-1
1200
)]
;; Check that width is within a range, since actual rendered result can very slightly by environment
(
is
(
<
170
(
.getWidth
png
)
210
)))))
(
is
(
<
170
(
.getWidth
png
)
210
))))
(
testing
"The PNG of a table should not clip any of its content"
(
let
[
png
(
@#
'png/render-to-png
test-table-html-2
1200
)]
(
is
(
<
320
(
.getWidth
png
)
360
)))))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment