working graph widgets and local doughnut chart

This commit is contained in:
piratefinn 2017-12-14 16:44:23 +00:00
parent 846c21f967
commit df9ea2436c
7 changed files with 194 additions and 70 deletions

View file

@ -24,6 +24,7 @@ import { OrgGraphsService } from './providers/org-graphs.service';
import { CustGraphsService } from './providers/cust-graphs.service'; import { CustGraphsService } from './providers/cust-graphs.service';
import { OrgSnippetsService } from './providers/org-snippets.service'; import { OrgSnippetsService } from './providers/org-snippets.service';
import { CustSnippetsService } from './providers/cust-snippets.service'; import { CustSnippetsService } from './providers/cust-snippets.service';
import { CustPiesService } from './providers/cust-pies.service';
// Layouts // Layouts
import { FullLayoutComponent } from './layouts/full-layout.component'; import { FullLayoutComponent } from './layouts/full-layout.component';
@ -69,6 +70,7 @@ import { DashboardModule } from './dashboard/dashboard.module';
OrgSnippetsService, OrgSnippetsService,
CustGraphsService, CustGraphsService,
CustSnippetsService, CustSnippetsService,
CustPiesService,
{ {
provide: LocationStrategy, provide: LocationStrategy,
useClass: HashLocationStrategy useClass: HashLocationStrategy

View file

@ -12,8 +12,151 @@
</div><!--/.row--> </div><!--/.row-->
<!-- http://www.chartjs.org/docs/latest/charts/polar.html?h=polar --> <!-- http://www.chartjs.org/docs/latest/charts/polar.html?h=polar -->
<div class=row> <div class=row>
<div class="col-12 col-md-4 no-gutters"> <div class="col-md-4">
<panel-pie></panel-pie> <panel-pie></panel-pie>
</div><!--/.col-->
<div class="col-md-4">
<div class="card">
<div class="card-block">
<div class="row">
<div class="col-12">
<h4 class="card-title float-left mb-0">Purchases Per Week</h4>
</div><!--/.col-->
</div><!--/.row-->
<div class="chart-wrapper">
<ul class="horizontal-bars type-2">
<li>
<span class="title">This Week</span>
<span class="value">191,235 <span class="text-muted small">(56%)</span></span>
<div class="bars">
<div class="progress progress-xs">
<div class="progress-bar bg-success" role="progressbar" style="width: 56%" aria-valuenow="56" aria-valuemin="0" aria-valuemax="100"></div>
</div> </div>
</div> </div>
</li>
<li>
<span class="title">Last Week</span>
<span class="value">51,223 <span class="text-muted small">(15%)</span></span>
<div class="bars">
<div class="progress progress-xs">
<div class="progress-bar bg-success" role="progressbar" style="width: 15%" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</li>
<li>
<span class="title">2 Weeks Ago</span>
<span class="value">37,564 <span class="text-muted small">(11%)</span></span>
<div class="bars">
<div class="progress progress-xs">
<div class="progress-bar bg-success" role="progressbar" style="width: 11%" aria-valuenow="11" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</li>
<li>
<span class="title">3 Weeks Ago</span>
<span class="value">27,319 <span class="text-muted small">(8%)</span></span>
<div class="bars">
<div class="progress progress-xs">
<div class="progress-bar bg-success" role="progressbar" style="width: 8%" aria-valuenow="8" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div><!--/.col-->
<div class="col-md-4">
<div class="card">
<div class="card-block">
<div class="row">
<div class="col-12">
<h4 class="card-title float-left mb-0">Sector Purchase Amounts</h4>
</div><!--/.col-->
</div><!--/.row-->
<div class="chart-wrapper">
<ul class="icons-list">
<li>
<i class="icon-screen-desktop bg-primary"></i>
<div class="desc">
<div class="title">Sector A</div>
<small>Lorem ipsum dolor sit amet</small>
</div>
<div class="value">
<div class="small text-muted">Bought this week</div>
<strong>1.924</strong>
</div>
</li>
<li>
<i class="icon-screen-smartphone bg-info"></i>
<div class="desc">
<div class="title">Sector B</div>
<small>Lorem ipsum dolor sit amet</small>
</div>
<div class="value">
<div class="small text-muted">Bought this week</div>
<strong>1.224</strong>
</div>
</li>
<li>
<i class="icon-screen-smartphone bg-warning"></i>
<div class="desc">
<div class="title">Sector C</div>
<small>Lorem ipsum dolor sit amet</small>
</div>
<div class="value">
<div class="small text-muted">Bought this week</div>
<strong>1.163</strong>
</div>
</li>
<li>
<i class="icon-user bg-danger"></i>
<div class="desc">
<div class="title">Sector D</div>
<small>Lorem ipsum dolor sit amet</small>
</div>
<div class="value">
<div class="small text-muted">Bought this week</div>
<strong>928</strong>
</div>
</li>
<li>
<i class="icon-social-spotify bg-success"></i>
<div class="desc">
<div class="title">Sector E</div>
<small>Lorem ipsum dolor sit amet</small>
</div>
<div class="value">
<div class="small text-muted">Bought this week</div>
<strong>893</strong>
</div>
</li>
<li>
<i class="icon-cloud-download bg-danger"></i>
<div class="desc">
<div class="title">Sector F</div>
<small>Lorem ipsum dolor sit amet</small>
</div>
<div class="value">
<div class="small text-muted">Bought this week</div>
<strong>121.924</strong>
</div>
</li>
<li>
<i class="icon-camera bg-warning"></i>
<div class="desc">
<div class="title">Sector G</div>
<small>Lorem ipsum dolor sit amet</small>
</div>
<div class="value">
<div class="small text-muted">Bought this week</div>
<strong>12.125</strong>
</div>
</li>
</ul>
</div>
</div>
</div>
</div><!--/.col-->
</div><!--/.row-->
</div> </div>

View file

@ -26,18 +26,6 @@ export class DashboardCustomerComponent implements OnInit {
public polarAreaChartType = 'polarArea'; public polarAreaChartType = 'polarArea';
public widgetList = [ public widgetList = [
{
type: 'graph',
name: 'total_today',
title: 'Total Today',
dataType: DataType.currency,
},
{
type: 'graph',
name: 'avg_spend_today',
title: 'Avg. Spend Today',
dataType: DataType.currency,
},
{ {
type: 'graph', type: 'graph',
name: 'total_last_week', name: 'total_last_week',
@ -64,18 +52,6 @@ export class DashboardCustomerComponent implements OnInit {
title: 'Last Month Avg. Spend', title: 'Last Month Avg. Spend',
dataType: DataType.currency, dataType: DataType.currency,
}, },
{
type: 'graph',
name: 'total_user',
title: 'User Total',
dataType: DataType.currency,
},
{
type: 'graph',
name: 'avg_spend_user',
title: 'User Avg. Spend',
dataType: DataType.currency,
},
]; ];
constructor( constructor(

View file

@ -16,8 +16,8 @@
</div><!--/.row--> </div><!--/.row-->
<div class="chart-wrapper"> <div class="chart-wrapper">
<canvas baseChart class="chart" <canvas baseChart class="chart"
[data]="placeholderChartData" [data]="doughnutChartData"
[labels]="placeholderChartLabels" [labels]="doughnutChartLabels"
[legend]="chartLegend" [legend]="chartLegend"
[chartType]="chartType" [chartType]="chartType"
(chartHover)="chartHovered($event)" (chartHover)="chartHovered($event)"

View file

@ -1,8 +1,7 @@
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { OrgGraphsService } from '../providers/org-graphs.service'; import { CustPiesService } from '../providers/cust-pies.service';
import { DataType } from '../shared/data-types.enum'; import { DataType } from '../shared/data-types.enum';
import { ChartData } from '../_interfaces/chart-data'; import { ChartData } from '../_interfaces/chart-data';
import * as moment from 'moment';
@Component({ @Component({
selector: 'panel-pie', selector: 'panel-pie',
@ -10,57 +9,32 @@ import * as moment from 'moment';
}) })
export class PiePanel implements OnInit { export class PiePanel implements OnInit {
// Placeholder
public placeholderChartLabels: string[] = ['Local to Me', 'Local Store', 'Not Local'];
public placeholderChartData: number[] = [400, 100, 100];
public chartType = 'doughnut'; public chartType = 'doughnut';
public chartLegend = true; public chartLegend = true;
public doughnutChartLabels: string[] = [];
public doughnutChartData: number[] = [];
//Old //Old
public rawChartData: Array<number> = [];
public chartData: Array<ChartData> = [
{
data: [],
label: 'This Week'
},
{
data: [],
label: 'Last Week'
},
{
data: [],
label: 'Week Before Last'
}
];
public rawChartLabels: Array<string> = [];
public chartLabels: Array<string> = [];
// public mainChartElements = 7; // public mainChartElements = 7;
constructor( constructor(
private graphService: OrgGraphsService, private pieService: CustPiesService,
) { } ) { }
public ngOnInit(): void { public ngOnInit(): void {
// const end = moment().startOf('day'); this.pieService.getPie()
// const start = end.clone().subtract(this.mainChartElements * 3, 'days'); .subscribe( result => this.setData(result.pie) );
// this.graphService.getGraph('customers_range', {
// start: start.format('YYYY-MM-DD'),
// end: end.format('YYYY-MM-DD'),
// }).subscribe( result => this.setData(result.graph) );
} }
// private setData(data: any) { private setData(data: any) {
// this.chartLabels = data.labels.slice(this.mainChartElements * 2, this.mainChartElements * 3); this.doughnutChartData = Object.values(data);
// this.chartData[2].data = data.data.slice(0, this.mainChartElements); console.log(this.chartData);
// this.chartData[1].data = data.data.slice(this.mainChartElements, this.mainChartElements * 2); // setTimeout is currently a workaround for ng2-charts labels
// this.chartData[0].data = data.data.slice(this.mainChartElements * 2, this.mainChartElements * 3); setTimeout(() => this.doughnutChartLabels = Object.keys(data), 0);
// } console.log(this.chartLabels);
}
// convert Hex to RGBA // convert Hex to RGBA
public convertHex(hex: string, opacity: number) { public convertHex(hex: string, opacity: number) {

View file

@ -0,0 +1,14 @@
import { Injectable } from '@angular/core';
import { ApiService } from './api-service';
import { Observable } from 'rxjs/Rx';
@Injectable()
export class CustPiesService {
private custPieUrl = '/v1/customer/pies';
constructor(private api: ApiService) { }
public getPie(): Observable<any> {
return this.api.post(this.custPieUrl);
}
}

View file

@ -35,12 +35,21 @@ export class GraphWidget implements OnInit {
maintainAspectRatio: false, maintainAspectRatio: false,
scales: { scales: {
xAxes: [{ xAxes: [{
type: 'time',
time: {
unit: 'day',
displayFormats: {
day: 'MMM D',
},
tooltipFormat: 'MMM D',
},
gridLines: { gridLines: {
color: 'transparent', color: 'transparent',
zeroLineColor: 'transparent' zeroLineColor: 'transparent'
}, },
ticks: { ticks: {
fontSize: 2, fontSize: 2,
source: 'data',
fontColor: 'transparent', fontColor: 'transparent',
} }
@ -106,6 +115,12 @@ export class GraphWidget implements OnInit {
private setData(data: any) { private setData(data: any) {
this.setChartData(data.data); this.setChartData(data.data);
this.setChartLabels(data.labels); this.setChartLabels(data.labels);
this.setChartBounds(data.bounds);
}
private setChartBounds(data) {
this.lineChartOptions.scales.xAxes[0].time.max = data.max;
this.lineChartOptions.scales.xAxes[0].time.min = data.min;
} }
private setChartData(data: Array<number>) { private setChartData(data: Array<number>) {