Skip to content

Commit

Permalink
Merge pull request #210 from BennieMeng/feature/node-resource-usage
Browse files Browse the repository at this point in the history
node resource usage ui optimize
  • Loading branch information
wilhelmguo committed Jan 11, 2019
2 parents b03c5bd + ec0c5ff commit 4f65055
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,8 @@
</svg>
</div>
<div class="box" *ngIf="showView">
<div class="nodeSummary">
<h3>Node 使用概况</h3>
<p>
<span>Ready:</span>
<span>{{node.ready}}</span>
</p>
<p>
<span>可调度:</span>
<span>{{node.schedulable}}</span>
</p>
<p>
<span>总量:</span>
<span>{{node.total}}</span>
</p>
</div>
<echarts-gauge style="height: 250px; width: 250px;" [title]="cpu.title" [data]="cpu.data" [name]="cpu.name" [max]="cpu.max"></echarts-gauge>
<echarts-gauge style="height: 250px; width: 250px;" [title]="memory.title" [data]="memory.data" [name]="cpu.name" [max]="memory.max"></echarts-gauge>
<echarts-gauge style="height: 250px; width: 250px;" [title]="ready.title" [data]="ready.data" [name]="ready.name" type="percent" [tooltip]="ready.tooltip"></echarts-gauge>
<echarts-gauge style="height: 250px; width: 250px;" [title]="schedulable.title" [data]="schedulable.data" [name]="schedulable.name" type="percent" [tooltip]="schedulable.tooltip"></echarts-gauge>
<echarts-gauge style="height: 250px; width: 250px;" [title]="cpu.title" [data]="cpu.data" [name]="cpu.name" type="percent" [tooltip]="cpu.tooltip"></echarts-gauge>
<echarts-gauge style="height: 250px; width: 250px;" [title]="memory.title" [data]="memory.data" [name]="cpu.name" type="percent" [tooltip]="memory.tooltip"></echarts-gauge>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
display: flex;
justify-content: space-around;
flex-wrap: wrap;
height: 200px;
align-items: center;
& > * {
transform: scale(.8);
}
}
:host{
display: block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,43 @@ export class NodeResourceComponent implements OnInit {
}
}
showView = GlobalState.node.showResource;
ready = {
title: 'Node 就绪',
name: '使用量',
tooltip: '',
data: []
};
schedulable = {
title: 'Node 可调度',
name: '可调度',
tooltip: '',
data: []
};
cpu = {
title: 'CPU 使用概况',
title: 'CPU 使用',
name: '使用量',
max: 0,
tooltip: '',
data: []
};
memory = {
title: 'Memory 使用概况',
title: 'Memory 使用',
name: '使用量',
max: 0,
tooltip: '',
data: []
};
node = {
total: 0,
ready: 0,
schedulable: 0
};
setCpu(cpuSummary: Summary) {
this.cpu.max = cpuSummary.Total;
this.cpu.data = [cpuSummary.Used];
this.cpu.tooltip = `usage/total: ${cpuSummary.Used}/${cpuSummary.Total}`;
this.cpu.data = [parseInt((cpuSummary.Used / cpuSummary.Total) * 100 + '', 10)];
}
setMemory(memorySummary: Summary) {
this.memory.max = memorySummary.Total;
this.memory.data = [memorySummary.Used];
this.memory.tooltip = `usage/total: ${memorySummary.Used}/${memorySummary.Total}`;
this.memory.data = [parseInt((memorySummary.Used / memorySummary.Total) * 100 + '', 10)];
}
setNode(nodeSummary: NodeSummary) {
this.node.total = nodeSummary.Total;
this.node.ready = nodeSummary.Ready;
this.node.schedulable = nodeSummary.Schedulable;
this.ready.tooltip = `Ready/total: ${nodeSummary.Ready}/${nodeSummary.Total}`;
this.ready.data = [parseInt((nodeSummary.Ready / nodeSummary.Total) * 100 + '', 10)];
this.schedulable.tooltip = `可调度/total: ${nodeSummary.Schedulable}/${nodeSummary.Total}`;
this.schedulable.data = [parseInt((nodeSummary.Schedulable / nodeSummary.Total) * 100 + '', 10)];
}
changeShow() {
this.showView = !this.showView;
Expand Down
9 changes: 6 additions & 3 deletions src/frontend/src/app/shared/echarts/echars.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { NgModule } from '@angular/core';
import { EcharsGaugeComponent } from './gauge/gauge.component';
import { EchartsGaugeComponent } from './gauge/gauge.component';
import { EchartsPieComponent } from './pie/pie.component';
@NgModule({
imports: [],
exports: [
EcharsGaugeComponent
EchartsGaugeComponent,
EchartsPieComponent
],
declarations: [
EcharsGaugeComponent
EchartsGaugeComponent,
EchartsPieComponent
]
})
export class EchartsModule { }
15 changes: 11 additions & 4 deletions src/frontend/src/app/shared/echarts/gauge/gauge.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import EChartOption = echarts.EChartOption;
styleUrls: ['./gauge.component.scss']
})

export class EcharsGaugeComponent implements AfterViewInit {
export class EchartsGaugeComponent implements AfterViewInit {
/**
* 可传参数:
* save: saveAsImage, 默认不打开
Expand All @@ -23,12 +23,14 @@ export class EcharsGaugeComponent implements AfterViewInit {
* data: number[] 数值
* min: number 起点,默认为0
* max: number 当 type 不是 percent 时候,传入max
* tooltip 定制化的tip显示
*/
_title: string;
_save: boolean;
_name: string;
_type: string;
_data: number[];
_tooltip: string;
_min = 0;
_max = 100;
@ViewChild('view') view;
Expand Down Expand Up @@ -69,6 +71,11 @@ export class EcharsGaugeComponent implements AfterViewInit {
this._max = value || 100;
this.initOption();
}
@Input('tooltip')
set tooltip(value: string) {
this._tooltip = value;
this.initOption();
}

get chartData(): Data[] {
return this._data.map(item => {
Expand All @@ -93,7 +100,7 @@ export class EcharsGaugeComponent implements AfterViewInit {
}
},
tooltip: {
formatter: this.type === 'percent' ? '{b} : {c}%' : '{b} : {c}'
formatter: this._tooltip ? this._tooltip : this._type === 'percent' ? '{b} : {c}%' : '{b} : {c}'
},
toolbox: {
feature: {
Expand All @@ -114,9 +121,9 @@ export class EcharsGaugeComponent implements AfterViewInit {
}
},
detail: {
formatter: this.type === 'percent' ? '{value}%' : '{value}',
formatter: this._type === 'percent' ? '{value}%' : '{value}',
textStyle: {
fontSize: 20,
fontSize: 18,
color: 'auto'
}
},
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/app/shared/echarts/pie/pie.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div #view class="box"></div>
8 changes: 8 additions & 0 deletions src/frontend/src/app/shared/echarts/pie/pie.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:host {
height:300px;
width: 300px;
}
.box{
width: 100%;
height: 100%;
}
82 changes: 82 additions & 0 deletions src/frontend/src/app/shared/echarts/pie/pie.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Component, ViewChild, AfterViewInit, Input } from '@angular/core';
import * as echarts from 'echarts';
import ECharts = echarts.ECharts;
import EChartOption = echarts.EChartOption;
import { Data } from './pie';

@Component({
selector: 'echarts-pie',
templateUrl: './pie.component.html',
styleUrls: ['./pie.component.scss']
})
export class EchartsPieComponent implements AfterViewInit {
@ViewChild('view') view;
chart: ECharts;
_title: string;
_data: Data[];
@Input('title')
set title(value) {
this._title = value;
this.initOption();
}
@Input('data')
set data(value: Data[]) {
this._data = value;
this.initOption();
}
get option() {
const option = {
title: {
text: this._title,
left: 'center',
top: '15px',
textStyle: {
color: '#333',
fontSize: 20,
letterSpacing: '2px'
}
},
tooltip: {
trigger: 'item',
formatter: '{b} : {c} ({d}%)'
},
toolbox: {
show: true,
feature: {
}
},
calculable: false,
series: []
};
option.series = this._data.map((item, index) => {
return {
center: ['50%', '60%'],
name: item.title,
type: 'pie',
selectedMode: 'single',
radius: index ? [55 + 15 * index, 75 + 15 * index] : [0, 55],
itemStyle: {
normal: {
label: {
position: 'inner'
},
labelLine: {
show: false
}
}
},
data: item.data
};
});
return option;
}
ngAfterViewInit() {
this.chart = echarts.init(this.view.nativeElement);
this.chart.setOption(this.option, true);
}
initOption() {
if (this.chart) {
this.chart.setOption(this.option, true);
}
}
}
9 changes: 9 additions & 0 deletions src/frontend/src/app/shared/echarts/pie/pie.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface Data {
title: string;
data: PieData[];
}

interface PieData {
name: string;
value: number;
}

0 comments on commit 4f65055

Please sign in to comment.