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

refactor: Improve uniformity of VisualizerInterface and P5Visualizer #310

Merged
merged 3 commits into from
Apr 23, 2024

Conversation

gwhitney
Copy link
Collaborator

Three related interface changes for the Visualizer hierarchy, as
discussed in #293. These are all designed to make some of the
details of defining a Visualizer less confusing and more concise.

(A) In P5Visualizer, draw() should be abstract and hence required
on runnable derived Visualizers, since any (additional) boilerplate
needed by all P5Visualizers would go in the function that wraps
this method in the default inhabit() method. Thus implementation
draw() functions no longer need to call super.draw().
(B) Since setup() is the default p5 initialization method and can only
be called once per sketch anyway, clarify that generally initialization
should be carried out in setup() rather than inhabit(), in derived
Visualizers.
(C) Since name is used as an instance property in SequenceInterface
indicating the details of the particular interface, re-designate
that information as the return value of a visualization() method
of an entity implementing the VisualizationInterface, and suggest
that it should only depend on the class of the entity, not the
instance. Implement this in the P5Visualizer hierarchy with
the visualizationName static property, and modify the
VisualizerExportModule constructor to look for it there, so that
the visualizationName will not have to be stated twice in every
module implementing a Visualizer. At such time as there are other
base classes for concrete Visualizers, these conventions should
probably be moved one level up to a common base class of all
visualizers; there is nothing specifically related to p5 about this
naming scheme.

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.

@gwhitney
Copy link
Collaborator Author

(A) Oops, I accidentally pushed to origin rather than my fork when creating this PR. I will try to be more careful.

(B) There were likely some doc-page changes that should go with this, but my belief is that Aaron will merge or rebase this into #293 where there are overlapping doc changes and straighten it all out. @Vectornaut if that's not right, let me know, and I can add a doc commit to this PR as well.

Copy link
Member

@katestange katestange left a comment

Choose a reason for hiding this comment

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

Works in production and dev mode.

src/visualizers/Grid.ts Outdated Show resolved Hide resolved
src/visualizers/ModFill.ts Outdated Show resolved Hide resolved
src/visualizers/NumberGlyph.ts Outdated Show resolved Hide resolved
src/visualizers/Turtle.ts Outdated Show resolved Hide resolved
   Three related interface changes for the Visualizer hierarchy, as
   discussed in #293. These are all designed to make some of the
   details of defining a Visualizer less confusing and more concise.

   (A) In P5Visualizer, draw() should be abstract and hence required
       on runnable derived Visualizers, since any (additional) boilerplate
       needed by all P5Visualizers would go in the function that wraps
       this method in the default inhabit() method. Thus implementation
       draw() functions no longer need to call super.draw().
   (B) Since setup() is the default p5 initialization method and can only
       be called once per sketch anyway, clarify that generally initialization
       should be carried out in setup() rather than inhabit(), in derived
       Visualizers.
   (C) Since `name` is used as an instance property in SequenceInterface
       indicating the details of the particular interface, re-designate
       that information as the return value of a `visualization()` method
       of an entity implementing the VisualizationInterface, and suggest
       that it should only depend on the class of the entity, not the
       instance. Implement this in the P5Visualizer hierarchy with
       the visualizationName static property, and modify the
       VisualizerExportModule constructor to look for it there, so that
       the visualizationName will not have to be stated twice in every
       module implementing a Visualizer. At such time as there are other
       base classes for concrete Visualizers, these conventions should
       probably be moved one level up to a common base class of all
       visualizers; there is nothing specifically related to p5 about this
       naming scheme.
@gwhitney
Copy link
Collaborator Author

OK, all visualizers have a description. Should we enforce this going forward, or leave it optional as it has been to date?

@katestange
Copy link
Member

OK, all visualizers have a description. Should we enforce this going forward, or leave it optional as it has been to date?

I don't know... Yes, I'm imagining this might be a tooltip text or populate some type of menu or explorer or some type. I leave it to you to decide if it's useful to make mandatory here. It could be something that depends on the UI revamp.

Copy link
Member

@katestange katestange left a comment

Choose a reason for hiding this comment

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

tiny comment

src/visualizers/ShiftCompare.ts Show resolved Hide resolved
@gwhitney
Copy link
Collaborator Author

OK, I will remove any periods from descriptions that have them since I think they are mostly not full sentences. And I will make descriptions mandatory, since we now have them all and they seem like they might be handy in a UI revamp, if we ever have a chance to do one ;-)

@gwhitney
Copy link
Collaborator Author

Done. If all looks good to you, Kate, let's let @Vectornaut merge this one so he can time it most smoothly with his work on #293.

@katestange
Copy link
Member

looks good!

@gwhitney
Copy link
Collaborator Author

OK, Aaron, ready for you to push the merge button whenever it works for you.

@Vectornaut
Copy link
Collaborator

Implement this in the P5Visualizer hierarchy with
the visualizationName static property, and modify the
VisualizerExportModule constructor to look for it there, so that
the visualizationName will not have to be stated twice in every
module implementing a Visualizer.

I like this simplification!

Comment on lines +5 to +10
<h5 class="card-title">
{{ `${viz.visualization()} of ${seq.name}` }}
</h5>
<p class="card-text">
This is a bundle of {{ seq.name + ' + ' + viz.name }}.
Display {{ seq.name }} using a {{ viz.visualization() }}
visualization.
Copy link
Collaborator

Choose a reason for hiding this comment

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

These new messages are much clearer to me.

@Vectornaut Vectornaut merged commit 0257873 into main Apr 23, 2024
4 checks passed
Vectornaut pushed a commit to Vectornaut/frontscope that referenced this pull request Apr 23, 2024
- Discuss the new `inhabit()` / `depart()` scheme
- Explain that `super.setup()` calls `createCanvas()`
- Note that a `draw()` implementation is required (as of numberscope#310)
- Remove reference to `super.draw()`, which is removed in numberscope#310
Vectornaut pushed a commit to Vectornaut/frontscope that referenced this pull request Apr 23, 2024
@gwhitney gwhitney deleted the viz_interface branch May 18, 2024 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

visualizer superclass methods should be abstract
3 participants