2017-09-20 14:31:06 +03:00
|
|
|
import { AfterViewInit, Component, OnDestroy } from '@angular/core';
|
2017-08-01 17:42:21 +03:00
|
|
|
import { NbThemeService } from '@nebular/theme';
|
2017-07-24 19:10:59 +03:00
|
|
|
|
|
|
|
|
declare const echarts: any;
|
|
|
|
|
|
|
|
|
|
const points = [300, 520, 435, 530, 730, 620, 660, 860];
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'ngx-traffic-chart',
|
|
|
|
|
styleUrls: ['./traffic.component.scss'],
|
|
|
|
|
template: `
|
|
|
|
|
<div echarts [options]="option" class="echart"></div>
|
|
|
|
|
`,
|
|
|
|
|
})
|
2017-09-20 14:31:06 +03:00
|
|
|
export class TrafficChartComponent implements AfterViewInit, OnDestroy {
|
2017-07-24 19:10:59 +03:00
|
|
|
|
2017-10-20 17:31:36 +03:00
|
|
|
type = 'month';
|
2017-07-24 19:10:59 +03:00
|
|
|
types = ['week', 'month', 'year'];
|
|
|
|
|
option: any = {};
|
2017-09-20 14:31:06 +03:00
|
|
|
themeSubscription: any;
|
2017-07-24 19:10:59 +03:00
|
|
|
|
2017-08-01 17:42:21 +03:00
|
|
|
constructor(private theme: NbThemeService) {
|
2017-08-04 15:11:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
2017-09-20 14:31:06 +03:00
|
|
|
this.themeSubscription = this.theme.getJsTheme().delay(1).subscribe(config => {
|
2017-07-24 19:10:59 +03:00
|
|
|
|
2017-08-01 15:42:06 +03:00
|
|
|
const trafficTheme: any = config.variables.traffic;
|
|
|
|
|
|
2017-07-24 19:10:59 +03:00
|
|
|
this.option = Object.assign({}, {
|
|
|
|
|
grid: {
|
|
|
|
|
left: 0,
|
|
|
|
|
top: 0,
|
|
|
|
|
right: 0,
|
|
|
|
|
bottom: 0,
|
|
|
|
|
},
|
|
|
|
|
xAxis: {
|
|
|
|
|
type: 'category',
|
|
|
|
|
boundaryGap: false,
|
|
|
|
|
data: points,
|
|
|
|
|
},
|
|
|
|
|
yAxis: {
|
|
|
|
|
boundaryGap: [0, '5%'],
|
|
|
|
|
axisLine: {
|
|
|
|
|
show: false,
|
|
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
show: false,
|
|
|
|
|
},
|
|
|
|
|
axisTick: {
|
|
|
|
|
show: false,
|
|
|
|
|
},
|
|
|
|
|
splitLine: {
|
|
|
|
|
show: true,
|
|
|
|
|
lineStyle: {
|
2017-08-01 15:42:06 +03:00
|
|
|
color: trafficTheme.colorBlack,
|
2017-07-24 19:10:59 +03:00
|
|
|
opacity: 0.06,
|
|
|
|
|
width: '1',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
tooltip: {
|
|
|
|
|
axisPointer: {
|
|
|
|
|
type: 'shadow',
|
|
|
|
|
},
|
2017-08-07 16:12:38 +03:00
|
|
|
textStyle: {
|
|
|
|
|
color: trafficTheme.tooltipTextColor,
|
2017-09-01 17:18:02 +03:00
|
|
|
fontWeight: trafficTheme.tooltipFontWeight,
|
2017-08-07 16:12:38 +03:00
|
|
|
fontSize: 16,
|
|
|
|
|
},
|
2017-07-24 19:10:59 +03:00
|
|
|
position: 'top',
|
2017-08-01 15:42:06 +03:00
|
|
|
backgroundColor: trafficTheme.tooltipBg,
|
2017-08-07 16:12:38 +03:00
|
|
|
borderColor: trafficTheme.tooltipBorderColor,
|
2017-07-24 19:10:59 +03:00
|
|
|
borderWidth: 3,
|
|
|
|
|
formatter: '{c0} MB',
|
2017-08-07 16:12:38 +03:00
|
|
|
extraCssText: trafficTheme.tooltipExtraCss,
|
2017-07-24 19:10:59 +03:00
|
|
|
},
|
|
|
|
|
series: [
|
|
|
|
|
{
|
|
|
|
|
type: 'line',
|
|
|
|
|
symbol: 'circle',
|
|
|
|
|
symbolSize: 8,
|
|
|
|
|
sampling: 'average',
|
|
|
|
|
silent: true,
|
|
|
|
|
itemStyle: {
|
|
|
|
|
normal: {
|
2017-08-07 16:12:38 +03:00
|
|
|
color: trafficTheme.shadowLineDarkBg,
|
2017-07-24 19:10:59 +03:00
|
|
|
},
|
|
|
|
|
emphasis: {
|
|
|
|
|
color: 'rgba(0,0,0,0)',
|
|
|
|
|
borderColor: 'rgba(0,0,0,0)',
|
|
|
|
|
borderWidth: 0,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
lineStyle: {
|
|
|
|
|
normal: {
|
|
|
|
|
width: 2,
|
2017-08-07 16:12:38 +03:00
|
|
|
color: trafficTheme.shadowLineDarkBg,
|
2017-07-24 19:10:59 +03:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
data: points.map(p => p - 15),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'line',
|
|
|
|
|
symbol: 'circle',
|
|
|
|
|
symbolSize: 6,
|
|
|
|
|
sampling: 'average',
|
|
|
|
|
itemStyle: {
|
|
|
|
|
normal: {
|
2017-08-07 16:12:38 +03:00
|
|
|
color: trafficTheme.itemColor,
|
|
|
|
|
borderColor: trafficTheme.itemBorderColor,
|
2017-07-24 19:10:59 +03:00
|
|
|
borderWidth: 2,
|
|
|
|
|
},
|
|
|
|
|
emphasis: {
|
|
|
|
|
color: 'white',
|
2017-08-07 16:12:38 +03:00
|
|
|
borderColor: trafficTheme.itemEmphasisBorderColor,
|
|
|
|
|
borderWidth: 2,
|
2017-07-24 19:10:59 +03:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
lineStyle: {
|
|
|
|
|
normal: {
|
|
|
|
|
width: 2,
|
2017-08-01 15:42:06 +03:00
|
|
|
color: trafficTheme.lineBg,
|
2017-08-07 16:12:38 +03:00
|
|
|
shadowColor: trafficTheme.lineBg,
|
|
|
|
|
shadowBlur: trafficTheme.lineShadowBlur,
|
2017-07-24 19:10:59 +03:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
areaStyle: {
|
|
|
|
|
normal: {
|
|
|
|
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
|
|
|
|
|
offset: 0,
|
2017-08-01 15:42:06 +03:00
|
|
|
color: trafficTheme.gradFrom,
|
2017-07-24 19:10:59 +03:00
|
|
|
}, {
|
|
|
|
|
offset: 1,
|
2017-08-01 15:42:06 +03:00
|
|
|
color: trafficTheme.gradTo,
|
2017-07-24 19:10:59 +03:00
|
|
|
}]),
|
2017-08-10 16:29:51 +03:00
|
|
|
opacity: 1,
|
2017-07-24 19:10:59 +03:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
data: points,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-09-20 14:31:06 +03:00
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
this.themeSubscription.unsubscribe();
|
|
|
|
|
}
|
2017-07-24 19:10:59 +03:00
|
|
|
}
|