• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atinc / ngx-tethys / 3033f133-0f0d-43eb-a07d-e1848354018a

07 Mar 2024 01:58AM UTC coverage: 90.58% (-0.02%) from 90.604%
3033f133-0f0d-43eb-a07d-e1848354018a

Pull #3022

circleci

web-flow
feat(schematics): improve schematics for select and custom-select in template #INFR-11735 (#3047)
Pull Request #3022: feat: upgrade ng to 17 #INFR-11427 (#3021)

5422 of 6642 branches covered (81.63%)

Branch coverage included in aggregate %.

328 of 338 new or added lines in 193 files covered. (97.04%)

141 existing lines in 29 files now uncovered.

13502 of 14250 relevant lines covered (94.75%)

982.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.78
/src/progress/progress.component.ts
1
import { helpers, isNumber } from 'ngx-tethys/util';
2

3
import {
4
    ChangeDetectionStrategy,
5
    Component,
6
    HostBinding,
7
    Input,
8
    OnChanges,
9
    OnInit,
10
    QueryList,
11
    SimpleChanges,
12
    TemplateRef,
13
    ViewChildren,
14
    ViewEncapsulation
15
} from '@angular/core';
1✔
16
import { useHostRenderer } from '@tethys/cdk/dom';
17

28✔
18
import { ThyProgressGapPositionType, ThyProgressShapeType, ThyProgressStackedValue, ThyProgressType } from './interfaces';
19
import { THY_PROGRESS_COMPONENT, ThyParentProgress, ThyProgressStrip } from './progress-strip.component';
20
import { ThyProgressCircle } from './progress-circle.component';
26✔
21
import { ThyTooltipDirective } from 'ngx-tethys/tooltip';
26✔
22
import { NgIf, NgFor, NgClass, NgTemplateOutlet } from '@angular/common';
23
import { InputNumber } from 'ngx-tethys/core';
24

25
/**
31✔
26
 * 进度条组件
13✔
27
 * @name thy-progress
29✔
28
 */
13✔
29
@Component({
27✔
30
    selector: 'thy-progress',
31
    templateUrl: './progress.component.html',
13✔
32
    changeDetection: ChangeDetectionStrategy.OnPush,
33
    encapsulation: ViewEncapsulation.None,
34
    providers: [
18✔
35
        {
36
            provide: THY_PROGRESS_COMPONENT,
37
            useExisting: ThyProgress
38
        }
7✔
39
    ],
7✔
40
    host: {
41
        class: `thy-progress progress`,
42
        '[class.thy-progress-strip]': `thyShape === 'strip'`,
28✔
43
        '[class.thy-progress-circle]': `thyShape === 'circle'`
28✔
44
    },
28✔
45
    standalone: true,
28✔
46
    imports: [NgIf, NgFor, ThyProgressStrip, NgClass, ThyTooltipDirective, NgTemplateOutlet, ThyProgressCircle]
28✔
47
})
28✔
48
export class ThyProgress implements ThyParentProgress, OnInit, OnChanges {
28✔
49
    value: number | ThyProgressStackedValue[];
28✔
50

51
    bars: ThyProgressStrip[] = [];
52

53
    barsTotalValue: number;
54

20✔
55
    private settedMax: number;
13✔
56

57
    private hostRenderer = useHostRenderer();
58

7✔
59
    @HostBinding('attr.max') max = 100;
60

20✔
61
    @HostBinding(`class.progress-stacked`) isStacked = false;
2✔
62

63
    @ViewChildren(ThyProgressStrip)
20✔
64
    set barsQueryList(value: QueryList<ThyProgressStrip>) {
5✔
65
        this.bars = value.toArray();
66
    }
67

UNCOV
68
    /**
×
69
     * 进度条类型: `primary` | `success` | `info` | `warning` | `danger`
70
     */
1✔
71
    @Input() thyType: ThyProgressType = 'primary';
1✔
72

73
    /**
74
     * 进度条大小
75
     * @type xs | sm | md
76
     * @default md
77
     */
78
    @Input() set thySize(size: string | number) {
79
        this.size = size;
80
        this.hostRenderer.updateClass(size ? [`progress-${size}`] : []);
81
    }
82

83
    /**
84
     * 进度值,传入数字时显示百分比 = value / max * 100,当传入数组时显示多个 bar,stacked 模式的进度条
85
     * @type number | ThyProgressStackedValue[]
86
     */
1✔
87
    @Input() set thyValue(value: number | ThyProgressStackedValue[]) {
88
        // 自动求和计算 max
89
        if (Array.isArray(value)) {
90
            this.isStacked = true;
91
            this.value = [...value].filter(item => item.value !== 0);
1✔
92
            this.barsTotalValue = this.value.reduce((total, item) => {
93
                return total + item.value;
94
            }, 0);
95
            this.calculateMax();
1✔
96
        } else {
97
            this.value = value;
98
        }
99
    }
1✔
100

101
    /**
102
     * 最大值,主要计算百分比进度的分母使用,当 thyValue 传入数组时,自动累加数组中的 value 之和为 max
103
     */
104
    @Input()
105
    @InputNumber()
106
    set thyMax(max: number) {
107
        this.settedMax = helpers.coerceNumberValue(max);
108
        this.calculateMax();
109
    }
110

111
    /**
112
     * 鼠标移入进度条时显示的提示文案或者模板
113
     */
114
    @Input() thyTips: string | TemplateRef<unknown>;
115

116
    /**
117
     * 进度形状
118
     * @type strip | circle
119
     */
120
    @Input() thyShape: ThyProgressShapeType = 'strip';
121

122
    /**
123
     * 圆形进度条缺口角度,可取值 0 ~ 360
124
     */
125
    @Input() @InputNumber() thyGapDegree?: number = undefined;
126

127
    /**
128
     * 圆形进度条缺口位置
129
     * @type top | bottom | left | right
130
     */
131
    @Input() thyGapPosition: ThyProgressGapPositionType = 'top';
132

133
    /**
134
     *         圆形进度条线的宽度
135
     */
136
    @Input() @InputNumber() thyStrokeWidth: number;
137

138
    size: string | number;
139

140
    constructor() {}
141

142
    ngOnInit() {}
143

144
    ngOnChanges(changes: SimpleChanges): void {}
145

146
    calculateMax() {
147
        if (isNumber(this.settedMax) && this.settedMax > 0) {
148
            this.max = this.settedMax;
149
        } else {
150
            this.max = this.barsTotalValue;
151
        }
152
        if (this.max < this.barsTotalValue) {
153
            this.max = this.barsTotalValue;
154
        }
155
        this.bars.forEach(bar => {
156
            bar.recalculatePercentage();
157
        });
158
    }
159

160
    trackByFn(index: number) {
161
        return index;
162
    }
163
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc