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

chrt-points

v0.0.42

Published

Points component for Chrt

Downloads

212

Readme

chrt-points

Component for creating point-based visualizations in chrt, such as scatter plots, bubble charts, and point charts. Points can be customized in size, shape, color, and other visual properties to represent additional dimensions of data.

The component provides flexible ways to create:

  • Scatter Plots (points with fixed size)
  • Bubble Charts (points with size based on data)
  • Custom Point Charts (points with different shapes and rotations)

Observable Examples and Documentation:

Installing

For use with Webpack, Rollup, or other Node-based bundlers, chrt-points can be installed as a standalone module via a package manager such as Yarn or npm.

npm install chrt-points chrt-core

chrt-points can be used as part of the chrt package:

npm install chrt

Usage

ES6 / Bundlers (Webpack, Rollup, etc.)

import Chrt from "chrt-core";
import { chrtPoints } from "chrt-points";

// Create a basic scatter plot
Chrt()
  .data([
    { x: 1, y: 2 },
    { x: 2, y: 3 },
    { x: 3, y: 1 },
  ])
  .add(chrtPoints());

// Create a bubble chart
Chrt().add(
  chrtPoints()
    .data(data)
    .size((d) => d.value),
);

API Reference

Point Properties

.radius([value]) / .size([value])

Sets the radius or size of points. Size can be fixed or determined by data.

// Fixed size
chrtPoints().radius(5);

// Size based on data value
chrtPoints().size((d) => d.population);

// Size with custom scale
chrtPoints().size({
  range: [2, 20],
  field: "population",
});

.symbol([type[, option]])

Sets the symbol type for points. Available symbols: 'circle' (default), 'square', 'text', 'custom'.

// Use square symbols
chrtPoints().symbol("square");

// Use text as symbols
chrtPoints().symbol("text", "A");

// Custom symbol
chrtPoints().symbol("custom", "M 0,0 L 10,10");

.rotate([angle])

Sets the rotation angle of points in degrees.

// Fixed rotation
chrtPoints().rotate(45);

// Rotation based on data
chrtPoints().rotate((d) => d.angle);

Styling

.color([value]) / .fill([value])

Sets the fill color of points.

// Single color
chrtPoints().fill("#ff0000");

// Color based on data
chrtPoints().fill((d) => (d.value > 100 ? "#ff0000" : "#0000ff"));

.stroke([value]) / .strokeWidth([value])

Sets the stroke color and width of points.

// Set stroke color and width
chrtPoints().stroke("#000000").strokeWidth(2);

.opacity([value]) / .strokeOpacity([value])

Sets the opacity of point fill and stroke.

// Set fill and stroke opacity
chrtPoints().opacity(0.7).strokeOpacity(0.5);

Examples

Basic Scatter Plot

Chrt().add(
  chrtPoints()
    .data(data)
    .radius(5)
    .fill("#336699")
    .stroke("#000")
    .strokeWidth(1),
);

Bubble Chart

Chrt().add(
  chrtPoints()
    .data(data)
    .size((d) => d.population)
    .fill((d) => (d.category === "A" ? "#ff0000" : "#0000ff"))
    .opacity(0.7)
    .stroke("#333"),
);

Custom scale for size

Define a custom scale for the size of the points, with a domain and a range and a scaling function.

Chrt()
  .scale({
    name: "r",
    range: [0, 50],
    domain: [0, 10000],
    scale: "sqrt",
    field: "population",
    type: "other",
  })
  .add(
    chrtPoints()
      .data(data)
      .size({ scale: "r" })
      .fill((d) => (d.category === "A" ? "#ff0000" : "#0000ff"))
      .opacity(0.7)
      .stroke("#333"),
  );

Custom Symbols

Chrt().add(
  chrtPoints().data(data).symbol("square").rotate(45).size(8).fill("#ff6600"),
);

Points with Multiple Visual Encodings

The dataset could encode multiple visual encodings, such as size, color, opacity, symbol, and rotation based on the single data point.

Chrt().add(
  chrtPoints()
    .data(data)
    .size((d) => d.value) // size encodes value
    .fill((d) => d.category) // color encodes category
    .opacity((d) => d.confidence) // opacity encodes confidence
    .symbol((d) => d.type) // symbol encodes type
    .rotate((d) => d.direction), // rotation encodes direction
);