Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Customize the appearance of your Activity Graph however you want with URL params
| `hide_border` | makes the border of the graph transparent | boolean (default: `false`) |
| `hide_title` | sets the title to an empty string | boolean (default: `false`) |
| `custom_title` | set the title to any string | string |
| `title_font_size` | font-size of the graph's title | number (5-40 inclusive) |
| `theme` | name of [available themes](#available-themes) | string |
| `radius` | border radius of graph | number (0-16 inclusive) |
| `height` | height of the graph | number (200-600 inclusive) |
Expand Down
14 changes: 14 additions & 0 deletions __test__/fakeInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export let fakeQueryString = [
hide_title: false,
custom_title: undefined,
title_color: 'ffffff',
title_font_size: 30,
},
{
username: 'githubusername',
Expand All @@ -16,6 +17,7 @@ export let fakeQueryString = [
bg_color: '44475a',
hide_title: false,
custom_title: undefined,
title_font_size: 2,
},
{
username: 'githubusername',
Expand All @@ -25,6 +27,7 @@ export let fakeQueryString = [
color: '000000',
hide_title: false,
custom_title: undefined,
title_font_size: 50,
},
{
username: 'githubusername',
Expand Down Expand Up @@ -113,6 +116,7 @@ export let fakeQueryStringRes = [
pointColor: '403d3d',
},
hide_title: false,
title_font_size: 30,
area: false,
days: 31,
from: '',
Expand All @@ -133,6 +137,7 @@ export let fakeQueryStringRes = [
pointColor: '403d3d',
},
hide_title: false,
title_font_size: 5,
area: false,
days: 31,
from: '',
Expand All @@ -153,6 +158,7 @@ export let fakeQueryStringRes = [
pointColor: '403d3d',
},
hide_title: false,
title_font_size: 40,
area: false,
days: 31,
from: '',
Expand All @@ -173,6 +179,7 @@ export let fakeQueryStringRes = [
pointColor: '403d3d',
},
hide_title: false,
title_font_size: 20,
area: false,
days: 31,
from: '',
Expand All @@ -193,6 +200,7 @@ export let fakeQueryStringRes = [
pointColor: '44475a',
},
hide_title: false,
title_font_size: 20,
area: false,
days: 31,
from: '',
Expand All @@ -213,6 +221,7 @@ export let fakeQueryStringRes = [
pointColor: 'bd93f9',
},
hide_title: false,
title_font_size: 20,
area: true,
days: 31,
from: '',
Expand All @@ -234,6 +243,7 @@ export let fakeQueryStringRes = [
},
area: true,
hide_title: false,
title_font_size: 20,
days: 31,
from: '',
to: '',
Expand All @@ -254,6 +264,7 @@ export let fakeQueryStringRes = [
},
area: true,
hide_title: true,
title_font_size: 20,
days: 31,
from: '',
to: '',
Expand All @@ -274,6 +285,7 @@ export let fakeQueryStringRes = [
},
area: true,
hide_title: false,
title_font_size: 20,
custom_title: 'some title',
days: 31,
from: '',
Expand All @@ -295,6 +307,7 @@ export let fakeQueryStringRes = [
},
area: true,
hide_title: false,
title_font_size: 20,
days: 31,
from: '',
to: '',
Expand All @@ -316,6 +329,7 @@ export let fakeGraphArgs: GraphArgs = {
pointColor: 'bd93f9',
},
title: 'graphSvg',
titleFontSize: 20,
line: Promise.resolve('line'),
};

Expand Down
8 changes: 8 additions & 0 deletions __test__/svgs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ describe('SVG Testing', () => {
expect(invalidUserSvg(fakeInvalidSvgArg)).toMatchSnapshot();
});

it('Test custom title font-size', () => {
const svg = graphSvg({ ...fakeGraphArgs, titleFontSize: 32 });
expect(svg).toContain(
"font: 600 32px 'Segoe UI', Ubuntu, Sans-Serif;\n text-align: center;",
);
expect(svg).toContain('<foreignObject x="0" y="0" width="20" height="62">');
});

//- Svg testing Promise<string> (GrapgCards.ts)✔
it('chart SVGs', async () => {
expect.assertions(1);
Expand Down
2 changes: 2 additions & 0 deletions src/GraphCards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class Card {
private readonly title = '',
private readonly area = false,
private readonly showGrid = true,
private readonly titleFontSize = 20,
) {}

private getOptions() {
Expand Down Expand Up @@ -77,6 +78,7 @@ export class Card {
width: this.width,
colors: this.colors,
title: this.title,
titleFontSize: this.titleFontSize,
radius: this.radius,
line,
};
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class QueryOption {
username: string;
hide_title?: boolean;
custom_title?: string;
title_font_size: number;
from?: string;
to?: string;
grid: boolean;
Expand All @@ -33,6 +34,7 @@ export class ParsedQs {
username?: string;
hide_title?: boolean;
custom_title?: string;
title_font_size?: number;
bg_color?: string;
border_color?: string;
hide_border?: boolean;
Expand All @@ -56,6 +58,7 @@ export class GraphArgs {
width: number;
colors: Colors;
title: string;
titleFontSize: number;
radius: number;
line: Promise<string>;
}
Expand Down
4 changes: 2 additions & 2 deletions src/svgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const graphSvg = (props: GraphArgs) => `
font: 600 18px 'Segoe UI', Ubuntu, Sans-Serif;
}
.header {
font: 600 20px 'Segoe UI', Ubuntu, Sans-Serif;
font: 600 ${props.titleFontSize}px 'Segoe UI', Ubuntu, Sans-Serif;
text-align: center;
color: #${props.colors.titleColor ?? props.colors.color};
margin-top: 20px;
Expand All @@ -39,7 +39,7 @@ export const graphSvg = (props: GraphArgs) => `
${lineAnimation()}
</style>

<foreignObject x="0" y="0" width="${props.width}" height="50">
<foreignObject x="0" y="0" width="${props.width}" height="${props.titleFontSize + 30}">
<h1 xmlns="http://www.w3.org/1999/xhtml" class="header">
${props.title}
</h1>
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export class Utilities {
const options: QueryOption = {
username: this.username,
hide_title: String(this.queryString.hide_title) === 'true',
title_font_size: this.queryString.title_font_size
? Math.min(Math.max(this.queryString.title_font_size, 5), 40)
: 20, // Custom title font-size in range [5, 40], if not specified use default value - 20
radius: this.queryString.radius
? Math.min(Math.max(this.queryString.radius, 0), 16)
: 0, // Border radius in range [0, 16]
Expand Down Expand Up @@ -154,6 +157,7 @@ export class Utilities {
title,
options.area,
options.grid,
options.title_font_size,
);
const getChart = await graph.buildGraph(fetchCalendarData.contributions);
return {
Expand Down