question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong label when using id field

See original GitHub issue

Issue type Despite using label: 'data(id)', nodes can have duplicate (wrong) labels while still having the correct id.

Bug report

Environment info

  • Cytoscape.js version : 3.14.0
  • Browser/Node.js & version : Chrome 80.0.3987.106

Current (buggy) behaviour

The bug causes duplicates of one label on different nodes while using the ID as the label.

Desired behaviour

Since Ids have to be unique (and it is, infact, unique), a duplicate label should be impossible when using the data(id) selector.

Minimum steps to reproduce

Here is a simple reproduction of the bug using the given template. There are no complex things involved, just some nodes and the style.

https://jsbin.com/cugeqamoxe/1/edit?html,css,js,output

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
maxkfranzcommented, Apr 1, 2020

Related: Possible cache issue, how to diagnose? #2562

@josejulio

0reactions
maxkfranzcommented, Apr 1, 2020

@ng1905 See the hash-label-2636 branch and commit 0e01d53. That may address this particular case, but I’d like to see more data.

The explanation from the commit follows:

A hash function is used to create a single value that can represent the set of the style property values on an element. This is used for caching parts of the scene, e.g. labels and node bodies, as sprites. This way, things like labels don’t have to be rendered each frame: They can just be copied from a cache.

Using a hash allows for sharing cache entries between elements: For instance, an edge could have a number on it to represent multiplicity, and so multiple edges may have the same label. The typical case for the hash is node bodies: You may have a graph where all the node bodies are identical, with only one cache entry (sprite) shared among all nodes.

The hash is used to avoid lengthy style comparisons (i.e. 1 value comparison versus N style property value comparisons). The hash function has to be cheap and it should have a relatively low probability of collisions for a typical stylesheet. It may not be practical for performance to use a typical hash map approach where the entries are compared on a get operation (i.e. a diff of all style properties between two elements): The point is to avoid expensive style comparisons in the first place, and ideally you want lots of elements in the same buckets.

The problem here is that the prior hash algorithm collided for particular labels. The previous hash function didn’t do well for repeated values (like the repeated ‘0’ characters in the test case). This commit changes the hash function to an implementation that may fare better in this regard.

If this continues to be a problem in future, there are some alternatives:

(1) Don’t use hashing at all. You can lose a lot of performance, especially for shared node bodies. This also precludes the future enhancement of caching edge arrows (currently expensive and uncached).

(2) Don’t use hashing for labels. Most graphs only contain node labels, and node labels are almost always unique. There is the potential for node body collisions, though perhaps less likely.

(3) Use an alternative mechanism to generate a hash value. For example, a trie-like structure could be used: Each node in the trie would be a set of style property values, and each edge in the trie would be a particular property value. The leaves of the trie would each be assigned a unique integer. While this may work, it would be expensive and more complex.

(4) Double down on hashes and probability. It would be simple and cheap to use two cheap hash functions rather than one: The hash for a sprite would be a tuple of two integer hash values. The probability that both hash functions collide in the exact same case is much smaller than the probability that one hash function collides.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to correct the wrong label ID appearance in address and ...
The data for the address and contact information purposes is inserted during the setup. At that time, the label IDs will be attempted...
Read more >
Radio with WRONG LABEL ID
I want taht every radio group has different id in their label, so the user can click directly on the label, BUT CAKE...
Read more >
Trello Label ID Error - Power Platform Community - Microsoft
I have narrowed down the cause to the Label-ID field I have tried everything in this field putting text, 1 but it comes...
Read more >
Common validation errors when creating issue forms
You may see some of these common validation errors when creating, saving, or viewing issue forms.
Read more >
Accessibility:; Form Label error even with a corresponding id ...
While I would argue that visible labels increase usability for all users, if the design insists upon no visible labels, there are two...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found