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

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

              
                <div id='description'>
  <h3><code>margin();</code></h3>
  <p>Resize the margin of the graph also affects the size of all the custom labels. By default the margin is set to <code>26</code> on all sides.</p>

  <div>Change margin to
    <button class="rs-btn--small rs-btn--selected" onclick='_default()'>default</button>
    <button class="rs-btn--small" onclick='margin_10()'>'10' all sides</button>
    <button class="rs-btn--small" onclick='margin_topright30()'>'30' top & right</button>
  </div>
</div>
<div id='chart'></div>
<div id='margInfo'></div>
              
            
!

CSS

              
                #description, #chart, #margInfo{
  margin: 1em;
}
svg{
  border: 1px solid grey;
}
              
            
!

JS

              
                //RedSift
//margin();
//Resize the graph margin
//The example below has different margin size which include margin size of 10 and another example of 30 for the top and right of the graph. 

let chart = d3_rs_lines.html();

d3.select('#chart')
  .datum([1, 2, 3, 10, 20])
  .call(chart);

d3.select('#margInfo')
  .html('Margin is set to default size.');

function _default() {

  let chart = d3_rs_lines.html(); //margin set to default which is 26 when margin is not specified.  

  d3.select('#chart').datum([1, 2, 3, 10, 20]).call(chart);

  d3.select('#margInfo')
    .html('Margin is set to default size.');
}

function margin_10() {
  let chart = d3_rs_lines.html()
    .margin(10); //margin set to 10 on all size of the graph

  d3.select('#chart')
    .datum([1, 2, 3, 10, 20])
    .call(chart);

  d3.select('#margInfo')
    .html('<p>Margin is set to "10" on all sides <code>margin(10);</code></p>');

}

function margin_topright30() {
  let chart = d3_rs_lines.html()
    .margin({
      top: 30,
      left: 0,
      right: 30,
      bottom: 0
    }); //margin set to 20 

  d3.select('#chart')
    .datum([1, 2, 3, 10, 20])
    .call(chart);

  d3.select('#margInfo')
    .html('<p>Margin is set to "30" on top and right of the graph <code>margin({ top: 30, left: 0, right: 30, bottom: 0});</code></p>');
}

// Generic function to toggle selected state of a button
d3.selectAll('button')
  .on('click', function() {
    let selected = this;
    d3.selectAll('button')
      .classed('rs-btn--selected', function() {
        return (selected === this);
      });
  });
              
            
!
999px

Console