|
@@ -297,7 +297,7 @@ export function calculateResponsiveTileViewDimensions({
|
297
|
297
|
noHorizontalContainerMargin = false,
|
298
|
298
|
maxColumns,
|
299
|
299
|
numberOfParticipants,
|
300
|
|
- numberOfVisibleTiles = TILE_VIEW_DEFAULT_NUMBER_OF_VISIBLE_TILES
|
|
300
|
+ desiredNumberOfVisibleTiles = TILE_VIEW_DEFAULT_NUMBER_OF_VISIBLE_TILES
|
301
|
301
|
}) {
|
302
|
302
|
let height, width;
|
303
|
303
|
let columns, rows;
|
|
@@ -311,12 +311,12 @@ export function calculateResponsiveTileViewDimensions({
|
311
|
311
|
maxArea: 0
|
312
|
312
|
};
|
313
|
313
|
|
314
|
|
- for (let c = 1; c <= Math.min(maxColumns, numberOfParticipants); c++) {
|
|
314
|
+ for (let c = 1; c <= Math.min(maxColumns, numberOfParticipants, desiredNumberOfVisibleTiles); c++) {
|
315
|
315
|
const r = Math.ceil(numberOfParticipants / c);
|
316
|
316
|
|
317
|
|
- // we want to display as much as possible tumbnails up to numberOfVisibleTiles
|
|
317
|
+ // we want to display as much as possible tumbnails up to desiredNumberOfVisibleTiles
|
318
|
318
|
const visibleRows
|
319
|
|
- = numberOfParticipants <= numberOfVisibleTiles ? r : Math.floor(numberOfVisibleTiles / c);
|
|
319
|
+ = numberOfParticipants <= desiredNumberOfVisibleTiles ? r : Math.floor(desiredNumberOfVisibleTiles / c);
|
320
|
320
|
|
321
|
321
|
const size = calculateThumbnailSizeForTileView({
|
322
|
322
|
columns: c,
|
|
@@ -330,18 +330,38 @@ export function calculateResponsiveTileViewDimensions({
|
330
|
330
|
|
331
|
331
|
if (size) {
|
332
|
332
|
const { height: currentHeight, width: currentWidth, minHeightEnforced, maxVisibleRows } = size;
|
333
|
|
- let area = currentHeight * currentWidth * Math.min(c * maxVisibleRows, numberOfParticipants);
|
|
333
|
+ const numberOfVisibleParticipants = Math.min(c * maxVisibleRows, numberOfParticipants);
|
|
334
|
+
|
|
335
|
+ let area = Math.round(
|
|
336
|
+ (currentHeight + TILE_VERTICAL_MARGIN)
|
|
337
|
+ * (currentWidth + TILE_HORIZONTAL_MARGIN)
|
|
338
|
+ * numberOfVisibleParticipants);
|
|
339
|
+
|
334
|
340
|
const currentDimensions = {
|
335
|
341
|
maxArea: area,
|
336
|
342
|
height: currentHeight,
|
337
|
343
|
width: currentWidth,
|
338
|
344
|
columns: c,
|
339
|
|
- rows: r
|
|
345
|
+ rows: r,
|
|
346
|
+ numberOfVisibleParticipants
|
340
|
347
|
};
|
341
|
|
-
|
342
|
|
- if (!minHeightEnforced && area > dimensions.maxArea) {
|
343
|
|
- dimensions = currentDimensions;
|
344
|
|
- } else if (minHeightEnforced && area > minHeightEnforcedDimensions.maxArea) {
|
|
348
|
+ const { numberOfVisibleParticipants: oldNumberOfVisibleParticipants = 0 } = dimensions;
|
|
349
|
+
|
|
350
|
+ if (!minHeightEnforced) {
|
|
351
|
+ if (area > dimensions.maxArea) {
|
|
352
|
+ dimensions = currentDimensions;
|
|
353
|
+ } else if ((area === dimensions.maxArea)
|
|
354
|
+ && ((oldNumberOfVisibleParticipants > desiredNumberOfVisibleTiles
|
|
355
|
+ && oldNumberOfVisibleParticipants >= numberOfParticipants)
|
|
356
|
+ || (oldNumberOfVisibleParticipants < numberOfParticipants
|
|
357
|
+ && numberOfVisibleParticipants <= desiredNumberOfVisibleTiles))
|
|
358
|
+ ) { // If the area of the new candidates and the old ones are equal we preffer the one that will have
|
|
359
|
+ // closer number of visible participants to desiredNumberOfVisibleTiles config.
|
|
360
|
+ dimensions = currentDimensions;
|
|
361
|
+ }
|
|
362
|
+ } else if (minHeightEnforced && area >= minHeightEnforcedDimensions.maxArea) {
|
|
363
|
+ // If we choose configuration with minHeightEnforced there will be less than desiredNumberOfVisibleTiles
|
|
364
|
+ // visible tiles, that's why we prefer more columns when the area is the same.
|
345
|
365
|
minHeightEnforcedDimensions = currentDimensions;
|
346
|
366
|
} else if (minHeightEnforced && maxVisibleRows === 0) {
|
347
|
367
|
area = currentHeight * currentWidth * Math.min(c, numberOfParticipants);
|
|
@@ -400,7 +420,8 @@ export function calculateThumbnailSizeForTileView({
|
400
|
420
|
const minHeight = getThumbnailMinHeight(clientWidth);
|
401
|
421
|
const viewWidth = clientWidth - (columns * TILE_HORIZONTAL_MARGIN)
|
402
|
422
|
- (noHorizontalContainerMargin ? SCROLL_SIZE : TILE_VIEW_GRID_HORIZONTAL_MARGIN);
|
403
|
|
- const viewHeight = clientHeight - (minVisibleRows * TILE_VERTICAL_MARGIN) - TILE_VIEW_GRID_VERTICAL_MARGIN;
|
|
423
|
+ const availableHeight = clientHeight - TILE_VIEW_GRID_VERTICAL_MARGIN;
|
|
424
|
+ const viewHeight = availableHeight - (minVisibleRows * TILE_VERTICAL_MARGIN);
|
404
|
425
|
const initialWidth = viewWidth / columns;
|
405
|
426
|
let initialHeight = viewHeight / minVisibleRows;
|
406
|
427
|
let minHeightEnforced = false;
|
|
@@ -417,52 +438,47 @@ export function calculateThumbnailSizeForTileView({
|
417
|
438
|
return;
|
418
|
439
|
}
|
419
|
440
|
|
420
|
|
- const height = Math.floor(Math.min(aspectRatioHeight, initialHeight));
|
|
441
|
+ const height = Math.min(aspectRatioHeight, initialHeight);
|
421
|
442
|
|
422
|
443
|
return {
|
423
|
444
|
height,
|
424
|
|
- width: Math.floor(aspectRatio * height),
|
|
445
|
+ width: aspectRatio * height,
|
425
|
446
|
minHeightEnforced,
|
426
|
|
- maxVisibleRows: Math.floor(viewHeight / height)
|
|
447
|
+ maxVisibleRows: Math.floor(availableHeight / (height + TILE_VERTICAL_MARGIN))
|
427
|
448
|
};
|
428
|
449
|
}
|
429
|
450
|
|
430
|
451
|
const initialRatio = initialWidth / initialHeight;
|
431
|
|
- let height = Math.floor(initialHeight);
|
|
452
|
+ let height = initialHeight;
|
|
453
|
+ let width;
|
432
|
454
|
|
433
|
455
|
// The biggest area of the grid will be when the grid's height is equal to clientHeight or when the grid's width is
|
434
|
456
|
// equal to clientWidth.
|
435
|
457
|
|
436
|
458
|
if (initialRatio > aspectRatio) {
|
437
|
|
- return {
|
438
|
|
- height,
|
439
|
|
- width: Math.floor(initialHeight * aspectRatio),
|
440
|
|
- minHeightEnforced,
|
441
|
|
- maxVisibleRows: Math.floor(viewHeight / height)
|
442
|
|
- };
|
|
459
|
+ width = initialHeight * aspectRatio;
|
443
|
460
|
} else if (initialRatio >= TILE_PORTRAIT_ASPECT_RATIO) {
|
444
|
|
- return {
|
445
|
|
- height,
|
446
|
|
- width: Math.floor(initialWidth),
|
447
|
|
- minHeightEnforced,
|
448
|
|
- maxVisibleRows: Math.floor(viewHeight / height)
|
449
|
|
- };
|
|
461
|
+ width = initialWidth;
|
|
462
|
+ // eslint-disable-next-line no-negated-condition
|
450
|
463
|
} else if (!minHeightEnforced) {
|
451
|
|
- height = Math.floor(initialWidth / TILE_PORTRAIT_ASPECT_RATIO);
|
|
464
|
+ height = initialWidth / TILE_PORTRAIT_ASPECT_RATIO;
|
452
|
465
|
|
453
|
466
|
if (height >= minHeight) {
|
454
|
|
- return {
|
455
|
|
- height,
|
456
|
|
- width: Math.floor(initialWidth),
|
457
|
|
- minHeightEnforced,
|
458
|
|
- maxVisibleRows: Math.floor(viewHeight / height)
|
459
|
|
- };
|
|
467
|
+ width = initialWidth;
|
|
468
|
+ } else { // The width is so small that we can't reach the minimum height with portrait aspect ratio.
|
|
469
|
+ return;
|
460
|
470
|
}
|
|
471
|
+ } else {
|
|
472
|
+ // We can't fit that number of columns with the desired min height and aspect ratio.
|
|
473
|
+ return;
|
461
|
474
|
}
|
462
|
475
|
|
463
|
|
- // else
|
464
|
|
- // We can't fit that number of columns with the desired min height and aspect ratio.
|
465
|
|
- return;
|
|
476
|
+ return {
|
|
477
|
+ height,
|
|
478
|
+ width,
|
|
479
|
+ minHeightEnforced,
|
|
480
|
+ maxVisibleRows: Math.floor(availableHeight / (height + TILE_VERTICAL_MARGIN))
|
|
481
|
+ };
|
466
|
482
|
}
|
467
|
483
|
|
468
|
484
|
/**
|