Skip to content

Commit

Permalink
anuraghazra#3307 enhancement : prog_bg_color query added to change th…
Browse files Browse the repository at this point in the history
…e background of progress bar
  • Loading branch information
a-s-t-e-y-a committed Oct 1, 2023
1 parent 712cb18 commit e291374
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
3 changes: 2 additions & 1 deletion api/top-langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export default async (req, res) => {
border_color,
disable_animations,
hide_progress,
prog_bg_color,
} = req.query;
res.setHeader("Content-Type", "image/svg+xml");

if (blacklist.includes(username)) {
return res.send(renderError("Something went wrong"));
}
Expand Down Expand Up @@ -96,6 +96,7 @@ export default async (req, res) => {
locale: locale ? locale.toLowerCase() : null,
disable_animations: parseBoolean(disable_animations),
hide_progress: parseBoolean(hide_progress),
prog_bg_color,
}),
);
} catch (err) {
Expand Down
28 changes: 23 additions & 5 deletions src/cards/top-languages-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,19 @@ const trimTopLanguages = (topLangs, langs_count, hide) => {
* @param {number} props.width The card width
* @param {string} props.color Color of the programming language.
* @param {string} props.name Name of the programming language.
* @param {string} props.prog_bg_color Color of the background of progress bar
* @param {number} props.progress Usage of the programming language in percentage.
* @param {number} props.index Index of the programming language.
* @returns {string} Programming language SVG node.
*/
const createProgressTextNode = ({ width, color, name, progress, index }) => {
const createProgressTextNode = ({
width,
color,
name,
progress,
index,
prog_bg_color,
}) => {
const staggerDelay = (index + 3) * 150;
const paddingRight = 95;
const progressTextX = width - paddingRight + 10;
Expand All @@ -223,7 +231,9 @@ const createProgressTextNode = ({ width, color, name, progress, index }) => {
color,
width: progressWidth,
progress,
progressBarBackgroundColor: "#ddd",
progressBarBackgroundColor: prog_bg_color
? `#${prog_bg_color}`
: "#ddd",
delay: staggerDelay + 300,
})}
</g>
Expand Down Expand Up @@ -322,9 +332,10 @@ const createDonutLanguagesNode = ({ langs, totalSize }) => {
* @param {Lang[]} langs Array of programming languages.
* @param {number} width Card width.
* @param {number} totalLanguageSize Total size of all languages.
* @param {string} prog_bg_color Total size of all languages.
* @returns {string} Normal layout card SVG object.
*/
const renderNormalLayout = (langs, width, totalLanguageSize) => {
const renderNormalLayout = (langs, width, totalLanguageSize, prog_bg_color) => {
return flexLayout({
items: langs.map((lang, index) => {
return createProgressTextNode({
Expand All @@ -335,6 +346,7 @@ const renderNormalLayout = (langs, width, totalLanguageSize) => {
((lang.size / totalLanguageSize) * 100).toFixed(2),
),
index,
prog_bg_color,
});
}),
gap: 40,
Expand Down Expand Up @@ -738,8 +750,9 @@ const renderTopLanguages = (topLangs, options = {}) => {
border_radius,
border_color,
disable_animations,
prog_bg_color,
} = options;

console.log(prog_bg_color);
const i18n = new I18n({
locale,
translations: langCardLocales,
Expand Down Expand Up @@ -798,7 +811,12 @@ const renderTopLanguages = (topLangs, options = {}) => {
width = width + 50; // padding
finalLayout = renderDonutLayout(langs, width, totalLanguageSize);
} else {
finalLayout = renderNormalLayout(langs, width, totalLanguageSize);
finalLayout = renderNormalLayout(
langs,
width,
totalLanguageSize,
prog_bg_color,
);
}

const card = new Card({
Expand Down
1 change: 1 addition & 0 deletions src/cards/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type CommonOptions = {
icon_color: string;
text_color: string;
bg_color: string;
prog_bg_color: string;
theme: ThemeNames;
border_radius: number;
border_color: string;
Expand Down

0 comments on commit e291374

Please sign in to comment.