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

svg-spider-chart

v0.2.2

Published

SVG-based spider chart, a.k.a. radar chart.

Downloads

9

Readme

SVG-Spider-Chart

SVG spider chart

SVG-based spider chart, a.k.a. radar chart, based on Derhuerst's version. The main differences are:

  • The virtual dom library can be injected, for example, you can inject mithril's m function.
  • By default, a spider chart is displayed instead of a radar chart, i.e. using linear scale lines instead of circles.
  • It provides a Mithril component factory, SpiderChartFactory, to create SpiderCharts by injecting mithril's m function.
  • You can specify a CSS style to use in the options (so when you save it, the CSS style is saved too).
  • Using Typescript also provides type definitions.

Playground

To play around with the component using mithril, please visit flems.

Usage

You can either use the SpiderChartFactory to create your own SpiderChart by injecting the virtual dom function factory (in the example below, mithril is used). Or alternatively, you can import the render function, and render the content inside your own SVG (it generates the plain chart, without svg element around it).

import m from 'mithril';
import {
  SpiderChartFactory,
  SpiderColumns,
  SpiderData,
  SpiderOptions,
} from 'svg-spider-chart';


const columns = {
  price: 'Price',
  useful: 'Usefulness',
  design: 'Design',
  battery: 'Battery Capacity',
  camera: 'Camera Quality',
} as SpiderColumns;

const data = [
  {
    // iphone
    color: '#edc951',
    price: 1,
    battery: 0.7,
    design: 1,
    useful: 0.9,
    camera: 0.9,
  },
  {
    // galaxy
    color: '#cc333f',
    price: 0.8,
    battery: 1,
    design: 0.6,
    useful: 0.8,
    camera: 1,
  },
  {
    // nexus
    color: '#00a0b0',
    price: 0.5,
    battery: 0.8,
    design: 0.7,
    useful: 0.6,
    camera: 0.6,
  },
] as SpiderData[];

// Inject the m function
const SpiderChart = SpiderChartFactory(m);

// Render the chart
m.render(
  document.body,
  m(SpiderChart, {
    id: 'demo-target',
    columns,
    data,
    width: '100%',
    viewBox: '-10 0 120 100',
    options: {
      size: 100,
      scales: 5,
      scaleType: 'spider',
      shapeProps: (data) => ({
        className: 'shape',
        fill: data.color as string,
      }),
    } as Partial<SpiderOptions>,
  }),
);
import m from 'mithril';
import { render } from 'svg-spider-chart';

// Use the render function
const renderer = render(m);
const spiderChart = renderer(columns, data, options);

Default options

The following default options are used: tweak them as you see fit.

const defaults = {
  size: 100, // size of the chart (including captions)
  axes: true, // show axes?
  scales: 3, // show scale circles?
  scaleType: 'spider',
  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',
    'text-anchor': 'middle',
    'font-size': 3,
    'font-family': 'sans-serif',
  }),
} as Partial<SpiderOptions>;