Coder Social home page Coder Social logo

react-d3-tooltip's Introduction

react-d3-tooltip

Dependency Status

react-d3 tooltip implementation.

Quick example

With webpack build tool

  • line chart
"use strict";

var React = require('react');
var ReactDOM = require('react-dom');
var LineTooltip = require('react-d3-tooltip').LineTooltip;

(function() {

  var generalChartData = require('json!./data/user.json');

  var chartSeries = [
      {
        field: 'age',
        name: 'Age',
        color: '#ff7f0e'
      }
    ],
    x = function(d) {
      return d.index;
    }

  ReactDOM.render(
      <LineTooltip
        width= {600}
        height= {300}
        data= {generalChartData}
        chartSeries= {chartSeries}
        x= {x}
      />
    , document.getElementById('data_tooltip_line')
  )
})()

In html (without build tools)

Clone code react-d3-tooltip.js or minify js react-d3-tooltip.min.js and include the script in your HTML.

You'll also need react, react-dom, d3

<!DOCTYPE html>
<html>
  <head>
    <title>
      Line Chart example
    </title>
  </head>
  <body>
    <div id="data_tooltip_line"></div>
    <script src="https://fb.me/react-0.14.2.js"></script>
    <script src="https://fb.me/react-dom-0.14.2.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
    <script src="../react-d3-tooltip.min.js"></script>
    <script type="text/babel">
      var LineTooltip = ReactD3Tooltip.LineTooltip;

      var data = [
          {
              "age": 39,
              "index": 0
          },
          {
              "age": 38,
              "index": 1
          },
          {
              "age": 34,
              "index": 2
          },
          {
              "age": 12,
              "index": 3
          }
      ];

      var chartSeries = [
          {
            field: 'age',
            name: 'Age',
            color: '#ff7f0e',
            style: {
              "stroke-width": 2,
              "stroke-opacity": .2,
              "fill-opacity": .2
            }
          }
        ],
        x = function(d) {
          return d.index;
        }

      ReactDOM.render(
        <LineTooltip width= {600} height= {500} data= {data} chartSeries= {chartSeries} x= {x} />
      , document.getElementById('data_tooltip_line')
      )
    </script>
  </body>
</html>

Customization

Choose one of the components in tooltip folder.

Then require it in your project, take simple as example.

After you require it, render the tooltip as children. Like below example.

var SimpleTooltipStyle = require('react-d3-tooltip').SimpleTooltip;


ReactDOM.render(
    <LineTooltip
      data= {generalChartData}
      chartSeries = {chartSeries}
      interpolate = {interpolate}
      x= {x}
      xScale= {xScale}
    >
      <Simple/>  //<---------
    </LineTooltip>

, document.getElementById('data_tooltip_line_multi')
)

Then you can change tooltip style!

Install

npm install --save react-d3-tooltip

Support Tooltip Component

  • Line Chart: export as LineTooltip
  • Area Stack Chart: export as AreaStackTooltip
  • Scatter Plot: export as ScatterTooltip
  • Bar Chart: export as BarTooltip
  • Bar Stack: export as BarStackTooltip (you can now pass in onClick handler via props)
  • Bar Group: export as BarGroupTooltip
  • Pie Chart: export as PieTooltip

Gallery

img

License

Apache 2.0

react-d3-tooltip's People

Contributors

awesomejerry avatar chihsuan avatar chilijung avatar ctxhou avatar dokasto avatar gamebak avatar nkudo 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-d3-tooltip's Issues

Color field is empty

I am using PieToolTip and the Color field is empty no matter which color I write in the data.
What should I do?

Can anyone help me how to customize tooltip using BarStackedTooltip

I am using BarStackedTooltip and I am not able to customize tooltip. It always show me 4 parameters(Value, Field,FieldTitle, Color) in the tooltip. But I want follwing customizations: -

FieldTitle should be replaced by Name
Remove Color attribute from tooltip
Display Name in tooltip as a attribute

All Tags below 1.1.0 have a dependency on react 0.14. Why?

All Tags below 1.1.0 have a dependency on react 0.14. Why?
When I try to install a version prior to 1.1.0 (0.7.0 OR 0.5.0) I get a dependency error for react 0.14.

react-d3-core 0.4.2 does not have this issue. When can this be fixed. I cannot move to React 0.14 until Jan-Feb 2016.

Also, is there a tag for 1.0.0? The next largest tag below 1.1.0 (identified as the move to React 0.14) is 0.7.0?

showLegend = {false} does not hide legend

I am trying to hide the legend as my data is pretty huge and it occupies half of the container. Are there any other ways to disable it?

  <PieTooltip
    data= {this.state.data}
    width= {width}
    height= {height}
    chartSeries= {chartSeries}
    showLegend = {false}
    margins= {margins}
    value = {value}
    name = {name}
  />

LineTooltip

我將LineTooltip的範例套上不同的資料後,圖有正確的畫出來,但是hover時tooltip並沒有出現,另外console log也沒也任何的錯誤,sample code如下

'use strict';
/**
 * Created by Ben Hu on 2015/11/24.
 */
import React from 'react';
import d3 from 'd3';
import {LineTooltip} from 'react-d3-tooltip';

const MyLineChart = React.createClass({
    render(){
        var chartData = this.props.allBalance;
        var parseDate = d3.time.format("%Y").parse;
        var width = 1000,
            height = 350,
            margins = {left: 100, right: 100, top: 50, bottom: 50},
            chartSeries = [
                {
                    field: 'balance',
                    name: 'Balance',
                    color: '#3498db',
                    style: {
                        "stroke-width": 3,
                        "stroke-opacity": .7,
                        "fill-opacity": .0
                    }
                },
                {
                    field: 'yearExportValue',
                    name: 'Export',
                    color: '#8e44ad',
                    style: {
                        "stroke-width": 3,
                        "stroke-opacity": .7,
                        "fill-opacity": .0
                    }
                },
                {
                    field: 'yearImportValue',
                    name: 'Import',
                    color: '#ff7f0e',
                    style: {
                        "stroke-width": 3,
                        "stroke-opacity": .7,
                        "fill-opacity": .0
                    }
                }
            ],
            title = this.props.country.toUpperCase() + " Trade Balance",

            x = function (d) {
                return parseDate(d.year);
            },

            xRange = [0, width - margins.left - margins.right],

            yRange = [height - margins.top - margins.bottom, 0],

            yDomain = [
                d3.min(chartData, function (d) {
                    return d.balance;
                }),
                d3.max(chartData, function (d) {
                    return d.yearExportValue;
                })
            ],

            xScale = 'time';
        return (

            <LineTooltip
                margins={margins}
                title={title}
                data={chartData}
                width={width}
                height={height}
                chartSeries={chartSeries}
                x={x}
                xRange={xRange}
                xScale={xScale}
                yRange={yRange}
                yDomain={yDomain}
                />

        )
    }
});

export default MyLineChart;

資料格式如下

[
{
year: "1996",
yearExportValue: 115939232,
yearImportValue: 102367832,
balance: 13571400,
status: "trade surplus"
},
{
year: "1997",
yearExportValue: 122077877,
yearImportValue: 114421916,
balance: 7655961,
status: "trade surplus"
},
{
year: "1998",
yearExportValue: 110579613,
yearImportValue: 104661545,
balance: 5918068,
status: "trade surplus"
},
{
year: "1999",
yearExportValue: 121587866,
yearImportValue: 110684868,
balance: 10902998,
status: "trade surplus"
},
{
year: "2000",
yearExportValue: 148316282,
yearImportValue: 140004900,
balance: 8311382,
status: "trade surplus"
},
{
year: "2001",
yearExportValue: 126313837,
yearImportValue: 107965539,
balance: 18348298,
status: "trade surplus"
},
{
year: "2002",
yearExportValue: 135312632,
yearImportValue: 113237862,
balance: 22074770,
status: "trade surplus"
},
{
year: "2003",
yearExportValue: 150594744,
yearImportValue: 128007459,
balance: 22587285,
status: "trade surplus"
},
{
year: "2004",
yearExportValue: 182363733,
yearImportValue: 168750606,
balance: 13613127,
status: "trade surplus"
},
{
year: "2005",
yearExportValue: 198424333,
yearImportValue: 182610211,
balance: 15814122,
status: "trade surplus"
},
{
year: "2006",
yearExportValue: 224012938,
yearImportValue: 202694857,
balance: 21318081,
status: "trade surplus"
},
{
year: "2007",
yearExportValue: 246738914,
yearImportValue: 219320362,
balance: 27418552,
status: "trade surplus"
},
{
year: "2008",
yearExportValue: 255624848,
yearImportValue: 240444373,
balance: 15180475,
status: "trade surplus"
},
{
year: "2009",
yearExportValue: 203677115,
yearImportValue: 174413522,
balance: 29263593,
status: "trade surplus"
},
{
year: "2010",
yearExportValue: 274613069,
yearImportValue: 251367487,
balance: 23245582,
status: "trade surplus"
},
{
year: "2011",
yearExportValue: 308286826,
yearImportValue: 281586165,
balance: 26700661,
status: "trade surplus"
},
{
year: "2012",
yearExportValue: 301076384,
yearImportValue: 270706758,
balance: 30369626,
status: "trade surplus"
},
{
year: "2013",
yearExportValue: 305437260,
yearImportValue: 269893213,
balance: 35544047,
status: "trade surplus"
},
{
year: "2014",
yearExportValue: 313691879,
yearImportValue: 274021984,
balance: 39669895,
status: "trade surplus"
},
{
year: "2015",
yearExportValue: 142413431,
yearImportValue: 116658484,
balance: 25754947,
status: "trade surplus"
}
]

感謝!

Invalid prop `xScale` of value `band`

Using the latest version from NPM and seeing this error:

warning.js?8a56:45 Warning: Failed propType: Invalid prop `xScale` of value `band`
supplied to `Grid`, expected one of
["linear","identity","sqrt","pow","log","quantize","quantile","ordinal","time"].
Check the render method of `XGrid`.

This is clearly a bug since I did pass xScale: 'ordinal' to props.

Additionally the resulting chart seems to get drawn on the wrong scale. For example a series [1..5] actually comes out to start at 0.5 and ends at 4.5 ...

Issue running npm install --save react-d3-tooltip

Hi,

I'm unable to install react d3 tooltip. On running this command: npm install --save react-d3-tooltip, I get The package react does not satisfy its siblings' peerDependencies requirements!

`npm ERR! peerinvalid The package react does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants react@^15.0.0
npm ERR! peerinvalid Peer [email protected] wants react@>=0.14.0
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.3 || ^15.0.0
npm ERR! peerinvalid Peer [email protected] wants react@^15.1.0
npm ERR! peerinvalid Peer [email protected] wants [email protected] || ^15.0.0-rc
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.0 || ^15.0.0
npm ERR! peerinvalid Peer [email protected] wants react@^0.14 || ^15.0.0-rc || ^15.0
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.7 || ^15.0.0
npm ERR! peerinvalid Peer [email protected] wants react@^15.0.0-0
npm ERR! peerinvalid Peer [email protected] wants react@>=0.14.0
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.7

npm ERR! System Linux 4.2.0-27-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "--save" "react-d3-tooltip"
npm ERR! cwd /var/www/project
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR! code EPEERINVALID
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /var/www/project/npm-debug.log
npm ERR! not ok code 0
`

Compatibility

Hi!

Is there any way you guys can support React ^15.0.0?

import case sensitivity.

in utils\tooltip.jsx you seem to be importing from '../tooltip/table';

However the folder name is tooltip/Table, this is causing issues on case sensitive file systems such as linux.

Custom tooltip templates

Hi. I try to add custom template and have fail. When i try to apply standard simple or simple static template all fine. But if I need template like this: 'The customer with ID: '+x+' has '+y+' % stocks'.
I can't do it because function which return template have no one arguments...
Maybe does it have some way to give point from "data: statsChartData" to "setTooltipsTemplate" functions? It very important to use this components.
Thanks.

support negative

like below example

tooltip position doesn't locate at correct area.

2015-12-03 11 35 29

Console error while configuring margins

Throwing console error when configuring PieTooltip component with margins={{left: 100, top:100}} property.

<PieTooltip
  {...this.props}
  swatchShape = "circle"
  margins={{left: 100, top:100}}
>
	<SimpleTooltip />
</PieTooltip>

123

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.