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

funnel-chart

v1.1.1

Published

Funnel chart visualization using HTML5 canvas

Downloads

44

Readme

Funnel Chart

A funnel chart visualization using HTML5 canvas.

Installation

Via Bower:

$ bower install funnel-chart --save

Via npm:

$ npm install funnel-chart --save

Getting Started

First we need to include the funnel-chart.js library on the page. The library is available in the global variable FunnelChart.

<script src="/path/to/funnel-chart.js"></script>

The funnel-chart library also supports AMD and CommonJS loaders.

Creating a Funnel Chart

The chart requires an HTML <canvas> element to be present on the page with its width and height set via HTML attributes or CSS.

<canvas id="my-funnel" width="500" height="350"></canvas>

The chart must then be instantiated in the following manner:

FunnelChart(canvas, settings);

The canvas argument can be a string representing the element id:

FunnelChart('my-funnel', {
  values: [1012, 891, 96, 18],
  labels: [
    'Impressions',
    'Clicks',
    'Purchases',
    'Repeat Purchases'
  ]
});

or it can be an HTMLElement reference:

FunnelChart(document.getElementById('my-canvas'), {
  ...
});

or a jQuery selector:

FunnelChart($('canvas').get(0), {
  ...
});

The chart will be sized to best fit the dimensions of its <canvas> element.

Settings

The settings argument is an object containing a number of required and optional fields.

{

  /* Required */

  // Array - Numeric values that will be displayed in each funnel section
  // in descending order
  values: [3512, 891, 652, 81],

  /* Optional */

  // Array - These labels should correspond to the array entries in the
  // values setting. Omit the labels setting if you do not wish to display
  // labels.
  labels: [
    'Impressions',
    'Clicks',
    'Purchases',
    'Repeat Purchases'
  ],

  // Array - String values that correspond
  values: [3512, 891, 652, 81],

  // Boolean - Whether to display % change between sections
  displayPercentageChange: true,

  // Number - The number of decimal places that should be displayed for %
  // change values
  pPrecision: 1,

  // String - The color of the horizontal label lines (if labels are shown)
  labelLineColor: '#eee',

  // String or Array - The font color(s) of the labels.
  labelFontColor: '#657274',

  // String or Array - The color(s) of the funnel sections.
  sectionColor: '#0498b3',

  // String or Array - The color(s) of the funnel percentage sections.
  pSectionColor: '#bfd1d4',

  // String - The font for labels and values
  font: 'Helvetica Neue',

  // Number - The maximum font size in pixels (px) for labels and values.
  // This will always be used where possible unless the height of the
  // funnel sections is too small to permit it, in which case the font size
  // will be automatically reduced to fit
  maxFontSize: 13,

  // String - The font weight for labels and values.
  fontWeight: 'bold',

  // String or Array - The font color(s) for funnel sections
  sectionFontColor: '#fff',

  // String or Array - The font color(s) for % change sections
  pSectionFontColor: '#657274',

  // Number - The height of the % change sections compared to the main
  // funnel sections. This is a percent value.
  pSectionHeightPercent: 100,

  // Number - The percentage of the full canvas width that should be
  // reserved for display of labels (if provided). The funnel will expand
  // to fit the remainder.
  labelWidthPercent: 30,

  // Number - The percentage width difference between the top and the
  // bottom of the funnel.
  funnelReductionPercent: 40,

  // Number - The space between the right hand edge of the funnel and the
  // label text in pixels.
  labelOffset: 10

  // Number - The line height between each funnel section
  lineHeight: 1
}