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.


Auto Save

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.


                <div id="bar"><div id="barInner"></div></div>

<header id="header">
<!-- /#header --></header>

<section id="main">
    <div id="secGraph"></div>
<!-- /#main --></section>


                body { background:rgba(0,0,0,.95);}

h1 { color: #fff; font-size: 13px;}

#secGraph > div {
  background: rgba(0,0,0,.5);
  position: relative;
.node {
  position: absolute;
  box-sizing: border-box;
  overflow: hidden;
  color: #fff;
  font-size: 10px;
  text-indent: 10px;
  line-height: 2;


                var data = {
  'name': 'fishes',
  'children': [
    {'name': 'さば',num: 10},
    {'name': 'いわし',num: 40},
    {'name': 'キス',num: 4},
    {'name': 'めじな',num: 2},
    {'name': 'あじ',num: 22},
    {'name': 'ごんずい',num: 1},

var graph_width = 720//表示幅
var graph_height = 300;//表示高さ

var photoGraph ="#secGraph")
  .attr('style', function(){
    return 'width: ' + graph_width + 'px; height: ' + graph_height+'px;'


var treemap = d3.layout.treemap()
    .size([graph_width, graph_height])
    .value(function(d) {
    return ( parseInt( d.num ) );

  .selectAll(".node")//photoGraph から、「.node」クラスを持つ要素全てを選択
  .data( treemap.nodes(data) )//選択された全ての「.node」クラスを持つ要素群と、treemapに渡した釣りデータの返り値をデータバインド※1
  .attr('style',function(d , i){
  //スタイルの設定。引数のdはデータバインドされた、※1 の各データ、i はインデックス
    var hue = parseInt( i * 40  + 120 );//色分けのため、HUE(色相)を指定
    var styleCode = '';
    styleCode += 'width:' +  d.dx + 'px;';//
    styleCode += 'height:' +  d.dy + 'px;';
    styleCode += 'top:' + ( graph_height - d.y - d.dy) + 'px;';
    styleCode += 'left:' + ( graph_width - d.x - d.dx ) + 'px;';
    styleCode += 'background-color:hsl(' + hue + ', 50%, 40%);';
    return styleCode;