Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Network: Retain constraint values in label font handling #3520

Merged
merged 6 commits into from
Oct 8, 2017

Conversation

wimrijnders
Copy link
Contributor

@wimrijnders wimrijnders commented Oct 4, 2017

Fixes #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 refactoring of Label#constrain() in order to separate concerns
  • Added unit test for regression testing of this issue.

All 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.

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.
Copy link

@mbroad mbroad left a 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.

assert.equal(fontOptions.minWdt, -1);
assert.equal(fontOptions.maxWdt, expectedMaxWidthDefault);
} else {
let constraint = item.widthConstraint;
Copy link

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 ifs and elses can be avoided?

Copy link
Contributor Author

@wimrijnders wimrijnders Oct 5, 2017

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()).

@wimrijnders
Copy link
Contributor Author

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.

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.

@wimrijnders
Copy link
Contributor Author

wimrijnders commented Oct 5, 2017

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 constrainWidth and constrainHeight are not tested, will add these as well.


Update: Well, crap. It appears that constrainWidth and constrainHeight are never set. @mbroad, would you mind verifying this?

This implies that Label#adjustSizes() is useless. Do we need it in working condition, if at all???

I'm going to delve back in previous commits to see if this is a recent thing.
Update: Nope. Last commit before I started mangling Label.js doesn't set them either (Jan 29 2017). For once, it's not my fault.


Update 2: widthConstraint: false doesn't work as advertized. From the docs:

If false, no widthConstraint is applied

This is not true, the boolean value is plain ignored. Same goes for heightConstraint: false. Shall we just remove it from the docs? Removing a constraint can be achieved by setting the value to null, e.g. widthConstraint: null.
Update: This also means that boolean can/should be removed from the option definitions. This would be a breaking API change, though the least malevolent I can imagine. Users in their right mind wouldn't be using the value anyway, and worst of all, it does nothing.

@mbroad
Copy link

mbroad commented Oct 8, 2017

This also means that boolean can/should be removed from the option definitions. This would be a breaking API change, though the least malevolent I can imagine. Users in their right mind wouldn't be using the value anyway, and worst of all, it does nothing.

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.
Copy link

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.

Copy link
Contributor Author

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.

@mbroad
Copy link

mbroad commented Oct 8, 2017

Well, crap. It appears that constrainWidth and constrainHeight are never set. @mbroad, would you mind verifying this?

Verified. They are both set to false, but nothing else modifies them.

@wimrijnders
Copy link
Contributor Author

wimrijnders commented Oct 8, 2017

Verified. They are both set to false, but nothing else modifies them.

Thanks. I'll consider them artifacts and remove them and Label#adjustSize(), which is the only place were they are accessed and which thus does nothing.

Edit: if options widthConstraint and heightConstraint are retained, then these can not be removed. But I will rename them.

@wimrijnders
Copy link
Contributor Author

wimrijnders commented Oct 8, 2017

Should it really be removed, or just actually set?

Had a think about this: I can image a scenario where the widthConstraint/heightConstraint gets overridden in the more specific options (e.g. defined in the global options, overridden in group or node instance).

So setting to false actually has potential use. So it needs to be handled as well. What to do with setting to true, however? That is useless......

Anyway, I'll add the handling in.

@wimrijnders
Copy link
Contributor Author

wimrijnders commented Oct 8, 2017

Wrt. fully enabling width/heightConstraint: I'm digging myself into a hole here.

The consequence is that suddenly the margins are used again - option margin has not been active in a long time. So the changes are propagating.

Rather than fix this as well, I'll leave the margins as is, make a note and create an issue for it (#3536).

@yotamberk yotamberk merged commit 4a25c43 into almende:develop Oct 8, 2017
@wimrijnders
Copy link
Contributor Author

Oh, merged already ☹️. I was hoping to get some changes in still. Never mind, I'll add them in #3536.

@wimrijnders wimrijnders deleted the issue3517 branch October 9, 2017 03:49
primozs pushed a commit to primozs/vis that referenced this pull request Jan 3, 2019
* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants