Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


  <button id="sort1">Sort by Country</button>
  <button id="sort2">Sort by Median income (US$, PPP)[3]</button>
  <button id="sort3">Sort by mean PPP USD 2013</button>
  <button id="sort4">Sort both independently</button>
<svg id="one" width="400" height="600"></svg>
<svg id="two" width="400" height="600"></svg>


                .rivela .background{
.rivela .item.selected rect{


                var chartGen = rivela.barchart()
    .key(d => d.Country)
    .margin({left: 100})

var originalDataset

d3.csv('', data => {
  originalDataset = data
  update(data, data)

function update (data1, data2) {
  chartGen.value(d => d['Median income (US$, PPP)[3]'])
    .title('Median income (US$, PPP)[3]')'#one')
        .on('over', function () {
          var e = d3.event.detail

    .value(d => d['mean PPP USD 2013'])
    .title('mean PPP USD 2013')'#two')
        .on('over', function () {
          var e = d3.event.detail

function selectSameFromOne (dat) {
  var index1 = dat.index
  var index2
  var data2 ='#two').datum()
  data2.forEach((d, i) => {
    if (d.Country === dat.datum.Country) index2 = i
  selectSame(index1, index2)

function selectSameFromTwo (dat) {
  var index2 = dat.index
  var index1
  var data1 ='#one').datum()
  data1.forEach((d, i) => {
    if (d.Country === dat.datum.Country) index1 = i
  selectSame(index1, index2)

function selectSame (id1, id2) {
  console.log(id1, id2)'#one').selectAll('.item')
    .classed('selected', (d, i) => i === id1)'#two').selectAll('.item')
    .classed('selected', (d, i) => i === id2)

    .on('click', function () {
      var id ='id')

      var k = ''

      if (id === 'sort1') k = 'Country'
      if (id === 'sort2') k = 'Median income (US$, PPP)[3]'
      if (id === 'sort3') k = 'mean PPP USD 2013'

      var ndata1 = originalDataset.sort((a, b) => d3.descending(a[k], b[k]))
      var ndata2 = ndata1

      if (id === 'sort4') {
        var copy = => d)
        ndata1 = copy.sort((a, b) => d3.descending(a['Median income (US$, PPP)[3]'], b['Median income (US$, PPP)[3]']))
        ndata2 = originalDataset.sort((a, b) => d3.descending(a['mean PPP USD 2013'], b['mean PPP USD 2013']))

      update(ndata1, ndata2)