cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmloctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              // dataset 'birthdeathrates' loaded from pen http://codepen.io/jckr/pen/JKXLVe
// form: array of objects with country, birth and death properties

class Chart extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      buttonClicked: false,
    };
    this._message = 'Click the button to pass data to the scatterplot.';
  }
  render() {
    const {
      buttonClicked
    } = this.state;
    const updateMessage = (message) => this._message = message;
    return <div>
      <div>{this._message}</div>
      <Scatterplot 
        updateMessage = {updateMessage}
        data = {buttonClicked ? birthdeathrates : []}
      />
      <div><button
         onClick={() => this.setState({buttonClicked: !buttonClicked})}
      >
        {buttonClicked ? 'hide' : 'show'}
        </button></div>
    </div>
  }
}

class Scatterplot extends React.Component {
  constructor(props) {
    super(props);
  }
  componentDidMount() {
    this.props.updateMessage('Scatterplot component created for the first time.')
  }
  componentDidUpdate(nextProps) {
    this.props.updateMessage(`Scatterplot did update and have ${nextProps.data.length} points.`)
  }
  render() {
    return <svg
  height={300} 
  width={300}
>   
     
        {this.props.data.map((d, i) =>
  <Point birth={d.birth} death={d.death} id={'point' + i}/>
      )}
      
</svg>;
  }
}
class Point extends React.Component {
  componentDidMount() {
    document.getElementById(this.props.id).animate([
      {opacity: 0, fill: 'yellow'},
      {opacity: 0.5},
      {opacity: 0.2, fill: 'black'}
      
    ], {
      duration: 500
    });
  }

  render() {
    const {
      birth,
      death,
      id
    } = this.props;
    return <circle
    cx = {
      birth * 10
    }
    cy = {
      300 - death * 10
    }
    id = {
      id
    }
    r = '5'
    style = {
      {
        fill: '#222',
        opacity: 0.2
      }
    }
    />;
  }
}

const chart = <Chart />
ReactDOM.render(chart, document.querySelector('#root'));
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console