import * as i0 from '@angular/core'; import { EventEmitter, Component, Input, Output, InjectionToken, NgModule } from '@angular/core'; import Gauge from 'svg-gauge'; class GaugeDefaults { constructor() { /** * The angle in degrees to start the dial */ this.dialStartAngle = 135; /** * The angle in degrees to end the dial. This MUST be less than dialStartAngle */ this.dialEndAngle = 45; /** * The radius of the gauge */ this.dialRadius = 40; /** * The minimum value for the gauge */ this.min = 0; /** * The maximum value for the gauge */ this.max = 100; /** * Whether to show the value at the center of the gauge */ this.showValue = true; /** * The CSS class of the gauge */ this.gaugeClass = 'gauge'; /** * The CSS class of the gauge's dial */ this.dialClass = 'dial'; /** * The CSS class of the gauge's fill (value dial) */ this.valueDialClass = 'value'; /** * The CSS class of the gauge's text */ this.valueClass = 'value-text'; /** * Whether to animate changing the gauge */ this.animated = false; } } class GaugeComponent { constructor(elm, defaults) { this.elm = elm; this.defaults = defaults; /** * Called when the gauge is created */ this.gaugeCreated = new EventEmitter(); } ngAfterViewInit() { const options = { dialStartAngle: this.dialStartAngle, dialEndAngle: this.dialEndAngle, dialRadius: this.dialRadius, min: this.min, max: this.max, label: this.label, showValue: this.showValue, gaugeClass: this.gaugeClass, dialClass: this.dialClass, valueDialClass: this.valueDialClass, valueClass: this.valueClass, value: this.value, color: this.color, }; Object.keys(this.defaults).forEach((optionKey) => { const key = optionKey; if (options[key] == null) { options[key] = this.defaults[key]; } }); Object.keys(options).forEach((optionKey) => { const key = optionKey; if (options[key] == null) { delete options[key]; } }); this.gauge = Gauge(this.elm.nativeElement, options); this.gaugeCreated.emit({ gauge: this.gauge }); this.updateValue(); } ngOnChanges(changes) { if (changes['value']) { this.updateValue(); } } updateValue() { if (this.gauge) { if (this.animated) { this.gauge.setValueAnimated(this.value, this.animationDuration); } else { this.gauge.setValue(this.value); } } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: GaugeComponent, deps: [{ token: i0.ElementRef }, { token: GaugeDefaults }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.0.1", type: GaugeComponent, selector: "mwl-gauge", inputs: { dialStartAngle: "dialStartAngle", dialEndAngle: "dialEndAngle", dialRadius: "dialRadius", min: "min", max: "max", label: "label", color: "color", showValue: "showValue", gaugeClass: "gaugeClass", dialClass: "dialClass", valueDialClass: "valueDialClass", valueClass: "valueClass", value: "value", animated: "animated", animationDuration: "animationDuration" }, outputs: { gaugeCreated: "gaugeCreated" }, usesOnChanges: true, ngImport: i0, template: '', isInline: true }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: GaugeComponent, decorators: [{ type: Component, args: [{ selector: 'mwl-gauge', template: '', }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: GaugeDefaults }]; }, propDecorators: { dialStartAngle: [{ type: Input }], dialEndAngle: [{ type: Input }], dialRadius: [{ type: Input }], min: [{ type: Input }], max: [{ type: Input }], label: [{ type: Input }], color: [{ type: Input }], showValue: [{ type: Input }], gaugeClass: [{ type: Input }], dialClass: [{ type: Input }], valueDialClass: [{ type: Input }], valueClass: [{ type: Input }], value: [{ type: Input }], animated: [{ type: Input }], animationDuration: [{ type: Input }], gaugeCreated: [{ type: Output }] } }); const USER_DEFAULTS = new InjectionToken('gauge defaults'); class GaugeModule { static forRoot(userDefaults = {}) { return { ngModule: GaugeModule, providers: [ { provide: USER_DEFAULTS, useValue: userDefaults, }, { provide: GaugeDefaults, useFactory: (options) => { const defaults = new GaugeDefaults(); Object.assign(defaults, options); return defaults; }, deps: [USER_DEFAULTS], }, ], }; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: GaugeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.0.1", ngImport: i0, type: GaugeModule, declarations: [GaugeComponent], exports: [GaugeComponent] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: GaugeModule }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: GaugeModule, decorators: [{ type: NgModule, args: [{ declarations: [GaugeComponent], imports: [], exports: [GaugeComponent], }] }] }); /* * Public API Surface of angular-gauge */ /** * Generated bundle index. Do not edit. */ export { GaugeComponent, GaugeModule, USER_DEFAULTS }; //# sourceMappingURL=angular-gauge.mjs.map