Skip to content
Open
Changes from all 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
20 changes: 12 additions & 8 deletions src/cards/wakatime.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const languageColors = require("../common/languageColors.json"); // now works
const DEFAULT_CARD_WIDTH = 495;
const MIN_CARD_WIDTH = 250;
const COMPACT_LAYOUT_MIN_WIDTH = 400;
const DEFAULT_LINE_HEIGHT = 25;

/**
* Creates the no coding activity SVG node.
Expand Down Expand Up @@ -103,7 +104,7 @@ const createLanguageTextNode = ({ langs, y, display_format, card_width }) => {
return createCompactLangNode({
lang,
x: isLeft ? LEFT_X : RIGHT_X,
y: isLeft ? 12.5 * index + y : 12.5 + 12.5 * index,
y: y + DEFAULT_LINE_HEIGHT * Math.floor(index / 2),
display_format,
});
});
Expand Down Expand Up @@ -135,6 +136,8 @@ const createTextNode = ({
progressBarBackgroundColor,
progressBarWidth,
}) => {
const PROGRESSBAR_PADDING = 130;
const HIDDEN_PROGRESSBAR_PADDING = 170;
const staggerDelay = (index + 3) * 150;

const cardProgress = hideProgress
Expand All @@ -156,7 +159,7 @@ const createTextNode = ({
<text class="stat bold" y="12.5" data-testid="${id}">${label}:</text>
<text
class="stat"
x="${hideProgress ? 170 : 130 + progressBarWidth}"
x="${hideProgress ? HIDDEN_PROGRESSBAR_PADDING : PROGRESSBAR_PADDING + progressBarWidth}"
y="12.5"
>${value}</text>
${cardProgress}
Expand Down Expand Up @@ -249,7 +252,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
hide_border = false,
card_width,
hide,
line_height = 25,
line_height = DEFAULT_LINE_HEIGHT,
title_color,
icon_color,
text_color,
Expand Down Expand Up @@ -318,16 +321,16 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {

// RENDER COMPACT LAYOUT
if (layout === "compact") {
let width = normalizedWidth - 5;
height = 90 + Math.round(filteredLanguages.length / 2) * 25;
const PROGRESSBAR_PADDING = 25;
height = 90 + Math.round(filteredLanguages.length / 2) * DEFAULT_LINE_HEIGHT;

// progressOffset holds the previous language's width and used to offset the next language
// so that we can stack them one after another, like this: [--][----][---]
let progressOffset = 0;
const compactProgressBar = filteredLanguages
.map((language) => {
// const progress = (width * lang.percent) / 100;
const progress = ((width - 25) * language.percent) / 100;
const progress = ((normalizedWidth - PROGRESSBAR_PADDING) * language.percent) / 100;

const languageColor = languageColors[language.name] || "#858585";

Expand All @@ -349,7 +352,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {

finalLayout = `
<mask id="rect-mask">
<rect x="25" y="0" width="${width - 50}" height="8" fill="white" rx="5" />
<rect x="${PROGRESSBAR_PADDING}" y="0" width="${normalizedWidth - 2 * PROGRESSBAR_PADDING}" height="8" fill="white" rx="5" />
</mask>
${compactProgressBar}
${
Expand All @@ -372,6 +375,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
}
`;
} else {
const TOTAL_TEXT_WIDTH = 275;
finalLayout = flexLayout({
items: filteredLanguages.length
? filteredLanguages.map((language, index) => {
Expand All @@ -386,7 +390,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
// @ts-ignore
progressBarBackgroundColor: textColor,
hideProgress: hide_progress,
progressBarWidth: normalizedWidth - 275,
progressBarWidth: normalizedWidth - TOTAL_TEXT_WIDTH,
});
})
: [
Expand Down
Loading