Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, AfterViewInit, ViewChild, NgModule } from '@angular/core';
  2. import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material';
  3. import { BreakpointObserver } from '@angular/cdk/layout';
  4. import * as Chartist from 'chartist';
  5. import { ChartType, ChartEvent } from 'ng-chartist/dist/chartist.component';
  6. import { BrowserModule } from '@angular/platform-browser';
  7. import { FormsModule } from '@angular/forms';
  8. import { AppComponent } from '../../app.component';
  9. declare var require: any;
  10.  
  11. const data: any = require('./data.json');
  12.  
  13. export interface Chart {
  14.   type: ChartType;
  15.   data: Chartist.IChartistData;
  16.   options?: any;
  17.   responsiveOptions?: any;
  18.   events?: ChartEvent;
  19. }
  20.  
  21. export interface Element {
  22.   pic: string;
  23.   nome: string;
  24.   linha: number;
  25.   setor: string;
  26.   gasto: number;
  27. }
  28.  
  29. const ELEMENT_DATA: Element[] = [
  30.   {
  31.     pic: 'assets/images/users/1.jpg',
  32.     nome: 'José X',
  33.     linha: 93991227676,
  34.     setor: 'GHI',
  35.     gasto: 354.60
  36.   },
  37.   {
  38.     pic: 'assets/images/users/2.jpg',
  39.     nome: 'Sunil joshi',
  40.     linha: 93991227676,
  41.     setor: 'GHI',
  42.     gasto: 35460
  43.   },
  44.   {
  45.     pic: 'assets/images/users/3.jpg',
  46.     nome: 'Vishal Bhatt',
  47.     linha: 93991227676,
  48.     setor: 'GHI',
  49.     gasto: 35460
  50.   },
  51.   {
  52.     pic: 'assets/images/users/4.jpg',
  53.     nome: 'Beryllium Lon',
  54.     linha: 93991227676,
  55.     setor: 'GHI',
  56.     gasto: 35460
  57.   },
  58.   {
  59.     pic: 'assets/images/users/5.jpg',
  60.     nome: 'Boron son',
  61.     linha: 93991227676,
  62.     setor: 'GHI',
  63.     gasto: 35460
  64.   },
  65.   {
  66.     pic: 'assets/images/users/6.jpg',
  67.     nome: 'Carbon hryt',
  68.     linha: 93991227676,
  69.     setor: 'GHI',
  70.     gasto: 35460
  71.   },
  72.   {
  73.     pic: 'assets/images/users/7.jpg',
  74.     nome: 'Nitro oxur',
  75.     linha: 93991227676,
  76.     setor: 'GHI',
  77.     gasto: 35460
  78.   }
  79. ];
  80.  
  81. @NgModule({
  82.   declarations: [
  83.     AppComponent
  84.   ],
  85.   imports: [  
  86.     BrowserModule,
  87.     FormsModule
  88.   ],
  89.   providers: [],
  90.   bootstrap: [AppComponent]
  91. })
  92.  
  93. @Component({
  94.   selector: 'app-dashboard',
  95.   templateUrl: './dashboard1.component.html',
  96.   styleUrls: ['./dashboard1.component.scss']
  97. })
  98.  
  99. export class Dashboard1Component implements AfterViewInit {
  100.  
  101.   clientes = [];
  102.   cliente = "";
  103.  
  104.   addCliente(){
  105.     this.clientes.push(this.cliente);
  106.   }
  107.  
  108.   displayedColumns = ['pic', 'nome', 'linha', 'setor', 'gasto'];
  109.  
  110.   dataSource: MatTableDataSource<Element>;
  111.   @ViewChild(MatPaginator) paginator: MatPaginator;
  112.   @ViewChild(MatSort) sort: MatSort;
  113.  
  114.   constructor(breakpointObserver: BreakpointObserver) {
  115.     breakpointObserver.observe(['(max-width: 600px)']).subscribe(result => {
  116.       this.displayedColumns = result.matches ?
  117.         ['pic', 'nome', 'linha', 'setor', 'gasto'] :
  118.         ['pic', 'nome', 'linha', 'setor', 'gasto'];
  119.     });
  120.  
  121.     // Assign the data to the data source for the table to render
  122.     this.dataSource = new MatTableDataSource<Element>(ELEMENT_DATA);
  123.   }
  124.  
  125.   //Strings
  126.   str_total_linhas = 'Linhas';
  127.   str_total_linhas_ativas = 'Em uso';
  128.   str_total_linhas_disp = 'Disponíveis';
  129.   str_total_linhas_cancel = 'Aparelhos';
  130.   //planos
  131.   str_plano_base = 'Básico';
  132.   str_plano_inter = 'Intermediário';
  133.   str_plano_avan = 'Avançado';
  134.  
  135.   str_plano_base_qt = ' - 600MB';
  136.   str_plano_inter_qt = ' - 5GB';
  137.   str_plano_avan_qt = ' - 10GB';
  138.  
  139.   // Barchart
  140.   barChart1: Chart = {
  141.     type: 'Bar',
  142.     data: data['Bar'],
  143.     options: {
  144.       seriesBarDistance: 15,
  145.       high: 12,
  146.  
  147.       axisX: {
  148.         showGrid: false,
  149.         offset: 20
  150.       },
  151.       axisY: {
  152.         showGrid: true,
  153.         offset: 40
  154.       }
  155.     },
  156.  
  157.     responsiveOptions: [
  158.       [
  159.         'screen and (min-width: 640px)',
  160.         {
  161.           axisX: {
  162.             labelInterpolationFnc: function (
  163.               value: number,
  164.               index: number
  165.             ): string {
  166.               return index % 1 === 0 ? `${value}` : null;
  167.             }
  168.           }
  169.         }
  170.       ]
  171.     ]
  172.   };
  173.  
  174.   // This is for the donute chart
  175.   donuteChart1: Chart = {
  176.     type: 'Pie',
  177.     data: data['Pie'],
  178.     options: {
  179.       donut: true,
  180.       showLabel: false,
  181.       donutWidth: 30
  182.     }
  183.     // events: {
  184.     //   draw(data: any): boolean {
  185.     //     return data;
  186.     //   }
  187.     // }
  188.   };
  189.  
  190.   ngAfterViewInit() {
  191.     // Sparkline chart
  192.     const sparklineLogin = function () {
  193.       // spark count
  194.       (<any>$('.spark-count')).sparkline(
  195.         [4, 5, 0, 10, 9, 12, 4, 9, 4, 5, 3, 10, 9, 12, 10, 9, 12, 4, 9],
  196.         {
  197.           type: 'bar',
  198.           width: '100%',
  199.           height: '70',
  200.           barWidth: '2',
  201.           resize: true,
  202.           barSpacing: '6',
  203.           barColor: 'rgba(255, 255, 255, 0.3)'
  204.         }
  205.       );
  206.     };
  207.  
  208.     let sparkResize;
  209.     (<any>$(window)).resize(function (e) {
  210.       clearTimeout(sparkResize);
  211.       sparkResize = setTimeout(sparklineLogin, 500);
  212.     });
  213.  
  214.     sparklineLogin();
  215.  
  216.     this.dataSource.paginator = this.paginator;
  217.     this.dataSource.sort = this.sort;
  218.   }
  219.  
  220.   applyFilter(filterValue: string) {
  221.     filterValue = filterValue.trim(); // Remove whitespace
  222.     filterValue = filterValue.toLowerCase(); // Datasource defaults to lowercase matches
  223.     this.dataSource.filter = filterValue;
  224.   }
  225.  
  226.  
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement