Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                  <html class="no-js">
    <head>
      <title>d3 Demo CSS Layout 11</title>
      <script src="https://cdn.rawgit.com/mbostock/d3/master/d3.js"></script>
    </head>
    <body>
      <div class="resizable ui-widget-content container-fluid wrap">
        <div class="row-fluid">
          <h3 class="ui-widget-header">Pie Chart</h3>
          <div class="col-xs-6 column visualization">
          </div>
          <div class="col-xs-6 column">
            <div class="btn-group">
              <button class="btn btn-default" type="button"><em class="glyphicon glyphicon-align-left"></em> Left</button> 
              <button class="btn btn-default" type="button"><em class="glyphicon glyphicon-align-center"></em> Center</button> 
              <button class="btn btn-default" type="button"><em class="glyphicon glyphicon-align-right"></em> Right</button>
            </div>
          </div>
        </div>
      </div>
    </body>

              
            
!

CSS

              
                html, body {
  font-family: sans-serif;
  background-color: transparent;
}

.row-fluid {
  height: 100%;
}

.resizable {
  top: 10px;
  left: 10px;
  width: 525px;
  height: 300px;
  padding: 0em 0em 4em;
  margin: 0;
  font-size: 10px;
  background: #F3F3F3;
}

.resizable h3 {
  text-align: center;
  margin: 0 0 10px;
  font-size: 13px;
  height: 16px;
  border: none;
}

.ui-resizable-handle.ui-resizable-se.ui-icon.ui-icon-gripsmall-diagonal-se {
  z-index: 0 !important;
}

.visualization {
  height: 100%;
  min-height: 100%;
}

.visualization svg {
  width: 100%;
  height: 100%;
  border: 1px solid #666666;
}

.cell .label {
  color: #333333;
  font-size: 8px;
  white-space: pre-wrap;
  text-align: left;
  text-overflow: ellipsis;
}

.cell .background {
  stroke: #333333;
  stroke-width: 0.5;
}

              
            
!

JS

              
                ReusableTreemap = function() {

    var data = [],
        json = null,
        chartWidth = 0,
        chartHeight = 0,
        domNode = null,
        svg = null,
        rootGroup = null,
        color = d3.scale.ordinal().range(colorbrewer.RdGy[9]),
        treemap = d3.layout.treemap(),
        dispatch = d3.dispatch("pageDown", "pageUp");

    function reusabletreemap(selection) {
        // initial setup
        domNode = selection.node(); // item dom node
        rootGroup = selection.append("svg");
        treemap.size([chartWidth, chartHeight])
            .sticky(false)
            .value(function(d) {
                return d.size;
            });
        data = treemap.nodes(json);
        cellSelection = rootGroup.selectAll("g").data(data)
            .enter().append("g")
            .classed("cell", true);
        cellSelection.append("rect")
            .classed("background", true);
        cellSelection.append('foreignObject')
            .attr("class", "foreignObject")
            .append("xhtml:body")
            .attr("class", "labelbody")
            .append("div")
            .attr("class", "label")
            .text(function(d) {
                return d.name;
            });


        function handleResize() {
            chartWidth = parseInt(d3.select(domNode).style("width"));
            chartHeight = parseInt(d3.select(domNode).style("height"));
            data = treemap.size([chartWidth, chartHeight])
                .nodes(json);
            d3.select(domNode)
                .attr("width", chartWidth + "px")
                .attr("height", chartHeight + "px");
            rootGroup.selectAll(".cell")
                .each(function() {
                    d3.select(this).call(position);
                });
        }


        function position() {
            this.attr("transform", function(d) {
                return "translate(" + d.x + "," + d.y + ")";
            });
            this.select(".background")
                .attr("width", function(d) {
                    return Math.max(0.01, d.dx);
                })
                .attr("height", function(d) {
                    return d.dy;
                })
                .style("fill", function(d) {
                    return color(d.name);
                });
            this.select(".foreignObject")
                .attr("transform", "translate(3,3)")
                .attr("width", function(d) {
                    return Math.max(0.01, d.dx);
                })
                .attr("height", function(d) {
                    return Math.max(0.01, d.dy);
                })
                .select(".label")
                .text(function(d) {
                    return d.name;
                });
        }

        reusabletreemap.handleResize = handleResize; // make handleResize function publicly visible 
        handleResize(); // call handleResize() to start
    }

    reusabletreemap.handleResize = function(evt) { // placeholder function that is overridden at runtime
        return reusabletreemap;
    };

    reusabletreemap.json = function(_) {
        if (!arguments.length) return json;
        json = _;
        return reusabletreemap;
    };

    d3.rebind(reusabletreemap, dispatch, "on");

    return reusabletreemap;
};

$(function() {
    var resizableWindow = $(".resizable");
    d3.json("http://www.billdwhite.com/wordpress/wp-content/data/flare.json", function(error, data) {
        resizableWindow = resizableWindow.resizable({
            minHeight: 175,
            minWidth: 225
        }).draggable()[0];
        var treemap = ReusableTreemap();
        treemap.json(data);
        d3.select(resizableWindow).select(".visualization").call(treemap);
        resizableWindow.onresize = function(e) {
            treemap.handleResize();
        };
    });
});
              
            
!
999px

Console