Ensure at least one Legend Item is ON (old way)

This solution is not perfect. The last ON legend item should not display a "hand" cursor, like if it were enabled. Clicking it will do nothing.

by duarteleao

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.19/require.min.js"></script>
<script src="//webdetails.github.io/ccc/charts/lib/amd/require.config.js"></script>
<script src="//webdetails.github.io/ccc/charts/lib/q01-01.js"></script>
<div id="cccExample" />

JavaScript

// NOTE: this is now standard behaviour.
// and can be done this way: https://jsfiddle.net/duarteleao/7tp2P/

require([
  "ccc/pvc", 
  "ccc/def", 
  "ccc/protovis"
], function(pvc, def, pv) {

    new pvc.BarChart({
      canvas: "cccExample",
      width:  600,
      height: 400,
      title:     "Ensure at least one Legend Item is ON (old way)",
      animate:    false,
      selectable: true,
      hoverable:  true,
      legend: {
          scenes: {
              item: {
                  execute: function() {
                      var siblings = this.parentNode.childNodes;
                      var L = siblings.length;
                      if(L > 1) {
                          var otherOn = false;
                          for(var i = 0 ; i < L ; i++) {
                              var sibling = siblings[i];
                              if(sibling !== this && 
                                 sibling.isOn()) {
                                  otherOn = true;
                                  break;
                              }
                          }

                          if(otherOn) return this.base();
                      }
                  }
              }
          }
      }
  })
  .setData(relational_04, {crosstabMode: false })
  .render();
});