




'use strict';

import { Injectable, Inject } from '@angular/core';
import { HttpClient} from '@angular/common/http';
//import 'rxjs/Rx';
import {map} from 'rxjs/operator/map';

// Common data service
@Injectable()
export class DataSvc {
    http: HttpClient;

    constructor( @Inject(HttpClient) http: HttpClient) {
        this.http = http;
    }

    // get chart data
    getData() {
        //var data = <any>this.http.get('data/fb.json').map(res => {
        var data = map.call(this.http.get('data/fb.json'), res => {
            var d = res,
                len = d.length,
                i, dateStr;
            
            for (i = 0; i < len; i++) {
                dateStr = d[i].date;
                dateStr = dateStr.split('/');
                d[i].date = new Date(dateStr[2], dateStr[0] - 1, dateStr[1]);
            }
            return d;
        });
        return data;
    }

}
