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

@cantoo/svg-radar-chart

v1.0.11

Published

A reusable radar chart in SVG.

Downloads

29

Readme

svg-radar-chart

Generate SVG radar charts.

an example

npm version ISC-licensed minimum Node.js version support me via GitHub Sponsors chat with me on Twitter

This library is inspired by radar-chart-d3 but tries to do a few things differently:

  • svg-radar-chart does not limit you in which frontend stack you use. It just returns virtual-dom nodes.
  • Because radar-chart-d3 includes D3, it weighs 212k. svg-radar-chart weighs 9k.
  • Because angular-radial-plot includes includes D3, it weighs roughly 160k. svg-radar-chart weighs 9k.

Note: This library is an opinionated tool; I maintain it with my personal use cases in mind. I do'nt intend to cover every feature a radar chart library might possibly need.

Installing

npm install svg-radar-chart

Usage

import {radar} from 'svg-radar-chart'

const chart = radar({
	// columns
	battery: 'Battery Capacity',
	design: 'Design',
	useful: 'Usefulness',
}, [
	// data
	{class: 'iphone', battery: .7, design:  1, useful: .9},
	{class: 'galaxy', battery:  1, design: .6, useful: .8},
	{class: 'nexus',  battery: .8, design: .7, useful: .6},
])

svg-radar-chart returns virtual-dom, so you can decide what to do with it.

To generate an SVG string from it, use virtual-dom-stringify:

import stringify from 'virtual-dom-stringify'

const svg = `
<svg version="1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
	<style>
		.axis {
			stroke-width: .2;
		}
		.scale {
			stroke-width: .2;
		}
		.shape {
			fill-opacity: .3;
		}
		.shape:hover {
			fill-opacity: .6;
		}
	</style>
	${stringify(chart)}
</svg>
`

You may now create an SVG file using Node.js:

process.stdout.write(svg)
node generate-chart.js >chart.svg

Or insert it into the DOM:

document.querySelector('#my-chart').innerHTML = svg

Check the website or the example on how to customize charts further.

Smoothing

You can pass the cardinal-closed smoothing function as follows, but it will add another 18k to your bundle, if you use common-shakeify, otherwise a bit more.

import {smoothing} from 'svg-radar-chart/smoothing.js'

radar(columns, data, {
	smoothing: smoothing(.3), // tension of .3
})

API

radar(columns, data, opt = {})

columns must be an object. The values are captions.

data must be an array of data points. The keys in one data points must exist in columns.

opt is optional and has the following default values:

const defaults = {
	size: 100, // size of the chart (including captions)
	axes: true, // show axes?
	scales: 3, // show scale circles?
	captions: true, // show captions?
	captionsPosition: 1.2, // where on the axes are the captions?
	smoothing: noSmoothing, // shape smoothing function
	axisProps: () => ({className: 'axis'}),
	scaleProps: () => ({className: 'scale', fill: 'none'}),
	shapeProps: () => ({className: 'shape'}),
	captionProps: () => ({
		className: 'caption',
		textAnchor: 'middle', fontSize: 3,
		fontFamily: 'sans-serif',
	}),
}

smoothing(points) must return valid SVG <path> commands.

See also

  • svg-patterns – Create SVG patterns programmatically to visualize data.
  • svg-world-map – Render a world map with a pin at a specific location.

Contributing

If you have a question, found a bug or want to propose a feature, have a look at the issues page.