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

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

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

0.0
/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid-dimensions.ts
1
import { GridResourceStringsEN, IGridResourceStrings } from '../../core/i18n/grid-resources';
2
import { getCurrentResourceStrings } from '../../core/i18n/resources';
3
import { GridColumnDataType } from '../../data-operations/data-util';
4
import { IPivotDimension } from './pivot-grid.interface';
5
import { PivotUtil } from './pivot-util';
6

7
export interface IPivotDateDimensionOptions {
8
    /** Enables/Disables total value of all periods. */
9
    total?: boolean;
10
    /** Enables/Disables dimensions per year from provided periods. */
11
    years?: boolean;
12
    /*/** Enables/Disables dimensions per quarter from provided periods. */
13
    quarters?: boolean;
14
    /** Enables/Disables dimensions per month from provided periods. */
15
    months?: boolean;
16
    /** Enabled/Disables dimensions for the full date provided */
17
    fullDate?: boolean;
18
}
19

20
/* blazorAlternateBaseType: PivotDimension */
21
/* alternateBaseType: PivotDimension */
22
// Equals to pretty much this configuration:
23
// {
24
//     member: () => 'All Periods',
25
//     enabled: true,
26
//     fieldName: 'AllPeriods',
27
//     childLevel: {
28
//         fieldName: 'Years',
29
//         member: (rec) => {
30
//             const recordValue = rec['Date'];
31
//             return recordValue ? (new Date(recordValue)).getFullYear().toString() : rec['Years'];
32
//         },
33
//         enabled: true,
34
//         childLevel: {
35
//                 member: (rec) => {
36
//                     const recordValue = rec['Date'];
37
//                     return recordValue ? new Date(recordValue).toLocaleString('default', { month: 'long' }) : rec['Months'];
38
//                 },
39
//                 enabled: true,
40
//                 fieldName: 'Months',
41
//                 childLevel: {
42
//                         member: 'Date',
43
//                         fieldName:'Date',
44
//                         enabled: true
45
//                     }
46
//             }
47
//     }
48
// },
49
export class IgxPivotDateDimension implements IPivotDimension {
50
    /** Enables/Disables a particular dimension from pivot structure. */
UNCOV
51
    public enabled = true;
×
52

53
    /**
54
     * Gets/Sets data type
55
     */
56
    public dataType?: GridColumnDataType;
57

58
    /* blazorSuppress */
59
    /** Default options. */
UNCOV
60
    public defaultOptions = {
×
61
        total: true,
62
        years: true,
63
        months: true,
64
        fullDate: true
65
    };
66

67
    /**
68
     * Gets/Sets the resource strings.
69
     *
70
     * @remarks
71
     * By default it uses EN resources.
72
     */
73
    public set resourceStrings(value: IGridResourceStrings) {
74
        this._resourceStrings = Object.assign({}, this._resourceStrings, value);
×
75
    }
76

77
    public get resourceStrings(): IGridResourceStrings {
UNCOV
78
        return this._resourceStrings;
×
79
    }
80

81
    /**
82
     * Gets/Sets the base dimension that is used by this class to determine the other dimensions and their values.
83
     * Having base dimension set is required in order for the Date Dimensions to show.
84
     */
85
    public get baseDimension(): IPivotDimension {
UNCOV
86
        return this._baseDimension;
×
87
    }
88
    public set baseDimension(value: IPivotDimension) {
UNCOV
89
        this._baseDimension = value;
×
UNCOV
90
        this.initialize(this.baseDimension, this.options);
×
91
    }
92

93
    /**
94
     * Gets/Sets the options for the predefined date dimensions whether to show quarter, years and etc.
95
     */
96
    public get options(): IPivotDateDimensionOptions {
UNCOV
97
        return this._options;
×
98
    }
99
    public set options(value: IPivotDateDimensionOptions) {
UNCOV
100
        this._options = value;
×
UNCOV
101
        if (this.baseDimension) {
×
UNCOV
102
            this.initialize(this.baseDimension, this.options);
×
103
        }
104
    }
105

106
    /** @hidden @internal */
107
    public childLevel?: IPivotDimension;
108
    /** @hidden @internal */
UNCOV
109
    public memberName = 'AllPeriods';
×
110
    public displayName: string;
UNCOV
111
    private _resourceStrings = getCurrentResourceStrings(GridResourceStringsEN);
×
112
    private _baseDimension: IPivotDimension;
UNCOV
113
    private _options: IPivotDateDimensionOptions = {};
×
UNCOV
114
    private _monthIntl = new Intl.DateTimeFormat('default', { month: 'long' });
×
115

116

117
    /**
118
     * Creates additional pivot date dimensions based on a provided dimension describing date data:
119
     *
120
     * @param inDateDimension Base dimension that is used by this class to determine the other dimensions and their values.
121
     * @param inOptions Options for the predefined date dimensions whether to show quarter, years and etc.
122
     * @example
123
     * ```typescript
124
     * // Displays only years as parent dimension to the base dimension provided.
125
     * new IgxPivotDateDimension({ memberName: 'Date', enabled: true }, { total: false, months: false });
126
     * ```
127
     */
128
    constructor(inBaseDimension: IPivotDimension = null, inOptions: IPivotDateDimensionOptions = {}) {
×
UNCOV
129
        this._baseDimension = inBaseDimension;
×
UNCOV
130
        this._options = inOptions;
×
UNCOV
131
        if (this.baseDimension && this.options) {
×
UNCOV
132
            this.initialize(this.baseDimension, this.options);
×
133
        }
134
    }
135

136
    protected initialize(inBaseDimension, inOptions) {
UNCOV
137
        const options = { ...this.defaultOptions, ...inOptions };
×
138

UNCOV
139
        this.dataType = GridColumnDataType.Date;
×
UNCOV
140
        inBaseDimension.dataType = GridColumnDataType.Date;
×
141

UNCOV
142
        this.enabled = inBaseDimension.enabled;
×
UNCOV
143
        this.displayName = inBaseDimension.displayName || this.resourceStrings.igx_grid_pivot_date_dimension_total;
×
144

UNCOV
145
        const baseDimension = options.fullDate ? inBaseDimension : null;
×
UNCOV
146
        const monthDimensionDef: IPivotDimension = {
×
147
            memberName: 'Months',
148
            memberFunction: (rec) => {
UNCOV
149
                const recordValue = PivotUtil.extractValueFromDimension(inBaseDimension, rec);
×
UNCOV
150
                return recordValue ? this._monthIntl.format(new Date(recordValue)) : rec['Months'];
×
151
            },
152
            enabled: true,
153
            childLevel: baseDimension
154
        };
UNCOV
155
        const monthDimension = options.months ? monthDimensionDef : baseDimension;
×
156

UNCOV
157
        const quarterDimensionDef: IPivotDimension = {
×
158
            memberName: 'Quarters',
159
            memberFunction: (rec) => {
UNCOV
160
                const recordValue = PivotUtil.extractValueFromDimension(inBaseDimension, rec);
×
UNCOV
161
                return recordValue ? `Q` + Math.ceil((new Date(recordValue).getMonth() + 1) / 3) : rec['Quarters'];
×
162
            },
163
            enabled: true,
164
            childLevel: monthDimension
165
        };
UNCOV
166
        const quarterDimension = options.quarters ? quarterDimensionDef : monthDimension;
×
167

UNCOV
168
        const yearsDimensionDef: IPivotDimension = {
×
169
            memberName: 'Years',
170
            memberFunction: (rec) => {
UNCOV
171
                const recordValue = PivotUtil.extractValueFromDimension(inBaseDimension, rec);
×
UNCOV
172
                return recordValue ? (new Date(recordValue)).getFullYear().toString() : rec['Years'];
×
173
            },
174
            enabled: true,
175
            childLevel: quarterDimension
176
        };
UNCOV
177
        const yearsDimension = options.years ? yearsDimensionDef : quarterDimension;
×
UNCOV
178
        this.childLevel = yearsDimension;
×
179

UNCOV
180
        if (!options.total) {
×
UNCOV
181
            this.memberName = yearsDimension.memberName;
×
UNCOV
182
            this.memberFunction = yearsDimension.memberFunction;
×
UNCOV
183
            this.childLevel = yearsDimension.childLevel;
×
UNCOV
184
            this.displayName = yearsDimension.displayName;
×
185
        }
186
    }
187

188
    /** @hidden @internal */
UNCOV
189
    public memberFunction = (_data) => this.resourceStrings.igx_grid_pivot_date_dimension_total;
×
190
}
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