Giter VIP home page Giter VIP logo

react-d3-wrap's Introduction

Install

npm install react-d3-wrap

Define a D3 component

Extend the wrapper then override update to implement your D3 graphics. Optionally, if you have setup or cleanup to do, override initialize or destroy.

import D3Wrap from 'react-d3-wrap'

export default class MyChart extends D3Wrap {
  initialize (svg, data, options) {
    // Optional initialize method called once when component mounts
  }

  update (svg, data, options) {
    // setup container, root svg element passed in along with data and options
    const chart = d3.select(svg)
      .append('g')
      .attr('transform', `translate(${options.margin.left}, ${options.margin.top})`)

    // continue you d3 implementation as usual...
  }

  destroy {
    // clean up...
  }
}

Usage

import MyChart from './MyChart'

// Use options to pass in configuration and callbacks
React.render(<MyChart 
  data={ [0, 1, 2] }
  width='400'
  height='300'
  options={{ onClick: this.handleClick }} />, document.getElementById('chart'))

Default options

{
  margin: {
    top: 0,
    bottom: 0,
    left: 0,
    right: 0
  },
  xaxis: { orientation: 'bottom' },
  yaxis: { orientation: 'left' }
}

react-d3-wrap's People

Contributors

skellyb avatar

Watchers

 avatar  avatar

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.