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

@nebula.js/sn-pie-chart

v1.27.10

Published

Pie chart supernova

Downloads

10,026

Readme

@nebula.js/sn-pie-chart

A pie chart is a circular chart divided into more slices that each represent a proportion of the whole. Pie charts are most visually efficient when a small number (10 or fewer) of slices are displayed.

Requirements

Requires @nebula.js/stardust version 1.7.0 or later.

Installing

If you use npm: npm install @nebula.js/sn-pie-chart. You can also load through the script tag directly from https://unpkg.com.

Usage

import { embed } from '@nebula.js/stardust';
import pie from '@nebula.js/sn-pie-chart';

// 'app' is an enigma app model
const nuked = embed(app, {
  types: [{ // register pie chart
    name: 'piechart',
    load: () => Promise.resolve(pie);
  }]
});

nuked.render({
  element: document.querySelector('.pie'),
  type: 'piechart',
  fields: ['Year', '=Avg(Price)'],

  // Overrides default properties
  properties: {
    title: 'Price of Cars by Year',
    dataPoint: {
        labelMode: 'none'
    },
  },
});

More examples

One dimension, one measure, value labels

nuked.render({
  element: document.querySelector('.pie'),
  type: 'piechart',
  fields: ['Country', '=Avg(Price)'],

  // Overrides default properties
  properties: {
    title: 'Price of Cars by Country',
    dataPoint: {
      labelMode: 'value',
    },
  },
});

One dimension, two measures, percentage labels

nuked.render({
  element: document.querySelector('.pie'),
  type: 'piechart',
  fields: ['Country', '=Avg(Price)', '=Avg(Horsepower)'],

  // Overrides default properties
  properties: {
    title: 'Price and horsepower by country',
    dataPoint: {
      labelMode: 'share',
    },
  },
});

One dimension, one measure, donut chart view

nuked.render({
  element: document.querySelector('.pie'),
  type: 'piechart',
  fields: ['Country', '=Avg(Price)'],

  // Overrides default properties
  properties: {
    title: 'Price by country',
    dataPoint: {
      labelMode: 'share',
    },
    donut: {
      showAsDonut: true,
    },
  },
});

One dimension, two measures, donut chart view

nuked.render({
  element: document.querySelector('.pie'),
  type: 'piechart',
  fields: ['Country', '=Avg(Price)', '=Avg(Horsepower)'],

  // Overrides default properties
  properties: {
    title: 'Price and horsepower by country',
    dataPoint: {
      labelMode: 'share',
    },
    donut: {
      showAsDonut: true,
    },
  },
});

Pie chart plugins

A plugin can be passed into a pie chart to add or modify its capability or visual appearance. A plugin needs to be defined before it can be rendered together with the chart.

// Step 1: define the plugin

// Modifying the look of the dimension title component
const totalPopulationLabelPlugin = {
  info: {
    name: 'total-title-plugin',
    type: 'component-definition',
  },
  fn: ({ keys, layout }) => {
    const componentDefinition = {
      type: 'text',
      text: 'World Total: 7.9 Billions',
      layout: { dock: 'bottom' },
    };
    return componentDefinition;
  },
};

// Step 2: passing the plugin definition into the render function

// Render a pie chart with plugins
nuked.render({
  element: document.querySelector('#object'),
  type: 'sn-pie-chart',
  plugins: [totalPopulationLabelPlugin],
  fields: ['Country', '=Sum(Population)'],
  properties: {
    dataPoint: { labelMode: 'value' },
  },
});

The plugin definition is an object, with two properties info and fn. The fn returns a picasso.js component. To build this component, some important chart internals are passed into the argument object of fn.

// Structure of the argument object of fn
const pluginArgs = {
  layout,
  keys: {
    SCALE: { FILL },
    COMPONENT: { DIMENSION_TITLE, SLICES, PIE_LABELS },
  },
};

With plugins, you can either add new components or modify existing components of the pie chart.

Modify existing components

As an example, the appearance of the slices can be modified by plugins.

To overide an existing component, fn should returns a picasso.js component that has the same key as the existing component (keys.COMPONENT.SLICES in this example)

// Modifying the look of the slices component
const slicesPlugin = {
  info: {
    name: 'pie-plugin',
    type: 'component-definition',
  },
  fn: ({ keys, layout }) => {
    const componentDefinition = {
      type: 'pie',

      // Provide the same name as the exisiting component to override it
      key: keys.COMPONENT.SLICES,
      settings: {
        slice: {
          innerRadius: 0.6,
          strokeWidth: 0,
          stroke: 'red',
          outerRadius: 0.8,
          cornerRadius: 2,
        },
      },
    };
    return componentDefinition;
  },
};

Add new components

The new component can be a standard Picasso component or a custom Picasso component. The code for adding a new component is similar to that for modifying an existing component, the only difference is that the key should be different from that of any of the existing components.

Plugins disclaimer

  • The plugins API is still experimental.
  • We can not guarantee our charts to be compatible with all different settings, especially when modifying existing components.