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

Introducing 3D annotations #1638

Merged
merged 29 commits into from
May 26, 2017
Merged

Introducing 3D annotations #1638

merged 29 commits into from
May 26, 2017

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented Apr 28, 2017

resolves #751 and more precisely implements #751 (comment).

peek 2017-04-28 17-29

This PR is still a very much WIP. Here are some TODOs:

  • get the autorange logic hooked in
  • get this to work with category axes types
  • register the new logic under components/annotations/ (or a new components/annotations3d maybe?)
  • DRY up defaults
  • tests

- one `data-index` attr on the top-level ann group
  should be enough.
- instead of looking through the whole graph div
- so that they can be mutated downstream
- which expects an option object, xaxis and yaxis
- generalize className given to annotation to group and
  base attribute string (for editable: true)
  to accommodate 3d annotations
- use `_input` ref instead of `gd.layout` to grab user layout options
- add attrs and defaults to scene containers
- N.B. x/y/z are always in data coords ax/ay are always in px coords
- mock xaxis and yaxis on scene updates so that
  their l2p method updates the projection data coord in the x-y plane
- and annotations handler in render loop
- as this problem is ill-defined,
  mouse xy -> scene xyz as infinity-many solutions.
- N.B. editing arrow tail position (i.e. ax, ay) and annotation
  text works!
@@ -168,7 +168,6 @@ function drawOne(gd, index) {
var font = options.font;

var annText = annTextGroupInner.append('text')
.classed('annotation', true)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This commit is reverted in ababc49 to make the tests added in #1683

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you've hit on a flaw in how github displays comments... I'm reading:

This commit is reverted in ababc49 to make the tests added in #1683

but I'm looking at a31549d which came after ababc49 and rereverts the change originally made in 1a8f1ed 💫

Anyway, totally approve of this change. My best guess is these got the same .annotation class because at some point in the distant past they weren't all encapsulated in one group like they are now, and I wanted to be able to more easily select the whole annotation. Has always been confusing to deal with...

Copy link
Contributor Author

@etpinard etpinard May 25, 2017

Choose a reason for hiding this comment

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

In brief, as of a31549d, the annotations text nodes have class name annotation-text.

etpinard added 5 commits May 24, 2017 19:19
- coerce (x, y, z) in scene.plot after the ax._categories
  is filled
- use .r2l to update annotation position
- could be cleaned up (by e.g. wrapping the 3d annotation default
  into a required subroutine).
- N.B. does not take into consideration the arrowhead (debatable)
@etpinard
Copy link
Contributor Author

etpinard commented May 24, 2017

Ok. All the functionality is in (I think), so I'll tagged this as reviewable.

I'm currently thinking about putting this new 3d annotation code under a new component components/annotations3d/ which would reuse much of components/annotations/ but would remain separate allowing users that do not need 3d annotations (or 3d graphs 😏 ) for that matter to trim down their bundle size even more in v2 (i.e. when components will be taken out of the core module).

Any objections before I shuffle the new code around?

etpinard added 2 commits May 25, 2017 10:48
- so that the `selectAll('.annotation')` call Annotation.draw
  doesn't clear 3d annotation text nodes.

ann._xa = {};
Lib.extendFlat(ann._xa, base);
Axes.setConvert(ann._xa);
Copy link
Collaborator

Choose a reason for hiding this comment

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

what do you need from setConvert, if you're overriding _offset and l2p?

Copy link
Collaborator

Choose a reason for hiding this comment

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

what do you need from setConvert, if you're overriding _offset and l2p?

Oh I see - ax.l2p is now controlling all the other 2p conversions (instead of the local var l2p) so you get those for free. Seems fine - tiny tiny 🐎 hit from having to look up attributes more often... but should be negligible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see - ax.l2p is now controlling all the other 2p conversions (instead of the local var l2p) so you get those for free

Exactly.

@alexcjohnson
Copy link
Collaborator

Any objections before I shuffle the new code around?

sounds reasonable, go for it!

var fullLayout = gd._fullLayout;
var gs = gd._fullLayout._size;

var className = options._scene ?
Copy link
Collaborator

Choose a reason for hiding this comment

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

elsewhere _scene is an object, but this one is an id - can we call it _sceneId instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Done in c084da0

].join(' ')
},
ax: {
valType: 'any',
Copy link
Collaborator

Choose a reason for hiding this comment

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

'number' now since it's always going to be in px?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Done in adfc305

.attr('data-index', String(index))
.style('opacity', options.opacity);

// another group for text+background so that they can rotate together
var annTextGroup = annGroup.append('g')
.classed('annotation-text-g', true)
.attr('data-index', String(index));
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 another relic 🔪

etpinard added 4 commits May 25, 2017 16:01
- N.B. leave (small) autorange block in scene.js
- which coerces all non-position attributes for
  annotations and annotations3d
- automatically adds supports for 'hovertext' and 'hoverlabel'
  for annotation3d 🎉
- as they can only be set in pixels.
@etpinard etpinard force-pushed the gl3d-annotations branch from 21a5a0e to 876b37b Compare May 25, 2017 20:26
@etpinard etpinard force-pushed the gl3d-annotations branch from 876b37b to ef985cf Compare May 25, 2017 20:30
@@ -75,13 +75,13 @@ module.exports = {
arrowwidth: annAtts.arrowwidth,
standoff: annAtts.standoff,
hovertext: annAtts.hovertext,
hoverlabel: annAtts.hoverlabel
hoverlabel: annAtts.hoverlabel,
captureevents: annAtts.captureevents
Copy link
Contributor Author

@etpinard etpinard May 25, 2017

Choose a reason for hiding this comment

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

With this, hover labels on 3d annotations are working:
peek 2017-05-25 16-37

off:

        Plotly.newPlot('graph', [{
            type: 'scatter3d',
            x: [1, 2, 3],
            y: [1, 2, 3],
            z: [1, 2, 1]
        }], {
            scene: {
                annotations: [{
                    text: 'hello',
                    x: 2, 
                    y: 2,
                    z: 2,
                    ay: -100,
                    hovertext: 'HELLO',
                    hoverlabel: {
                      bgcolor: 'red',
                      font: {size: 20}
                    }
                }]
            },
        })

Copy link
Collaborator

Choose a reason for hiding this comment

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

what about the plotly_clickannotation event? Looks like that might need a sceneId if there is one? Which brings up the point that for extensibility to other non-cartesian subplots perhaps it should really be called subplotId...

Copy link
Contributor Author

@etpinard etpinard May 26, 2017

Choose a reason for hiding this comment

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

  • commit 8b8a088 generalises drawRaw
  • commit 1d5606a add subplotId to the plotly_clickannotation event data + 🔒 it down.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After 1d5606a, this and that assertions are failing, because the event data now contains subplotId: false for cartesian/paper-ref annotations.

@alexcjohnson would you prefer leaving subplotId out of the cartesian/paper-ref annotation event data or keep it as subplotId: false?

Copy link
Collaborator

Choose a reason for hiding this comment

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

would you prefer leaving subplotId out of the cartesian/paper-ref annotation event data or keep it as subplotId: false

haha didn't see this before my comment

yeah, lets omit it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 46ab63d

@alexcjohnson
Copy link
Collaborator

That's all from my side, looks great! 💃

@etpinard etpinard merged commit 6b7c9d7 into master May 26, 2017
@etpinard etpinard deleted the gl3d-annotations branch May 26, 2017 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Data-referenced annotations on 3D graphs
2 participants