1
+ // @ts -nocheck
1
2
import {
2
3
getNodeTopLeftAbsolute ,
3
4
getTopLeftForBorder ,
@@ -8,6 +9,12 @@ export function deleteAllBorders() {
8
9
document . querySelectorAll ( ".border" ) . forEach ( ( el ) => el . remove ( ) ) ;
9
10
}
10
11
12
+ function makeAllBordersTransparent ( ) {
13
+ document
14
+ . querySelectorAll ( ".border" )
15
+ . forEach ( ( el ) => ( el . style . borderColor = "transparent" ) ) ;
16
+ }
17
+
11
18
// @ts -ignore
12
19
const iconMap = window . iconMap ;
13
20
@@ -28,36 +35,50 @@ function drawNodeIcon(fontSize, color, label) {
28
35
return icon ;
29
36
}
30
37
31
- function isEnoughRoomForBorders ( cy , paddingX , paddingY , iconSize , iconGap , windowPadding ) {
32
- const windowWidth = window . innerWidth
33
- const windowHeight = window . innerHeight ;
34
- let widthNeededForAllNodes = 0
35
- let maxHeightNeededForBorder = 0
36
- cy . nodes ( ) . forEach ( node => {
37
- const nodeW = node . renderedWidth ( ) ;
38
- const nodeH = node . renderedHeight ( ) ;
39
- const dimensions = getBorderWidthAndHeight ( paddingX , nodeW , paddingY , nodeH , iconSize , iconGap ) ;
40
- widthNeededForAllNodes += dimensions . width
41
- maxHeightNeededForBorder = Math . max ( maxHeightNeededForBorder , dimensions . height )
42
- } )
43
- return widthNeededForAllNodes < windowWidth - windowPadding * 2 && maxHeightNeededForBorder < windowHeight - windowPadding * 2
38
+ function isOverlappingWithTopRightCorner ( bordersTopRightPosition , topLeft ) {
39
+ const marginOfError = 8 ;
40
+ return bordersTopRightPosition . some ( ( [ x , y ] ) => {
41
+ if ( y === topLeft . y ) {
42
+ return x + marginOfError >= topLeft . x ;
43
+ }
44
+ } ) ;
44
45
}
45
46
46
- function isEnoughAreaForBorders ( cy , paddingX , paddingY , iconSize , iconGap , windowPadding ) {
47
+ function isEnoughAreaForBorders (
48
+ cy ,
49
+ paddingX ,
50
+ paddingY ,
51
+ iconSize ,
52
+ iconGap ,
53
+ windowPadding
54
+ ) {
47
55
const windowWidth = window . innerWidth ;
48
56
const windowHeight = window . innerHeight ;
49
57
50
58
let areaNeededForAllNodes = 0 ;
51
59
let maxHeightNeededForBorder = 0 ;
52
60
let maxWidthNeededForBorder = 0 ;
53
61
54
- cy . nodes ( ) . forEach ( node => {
62
+ cy . nodes ( ) . forEach ( ( node ) => {
55
63
const nodeW = node . renderedWidth ( ) ;
56
64
const nodeH = node . renderedHeight ( ) ;
57
- const dimensions = getBorderWidthAndHeight ( paddingX , nodeW , paddingY , nodeH , iconSize , iconGap ) ;
65
+ const dimensions = getBorderWidthAndHeight (
66
+ paddingX ,
67
+ nodeW ,
68
+ paddingY ,
69
+ nodeH ,
70
+ iconSize ,
71
+ iconGap
72
+ ) ;
58
73
areaNeededForAllNodes += dimensions . width * dimensions . height ;
59
- maxHeightNeededForBorder = Math . max ( maxHeightNeededForBorder , dimensions . height ) ;
60
- maxWidthNeededForBorder = Math . max ( maxWidthNeededForBorder , dimensions . width ) ;
74
+ maxHeightNeededForBorder = Math . max (
75
+ maxHeightNeededForBorder ,
76
+ dimensions . height
77
+ ) ;
78
+ maxWidthNeededForBorder = Math . max (
79
+ maxWidthNeededForBorder ,
80
+ dimensions . width
81
+ ) ;
61
82
} ) ;
62
83
63
84
const usableWidth = windowWidth - 2 * windowPadding ;
@@ -71,22 +92,56 @@ function isEnoughAreaForBorders(cy, paddingX, paddingY, iconSize, iconGap, windo
71
92
return cy . nodes ( ) . length <= maxNodesThatCanFit ;
72
93
}
73
94
74
- export function drawBorderAndIconForEachExplainNode ( cy , windowPadding , isVisible ) {
95
+ export function drawBorderAndIconForEachExplainNode (
96
+ cy ,
97
+ windowPadding ,
98
+ isVisible
99
+ ) {
75
100
const paddingX = 30 ;
76
101
const paddingY = 10 ;
77
- const iconSize = 50 ;
78
102
const iconGap = 20 ;
79
103
const borderRadius = 10 ;
80
104
const iconColor = "#007acc" ;
81
- const shouldDrawBorders = isEnoughAreaForBorders ( cy , paddingX , paddingY , iconSize , iconGap , windowPadding )
82
105
83
- cy . nodes ( ) . forEach ( node => {
106
+ let minIconSize = 50 ;
107
+ cy . nodes ( ) . forEach ( ( node ) => {
108
+ const nodeW = node . renderedWidth ( ) ;
109
+ const iconSize = nodeW / 2 ;
110
+ minIconSize = Math . min ( minIconSize , iconSize ) ;
111
+ } ) ;
112
+
113
+ let shouldDrawBorders = isEnoughAreaForBorders (
114
+ cy ,
115
+ paddingX ,
116
+ paddingY ,
117
+ minIconSize ,
118
+ iconGap ,
119
+ windowPadding
120
+ ) ;
121
+ const bordersTopRightPosition = [ ] ;
122
+
123
+ cy . nodes ( ) . forEach ( ( node ) => {
84
124
const nodeW = node . renderedWidth ( ) ;
85
125
const nodeH = node . renderedHeight ( ) ;
126
+
86
127
const nodeTopLeft = getNodeTopLeftAbsolute ( node , cy ) ;
87
128
88
- const topLeft = getTopLeftForBorder ( nodeTopLeft . x , nodeTopLeft . y , paddingX , paddingY , iconSize , iconGap ) ;
89
- const dimensions = getBorderWidthAndHeight ( paddingX , nodeW , paddingY , nodeH , iconSize , iconGap ) ;
129
+ const topLeft = getTopLeftForBorder (
130
+ nodeTopLeft . x ,
131
+ nodeTopLeft . y ,
132
+ paddingX ,
133
+ paddingY ,
134
+ minIconSize ,
135
+ iconGap
136
+ ) ;
137
+ const dimensions = getBorderWidthAndHeight (
138
+ paddingX ,
139
+ nodeW ,
140
+ paddingY ,
141
+ nodeH ,
142
+ minIconSize ,
143
+ iconGap
144
+ ) ;
90
145
91
146
const border = document . createElement ( "div" ) ;
92
147
border . className = "border" ;
@@ -100,13 +155,24 @@ export function drawBorderAndIconForEachExplainNode(cy, windowPadding, isVisible
100
155
display : "flex" ,
101
156
justifyContent : "center" ,
102
157
paddingTop : `${ paddingY } px` ,
103
- borderRadius : `${ borderRadius } px`
158
+ borderRadius : `${ borderRadius } px` ,
104
159
} ) ;
105
- if ( ! shouldDrawBorders || ! isVisible ) {
106
- border . style . borderColor = "transparent"
160
+
161
+ const overlappingWithTopRightCorner = isOverlappingWithTopRightCorner (
162
+ bordersTopRightPosition ,
163
+ topLeft
164
+ ) ;
165
+ if ( overlappingWithTopRightCorner ) {
166
+ shouldDrawBorders = false ;
167
+ makeAllBordersTransparent ( ) ;
168
+ }
169
+ bordersTopRightPosition . push ( [ topLeft . x + dimensions . width , topLeft . y ] ) ;
170
+
171
+ if ( ! shouldDrawBorders || ! isVisible ) {
172
+ border . style . borderColor = "transparent" ;
107
173
}
108
174
109
- border . appendChild ( drawNodeIcon ( iconSize , iconColor , node . data ( ) . label ) ) ;
175
+ border . appendChild ( drawNodeIcon ( minIconSize , iconColor , node . data ( ) . label ) ) ;
110
176
document . body . appendChild ( border ) ;
111
177
} ) ;
112
178
}
0 commit comments