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

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM UTC 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

4.55
/projects/igniteui-angular/src/lib/services/excel/worksheet-data-dictionary.ts
1
import { ExportUtilities } from '../exporter-common/export-utilities';
2

3
/** @hidden */
4
export class WorksheetDataDictionary {
5
    private static DEFAULT_FONT = '11pt Calibri';
2✔
6
    private static TEXT_PADDING = 5;
2✔
7

UNCOV
8
    public hasNumberValues = false;
×
UNCOV
9
    public hasDateValues = false;
×
10

11
    public stringsCount: number;
12

13
    private _dictionary: any;
14
    private _widthsDictionary: any;
15

16
    private _keys: string[];
17
    private _keysAreValid: boolean;
18

19
    private _counter: number;
20
    private _columnWidths: number[];
21
    private _context: any;
22

23
    constructor(columnCount: number, columnWidth: number, columnWidthsList: number[]) {
UNCOV
24
        this._dictionary = {};
×
UNCOV
25
        this._widthsDictionary = {};
×
UNCOV
26
        this._counter = 0;
×
UNCOV
27
        this.dirtyKeyCollections();
×
28

UNCOV
29
        this._columnWidths = new Array<number>(columnCount);
×
30

UNCOV
31
        if (columnWidth) {
×
UNCOV
32
            this._columnWidths.fill(columnWidth);
×
33
        } else {
UNCOV
34
            this._columnWidths = columnWidthsList;
×
35
        }
36

UNCOV
37
        this.stringsCount = 0;
×
38
    }
39

40
    public get columnWidths() {
UNCOV
41
        return this._columnWidths;
×
42
    }
43

44
    public saveValue(value: any, isHeader: boolean, shouldSanitizeValue = true): number {
×
UNCOV
45
        let sanitizedValue = '';
×
UNCOV
46
        const isDate = value instanceof Date;
×
UNCOV
47
        const isSavedAsString = isHeader || (typeof value !== 'number' && value !== Number(value) && !Number.isFinite(value) && !isDate);
×
48

UNCOV
49
        if (isSavedAsString) {
×
UNCOV
50
            sanitizedValue = shouldSanitizeValue ? ExportUtilities.sanitizeValue(value) : value;
×
51

UNCOV
52
            if (this._dictionary[sanitizedValue] === undefined) {
×
UNCOV
53
                this._dictionary[sanitizedValue] = this._counter++;
×
UNCOV
54
                this.dirtyKeyCollections();
×
55
            }
56

UNCOV
57
            this.stringsCount ++;
×
UNCOV
58
        } else if (isDate) {
×
UNCOV
59
            this.hasDateValues = true;
×
60
        } else {
UNCOV
61
            this.hasNumberValues = true;
×
62
        }
63

UNCOV
64
        return isSavedAsString ? this.getSanitizedValue(sanitizedValue) : -1;
×
65
    }
66

67
    public getValue(value: string): number {
68
        return this.getSanitizedValue(ExportUtilities.sanitizeValue(value));
×
69
    }
70

71
    public getSanitizedValue(sanitizedValue: string): number {
UNCOV
72
        return this._dictionary[sanitizedValue];
×
73
    }
74

75
    public getKeys(): string[] {
UNCOV
76
        if (!this._keysAreValid) {
×
UNCOV
77
            this._keys = Object.keys(this._dictionary);
×
UNCOV
78
            this._keysAreValid = true;
×
79
        }
80

UNCOV
81
        return this._keys;
×
82
    }
83

84
    private getTextWidth(value: any): number {
85
        if (this._widthsDictionary[value] === undefined) {
×
86
            const context = this.getContext();
×
87
            const metrics = context.measureText(value);
×
88
            this._widthsDictionary[value] = metrics.width + WorksheetDataDictionary.TEXT_PADDING;
×
89
        }
90

91
        return this._widthsDictionary[value];
×
92
    }
93

94
    private getContext(): any {
95
        if (!this._context) {
×
96
            const canvas = globalThis.document?.createElement('canvas');
×
97
            this._context = canvas.getContext('2d');
×
98
            this._context.font = WorksheetDataDictionary.DEFAULT_FONT;
×
99
        }
100

101
        return this._context;
×
102
    }
103

104
    private dirtyKeyCollections(): void {
UNCOV
105
        this._keysAreValid = false;
×
106
    }
107
}
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