(sizesToTrim)
| 390 | // (and decreased from the other elements) to make space for the pixels |
| 391 | // subtracted by the gutters. |
| 392 | function trimToMin(sizesToTrim) { |
| 393 | // Try to get inner size of parent element. |
| 394 | // If it's no supported, return original sizes. |
| 395 | var parentSize = innerSize(parent); |
| 396 | if (parentSize === null) { |
| 397 | return sizesToTrim |
| 398 | } |
| 399 | |
| 400 | if (minSizes.reduce(function (a, b) { return a + b; }, 0) > parentSize) { |
| 401 | return sizesToTrim |
| 402 | } |
| 403 | |
| 404 | // Keep track of the excess pixels, the amount of pixels over the desired percentage |
| 405 | // Also keep track of the elements with pixels to spare, to decrease after if needed |
| 406 | var excessPixels = 0; |
| 407 | var toSpare = []; |
| 408 | |
| 409 | var pixelSizes = sizesToTrim.map(function (size, i) { |
| 410 | // Convert requested percentages to pixel sizes |
| 411 | var pixelSize = (parentSize * size) / 100; |
| 412 | var elementGutterSize = getGutterSize( |
| 413 | gutterSize, |
| 414 | i === 0, |
| 415 | i === sizesToTrim.length - 1, |
| 416 | gutterAlign |
| 417 | ); |
| 418 | var elementMinSize = minSizes[i] + elementGutterSize; |
| 419 | |
| 420 | // If element is too smal, increase excess pixels by the difference |
| 421 | // and mark that it has no pixels to spare |
| 422 | if (pixelSize < elementMinSize) { |
| 423 | excessPixels += elementMinSize - pixelSize; |
| 424 | toSpare.push(0); |
| 425 | return elementMinSize |
| 426 | } |
| 427 | |
| 428 | // Otherwise, mark the pixels it has to spare and return it's original size |
| 429 | toSpare.push(pixelSize - elementMinSize); |
| 430 | return pixelSize |
| 431 | }); |
| 432 | |
| 433 | // If nothing was adjusted, return the original sizes |
| 434 | if (excessPixels === 0) { |
| 435 | return sizesToTrim |
| 436 | } |
| 437 | |
| 438 | return pixelSizes.map(function (pixelSize, i) { |
| 439 | var newPixelSize = pixelSize; |
| 440 | |
| 441 | // While there's still pixels to take, and there's enough pixels to spare, |
| 442 | // take as many as possible up to the total excess pixels |
| 443 | if (excessPixels > 0 && toSpare[i] - excessPixels > 0) { |
| 444 | var takenPixels = Math.min( |
| 445 | excessPixels, |
| 446 | toSpare[i] - excessPixels |
| 447 | ); |
| 448 | |
| 449 | // Subtract the amount taken for the next iteration |
no test coverage detected