Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

layout

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

layout - npm Package Compare versions

Comparing version 1.3.2 to 2.0.0

2

CHANGELOG.md
# layout changelog
2.0.0 - Added option to allow skipping, altered custom algorithm signature
1.3.2 - Added Travis CI
Before 1.3.2 - See `git log`

10

lib/algorithms/alt-diagonal.algorithm.js
// Add in reverse-diagonal algorithm
function reverseDiagonalAlgorithm (items) {
exports.sort = function (items) {
// Sort the items by their diagonal

@@ -9,3 +9,6 @@ items.sort(function (a, b) {

});
return items;
};
exports.placeItems = function (items) {
// Iterate over each of the items

@@ -26,5 +29,2 @@ var x = 0,

return items;
}
// Export our algorithm
module.exports = reverseDiagonalAlgorithm;
};

@@ -5,3 +5,3 @@ // Load in our binary packer

function binaryTreePackingAlgorithm(items) {
exports.sort = function (items) {
// Sort the items by their height

@@ -11,3 +11,6 @@ items.sort(function (a, b) {

});
return items;
};
exports.placeItems = function (items) {
// Rename all `width` and `height`

@@ -39,4 +42,2 @@ items.forEach(function (item) {

return items;
}
module.exports = binaryTreePackingAlgorithm;
};
// Add in diagonal algorithm
function diagonalAlgorithm(items) {
exports.sort = function (items) {
// Sort the items by their diagonal

@@ -9,3 +9,6 @@ items.sort(function (a, b) {

});
return items;
};
exports.placeItems = function (items) {
// Iterate over each of the items

@@ -26,5 +29,2 @@ var x = 0,

return items;
}
// Export our algorithm
module.exports = diagonalAlgorithm;
};
// Add in left-right algorithm
function leftRightAlgorithm(items) {
exports.sort = function (items) {
// Sort the items by their width

@@ -7,3 +7,6 @@ items.sort(function (a, b) {

});
return items;
};
exports.placeItems = function (items) {
// Iterate over each of the items

@@ -22,5 +25,2 @@ var x = 0;

return items;
}
// Export our algorithm
module.exports = leftRightAlgorithm;
};
// Add in top-down algorithm
function topDownAlgorithm(items) {
exports.sort = function (items) {
// Sort the items by their height

@@ -7,3 +7,6 @@ items.sort(function (a, b) {

});
return items;
};
exports.placeItems = function (items) {
// Iterate over each of the items

@@ -22,5 +25,2 @@ var y = 0;

return items;
}
// Export our algorithm
module.exports = topDownAlgorithm;
};

@@ -9,6 +9,6 @@ // Load in packing.smith (from spritesmith) and create algorithm store

* @constructor
* @param {String|Function} [algorithm="top-down"] Name of algorithm or custom algorithm to use
* @param {String|Object} [algorithm="top-down"] Name of algorithm or custom algorithm to use
* Algorithms available: top-down, left-right, diagonal, alt-diagonal, binary-tree
*/
function Layout(algorithmName) {
function Layout(algorithmName, options) {
// Save the algorithmName as our algorithm (assume function)

@@ -26,3 +26,3 @@ var algorithm = algorithmName || 'top-down';

// Create a new PackingSmith with our algorithm and return
var retSmith = new PackingSmith(algorithm);
var retSmith = new PackingSmith(algorithm, options);
return retSmith;

@@ -37,3 +37,5 @@ }

* @param {String} name Name of algorithm
* @param {Function} algorithm Algorithm to bind under name
* @param {Object} algorithm Algorithm to bind under name
* @param {Function} algorithm.sort Algorithm to sort object by
* @param {Function} algorithm.placeItems Algorithm to place items by
*/

@@ -86,2 +88,2 @@ function addAlgorithm(name, algorithm) {

// Expose Layout to the outside
module.exports = Layout;
module.exports = Layout;

@@ -1,4 +0,10 @@

function PackingSmith(algorithm) {
function PackingSmith(algorithm, options) {
// Define items and save algorithm for later
this.items = [];
this.algorithm = algorithm;
// Fallback options and determine whether to sort or not
options = options || {};
var sort = options.sort !== undefined ? options.sort : true;
this.sort = sort;
}

@@ -74,3 +80,6 @@ PackingSmith.prototype = {

var items = this.items;
items = this.algorithm(items);
if (this.sort) {
items = this.algorithm.sort(items);
}
items = this.algorithm.placeItems(items);

@@ -115,2 +124,2 @@ // Save the items for later

// Export PackingSmith
module.exports = PackingSmith;
module.exports = PackingSmith;
{
"name": "layout",
"description": "Organize and layout items based on various algorithms",
"version": "1.3.2",
"version": "2.0.0",
"homepage": "https://github.com/twolfson/layout",

@@ -6,0 +6,0 @@ "author": {

@@ -55,3 +55,3 @@ # layout [![Build status](https://travis-ci.org/twolfson/layout.png?branch=master)](https://travis-ci.org/twolfson/layout)

* @constructor
* @param {String|Function} [algorithm="top-down"] Name of algorithm or custom algorithm to use
* @param {String|Object} [algorithm="top-down"] Name of algorithm or custom algorithm to use
* Algorithms available: top-down, left-right, diagonal, alt-diagonal, binary-tree

@@ -87,3 +87,5 @@ */

* @param {String} name Name of algorithm
* @param {Function} algorithm Algorithm to bind under name
* @param {Object} algorithm Algorithm to bind under name
* @param {Function} algorithm.sort Algorithm to sort object by
* @param {Function} algorithm.placeItems Algorithm to place items by
*/

@@ -90,0 +92,0 @@ ```

@@ -137,4 +137,4 @@ var layout = require('../lib/layout.js');

var result = layer['export']();
test.equal(result.height, 50, 'Result has a height of 80');
test.equal(result.width, 50, 'Result has a width of 60');
test.equal(result.height, 50, 'Result has a height of 50');
test.equal(result.width, 50, 'Result has a width of 50');
test.equal(result.items.length, 3, 'Result has 3 items');

@@ -149,3 +149,25 @@ test.equal(typeof result.items[0].y, 'number');

test.done();
},
'non-sorting layout': function (test) {
test.expect(9);
// A layout without sorting and multiple items
var layer = layout('top-down', {'sort': false});
layer.addItem({'height': 20, 'width': 10, 'meta': 'medium'});
layer.addItem({'height': 10, 'width': 10, 'meta': 'small'});
layer.addItem({'height': 50, 'width': 40, 'meta': 'large'});
// packs them in the order they were received
var result = layer['export']();
test.equal(result.height, 80, 'Result has a height of 80');
test.equal(result.width, 40, 'Result has a width of 40');
test.equal(result.items.length, 3, 'Result has 3 items');
test.equal(result.items[0].y, 0);
test.equal(result.items[0].x, 0);
test.equal(result.items[1].y, 0 + 20);
test.equal(result.items[1].x, 0);
test.equal(result.items[2].y, 0 + 20 + 10);
test.equal(result.items[2].x, 0);
test.done();
}
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc