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 Behaviors #57

Closed
sanbales opened this issue Feb 25, 2023 · 2 comments · Fixed by #58
Closed

Refactor Behaviors #57

sanbales opened this issue Feb 25, 2023 · 2 comments · Fixed by #58
Labels
backwards-incompatible Breaks public API enhancement New feature or request
Milestone

Comments

@sanbales
Copy link
Contributor

sanbales commented Feb 25, 2023

Elevator Pitch

Refactor Behaviors to use the new Column and Nunjuck widgets, as developed in #54.

Motivation

  • This will make the behaviors more compact, and easier to use, and ultimately help new users understand how to use the library.
    • It will avoid issues with combining the individual behaviors, e.g., with the particles not displaying correctly unless they are all set to appropriate values.
    • Would make it easier to add validation to the results, helping users understand what values are not appropriate.

Design Ideas

  • Move away from the Behavior.(column_name|template), favoring dedicated widget subclasses Column and Nunjuck.
    • Work a means to coerce values into an appropriate type for the output of Nunjuck templates, this will help make falsey python types evaluate to false in js
  • Group behaviors into reasonable groups, e.g.,
    • NodeStyle combines NodeColors and NodeSizes
    • LinkStyle combines LinkColors and LinkWidths
    • LinkArrow combines LinkDirectionalArrowColor, LinkDirectionalArrowLength, and LinkDirectionalArrowRelPos
    • LinkParticles combines LinkDirectionalParticleColor, LinkDirectionalParticleSpeed, LinkDirectionalParticleWidth, amd LinkDirectionalParticles
  • Should we extend this pattern to Forces? It does not seem to be immediately relevant, but maybe there is a common way to think about them?
  • If not, should we refactor the python API and put the style related behaviors in their own submodule, e.g., ipyforcegraph/behaviors/style/ where we would have node.py, link.py, and shape.py?
@sanbales sanbales added the enhancement New feature or request label Feb 25, 2023
@sanbales sanbales added this to the 0.3.0 milestone Feb 25, 2023
@sanbales sanbales mentioned this issue Feb 25, 2023
39 tasks
@sanbales sanbales linked a pull request Feb 25, 2023 that will close this issue
39 tasks
@sanbales sanbales added the backwards-incompatible Breaks public API label Feb 28, 2023
@nrbgt
Copy link
Contributor

nrbgt commented Mar 1, 2023

I think the *Style would live under the NodeShapes and eventual LinkShapes

NodeShapes(size=10, color="red")

These would be ignored entirely in the presence of NodeShapes.shapes, and/or be an a shortcut for an implicit Circle:

NodeShapes(Circle(size=10, color="red"))

@sanbales
Copy link
Contributor Author

sanbales commented Mar 2, 2023

I think the *Style would live under the NodeShapes and eventual LinkShapes

NodeShapes(size=10, color="red")

These would be ignored entirely in the presence of NodeShapes.shapes, and/or be an a shortcut for an implicit Circle:

NodeShapes(Circle(size=10, color="red"))

Yep, completely agree.

sanbales pushed a commit that referenced this issue Mar 5, 2023
sanbales pushed a commit that referenced this issue Mar 6, 2023
sanbales pushed a commit that referenced this issue Mar 10, 2023
sanbales pushed a commit that referenced this issue Mar 11, 2023
sanbales added a commit that referenced this issue Mar 12, 2023
sanbales pushed a commit that referenced this issue Mar 13, 2023
sanbales added a commit that referenced this issue Mar 14, 2023
## References

- Implements gh-57 (by completing the implementation from gh-43)

## Code changes

- [x] combine behaviors based on their functionality
- [x] refactor behaviors to use the new `Column` and `Nunjucks` dynamic features, this includes:
  - [x] base `Behavior` model (or make new intermediary `Behavior` that accepts dynamic features)
  - [x] `node` shape (`color` and `size`)
  - [x] `link` shape (`color`, `width`, and 
    - [x] separately `arrows`
  - [x] `particles`
  - [x] `tooltips` for both `node` and `link` (formerly known as `labels`)
  - [x] all `forces`
    - [x] x
    - [x] y
    - [x] z
    - [x] link
    - [x] collision
    - [x] manybody
    - [x] center
    - [x] cluster
    - [x] dag  
- [x] `selection` 
  - [x] `node`  
    - [x] use row index instead of `id`
  - [x] `link`
  - [x] add optional `column_name`
- [x] recorders
  - [x] `image`
  - [x] `data`  
    - > this cannot reliably capture custom `*Selection.column_name` data, but can be combined with `.selected` indices
- [x] update notebooks
  - [x] `Behavior.ipynb`
  - [x] `Forces.ipynb`
  - [x] `Test_Forces.ipynb`
  - [x] `WidgetSource.ipynb`
- [x] update docs
- [x] update tests
- [x] fix line ending issues in `Windows` 🪟 to avoid inadvertently committing CRLF files to the repo
  - added a `fix-windows-line-endings` task to avoid inadvertently committing `CRLF` files, uses `dos2unix`
  - ~~also added `newline="\n"` to the `.write_text` calls but it does not seem to be sufficient~~
    - > not compatible with our oldest supported python
- [x] use a simpler and more consistent UI for the `DynamicModel` fields
  - e.g., added an auto-generated UI for traits created with `_make_trait` in `Utils.ipynb`, a better implementation for this is being explored in [gh-61-ui-for-behaviors](https://github.com/jupyrdf/ipyforcegraph/tree/gh-61-ui-for-behaviors)
- [x] add check for stderr outputs in notebook smoke test
  - [x] add `lxml` to utest env
- [x] move more widgets/hastraits that are never instantiated directly to `base`
  - [x] `Has*` for shapes, etc.

## User-facing changes

- Users now have a more compact and consistent API for the `behaviors`, the controls for these may also be more intuitive as we could use a single `Combobox` to specify a `Nunjucks` template, a `Column` name, or a literal value
- It is easier for users to integrate `ipyforcegraph` with other widgets as the interactions between behaviors is more predictable and tractable

<!-- For visual changes, include before and after screenshots here. -->

## Backwards-incompatible changes

- Following classes are no longer available:
  - ``behaviors.node.NodeSizes``
  - ``behaviors.node.NodeColors``
  - ``behaviors.link.LinkColors``
  - ``behaviors.link.LinkWidths``
  - ``behaviors.link.LinkColors``
  - ``behaviors.link.LinkDirectionalArrowColor``
  - ``behaviors.link.LinkDirectionalArrowLength``
  - ``behaviors.link.LinkDirectionalArrowRelPos``
  - ``behaviors.link.LinkDirectionalParticleColor``
  - ``behaviors.link.LinkDirectionalParticleWidth``
  - ``behaviors.link.LinkDirectionalParticleSpeed``
  - ``behaviors.link.LinkDirectionalParticles``

- Behaviors are grouped by functionality, not what they operate on, e.g., `NodeSelection` is no longer under ``behaviors.node`` but under ``behaviors.selection``.

---------

Co-authored-by: Santiago Balestrini <santiago.balestrini@gtri.gatech.edu>
Co-authored-by: Nicholas Bollweg <nicholas.bollweg@gtri.gatech.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backwards-incompatible Breaks public API enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants