-
Notifications
You must be signed in to change notification settings - Fork 943
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
Use same color for same namespace. #338
Conversation
function selectColor(namespace) { | ||
var hash = 0, i, chr, len; | ||
|
||
for (i in namespace) { |
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.
is this algorithm for somewhere that we need to give credit for?
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.
Hard to find who to credit: https://www.google.com/search?q=%22Convert+to+32bit+integer%22
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.
Nice and simple, thanks for the PR! I'm 👍 for this feature. There's been plenty of times where the order of require calls changing ends up changing the colors of the debug instances, since they get instantiated in a different order which has always felt strange. The only thing I'd be worried about is if the algorithm doesn't "distribute" the colors evenly enough. But I guess we'll just have to feel it out and see. |
I agree, it will have less perfect distribution on colors over namespace. |
This algorithm doesn't seem to work well. Example: console.log({
namespace,
hash: Math.abs(hash),
color: exports.colors[Math.abs(hash) % exports.colors.length],
}); {namespace: "rto-ext:EVENTS", hash: 1808327694, color: "lightseagreen"}
{namespace: "rto-ext:SETTINGS", hash: 1479630660, color: "lightseagreen"}
{namespace: "rto-ext:BG", hash: 33268638, color: "lightseagreen"} Three different namespaces have the same color. |
exports.colors.length == 6 @TooTallNate More color ? Otherwise we need to have an array to store the colors stickiness. Not as complicated as this. |
We can try something like that otherwise : lchenay@9f4404f The color will be better distributed as before, with reuse of same color for same namespace, but will use some memory to store the array of mapping. |
CF #258