v0.0.2 2024-06-28 11:57 UTC

This package is auto-updated.

Last update: 2024-09-02 08:56:32 UTC


README

Packagist PHP Version Support Packagist Version Packagist Downloads

关于

从自定义数据集创建热图应该非常简单。我们在这里帮助你完成这项工作。

什么是热图?它是一种数据可视化技术,在二维空间中以颜色显示现象的强度[1],你可以从 GitHub 用户个人资料页面了解它

./docs/github.png

安装

Heatmap 以 Composer 库的形式通过 Packagist 分发。要将它添加到你的项目中,只需运行

composer require blumilksoftware/heatmap

使用方法

你可以使用任何你想要的数据集。默认情况下,日期将来自数组的 "created_at" 键或实现了 \ArrayAccess 接口的对象。构建器还接受实现了 \Blumilk\HeatmapBuilder\Contracts\TimeGroupable 协议的对象,该协议必须包含返回适当日期的 getTimeGroupableIndicator() 方法

$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", /** (...) */],
];

然后创建一个 \Blumilk\HeatmapBuilder\HeatmapBuilder 的实例。默认情况下,它将基于从调用时的那一刻起的一周内的天级周期进行工作

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

方法 build() 返回可以序列化为 JSON 的瓦片数组,使用简单的 json_encode() 函数或其他任何序列化器

[
  {
    "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": ""
  }
]