Giter Site home page Giter Site logo

react-bubble-chart-d3's Introduction

react-bubble-chart-d3

ReactJS component to display data as a bubble chart using d3.

Preview

Bubble Chart D3

General Usage

As you will be able to see in test in order to use the component we need to importe it as:

import BubbleChart from '@weknow/react-bubble-chart-d3';

Then, in the render method we can just call it like:

bubbleClick = (label) =>{
  console.log("Custom bubble click func")
}
legendClick = (label) =>{
  console.log("Customer legend click func")
}
<BubbleChart
  graph= {{
    zoom: 1.1,
    offsetX: -0.05,
    offsetY: -0.01,
  }}
  width={1000}
  height={800}
  padding={0} // optional value, number that set the padding between bubbles
  showLegend={true} // optional value, pass false to disable the legend.
  legendPercentage={20} // number that represent the % of with that legend going to use.
  legendFont={{
        family: 'Arial',
        size: 12,
        color: '#000',
        weight: 'bold',
      }}
  valueFont={{
        family: 'Arial',
        size: 12,
        color: '#fff',
        weight: 'bold',
      }}
  labelFont={{
        family: 'Arial',
        size: 16,
        color: '#fff',
        weight: 'bold',
      }}
  //Custom bubble/legend click functions such as searching using the label, redirecting to other page
  bubbleClickFunc={this.bubbleClick}
  legendClickFun={this.legendClick}
  data={[
    { label: 'CRM', value: 1 },
    { label: 'API', value: 1 },
    { label: 'Data', value: 1 },
    { label: 'Commerce', value: 1 },
    { label: 'AI', value: 3 },
    { label: 'Management', value: 5 },
    { label: 'Testing', value: 6 },
    { label: 'Mobile', value: 9 },
    { label: 'Conversion', value: 9 },
    { label: 'Misc', value: 21 },
    { label: 'Databases', value: 22 },
    { label: 'DevOps', value: 22 },
    { label: 'Javascript', value: 23 },
    { label: 'Languages / Frameworks', value: 25 },
    { label: 'Front End', value: 26 },
    { label: 'Content', value: 26 },
  ]}
/>

The data prop receive and array of objects:

{
  label: 'label', // Text to display.
  value: 1, // Numeric Value.
  /**
    Color of the circle this value it's optional,
    accept hex (#ff0000) and string (red) name values.
    If you don't provide a value the default behavior
    is assign a color based on a d3.schemeCategory20c
    color schema.
  */
  color: '#ff00ff',
}

The graph prop receive a configuration object to set the zoom and offset of the bubbles:

graph: {
  zoom: 1.1, // 1.1 means 110% of zoom.
  offsetX: -0.05, // -0.05 means that the offset is -5% of the graph width.
  offsetY: -0.01,
}

The overflow prop receive a boolean value if you want to make bubbles visible beyond its SVG element bounday. The default value is set to 'false':

overflow={true}

The legendFont, valueFont and labelFont prop receive a configuration object to set the font-family, font-size, font-weight and color of the text:

// If you don't set this prop the default configuration will be this object.
{
  family: 'Arial',
  size: 12,
  color: '#000',
  weight: 'bold',
  // lineColor and lineWeight are optionals. use only to add a border line to the text.
  lineColor: "#3f3f3f",
  lineWeight: 2,
}

Installation

Install this component is easy, just use npm as:

npm install @weknow/react-bubble-chart-d3

react-bubble-chart-d3's People

Contributors

enzolutions avatar jevy-wangfei avatar jmsv23 avatar potlid avatar sftmlg 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

Watchers

 avatar  avatar  avatar

react-bubble-chart-d3's Issues

Is it possible to pack my bubbles in groups by type?

Hello! I want to know if it is possible to pack my bubbles by properties:

ex:
const data = [
{type: 'food', name: "banana", value: 10 },
{type: 'food', name: "apple", value: 11 },
{type: 'food', name: "grape", value: 12 },
{type: 'beverage', name: "beer", value: 12 },
{type: 'beverage', name: "wine", value: 12 },
{type: 'beverage', name: "gin", value: 12 },
]

Is it possible to group the foods in a circle and beverage on another and keep them in the same Chart (SVG)?

Experimenting errorr while trying to implement the example code

When I try to implement the basic test scenario, I'm thrown at the following error :

Uncaught Error: Unable to find node on an unmounted component.
    at findHostInstanceWithWarning (react-dom.development.js:24281)
    at Object.findDOMNode (react-dom.development.js:24804)
    at BubbleChart.componentDidMount (react-bubble-chart-d3.js:52)
    at commitLifeCycles (react-dom.development.js:20663)
    at commitLayoutEffects (react-dom.development.js:23426)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994)
    at invokeGuardedCallback (react-dom.development.js:4056)
    at commitRootImpl (react-dom.development.js:23151)
    at unstable_runWithPriority (scheduler.development.js:646)
    at runWithPriority$1 (react-dom.development.js:11276)
    at commitRoot (react-dom.development.js:22990)
    at performSyncWorkOnRoot (react-dom.development.js:22329)
    at react-dom.development.js:11327
    at unstable_runWithPriority (scheduler.development.js:646)
    at runWithPriority$1 (react-dom.development.js:11276)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11322)
    at flushSyncCallbackQueue (react-dom.development.js:11309)
    at discreteUpdates$1 (react-dom.development.js:22420)
    at discreteUpdates (react-dom.development.js:3756)
    at dispatchDiscreteEvent (react-dom.development.js:5889)

React version : 17.0.1
@weknow/react-bubble-chart-d3 version : 1.0.12

bubbleClickFunc function isn't working

There seems to be a click function that always seems to happen which console.log's the label and the custom one doesn't work. It fires on load but not on click

Unable to edit tooltip

I want to display a tooltip on clicking the bubble and edit the tooltip.How to do that?

buttonClickFunc not working

The following is defined inside of a component. Defining a buttonClickFunc does not override the behavior of the default on click behavior which displays "Bubble [name of bubble] is clicked ..."

`createBubbleChart(){

            let graph = {
                zoom: 1.0,
                offsetX: -0.01,
                offsetY: -0.01,
            }

            let width = 1000
            let height = 1000

            let showLegend=false // optional value, pass false to disable the legend.
            let legendPercentage = 20 // number that represent the % of with that legend going to use.
            let legendFont={
                    family: 'Arial',
                    size: 12,
                    color: '#000',
                    weight: 'bold',
                }
            let valueFont={
                    family: 'Arial',
                    size: 12,
                    color: '#fff',
                    weight: 'bold',
                }
           let labelFont={
                    family: 'Arial',
                    size: 16,
                    color: '#fff',
                    weight: 'bold',
                }
            //Custom bubble/legend click functions such as searching using the label, redirecting to other page

            return <BubbleChart graph={graph}
                                width = {width}
                                height = {height}
                                showLegend = {showLegend}
                                legendPercentage = {legendPercentage}
                                legendFont = {legendFont}
                                valueFont = {valueFont}
                                labelFont  = {labelFont}
                                bubbleClickFunc={this.bubbleClick}
                                legendClickFun={this.legendClick}
                                data = {this.createBubbleChartData()}
                                > </BubbleChart>
}`

Having a problem where the text starts at center instead of centered at center.

Here is a picture for reference.

bubble chart problem

As you can see, all the text for the bubble charts starts at the middle. The examples I have seen all have text centered at the middle. The code, besides my own data which I passed my own list object in the data parameter, is literally copy + pasted from the example in the README. Also, I did a little debugging and found out this text starting at the middle apparently happened when I put the BubbleChart inside a ReactJS Carousel.Item, but only if the second item onward. But it is also not consistent either. I have no idea what is causing this. If I put it outside a Carousel and other places, the text is centered and it seems almost arbirtrary tbh.

Update #1: I don't know if the problem is on the bubble chart or other components in ReactJS, but when I do a componentDidMount set to true and do not load the chart dynamically, the chart text is centered correctly. When I remove that, the chart text starts at middle. Not sure why it does that.

Bubbles Cut Off Regardless of Width

Hi, I'm starting off by creating a pretty basic bubble chart with just two bubbles, each of them with some variable value.

However, I'm finding that no matter what values I put in and that no matter how large I make the "width" prop, the bubbles are still getting cut off:

screen shot 2018-12-04 at 7 38 41 am

Do you have any suggestions as to how to resolve this? Am I missing an additional CSS import?

Thanks.

Include HTML in data.label

Cool library! I would love to use this if I can add icons inside the bubbles. Is this possible to do in the data.label prop?

Bubbles cutting off on outside

This is great! Currently, the only issue I have is that it is cutting off bubbles on the outside. Any ideas on how to fix that?

Thanks!
D

In the readme example there is an error

In the example code in the readme there is an error while declaring the graph attribute.
Instead of a dictionary it should be a prop.

Example code in README:

<BubbleChart

**Updated code**
graph = {{
    zoom: 1.1,
    offsetX: -0.05,
    offsetY: -0.01,
  }}
====
  graph: {
    zoom: 1.1,
    offsetX: -0.05,
    offsetY: -0.01,
  },
**Older Code**

  width={1000}
  height={800}
  showLegend={true} // optional value, pass false to disable the legend.
  legendPercentage={20} // number that represent the % of with that legend going to use.
  legendFont={{
        family: 'Arial',
        size: 12,
        color: '#000',
        weight: 'bold',
      }}
  valueFont={{
        family: 'Arial',
        size: 12,
        color: '#fff',
        weight: 'bold',
      }}
  labelFont={{
        family: 'Arial',
        size: 16,
        color: '#fff',
        weight: 'bold',
      }}
  data={[
    { label: 'CRM', value: 1 },
    { label: 'API', value: 1 },
    { label: 'Data', value: 1 },
    { label: 'Commerce', value: 1 },
    { label: 'AI', value: 3 },
    { label: 'Management', value: 5 },
    { label: 'Testing', value: 6 },
    { label: 'Mobile', value: 9 },
    { label: 'Conversion', value: 9 },
    { label: 'Misc', value: 21 },
    { label: 'Databases', value: 22 },
    { label: 'DevOps', value: 22 },
    { label: 'Javascript', value: 23 },
    { label: 'Languages / Frameworks', value: 25 },
    { label: 'Front End', value: 26 },
    { label: 'Content', value: 26 },
  ]}
/>

Error on npm i @weknow/react-bubble-chart-d3

Unexpected end of JSON input while parsing near '...,"d3-chord":"1","d3-c'

Error log:
22 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...,"d3-chord":"1","d3-c'
22 verbose stack at JSON.parse ()
22 verbose stack at parseJson (C:\Program Files\nodejs\node_modules\npm\node_modules\json-parse-better-errors\index.js:7:17)
22 verbose stack at consumeBody.call.then.buffer (C:\Program Files\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\body.js:96:50)
22 verbose stack at
22 verbose stack at process._tickCallback (internal/process/next_tick.js:189:7)
23 verbose cwd C:\MaheshK\puls\web-app
24 verbose Windows_NT 10.0.10240
25 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "i" "@weknow/react-bubble-chart-d3" "--save"
26 verbose node v8.12.0
27 verbose npm v6.4.1
28 error Unexpected end of JSON input while parsing near '...,"d3-chord":"1","d3-c'
29 verbose exit [ 1, true ]

License

Hello,

is this open source? there is no license file that clarifies this (MIT, Apache license, ...)
This component would potentially be used in a production application

best regards

Centered Node

Hello, is it possible to get one root node at center and others around it?

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.