text: /**
   * General data munging functionality
   */
  
  import * as d3 from 'd3';
  import loadData from '@financial-times/load-data';
  
  /**
   * Parses data file and returns structured data
   * @param  {String} url Path to CSV/TSV/JSON file
   * @return {Object}     Object containing series names, value extent and raw data object
   */
  export function load(url, options) { // eslint-disable-line
      const { dateFormat } = options;
  
      return loadData(url).then((result) => {
          const data = result.data ? result.data : result;
          // make sure all the dates in the date column are a date object
          const parseDate = d3.timeParse(dateFormat);
          data.forEach((d) => {
              d.date = parseDate(d.date);
          });
  
          return data;
      });
  }
  
  
  /**
   * Returns the columns headers from the top of the dataset, excluding specified
   * @param  {[type]} columns [description]
   * @return {[type]}         [description]
   */
  export function getSeriesNames(columns) {
      const exclude = ['date', 'annotate', 'highlight'];
      return columns.filter(d => (exclude.indexOf(d) === -1));
  }
  
  /**
   * Calculates the extent of multiple columns
   * @param  {[type]} d       [description]
   * @param  {[type]} columns [description]
   * @param  {[type]} yMin    [description]
   * @return {[type]}         [description]
   */
  export function extentMulti(d, columns, yMin) {
      const ext = d.reduce((acc, row) => {
          const values = columns.map(key => row[key])
          .map((item) => {
              if (item !== 0 && (!item || item === '*')) {
                  return yMin;
              }
              return Number(item);
          });
          const rowExtent = d3.extent(values);
          if (!acc.max) {
              acc.max = rowExtent[1];
              acc.min = rowExtent[0];
          } else {
              acc.max = Math.max(acc.max, rowExtent[1]);
              acc.min = Math.min(acc.min, rowExtent[0]);
          }
          return acc;
      }, {});
      return [ext.min, ext.max];
  }
  
  /**
   * Sorts the column information in the dataset into groups according to the column
   * head, so that the line path can be passed as one object to the drawing function
   */
  export function getlines(d, group, index) {
      const lineData = [];
      d.forEach((el) => {
          const column = {};
          column.name = group;
          column.index = index;
          column.date = el.date;
          column.value = +el[group];
          column.highlight = el.highlight;
          column.annotate = el.annotate;
          if (el[group]) {
              lineData.push(column);
          }
          if (el[group] === false) {
              lineData.push(null);
          }
      });
      return lineData;
      // return d.map((el) => {
      //     if (el[group]) {
      //         return {
      //             name: group,
      //             date: el.date,
      //             value: +el[group],
      //             highlight: el.highlight,
      //             annotate: el.annotate,
      //         };
      //     }
  
      //     return null;
      // }).filter(i => i);
  }
  