How to use checkRect method in wpt

Best JavaScript code snippet using wpt

Grouper.spec.js

Source:Grouper.spec.js Github

copy

Full Screen

...49 const grouped = getSheetArea(testItems.gt1);50 new Grouper(bladeWidth).group(rects, grouped);51 checkArea(grouped, 610, 100, 0, 0, 0, 0, 3, 0);52 checkRemainingWidth(grouped, [[0, 0]]);53 checkRect(grouped.rects[0], 'C', 0, 0, bladeWidth, 0);54 checkRect(grouped.rects[1], 'B', 305, 0, bladeWidth, 0);55 checkRect(grouped.rects[2], 'A', 510, 0, 0, 0);56 });57 it('should pack three items into a wider sheet (GT2)', () => {58 const rects = getRects(testItems.gt2);59 const grouped = getSheetArea(testItems.gt2);60 new Grouper(bladeWidth).group(rects, grouped);61 checkArea(grouped, 700, 100, 0, 0, 0, 0, 3, 0);62 checkRemainingWidth(grouped, [[0, 85]]);63 checkRect(grouped.rects[0], 'C', 0, 0, bladeWidth, 0);64 checkRect(grouped.rects[1], 'B', 305, 0, bladeWidth, 0);65 checkRect(grouped.rects[2], 'A', 510, 0, bladeWidth, 0);66 });67 it('should pack three items into a little bit wider sheet (GT3)', () => {68 const rects = getRects(testItems.gt3);69 const grouped = getSheetArea(testItems.gt3);70 new Grouper(bladeWidth).group(rects, grouped);71 checkArea(grouped, 613, 100, 0, 0, 0, 0, 3, 0);72 checkRemainingWidth(grouped, [[0, 0]]);73 checkRect(grouped.rects[0], 'C', 0, 0, bladeWidth, 0);74 checkRect(grouped.rects[1], 'B', 305, 0, bladeWidth, 0);75 checkRect(grouped.rects[2], 'A', 510, 0, 3, 0);76 });77 it('should pack three items into a higher sheet (GT4)', () => {78 const rects = getRects(testItems.gt4);79 const grouped = getSheetArea(testItems.gt4);80 new Grouper(bladeWidth).group(rects, grouped);81 checkArea(grouped, 610, 200, 0, 0, 0, 0, 3, 0);82 checkRemainingWidth(grouped, [[0, 0]]);83 checkRect(grouped.rects[0], 'C', 0, 0, bladeWidth, bladeWidth);84 checkRect(grouped.rects[1], 'B', 305, 0, bladeWidth, bladeWidth);85 checkRect(grouped.rects[2], 'A', 510, 0, 0, bladeWidth);86 });87 it('should pack six items into two rows (GT5)', () => {88 const rects = getRects(testItems.gt5);89 const grouped = getSheetArea(testItems.gt5);90 new Grouper(bladeWidth).group(rects, grouped);91 checkArea(grouped, 610, 200, 0, 0, 0, 0, 4, 1);92 checkRemainingWidth(grouped, [93 [0, 0],94 [105, 0],95 ]);96 checkRect(grouped.rects[0], 'B', 305, 0, bladeWidth, bladeWidth);97 checkRect(grouped.rects[1], 'A', 510, 0, 0, bladeWidth);98 checkRect(grouped.rects[2], 'E', 305, 105, bladeWidth, 0);99 checkRect(grouped.rects[3], 'F', 510, 105, 0, 0);100 const area1 = grouped.nestedAreas[0];101 checkArea(area1, 305, 200, 0, 0, bladeWidth, 0, 2, 0);102 checkRect(area1.rects[0], 'C', 0, 0, 0, bladeWidth);103 checkRect(area1.rects[1], 'D', 0, 105, 0, 0);104 });105 it('should pack six items into two rows in a bigger sheet (GT6)', () => {106 const rects = getRects(testItems.gt6);107 const grouped = getSheetArea(testItems.gt6);108 new Grouper(bladeWidth).group(rects, grouped);109 checkArea(grouped, 2000, 600, 0, 0, 0, 0, 0, 1);110 checkRemainingWidth(grouped, [[0, 1690]]);111 const area1 = grouped.nestedAreas[0];112 checkArea(area1, 310, 600, 0, 0, bladeWidth, 0, 6, 0);113 checkRect(area1.rects[0], 'B', 0, 0, bladeWidth, bladeWidth);114 checkRect(area1.rects[1], 'A', 205, 0, 0, bladeWidth);115 checkRect(area1.rects[2], 'E', 0, 105, bladeWidth, bladeWidth);116 checkRect(area1.rects[3], 'F', 205, 105, 0, bladeWidth);117 checkRect(area1.rects[4], 'C', 0, 205, bladeWidth, bladeWidth);118 checkRect(area1.rects[5], 'D', 0, 310, bladeWidth, bladeWidth);119 });120 it('should pack three items into a wider and higher sheet (GT7)', () => {121 const rects = getRects(testItems.gt7);122 const grouped = getSheetArea(testItems.gt7);123 new Grouper(bladeWidth).group(rects, grouped);124 checkArea(grouped, 700, 200, 0, 0, 0, 0, 0, 1);125 checkRemainingWidth(grouped, [[0, 0]]);126 const nestedArea = grouped.nestedAreas[0];127 checkArea(nestedArea, 700, 105, 0, 0, 0, bladeWidth, 3, 0);128 checkRemainingWidth(nestedArea, [[0, 85]]);129 checkRect(nestedArea.rects[0], 'C', 0, 0, bladeWidth, 0);130 checkRect(nestedArea.rects[1], 'B', 305, 0, bladeWidth, 0);131 checkRect(nestedArea.rects[2], 'A', 510, 0, bladeWidth, 0);132 });133 it('should pack two items, one smaller than the other (GT8)', () => {134 const rects = getRects(testItems.gt8);135 const grouped = getSheetArea(testItems.gt8);136 new Grouper(bladeWidth).group(rects, grouped);137 checkArea(grouped, 700, 400, 0, 0, 0, 0, 1, 1);138 checkRemainingWidth(grouped, [139 [0, 440],140 [199, 440],141 ]);142 checkRect(grouped.rects[0], 'A', 0, 0, bladeWidth, 0);143 const nestedArea = grouped.nestedAreas[0];144 checkArea(nestedArea, 55, 400, 205, 0, bladeWidth, 0, 1, 0);145 checkRemainingWidth(nestedArea, [146 [0, 0],147 [355, 50],148 ]);149 checkRect(nestedArea.rects[0], 'B', 0, 0, 0, bladeWidth);150 });151 it('should pack three items, two smaller than the first (GT9)', () => {152 const rects = getRects(testItems.gt9);153 const grouped = getSheetArea(testItems.gt9);154 new Grouper(bladeWidth).group(rects, grouped);155 checkArea(grouped, 700, 400, 0, 0, 0, 0, 1, 1);156 checkRemainingWidth(grouped, [157 [0, 355],158 [199, 355],159 ]);160 checkRect(grouped.rects[0], 'A', 0, 0, bladeWidth, 0);161 const nestedArea = grouped.nestedAreas[0];162 checkArea(nestedArea, 140, 400, 205, 0, bladeWidth, 0, 2, 0);163 checkRect(nestedArea.rects[0], 'C', 0, 0, bladeWidth, bladeWidth);164 checkRect(nestedArea.rects[1], 'B', 85, 0, 0, bladeWidth);165 });166 it('should pack 5 of 6 items (GT10)', () => {167 const rects = getRects(testItems.gt10);168 const grouped = getSheetArea(testItems.gt10);169 new Grouper(bladeWidth).group(rects, grouped);170 checkArea(grouped, 2000, 600, 0, 0, 0, 0, 1, 1);171 checkRemainingWidth(grouped, [172 [0, 205],173 [558, 205],174 [559, 205],175 [560, 205],176 [561, 205],177 [562, 205],178 [563, 205],179 [564, 205],180 [565, 205],181 [566, 205],182 [599, 205],183 [600, NaN],184 ]);185 checkRect(grouped.rects[0], 'A', 0, 0, bladeWidth, 0);186 const nestedArea = grouped.nestedAreas[0];187 checkArea(nestedArea, 890, 600, 905, 0, bladeWidth, 0, 2, 1);188 checkRemainingWidth(nestedArea, [[0, 0]]);189 checkRect(nestedArea.rects[0], 'B', 0, 0, bladeWidth, bladeWidth);190 checkRect(nestedArea.rects[1], 'B', 445, 0, 0, bladeWidth);191 const nestedNestedArea = nestedArea.nestedAreas[0];192 checkArea(nestedNestedArea, 745, 205, 0, 395, bladeWidth, 0, 1, 1);193 checkRemainingWidth(nestedNestedArea, [194 [0, 0],195 [106, 35],196 ]);197 checkRect(nestedNestedArea.rects[0], 'D', 0, 0, 0, bladeWidth);198 checkArea(nestedNestedArea.nestedAreas[0], 705, 100, 0, 105, bladeWidth, 0, 1, 0);199 checkRemainingWidth(nestedNestedArea.nestedAreas[0], [[0, 0]]);200 checkRect(nestedNestedArea.nestedAreas[0].rects[0], 'C', 0, 0, 0, bladeWidth);201 });202 it('should pack two items (GT11)', () => {203 const rects = getRects(testItems.gt11);204 const grouped = getSheetArea(testItems.gt11);205 new Grouper(bladeWidth).group(rects, grouped);206 checkArea(grouped, 1000, 600, 0, 0, 0, 0, 1, 1);207 checkRemainingWidth(grouped, [208 [0, 0],209 [55, 945],210 [599, 945],211 ]);212 checkRect(grouped.rects[0], 'A', 0, 0, 0, bladeWidth);213 const nestedArea = grouped.nestedAreas[0];214 checkArea(nestedArea, 55, 545, 0, 55, bladeWidth, 0, 1, 0);215 checkRemainingWidth(nestedArea, [216 [0, 0],217 [55, 0],218 [544, 50],219 ]);220 checkRect(nestedArea.rects[0], 'B', 0, 0, 0, bladeWidth);221 });222 it('should pack three items (GT12)', () => {223 const rects = getRects(testItems.gt12);224 const grouped = getSheetArea(testItems.gt12);225 new Grouper(bladeWidth).group(rects, grouped);226 checkArea(grouped, 2000, 600, 0, 0, 0, 0, 2, 1);227 checkRemainingWidth(grouped, [228 [0, 0],229 [55, 1040],230 [599, 1040],231 ]);232 checkRect(grouped.rects[0], 'A', 0, 0, bladeWidth, 0);233 checkRect(grouped.rects[1], 'B', 905, 0, 0, bladeWidth);234 const nestedArea = grouped.nestedAreas[0];235 checkArea(nestedArea, 55, 545, 905, 55, bladeWidth, 0, 1, 0);236 checkRemainingWidth(nestedArea, [237 [0, 0],238 [55, 0],239 [544, 50],240 ]);241 checkRect(nestedArea.rects[0], 'C', 0, 0, 0, bladeWidth);242 });243 it('should pack four items in three rows (GT13)', () => {244 const rects = getRects(testItems.gt13);245 const grouped = getSheetArea(testItems.gt13);246 new Grouper(bladeWidth).group(rects, grouped);247 checkArea(grouped, 2000, 600, 0, 0, 0, 0, 3, 1);248 checkRemainingWidth(grouped, [249 [0, 0],250 [55, 0],251 [599, 1040],252 ]);253 checkRect(grouped.rects[0], 'A', 0, 0, bladeWidth, 0);254 checkRect(grouped.rects[1], 'B', 905, 0, 0, bladeWidth);255 checkRect(grouped.rects[2], 'B', 905, 55, 0, bladeWidth);256 const nestedArea = grouped.nestedAreas[0];257 checkArea(nestedArea, 55, 490, 905, 110, bladeWidth, 0, 1, 0);258 checkRemainingWidth(nestedArea, [259 [0, 0],260 [55, 0],261 [489, 50],262 ]);263 checkRect(nestedArea.rects[0], 'C', 0, 0, 0, bladeWidth);264 });265 it('should pack six items in three rows (GT14)', () => {266 const rects = getRects(testItems.gt14);267 const grouped = getSheetArea(testItems.gt14);268 new Grouper(bladeWidth).group(rects, grouped);269 checkArea(grouped, 2000, 600, 0, 0, 0, 0, 5, 1);270 checkRemainingWidth(grouped, [271 [0, 0],272 [55, 0],273 [599, 1040],274 ]);275 checkRect(grouped.rects[0], 'A', 0, 0, bladeWidth, 0);276 checkRect(grouped.rects[1], 'E', 905, 0, 0, bladeWidth);277 checkRect(grouped.rects[2], 'B', 905, 55, bladeWidth, bladeWidth);278 checkRect(grouped.rects[3], 'C', 1505, 55, bladeWidth, bladeWidth);279 checkRect(grouped.rects[4], 'D', 1905, 55, 0, bladeWidth);280 const nestedArea = grouped.nestedAreas[0];281 checkArea(nestedArea, 55, 490, 905, 110, bladeWidth, 0, 1, 0);282 checkRect(nestedArea.rects[0], 'F', 0, 0, 0, bladeWidth);283 });284 it('should pack three + one items (GT15)', () => {285 const rects = getRects(testItems.gt15);286 const grouped = getSheetArea(testItems.gt15);287 new Grouper(bladeWidth).group(rects, grouped);288 checkArea(grouped, 2000, 600, 0, 0, 0, 0, 2, 2);289 checkRemainingWidth(grouped, [290 [0, 0],291 [55, 935],292 [599, 935],293 ]);294 checkRect(grouped.rects[0], 'A', 0, 0, bladeWidth, 0);295 checkRect(grouped.rects[1], 'B', 905, 0, 0, bladeWidth);296 checkArea(grouped.nestedAreas[0], 55, 545, 905, 55, bladeWidth, 0, 1, 0);297 checkRect(grouped.nestedAreas[0].rects[0], 'C', 0, 0, 0, bladeWidth);298 checkArea(grouped.nestedAreas[1], 105, 545, 960, 55, bladeWidth, 0, 1, 0);299 checkRect(grouped.nestedAreas[1].rects[0], 'D', 0, 0, 0, bladeWidth);300 });301 it('should pack four rects in two rows (GT16)', () => {302 const rects = getRects(testItems.gt16);303 const grouped = getSheetArea(testItems.gt16);304 new Grouper(bladeWidth).group(rects, grouped);305 checkArea(grouped, 2500, 1250, 0, 0, 0, 0, 0, 1);306 checkRemainingWidth(grouped, [307 [0, 800],308 [1000, 800],309 [1244, 800],310 [1245, 800],311 [1246, 800],312 [1247, 800],313 [1248, 800],314 [1249, 800],315 ]);316 const nestedArea = grouped.nestedAreas[0];317 checkArea(nestedArea, 1700, 1250, 0, 0, bladeWidth, bladeWidth, 4, 0);318 checkRemainingWidth(nestedArea, [319 [0, 0],320 [1000, 0],321 [1244, 0],322 ]);323 checkRect(nestedArea.rects[0], 'A', 0, 0, bladeWidth, bladeWidth);324 checkRect(nestedArea.rects[1], 'A', 850, 0, 0, bladeWidth);325 checkRect(nestedArea.rects[2], 'A', 0, 625, bladeWidth, 0);326 checkRect(nestedArea.rects[3], 'A', 850, 625, 0, 0);327 });328 it('should pack four rects in two rows with eight rects beside them (GT17)', () => {329 const rects = getRects(testItems.gt17);330 const grouped = getSheetArea(testItems.gt17);331 new Grouper(bladeWidth).group(rects, grouped);332 checkArea(grouped, 2500, 1250, 0, 0, 0, 0, 0, 2);333 checkRemainingWidth(grouped, [334 [0, 175],335 [1000, 175],336 [1249, 175],337 ]);338 const nestedArea = grouped.nestedAreas[0];339 checkArea(nestedArea, 1700, 1250, 0, 0, bladeWidth, bladeWidth, 4, 0);340 checkRemainingWidth(nestedArea, [341 [0, 0],342 [1000, 0],343 [1244, 0],344 ]);345 checkRect(nestedArea.rects[0], 'C', 0, 0, bladeWidth, bladeWidth);346 checkRect(nestedArea.rects[1], 'C', 850, 0, 0, bladeWidth);347 checkRect(nestedArea.rects[2], 'C', 0, 625, bladeWidth, 0);348 checkRect(nestedArea.rects[3], 'C', 850, 625, 0, 0);349 const nestedArea2 = grouped.nestedAreas[1];350 checkArea(nestedArea2, 625, 1250, 1700, 0, bladeWidth, 0, 8, 0);351 checkRemainingWidth(nestedArea2, [352 [0, 0],353 [1000, 0],354 [1249, 620],355 ]);356 checkRect(nestedArea2.rects[0], 'A', 0, 0, 0, bladeWidth);357 checkRect(nestedArea2.rects[1], 'A', 0, 205, 0, bladeWidth);358 checkRect(nestedArea2.rects[2], 'A', 0, 410, 0, bladeWidth);359 checkRect(nestedArea2.rects[3], 'A', 0, 615, 0, bladeWidth);360 checkRect(nestedArea2.rects[4], 'B', 0, 820, 0, bladeWidth);361 checkRect(nestedArea2.rects[5], 'B', 0, 925, 0, bladeWidth);362 checkRect(nestedArea2.rects[6], 'B', 0, 1030, 0, bladeWidth);363 checkRect(nestedArea2.rects[7], 'B', 0, 1135, 0, bladeWidth);364 });365 it('should pack 7 of 7 items (GT18)', () => {366 const rects = getRects(testItems.gt18);367 const grouped = getSheetArea(testItems.gt18);368 new Grouper(bladeWidth).group(rects, grouped);369 checkArea(grouped, 2000, 600, 0, 0, 0, 0, 1, 1);370 checkRemainingWidth(grouped, [371 [0, 205],372 [558, 205],373 [559, 205],374 [560, 205],375 [561, 205],376 [562, 205],377 [563, 205],378 [564, 205],379 [565, 205],380 [566, 205],381 [599, 205],382 [600, NaN],383 ]);384 checkRect(grouped.rects[0], 'A', 0, 0, bladeWidth, 0);385 const nestedArea = grouped.nestedAreas[0];386 checkArea(nestedArea, 890, 600, 905, 0, bladeWidth, 0, 2, 1);387 checkRemainingWidth(nestedArea, [388 [0, 0],389 [395, 140],390 ]);391 checkRect(nestedArea.rects[0], 'B', 0, 0, bladeWidth, bladeWidth);392 checkRect(nestedArea.rects[1], 'B', 445, 0, 0, bladeWidth);393 checkArea(nestedArea.nestedAreas[0], 745, 205, 0, 395, bladeWidth, 0, 2, 1);394 checkRemainingWidth(nestedArea.nestedAreas[0], [395 [0, 0],396 [70, 35],397 ]);398 checkRect(nestedArea.nestedAreas[0].rects[0], 'D', 0, 0, 0, bladeWidth);399 checkRect(nestedArea.nestedAreas[0].rects[1], 'D', 0, 35, 0, bladeWidth);400 const nestedNestedArea = nestedArea.nestedAreas[0].nestedAreas[0];401 checkArea(nestedNestedArea, 705, 135, 0, 70, bladeWidth, 0, 2, 0);402 checkRemainingWidth(nestedNestedArea, [403 [0, 0],404 [74, 0],405 ]);406 checkRect(nestedNestedArea.rects[0], 'C', 0, 0, 0, bladeWidth);407 checkRect(nestedNestedArea.rects[1], 'C', 0, 65, 0, bladeWidth);408 });409 it('should not use the deepest sheet area (GT19)', () => {410 const rects = getRects(testItems.gt19);411 const grouped = getSheetArea(testItems.gt19);412 new Grouper(bladeWidth).group(rects, grouped);413 checkArea(grouped, 740, 205, 0, 0, 0, 0, 3, 1);414 checkRect(grouped.rects[0], 'A', 0, 0, 0, bladeWidth);415 checkRect(grouped.rects[1], 'C', 0, 35, bladeWidth, bladeWidth);416 checkRect(grouped.rects[2], 'D', 373, 35, 0, bladeWidth);417 const nestedArea = grouped.nestedAreas[0];418 checkArea(nestedArea, 705, 135, 0, 70, bladeWidth, 0, 2, 0);419 });420 it('should use full width if rects plus cutting width are >= full width (GT20)', () => {421 const rects = getRects(testItems.gt20);422 const grouped = getSheetArea(testItems.gt20);423 new Grouper(bladeWidth).group(rects, grouped);424 checkArea(grouped, 740, 205, 0, 0, 0, 0, 3, 1);425 checkRect(grouped.rects[0], 'A', 0, 0, 0, bladeWidth);426 checkRect(grouped.rects[1], 'C', 0, 35, bladeWidth, bladeWidth);427 checkRect(grouped.rects[2], 'C', 372, 35, 1, bladeWidth);428 const nestedArea = grouped.nestedAreas[0];429 checkArea(nestedArea, 705, 135, 0, 70, bladeWidth, 0, 2, 0);430 });431 it('should group same height rects in one row of same width as a single rect (GT21)', () => {432 const rects = getRects(testItems.gt21);433 const grouped = getSheetArea(testItems.gt21);434 new Grouper(bladeWidth).group(rects, grouped);435 checkArea(grouped, 2000, 600, 0, 0, 0, 0, 1, 1);436 checkRemainingWidth(grouped, [437 [0, 205],438 [558, 205],439 [559, 205],440 [560, 205],441 [561, 205],442 [562, 205],443 [563, 205],444 [564, 205],445 [565, 205],446 [566, 205],447 [599, 205],448 [600, NaN],449 ]);450 checkRect(grouped.rects[0], 'A', 0, 0, bladeWidth, 0);451 const nestedArea = grouped.nestedAreas[0];452 checkArea(nestedArea, 890, 600, 905, 0, bladeWidth, 0, 2, 1);453 checkRemainingWidth(nestedArea, [454 [0, 0],455 [395, 140],456 ]);457 checkRect(nestedArea.rects[0], 'B', 0, 0, bladeWidth, bladeWidth);458 checkRect(nestedArea.rects[1], 'B', 445, 0, 0, bladeWidth);459 checkArea(nestedArea.nestedAreas[0], 745, 205, 0, 395, bladeWidth, 0, 3, 1);460 checkRemainingWidth(nestedArea.nestedAreas[0], [461 [0, 0],462 [70, 35],463 ]);464 checkRect(nestedArea.nestedAreas[0].rects[0], 'D', 0, 0, 0, bladeWidth);465 checkRect(nestedArea.nestedAreas[0].rects[1], 'E', 0, 35, bladeWidth, bladeWidth);466 checkRect(nestedArea.nestedAreas[0].rects[2], 'E', 372, 35, 1, bladeWidth);467 const nestedNestedArea = nestedArea.nestedAreas[0].nestedAreas[0];468 checkArea(nestedNestedArea, 705, 135, 0, 70, bladeWidth, 0, 2, 0);469 checkRemainingWidth(nestedNestedArea, [470 [0, 0],471 [74, 0],472 ]);473 checkRect(nestedNestedArea.rects[0], 'C', 0, 0, 0, bladeWidth);474 checkRect(nestedNestedArea.rects[1], 'C', 0, 65, 0, bladeWidth);475 });476 it('should add 20 tiny rects in one block (GT22)', () => {477 const rects = getRects(testItems.gt22);478 const grouped = getSheetArea(testItems.gt22);479 new Grouper(bladeWidth).group(rects, grouped);480 checkArea(grouped, 2000, 600, 0, 0, 0, 0, 21, 1);481 checkRemainingWidth(grouped, [482 [0, 0],483 [549, 0],484 [550, 205],485 [558, 205],486 [559, 205],487 [560, 205],488 [561, 205],489 [562, 205],490 [563, 205],491 [564, 205],492 [565, 205],493 [566, 205],494 [599, 205],495 [600, NaN],496 ]);497 checkRect(grouped.rects[0], 'A', 0, 0, bladeWidth, 0);498 let posY = 0;499 for (let r = 1; r < 21; r += 2) {500 checkRect(grouped.rects[r], 'E', 1795, posY, bladeWidth, bladeWidth);501 checkRect(grouped.rects[r + 1], 'E', 1900, posY, 0, bladeWidth);502 posY += 55;503 }504 const nestedArea = grouped.nestedAreas[0];505 checkArea(nestedArea, 890, 600, 905, 0, bladeWidth, 0, 2, 1);506 checkRemainingWidth(nestedArea, [507 [0, 0],508 [395, 140],509 ]);510 checkRect(nestedArea.rects[0], 'B', 0, 0, bladeWidth, bladeWidth);511 checkRect(nestedArea.rects[1], 'B', 445, 0, 0, bladeWidth);512 checkArea(nestedArea.nestedAreas[0], 745, 205, 0, 395, bladeWidth, 0, 2, 1);513 checkRemainingWidth(nestedArea.nestedAreas[0], [514 [0, 0],515 [70, 35],516 ]);517 checkRect(nestedArea.nestedAreas[0].rects[0], 'D', 0, 0, 0, bladeWidth);518 checkRect(nestedArea.nestedAreas[0].rects[1], 'D', 0, 35, 0, bladeWidth);519 const nestedNestedArea = nestedArea.nestedAreas[0].nestedAreas[0];520 checkArea(nestedNestedArea, 705, 135, 0, 70, bladeWidth, 0, 2, 0);521 checkRemainingWidth(nestedNestedArea, [522 [0, 0],523 [74, 0],524 ]);525 checkRect(nestedNestedArea.rects[0], 'C', 0, 0, 0, bladeWidth);526 checkRect(nestedNestedArea.rects[1], 'C', 0, 65, 0, bladeWidth);527 });528 it('should add 25 tiny rects in one block (GT23)', () => {529 const rects = getRects(testItems.gt23);530 const grouped = getSheetArea(testItems.gt23);531 new Grouper(bladeWidth).group(rects, grouped);532 checkArea(grouped, 2000, 600, 0, 0, 0, 0, 23, 1);533 checkRemainingWidth(grouped, [534 [0, 0],535 [549, 0],536 [550, 0],537 [558, 0],538 [559, 0],539 [560, 0],540 [561, 0],541 [562, 0],542 [563, 0],543 [564, 0],544 [565, 0],545 [566, 0],546 [599, 0],547 [600, NaN],548 ]);549 checkRect(grouped.rects[0], 'A', 0, 0, bladeWidth, 0);550 let posY = 0;551 for (let r = 1; r < 21; r += 2) {552 checkRect(grouped.rects[r], 'E', 1795, posY, bladeWidth, bladeWidth);553 checkRect(grouped.rects[r + 1], 'E', 1900, posY, 0, bladeWidth);554 posY += 55;555 }556 checkRect(grouped.rects[21], 'E', 1795, 550, bladeWidth, 0);557 checkRect(grouped.rects[22], 'E', 1900, 550, 0, 0);558 const nestedArea = grouped.nestedAreas[0];559 checkArea(nestedArea, 890, 600, 905, 0, bladeWidth, 0, 2, 2);560 checkRemainingWidth(nestedArea, [561 [0, 0],562 [395, 0],563 [559, 0],564 [560, 140],565 ]);566 checkRect(nestedArea.rects[0], 'B', 0, 0, bladeWidth, bladeWidth);567 checkRect(nestedArea.rects[1], 'B', 445, 0, 0, bladeWidth);568 checkArea(nestedArea.nestedAreas[0], 745, 205, 0, 395, bladeWidth, 0, 2, 1);569 checkRemainingWidth(nestedArea.nestedAreas[0], [570 [0, 0],571 [70, 35],572 ]);573 checkRect(nestedArea.nestedAreas[0].rects[0], 'D', 0, 0, 0, bladeWidth);574 checkRect(nestedArea.nestedAreas[0].rects[1], 'D', 0, 35, 0, bladeWidth);575 checkArea(nestedArea.nestedAreas[1], 140, 165, 745, 395, 0, bladeWidth, 3, 0);576 checkRemainingWidth(nestedArea.nestedAreas[1], [577 [0, 35],578 [70, 35],579 [139, 35],580 ]);581 checkRect(nestedArea.nestedAreas[1].rects[0], 'E', 0, 0, bladeWidth, bladeWidth);582 checkRect(nestedArea.nestedAreas[1].rects[1], 'E', 0, 55, bladeWidth, bladeWidth);583 checkRect(nestedArea.nestedAreas[1].rects[2], 'E', 0, 110, bladeWidth, 0);584 const nestedNestedArea = nestedArea.nestedAreas[0].nestedAreas[0];585 checkArea(nestedNestedArea, 705, 135, 0, 70, bladeWidth, 0, 2, 0);586 checkRemainingWidth(nestedNestedArea, [587 [0, 0],588 [74, 0],589 ]);590 checkRect(nestedNestedArea.rects[0], 'C', 0, 0, 0, bladeWidth);591 checkRect(nestedNestedArea.rects[1], 'C', 0, 65, 0, bladeWidth);592 });593 it('should pack all items in the most compact way (GT24)', () => {594 const rects = getRects(testItems.gt24);595 const grouped = getSheetArea(testItems.gt24);596 new Grouper(bladeWidth).group(rects, grouped);597 checkArea(grouped, 2000, 600, 0, 0, 0, 0, 0, 1);598 checkRemainingWidth(grouped, [599 [0, 950],600 [566, 950],601 [599, 950],602 [600, NaN],603 ]);604 const nestedArea = grouped.nestedAreas[0];605 checkArea(nestedArea, 1050, 600, 0, 0, bladeWidth, 0, 20, 1);606 checkRemainingWidth(nestedArea, [607 [0, 0],608 [110, 35],609 [395, 35],610 [489, 35],611 [599, 35],612 ]);613 for (let r = 0; r < 10; r += 1) {614 checkRect(nestedArea.rects[r], 'D', r * 105, 0, r === 9 ? 0 : bladeWidth, bladeWidth);615 }616 for (let r = 10; r < 20; r += 1) {617 checkRect(618 nestedArea.rects[r],619 'D',620 (r - 10) * 105,621 55,622 r === 19 ? 0 : bladeWidth,623 bladeWidth,624 );625 }626 const nestedArea1 = nestedArea.nestedAreas[0];627 checkArea(nestedArea1, 1010, 490, 0, 110, bladeWidth, 0, 4, 1);628 checkRemainingWidth(nestedArea1, [629 [0, 0],630 [100, 115],631 [395, 115],632 [489, 115],633 ]);634 checkRect(nestedArea1.rects[0], 'C', 0, 0, bladeWidth, bladeWidth);635 checkRect(nestedArea1.rects[1], 'C', 505, 0, 0, bladeWidth);636 checkRect(nestedArea1.rects[2], 'B', 0, 65, bladeWidth, bladeWidth);637 checkRect(nestedArea1.rects[3], 'B', 505, 65, 0, bladeWidth);638 const nestedArea2 = nestedArea1.nestedAreas[0];639 checkArea(nestedArea2, 890, 390, 0, 100, bladeWidth, 0, 2, 0);640 checkRemainingWidth(nestedArea2, [641 [0, 0],642 [389, 0],643 ]);644 checkRect(nestedArea2.rects[0], 'A', 0, 0, bladeWidth, 0);645 checkRect(nestedArea2.rects[1], 'A', 445, 0, 0, 0);646 });647 it('should pack all items in the most compact way (GT25)', () => {648 const rects = getRects(testItems.gt25);649 const grouped = getSheetArea(testItems.gt25);650 new Grouper(bladeWidth).group(rects, grouped);651 checkArea(grouped, 2000, 600, 0, 0, 0, 0, 0, 1);652 checkRemainingWidth(grouped, [653 [0, 950],654 [566, 950],655 [599, 950],656 [600, NaN],657 ]);658 const nestedArea = grouped.nestedAreas[0];659 checkArea(nestedArea, 1050, 600, 0, 0, bladeWidth, 0, 20, 1);660 checkRemainingWidth(nestedArea, [661 [0, 0],662 [110, 35],663 [395, 35],664 [489, 35],665 [599, 35],666 ]);667 for (let r = 0; r < 10; r += 1) {668 checkRect(nestedArea.rects[r], 'D', r * 105, 0, r === 9 ? 0 : bladeWidth, bladeWidth);669 }670 for (let r = 10; r < 20; r += 1) {671 checkRect(672 nestedArea.rects[r],673 'D',674 (r - 10) * 105,675 55,676 r === 19 ? 0 : bladeWidth,677 bladeWidth,678 );679 }680 const nestedArea1 = nestedArea.nestedAreas[0];681 checkArea(nestedArea1, 1010, 490, 0, 110, bladeWidth, 0, 4, 2);682 checkRemainingWidth(nestedArea1, [683 [0, 0],684 [100, 0],685 [155, 115],686 [395, 115],687 [489, 115],688 ]);689 checkRect(nestedArea1.rects[0], 'C', 0, 0, bladeWidth, bladeWidth);690 checkRect(nestedArea1.rects[1], 'C', 505, 0, 0, bladeWidth);691 checkRect(nestedArea1.rects[2], 'B', 0, 65, bladeWidth, bladeWidth);692 checkRect(nestedArea1.rects[3], 'B', 505, 65, 0, bladeWidth);693 const nestedArea2 = nestedArea1.nestedAreas[0];694 checkArea(nestedArea2, 890, 390, 0, 100, bladeWidth, 0, 2, 0);695 checkRemainingWidth(nestedArea2, [696 [0, 0],697 [389, 0],698 ]);699 checkRect(nestedArea2.rects[0], 'A', 0, 0, bladeWidth, 0);700 checkRect(nestedArea2.rects[1], 'A', 445, 0, 0, 0);701 const nestedArea3 = nestedArea1.nestedAreas[1];702 checkArea(nestedArea3, 115, 55, 890, 100, 0, bladeWidth, 1, 0);703 checkRemainingWidth(nestedArea3, [704 [0, 10],705 [49, 10],706 ]);707 checkRect(nestedArea3.rects[0], 'D', 0, 0, bladeWidth, 0);708 });709});710describe('Grouper for OSB sheets', () => {711 it('should group sheet 1 correct', () => {712 const rects = getRects(osbItems.s1);713 const grouped = getSheetArea(osbItems.s1);714 new Grouper(bladeWidth).group(rects, grouped);715 checkArea(grouped, 2040, 665, 0, 0, 0, 0, 0, 2);716 const area1 = grouped.nestedAreas[0];717 checkArea(area1, 1750, 665, 0, 0, bladeWidth, 0, 2, 0);718 checkRect(area1.rects[0], 'A', 0, 0, bladeWidth, bladeWidth);719 checkRect(area1.rects[1], 'A', 875, 0, 0, bladeWidth);720 const area3 = grouped.nestedAreas[1];721 checkArea(area3, 290, 625, 1750, 0, 0, bladeWidth, 2, 0);722 checkRect(area3.rects[0], 'B', 0, 0, bladeWidth, 0);723 checkRect(area3.rects[1], 'C', 205, 0, bladeWidth, 0);724 });725 it('should group sheet 2 correct', () => {726 const rects = getRects(osbItems.s2);727 const grouped = getSheetArea(osbItems.s2);728 new Grouper(bladeWidth).group(rects, grouped);729 checkArea(grouped, 2040, 665, 0, 0, 0, 0, 0, 1);730 const area1 = grouped.nestedAreas[0];731 checkArea(area1, 2040, 625, 0, 0, 0, bladeWidth, 5, 0);732 checkRect(area1.rects[0], 'A', 0, 0, bladeWidth, 0);733 checkRect(area1.rects[1], 'A', 850, 0, bladeWidth, 0);734 checkRect(area1.rects[2], 'B', 1700, 0, bladeWidth, 0);735 checkRect(area1.rects[3], 'C', 1905, 0, bladeWidth, 0);736 checkRect(area1.rects[4], 'C', 1970, 0, bladeWidth, 0);737 });738 it('should group sheet 3 correct', () => {739 const rects = getRects(osbItems.s3);740 const grouped = getSheetArea(osbItems.s3);741 new Grouper(bladeWidth).group(rects, grouped);742 checkArea(grouped, 2040, 665, 0, 0, 0, 0, 0, 1);743 const area1 = grouped.nestedAreas[0];744 checkArea(area1, 2040, 625, 0, 0, 0, bladeWidth, 6, 0);745 checkRect(area1.rects[0], 'A', 0, 0, bladeWidth, 0);746 checkRect(area1.rects[1], 'D', 850, 0, bladeWidth, 0);747 checkRect(area1.rects[2], 'E', 1055, 0, bladeWidth, 0);748 checkRect(area1.rects[3], 'C', 1160, 0, bladeWidth, bladeWidth);749 checkRect(area1.rects[4], 'C', 1160, 263, bladeWidth, bladeWidth);750 checkRect(area1.rects[5], 'B', 1160, 526, bladeWidth, 2);751 });752 it('should group sheet 4 correct', () => {753 const rects = getRects(osbItems.s4);754 const grouped = getSheetArea(osbItems.s4);755 new Grouper(bladeWidth).group(rects, grouped);756 checkArea(grouped, 2040, 665, 0, 0, 0, 0, 0, 1);757 const area1 = grouped.nestedAreas[0];758 checkArea(area1, 2040, 625, 0, 0, 0, bladeWidth, 4, 0);759 checkRect(area1.rects[0], 'A', 0, 0, bladeWidth, 0);760 checkRect(area1.rects[1], 'A', 850, 0, bladeWidth, 0);761 checkRect(area1.rects[2], 'B', 1700, 0, bladeWidth, 0);762 checkRect(area1.rects[3], 'C', 1905, 0, bladeWidth, 0);763 });764 it('should group sheet 5 correct', () => {765 const rects = getRects(osbItems.s5);766 const grouped = getSheetArea(osbItems.s5);767 new Grouper(bladeWidth).group(rects, grouped);768 checkArea(grouped, 2040, 665, 0, 0, 0, 0, 0, 1);769 const area1 = grouped.nestedAreas[0];770 checkArea(area1, 2040, 625, 0, 0, 0, bladeWidth, 5, 0);771 checkRect(area1.rects[0], 'A', 0, 0, bladeWidth, 0);772 checkRect(area1.rects[1], 'A', 850, 0, bladeWidth, 0);773 checkRect(area1.rects[2], 'B', 1700, 0, bladeWidth, 0);774 checkRect(area1.rects[3], 'B', 1805, 0, bladeWidth, 0);775 checkRect(area1.rects[4], 'B', 1910, 0, bladeWidth, 0);776 });777 it('should group sheet 6 correct', () => {778 const rects = getRects(osbItems.s6);779 const grouped = getSheetArea(osbItems.s6);780 new Grouper(bladeWidth).group(rects, grouped);781 checkArea(grouped, 2040, 665, 0, 0, 0, 0, 0, 1);782 const area1 = grouped.nestedAreas[0];783 checkArea(area1, 2040, 625, 0, 0, bladeWidth, bladeWidth, 9, 1);784 checkRect(area1.rects[0], 'A', 0, 0, bladeWidth, 0);785 checkRect(area1.rects[1], 'D', 850, 0, bladeWidth, 0);786 checkRect(area1.rects[2], 'D', 955, 0, bladeWidth, 0);787 checkRect(area1.rects[3], 'D', 1060, 0, bladeWidth, 0);788 checkRect(area1.rects[4], 'C', 1165, 0, 4, bladeWidth);789 checkRect(area1.rects[5], 'C', 1165, 149, 4, bladeWidth);790 checkRect(area1.rects[6], 'C', 1165, 298, 4, bladeWidth);791 checkRect(area1.rects[7], 'B', 1165, 447, 0, bladeWidth);792 checkRect(area1.rects[8], 'B', 1165, 502, 0, bladeWidth);793 checkArea(area1.nestedAreas[0], 870, 63, 1165, 557, 0, 3, 1, 0);794 checkRect(area1.nestedAreas[0].rects[0], 'E', 0, 0, bladeWidth, 0);795 });796 it('should group sheet 7 correct', () => {797 const rects = getRects(osbItems.s7);798 const grouped = getSheetArea(osbItems.s7);799 new Grouper(bladeWidth).group(rects, grouped);800 checkArea(grouped, 2040, 665, 0, 0, 0, 0, 0, 3);801 const area1 = grouped.nestedAreas[0];802 checkArea(area1, 871, 665, 0, 0, bladeWidth, 0, 3, 1);803 checkRect(area1.rects[0], 'F', 0, 0, 0, bladeWidth);804 checkRect(area1.rects[1], 'F', 0, 149, 0, bladeWidth);805 checkRect(area1.rects[2], 'F', 0, 298, 0, bladeWidth);806 checkArea(area1.nestedAreas[0], 826, 218, 0, 447, bladeWidth, 0, 1, 0);807 checkRect(area1.nestedAreas[0].rects[0], 'C', 0, 0, 0, bladeWidth);808 const area2 = grouped.nestedAreas[1];809 checkArea(area2, 875, 665, 871, 0, bladeWidth, 0, 2, 1);810 checkRect(area2.rects[0], 'D', 0, 0, 0, bladeWidth);811 checkRect(area2.rects[1], 'D', 0, 55, 0, bladeWidth);812 checkArea(area2.nestedAreas[0], 870, 480, 0, 110, 0, bladeWidth, 4, 0);813 checkRect(area2.nestedAreas[0].rects[0], 'C', 0, 0, bladeWidth, bladeWidth);814 checkRect(area2.nestedAreas[0].rects[1], 'B', 0, 205, bladeWidth, bladeWidth);815 checkRect(area2.nestedAreas[0].rects[2], 'B', 0, 310, bladeWidth, bladeWidth);816 checkRect(area2.nestedAreas[0].rects[3], 'E', 0, 415, bladeWidth, 0);817 const area3 = grouped.nestedAreas[2];818 checkArea(area3, 170, 665, 1746, 0, bladeWidth, 0, 2, 0);819 checkRect(area3.rects[0], 'G', 0, 0, bladeWidth, bladeWidth);820 checkRect(area3.rects[1], 'A', 105, 0, 0, bladeWidth);821 });822 it('should group sheet 8 correct', () => {823 const rects = getRects(osbItems.s8);824 const grouped = getSheetArea(osbItems.s8);825 new Grouper(bladeWidth).group(rects, grouped);826 checkArea(grouped, 2040, 665, 0, 0, 0, 0, 0, 2);827 const area1 = grouped.nestedAreas[0];828 checkArea(area1, 826, 665, 0, 0, bladeWidth, 0, 4, 0);829 checkRect(area1.rects[0], 'A', 0, 0, 0, bladeWidth);830 checkRect(area1.rects[1], 'A', 0, 205, 0, bladeWidth);831 checkRect(area1.rects[2], 'C', 0, 410, 0, bladeWidth);832 checkRect(area1.rects[3], 'C', 0, 515, 0, bladeWidth);833 const area2 = grouped.nestedAreas[1];834 checkArea(area2, 826, 665, 826, 0, bladeWidth, 0, 7, 0);835 checkRect(area2.rects[0], 'C', 0, 0, 0, bladeWidth);836 checkRect(area2.rects[1], 'C', 0, 105, 0, bladeWidth);837 checkRect(area2.rects[2], 'C', 0, 210, 0, bladeWidth);838 checkRect(area2.rects[3], 'C', 0, 315, 0, bladeWidth);839 checkRect(area2.rects[4], 'C', 0, 420, 0, bladeWidth);840 checkRect(area2.rects[5], 'B', 0, 525, 0, bladeWidth);841 checkRect(area2.rects[6], 'B', 0, 590, 0, bladeWidth);842 });843 it('should group sheet 9 correct', () => {844 const rects = getRects(osbItems.s9);845 const grouped = getSheetArea(osbItems.s9);846 new Grouper(bladeWidth).group(rects, grouped);847 checkArea(grouped, 2040, 665, 0, 0, 0, 0, 0, 1);848 const area1 = grouped.nestedAreas[0];849 checkArea(area1, 871, 665, 0, 0, bladeWidth, 0, 1, 1);850 checkRect(area1.rects[0], 'B', 0, 0, 0, bladeWidth);851 checkArea(area1.nestedAreas[0], 866, 315, 0, 97, 0, bladeWidth, 3, 0);852 checkRect(area1.nestedAreas[0].rects[0], 'A', 0, 0, bladeWidth, bladeWidth);853 checkRect(area1.nestedAreas[0].rects[1], 'A', 0, 105, bladeWidth, bladeWidth);854 checkRect(area1.nestedAreas[0].rects[2], 'A', 0, 210, bladeWidth, 0);855 });856 it('should group sheet 10 correct', () => {857 const rects = getRects(osbItems.s10);858 const grouped = getSheetArea(osbItems.s10);859 new Grouper(bladeWidth).group(rects, grouped);860 checkArea(grouped, 2040, 665, 0, 0, 0, 0, 0, 1);861 const area1 = grouped.nestedAreas[0];862 checkArea(area1, 1810, 665, 0, 0, bladeWidth, 0, 2, 0);863 checkRect(area1.rects[0], 'A', 0, 0, bladeWidth, bladeWidth);864 checkRect(area1.rects[1], 'A', 905, 0, 0, bladeWidth);865 });866 it('should group sheet 11 correct', () => {867 const rects = getRects(osbItems.s11);868 const grouped = getSheetArea(osbItems.s11);869 new Grouper(bladeWidth).group(rects, grouped);870 checkArea(grouped, 2040, 665, 0, 0, 0, 0, 0, 1);871 const area1 = grouped.nestedAreas[0];872 checkArea(area1, 2040, 210, 0, 0, 0, bladeWidth, 4, 0);873 checkRect(area1.rects[0], 'A', 0, 0, bladeWidth, bladeWidth);874 checkRect(area1.rects[1], 'A', 875, 0, bladeWidth, bladeWidth);875 checkRect(area1.rects[2], 'A', 0, 105, bladeWidth, 0);876 checkRect(area1.rects[3], 'A', 875, 105, bladeWidth, 0);877 });...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1/**2 * @file bdml's file's base elements <TrackLog>3 * @author wangyang(wangyang02@baidu.com)4 */5import style from './index.css';6import {config} from './config';7import {attrValBool} from '../utils';8import getObserverInstance from '../utils/getObserverInstance';9/**10 * 基础数据11 *12 * @type {Object}13 */14const logData = {};15export default {16 constructor(props) {17 /**18 * 判断可视状态的计时器id19 * 被置为0时表示当前没有在计时20 *21 * @type {number}22 */23 this.visibleTimer = 0;24 /**25 * 是否已经发送了可视展现日志26 *27 * @type {boolean}28 */29 this.isVisibleLogged = false;30 },31 behaviors: ['userTouchEvents', 'noNativeBehavior', 'animateEffect'],32 template: '<swan-track-log s-ref="trackEle"><slot></slot></swan-track-log>',33 initData() {34 return {35 type: '',36 params: '',37 visibleRatio: config.defaultVisibleRatio,38 visibleDuration: config.defaultVisibleDuration,39 coveringDetection: false,40 loadLog: false41 };42 },43 /**44 * 发送请求45 *46 * @param {string} options.url 请求url47 * @param {Object} options.data 要发送的数据,会跟logData中已有的字段合并48 * @param {string} [options.method = 'POST'] 请求方式,可选49 * @param {Object} [options.header = {}] 请求头,可选50 * @param {string} [options.dataType = 'json'] 响应类型,可选51 * @param {Function} [options.success] 请求成功的回调函数,可选52 * @param {Function} [options.fail] 请求失败的回调函数,可选53 * @param {number} [retryDelay = 1000] 如果请求失败,在重试之前需要延迟的时间,单位是ms,可选,默认100054 */55 request(options, retryDelay = config.requestRetryFirstDelay) {56 this.swan.request({57 url: options.url,58 data: options.data,59 method: options.method || 'POST',60 header: Object.assign({61 'content-type': 'application/json'62 }, options.header),63 dataType: options.dataType || 'json',64 success(res) {65 delete options.data.rtc;66 options.success && options.success(res);67 },68 fail(err) {69 options.data.rtc = (options.data.rtc || 0) + 1;70 if (options.data.rtc <= config.maxRequestRetryCount) {71 setTimeout(() => this.request(options, retryDelay * config.requestRetryMultiple), retryDelay);72 }73 else {74 options.data.rtc = 0;75 options.fail && options.fail(err);76 }77 }78 });79 },80 /**81 * 获取网络类型82 *83 * @return {Promise<Object>} 返回网络类型对象84 */85 getNetworkType() {86 if (logData.networkType) {87 return Promise.resolve(logData.networkType);88 }89 return this.boxjs.device.networkType().then(res => {90 logData.networkType = res.networkType;91 });92 },93 /**94 * 发送事件日志95 *96 * @param {Object} data 参数97 */98 trackEvent(data) {99 // 先从小程序存储中读取百度统计sdk写的mtj_key100 if (!logData.keyData) {101 logData.keyData = this.swan.getStorageSync('mtj_key');102 logData.uuid = this.swan.getStorageSync('mtj_uuid');103 }104 // 移动统计sdk获取key要访问手百的服务器,速度可能会比较慢,需要重试机制105 if (!logData.keyData) {106 setTimeout(() => this.trackEvent(data), config.getKeyRetryDelay);107 return;108 }109 logData.sid = logData.sid || Math.floor(Math.random() * 0xffffffff);110 logData.rqc = (logData.rqc || 0) + 1;111 if (!logData.appInfo) {112 logData.appInfo = this.boxjs.data.get({name: 'swan-appInfoSync'});113 }114 if (!logData.systemInfo) {115 logData.systemInfo = this.boxjs.device.systemInfo({type: 'sync'});116 }117 this.getNetworkType().then(networkType => this.request({118 url: config.logServerUrl,119 dataType: 'text',120 data: Object.assign({121 type: 0,122 key: logData.keyData.bdstatistic_key,123 officialNo: logData.keyData.official_no,124 containerNo: logData.keyData.container_no,125 uuid: logData.uuid,126 appid: logData.appInfo.appid,127 cuid: logData.appInfo.cuid,128 mtjcuid: logData.appInfo.mtjCuid,129 aso: {130 scene: '' + (logData.appInfo.scene || '')131 },132 system: {133 version: logData.systemInfo.version,134 SDKVersion: logData.systemInfo.SDKVersion,135 system: logData.systemInfo.system136 },137 network: {138 networkType139 },140 sid: logData.sid,141 rid: Math.floor(Math.random() * 0xffffffff),142 rqc: logData.rqc143 }, data)144 }));145 },146 /**147 * 发送track-log组件的事件日志148 *149 * @param {string} eventName 事件名称150 */151 sendTrackLogEvent(eventName) {152 this.trackEvent({153 et: 'tracklog',154 en: eventName,155 ep: {156 type: this.type,157 params: this.params158 }159 });160 },161 /**162 * 获取当前组件的可视状态163 * 可视状态取决于两个条件:164 * 1.是否位于屏幕可视区域内165 * 2.是否被其他元素遮挡166 *167 * @return {boolean} 当前组件的可视状态168 */169 getVisibility() {170 /**171 * 当前组件元素的位置和宽高172 *173 * @type {DOMRect}174 */175 const elRect = this.el.getBoundingClientRect();176 /**177 * 用来判断可视状态的检测区域178 * 如果visibleRatio大于0.5,该区域是个正常的矩形179 * 如果visibleRatio等于0.5,该区域为1x1或2x2,位于元素正中心180 * 如果visibleRatio小于0.5,该区域的top在bottom下面,left在right右侧181 *182 * @type {Object}183 */184 const checkRect = {185 top: elRect.bottom - elRect.height * this.visibleRatio + 1,186 bottom: elRect.top + elRect.height * this.visibleRatio - 1,187 left: elRect.right - elRect.width * this.visibleRatio + 1,188 right: elRect.left + elRect.width * this.visibleRatio - 1189 };190 // 如果检测区域的任意一个边界超出屏幕,则认为不可视191 if (checkRect.top < 0192 || checkRect.bottom >= window.innerHeight193 || checkRect.left < 0194 || checkRect.right >= window.innerWidth) {195 return false;196 }197 // 如果不识别遮挡,到这里就可以认为是可视了,直接返回true198 if (!this.coveringDetection) {199 return true;200 }201 // 为提高效率,如果visibleRatio等于0.5,只要一个中心点没有被遮挡就算可视202 if (this.visibleRatio === 0.5) {203 return this.el.contains(document.elementFromPoint(checkRect.left, checkRect.top));204 }205 /**206 * 用来判断遮挡情况的检测点数组207 *208 * @type {Array}209 */210 const checkPoints = [211 [checkRect.left, checkRect.top],212 [checkRect.right, checkRect.top],213 [checkRect.left, checkRect.bottom],214 [checkRect.right, checkRect.bottom]215 ];216 /**217 * 没有被其他元素遮挡的检测点数组218 *219 * @type {Array}220 */221 const visiblePoints = checkPoints.filter(([x, y]) => this.el.contains(document.elementFromPoint(x, y)));222 // 如果visibleRatio小于0.5,只要2个检测点没有被遮挡就算可视223 // 否则需要4个检测点都没有被遮挡才算可视224 return (this.visibleRatio < 0.5 && visiblePoints.length >= 2) || visiblePoints.length === 4;225 },226 /**227 * 检测可视展现状态,可视时长超过visibileDuration才算一次可视展现228 */229 checkVisibleDuration() {230 // 满足这些条件就直接返回:已经发过可视展现日志,或正在计时中,或当前不可视231 if (this.isVisibleLogged) {232 return;233 }234 const visibilityObserver = getObserverInstance('track-log', {235 threshold: [0, .5]236 });237 // this.enterTime = Date.now(); // 默认可见238 visibilityObserver.observe(this.el, entry => {239 const {240 intersectionRatio,241 isIntersecting,242 time,243 target244 } = entry;245 if (!this.starTime && intersectionRatio > 0.5) {246 this.starTime = time;247 }248 if (!isIntersecting && this.starTime) {249 if (time - this.starTime >= this.visibleDuration) {250 visibilityObserver.unobserve(target);251 this.isVisibleLogged = true;252 this.dispatch('visible');253 this.sendTrackLogEvent('visible');254 }255 else {256 this.starTime = 0;257 }258 }259 });260 },261 compiled() {262 // 监控点击263 this.bindAction('bindtap', () => this.sendTrackLogEvent('tap'));264 },265 attached() {266 /**267 * 组件类型,用于记录日志268 *269 * @type {string}270 */271 this.type = this.data.get('type');272 /**273 * 组件参数,用于记录日志274 *275 * @type {string}276 */277 this.params = this.data.get('params');278 /**279 * 用户自定义的可视展现比例280 *281 * @type {number}282 */283 const userDefinedVisibleRatio = +this.data.get('visibleRatio');284 if (userDefinedVisibleRatio > 0 && userDefinedVisibleRatio <= 1) {285 this.visibleRatio = userDefinedVisibleRatio;286 }287 /**288 * 用户自定义的可视展现时长289 *290 * @type {number}291 */292 const userDefinedVisibleDuration = +this.data.get('visibleDuration');293 if (Number.isSafeInteger(userDefinedVisibleDuration) && userDefinedVisibleDuration >= 0) {294 this.visibleDuration = userDefinedVisibleDuration;295 }296 /**297 * 是否识别遮挡298 *299 * @type {boolean}300 */301 this.coveringDetection = attrValBool(this.data.get('coveringDetection'));302 /**303 * 是否发送展现日志304 *305 * @type {boolean}306 */307 this.loadLog = attrValBool(this.data.get('loadLog'));308 if (this.loadLog) {309 this.sendTrackLogEvent('load');310 }311 // 监控可视展现312 this.checkVisibleDuration();313 }...

Full Screen

Full Screen

intersection-observer-test-utils.js

Source:intersection-observer-test-utils.js Github

copy

Full Screen

...63}64function rectArea(rect) {65 return (rect.left - rect.right) * (rect.bottom - rect.top);66}67function checkRect(actual, expected, description, all) {68 if (!expected.length)69 return;70 assert_equals(actual.left | 0, expected[0] | 0, description + '.left');71 assert_equals(actual.right | 0, expected[1] | 0, description + '.right');72 assert_equals(actual.top | 0, expected[2] | 0, description + '.top');73 assert_equals(actual.bottom | 0, expected[3] | 0, description + '.bottom');74}75function checkLastEntry(entries, i, expected) {76 assert_equals(entries.length, i + 1, 'entries.length');77 if (expected) {78 checkRect(79 entries[i].boundingClientRect, expected.slice(0, 4),80 'entries[' + i + '].boundingClientRect', entries[i]);81 checkRect(82 entries[i].intersectionRect, expected.slice(4, 8),83 'entries[' + i + '].intersectionRect', entries[i]);84 checkRect(85 entries[i].rootBounds, expected.slice(8, 12),86 'entries[' + i + '].rootBounds', entries[i]);87 if (expected.length > 12) {88 assert_equals(89 entries[i].isIntersecting, expected[12],90 'entries[' + i + '].isIntersecting');91 }92 }93}94function checkJsonEntry(actual, expected) {95 checkRect(96 actual.boundingClientRect, expected.boundingClientRect,97 'entry.boundingClientRect');98 checkRect(99 actual.intersectionRect, expected.intersectionRect,100 'entry.intersectionRect');101 if (actual.rootBounds == 'null')102 assert_equals(expected.rootBounds, 'null', 'rootBounds is null');103 else104 checkRect(actual.rootBounds, expected.rootBounds, 'entry.rootBounds');105 assert_equals(actual.target, expected.target);106}107function checkJsonEntries(actual, expected, description) {108 test(function() {109 assert_equals(actual.length, expected.length);110 for (var i = 0; i < actual.length; i++)111 checkJsonEntry(actual[i], expected[i]);112 }, description);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.checkRect(1234, 0, 0, 100, 100, function(err, data) {4 if (err) return console.log(err);5 console.log(data);6});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolbox = require('wptoolbox');2var rect = {"x":0,"y":0,"width":100,"height":100};3var point = {"x":50,"y":50};4var result = wptoolbox.checkRect(rect, point);5#### checkRect(rect, point)6var wptoolbox = require('wptoolbox');7var point1 = {"x":0,"y":0};8var point2 = {"x":100,"y":100};9var result = wptoolbox.checkPoint(point1, point2);10#### checkPoint(point1, point2)11var wptoolbox = require('wptoolbox');12var array1 = [1,2,3];13var array2 = [1,2,3];14var result = wptoolbox.checkArray(array1, array2);15#### checkArray(array1, array2)16var wptoolbox = require('wptoolbox');17var obj1 = {"x":0,"y":0};18var obj2 = {"x":0,"y":0};19var result = wptoolbox.checkObject(obj1, obj2);20#### checkObject(obj1, obj2)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2wpt.checkRect(url, 0, 0, 100, 100, function(err, result) {3 if (err) {4 console.error(err);5 } else {6 console.log(result);7 }8});9var wpt = require('./wpt.js');10wpt.checkText(url, 0, 0, 100, 100, function(err, result) {11 if (err) {12 console.error(err);13 } else {14 console.log(result);15 }16});17var wpt = require('./wpt.js');18wpt.checkVideo(url, 0, 0, 100, 100, function(err, result) {19 if (err) {20 console.error(err);21 } else {22 console.log(result);23 }24});25var wpt = require('./wpt.js');26wpt.clearCache(url, function(err, result) {27 if (err) {28 console.error(err);29 } else {30 console.log(result);31 }32});33var wpt = require('./wpt.js');34wpt.clearCookies(url, function(err, result) {35 if (err) {36 console.error(err);37 } else {38 console.log(result);39 }40});41var wpt = require('./w

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptcheck = require('./wptcheck');2var wptcheckObj = new wptcheck();3var rect = {4};5var rect2 = {6};7var rect3 = {8};9var rect4 = {10};11var rect5 = {12};13var rect6 = {14};15var rect7 = {16};17var rect8 = {18};19var rect9 = {20};21var rect10 = {22};23var rect11 = {24};25var rect12 = {26};27var rect13 = {28};29var rect14 = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2var wpt = new WebPagetest('www.webpagetest.org');3wpt.checkRect(0, 0, 100, 100, function(err, data) {4 console.log(data);5});6### WebPagetest(key, host)7### WebPagetest.prototype.runTest(url, options, callback)8### WebPagetest.prototype.getTestResults(testId, callback)9### WebPagetest.prototype.getLocations(callback)10### WebPagetest.prototype.getTesters(callback)11### WebPagetest.prototype.getTestStatus(testId, callback)12### WebPagetest.prototype.checkRect(left, top, width, height, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wptoolkit.js');2var rect = {3};4var canvas = {5};6var result = wpt.checkRect(rect, canvas);7console.log(result);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful