npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hsablonniere/activity-graph

v1.0.2

Published

A low level and stylable Web Component to display an activity graph.

Downloads

42

Readme

activity-graph

A low level and stylable Web Component to display an activity graph.

Demos and screenshots

Here are some demos:

[!NOTE]

Keep in mind that the themes on the demo page and screenshots are just examples of what can be done. They're not released with this component, you will have to create your own theme.

GitHub

Here's an example of my 2023 GitHub contribution graph.

An activity graph representing a year with weeks as columns. Some days are colored with different tones for indicating contribution intensity. It's the same theme as the one on GitHub.

Serializd

Here's an example of my 2024 Serializd stats graph.

[An activity graph representing a year with weeks as columns. Some days are colored with different tones for indicating how many TV show episodes were watched. It's the same theme as the one on Serializd.]

Monkeytype

Here's an example of my 2024 Monkeytype stats graph.

[An activity graph representing a year with weeks as columns. Some days are colored with different tones for indicating how many tests were done. It's the same theme as the one on Monkeytype.]

Letterboxd

Here's an example of what could be my 2023 Letterboxd stats graph, if they had such a graph.

[An activity graph representing a year with weeks as columns. Some days are colored with different tones for indicating how many movies were watched. It's following the general look and feel of Letterboxd.]

How to install?

Via npm

This component is published on npm. You can "npm install" it in your project with this command:

npm install @hsablonniere/activity-graph

Via CDN

You can also directly use modern CDNs that exposes npm packages like JSDelivr:

<script type="module" src="https://cdn.jsdelivr.net/npm/@hsablonniere/activity-graph/+esm"></script>

or esm.sh:

<script type="module" src="https://esm.sh/@hsablonniere/activity-graph"></script>

How to use?

Use the <activity-graph> custom HTML tag like this:

<activity-graph start-date="2024-01-01" end-date="2024-12-31"></activity-graph>

Attributes / properties

Data

The data can be set as a JavaScript object on the data property, or as JSON on the data attribute. It must respect the following type definition:

// Keys must be YYYY-MM-DD date strings
type ActivityGraphData = Record<string, ActivityGraphDataEntry>;

interface ActivityGraphDataEntry {
  // Used for the day "cell" inner text
  text?: string;
  // Used for the day "cell" `title` attribute, for tooltips and accessibility
  title?: string;
  // Used for the day "cell" `part` attribute, as in CSS shadow part for styling purposes
  parts?: Array<string>;
}

Here's an example:

myActivityGraph.data = {
  '2024-04-01': {
    title: '2 contributions',
    parts: ['level-1'],
  },
  '2024-04-04': {
    title: '27 contributions',
    parts: ['level-4'],
  },
};

Styling

By default, the component does not have any styles. You'll have to rely on the different CSS parts and custom properties to create a theme.

[!NOTE]

  • You can rely on the fact that the element has a display: grid and use properties like gap directly on it.
  • You can have a look at the demos and their respective themes to get some ideas on how to style the component.

CSS parts

| Part | Description | | ---------------------- | ------------------------------------ | | weekday-header | Target any weekday header | | weekday-header--even | Target even numbered weekday headers | | weekday-header--odd | Target odd numbered weekday headers | | month-header | Target any month header | | day | Target any day "cell" |

[!TIP]

If you want to use a CSS shadow part, you'll need the ::part() pseudo element like this:

activity-graph::part(month-header) {
  text-align: center;
}

Custom properties

| Property | Description | | --------------------------------- | ----------------------------------------------------------- | | var(--activity-graph-month-gap) | Spacing between months, can be any CSS unit, 0 by default |

Why this project?

I really like this way of visualizing a whole year of data at once. Watching such graphs on GitHub, Serializd or Monkeytype, I grew a need to have a similar dataviz for other services where I track and log stuffs like Letterboxd or fitbit. I wondered how easy it would be to create my own component and that's how I went down this rabbit whole.

In the end, I restarted from scratch 3 times to try different ideas to handle the dates and the CSS grid. It wasn't a simple problem to tackle but I had lots of fun working on this.

Design decisions

I started the project as a vanilla Web Component, without any dependency. I guess I was wondering how small the final bundle would be, I achied something close to 1.6kb (minified and compressed). My code was not that easy to read and I had no support for properties, just attributes. A few commits later, I quickly realized I was recreating a very dumb, verbose and unefficient version of lit. That's when I decided to add lit as the only dependency. In the end, the component code + lit is 6.4kb (minified and compressed).

I wanted something based on CSS grids without any styles by default so that anyone could reuse it and apply their own theme. At first, you could specify some style properties on the data object but I replaced it with CSS shadow parts to maximize styling in the CSS.

Other similar projects

I created this project without looking at the competition but obviously many smart people tried before me.

Mario Hamann also made a Web Component and his approach (a11y, WASM, SSR...) is very interesting!

  • GitHub project: https://github.com/mariohamann/activity-graph
  • Article: https://mariohamann.com/activity-graph-component

And of course, there are plenty of framework specific components for React, Vue, Svelte:

  • https://github.com/Angstboksen/date-activity-graph
  • https://github.com/AyushSaini00/github-contribution-graph
  • https://github.com/KaranGulve4342/react-github-contributions
  • https://github.com/cairongquan/contriGraph
  • https://github.com/charpeni/sync-external-contributions
  • https://github.com/grubersjoe/react-activity-calendar
  • https://github.com/grubersjoe/react-github-calendar
  • https://github.com/marcelovicentegc/react-github-heatmap
  • https://github.com/razorness/vue3-calendar-heatmap
  • https://github.com/scottbedard/svelte-heatmap
  • https://github.com/srivenkat13/github-calendar-component
  • https://github.com/uiwjs/react-heat-map
  • https://github.com/x3388638/github-calendar-graph