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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <html lang="en">

<head>
   <meta charset="utf-8">
   <!-- Setting the viewport -->
   <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

   <title>CSV Parsing</title>
</head>

<body ng-app="csvParse" ng-controller="csvParseController">

   <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">

      <!-- HEADER -->
      <header class="mdl-layout__header">
         <div class="mdl-layout__header-row">
            <!-- Title -->
            <span class="mdl-layout-title">
                CSV Parse Playground
            </span>
            <!-- spacer right-aligns Nav controls -->
            <div class="mdl-layout-spacer"></div>
            <!-- Nav controls -->
            <nav class="mdl-navigation">
               <a class="mdl-navigation__link" href="#top">TOP</a>
               <a class="mdl-navigation__link" href="#table">TABLE</a>
               <a class="mdl-navigation__link" href="#json">JSON</a>
            </nav>
         </div>
      </header>

      <!-- MAIN CONTENT -->
      <main class="mdl-layout__content">
         <div class="page-content">
            <div class="mdl-grid">

               <!-- INTRODUCTION -->
               <div id="top" class="mdl-cell mdl-cell--12-col">
                  <div class="mdl-card mdl-shadow--4dp mdl-card-wide">
                     <div class="mdl-card__title">
                        <h3 class="mdl-card__title-text">
                                What's the Point of this?
                            </h3>
                     </div>

                     <div class="mdl-card__supporting-text">
                        <p>This app takes an array of data, outputs the contents as a table and raw JSON. A HTML5 input/range slider is used to filter the results by specific dates.</p>

                        <p>Total range of dataset: {{minDate | date}} - {{maxDate | date}}</p>
                        <p>Drag to filter on specific dates:</p>
                        <p>
                           <input type="range" id="sl1" class="mdl-slider date-slider" min="0" max="{{dateArray.length - 1}}" step="1" value="0" ng-model="myDate">
                        </p>
                        <p>Showing: {{ (outputData|filter:dateArray[myDate]).length }} of {{ outputData.length }} total results:</p>
                        <table class="mdl-data-table mdl-js-data-table table-narrow">
                           <thead>
                              <th class="mdl-data-table__cell--non-numeric">Date index</th>
                              <th class="mdl-data-table__cell--non-numeric">Javascript Date</th>
                              <th class="mdl-data-table__cell--non-numeric">Formatted Date</th>
                           </thead>
                           <tbody>
                              <tr>
                                 <td class="mdl-data-table__cell--non-numeric">{{myDate}}</td>
                                 <td class="mdl-data-table__cell--non-numeric">{{dateArray[myDate]}}</td>
                                 <td class="mdl-data-table__cell--non-numeric">{{dateArray[myDate] | date}}</td>
                              </tr>
                           </tbody>
                        </table>

                     </div>
                  </div>
               </div>


               <!-- OUTPUT AS TABLE -->
               <div id="table" class="mdl-cell mdl-cell--12-col">
                  <div class="mdl-card mdl-shadow--4dp mdl-card-wide">
                     <div class="mdl-card__title">
                        <h3 class="mdl-card__title-text">
                                Tabular Output:
                            </h3>
                     </div>

                     <div class="mdl-card__supporting-text">
                        <table class="mdl-data-table
                                          mdl-js-data-table
                                          table-wide">
                           <thead>
                              <th class="mdl-data-table__cell--non-numeric">Source</th>
                              <th class="mdl-data-table__cell--non-numeric">Target</th>
                              <th>Value</th>
                              <th>Annum</th>
                           </thead>
                           <tbody>
                              <tr ng-repeat="data in outputData | filter:dateArray[myDate]">
                                 <td class="mdl-data-table__cell--non-numeric">{{data.source}}</td>
                                 <td class="mdl-data-table__cell--non-numeric">{{data.target}}</td>
                                 <td>{{data.value}}</td>
                                 <td>{{data.annum | date}}</td>
                              </tr>
                           </tbody>
                        </table>
                     </div>
                  </div>
               </div>

               <!-- OUTPUT AS JSON -->
               <div id="json" class="mdl-cell mdl-cell--12-col">
                  <div class="mdl-card mdl-shadow--4dp mdl-card-wide">
                     <div class="mdl-card__title">
                        <h3 class="mdl-card__title-text">
                                In the raw...
                            </h3>
                     </div>

                     <div class="mdl-card__supporting-text">
                        <pre>{{ outputData | filter:dateArray[myDate] | json:4 }}</pre>
                     </div>
                  </div>
               </div>

            </div>
         </div>
      </main>
   </div>

</body>

</html>
            
          
!

CSS

            
              .mdl-card-wide {
   width: 100%;
}

.mdl-card__supporting-text {
   width: auto;
}

.table-narrow {
   width: 440px;
}

.table-wide {
   width: 100%;
}

.date-slider {
   width: 400px;
}
            
          
!

JS

            
              (function() {
   'use strict';

   var app = angular.module('csvParse', []);

   // ============= CONTROLLERS =============
   app.controller('csvParseController', function($scope) {
      
      $scope.myDate = 0;
      
      var i, j, k, l,
          uniqueDates,
          formattedResults = [];

      // ** faking it for Codepen... **
      var formattedResults = [
         {
         "source": "SCM",
         "target": "DOCUMENTATION",
         "value": 143511206,
         "annum": 1455602400000
      }, {
         "source": "DMEE",
         "target": "DIAGNOSIS AND PROCEDURES",
         "value": 21878533,
         "annum": 1456466400000
      }, {
         "source": "SCM",
         "target": "PATIENT",
         "value": 8165055,
         "annum": 1456207200000
      }, {
         "source": "SV",
         "target": "PATIENT",
         "value": 25408360,
         "annum": 1456207200000
      }, {
         "source": "EMTRAC",
         "target": "DIAGNOSIS AND PROCEDURES",
         "value": 5439516,
         "annum": 1454306400000
      }, {
         "source": "THERADOC",
         "target": "INFECTION",
         "value": 662607,
         "annum": 1455775200000
      }, {
         "source": "SCM",
         "target": "PATIENT",
         "value": 8162677,
         "annum": 1456120800000
      }, {
         "source": "CV",
         "target": "ENCOUNTER",
         "value": 59037,
         "annum": 1456466400000
      }, {
         "source": "THERADOC",
         "target": "CROSSREFERENCE",
         "value": 123145,
         "annum": 1454997600000
      }, {
         "source": "HDMPMC",
         "target": "ENCOUNTER",
         "value": 593412,
         "annum": 1456725600000
      }, {
         "source": "THERADOC",
         "target": "INFECTION",
         "value": 664846,
         "annum": 1456725600000
      }, {
         "source": "EPIC",
         "target": "DIAGNOSIS AND PROCEDURES",
         "value": 160351773,
         "annum": 1454738400000
      }, {
         "source": "EMTRAC",
         "target": "DIAGNOSIS AND PROCEDURES",
         "value": 5439516,
         "annum": 1454738400000
      }, {
         "source": "SCM",
         "target": "DIAGNOSIS AND PROCEDURES",
         "value": 11113132,
         "annum": 1454738400000
      }, {
         "source": "THERADOC",
         "target": "CROSSREFERENCE",
         "value": 123448,
         "annum": 1455343200000
      }, {
         "source": "ARIA",
         "target": "PATIENT",
         "value": 99093,
         "annum": 1456552800000
      }, {
         "source": "EPIC",
         "target": "PATIENT",
         "value": 59185841,
         "annum": 1456552800000
      }, {
         "source": "SCM",
         "target": "PATIENT",
         "value": 8131545,
         "annum": 1454565600000
      }, {
         "source": "HDMHUP",
         "target": "ENCOUNTER",
         "value": 1454417,
         "annum": 1455084000000
      }, {
         "source": "DOCUSYS",
         "target": "ENCOUNTER",
         "value": 832915055,
         "annum": 1455170400000
      }, {
         "source": "PMCCH-DSS",
         "target": "ENCOUNTER",
         "value": 1486222,
         "annum": 1455170400000
      }];
      
      // === begin build array of unique dates ===
      
      // add 'contains' method to Array prototype
      Array.prototype.contains = function (v) {
         for (j = 0; j < this.length; j += 1) {
            if (this[j] === v) {
               return true;
            }
         }
         return false;
      };
      
      // add 'unique' method to Array prototype
      Array.prototype.unique = function () {
         var arr = [];
         for (k = 0; k < this.length; k += 1) {
            if (!arr.contains(this[k].annum)) {
               arr.push(this[k].annum);
            }
         }
         return arr;
      };
      
      // find unique dates within formattedResults array
      uniqueDates = formattedResults.unique().sort();
      // console.log('Unique dates:\n', uniqueDates);   // testing
      // console.log('Unique dates length:', uniqueDates.length);   // testing
      
      // find min date within uniqueDates
      $scope.minDate = Math.min.apply(Math, uniqueDates.map(function (objMin) {
         return objMin;
      }));
      
      // find min date within uniqueDates
      $scope.maxDate = Math.max.apply(Math, uniqueDates.map(function (objMax) {
         return objMax;
      }));
      
      // ================== bind data to $scope object ==================
      $scope.outputData = formattedResults;
      $scope.dateArray  = uniqueDates;
   
   });

})();
            
          
!
999px

Console