Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Width constraint maximum is not being applied correctly because Node and Edge labels are not being measured correctly #46

Closed
channeladam opened this issue Jan 18, 2019 · 0 comments · Fixed by visjs/vis-network#27 or #47

Comments

@channeladam
Copy link
Collaborator

channeladam commented Jan 18, 2019

Prerequisites:

  • Node or Edge has a WidthConstraint.maximum set
  • Label for the Node or Edge is longer than the width constraint
  • hover and hoverConnectedEdges interactions are true
  • All the chosen settings are set to false to disable them (so as not to confuse the issue)

When hovering over a such a Node or Edge, even though chosen settings are disabled, the Node changes width. This is distracting and incorrect behaviour. And when the mouse is removed from the node, the node with changes back. Similar for edge labels.

This is because the label measurement is not being performed correctly - specifically because the canvas context font has not been set properly.

On the initial and normal render of a frame, the label measurement is NOT being performed properly.
On hover over the node, the label measurement IS properly being performed.

Partial reverse stack trace for when the hover and correct measure is performed:

  • on mouse move
  • hover object (node is identified)
  • request redraw
  • ...
  • _requestRedraw
  • _drawNodes
  • _draw
  • draw
  • shape.draw
  • resize
  • getDimensionsFromLabel
  • ...

Specifically note that on mouse move happens, and the mouse is hovering over a node, which is identified correctly, and _drawNodes is performed.

In the normal situation where the incorrect measurement is performed:

  • on mouse move
  • hover object (no node identified as mouse is not hovering over anything)
  • request redraw
  • ...
  • _requestRedraw
  • _drawEdges
  • Edge.draw
  • ...

Note here that _drawEdges is called (instead of _drawNodes), which draws the edges and then draws the nodes that the edges are connected with.

When the label is eventually processed, in this case where the edge is drawn first, when the getLongestFit is performed in LabelSplitter for the node's label, the canvas context had a font setting of 10 sans-serif (when my node font was size 14) and the measurement is calculated incorrectly, so the lines of the label aren't split at the right place.

LabelSplitter needs to set the canvas context font to the correct value for the current block, before measuring the text - so that the node width and edge label width doesn't change incorrectly on hover... and so that width constraint is correctly applied on a normal frame render.

PR coming.

channeladam added a commit to channeladam/visjs-network that referenced this issue Jan 19, 2019
…pplied with labels that are correctly measured
channeladam added a commit to channeladam/visjs-network that referenced this issue Jan 22, 2019
…pplied with labels that are correctly measured
micahstubbs added a commit that referenced this issue Jan 27, 2019
FIX #46 to ensure that the width constraint is being applied with lab…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant