refactor gauge component using angular way,remove jquery

Signed-off-by: Meina Zhou <meinaz@vmware.com>
This commit is contained in:
Meina Zhou 2018-10-10 10:44:20 +08:00
parent d1981d23b1
commit 081921cf89
5 changed files with 230 additions and 294 deletions

View File

@ -7728,12 +7728,6 @@
"integrity": "sha1-43zwsX8ZnM4jvqcbIDk5Uka07E4=", "integrity": "sha1-43zwsX8ZnM4jvqcbIDk5Uka07E4=",
"dev": true "dev": true
}, },
"jquery": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.3.1.tgz",
"integrity": "sha512-Ubldcmxp5np52/ENotGxlLe6aGMvmF4R8S6tZjsP6Knsaxd/xp3Zrh50cG93lR6nPXyUFwzN3ZSOQI0wRJNdGg==",
"dev": true
},
"js-base64": { "js-base64": {
"version": "2.4.8", "version": "2.4.8",
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.4.8.tgz", "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.4.8.tgz",

View File

@ -15,7 +15,8 @@
"build_lib": "ng build --prod lib", "build_lib": "ng build --prod lib",
"npm_pack": "cd lib/dist && npm pack", "npm_pack": "cd lib/dist && npm pack",
"package": "npm run build_lib && npm run npm_pack", "package": "npm run build_lib && npm run npm_pack",
"link_lib": "cd lib/dist && npm link && cd ../../ && npm link @harbor/ui" "link_lib": "cd lib/dist && npm link && cd ../../ && npm link @harbor/ui",
"build_all":"npm run build_lib && npm run link_lib && npm run build"
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {
@ -63,7 +64,6 @@
"enhanced-resolve": "^3.0.0", "enhanced-resolve": "^3.0.0",
"jasmine-core": "~2.99.1", "jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1", "jasmine-spec-reporter": "~4.2.1",
"jquery": "^3.3.1",
"karma": "~1.7.1", "karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0", "karma-chrome-launcher": "~2.2.0",
"karma-cli": "^1.0.1", "karma-cli": "^1.0.1",

View File

@ -1,8 +1,8 @@
<div class="{{sizeClass}}"> <div class="{{sizeClass}}">
<div class="esxc-gauge-container esxc-gauge"> <div class="esxc-gauge-container esxc-gauge">
<div class="esxc-gauge-circle-bg"></div> <div class="esxc-gauge-circle-bg"></div>
<div #barOne class="esxc-gauge-circle-fill esxc-gauge-bar-one"></div> <div #barOne [style.transform]="'rotate(' + posOne + 'deg)'" [style.background-color]="_colorOne" [style.transition]="transition" class="esxc-gauge-circle-fill esxc-gauge-bar-one"></div>
<div #barTwo class="esxc-gauge-circle-fill esxc-gauge-bar-two"></div> <div #barTwo [style.transform]="'rotate(' + posTwo + 'deg)'" [style.background-color]="_colorTwo" [style.transition]="transition" class="esxc-gauge-circle-fill esxc-gauge-bar-two"></div>
<div class="esxc-gauge-circle-inner" [ngStyle]="{'background-color': backgroundColor}"> <div class="esxc-gauge-circle-inner" [ngStyle]="{'background-color': backgroundColor}">
<div class="esxc-gauge-circle-caption"> <div class="esxc-gauge-circle-caption">
<span class="esxc-value">{{used}}</span> <span class="esxc-value">{{used}}</span>

View File

@ -52,239 +52,245 @@
* Small size gauge sizing * Small size gauge sizing
*/ */
.esxc-gauge-small .esxc-gauge-container { .esxc-gauge-small {
width: 60px; .esxc-gauge-container {
height: 30px; width: 60px;
top: -8px; height: 30px;
left: 4px; top: -8px;
left: 4px;
}
.esxc-gauge-circle-fill {
height: 60px;
border-radius: 30px;
clip: rect(30px, 60px, 60px, 0);
}
.esxc-gauge-circle-bg {
height: 60px;
border-radius: 30px;
}
.esxc-gauge-circle-inner {
width: 50px;
height: 50px;
border-radius: 25px;
margin: 5px;
}
.esxc-gauge-circle-caption {
margin-top: 6px;
}
/*Small size*/
.esxc-gauge-circle-caption .esxc-value {
font-size: 16px;
font-weight: 600;
}
.esxc-gauge-circle-caption .esxc-unit {
font-size: 10px;
}
.esxc-gauge-circle-caption .esxc-loading {
font-size: 10px;
}
.esxc-title {
font-size: 10px;
text-align: center;
margin-top: 3px;
position: relative;
bottom: 12px;
}
.esxc-title .esxc-bar-title {
float: left;
text-align: right;
width: 70px;
margin-top: 0;
}
.esxc-limit {
text-align: center;
position: relative;
top: -8px;
width: 70px;
}
.esxc-limit .esxc-value {
font-size: 8px;
}
.esxc-limit .esxc-unit {
font-size: 8px;
}
.esxc-limit .esxc-label {
font-size: 8px;
}
.esxc-limit .esxc-bar-limit {
text-align: right;
}
} }
.esxc-gauge-small .esxc-gauge-circle-fill {
height: 60px;
border-radius: 30px;
clip: rect(30px, 60px, 60px, 0);
}
.esxc-gauge-small .esxc-gauge-circle-bg {
height: 60px;
border-radius: 30px;
}
.esxc-gauge-small .esxc-gauge-circle-inner {
width: 50px;
height: 50px;
border-radius: 25px;
margin: 5px;
}
.esxc-gauge-small .esxc-gauge-circle-caption {
margin-top: 6px;
}
/* /*
* Medium size gauge sizing * Medium size gauge sizing
*/ */
.esxc-gauge-medium {
.esxc-gauge-container {
width: 130px;
height: 65px;
}
.esxc-gauge-circle-fill {
height: 130px;
border-radius: 130px;
clip: rect(65px, 130px, 130px, 0);
}
.esxc-gauge-circle-bg {
height: 130px;
border-radius: 65px;
}
.esxc-gauge-circle-inner {
height: 120px;
width: 120px;
border-radius: 60px;
margin: 5px;
}
.esxc-gauge-medium .esxc-gauge-container { /*medium size*/
width: 130px;
height: 65px;
}
.esxc-gauge-medium .esxc-gauge-circle-fill { .esxc-gauge-circle-caption {
height: 130px; margin-top: 40px;
border-radius: 130px; color: #000;
clip: rect(65px, 130px, 130px, 0); }
}
.esxc-gauge-medium .esxc-gauge-circle-bg { .esxc-gauge-circle-caption .esxc-value {
height: 130px; font-size: 22px;
border-radius: 65px; }
}
.esxc-gauge-circle-caption .esxc-unit {
font-size: 14px;
}
.esxc-gauge-circle-caption .esxc-loading {
font-size: 25px;
}
.esxc-limit {
text-align: center;
color: #565656;
}
.esxc-limit .esxc-value {
font-size: 12px;
}
.esxc-limit .esxc-unit {
font-size: 12px;
}
.esxc-limit .esxc-label {
font-size: 12px;
}
.esxc-title {
font-size: 13px;
font-weight: 600;
color: #565656;
text-align: center;
margin-top: -8px;
}
}
.esxc-gauge-medium .esxc-gauge-circle-inner {
height: 120px;
width: 120px;
border-radius: 60px;
margin: 5px;
}
/* /*
* Large size gauge sizing * Large size gauge sizing
*/ */
.esxc-gauge-large .esxc-gauge-container { .esxc-gauge-large {
width: 260px; .esxc-gauge-container {
height: 130px; width: 260px;
} height: 130px;
}
.esxc-gauge-circle-fill {
height: 260px;
border-radius: 130px;
clip: rect(130px, 260px, 260px, 0);
}
.esxc-gauge-circle-bg {
height: 260px;
border-radius: 130px;
}
.esxc-gauge-circle-inner {
width: 240px;
height: 240px;
border-radius: 120px;
margin: 10px;
}
.esxc-gauge-circle-caption {
margin-top: 95px;
}
.esxc-gauge-large .esxc-gauge-circle-fill { /*large size*/
height: 260px;
border-radius: 130px;
clip: rect(130px, 260px, 260px, 0);
}
.esxc-gauge-large .esxc-gauge-circle-bg { .esxc-gauge-circle-caption .esxc-value {
height: 260px; font-size: 40px;
border-radius: 130px; }
}
.esxc-gauge-large .esxc-gauge-circle-inner { .esxc-gauge-circle-caption .esxc-unit {
width: 240px; font-size: 18px;
height: 240px; }
border-radius: 120px;
margin: 10px;
}
.esxc-gauge-large .esxc-gauge-circle-caption { .esxc-gauge-circle-caption .esxc-loading {
margin-top: 95px; font-size: 30px;
} }
/*Sall size*/ .esxc-limit {
text-align: center;
margin-top: 4px;
}
.esxc-gauge-small .esxc-gauge-circle-caption .esxc-value { .esxc-limit .esxc-value {
font-size: 16px; font-size: 14px;
font-weight: 600; color: #565656;
} line-height: 18px;
}
.esxc-gauge-small .esxc-gauge-circle-caption .esxc-unit { .esxc-limit .esxc-unit {
font-size: 10px; font-size: 14px;
} }
.esxc-gauge-small .esxc-gauge-circle-caption .esxc-loading { .esxc-limit .esxc-label {
font-size: 10px; font-size: 14px;
} }
.esxc-gauge-small .esxc-title { .esxc-limit .esxc-bar-limit {
font-size: 10px; text-align: right;
text-align: center; }
margin-top: 3px;
position: relative;
bottom: 12px;
}
.esxc-gauge-small .esxc-title .esxc-bar-title { .esxc-title {
float: left; font-size: 18px;
text-align: right; font-weight: 600;
width: 70px; color: #565656;
margin-top: 0; line-height: 18px;
} text-align: center;
margin-top: -2px;
.esxc-gauge-small .esxc-limit { .esxc-bar-title {
text-align: center; float: left;
position: relative; text-align: right;
top: -8px; width: 70px;
width: 70px; margin-top: 0;
} }
}
.esxc-gauge-small .esxc-limit .esxc-value { }
font-size: 8px;
}
.esxc-gauge-small .esxc-limit .esxc-unit {
font-size: 8px;
}
.esxc-gauge-small .esxc-limit .esxc-label {
font-size: 8px;
}
.esxc-gauge-small .esxc-limit .esxc-bar-limit {
text-align: right;
}
/*medium size*/
.esxc-gauge-medium .esxc-gauge-circle-caption {
margin-top: 40px;
color: #000;
}
.esxc-gauge-medium .esxc-gauge-circle-caption .esxc-value {
font-size: 22px;
}
.esxc-gauge-medium .esxc-gauge-circle-caption .esxc-unit {
font-size: 14px;
}
.esxc-gauge-medium .esxc-gauge-circle-caption .esxc-loading {
font-size: 25px;
}
.esxc-gauge-medium .esxc-limit {
text-align: center;
color: #565656;
}
.esxc-gauge-medium .esxc-limit .esxc-value {
font-size: 12px;
}
.esxc-gauge-medium .esxc-limit .esxc-unit {
font-size: 12px;
}
.esxc-gauge-medium .esxc-limit .esxc-label {
font-size: 12px;
}
.esxc-gauge-medium .esxc-title {
font-size: 13px;
font-weight: 600;
color: #565656;
text-align: center;
margin-top: -8px;
}
/*large size*/
.esxc-gauge-large .esxc-gauge-circle-caption .esxc-value {
font-size: 40px;
}
.esxc-gauge-large .esxc-gauge-circle-caption .esxc-unit {
font-size: 18px;
}
.esxc-gauge-large .esxc-gauge-circle-caption .esxc-loading {
font-size: 30px;
}
.esxc-gauge-large .esxc-limit {
text-align: center;
margin-top: 4px;
}
.esxc-gauge-large .esxc-limit .esxc-value {
font-size: 14px;
color: #565656;
line-height: 18px;
}
.esxc-gauge-large .esxc-limit .esxc-unit {
font-size: 14px;
}
.esxc-gauge-large .esxc-limit .esxc-label {
font-size: 14px;
}
.esxc-gauge-large .esxc-limit .esxc-bar-limit {
text-align: right;
}
.esxc-gauge-large .esxc-title {
font-size: 18px;
font-weight: 600;
color: #565656;
line-height: 18px;
text-align: center;
margin-top: -2px;
}
.esxc-gauge-large .esxc-title .esxc-bar-title {
float: left;
text-align: right;
width: 70px;
margin-top: 0;
}

View File

@ -19,8 +19,6 @@ import {
ElementRef ElementRef
} from '@angular/core'; } from '@angular/core';
import * as $ from 'jquery';
const RESOURCE_COLOR_GREEN_NORMAL: string = '#5DB700'; const RESOURCE_COLOR_GREEN_NORMAL: string = '#5DB700';
const RESOURCE_COLOR_ORANGE_NORMAL: string = '#FBBF00'; const RESOURCE_COLOR_ORANGE_NORMAL: string = '#FBBF00';
const RESOURCE_COLOR_RED_NORMAL: string = '#EA400D'; const RESOURCE_COLOR_RED_NORMAL: string = '#EA400D';
@ -43,6 +41,9 @@ export class GaugeComponent implements AfterViewInit {
_title: string = "UNKNOWN"; // Lang key _title: string = "UNKNOWN"; // Lang key
_free: number = 0; _free: number = 0;
_threasHold: number = 0; _threasHold: number = 0;
posOne = 0;
posTwo = 0;
transition = '';
/** /**
* Background color of the component. Default is white. * Background color of the component. Default is white.
@ -195,7 +196,6 @@ export class GaugeComponent implements AfterViewInit {
this._positionOne = percent; this._positionOne = percent;
this.setBars(); this.setBars();
this.setColors();
this.setAnimate(); this.setAnimate();
} }
@ -204,58 +204,12 @@ export class GaugeComponent implements AfterViewInit {
return; return;
} }
let barOne = $(this.barOne.nativeElement);
let barTwo = $(this.barTwo.nativeElement);
if (!barOne || !barTwo) {
return;
}
let posOne, posTwo;
if (isNaN(this.positionOne)) { if (isNaN(this.positionOne)) {
posOne = posTwo = 0; this.posOne = this.posTwo = 0;
} else { } else {
posOne = (this.positionOne / 100) * 180; this.posOne = (this.positionOne / 100) * 180;
posTwo = (this.positionTwo / 100) * 180; this.posTwo = (this.positionTwo / 100) * 180;
} }
barOne.css({
'-webkit-transform': 'rotate(' + posOne + 'deg)',
'-moz-transform': 'rotate(' + posOne + 'deg)',
'-ms-transform': 'rotate(' + posOne + 'deg)',
'-o-transform': 'rotate(' + posOne + 'deg)',
'transform': 'rotate(' + posOne + 'deg)'
});
barTwo.css({
'-webkit-transform': 'rotate(' + posTwo + 'deg)',
'-moz-transform': 'rotate(' + posTwo + 'deg)',
'-ms-transform': 'rotate(' + posTwo + 'deg)',
'-o-transform': 'rotate(' + posTwo + 'deg)',
'transform': 'rotate(' + posTwo + 'deg)'
});
}
setColors() {
if (!this.barOne || !this.barTwo) {
return;
}
let barOne = $(this.barOne.nativeElement);
let barTwo = $(this.barTwo.nativeElement);
if (!barOne || !barTwo) {
return;
}
barOne.css({
'background-color': this._colorOne
});
barTwo.css({
'background-color': this._colorTwo
});
} }
setAnimate() { setAnimate() {
@ -263,29 +217,11 @@ export class GaugeComponent implements AfterViewInit {
return; return;
} }
let barOne = $(this.barOne.nativeElement);
let barTwo = $(this.barTwo.nativeElement);
if (!barOne || !barTwo) {
return;
}
let transition = 'transform 1s ease';
let prefixes = ['webkit', 'moz', 'ms', 'o'];
let css = {
'transition': transition
};
if (!this._animate) { if (!this._animate) {
transition = 'none'; this.transition = 'none';
} else {
this.transition = 'transform 1s ease';
} }
for (let prefix of prefixes) {
css['-' + prefix + '-transition'] = transition;
}
barOne.css(css);
barTwo.css(css);
} }
} }