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

Add default plotting description for Collections #634

Merged
merged 31 commits into from Jul 28, 2023

Conversation

Alexboiboi
Copy link
Member

@Alexboiboi Alexboiboi commented Jul 20, 2023

This adds a default description to the the Collection objects. This PR also makes the draw function get_trace public and therefore easily overridable when subclassing any magpylib core class. Some larger code base has been refactored, mainly in the traces_generic.py module.

import magpylib as magpy

sens = [magpy.Sensor(position=(0,0,2*i)) for i in range(5)]
src = [magpy.magnet.Cuboid(magnetization=(0,0,1), dimension=(1,1,1), position=(0,i/5,0)) for i in range(5)]
c1 = magpy.Collection(sens[0], style_label='Sensor Collection', style_color="red")
c2 = magpy.Collection(*src[:3], style_label='Source Collection', style_description="custom description")
c3 = magpy.Collection(*sens[1:], *src[3:])

magpy.show({"objects": c1, "col":1}, {"objects": c2, "col":2}, {"objects": c3, "col":3}, backend="matplotlib", figsize=(20,10))
image

@@ -37,6 +37,7 @@
from magpylib._src.display.traces_utility import draw_arrowed_circle
from magpylib._src.display.traces_utility import draw_arrowed_line
from magpylib._src.display.traces_utility import get_flatten_objects_properties
from magpylib._src.display.traces_utility import get_label

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
magpylib._src.display.traces_utility
begins an import cycle.
@codecov-commenter
Copy link

codecov-commenter commented Jul 20, 2023

Codecov Report

Merging #634 (c4fe7be) into main (03116b5) will decrease coverage by 0.17%.
The diff coverage is 97.44%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main     #634      +/-   ##
==========================================
- Coverage   99.22%   99.06%   -0.17%     
==========================================
  Files          54       55       +1     
  Lines        6883     6928      +45     
==========================================
+ Hits         6830     6863      +33     
- Misses         53       65      +12     
Files Changed Coverage Δ
magpylib/_src/style.py 99.86% <66.66%> (-0.14%) ⬇️
magpylib/_src/display/traces_core.py 96.71% <96.71%> (ø)
magpylib/_src/display/traces_generic.py 100.00% <100.00%> (ø)
magpylib/_src/display/traces_utility.py 99.74% <100.00%> (+0.01%) ⬆️
magpylib/_src/obj_classes/class_BaseDisplayRepr.py 100.00% <100.00%> (ø)
magpylib/_src/obj_classes/class_Collection.py 100.00% <100.00%> (ø)
magpylib/_src/obj_classes/class_Sensor.py 100.00% <100.00%> (ø)
magpylib/_src/obj_classes/class_current_Line.py 100.00% <100.00%> (ø)
magpylib/_src/obj_classes/class_current_Loop.py 100.00% <100.00%> (ø)
magpylib/_src/obj_classes/class_magnet_Cuboid.py 100.00% <100.00%> (ø)
... and 7 more

@Alexboiboi Alexboiboi added this to the 4.4 milestone Jul 20, 2023
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

@OrtnerMichael
Copy link
Member

@Alexboiboi

  1. This works only in plotly, not in the other two backends.

  2. Also: when did we descide that we can show objects without dimension ? I like the idea - but I don't rememeber that we discussed this. Is this new in this PR ?

@Alexboiboi
Copy link
Member Author

  1. This works only in plotly, not in the other two backends.

Will fix it. If we agree on below

  1. Also: when did we decide that we can show objects without dimension ? I like the idea - but I don't remember that we discussed this. Is this new in this PR ?

Yes it is new. It came up because of a bug (see below). Then I implemented it

import magpylib as magpy

src = magpy.magnet.Cuboid()
magpy.show(magpy.Collection(src))

raises MagpylibMissingInput: Parameter dimension of Cuboid(id=140665705787888) must be set.

but

import magpylib as magpy

src = magpy.magnet.Cuboid()
magpy.show(magpy.Collection(src))

bypasses the check_function validation process.
Should we permit it in all cases and display a dimensionless scatter point like in the figure above?

@Alexboiboi
Copy link
Member Author

@OrtnerMichael

I fixed the check_dimension bypass bug. I'll leave the feature of displaying unset dimension hidden in this PR and I opened an issue (#638) to discuss it.

Ready for review now i think

@Alexboiboi Alexboiboi marked this pull request as ready for review July 26, 2023 15:10
Copy link
Member

@OrtnerMichael OrtnerMichael left a comment

Choose a reason for hiding this comment

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

seems to work

@OrtnerMichael OrtnerMichael merged commit 4a72dab into main Jul 28, 2023
10 checks passed
@OrtnerMichael OrtnerMichael deleted the collection-description branch July 28, 2023 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants