magicoder10 / github-stats

Embed Github profile every where you want
https://www.time4hacks.com
67 stars 7 forks source link
chart commit es6 github javascript library statistics utility

Github Stats

Embed Github profile every where you want

Preview

Commit Contributions

Language Contributions

Getting Started

Installation

Include github-stats.js in your html head tag:

<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/byliuyang/github-stats@0.0.4/src/github-stats.js"></script>

For older releases, use the follow snippet instead:

<script type="text/javascript" src="https://github.com/magicoder10/github-stats/raw/master/
https://cdn.jsdelivr.net/gh/byliuyang/github-stats@VERSION/src/github-stats.js"></script>

Please remember to replace VERSION with the version number you are using.

Usage

To use Github Stats, add the following JavaScript to your website:

(async () => {
    const GITHUB_USERNAME = 'byliuyang';
    const COMMITS_CONTAINER = '#github-contributions';
    const LANGUAGES_CONTAINER = '#github-language-distribution';

    const githubStats = await GithubStats(GITHUB_USERNAME);

    let githubCommits = document.querySelector(COMMITS_CONTAINER);
    /* Render SVG for commit contributions */
    let commitsContribSVG = githubStats.commitsContribSVG({
        rows: 7,
        space: 4,
        rectWidth: 16,
        levelColors: [
            {
                minCommits: 0,
                color: '#ebedf0'
            },
            {
                minCommits: 1,
                color: '#c6e48b'
            },
            {
                minCommits: 9,
                color: '#7bc96f'
            },
            {
                minCommits: 17,
                color: '#239a3b'
            },
            {
                minCommits: 26,
                color: '#196127'
            }
        ]
    });
    githubCommits.appendChild(commitsContribSVG);

    let githubLanguageDistribution = document.querySelector(LANGUAGES_CONTAINER);
    /* Render SVG for language contributions */
    let languageContribSVG = githubStats.languagesContribSVG({
        barHeight: 20,
        barWidth: githubLanguageDistribution.offsetWidth,
        lineSpacing: 4,
        languageNameWidth: 100,
        fontSize: 14
    });
    githubLanguageDistribution.appendChild(languageContribSVG);
})();

Please don't forget to replace GITHUB_USERNAME with your Github username and *_CONTAINER with the css selector where you want render the contributions inside.

Options

Commit Contributions SVG

Language Contributions SVG

Release

The latest release is v0.0.4. You can find all the releases here

Design Patterns

This project is engineered based on closure mentioned in You Don't Know Js

Authors

License

This project is maintained under the MIT License.