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>animation();</code></h3>
<p>Animate the chart, interpollating through the points using <code>reveal</code> or <code>value</code>. <code>default</code> can also be used but it cancel out the animation.</p>
 
 <div><p>Animate using <code>reveal</code>, <code>.animation('reveal')</code><br><button class="rs-btn--small" onclick = 'animated()'>Animate</button></p></div>
  
<div id = 'chart'></div>
  
<div>Animate the chart using 2 stage animation, scaling and adding data to end of the line.<br><button class="rs-btn--small"; onclick = 'animateSecond()'>Animate</button></p>

<div id='secChart'></div>
  
</div>  
              
            
!

CSS

              
                #description {
  margin: 1em;
}
              
            
!

JS

              
                //Redsift
//animation();
//animation of interpollation throught the points
//example below shows the animation in connecting the points of the dataset TIMES
//animation can be of 3 different type; default, reveal and value.
//default: cancel the animation
//reveal: interpolate through all the points smoothly
//value: interpolate from the last known point to the current point

let TIMES = [               //dataSet
      {
        "l" : 1461456000000,
        "v" : 12
      },
      {
        "l" : 1461542400000,
        "v" : 5
      },
      {
        "l" : 1461628800000,
        "v" : 8
      },
      {
        "l" : 1461715200000,
        "v" : 18
      },
      {
        "l" : 1461801600000,
        "v" : 18
      },
      {
        "l" : 1461888000000,
        "v" : 8
      },
      {
        "l" : 1461974400000,
        "v" : 11
      },
      {
        "l" : 1462060800000,
        "v" : 8
      },
      {
        "l" : 1462147200000,
        "v" : 9
      },
      {
        "l" : 1462233600000,
        "v" : 8
      },
      {
        "l" : 1462320000000,
        "v" : 17
      },
      {
        "l" : 1462406400000,
        "v" : 19
      },
      {
        "l" : 1462492800000,
        "v" : 13
      },
      {
        "l" : 1462579200000,
        "v" : 17
      },
      {
        "l" : 1462665600000,
        "v" : 19
      },
      {
        "l" : 1462752000000,
        "v" : 9
      },
      {
        "l" : 1462838400000,
        "v" : 13
      },
      {
        "l" : 1462924800000,
        "v" : 7
      }
];
//chart property  
let chart = d3_rs_lines.html()
    .labelTime('multi')         //label the time format,check labelTime example: https://codepen.io/geervesh/pen/GqYdoo
    .tickCountIndex('utcWeek')  //change the index format, check tickCountIndex example: https://codepen.io/geervesh/pen/QEVPJk
    .width(500)       //width of the chart
    .animateAxis(true) //turning axis animation off. 
    //.animateLabels(true)  
    .fillArea(false);   //fillArea set to 'false

// First chart
d3.select('#chart')
    .call(chart)        //call chart
    .datum(TIMES) //slice TIMES dataset
    .transition()       //animate data
      .duration(15000)   //duration of transition
      .call(chart.animation('reveal'));  //animate chart using 'reveal' property
  console.log(TIMES);


//Second chart

    let i = 1;              //set variable
    let animate = d3.select('#secChart')    //select by 'id'  
      .datum(TIMES.slice(0, i))     //select data from TIMES from 0 to i.
      .call(chart);     //call the chart 
    
    let timer = null;    //set timer to null
    function addData() {    
        // keep adding data sets
        if (i < TIMES.length) {   //if the length of times is less than i
            i++;                  //increment i
        } else {                
            clearInterval(timer);	  //clear timer interval
            timer = null;            //set timer to null
            return                   
        }
        animate
          .datum(TIMES.slice(0, i))   //interpolate from 0 to i
          .transition()               //animate
            .duration(500)            //duration of transition
            .call(chart.animation('default').trim(i-1))   //rescale the graph using trim
            .on('end', function() {   //interpolate the end section of the graph 
                animate.transition()  //animate 
                        .duration(500)  //duration 
                        .call(chart.animation('reveal').trim(null)); //animate chart using 'reveal' property and set the data trimming(scaling) to null 
          //
            });     
    }
    timer = setInterval(addData, 2000);  //time interval between rescaling and adding end data

///animate purposes
//animate first chart on click
function animated(){
  d3.select('#chart')
    .call(chart)        //call chart
    .datum(TIMES) //slice TIMES dataset
    .transition()       //animate data
      .duration(15000)   //duration of transition
      .call(chart.animation('reveal'));  //animate chart using 'reveal' property
}
//animate second chart
function animateSecond(){     
  let i = 2;              //set variable
    let animate = d3.select('#secChart')    //select by 'id'  
      .datum(TIMES.slice(0, i))     //select data from TIMES from 0 to i.
      .call(chart);     //call the chart 
    
    let timer = null;    //set timer to null
    function addData() {    
        // keep adding data sets
        if (i < TIMES.length) {   //if the length of times is less than i
            i++;                  //increment i
        } else {                
            clearInterval(timer);	  //clear timer interval
            timer = null;            //set timer to null
            return                   
        }
        animate
          .datum(TIMES.slice(0, i))   //interpolate from 0 to i
          .transition()               //animate
            .duration(500)            //duration of transition
            .call(chart.animation('default').trim(i-1))   //rescale the graph using trim
            .on('end', function() {   //interpolate the end section of the graph 
                animate.transition()  //animate 
                        .duration(500)  //duration 
                        .call(chart.animation('reveal').trim(null)); //animate chart using 'reveal' property and set the data trimming(scaling) to null 
          //
            });     
    }
    timer = setInterval(addData, 2000);  //time interval between rescaling and adding end data 
}




              
            
!
999px

Console