Git Product home page Git Product logo

day-heatmap's Introduction

day-heatmap.js

Day-heatmap exemple

day-heatmap.js is a simple library to create responsive github like heatmap to display data on a scale of a day.

Try it: live demo.

Setup

It's composed of a javascript and a css file.

Note: This library requires jQuery to work.

Method 1: Direct files

You can download the source files (under src/), and add them to your project (the javascript must be loaded after jQuery).

    <link rel="stylesheet" href="css/day-heatmap.min.css">
    <script src="js/day-heatmap.min.js"></script>

Method 2: CDN

The most easier thing is to use github as a CDN, so you don't have to donwload the files. Just add that to your project:

    <link rel="stylesheet" href="https://cdn.rawgit.com/CorentinTh/day-heatmap/master/src/day-heatmap.min.js">
    <script src="https://cdn.rawgit.com/CorentinTh/day-heatmap/master/src/day-heatmap.min.js"></script>

Make it works

To make it works you just need one line of javascript:

<script>
    DayHeatmap(element, options).data(dataset).draw();    
</script>

Where :

  • element is a string representing the id of the div where you want it to be displayed.
  • options (optional) is an object to customize a the heatmap.
    • halfDays a boolean, to display only a day in two
    • halfHours a boolean, to display only a hour in two
    • colors a 5 row array contening your custom gradient (index 0: the lighter, and index 4 the darker).
  • data is an object array with the following format :
var data = [
    {timestamp:1511401167678, value:5},
    {timestamp:1511401177542, value:2},
    // ...
]

Exemple

Here is a working exemple with all the functionnalities:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Heatmap</title>
    
    <link rel="stylesheet" href="https://cdn.rawgit.com/CorentinTh/day-heatmap/master/src/day-heatmap.min.js">

    <!-- Just for styling purpose -->
    <style>
        .container{
            width: 50%;
            margin:200px 25%;
        }
    </style>
</head>
<body>

<div class="container">
   <div id="day-heatmap"></div>
</div>

<!-- First jQuery -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdn.rawgit.com/CorentinTh/day-heatmap/master/src/day-heatmap.min.js"></script>
<script>
    var dummyData = [{timestamp: 738221588, value: 34}, {timestamp: 455091188, value: 85}, {timestamp: 1006992511, value: 61}, {timestamp: 374216407, value: 96}, {timestamp: 557060294, value: 39}, {timestamp: 1088268560, value: 45}, {timestamp: 790274681, value: 95}, {timestamp: 924184922, value: 46}, {timestamp: 16227933, value: 47}];

    DayHeatmap("day-heatmap",
        {
            halfDays: true,
            halfHours: true,
            colors: [
                "#7ae0cc",
                "#3fc5ab",
                "#379e8a",
                "#28675b",
                "#294C58"
            ]
        }).data(dummyData).draw();
</script>
</body>
</html>

Todo

  • Allow other type of data input.
  • Display tooltip with the value on hover of a square.

day-heatmap's People

Contributors

corentinth avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.