Giter VIP home page Giter VIP logo

react-vis's Introduction

deprecated version build build downloads

react-vis | Demos | Docs

A COMPOSABLE VISUALIZATION SYSTEM

demo

NOTE: This repository is now under new management. Please reach out to the new administrators if you have any questions.

Overview

A collection of react components to render common data visualization charts, such as line/area/bar charts, heat maps, scatterplots, contour plots, hexagon heatmaps, pie and donut charts, sunbursts, radar charts, parallel coordinates, and tree maps.

Some notable features:

  • Simplicity. react-vis doesn't require any deep knowledge of data visualization libraries to start building your first visualizations.
  • Flexibility. react-vis provides a set of basic building blocks for different charts. For instance, separate X and Y axis components. This provides a high level of control of chart layout for applications that need it.
  • Ease of use. The library provides a set of defaults which can be overridden by the custom user's settings.
  • Integration with React. react-vis supports the React's lifecycle and doesn't create unnecessary nodes.

Usage

Install react-vis via npm.

npm install react-vis --save

Include the built main CSS file in your HTML page or via SASS:

@import "~react-vis/dist/style";

You can also select only the styles you want to use. This helps minimize the size of the outputted CSS. Here's an example of importing only the legends styles:

@import "~react-vis/dist/styles/legends";

Import the necessary components from the library...

import {XYPlot, XAxis, YAxis, HorizontalGridLines, LineSeries} from 'react-vis';

… and add the following code to your render function:

<XYPlot
  width={300}
  height={300}>
  <HorizontalGridLines />
  <LineSeries
    data={[
      {x: 1, y: 10},
      {x: 2, y: 5},
      {x: 3, y: 15}
    ]}/>
  <XAxis />
  <YAxis />
</XYPlot>

If you're working in a non-node environment, you can also directly include the bundle and compiled style using basic html tags.

<link rel="stylesheet" href="https://unpkg.com/react-vis/dist/style.css">
<script type="text/javascript" src="https://unpkg.com/react-vis/dist/dist.min.js"></script>

The global reactVis object will now be available for you to play around.

You can checkout these example CodePens: #1, #2, #3 or #4

More information

Take a look at the folder with examples or check out some docs:

Development

Make sure you are using the correct version of node and yarn. To do so, check package.json and find the entry "volta", e.g.

"volta": {
  "node": "14.18.0",
  "yarn": "1.22.4"
}

It's recommanded to install volta to manage node and yarn.

To develop on react-vis, navigate to packages/react-vis, and install the dependencies and then build and watch the static files:

yarn && yarn start

Once complete, you can view the component's example in your browser (will open automatically). Any changes you make to the example code will run the compiler to build the files again.

To run the tests, and create code coverage reports:

yarn cover

Requirements

react-vis makes use of ES6 array methods such as Array.prototype.find. If you make use of react-vis, in an environment without these methods, you'll see errors like TypeError: Server rendering error: Object x,y,radius,angle,color,fill,stroke,opacity,size has no method 'find'. You can use babel-polyfill to polyfill these methods.

react-vis's People

Contributors

akindr avatar amilajack avatar anton-bulyenov avatar balthazar avatar benshope avatar bulyonov avatar charliemartell avatar chrisirhc avatar dmitry-zaets avatar gsas2 avatar ibgreen avatar javidhsueh avatar jckr avatar jonathanbaker7 avatar jonsadka avatar kenns29 avatar lzhuor avatar manassra avatar mcnuttandrew avatar mrawdon avatar noobcit avatar reitlepax avatar samhogg avatar sandiiarov avatar skastel avatar sorenlouv avatar targos avatar wattenberger avatar xiot avatar zachguo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-vis's Issues

Pie chart gives console error when changing number of segments is animated

The pie chart yields a bunch of console errors like this

d3.js:8756 Error: Invalid value for <path> attribute d="M109.35191368826634,412.2430898706445A426.5,426.5 0 0.000006912,1 -225.26700899816143,362.14965805466653L-144.9842766002235,233.08532321974673Z"

when animation is on and the number of segments is increasing or decreasing. This doesn't appear to affect the functionality of the chart, but is a little worrisome.

Assign the series event listeners using react (e.g. not using d3)

Currently the components' event listeners are assigned via d3 either at componentDidMount or at componentDidUpdate. The usage of d3 definitely helps: the event handler automatically gets the values associated with the DOM node, but these event listeners are not testable.

Thus, we should move the components' event listeners to the render function.

XYPlot appears to require a consistant number of children

For both area and line charts it appears that there is a render issue such that react-vis requries a consitant number of elements. For instance, say we were render three line series:

<XYPlot> <series 1> <series 2> <series 3> </XYPlot>
and then add grid lines

<XYPlot> <grid> <grid> <series 1> <series 2> <series 3> </XYPlot>

More likely than not series 3 would not appear

Change the margin property to a set of four properties for each of the sides

Current way to organize margin enforces the user to pass all four margins (left, right, top and bottom) in the single margin property. It's better to have marginLeft, marginRight, marginTop and marginBottom properties instead.

E. g. instead of having

<XYPlot margin={{left: 20, right: 20, top: 10, bottom: 10}} />

we should have this (in case if we want to override just one of them)

<XYPlot marginLeft={20} />

Support dropoffs in sankey diagram

In order to visualize the lost data/money/visitors, we should be able to show "dropoffs" on the sankey diagram (Google Analytics has a great example). Current d3-sankey does not support this behavior. Most likely we'll have to fork/adjust it.

This task should be implemented after #34.

API to use chart components directly?

Hello, great work on this library.

I'm wondering if it is possible, or if you would like to add, some kind of API for using components such as LineSeries etc directly, rather than making them part of some explicit plot wrapper. The use case for this is if a user (such as myself) would like to draw them onto an existing SVG or combine them with custom SVG components that are not part of this library. For example I work on a chart-making tool and we'd like to add custom elements such as labels to the chart, but currently react-vis takes responsibility for the entire SVG.

Perhaps this API is there already, and can e.g. be used by passing all of these props to each series type, only that they are not documented as part of propTypes?

_getClonedChildComponents() {
  const {animation} = this.props;
  const {scaleMixins, data} = this.state;
  const dimensions = getInnerDimensions(this.props);
  const children = React.Children.toArray(this.props.children);
  const seriesProps = getSeriesPropsFromChildren(children);
  return children.map((child, index) => {
    const dataProps = data[index] ? {data: data[index]} : null;
    return React.cloneElement(child, {
      ...dimensions,
      animation,
      ...seriesProps[index],
      ...scaleMixins,
      ...child.props,
      ...dataProps
    });
  });
}

Otherwise, I'd be happy to look at submitting a PR to make this possible

Ability to supply class prefix?

It'd be cool to be able to isolate the CSS classes with a prefix of our choosing.
Is this something you'd be interested in incorporating if we submit a PR?

Add sankey diagrams to the library

Currently we have a big need to show the flow of step by step changes. Sankey Diagram is a good way to visualize it.

I think, we should use d3-sankey for this purpose, but before that we should upgrade to [email protected] (see #29 for detail).

Legends for charts with multiple series

I've been pondering this for the last couple days, working out a means of building a legend with interactivity hooks into the existing XY chart series.

Perhaps something like this could work as a starter - wrapping a higher order component around the series components. This component would essentially be an interface rendering a 'default legend' and include event handlers to do things like filtering on selection of a specific series.

<XYPlot
  width={300}
  height={300}>
  <HorizontalGridLines />
  <Legend onSelection={this.onSelection} style={style}>
    <LineSeries
      color='red'
      data={[
        {x: 1, y: 10},
        {x: 2, y: 5},
        {x: 3, y: 15}
      ]}/>
    <LineSeries
      color='blue'
      data={[
        {x: 1, y: 10},
        {x: 2, y: 5},
        {x: 3, y: 15}
      ]}/>
  </Legend>
  <XAxis />
  <YAxis />
</XYPlot>

An alternative would be just to have a standalone <Legend/> component that is fed information about series the chart from the XYPlot - potentially less complexity there, I guess.

Would appreciate thoughts (or alternative approaches!) on this, and happy to help with PR to get it landed.

Upgrade to d3 4.0

Upgrade to d3 4.0 will help us to make our codebase smaller and more extensible.

pass style objects / class names to series

I'd like to be able to have complete style control on the series. two ways that could be done:
passing a style argument to the series, with an object that d3 could just assign to the style.
also, I'd like to be able to pass specific classes to series. I'm thinking we can just pass a string with a class name to add to begin with, and if needs be be more specific. But being able to have full, css-like access to each individual series would be really nice.

Add better documentation on how to use scales in react-vis

Please provide an example of how to use fill scale and innerRadius scale. Here's how I tried to do it. It didn't work as expected. I couldn't find any examples about the same.

<RadialChart
  radiusDomain={[0,20]}
  innerRadiusDomain={[5,9]}
  data={[
    {angle: 2, fill: '#1a3141', radius: 10, innerRadius: 7},
    {angle: 7, fill: '#ff6f00', radius: 10, innerRadius: 7},
    {angle: 5, fill: '#1a3242', radius: 10, innerRadius: 7}
  ]}
  width={300}
  height={300} />

Add Labels in Scatter/Bubble Plot

Label field on bubble chart - now you can make cool bubble charts, but you are not able to understand what this specific bubble stands for without clicking on it

Add the checks for most frequent user's errors

There are several most frequent errors made by users that should be checked:

  • nulls or undefineds in the data properties;
  • mismatching x properties for stacked charts;
  • negative or zero values for log scales.

Y axis issues when data is constant

The y-axis lacks a tickmark when data is constant. I'd expect the line series to be vertically in the xyplot with 1 tickmark & gridline at the value specified.

<XYPlot
  width={600}
  height={300}>
  <HorizontalGridLines />
  <LineMarkSeries
    color='blue'
    data={[ {x: 1,y:10}, {x: 2, y:10}]}/>
  <XAxis />
  <YAxis />
</XYPlot>

screen shot 2016-03-17 at 3 35 39 pm

Example issues

I'd like to do some exercises of react-vis, but some issues happened.

1.The LineSeries doesn't look like same as 'http://uber.github.io/react-vis/' provided. Just like as the attachment image.
image

2.The VerticalBarSeries doesn't display normally, It only has coordinate like as the attachment image.
image

Other series and radial work fine. All the example codes come from the 'src/example' file directory.

Some suggestions: Could you provide the example codes for each chart in 'http://uber.github.io/react-vis/' or build online editors in jsfiddle?

Charting XY

Quick question I was going through some of the source and examples, when charting line series and the like does you data keys need to be in the format x/y?

data={[
  {x: '..', y: '..'},
   ...
]}

offsetLeft/offsetTop's behavior is unexpected in bottom and right hint alignment

Using offsetLeft actually offsets the hint in the opposite direction (pushing it more towards left as it's increased) when the tip is positioned with topright because it's added to the css right property.

We can either also accept offsetRight or offsetBottom (which would be less ambiguous and offer more control, or subtract instead of add offsetLeft and offsetTop in the case of right and bottom orientations.

/cc @chrisirhc

Bars have 0 height

The bars have the 0 height in following case

<XYPlot, {
      width: 900,
      height: 250,
      yDomain: [0, 9367]
}>
  <VerticalBarSeries, {
    data: [{x: 0, y: 9367}, {x: 1, y: 184}]
  } />
  <XAxis />
  <YAxis />
</XYPlot>

Is there some graph map with edges?

Let's say we start with one node, attach a click listener in which it will fetch some data, then we will expand that "graph map" with more edges connected with these other nodes that we get from our new data.

static displayName getter interferes with livereactreload

livereactreload overwrites displayName while it proxies React components. This fails since react-vis uses a static getter to define the displayName attribute. As alternative to static get displayName() it would be great if we could either rely on auto deduction of displayNames or just assign them after the class declaration:

class Component extends React.Component {
  ...
}
Component.displayName = 'Component';

Greater than five data series wraps data

When trying to plot more than five line series i find that each additional series greater than five doesn't render. This appears to be because react-vis is wrapping the data so that given six line series, what you would expect would be:

<lineseries data=data_1>
<lineseries data=data_2>
<lineseries data=data_3>
<lineseries data=data_4>
<lineseries data=data_5>
<lineseries data=data_6>

But instead i find that last one gets the firsts data, that is:

<lineseries data=data_1>
<lineseries data=data_2>
<lineseries data=data_3>
<lineseries data=data_4>
<lineseries data=data_5>
<lineseries data=data_1>

I think that this is connected to #62.

getStackedData causes an error if XY-Plot maps data into series children

var data = child.props.data; on line 109 of series-utils.js will fail if the XY-Plot maps data into children such as this case:

{dataSets.map((set, index) => {
  return (
    <LineSeries
      key={index}
      data={set.points}
      onNearestX={this.onNearestX.bind(null, set.name)}
      color={colorMap[set.name]} />
  );
})}

which will send an array of children to the getStackedData function, and child.props will be undefined, causing this error: Uncaught TypeError: Cannot read property 'data' of undefined

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.