Comparing version 4.0.1 to 4.0.2
@@ -324,11 +324,11 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
for (var id in this.allLabels) { | ||
Object.keys(this.allLabels).forEach(function (id) { | ||
var label = this.allLabels[id]; | ||
var label = _this2.allLabels[id]; | ||
this.ingestLabel({ | ||
_this2.ingestLabel({ | ||
bottomLeft: [label.minX, label.minY], | ||
topRight: [label.maxX, label.maxY] | ||
}, label.id, label.weight, label.labelObject, label.name, label.isDragged); | ||
} | ||
}); | ||
} else if (this.hasChanged.size) { | ||
@@ -364,3 +364,2 @@ var changed = [].concat(_toConsumableArray(this.hasChanged)); | ||
this._handlePreviousCollisions(); | ||
this._hideShownCollisions(); // TODO: why is this necessary ? :( | ||
this.callLabelCallbacks(); | ||
@@ -436,2 +435,7 @@ } | ||
value: function _makeLabel(boundingBox, id, weight, labelObject, labelName, isDragged) { | ||
if (weight === undefined || weight === null) { | ||
weight = 0; | ||
} | ||
return { | ||
@@ -444,3 +448,3 @@ minX: boundingBox.bottomLeft[0], | ||
id: id, | ||
weight: weight || 1, | ||
weight: weight, | ||
labelObject: labelObject, | ||
@@ -543,2 +547,3 @@ name: labelName, | ||
highest.state = "show"; | ||
if (originalWeight) highest.weight = originalWeight; | ||
@@ -545,0 +550,0 @@ } |
{ | ||
"name": "labelgun", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "A mapping library agnostic labelling engine", | ||
@@ -14,2 +14,3 @@ "main": "lib/labelgun.js", | ||
"build-both": "webpack && webpack --env.minified", | ||
"benchmark" : "node ./benchmark/benchmark.js", | ||
"doc": "jsdoc src/labelgun.js --destination docs/documentation --pedantic", | ||
@@ -16,0 +17,0 @@ "doc-deploy": "npm run doc && git add docs && git commit -m 'Updated docs' && git push origin --delete gh-pages && git subtree push --prefix docs/ origin gh-pages" |
@@ -29,3 +29,3 @@ ![labelgun](logo.png) | ||
`https://unpkg.com/labelgun@3.0.0/lib/labelgun.js` | ||
`https://unpkg.com/labelgun@4.0.1/lib/labelgun.js` | ||
@@ -32,0 +32,0 @@ ### Docs and Demos |
@@ -273,3 +273,3 @@ var labelgun = require("../lib/labelgun"); | ||
it("no shown labels should collide after their collisions have been dealt with", function(){ | ||
it("none overlapping labels should all be shown (1000 labels)", function(){ | ||
@@ -283,13 +283,12 @@ var hideLabel = function(){ return false; }; | ||
for (var i=0; i < n; i++) { | ||
boundingBox = { | ||
bottomLeft : [i, i], | ||
topRight : [i + 1.0, i + 1.0] | ||
bottomLeft : [i, 1 + i], | ||
topRight : [0.5 + i, 0.5 + i] | ||
}; | ||
labelEngine.ingestLabel( | ||
boundingBox, | ||
i, //id | ||
parseInt(Math.random() * (5 - 1) + 1), // Weight | ||
1, // Weight | ||
{}, // label object | ||
@@ -306,14 +305,7 @@ "Test", | ||
expect(Object.keys(labelEngine.allLabels).length).toBe(n); | ||
labelEngine.getShown().forEach(function(label){ | ||
expect(label).toBeDefined(); | ||
expect(label.id).toBeDefined(); | ||
expect(label.maxX).toBeDefined(); | ||
labelEngine.getCollisions(label.id).forEach(function(collision) { | ||
expect(collision.state).toBe("hide"); | ||
}); | ||
}); | ||
expect(labelEngine.getShown().length).toBe(1000); | ||
}); | ||
it("overlapping labels should all be hidden except the one with the highest weight", function(){ | ||
it("overlapping labels should all be hidden except the one with the highest weight (1000 labels)", function(){ | ||
@@ -336,3 +328,3 @@ var hideLabel = function(){ return false; }; | ||
i, //id | ||
i, // Weight | ||
parseInt(Math.random() * (100 - 1) + 1), // Weight | ||
{}, // label object | ||
@@ -349,13 +341,45 @@ "Test", | ||
expect(Object.keys(labelEngine.allLabels).length).toBe(n); | ||
expect(labelEngine.getShown().length).toBe(1); | ||
for (var key in labelEngine.allLabels) { | ||
var label = labelEngine.allLabels[key]; | ||
if (label.id === i - 1) { | ||
expect(label.state).toBe("show"); | ||
} else { | ||
expect(label.state).toBe("hide"); | ||
} | ||
var shownLabels = labelEngine.getShown(); | ||
expect(shownLabels.length).toBe(1); | ||
expect(shownLabels[0].state).toBe("show"); | ||
labelEngine.getHidden().forEach(function(label) { | ||
expect(label.state).toBe("hide"); | ||
}); | ||
}); | ||
it("intermittently overlapping labels should be shown and hidden correctly (1000 labels)", function(){ | ||
var hideLabel = function(){ return false; }; | ||
var showLabel = function(){ return true; }; | ||
var labelEngine = new labelgun.default(hideLabel, showLabel); | ||
var boundingBox; | ||
var n = 1000; | ||
for (var i=0; i < n; i++) { | ||
boundingBox = { | ||
bottomLeft : [i, i], | ||
topRight : [1 + i, 1 + i] | ||
}; | ||
labelEngine.ingestLabel( | ||
boundingBox, | ||
i, //id | ||
1, // Weight | ||
{}, // label object | ||
"Test", | ||
false | ||
); | ||
} | ||
labelEngine.update(); | ||
expect(labelEngine.tree.all().length).toBe(n); | ||
expect(Object.keys(labelEngine.allLabels).length).toBe(n); | ||
expect(labelEngine.getShown().length).toBe(500); | ||
expect(labelEngine.getHidden().length).toBe(500); | ||
}); | ||
@@ -362,0 +386,0 @@ |
@@ -195,6 +195,6 @@ | ||
for (var id in this.allLabels) { | ||
Object.keys(this.allLabels).forEach((id) => { | ||
const label = this.allLabels[id]; | ||
this.ingestLabel( | ||
@@ -212,3 +212,3 @@ { | ||
} | ||
}); | ||
@@ -253,3 +253,2 @@ } | ||
this._handlePreviousCollisions(); | ||
this._hideShownCollisions(); // TODO: why is this necessary ? :( | ||
this.callLabelCallbacks(); | ||
@@ -316,2 +315,7 @@ | ||
_makeLabel(boundingBox, id, weight, labelObject, labelName, isDragged) { | ||
if (weight === undefined || weight === null) { | ||
weight = 0; | ||
} | ||
return { | ||
@@ -324,3 +328,3 @@ minX: boundingBox.bottomLeft[0], | ||
id : id, | ||
weight: weight || 1, | ||
weight: weight, | ||
labelObject : labelObject, | ||
@@ -330,2 +334,3 @@ name : labelName, | ||
}; | ||
} | ||
@@ -402,3 +407,3 @@ | ||
} | ||
if (collision.weight > highest.weight) { | ||
@@ -414,2 +419,3 @@ highest.state = "hide"; | ||
highest.state = "show"; | ||
if (originalWeight) highest.weight = originalWeight; | ||
@@ -416,0 +422,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6825179
50
3548