GithubHelp home page GithubHelp logo

ibhi / d3-funnel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jakezatecky/d3-funnel

0.0 2.0 1.0 614 KB

A JavaScript library for rendering funnel charts using the D3.js framework.

Home Page: http://jakezatecky.github.io/d3-funnel/

License: MIT License

JavaScript 100.00%

d3-funnel's Introduction

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

Option Description Type Default
chart.width The pixel width of the chart. int Container's width
chart.height The pixel height of the chart. int Container's height
chart.bottomWidth The percent of total width the bottom should be. float 1 / 3
chart.bottomPinch How many blocks to pinch on the bottom to create a "neck". int 0
chart.inverted Whether the funnel is inverted (like a pyramid). bool false
chart.animate The load animation speed in milliseconds. int/bool false
chart.curve.enabled Whether the funnel is curved. bool false
chart.curve.height The curvature amount. int 20
block.dynamicHeight Whether the block heights are proportional to its weight. bool false
block.fill.scale The block background color scale. Expects an index and returns a color. function/array d3.scale.category10()
block.fill.type Either 'solid' or 'gradient'. string 'solid'
block.minHeight The minimum pixel height of a block. int/bool false
block.highlight Whether the blocks are highlighted on hover. bool false
label.fontSize Any valid font size for the labels. string '14px'
label.fill Any valid hex color for the label color string '#fff'
label.format Either function(label, value) or a format string. See below. function/array '{l}: {f}'
events.click.block Callback for when a block is clicked. function null

Label Format

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

Key Description
'{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, {
    block: {
        dynamicHeight: true,
        fill: {
            type: 'gradient',
        },
    },
    label: {
        format: '{l}: ${f}',
    },
});

API

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

Method Description
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.

d3-funnel's People

Contributors

jakezatecky avatar arfon avatar jonathanmv avatar

Watchers

James Cloos avatar Mohamed Ibrahim avatar

Forkers

anncycmaria

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.