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 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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

                 <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.0.8/d3.min.js"></script>
<script src="https://rawgithub.com/d3/d3-plugins/master/fisheye/fisheye.js"></script>
  <aside>Aug 13, 2013</aside>
  <a href="http://www.wundes.com" rel="author">John Wundes</a>

<h1><span id="sizeTitle"></span> Cartesian Fisheye Distortion Heatmap Test</h1>Discussion: <a href="https://groups.google.com/forum/#!msg/d3-js/IbnqY24eBx0/wfixKeNTbPwJ">D3 Google Groups:Looking for a Cartesian Fisheye Distortion Heatmap example</a>
<p id="chart3">  
text {
  font: 10px sans-serif;

.background { 
  fill: none;
  pointer-events: all;
#chart3 svg { 
  border: solid 1px #ccc;

.ytext:hover {  
 #chart3 line {
  fill: none;
  stroke: #ddd;

#chart3 line {
  shape-rendering: crispEdges;
.axis path, .axis line {
  fill: none;
  stroke: #fff;
  shape-rendering: crispEdges;
              var rowLen = 20;
d3.select("#sizeTitle").text(rowLen+ " x "+rowLen);

var dataset = [];

var elGen = function(c){
     var e = {};
     e.val = c;
     //cheap random but repeatable colors:
     e.col = ('#'+ parseInt(c%255,16)+ 
     return e;
for(var c=0,len = rowLen*rowLen;c<len;c++){
(function chart3() {
  var width = 600,
      height = 400,
       boxes = rowLen,
      xSteps =  d3.range(0, width, width/rowLen), 
      ySteps =  d3.range(0, height, height/rowLen),
       boxSteps = d3.range(boxes*boxes);
     //set scale and origin focus
  var xFisheye = d3.fisheye.scale(d3.scale.identity).domain([0, width]).focus(width/2),
      yFisheye = d3.fisheye.scale(d3.scale.identity).domain([0, height]).focus(height/2);
       fontSizeFisheye = d3.fisheye.scale(d3.scale.log).domain([3,150]).range([8,15]).focus(12),
       fontOpacityFisheye = d3.fisheye.scale(d3.scale.log).domain([8,50]).range([0,1]).focus(1)
  var svg = d3.select("#chart3").append("svg")
      .attr("width", width)
      .attr("height", height)
      .attr("transform", "translate(-.5,-.5)");

      .attr("class", "background")
      .attr("width", width)
      .attr("height", height); 
     var boxTest = svg.selectAll(".yrect")
       .attr("class", "yrect")
       .style("fill",function(d,i){return d.col})       
     var yText = svg.selectAll("ytext")
      .text(function(d,i){return d.val})
       .attr("class", "ytext") 
       .attr("text-anchor", "middle");


  svg.on("mousemove", function() {
    var mouse = d3.mouse(this);

  function redraw() { 
               return xFisheye(xSteps[i%rowLen]) + (xFisheye(xSteps[(i+1)%rowLen] || width) - xFisheye(xSteps[i%rowLen]))/2;
               var rowNum = Math.floor(i/rowLen);
               return yFisheye(ySteps[rowNum]) + (yFisheye(ySteps[rowNum+1] || height) - yFisheye(ySteps[rowNum]))/2;
               var rowNum = Math.floor(i/rowLen);
               var xx = (xFisheye(xSteps[(i+1)%rowLen] || width) - xFisheye(xSteps[(i)%rowLen]));
               var yy = (yFisheye(ySteps[rowNum+1]|| height) - yFisheye(ySteps[rowNum]));
               var minDim = d3.min([xx,yy]);
               return fontSizeFisheye(minDim);
               var rowNum = Math.floor(i/rowLen);
               var xx = (xFisheye(xSteps[(i+1)%rowLen] || width) - xFisheye(xSteps[(i)%rowLen]));
               var yy = (yFisheye(ySteps[rowNum+1] || height) - yFisheye(ySteps[rowNum])); 
               var minDim = d3.min([xx,yy]);
               return fontOpacityFisheye(minDim);
               var rowNum = i%rowLen;
               var yy = (yFisheye(ySteps[rowNum]) - yFisheye(ySteps[rowNum-1])); 
               return (fontSizeFisheye(yy)/2);
     boxTest.attr("x", function(d,i){
          return xFisheye(xSteps[i%rowLen]);
     .attr("y", function(d,i){
          var rowNum = Math.floor(i/rowLen);
          return yFisheye(ySteps[rowNum-1] || 0) + (yFisheye(ySteps[rowNum]) - yFisheye(ySteps[rowNum-1] || 0))})
     .attr("width", function(d,i){
          var rowNum = Math.floor(i/rowLen);
          return (xFisheye(xSteps[(i+1)%rowLen] || width) - xFisheye(xSteps[i%rowLen]))})
     .attr("height", function(d,i){
          var rowNum = Math.floor(i/rowLen);
          return (yFisheye(ySteps[rowNum+1]|| height) - yFisheye(ySteps[rowNum]))})
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................