• 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

38.36
/projects/igniteui-angular/src/lib/services/overlay/position/auto-position-strategy.ts
1
import { AnimationReferenceMetadata } from '@angular/animations';
2
import { ConnectedFit, HorizontalAlignment, VerticalAlignment } from './../utilities';
3
import { BaseFitPositionStrategy } from './base-fit-position-strategy';
4
import { AnimationUtil } from 'igniteui-angular/animations';
5

6
/**
7
 * Positions the element as in **Connected** positioning strategy and re-positions the element in
8
 * the view port (calculating a different start point) in case the element is partially getting out of view
9
 */
10
export class AutoPositionStrategy extends BaseFitPositionStrategy {
11

12
    /**
13
     * Fits the element into viewport according to the position settings
14
     *
15
     * @param element element to fit in viewport
16
     * @param connectedFit connectedFit object containing all necessary parameters
17
     */
18
    protected fitInViewport(element: HTMLElement, connectedFit: ConnectedFit) {
19
        const transformString: string[] = [];
6✔
20
        if (connectedFit.fitHorizontal.back < 0 || connectedFit.fitHorizontal.forward < 0) {
6!
UNCOV
21
            if (this.canFlipHorizontal(connectedFit)) {
×
UNCOV
22
                this.flipHorizontal();
×
UNCOV
23
                this.flipAnimation(FlipDirection.Horizontal);
×
24
            } else {
UNCOV
25
                const horizontalPush = this.horizontalPush(connectedFit);
×
UNCOV
26
                transformString.push(`translateX(${horizontalPush}px)`);
×
27
            }
28
        }
29

30
        if (connectedFit.fitVertical.back < 0 || connectedFit.fitVertical.forward < 0) {
6✔
31
            if (this.canFlipVertical(connectedFit)) {
6!
32
                this.flipVertical();
6✔
33
                this.flipAnimation(FlipDirection.Vertical);
6✔
34
            } else {
UNCOV
35
                const verticalPush = this.verticalPush(connectedFit);
×
UNCOV
36
                transformString.push(`translateY(${verticalPush}px)`);
×
37
            }
38
        }
39

40
        element.style.transform = transformString.join(' ').trim();
6✔
41
    }
42

43
    /**
44
     * Checks if element can be flipped without get off the viewport
45
     *
46
     * @param connectedFit connectedFit object containing all necessary parameters
47
     * @returns true if element can be flipped and stain in viewport
48
     */
49
    private canFlipHorizontal(connectedFit: ConnectedFit): boolean {
50
        //  HorizontalAlignment can be Left = -1; Center = -0.5 or Right = 0.
51
        //  To virtually flip direction and start point (both are HorizontalAlignment) we can do this:
52
        //  flippedAlignment = (-1) * (HorizontalAlignment + 1)
53
        //  this way:
54
        //  (-1) * (Left + 1) = 0 = Right
55
        //  (-1) * (Center + 1) = -0.5 = Center
56
        //  (-1) * (Right + 1) = -1 = Left
UNCOV
57
        const flippedStartPoint = (-1) * (this.settings.horizontalStartPoint + 1);
×
UNCOV
58
        const flippedDirection = (-1) * (this.settings.horizontalDirection + 1);
×
59

UNCOV
60
        const leftBorder = this.calculateLeft(
×
61
            connectedFit.targetRect, connectedFit.contentElementRect, flippedStartPoint, flippedDirection, 0);
UNCOV
62
        const rightBorder = leftBorder + connectedFit.contentElementRect.width;
×
UNCOV
63
        return 0 < leftBorder && rightBorder < connectedFit.viewPortRect.width;
×
64
    }
65

66
    /**
67
     * Checks if element can be flipped without get off the viewport
68
     *
69
     * @param connectedFit connectedFit object containing all necessary parameters
70
     * @returns true if element can be flipped and stain in viewport
71
     */
72
    private canFlipVertical(connectedFit: ConnectedFit): boolean {
73
        const flippedStartPoint = (-1) * (this.settings.verticalStartPoint + 1);
6✔
74
        const flippedDirection = (-1) * (this.settings.verticalDirection + 1);
6✔
75

76
        const topBorder = this.calculateTop(
6✔
77
            connectedFit.targetRect, connectedFit.contentElementRect, flippedStartPoint, flippedDirection, 0);
78
        const bottomBorder = topBorder + connectedFit.contentElementRect.height;
6✔
79
        return 0 < topBorder && bottomBorder < connectedFit.viewPortRect.height;
6✔
80
    }
81

82
    /**
83
     * Flips direction and start point of the position settings
84
     */
85
    private flipHorizontal() {
UNCOV
86
        switch (this.settings.horizontalDirection) {
×
87
            case HorizontalAlignment.Left:
UNCOV
88
                this.settings.horizontalDirection = HorizontalAlignment.Right;
×
UNCOV
89
                break;
×
90
            case HorizontalAlignment.Right:
UNCOV
91
                this.settings.horizontalDirection = HorizontalAlignment.Left;
×
UNCOV
92
                break;
×
93
        }
UNCOV
94
        switch (this.settings.horizontalStartPoint) {
×
95
            case HorizontalAlignment.Left:
UNCOV
96
                this.settings.horizontalStartPoint = HorizontalAlignment.Right;
×
UNCOV
97
                break;
×
98
            case HorizontalAlignment.Right:
UNCOV
99
                this.settings.horizontalStartPoint = HorizontalAlignment.Left;
×
UNCOV
100
                break;
×
101
        }
102
    }
103

104
    /**
105
     * Flips direction and start point of the position settings
106
     */
107
    private flipVertical() {
108
        switch (this.settings.verticalDirection) {
6!
109
            case VerticalAlignment.Top:
UNCOV
110
                this.settings.verticalDirection = VerticalAlignment.Bottom;
×
UNCOV
111
                break;
×
112
            case VerticalAlignment.Bottom:
113
                this.settings.verticalDirection = VerticalAlignment.Top;
6✔
114
                break;
6✔
115
        }
116
        switch (this.settings.verticalStartPoint) {
6!
117
            case VerticalAlignment.Top:
UNCOV
118
                this.settings.verticalStartPoint = VerticalAlignment.Bottom;
×
UNCOV
119
                break;
×
120
            case VerticalAlignment.Bottom:
121
                this.settings.verticalStartPoint = VerticalAlignment.Top;
6✔
122
                break;
6✔
123
        }
124
    }
125

126
    /**
127
     * Calculates necessary horizontal push according to provided connectedFit
128
     *
129
     * @param connectedFit connectedFit object containing all necessary parameters
130
     * @returns amount of necessary translation which will push the element into viewport
131
     */
132
    private horizontalPush(connectedFit: ConnectedFit): number {
UNCOV
133
        const leftExtend = connectedFit.left;
×
UNCOV
134
        const rightExtend = connectedFit.right - connectedFit.viewPortRect.width;
×
135
        //  if leftExtend < 0 overlay goes beyond left end of the screen. We should push it back with exactly
136
        //  as much as it is beyond the screen.
137
        //  if rightExtend > 0 overlay goes beyond right end of the screen. We should push it back with the
138
        //  extend but with amount not bigger than what left between left border of screen and left border of
139
        //  overlay, e.g. leftExtend
UNCOV
140
        if (leftExtend < 0) {
×
UNCOV
141
            return Math.abs(leftExtend);
×
UNCOV
142
        } else if (rightExtend > 0) {
×
UNCOV
143
            return - Math.min(rightExtend, leftExtend);
×
144
        } else {
145
            return 0;
×
146
        }
147
    }
148

149
    /**
150
     * Calculates necessary vertical push according to provided connectedFit
151
     *
152
     * @param connectedFit connectedFit object containing all necessary parameters
153
     * @returns amount of necessary translation which will push the element into viewport
154
     */
155
    private verticalPush(connectedFit: ConnectedFit): number {
UNCOV
156
        const topExtend = connectedFit.top;
×
UNCOV
157
        const bottomExtend = connectedFit.bottom - connectedFit.viewPortRect.height;
×
UNCOV
158
        if (topExtend < 0) {
×
UNCOV
159
            return Math.abs(topExtend);
×
UNCOV
160
        } else if (bottomExtend > 0) {
×
UNCOV
161
            return - Math.min(bottomExtend, topExtend);
×
162
        } else {
163
            return 0;
×
164
        }
165
    }
166

167
    /**
168
     * Changes open and close animation with reverse animation if one exists
169
     *
170
     * @param flipDirection direction for which to change the animations
171
     */
172
    private flipAnimation(flipDirection: FlipDirection): void {
173
        if (this.settings.openAnimation) {
6✔
174
            this.settings.openAnimation = this.updateAnimation(this.settings.openAnimation, flipDirection);
6✔
175
        }
176
        if (this.settings.closeAnimation) {
6✔
177
            this.settings.closeAnimation = this.updateAnimation(this.settings.closeAnimation, flipDirection);
6✔
178
        }
179
    }
180

181
    /**
182
     * Tries to find the reverse animation according to provided direction
183
     *
184
     * @param animation animation to update
185
     * @param direction required animation direction
186
     * @returns reverse animation in given direction if one exists
187
     */
188
    private updateAnimation(animation: AnimationReferenceMetadata, direction: FlipDirection): AnimationReferenceMetadata {
189
        switch (direction) {
12!
190
            case FlipDirection.Horizontal:
UNCOV
191
                if (AnimationUtil.instance().isHorizontalAnimation(animation)) {
×
192
                    return AnimationUtil.instance().reverseAnimationResolver(animation);
×
193
                }
UNCOV
194
                break;
×
195
            case FlipDirection.Vertical:
196
                if (AnimationUtil.instance().isVerticalAnimation(animation)) {
12✔
197
                    return AnimationUtil.instance().reverseAnimationResolver(animation);
12✔
198
                }
199
                break;
×
200
        }
201

UNCOV
202
        return animation;
×
203
    }
204
}
205

206
enum FlipDirection {
2✔
207
    Horizontal,
2✔
208
    Vertical
2✔
209
}
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