UNPKG

cluedin-widget

Version:

This is the project for creating and managing widgets in CluedIn.

35 lines (25 loc) 980 B
var Grid = require( './grid' ); var combinatronics = require( './combinatronics' ); var Layout = require( './layout' ); function findBestLayout( widget ) { var widgetCombinations = combinatronics.permutation( widget ); var grids = []; var allCombination = widgetCombinations.toArray(); allCombination.forEach( function( widgetList ) { var g = new Grid( JSON.parse( JSON.stringify( widgetList ) ) ); g.generateRows(); grids.push( g ); } ); var currentGrids = grids[ 0 ]; grids.forEach( function( candidate ) { if ( candidate.getLength() < currentGrids.getLength() ) { currentGrids = candidate; } else if ( candidate.getLength() === currentGrids.getLength() && candidate.numberOfFullRowsAtFirst() > currentGrids.numberOfFullRowsAtFirst() ) { currentGrids = candidate; } } ); return currentGrids; } module.exports = { findBestLayout: findBestLayout };