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

fix badge style when logo only #10794

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
290 changes: 221 additions & 69 deletions __snapshots__/make-badge.spec.mjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2161,75 +2161,6 @@ exports['The badge generator "social" template badge generation should match sna

`

exports['The badge generator badges with logos should always produce the same badge badge with logo 1'] = `
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="113"
height="20"
role="img"
aria-label="label: message"
>
<title>label: message</title>
<linearGradient id="s" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1" />
<stop offset="1" stop-opacity=".1" />
</linearGradient>
<clipPath id="r">
<rect width="113" height="20" rx="3" fill="#fff" />
</clipPath>
<g clip-path="url(#r)">
<rect width="54" height="20" fill="#555" />
<rect x="54" width="59" height="20" fill="#4c1" />
<rect width="113" height="20" fill="url(#s)" />
</g>
<g
fill="#fff"
text-anchor="middle"
font-family="Verdana,Geneva,DejaVu Sans,sans-serif"
text-rendering="geometricPrecision"
font-size="110"
>
<image
x="5"
y="3"
width="14"
height="14"
xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxu"
/>
<text
aria-hidden="true"
x="365"
y="150"
fill="#010101"
fill-opacity=".3"
transform="scale(.1)"
textLength="270"
>
label
</text>
<text x="365" y="140" transform="scale(.1)" fill="#fff" textLength="270">
label
</text>
<text
aria-hidden="true"
x="825"
y="150"
fill="#010101"
fill-opacity=".3"
transform="scale(.1)"
textLength="490"
>
message
</text>
<text x="825" y="140" transform="scale(.1)" fill="#fff" textLength="490">
message
</text>
</g>
</svg>

`

exports['The badge generator "flat" template badge generation should match snapshots: message with custom suffix 1'] = `
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down Expand Up @@ -2551,3 +2482,224 @@ exports['The badge generator "social" template badge generation should match sna
</svg>

`

exports['The badge generator badges with logos should always produce the same badge default badge with logo 1'] = `
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="113"
height="20"
role="img"
aria-label="label: message"
>
<title>label: message</title>
<linearGradient id="s" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1" />
<stop offset="1" stop-opacity=".1" />
</linearGradient>
<clipPath id="r">
<rect width="113" height="20" rx="3" fill="#fff" />
</clipPath>
<g clip-path="url(#r)">
<rect width="54" height="20" fill="#555" />
<rect x="54" width="59" height="20" fill="#4c1" />
<rect width="113" height="20" fill="url(#s)" />
</g>
<g
fill="#fff"
text-anchor="middle"
font-family="Verdana,Geneva,DejaVu Sans,sans-serif"
text-rendering="geometricPrecision"
font-size="110"
>
<image
x="5"
y="3"
width="14"
height="14"
xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxu"
/>
<text
aria-hidden="true"
x="365"
y="150"
fill="#010101"
fill-opacity=".3"
transform="scale(.1)"
textLength="270"
>
label
</text>
<text x="365" y="140" transform="scale(.1)" fill="#fff" textLength="270">
label
</text>
<text
aria-hidden="true"
x="825"
y="150"
fill="#010101"
fill-opacity=".3"
transform="scale(.1)"
textLength="490"
>
message
</text>
<text x="825" y="140" transform="scale(.1)" fill="#fff" textLength="490">
message
</text>
</g>
</svg>

`

exports['The badge generator badges with logo-only should always produce the same badge flat badge, logo-only 1'] = `
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="25"
height="20"
role="img"
aria-label=""
>
<title></title>
<linearGradient id="s" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1" />
<stop offset="1" stop-opacity=".1" />
</linearGradient>
<clipPath id="r"><rect width="25" height="20" rx="3" fill="#fff" /></clipPath>
<g clip-path="url(#r)">
<rect width="0" height="20" fill="#555" />
<rect x="0" width="25" height="20" fill="#4c1" />
<rect width="25" height="20" fill="url(#s)" />
</g>
<g
fill="#fff"
text-anchor="middle"
font-family="Verdana,Geneva,DejaVu Sans,sans-serif"
text-rendering="geometricPrecision"
font-size="110"
>
<image
x="5"
y="3"
width="14"
height="14"
xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxu"
/>
</g>
</svg>

`

exports['The badge generator badges with logo-only should always produce the same badge flat-square badge, logo-only 1'] = `
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="25"
height="20"
role="img"
aria-label=""
>
<title></title>
<g shape-rendering="crispEdges">
<rect width="0" height="20" fill="#555" />
<rect x="0" width="25" height="20" fill="#4c1" />
</g>
<g
fill="#fff"
text-anchor="middle"
font-family="Verdana,Geneva,DejaVu Sans,sans-serif"
text-rendering="geometricPrecision"
font-size="110"
>
<image
x="5"
y="3"
width="14"
height="14"
xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxu"
/>
</g>
</svg>

`

exports['The badge generator badges with logo-only should always produce the same badge social badge, logo-only 1'] = `
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="35"
height="28"
role="img"
aria-label=""
>
<title></title>
<g shape-rendering="crispEdges">
<rect width="35" height="28" fill="#4c1" />
</g>
<g
fill="#fff"
text-anchor="middle"
font-family="Verdana,Geneva,DejaVu Sans,sans-serif"
text-rendering="geometricPrecision"
font-size="100"
>
<image
x="9"
y="7"
width="14"
height="14"
xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxu"
/>
<text
transform="scale(.1)"
x="230"
y="175"
textLength="0"
fill="#fff"
font-weight="bold"
></text>
</g>
</svg>

`

exports['The badge generator badges with logo-only should always produce the same badge plastic badge, logo-only 1'] = `
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="35"
height="28"
role="img"
aria-label=""
>
<title></title>
<g shape-rendering="crispEdges">
<rect width="35" height="28" fill="#4c1" />
</g>
<g
fill="#fff"
text-anchor="middle"
font-family="Verdana,Geneva,DejaVu Sans,sans-serif"
text-rendering="geometricPrecision"
font-size="100"
>
<image
x="9"
y="7"
width="14"
height="14"
xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxu"
/>
<text
transform="scale(.1)"
x="230"
y="175"
textLength="0"
fill="#fff"
font-weight="bold"
></text>
</g>
</svg>

`
11 changes: 6 additions & 5 deletions badge-maker/lib/badge-renderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class Badge {
}
let rightWidth = messageWidth + 2 * horizPadding
if (hasLogo && !hasLabel) {
rightWidth += totalLogoWidth + horizPadding - 1
rightWidth += totalLogoWidth + (message.length ? horizPadding - 1 : 0)
}

const width = leftWidth + rightWidth
Expand Down Expand Up @@ -804,11 +804,13 @@ function forTheBadge({
// there is no label. When `needsLabelRect` is true, render a label rect and a
// message rect; when false, only a message rect.
const hasLabel = Boolean(label.length)
const noText = !hasLabel && !message
const needsLabelRect = hasLabel || (logo && labelColor)
const gutter = noText ? LOGO_TEXT_GUTTER - LOGO_MARGIN : LOGO_TEXT_GUTTER
let logoMinX, labelTextMinX
if (logo) {
logoMinX = LOGO_MARGIN
labelTextMinX = logoMinX + logoWidth + LOGO_TEXT_GUTTER
labelTextMinX = logoMinX + logoWidth + gutter
} else {
labelTextMinX = TEXT_MARGIN
}
Expand All @@ -823,9 +825,8 @@ function forTheBadge({
messageRectWidth = 2 * TEXT_MARGIN + messageTextWidth
} else {
if (logo) {
messageTextMinX = TEXT_MARGIN + logoWidth + LOGO_TEXT_GUTTER
messageRectWidth =
2 * TEXT_MARGIN + logoWidth + LOGO_TEXT_GUTTER + messageTextWidth
messageTextMinX = TEXT_MARGIN + logoWidth + gutter
messageRectWidth = 2 * TEXT_MARGIN + logoWidth + gutter + messageTextWidth
} else {
messageTextMinX = TEXT_MARGIN
messageRectWidth = 2 * TEXT_MARGIN + messageTextWidth
Expand Down
44 changes: 43 additions & 1 deletion badge-maker/lib/make-badge.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ describe('The badge generator', function () {
})

describe('badges with logos should always produce the same badge', function () {
it('badge with logo', async function () {
it('default badge with logo', async function () {
await expectBadgeToMatchSnapshot({
label: 'label',
message: 'message',
Expand All @@ -709,4 +709,46 @@ describe('The badge generator', function () {
})
})
})

describe('badges with logo-only should always produce the same badge', function () {
it('flat badge, logo-only', async function () {
await expectBadgeToMatchSnapshot({
label: '',
message: '',
format: 'svg',
logo: 'data:image/svg+xml;base64,PHN2ZyB4bWxu',
style: 'flat',
})
})

it('flat-square badge, logo-only', async function () {
await expectBadgeToMatchSnapshot({
label: '',
message: '',
format: 'svg',
logo: 'data:image/svg+xml;base64,PHN2ZyB4bWxu',
style: 'flat-square',
})
})

it('social badge, logo-only', async function () {
await expectBadgeToMatchSnapshot({
label: '',
message: '',
format: 'svg',
logo: 'data:image/svg+xml;base64,PHN2ZyB4bWxu',
style: 'for-the-badge',
})
})

it('plastic badge, logo-only', async function () {
await expectBadgeToMatchSnapshot({
label: '',
message: '',
format: 'svg',
logo: 'data:image/svg+xml;base64,PHN2ZyB4bWxu',
style: 'for-the-badge',
LitoMore marked this conversation as resolved.
Show resolved Hide resolved
})
})
})
})
Loading