cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              .chart {
  display: inline-block;
  width: 300px;
}
.bar {
  transition: top .5s, background .5s;
}
.bar__label, .label {
  display: inline-block;
  font-family: sans-serif;
  font-size: 10px;
  line-height: 20px;
  text-transform: uppercase;
  vertical-align: top;
}
.bar__label {
  text-align: right;
  width: 50px;
}
.highlighted .bar__label {
  font-weight: bold;
}
.bar__mark {
  background: orange;
  display: inline-block;
  height: 16px;
  margin-left: 10px;
  margin-top: 2px;
  transition: width 1s, background 1s;
}

.highlighted .bar__mark {
  background: red;
}

.switch__track {
  border-radius: 10px;
  box-shadow: inset 0px 1px 3px 0px rgba(0,0,0,0.50);
  display: inline-block;
  margin: 0 20px;
  position: relative;
  width: 60px;
  height: 20px;
  background: #c0c0c0;
}

.switch__thumb {
  background: #d6d6d5;
  border-radius: 10px;
  position: relative;
  left: 1px;
  top: 1px;
  width: 18px;
  height: 18px;
  transition: left .5s;
}

.switch__thumb.death {
  left: 41px;
}

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

class Dashboard extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      highlighted: null
    }
    this.highlight = this.highlight.bind(this);
  }
  highlight(country) {
    this.setState({highlighted: country});
  }
  render() {
    const {
      data
    } = this.props;
    const {
      highlighted
    } = this.state;
 
    return <div className='dashboard'>
      <Chart 
        data = {data}
        highlight = {this.highlight}
        highlighted = {highlighted}
        label = 'Birth Rate'
        metric = 'birth'
      />
      <Chart 
        data = {data}
        highlight = {this.highlight}
        highlighted = {highlighted}
        label = 'Death Rate'
        metric = 'death'
      />
     </div>;
  }
}

function Chart({
  data,
  highlight,
  highlighted,
  label,
  metric
}) {
  const barData = data.sort((a, b) => b[metric] - a[metric])
    .map((d, i) => ({...d,
      rank: i
    }))
  return <div className='chart'>
      {[
       <div className='label'>{label}</div>,
       <div>
         {barData.map(d => 
          <Bar
            country={d.country}
            value={d[metric]}
            rank={d.rank}
            highlight={highlight}
            highlighted={d.country === highlighted}
          />
         )}
      </div>
      ]}
    </div>;
}

function Bar({
  country,
  highlight,
  highlighted,
  value,
  rank
}) {
  return <div
  className = {'bar' + (highlighted ? ' highlighted' : '')}
  onMouseOver = {
    () => highlight(country)
  }
  style = {
      {
        position: 'absolute',
        top: 30 + 20 * rank,
        transition: 'top .5s'
      }
    } >
    <div className='bar__label'>{country}</div> <
    div className = 'bar__mark'
  style = {
    {
      width: 4 * value,
    }
  }
  /> <
  /div>;    
}

const dash = <Dashboard data={birthdeathrates.slice(0,10)} />

ReactDOM.render(dash, document.querySelector('#root'));
            
          
!
999px
Loading ..................

Console