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

IgniteUI / igniteui-angular / 12300330513

12 Dec 2024 04:10PM CUT coverage: 91.592% (-0.03%) from 91.621%
12300330513

push

github

web-flow
Merge pull request #15120 from IgniteUI/19.0.x

Mass Merge 19.0.x to master

12984 of 15225 branches covered (85.28%)

86 of 106 new or added lines in 16 files covered. (81.13%)

12 existing lines in 3 files now uncovered.

26320 of 28736 relevant lines covered (91.59%)

34007.75 hits per line

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

75.0
/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

8
    public hasNumberValues = false;
131✔
9
    public hasDateValues = false;
131✔
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[]) {
24
        this._dictionary = {};
131✔
25
        this._widthsDictionary = {};
131✔
26
        this._counter = 0;
131✔
27
        this.dirtyKeyCollections();
131✔
28

29
        this._columnWidths = new Array<number>(columnCount);
131✔
30

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

37
        this.stringsCount = 0;
131✔
38
    }
39

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

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

49
        if (isSavedAsString) {
7,641✔
50
            sanitizedValue = shouldSanitizeValue ? ExportUtilities.sanitizeValue(value) : value;
5,400✔
51

52
            if (this._dictionary[sanitizedValue] === undefined) {
5,400✔
53
                this._dictionary[sanitizedValue] = this._counter++;
4,096✔
54
                this.dirtyKeyCollections();
4,096✔
55
            }
56

57
            this.stringsCount ++;
5,400✔
58
        } else if (isDate) {
2,241✔
59
            this.hasDateValues = true;
207✔
60
        } else {
61
            this.hasNumberValues = true;
2,034✔
62
        }
63

64
        return isSavedAsString ? this.getSanitizedValue(sanitizedValue) : -1;
7,641✔
65
    }
66

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

71
    public getSanitizedValue(sanitizedValue: string): number {
72
        return this._dictionary[sanitizedValue];
9,496✔
73
    }
74

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

81
        return this._keys;
126✔
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) {
×
NEW
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 {
105
        this._keysAreValid = false;
4,227✔
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