Skip to content

Commit 7cd57f2

Browse files
committed
fix: restore 'top-languages-card'
Restores the original 'top-languages-card' code since it is not part of \#2900.
1 parent 5467847 commit 7cd57f2

File tree

1 file changed

+43
-47
lines changed

1 file changed

+43
-47
lines changed

src/cards/top-languages-card.js

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from "../common/utils.js";
1313
import { langCardLocales } from "../translations.js";
1414

15-
15+
const DEFAULT_CARD_WIDTH = 300;
1616
const MIN_CARD_WIDTH = 280;
1717
const DEFAULT_LANG_COLOR = "#858585";
1818
const CARD_PADDING = 25;
@@ -218,14 +218,14 @@ const createProgressTextNode = ({ width, color, name, progress, index }) => {
218218
<text data-testid="lang-name" x="2" y="15" class="lang-name">${name}</text>
219219
<text x="${progressTextX}" y="34" class="lang-name">${progress}%</text>
220220
${createProgressNode({
221-
x: 0,
222-
y: 25,
223-
color,
224-
width: progressWidth,
225-
progress,
226-
progressBarBackgroundColor: "#ddd",
227-
delay: staggerDelay + 300,
228-
})}
221+
x: 0,
222+
y: 25,
223+
color,
224+
width: progressWidth,
225+
progress,
226+
progressBarBackgroundColor: "#ddd",
227+
delay: staggerDelay + 300,
228+
})}
229229
</g>
230230
`;
231231
};
@@ -382,22 +382,21 @@ const renderCompactLayout = (langs, width, totalLanguageSize, hideProgress) => {
382382
.join("");
383383

384384
return `
385-
${
386-
!hideProgress
387-
? `
388-
<mask id="rect-mask">
389-
<rect x="0" y="0" width="${offsetWidth}" height="8" fill="white" rx="5"/>
390-
</mask>
391-
${compactProgressBar}
392-
`
393-
: ""
394-
}
385+
${hideProgress
386+
? ""
387+
: `
388+
<mask id="rect-mask">
389+
<rect x="0" y="0" width="${offsetWidth}" height="8" fill="white" rx="5"/>
390+
</mask>
391+
${compactProgressBar}
392+
`
393+
}
395394
<g transform="translate(0, ${hideProgress ? "0" : "25"})">
396395
${createLanguageTextNode({
397-
langs,
398-
totalSize: totalLanguageSize,
399-
hideProgress,
400-
})}
396+
langs,
397+
totalSize: totalLanguageSize,
398+
hideProgress,
399+
})}
401400
</g>
402401
`;
403402
};
@@ -431,7 +430,7 @@ const renderDonutVerticalLayout = (langs, totalLanguageSize) => {
431430

432431
circles.push(`
433432
<g class="stagger" style="animation-delay: ${delay}ms">
434-
<circle
433+
<circle
435434
cx="150"
436435
cy="100"
437436
r="${radius}"
@@ -462,10 +461,10 @@ const renderDonutVerticalLayout = (langs, totalLanguageSize) => {
462461
<g transform="translate(0, 220)">
463462
<svg data-testid="lang-names" x="${CARD_PADDING}">
464463
${createLanguageTextNode({
465-
langs,
466-
totalSize: totalLanguageSize,
467-
hideProgress: false,
468-
})}
464+
langs,
465+
totalSize: totalLanguageSize,
466+
hideProgress: false,
467+
})}
469468
</svg>
470469
</g>
471470
</svg>
@@ -557,10 +556,10 @@ const renderPieLayout = (langs, totalLanguageSize) => {
557556
<g transform="translate(0, 220)">
558557
<svg data-testid="lang-names" x="${CARD_PADDING}">
559558
${createLanguageTextNode({
560-
langs,
561-
totalSize: totalLanguageSize,
562-
hideProgress: false,
563-
})}
559+
langs,
560+
totalSize: totalLanguageSize,
561+
hideProgress: false,
562+
})}
564563
</svg>
565564
</g>
566565
</svg>
@@ -629,11 +628,11 @@ const renderDonutLayout = (langs, width, totalLanguageSize) => {
629628
langs.length === 1
630629
? `<circle cx="${centerX}" cy="${centerY}" r="${radius}" stroke="${colors[0]}" fill="none" stroke-width="${strokeWidth}" data-testid="lang-donut" size="100"/>`
631630
: langPaths
632-
.map((section, index) => {
633-
const staggerDelay = (index + 3) * 100;
634-
const delay = staggerDelay + 300;
631+
.map((section, index) => {
632+
const staggerDelay = (index + 3) * 100;
633+
const delay = staggerDelay + 300;
635634

636-
const output = `
635+
const output = `
637636
<g class="stagger" style="animation-delay: ${delay}ms">
638637
<path
639638
data-testid="lang-donut"
@@ -646,9 +645,9 @@ const renderDonutLayout = (langs, width, totalLanguageSize) => {
646645
</g>
647646
`;
648647

649-
return output;
650-
})
651-
.join("");
648+
return output;
649+
})
650+
.join("");
652651

653652
const donut = `<svg width="${width}" height="${width}">${donutPaths}</svg>`;
654653

@@ -681,8 +680,7 @@ const renderDonutLayout = (langs, width, totalLanguageSize) => {
681680
*/
682681
const noLanguagesDataNode = ({ color, text, layout }) => {
683682
return `
684-
<text x="${
685-
layout === "pie" || layout === "donut-vertical" ? CARD_PADDING : 0
683+
<text x="${layout === "pie" || layout === "donut-vertical" ? CARD_PADDING : 0
686684
}" y="11" class="stat bold" fill="${color}">${text}</text>
687685
`;
688686
};
@@ -734,8 +732,6 @@ const renderTopLanguages = (topLangs, options = {}) => {
734732
layout,
735733
custom_title,
736734
locale,
737-
card_width = DEFAULT_CARD_WIDTH,
738-
card_height = calculateNormalLayoutHeight(topLangs.length),
739735
langs_count = getDefaultLanguagesCountByLayout({ layout, hide_progress }),
740736
border_radius,
741737
border_color,
@@ -757,8 +753,8 @@ const renderTopLanguages = (topLangs, options = {}) => {
757753
? isNaN(card_width)
758754
? DEFAULT_CARD_WIDTH
759755
: card_width < MIN_CARD_WIDTH
760-
? MIN_CARD_WIDTH
761-
: card_width
756+
? MIN_CARD_WIDTH
757+
: card_width
762758
: DEFAULT_CARD_WIDTH;
763759
let height = calculateNormalLayoutHeight(langs.length);
764760

@@ -806,8 +802,8 @@ const renderTopLanguages = (topLangs, options = {}) => {
806802
const card = new Card({
807803
customTitle: custom_title,
808804
defaultTitle: i18n.t("langcard.title"),
809-
width: card_width,
810-
height: card_height,
805+
width,
806+
height,
811807
border_radius,
812808
colors,
813809
});

0 commit comments

Comments
 (0)