Giter VIP home page Giter VIP logo

heatmap's Introduction

Packagist PHP Version Support Packagist Version Packagist Downloads

About

Making a heatmap from custom datasets should be extremely easy. We are here to help you with that.

What's a heatmap? It is a data visualization technique that shows magnitude of a phenomenon as color in two dimensions[1], and you can know it from GitHub user profile pages:

./docs/github.png

Installation

The Heatmap is distributed as Composer library via Packagist. To add it to your project, just run:

composer require blumilksoftware/heatmap

Usage

You can use any set of data you want. By default, dates will be taken from "created_at" key of arrays or objects implementing \ArrayAccess interface. Builder accepts also objects implementing \Blumilk\HeatmapBuilder\Contracts\TimeGroupable contract with mandatory getTimeGroupableIndicator() method returning a string with proper date:

$data = [
    ["created_at" => "2022-11-01 00:00:00", /** (...) */],
    ["created_at" => "2022-11-03 00:00:00", /** (...) */],
    ["created_at" => "2022-11-16 00:00:00", /** (...) */],
    ["created_at" => "2022-11-16 00:00:00", /** (...) */],
    ["created_at" => "2022-11-18 00:00:00", /** (...) */],
    ["created_at" => "2022-11-19 00:00:00", /** (...) */],
];

Then create an instance of \Blumilk\HeatmapBuilder\HeatmapBuilder. By default, it will be working on day-based periods for last week from the moment you are calling it:

$builder = new HeatmapBuilder();
$result = $builder->build($data);

Method build() returns array of tiles that can be serialized into JSON with simple json_encode() function or any other serializer:

[
  {
    "label": "2022-11-16",
    "count": 2,
    "description": ""
  },
  {
    "label": "2022-11-17",
    "count": 0,
    "description": ""
  },
  {
    "label": "2022-11-18",
    "count": 1,
    "description": ""
  },
  {
    "label": "2022-11-19",
    "count": 1,
    "description": ""
  },
  {
    "label": "2022-11-20",
    "count": 0,
    "description": ""
  },
  {
    "label": "2022-11-21",
    "count": 0,
    "description": ""
  },
  {
    "label": "2022-11-22",
    "count": 0,
    "description": ""
  },
  {
    "label": "2022-11-23",
    "count": 0,
    "description": ""
  }
]

heatmap's People

Contributors

bartracz avatar krzysztofrewak avatar

Stargazers

 avatar Kamil Piech avatar

Watchers

Jacek Sawoszczuk avatar Mateusz Lencki avatar Adrian Hopek avatar  avatar  avatar

heatmap's Issues

Proper documentation

Proper documentation (hosted on GithubPages?) should be created for this package.

Showing current tile

Adding some specific classes to "current" tile would be nice.

Instead of this:
obraz

it could render something like this:
obraz

Introduce GitHub Action

At least these actions should be added to the repositoty:

  • lint & test
  • check PR title
  • deploy documentation (when #3 would be finished)

Prepare package for Packagist

In this metatask I would like to prepare package to be published in Packagist.

AC:

  • adjust repository name and library name
  • think about how main namespace should be named
  • add Packagist badges in readme (as in our other public PHP repositories)
  • maybe something more?

Playground for manual testing

I think that we could provide really simple set of tools to play with the package. We could add some index.html with simple script fetch prebuilt data.json (that could be gitignored) and simple index.php script with heatmap builder results saved to JSON file.

Bug with isFuture flag

Current day tile is incorrectly marked as "future one".

Te replicate:

        $builder = new HeatmapBuilder(
            periodInterval: PeriodInterval::Weekly,
            period: new CarbonPeriod($firstEpisode->watched_at, "1 week", Carbon::now()->endOfYear()),
            arrayAccessIndex: "watched_at",
            decorator: new Decorator("sky"),
            alignedToEndOfPeriod: true,
        );

Screenshot:
image

Current week's tile receives $futureTileClass in tile's decorator. It should not.

Timezone handling

I believe that there would be multiple problems with timezones within this package. It should be studied, discussed and refactored to handle timezones of provided data.

Bonus: probably we should update package to Carbon 3.

Laravel integration

I would like to have an option to pass Eloquent models/queries with some parameters instead of sets of data. Blade components would be nice too.

We should discuss if this should be done here or maybe in another package (eg. laravel-heatmap).

Extending tiles to target start of period

Github has nice mechanism that extends number of tiles for year not to exact 365 days, but to first day of week:

image

I would like to add methods to align that in this package. Maybe something like this would be good approach:

public function forLastYear(bool $align = false): static

Bump dev dependencies

I would like to (at least):

  • test package on PHP 8.2 and PHP 8.3
  • think about minimal PHP version requirement
  • bump PHPUnit to the newest
  • bump codestyle version to the newest

Tests fix

Tests need to be fixed because they do not work properly without a time zone.

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.