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

react-dc

v1.0.6

Published

React bindings for dc.js charts

Downloads

128

Readme

React-dc

React-dc is a wrapper around dc.js charts for React. Dc.js is an awesome library, but like many charting libraries, its API is imperative, meaning you have to select a DOM element by its id to transform it into a chart. The goal of this library is to make it very easy for you to create and use dc.js charts as React components.

Table of contents

Installation

Using npm (recommended)

npm install --save react-dc

Without npm

An UMD build is available on unpkg:

<script src="https://unpkg.com/react-dc"></script>

Warning: You will also need React, which is a peer dependency of this library. The reasoning behind this is that you are probably already using React in your project, and don't want to end up with two versions of React in your final bundle. If you haven't already installed React, you can install it from npm with npm install --save react, or use a CDN version.

Usage

React-js comes with two versions: an UMD ES5 build, and an ES6 module version to allow for a better integration with your module bundler (like Webpack or Rollup), if you use one. Rollup has a great article on this topic on their wiki.

In an ES6 environment

import {BarChart, PieChart, RowChart} from 'react-dc'

In an ES5 environment

The library is available as a global variable: ReactDc

Charts

BarChart

import React from 'react'
import d3 from 'd3'
import crossfilter from 'crossfilter'
import {BarChart} from 'react-dc'

const records = [{x: 0, y: 1}, {x: 1, y: 3}, {x: 2, y: 5}, {x: 3, y: 1}, {x: 4, y: 2}]
const data = crossfilter(records)
const dimension = data.dimension(record => record.x)
const group = dimenion.group().reduceSum(record => record.y)

export default () => <BarChart dimension={dimension} group={group} x={d3.scale.linear().domain([0, 5])} />

Roadmap

  • [ ] Document all components (charts)
  • [ ] Add a component for every dc chart
    • [x] BarChart
    • [x] BaseChart
    • [ ] BoxPlot
    • [ ] BubbleChart
    • [ ] BubbleOverlay
    • [ ] DataCount
    • [ ] DataGrid
    • [ ] DataTable
    • [x] CompositeChart
    • [ ] GeoChoroplethChart
    • [ ] Heatmap
    • [x] LineChart
    • [ ] NumberDisplay
    • [x] PieChart
    • [x] RowChart
    • [x] ScatterPlot
    • [ ] SelectMenu
    • [x] SeriesChart
  • [ ] Make sure charts are properly re-rendered when props change
  • [ ] Make charts responsive

Common issues

When using Webpack, you might see the following error in your console Module not found: Error: Can't resolve 'crossfilter' or Uncaught Error: Cannot find module "crossfilter". This issue is not a problem with react-dc itself. This is due to dc.js' use of a library called crossfilter2, which is a fork of crossfilter. See this issue for more information. It can be fixed using Webpack's resolve feature:

{
  resolve: {
    alias: {
     'crossfilter': 'crossfilter2'
    }
  }
}

FAQ

Is React-dc production ready ?

Not yet. This library is still being actively developed, and needs to be thoroughly tested before being production-ready. However, you can use it for a personal project. If you encounter any bug, please open an issue.