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

glideapps / glide-data-grid / 7333166280

26 Dec 2023 10:45PM UTC coverage: 90.585% (+4.2%) from 86.42%
7333166280

Pull #810

github

jassmith
5.99.9-charlie1
Pull Request #810: 6.0.0

2594 of 3246 branches covered (0.0%)

3363 of 3831 new or added lines in 62 files covered. (87.78%)

265 existing lines in 12 files now uncovered.

15759 of 17397 relevant lines covered (90.58%)

3076.99 hits per line

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

94.87
/packages/core/src/common/render-state-provider.ts
1
import type { Item, Rectangle } from "../internal/data-grid/data-grid-types.js";
1✔
2

1✔
3
// max safe int 2^53 - 1 (minus 1 omitted from here on)
1✔
4
// max safe columns is 2^21 or 2,097,151
1✔
5
// max safe rows is 2^32 or 4,294,967,295
1✔
6
// If 3 rows render as an inch, then the max safe height is 1,431,655,765 inches or 22,426,868 miles
1✔
7
// the distance to the moon is 238,900 miles, so this would give you a data grid that goes to the moon and back 94 times
1✔
8
// seems fine
1✔
9
const rowShift = 1 << 21;
1✔
10

1✔
11
export function packColRowToNumber(col: number, row: number) {
1✔
12
    return (row + 2) * rowShift + col;
164,191✔
13
}
164,191✔
14

1✔
15
export function unpackCol(packed: number): number {
1✔
16
    return packed % rowShift;
4,197✔
17
}
4,197✔
18

1✔
19
export function unpackRow(packed: number): number {
1✔
20
    return Math.floor(packed / rowShift) - 2;
5,327✔
21
}
5,327✔
22

1✔
23
export function unpackNumberToColRow(packed: number): [number, number] {
1✔
24
    const col = unpackCol(packed);
6✔
25
    const row = unpackRow(packed);
6✔
26
    return [col, row];
6✔
27
}
6✔
28

1✔
29
export class RenderStateProvider {
1✔
30
    private visibleWindow: Rectangle = {
1✔
31
        x: 0,
151✔
32
        y: 0,
151✔
33
        width: 0,
151✔
34
        height: 0,
151✔
35
    };
151✔
36

151✔
37
    private freezeCols: number = 0;
151✔
38

151✔
39
    private isInWindow = (packed: number) => {
151✔
40
        const col = unpackCol(packed);
2✔
41
        const row = unpackRow(packed);
2✔
42
        const w = this.visibleWindow;
2✔
43
        if (col < this.freezeCols && row >= w.y && row <= w.y + w.height) return true;
2✔
44
        return col >= w.x && col <= w.x + w.width && row >= w.y && row <= w.y + w.height;
2!
45
    };
2✔
46

151✔
47
    private cache: Map<number, any> = new Map();
151✔
48

151✔
49
    public setValue = (location: Item, state: any): void => {
151✔
50
        this.cache.set(packColRowToNumber(location[0], location[1]), state);
3✔
51
    };
3✔
52

151✔
53
    public getValue = (location: Item): any => {
151✔
54
        return this.cache.get(packColRowToNumber(location[0], location[1]));
117,801✔
55
    };
117,801✔
56

151✔
57
    private clearOutOfWindow = () => {
151✔
58
        for (const [key] of this.cache.entries()) {
1✔
59
            if (!this.isInWindow(key)) {
2✔
60
                this.cache.delete(key);
1✔
61
            }
1✔
62
        }
2✔
63
    };
1✔
64

1✔
65
    public setWindow(newWindow: Rectangle, freezeCols: number): void {
1✔
66
        if (
1✔
67
            this.visibleWindow.x === newWindow.x &&
1!
NEW
68
            this.visibleWindow.y === newWindow.y &&
×
NEW
69
            this.visibleWindow.width === newWindow.width &&
×
NEW
70
            this.visibleWindow.height === newWindow.height &&
×
NEW
71
            this.freezeCols === freezeCols
×
72
        )
1✔
73
            return;
1!
74
        this.visibleWindow = newWindow;
1✔
75
        this.freezeCols = freezeCols;
1✔
76
        this.clearOutOfWindow();
1✔
77
    }
1✔
78
}
1✔
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