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

Formula grid #542

Draft
wants to merge 12 commits into
base: ui2
Choose a base branch
from
Draft

Formula grid #542

wants to merge 12 commits into from

Conversation

gwhitney
Copy link
Collaborator

@gwhitney gwhitney commented Feb 21, 2025

By submitting this PR, I am indicating to the Numberscope maintainers that I have read and understood the contributing guidelines and that this PR follows those guidelines to the best of my knowledge. I have also read the pull request checklist and followed the instructions therein.


Introduces the FormulaGrid Visualizer, a formula-based common generalization of Grid and SelfSimilarity.
This is a work in progress. Still needs:

  • Implementation of mouseover (prototyped, needs to move near mouse)
  • Diagram for hexagonal cells, and guidance for doing triangular arrays.
  • Diagram for triangular cells
  • Snapshots and other polishing of documentation (including improving help popups in parameter tab)
  • Selection and addition of featured specimens
  • Updated tests, including unit tests for triangular and invTriangular

However, it's definitely not too early to provide feedback.

Here's a classic view of the arithmetic triangle:
http://localhost:5173/?name=OEIS+A007318&viz=FormulaGrid&aspect=r&fillOrder=2&pathFormula=%5Bceil%28c%2F2%29+-+invTriangular%28k-1%29+%2B+2*%28k+-+triangular%28invTriangular%28k-1%29%29+-+1%29%2CinvTriangular%28k-1%29+%2B+1%5D&fillFormula=%7Bhexagon%3A+rainbow%2872a%29%7D&seq=OEIS+A007318

@gwhitney gwhitney added the visualizer Has to do with a visualizer or the visualizer subsystem. label Feb 21, 2025
@gwhitney gwhitney marked this pull request as draft February 21, 2025 23:10
@gwhitney
Copy link
Collaborator Author

OK, I added a prototype of mouseover. You can see it in action in this monochrome version of the gcd(x,y) plot (not saying it's the best version of such a plot, by any means):
http://localhost:5173/?name=Formula%3A+n&viz=FormulaGrid&dimensions=200&speed=1024&fillFormula=%7Brectangle%3A+1+-+%28gcd%28x%2Cy%29-1%29%2Fx%2C%0A+mouseover%3A+%5B%0A++++%27gcd%28%27%2C+x%2C+%27%2C+%27%2C+y%2C+%27%29+%3D+%27%2C+gcd%28x%2Cy%29%0A%5D%7D&seq=Formula

However, I definitely don't think it is done. Right now it just overlays the mouseover text at the top right of the canvas, in the default font and color. There's no effort to set it off in a box and no styling. I could definitely use feedback/ideas on what the mouseover text should look like and where it should appear. Should it follow some offset from the mouse like FactorHistogram? Should it always be in the top right corner? Or should it actually be just above the canvas somewhere so it shows up in the specimen bar? Or some other location option? (Or heavens forfend, should its location be configurable in some way? We should not indulge in configurability always for configurability's sake...)

Personally, I would be happy with it styled in some way (maybe an outlined box with an opaque or semitransparent white or pastel-tinted background, maybe with the same drop shadows as our help boxes) and always appearing in the same place (like the top right where it is now, or any fixed location folks think would be better...).

@gwhitney
Copy link
Collaborator Author

So I think this PR is now at the stage that it would be best for me to get some feedback before proceeding further, even though it is still a draft.

@gwhitney
Copy link
Collaborator Author

In particular @katestange if you could try translating some of your specimens from #526 into this FormulaGrid and see how that goes, that would be really great.

@katestange
Copy link
Member

When I preview other sequences, the full set of parameters doesn't seem to be applied in the thumbnails.
Screenshot from 2025-02-22 17-42-06

@katestange
Copy link
Member

With these settings, why is there background showing through? The aspect ratio of the cells is 'r' for regular, and the "inset" for the squares is '1' to fill the short side. I put one number in "dimensions" to specify only rows.
Screenshot from 2025-02-22 17-44-00

@katestange
Copy link
Member

This particular error may be difficult to isolate, since it presumably has to do with the pile of sequences I have in my sequence chooser, but when I open the sequence chooser, I get TypeError: args[0].slice is not a function. If that doesn't immediately mean something to you, I'll try to track it down to a minimal example.

@katestange
Copy link
Member

This error message seems in error:
Screenshot from 2025-02-22 17-55-47

@katestange
Copy link
Member

I suspect it's because it has to compute the chroma scale afresh for each dot.

Maybe one possibility is to have more inbuilt chroma scales for people to choose from that are pre-computed?

@katestange
Copy link
Member

I suspect it's because it has to compute the chroma scale afresh for each dot.

This is borne out by a better formula: http://localhost:5173/?name=Formula%3A+n&viz=FormulaGrid&aspect=0.999&backgroundColor=040404FF&speed=100&fillFormula=%7Bcircle%3A+chroma.mix%28%27%23ffff6a%27%2C+%27%23000000%27%2C+1-gcd%28x%2Cy%29%2Fmax%28x%2Cy%29%2C+%27hsl%27%29%7D&inset=1&seq=Formula

That's a variation on my favourite "gcd" self-similarity.

@gwhitney
Copy link
Collaborator Author

With these settings, why is there background showing through?

Because r makes the hexagons and triangles regular, which is an aspect ratio of 1/√3. So centering squares in those tall thin rectangles leaves some background visible. If you want to fill the plane with squares, you should use an aspect ratio of 1.

@gwhitney
Copy link
Collaborator Author

This error message seems in error: [Cell aspect: 1]
Reproduced. Working on it. Don't push any commits ;-)

@gwhitney
Copy link
Collaborator Author

This error message seems in error: [Cell aspect: 1]
Reproduced. Working on it. Don't push any commits ;-)

OK, should be fixed if you pull.

@gwhitney
Copy link
Collaborator Author

gwhitney commented Feb 23, 2025

I suspect it's because it has to compute the chroma scale afresh for each dot.

Maybe one possibility is to have more inbuilt chroma scales for people to choose from that are pre-computed?

I observe the same thing, and if I replace the scale with "rainbow" it's super snappy. So I agree, recomputing the scale is expensive. But formula chroma('#ffff6a').mix('#000000', 1-gcd(x,y)/max(x,y), 'oklch') does essentially the same thing as what you wrote, and is shorter and doesn't involve an arbitrary constant 600, and is also super snappy. So I think the moral is don't make very long scales -- when you are doing that, probably you want a continuous mix. Oh and note I changed to mode oklch as that is recommended over lch in the chroma.js docs -- you can see the difference quite clearly if you switch that string back and forth between oklch and lch in this visualization.

@gwhitney
Copy link
Collaborator Author

gwhitney commented Feb 23, 2025

This is borne out by a better formula

Ah yes, you and I got to the same place; your comment just hadn't refreshed into my view of this page when I was working on the "laggy" comment. So unless you think otherwise, there doesn't seem to be any action item here.

@gwhitney
Copy link
Collaborator Author

This particular error may be difficult to isolate, since it presumably has to do with the pile of sequences I have in my sequence chooser, but when I open the sequence chooser, I get TypeError: args[0].slice is not a function. If that doesn't immediately mean something to you, I'll try to track it down to a minimal example.

Yeah, I think I would need more than that to debug. I'm not seeing this phenomenon.

@gwhitney
Copy link
Collaborator Author

When I preview other sequences, the full set of parameters doesn't seem to be applied in the thumbnails.

I think this is #539 biting you. Let me know if you want me to fold a fix for that into this PR.

@gwhitney
Copy link
Collaborator Author

Oh, I added a to-do item at the top about featured specimens - @katestange feel free to push a commit with some you like whenever the feeling moves you.

@katestange
Copy link
Member

Would it be ok if I push a few new functions for colours? There's things I'm trying to do simply/frequently that it would be great to have shortcuts for. Like "rainbow()".

@katestange
Copy link
Member

It would be great to have a variable for the coordinates of the center of the canvas

@katestange
Copy link
Member

Because there's a little question mark next to the little drag handle to grow the formula box, it's hard to get with the mouse. Maybe the formula box entire lower bar should drag?

@gwhitney
Copy link
Collaborator Author

should we move our little question mark help icon?

In particular, it could be at the top right instead of the bottom right, and I think that would actually make more sense. it seems weird to me that the help icon moves as you drag to resize the input box.

@gwhitney
Copy link
Collaborator Author

It appears that this formula becomes gigantic, and for some reason that causes the popup when it exists in the sequence chooser.

Should be fixed now.

@katestange
Copy link
Member

In particular, it could be at the top right instead of the bottom right, and I think that would actually make more sense. it seems weird to me that the help icon moves as you drag to resize the input box.

That seems reasonable.

@gwhitney
Copy link
Collaborator Author

gwhitney commented Feb 23, 2025

Just pretty

Just so you know you can simplify this:
http://localhost:5173/?name=Stars&viz=FormulaGrid&dimensions=99+99&aspect=1&fillOrder=1&pathFormula=spiral%28k%29&backgroundColor=040303FF&fillFormula=chroma.mix%28%230571b0%2C+darkseagreen%2C+0.00125a%29&inset=1&seq=OEIS+A055684

  • a is a shorthand for A(n)
  • If you make the cell aspect 1 and inset 1, then square and rectangle are the same thing, and if all you have is rectangle, you don't even need to wrap it in an object with keys; you can just return the color or array of colors to overlay.
  • You don't need to quote #HEX colors and color names.

@gwhitney
Copy link
Collaborator Author

In particular, it could be at the top right instead of the bottom right, and I think that would actually make more sense. it seems weird to me that the help icon moves as you drag to resize the input box.

That seems reasonable.

OK, I will change to that when I get the chance, probably not tonight.

  * Put the help-info icon for a field near its top rather than its
    bottom so that it will not move as you resize a formula input area
  * Pop the resulting help info up above all other elements so the whole
    thing is readable
  * Validate and restore color codes correctly
  * At load time and whenever there is input, auto-grow formula text areas
    if necessary to show the entire formula
@gwhitney
Copy link
Collaborator Author

In particular, it could be at the top right instead of the bottom right, and I think that would actually make more sense. it seems weird to me that the help icon moves as you drag to resize the input box.

OK, I will change to that when I get the chance, probably not tonight.

OK, I have changed this and taken care of #539 because it kept being a pain. I also changed the formula text area to auto-grow if needed to show the whole formula, when the page is loaded and any time you type anything. Let me know what you think of that change. Also, I'd love to get feedback on the behavior when you add a mouseover: <WHATEVER TEXT HERE> property in the fill formula, like this example from above:

http://localhost:5173/?name=Formula%3A+n&viz=FormulaGrid&dimensions=200&speed=1024&fillFormula=%7Brectangle%3A+1+-+%28gcd%28x%2Cy%29-1%29%2Fx%2C%0A+mouseover%3A+%5B%0A++++%27gcd%28%27%2C+x%2C+%27%2C+%27%2C+y%2C+%27%29+%3D+%27%2C+gcd%28x%2Cy%29%0A%5D%7D&seq=Formula

@katestange
Copy link
Member

Also, I'd love to get feedback on the behavior when you add a mouseover: <WHATEVER TEXT HERE> property in the fill formula, like this example from above

Cool! If you change denominator to y, the text is not very readable... it may need a background rectangle of white. Also, I would move it slightly left to avoid it hitting up against the right end of the canvas. Here's the denominator y example to see what I mean: "http://localhost:5173/?name=Formula%3A+n&viz=FormulaGrid&dimensions=200&speed=1024&fillFormula=%7Brectangle%3A+1+-+%28gcd%28x%2Cy%29-1%29%2Fy%2C%0A+mouseover%3A+%5B%0A++++%27gcd%28%27%2C+x%2C+%27%2C+%27%2C+y%2C+%27%29+%3D+%27%2C+gcd%28x%2Cy%29%0A%5D%7D&seq=Formula"

@katestange
Copy link
Member

Also, I'd love to get feedback on the behavior when you add a mouseover: <WHATEVER TEXT HERE> property in the fill formula, like this example from above

And also, if you'd like to be really fancy, the mouseover text could "hop" out of the way (maybe to the opposite corner) when your mouse goes over there, so you have some way to access the grid pixels covered by the text.

@katestange
Copy link
Member

K, I have changed this and taken care of #539 because it kept being a pain. I also changed the formula text area to auto-grow if needed to show the whole formula, when the page is loaded and any time you type anything.

This is great!

@katestange
Copy link
Member

I don't know whether you want to go here or not... but the inset could be a formula.

@katestange
Copy link
Member

katestange commented Feb 24, 2025

Unusual behaviour: Microsoft edge has totally whacky tooltip behaviour on the parameter input cells. Depending on how the panel is scrolled up or down by the main scrollbar, some tooltips don't appear, or appear above the parameter pane entirely. (similar issues in chrome)

@katestange
Copy link
Member

Unusual behaviour: Microsoft edge has totally whacky tooltip behaviour on the parameter input cells. Depending on how the panel is scrolled up or down by the main scrollbar, some tooltips don't appear, or appear above the parameter pane entirely. (similar issues in chrome)

Oh I think I know what's happening! The tooltips are appearing behind the parameter pane instead of on top.

/** md
- Inset: The side length of the 'square' shape and/or diameter of the 'circle'
shape, as a multiple of the shorter dimension of a cell. Must be positive,
but allowed to be greater than one, in which case the shapes may overlap.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if it's a triangle or hexagon?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The triangles and hexagons are fixed sizes that singly and doubly cover the plane, respectively.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ok. Is it worth mentioning it is expected to have no effect on those?

and `y` giving the coordinates. The formula may use any of the variables
listed in the description above, where the inputs _x_, _y_, and _s_ are
calculated as if the fill order were the default 'By_Rows'. This latter
convention is useful if you want to tweak the default fill order.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an example would help here, if just to show that square brackets are needed on an ordered pair.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, will fill in an example of each format (for doing vertical instead of horizontal stripes).


On the other hand, the fill formula may instead return a plain object with keys
drawn from the list of supported shapes:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (fill formula) is sufficiently complicated that some examples should maybe be included to show the formatting for "objects" and "keys" for those not familiar. It helped me a lot to see an example with a shape and a mouseover.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, putting in three examples: one with just a color, one with rectangle and square together, and one with hexagon and mouseover.

+ 'keys are rectangle, square, ellipse, circle, hexagon, '
+ 'triangle, text, or mouseover; the values for the last two '
+ '"shapes" will be (converted to) strings, not colors. '
+ formulaDescription,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to improve this pop up description, but the use of this cell is very complicated and a tooltip can't possibly do it justice. Maybe it should just say something like "A formula giving the color of the cell, or a more complicated formula describing shapes, text and mouseover information for the cell." Because they need to visit the docs, maybe the only goal here is to describe the function, not the format. Perhaps this comment could even apply to some of the other tooltips also.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deferring this for in-person conversation.

@gwhitney
Copy link
Collaborator Author

Also, I'd love to get feedback on the behavior when you add a mouseover: <WHATEVER TEXT HERE> property in the fill formula, like this example from above

And also, if you'd like to be really fancy, the mouseover text could "hop" out of the way (maybe to the opposite corner) when your mouse goes over there, so you have some way to access the grid pixels covered by the text.

Is this what you meant (if you pull)? Also, it is opaque, bordered, and shadowed now, so I think it stands out pretty well wherever it is.

@gwhitney
Copy link
Collaborator Author

I don't know whether you want to go here or not... but the inset could be a formula.

Your wish is my code. Here's a version of your favorite gcd grid, but with the brighter circles smaller in diameter so that the overall intensity is relatively constant, just more concentrated at the high-gcd places:
http://localhost:5173/?name=Formula%3A+n&viz=FormulaGrid&backgroundColor=040404FF&speed=100&fillFormula=%7Bcircle%3A+chroma.mix%28yellow%2C+black%2C+1-gcd%28x%2Cy%29%2Fmax%28x%2Cy%29%2C+%27hsl%27%29%7D&inset=%281-gcd%28x%2Cy%29%2Fmax%28x%2Cy%29%29+%2B+0.2&seq=Formula

(not saying this is any better than the one with constant-size dots; mostly just a demo of the inset formula.

@gwhitney
Copy link
Collaborator Author

Unusual behaviour: Microsoft edge has totally whacky tooltip behaviour on the parameter input cells. Depending on how the panel is scrolled up or down by the main scrollbar, some tooltips don't appear, or appear above the parameter pane entirely. (similar issues in chrome)

Oh I think I know what's happening! The tooltips are appearing behind the parameter pane instead of on top.

OK, edge should be fixed now. Thanks for checking!

@gwhitney
Copy link
Collaborator Author

OK, got most of the review comments, except some I explicitly deferred either because I can't get to them tonight or because I think a voice/video conversation would be helpful.

@katestange
Copy link
Member

(not saying this is any better than the one with constant-size dots; mostly just a demo of the inset formula.

Very cool! Love it.

@katestange
Copy link
Member

Is this what you meant (if you pull)? Also, it is opaque, bordered, and shadowed now, so I think it stands out pretty well wherever it is.

Ok, it's totally legible now! And matches the decor. But now that I see it jumping around, I wonder why not just put it near the mouse cursor (where your eyes are looking anyway)? More like a typical mouseover popup.

@katestange
Copy link
Member

OK, edge should be fixed now. Thanks for checking!

Agree, looking good.

@katestange
Copy link
Member

Because r makes the hexagons and triangles regular, which is an aspect ratio of 1/√3. So centering squares in those tall thin rectangles leaves some background visible. If you want to fill the plane with squares, you should use an aspect ratio of 1.

BTW, this was because I didn't read the instructions carefully. So all is well.

@gwhitney
Copy link
Collaborator Author

Is this what you meant (if you pull)? Also, it is opaque, bordered, and shadowed now, so I think it stands out pretty well wherever it is.

Ok, it's totally legible now! And matches the decor. But now that I see it jumping around, I wonder why not just put it near the mouse cursor (where your eyes are looking anyway)? More like a typical mouseover popup.

OK, I added a to-do to put the popup by the mouse cursor. My plan is to put it below and to the right of the cursor, unless that would move it off of the canvas, in which case it will rotate around the pointer as you approach the bottom or the right edge of the canvas. If that doesn't sound good, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
visualizer Has to do with a visualizer or the visualizer subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants