-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Network: Retain constraint values in label font handling #3520
Conversation
Fixes almende#3517. Due to changed logic in the label font handling, the option values for `widthConstraint` and `heightConstraint` were overwritten. The fix is in effect a reversal of two code lines: parsing constraint options should come *after* parsing (multi)font options. Further changes: - Additional 1-liner fix: constraint values were not copied for edge-instance specific options. - Small refactoriing of `Label#constrain()` in order to separate concerns - Added unit test for regression testing of this issue. This leads to the curious observation that, while the actual change is two lines of source code, this resulted in a +-150 line regression test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily as part of the ticket, but it seems like we have a lot of work to do around documenting and testing the order and application of options.
test/Label.test.js
Outdated
assert.equal(fontOptions.minWdt, -1); | ||
assert.equal(fontOptions.maxWdt, expectedMaxWidthDefault); | ||
} else { | ||
let constraint = item.widthConstraint; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the test run be deterministic, so if
s and else
s can be avoided?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps that's what you mean: In the unit test, since you know exactly what value you are expecting, so can do a direct test on input and output. So, for e.g. node 100, following should suffice:
assert.equal(fontOptions.minWdt, -1);
assert.equal(fontOptions.maxWdt, 200);
assert.equal(fontOptions.minHgtt, -1);
assert.equal(fontOptions.valign, 'middle');
So trading in the conditionals for repetitive but flat code. Is that the clue? I'm agreeing to that. It's not that I don't know how to do that, e.g. it('respects the font option precedence')
.
In fact, I'm not even going to wait for your confirmation that that is what you mean to change to this. I've been following the source code logic too much here (notably Label#constrain()
).
Oh man. Surely you couldn't have missed me lamenting about the state of network option handling in the lobby. The direction I'd like to go, is to simplify option handling as much as possible so that the actual intent becomes obvious. 'We're not there yet' is an euphemism in this context. |
The consequence of making it more linear is that it's now obvious that there is too much checking of the same thing. I'm going let the idea of using the example go and make an 'enhanced subset' of it, so to speak, which also addresses the TODO's in the header comment. Also, I notice that internal font option fields Update: Well, crap. It appears that This implies that I'm going to delve back in previous commits to see if this is a recent thing. Update 2:
This is not true, the boolean value is plain ignored. Same goes for |
Should it really be removed, or just actually set? |
// checking incorrect settings or for future code changes. | ||
// | ||
// There is a lot of repetitiveness here. Perhaps using a direct copy of the | ||
// example should be let go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree wholeheartedly with this comment.
Test set ups should be made up of the minimal required code to satisfy preconditions for your tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. The thing is, I've already let go of the example and changed the test accordingly. I'll remove this comment and add some extra explanation.
Verified. They are both set to |
Thanks. I'll consider them artifacts and remove them and Edit: if options |
Had a think about this: I can image a scenario where the So setting to Anyway, I'll add the handling in. |
Wrt. fully enabling The consequence is that suddenly the margins are used again - option Rather than fix this as well, I'll leave the margins as is, make a note and create an issue for it (#3536). |
Oh, merged already |
* Network: Retain constraint values in label font handling Fixes almende#3517. Due to changed logic in the label font handling, the option values for `widthConstraint` and `heightConstraint` were overwritten. The fix is in effect a reversal of two code lines: parsing constraint options should come *after* parsing (multi)font options. Further changes: - Additional 1-liner fix: constraint values were not copied for edge-instance specific options. - Small refactoriing of `Label#constrain()` in order to separate concerns - Added unit test for regression testing of this issue. This leads to the curious observation that, while the actual change is two lines of source code, this resulted in a +-150 line regression test. * Made unit test more linear, removed tabs * Made 'enhanced subset' of unit test * Removed TODO from comment * Culled redundant nodes from unit test
Fixes #3517.
Due to changed logic in the label font handling, the option values for
widthConstraint
andheightConstraint
were overwritten.The fix is in effect a reversal of two code lines: parsing constraint options should come after parsing (multi)font options.
Further changes:
Label#constrain()
in order to separate concernsAll of which entices me to make the curious observation that two changed lines of source code has led to a +-150 line regression test.
Attentive observers may note that the automatic line breaks are now positioned differently, e.g. in the widthHeight example.
This is due to a fix in the line width calculation in #3486: current stable does not take the spaces into account when calculating width.