Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

livereload when chart components are updated #163

Open
mercicle opened this issue May 1, 2018 · 1 comment
Open

livereload when chart components are updated #163

mercicle opened this issue May 1, 2018 · 1 comment

Comments

@mercicle
Copy link

mercicle commented May 1, 2018

HI,

I'm unable to detect a change in a d3 chart component and have the updated chart reload live. For example, if when I change the rect color of the BarChart, I wanted to see the color livereload. If in the build-systems example you were to add a BarChart:

import React from "react"
import BarChart from './BarChart'

const systems = ['Gulp1!','Grunt','Tsers']

export default class App extends React.Component {
  render() {
    return (
      <div>
        <h1>Hello!</h1>
        <ul>{systems.map(s => <li>{s}</li>)}</ul>
        <BarChart data = {[5,10,1,3]} size = {[500,500]} />
      </div>
    )
  }
}

and then add this component:

import React, {Component} from 'react'
import * as d3 from 'd3';

const bar_color ="red"; //"#fe9922"
class BarChart extends React.Component{

	constructor(props){
		super(props)
		this.createBarChart = this.createBarChart.bind(this)
	}

	componentDidMount(){
		this.createBarChart()
	}

	createBarChart(){
		const node = this.node
		const dataMax = d3.max(this.props.data)
		const yScale = d3.scaleLinear()
						.domain([0,dataMax])
						.range([0, this.props.size[1]])
 
	   d3.select(node)
			.selectAll('rect')
			.data(this.props.data)
			.enter()
			.append('rect')
			.style('fill', bar_color)
			.attr('x', (d,i) => i*25)
			.attr('y', d => this.props.size[1] - yScale(d))
			.attr('height', d => yScale(d))
			.attr('width', 25)
			.attr("opacity",0)
			.transition().duration(1000).attr("opacity",1)

	}

	render(){
		return <svg ref = {node => this.node = node } width = {500} height = {500}></svg>
	}

}

export default BarChart
@milankinen
Copy link
Owner

Hi! Side effects made during the mounting do not get reloaded because react-proxy preserves class identity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants