Skip to content

Commit

Permalink
Merge pull request #45 from channeladam/fix-short-circuit-draw-visibl…
Browse files Browse the repository at this point in the history
…e-in-labeljs

FIX #44 - correctly set invalid labels to undefined
  • Loading branch information
micahstubbs authored Jan 27, 2019
2 parents a343aff + 0f48f70 commit 9401c77
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/network/modules/components/shared/Label.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Label {
this.labelDirty = true
} else {
// Bad label! Change the option value to prevent bad stuff happening
options.label = ''
options.label = undefined
}

if (options.font !== undefined && options.font !== null) {
Expand Down
41 changes: 41 additions & 0 deletions test/Label.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
var assert = require('assert')
var Label = require('../lib/network/modules/components/shared/Label').default
var ComponentUtil = require('../lib/network/modules/components/shared/ComponentUtil')
.default
var NodesHandler = require('../lib/network/modules/NodesHandler').default
var util = require('../lib/util')
var canvasMockify = require('./canvas-mock')
Expand Down Expand Up @@ -1843,4 +1845,43 @@ describe('Network Label', function() {

done()
})

describe('visible function', function() {
it('correctly determines label is not visible when label is invalid', function(done) {
var invalidLabel = ''
assert(
!ComponentUtil.isValidLabel(invalidLabel),
'An empty string should be identified as an invalid label'
)

var body = {
view: {
scale: 1
}
}

var options = {
label: invalidLabel,
font: {
size: 12
},
scaling: {
label: {
drawThreshold: 1
}
}
}

var label = new Label(body, options)
label.size.width = 1
label.size.height = 1

assert(
!label.visible(),
'Label should not be visible because the label text is invalid'
)

done()
})
})
})

0 comments on commit 9401c77

Please sign in to comment.