Skip to content

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.
The following tasks have been completed:

  • Implementation of mouseover (prototyped, needs to move near mouse)
  • Diagram for hexagonal cells, and guidance for doing triangular arrays.
  • Diagram for triangular cells
  • Snapshots (we decided on an ulam spiral with the spiral emphasized and the mod-5 arithmetic triangle, and other polishing of documentation (including improving help popups in parameter tab) [decided to leave that for post alpha when we have more features for help facilities, like markdown or context-help "drawer")
  • Selection and addition of featured specimens
  • Updated tests, including unit tests for triangular and invTriangular
  • Investigate phenomenon of specimen tests being erratic on the number of frames they display
  • Investigate why aspect ratio does not update when dimensions change
  • Make the placeholder text for dimensions and aspect parameters show the values actually being used, together with a phrase like '(from window size)' for dimensions and '(to fill window)' for aspect.

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

Resolves #527

@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

gwhitney commented Mar 3, 2025

Indeed, in my very first e2e run, one of the formulagrid filled more pixels than expected and one filled less. Everything else was fine. Will investigate.

@gwhitney
Copy link
Collaborator Author

gwhitney commented Mar 3, 2025

@katestange, you have the alpha formula in the Modular Multiplication Table featured specimen to be abs((x*y) % 200-100)/100, but this seems to presuppose that the number of rows and columns is 200. But a nice thing to do is to experiment with different moduli by changing the number of rows and columns. So would it be better for the formula to be abs(2((x*y) % c) - c)/c ?

@gwhitney
Copy link
Collaborator Author

gwhitney commented Mar 3, 2025

OK, I believe I tracked down an async race condition between onBeforeMount and onMounted in the Scope.vue view, and fixed it. The tests seem much more solid to me now. Give them a whirl on your end. If all seems well, then we just need to discuss the popups with the description of the formula parameters, and then I need to tweak the documentation just a little more, and update the CI snapshots, and we shoulld be ready for final review.

@gwhitney
Copy link
Collaborator Author

gwhitney commented Mar 4, 2025

OK, I had found another bug in that when you changed the dimensions, the canvas wouldn't change shape even if the change resulted in a different requestedAspectRatio. That's fixed now, so we remain in exactly the state of my immediately preceding comment.

@katestange
Copy link
Member

@katestange, you have the alpha formula in the Modular Multiplication Table featured specimen to be abs((x*y) % 200-100)/100, but this seems to presuppose that the number of rows and columns is 200. But a nice thing to do is to experiment with different moduli by changing the number of rows and columns. So would it be better for the formula to be abs(2((x*y) % c) - c)/c ?

Definitely!

@gwhitney
Copy link
Collaborator Author

gwhitney commented Mar 7, 2025

I think it's fantastic, we should add it as a gallery specimen!

OK, I will definitely use it for the snapshot. As far as featured specimens go, I think we shouldn't have both the Ulam Divisors and this one -- I feel like they are cognitively too close. I think we may at some point want to have a "library" of specimens that are not all "Featured" and then I'd be happy to include this (as well as maybe a very plain, very zoomed-out Ulam spiral). For now I will just put it in the interesting specimens discussion.

@gwhitney
Copy link
Collaborator Author

gwhitney commented Mar 7, 2025

OK, please check out the new placeholders for dimensions and aspect. It was a bit tricky because the placeholder needs to stay even when you have entered the number of rows but not the number of columns, so that you can see how many columns the visualizer ended up choosing. But I think I have it working OK now -- happy for any feedback. As far as I know, once we are settled on this I can update the CI snapshots and mark this as ready for review. Of course if you see anything else that needs improving, just let me know.

@katestange
Copy link
Member

OK, please check out the new placeholders for dimensions and aspect. It was a bit tricky

Wow, this is great! It's really nice and intuitive.

@gwhitney gwhitney marked this pull request as ready for review March 11, 2025 20:08
@gwhitney
Copy link
Collaborator Author

OK, I am not at the moment aware of anything that needs to be done with respect to this PR and all tests are passing, so I have marked it ready for review. Of course, if anything comes up in the final review, I am happy to make further changes/fixes.

@katestange
Copy link
Member

Small detail: "visualizer" isn't capitalized in the documentation page title (in contrast to other Visualizers). That's the only nitpick I have left!

@gwhitney
Copy link
Collaborator Author

OK, typo should be fixed.

@katestange katestange merged commit b235d55 into numberscope:ui2 Mar 12, 2025
2 checks passed
katestange added a commit to katestange/frontscope that referenced this pull request Mar 12, 2025
* wip: start FormulaGrid visualizer

* feat: Prototype FormulaGrid visualizer

* feat: prototype mouseover feature of FormulaGrid

* fix: correct aspect validation

* fix: interpret any number as a color in some way or other

* fix: Typescript doesn't know abs(number) is number??

* fix: Miscellaneous UI improvements

  * 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

* feat: mouseover text opaque, shadowed, and moves left to right

* feat: inset is formula

* fix: edge browser z-indexing

* fix: updates per review

* doc: add diagram for hexagon and plug for using it with Triangle fill order

* featured specs

* doc: triangle diagram and misc fixes

* feat: mouseover popup travels with mouse pointer, avoiding in corner

* doc,test: document and test math.triangular and inverse

* fix,test: remove async race in Scope.vue mounting, update tests

* fix: Recompute size on visualizer reset(); e.g, aspect ratio might change

* ui: placeholder for aspect

* ui: ditto for dimensions

* feat: allow placeholder to remain on input, use for dimensions/aspect

* chore: briefer formulas in featured gallery and generate example images

* doc: final polish on new doc, some formula features for it

* chore: continuous integration snapshots

* doc: fix capitalization typo

---------

Co-authored-by: Kate Stange <kstange@math.colorado.edu>
gwhitney added a commit that referenced this pull request Jan 12, 2026
* wip: start FormulaGrid visualizer

* feat: Prototype FormulaGrid visualizer

* feat: prototype mouseover feature of FormulaGrid

* fix: correct aspect validation

* fix: interpret any number as a color in some way or other

* fix: Typescript doesn't know abs(number) is number??

* fix: Miscellaneous UI improvements

  * 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

* feat: mouseover text opaque, shadowed, and moves left to right

* feat: inset is formula

* fix: edge browser z-indexing

* fix: updates per review

* doc: add diagram for hexagon and plug for using it with Triangle fill order

* featured specs

* doc: triangle diagram and misc fixes

* feat: mouseover popup travels with mouse pointer, avoiding in corner

* doc,test: document and test math.triangular and inverse

* fix,test: remove async race in Scope.vue mounting, update tests

* fix: Recompute size on visualizer reset(); e.g, aspect ratio might change

* ui: placeholder for aspect

* ui: ditto for dimensions

* feat: allow placeholder to remain on input, use for dimensions/aspect

* chore: briefer formulas in featured gallery and generate example images

* doc: final polish on new doc, some formula features for it

* chore: continuous integration snapshots

* doc: fix capitalization typo

---------

Co-authored-by: Kate Stange <kstange@math.colorado.edu>
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