JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<div id='root' />
.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'));
Also see: Tab Triggers