Socket
Socket
Sign inDemoInstall

d3-funnel

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-funnel

A library for rendering SVG funnel charts using D3.js


Version published
Weekly downloads
4.2K
decreased by-1.93%
Maintainers
1
Weekly downloads
 
Created
Source

D3 Funnel

npm Build Status GitHub license

D3Funnel is an extensible, open-source JavaScript library for rendering funnel charts using the D3.js library.

D3Funnel is focused on providing practical and visually appealing funnels through a variety of customization options. Check out the examples page to get a showcasing of the several possible options.

Installation

To install this library, simply include both D3.js and D3Funnel:

<script src="/path/to/d3.min.js"></script>
<script src="/path/to/dist/d3-funnel.js"></script>

Alternatively, if you are using Webpack or Browserify, you can install the npm package and require the module:

npm install d3-funnel --save
var D3Funnel = require('d3-funnel')

Usage

To use this library, you must create a container element and instantiate a new funnel chart:

<div id="funnel"></div>

<script>
    var data = [
        ['Plants',     5000],
        ['Flowers',    2500],
        ['Perennials', 200],
        ['Roses',      50],
    ];
    var options = {};

    var chart = new D3Funnel('#funnel');
    chart.draw(data, options);
</script>

Options

OptionDescriptionTypeDefault
chart.widthThe pixel width of the chart.intContainer's width
chart.heightThe pixel height of the chart.intContainer's height
chart.bottomWidthThe percent of total width the bottom should be.float1 / 3
chart.bottomPinchHow many blocks to pinch on the bottom to create a "neck".int0
chart.invertedWhether the funnel is inverted (like a pyramid).boolfalse
chart.animateThe load animation speed in milliseconds.int/boolfalse
chart.curve.enabledWhether the funnel is curved.boolfalse
chart.curve.heightThe curvature amount.int20
block.dynamicHeightWhether the block heights are proportional to its weight.boolfalse
block.fill.scaleThe block background color scale. Expects an index and returns a color.function/arrayd3.scale.category10()
block.fill.typeEither 'solid' or 'gradient'.string'solid'
block.minHeightThe minimum pixel height of a block.int/boolfalse
block.highlightWhether the blocks are highlighted on hover.boolfalse
label.fontSizeAny valid font size for the labels.string'14px'
label.fillAny valid hex color for the label colorstring'#fff'
label.formatEither function(label, value) or a format string. See below.mixed'{l}: {f}'
events.click.blockCallback for when a block is clicked.functionnull

Label Format

The option label.format can either be a function or a string. The following keys will be substituted by the string formatter:

KeyDescription
'{l}'The block's supplied label.
'{v}'The block's raw value.
'{f}'The block's formatted value.

Overriding Defaults

You may wish to override the default chart options. For example, you may wish for every funnel to have proportional heights. To do this, simplify modify the D3Funnel.defaults property:

D3Funnel.defaults.block.dynamicHeight = true;

Should you wish to override multiple properties at a time, you may consider using lodash's _.merge or jQuery's $.extend:

D3Funnel.defaults = _.merge(D3Funnel.defaults, {
	chart: {
		dynamicHeight: true,
		animate: 200,
	},
	label: {
		format: '{l}: ${f}',
	},
});

API

Additional methods beyond draw() are accessible after instantiating the chart:

MethodDescription
destroy()Removes the funnel and its events from the DOM.

Advanced Data

You can specify colors to override block.fill.scale and label.fill for any data point (hex only):

var data = [
    ['Teal',      12000, '#008080' '#080800'],
    ['Byzantium', 4000,  '#702963'],
    ['Persimmon', 2500,  '#ff634d' '#6f34fd'],
    ['Azure',     1500,  '#007fff' '#07fff0'],
    //         Background ---^         ^--- Label
];

If you want to pass formatted values to be shown in the funnel, pass in an array containing the value and formatted value:

var data = [
    ['Teal',      [12000, 'USD 12,000']],
    ['Byzantium', [4000,  'USD 4,000']],
    ['Persimmon', [2500,  'USD 2,500']],
    ['Azure',     [1500,  'USD 1,500']],
];

License

MIT license.

FAQs

Package last updated on 04 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc