Giter Site home page Giter Site logo

Comments (6)

susielu avatar susielu commented on June 13, 2024

Can you post the code you're using with the legend?

from d3-legend.

susielu avatar susielu commented on June 13, 2024

I am going to close this issue please respond if you want it re-opened.

from d3-legend.

raubreywhite avatar raubreywhite commented on June 13, 2024

Hi,

I have the same problem

I'm using it within a react app, so the top part of the code is:

var d3=require('d3')
import legend from 'd3-svg-legend'

and the legend:

mainGraph.append('g')
.attr('transform', 'translate(20,20)')
.call(
legend.legendColor()
.shape('path', d3.symbol().type(d3.symbolTriangle).size(150)())
.shapePadding(10)
.scale(colour)
)

from d3-legend.

raubreywhite avatar raubreywhite commented on June 13, 2024

The exact file that I am trying this in is:

https://github.com/raubreywhite/sykdomspuls_reactjs/blob/60bbfa8766a1fcdd7c88a1cfd5307e9418b59ca5/src/Barometer.js

(the entire repository is my react app in total)

Thanks in advance!

from d3-legend.

susielu avatar susielu commented on June 13, 2024

@raubreywhite
I looked into your project to figure out why this is happening. It's because you're using the ReactFauxDOM element. At the time the legend code is called there are no elements in the DOM yet so when it's looking for the elements bounding box it can't find the element.

I put the following code in your App.js file's componentDidMount and it did display the legend correctly.

d3.selectAll('#root')
    .append('svg')

    d3.selectAll('svg')
      .append('g')
      .attr('transform', 'translate(10,10)')
      .call(
        legendColor()
        .shape("path", d3.symbol().type(d3.symbolTriangle).size(150)())
        .shapePadding(10)
        .scale(d3.scaleOrdinal()
        .range([ '#91cf60', '#ffffbf', '#fc8d59' ])
        .domain([0, 1, 2]))
    )

One option you could use is the components that are using Barometer, wrap that in an SVG with a Barometer class or id:
<svg className="barometer"><Barometer data={this.state.data} brushValues={this.state.brushValues} width={this.state.dimensions.width}/></svg>

Then within your Barometer component you should be able to select that SVG directly since it will be rendered by the parent already.

from d3-legend.

raubreywhite avatar raubreywhite commented on June 13, 2024

Thank you!

from d3-legend.

Related Issues (20)

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.