Gathering detailed insights and metrics for layout
Gathering detailed insights and metrics for layout
Gathering detailed insights and metrics for layout
Gathering detailed insights and metrics for layout
npm install layout
99.7
Supply Chain
100
Quality
75.6
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
114 Stars
91 Commits
15 Forks
10 Watching
6 Branches
3 Contributors
Updated on 12 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-6.4%
10,158
Compared to previous day
Last week
-2.1%
56,032
Compared to previous week
Last month
8.3%
277,583
Compared to previous month
Last year
-38.8%
3,205,906
Compared to previous year
Organize and layout items based on various algorithms
Visualizations of output data:
top-down | left-right | diagonal | alt-diagonal | binary-tree |
---|---|---|---|---|
Install the module with: npm install layout
1// Load in layout 2var layout = require('layout'); 3 4// Generate a new layer to organize items on 5var layer = layout('top-down'); 6 7// Add items that you want to organize 8layer.addItem({'height': 20, 'width': 10, 'meta': 'medium'}); 9layer.addItem({'height': 10, 'width': 10, 'meta': 'small'}); 10layer.addItem({'height': 50, 'width': 40, 'meta': 'large'}); 11 12// Export the info 13var info = layer['export'](); 14 15// We get back the width and height of the pack as well as organized items 16{ 17 height: 80, 18 width: 40, 19 items: [{ 20 height: 10, 21 width: 10, 22 meta: 'small', 23 x: 0, 24 y: 0 25 }, { 26 height: 20, 27 width: 10, 28 meta: 'medium', 29 x: 0, 30 y: 10 31 }, { 32 height: 50, 33 width: 40, 34 meta: 'large', 35 x: 0, 36 y: 30 37 }] 38}
Layout is a constructor function
1/** 2 * Layout adds items in an algorithmic fashion 3 * @constructor 4 * @param {String|Object} [algorithm="top-down"] Name of algorithm or custom algorithm to use 5 * Available algorithms are listed in the Algorithms section 6 * @param {Mixed} [options] Options to provide for the algorithm 7 */
Items can be added via addItem
which are required to have a height
and width
. Any additional info should be stored inside of meta
.
1/** 2 * @param {Object} item Item to store -- this currently is mutated in-memory 3 * @param {Number} item.width Width of the item 4 * @param {Number} item.height Height of the item 5 * @param {Mixed} [item.meta] Any meta data you would like to store related to the item 6 */
export
is how you take your items and organize them.
1/** 2 * @returns {Object} retObj 3 * @returns {Number} retObj.height Height of the processed layout 4 * @returns {Number} retObj.width Width of the processed layout 5 * @returns {Mixed[]} retObj.items Organized items 6 */
Currently layout
supports 5 different layout types which are listed below.
top-down
The top-down
algorithm places items vertically.
By default, it sorts from smallest (top) to largest (bottom). However, this can be disabled via sort: false
.
Options:
Boolean
Flag to enable/disable sorting from smallest (top) to largest (bottom)
true
)left-right
The left-right
algorithm places items horizontally.
By default, it sorts from smallest (left) to largest (right). However, this can be disabled via sort: false
.
Options:
Boolean
Flag to enable/disable sorting from smallest (left) to largest (right)
true
)diagonal
The diagonal
algorithm places items diagonally (top-left to bottom-right).
By default, it sorts from smallest (top-left) to largest (bottom-right). However, this can be disabled via sort: false
.
Options:
Boolean
Flag to enable/disable sorting from smallest (top-left) to largest (bottom-right)
true
)alt-diagonal
The alt-diagonal
algorithm places items diagonally (top-right to bottom-left).
By default, it sorts from smallest (top-right) to largest (bottom-left). However, this can be disabled via sort: false
.
Options:
Boolean
Flag to enable/disable sorting from smallest (top-right) to largest (bottom-left)
true
)binary-tree
The binary-tree
algorithm packs items via the binary tree algorithm.
This is an efficient way to pack items into the smallest container possible.
You can add your own algorithm via layout.addAlgorithm
1/** 2 * Method to add new algorithms via 3 * @param {String} name Name of algorithm 4 * @param {Object} algorithm Algorithm to bind under name 5 * @param {Function} algorithm.sort Algorithm to sort object by 6 * @param {Function} algorithm.placeItems Algorithm to place items by 7 */
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via npm run lint
and test via npm test
.
Support this project and others by twolfson via gratipay.
Copyright (c) 2012-2014 Todd Wolfson Licensed under the MIT license.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 2/28 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More