Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

HTML

              
                <html>
	<head>
		<script src="https://cdn.zingchart.com/zingchart.min.js"></script>
		<script>
      zingchart.MODULESDIR = "https://cdn.zingchart.com/modules/";
      ZC.LICENSE = ["bab21d016b2dadc18447d2a055f061e3"];
    </script>
        
    <script
      src="https://code.jquery.com/jquery-2.2.4.min.js"
      integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
      crossorigin="anonymous">
    </script>
    
  </head>
	<body>
    
    <script>
      window.setTimeout(function() {
        $(document.body).append('<iframe style="border:0px;position:absolute;top:0px;right:0px;width:270px;height:480px;" src="https://codepen.io/zingchart/full/ef639d5ca7dd69ae067720228a01d542"></iframe>');
      }, 2500);
    </script>
    
		<div>
      <div id="zch"></div>
      <div id="zcg" style="float:left"></div>
      <div id="zcv" style="float:left"></div>
  </div>
	
  </body>
</html>


              
            
!

CSS

              
                body { 
  margin:10px;
  padding:10px; 
}

*, input, button, select, textarea, label {
  font-family: 'Lucida Sans Unicode',Monaco,Tahoma,Verdana,Arial;
}
              
            
!

JS

              
                var iCols = 100;
var iRows = 50;
var iSize = 5;

var cdata = {
    type : "null",
    backgroundColor : "#fff",
    flat : true,
    heatmap : {
        alpha : 1,
        minValue : 0,
        maxValue : 1,
        brushType : 'square',
        size : iSize,
        blur : iSize
    }
};

function createArr(iCols, iRows) {
  var aData = new Array(iCols);
  for (var i=0;i<aData.length;i++) {
    aData[i] = new Array(iRows);
  }
  return aData;
};

var aGrid = createArr(iCols, iRows);
var aHValues = [], aVValues = [];
for (var i=0;i<iCols;i++) {    
    aHValues[i] = 0;
    for (var j=0;j<iRows;j++) {
      aGrid[i][j] = Math.floor(2*Math.random());
      if (aVValues[j] === null || typeof(aVValues[j]) === 'undefined') {
        aVValues[j] = 0;
      }
      aHValues[i] += aGrid[i][j];
      aVValues[j] += aGrid[i][j];
    }
}

zingchart.bind('zcg', 'load', function() {
    step();
});

function step() {
  var i, j;
  var aNextGrid = createArr(iCols, iRows);
  aHValues = [];
  aVValues = [];

  for (i=0;i<iCols;i++) {
      aHValues[i] = 0;
      for (j=0;j<iRows;j++) {
          var iState = aGrid[i][j];
          var iSum = 0;
          var iNeighbors = countNeighbors(aGrid, i, j);
    
          if (iState === 0 && iNeighbors === 3) {
            aNextGrid[i][j] = 1;
          } else if (iState === 1 && (iNeighbors < 2 || iNeighbors > 3)) {
            aNextGrid[i][j] = 0;
          } else {
            aNextGrid[i][j] = iState;
          }
          
          aHValues[i] += aNextGrid[i][j];
          if (aVValues[j] === null || typeof(aVValues[j]) === 'undefined') {
            aVValues[j] = 0;
          }
          aVValues[j] += aNextGrid[i][j];
      }
  }
  
  aGrid = aNextGrid;

  var aData = [];
  for (i=0;i<iCols;i++) {
    for (j=0;j<iRows;j++) {
      aData.push([i*iSize, j*iSize, aGrid[i][j]])
    }
  }
  zingchart.exec('zcg', 'heatmap.setdata', {
    data : aData
  });

  zingchart.exec('zch', 'setseriesvalues', {
    plotindex : 0,
    values : aHValues
  });
  zingchart.exec('zcv', 'setseriesvalues', {
    plotindex : 0,
    values : aVValues
  });
  
  window.setTimeout(step, 15);
}

function countNeighbors(aGrid, iX, iY) {
  var iSum = 0;
  for (var i=-1;i<2;i++) {
    for (var j=-1;j<2;j++) {
      var iCol = (iX + i + iCols) % iCols;
      var iRow = (iY + j + iRows) % iRows;
      iSum += aGrid[iCol][iRow];
    }
  }
  iSum -= aGrid[iX][iY];
  return iSum;
};

zingchart.loadModules('heatmap', function() {
  zingchart.render({
      id : 'zcg',
      width : iCols * iSize,
      height : iRows * iSize,
      output : 'canvas',
      data : cdata,
      modules : 'heatmap'
  });

  zingchart.render({
      id : 'zch',
      width : iCols * iSize,
      height : 80,
      output : 'canvas',
      data : {
          flat : true,
          type : 'area',
          title : {
            text : 'Game of Life using Heatmap module',
            fontSize : 11,
            align : 'left'
          },
          plotarea : {
              margin : '20 0 0 0'    
          },
          plot : {
              shadow : false,
              aspect : 'stepped',
              lineWidth : 1,
              maxNodes : 0,
              maxTrackers : 0
          },
          scaleX : {
              visible : false   
          },
          scaleY : {
              visible : false
          },
          series : [
              {
                  values : aHValues
              }    
          ]
      }
  });

  zingchart.render({
      id : 'zcv',
      width : 80,
      height : iRows * iSize,
      output : 'canvas',
      data : {
          type : 'varea',
          flat : true,
          plotarea : {
              margin : '0 20 0 0'    
          },
          plot : {
              shadow : false,
              aspect : 'stepped',
              maxNodes : 0,
              maxTrackers : 0,
              lineWidth : 1
          },
          scaleX : {
              mirrored : true,
              visible : false
          },
          scaleY : {
              visible : false
          },
          series : [
              {
                  values : aHValues
              }    
          ]
      }
  });
  
});
              
            
!
999px

Console