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 spikelines #2247

Merged
merged 12 commits into from Jan 17, 2018

Conversation

Projects
None yet
5 participants
@apalchys
Copy link
Contributor

commented Jan 11, 2018

This PR adds support of spikelines in any hovermode.

Also some new properties were added:

  • spikedistance and hoverdistance to control the range of appearing of spikelines and hoverlabels;
  • spikesnap to control the placement of the spikelines point.

Note: only the cartesian type of axis supports new functionality.

Relates to #2155

@etpinard

This comment has been minimized.

Copy link
Member

commented Jan 15, 2018

I'll review this tomorrow am (UTC-5). Sorry for the wait.

@etpinard
Copy link
Member

left a comment

@apalchys amazing work!

To the best of my knowledge, this latest iteration has everything @alexcjohnson described in his #2155 (comment) done in a very clear and concise matter.

I found a few ways to make your additions to fx/hover.js even clearer. Let me know what you think!

My most blocking comments are the following:

  • declare hoverdistance and spikedistance with min: -1
  • clicking on spikes button an even number of times in the modebar should get the user back to the original settings

Just as an FYI, if you can addressed these issues before tomorrow night, this PR will be merged and released as part of 1.33.0 on Thursday.


hoverdistance: {
valType: 'integer',
min: 0,

This comment has been minimized.

Copy link
@etpinard

etpinard Jan 16, 2018

Member

As Infinity isn't JSON-serializable, we declare attributes of the likes (e.g. hoverlabel.namelength) with min: -1, so that users can set hoverdistance: -1 for an infinite search radius. Morevover, hoverdistance: 0 should imply no hover labels/events, similarly for spikedistance.

This comment has been minimized.

Copy link
@apalchys

apalchys Jan 17, 2018

Author Contributor

Thanks! Done.

role: 'style',
editType: 'none',
description: [
'Sets the default distance (in points) to look for data',

This comment has been minimized.

Copy link
@etpinard

etpinard Jan 16, 2018

Member

We usually write (in pixels) instead of (in points) in our attribute descriptions.

@@ -28,6 +28,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
else hovermodeDflt = 'closest';

coerce('hovermode', hovermodeDflt);
coerce('hoverdistance');

This comment has been minimized.

Copy link
@etpinard

etpinard Jan 16, 2018

Member

We could get fancy here by making this:

var hoverMode = coerce('hovermode', hovermodeDflt);
if(hoverDistance) coerce('hoverdistance');

as hoverdistance is useless when hovermode: false.

Unfortunately, we can't add similar logic for spikedistance here as showspikes is per axis.

This comment has been minimized.

Copy link
@apalchys

apalchys Jan 17, 2018

Author Contributor

Actually, we can, because if hovermode is false, we are not firing any hover events, so the spikelines are disabled too.
So we can write it like this:

    var hoverMode = coerce('hovermode', hovermodeDflt);
    if(hoverMode) {
        coerce('hoverdistance');
        coerce('spikedistance');
    }

This comment has been minimized.

Copy link
@etpinard

etpinard Jan 17, 2018

Member

Good catch. Thanks!

@@ -551,12 +548,10 @@ modeBarButtons.toggleSpikelines = {
click: function(gd) {
var fullLayout = gd._fullLayout;

fullLayout._cartesianSpikesEnabled = fullLayout.hovermode === 'closest' ?
(fullLayout._cartesianSpikesEnabled === 'on' ? 'off' : 'on') : 'on';
fullLayout._cartesianSpikesEnabled = fullLayout._cartesianSpikesEnabled === 'on' ? 'off' : 'on';

This comment has been minimized.

Copy link
@etpinard

etpinard Jan 16, 2018

Member

We might still need something similar here.

For example, with

var layout = {
    xaxis: {
      showspikes: true
    },
   yaxis: {
     showspikes: false
   }
  };

then click on toggleSpikeLines gives:

peek 2018-01-16 11-58

with no way to get back to the original behavior using the mode bar buttons.

This comment has been minimized.

Copy link
@apalchys

apalchys Jan 17, 2018

Author Contributor

Done

This comment has been minimized.

Copy link
@etpinard

etpinard Jan 17, 2018

Member

Great. Thanks!

Now, could you restore and update the modebar_test.js cases you removed in your first commit?

@@ -2048,7 +2048,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
top: pos,
bottom: pos,
left: ax._offset,
rigth: ax._offset + ax._length,
right: ax._offset + ax._length,

This comment has been minimized.

Copy link
@etpinard

etpinard Jan 16, 2018

Member

Good catch. Did this cause any bugs previously?

This comment has been minimized.

Copy link
@apalchys

apalchys Jan 17, 2018

Author Contributor

It did in one of my early implementations

return result;
}

if(fullLayout._has('cartesian')) {

This comment has been minimized.

Copy link
@etpinard

etpinard Jan 16, 2018

Member

Nice use of _has('cartesian') 👌

@@ -1236,3 +1406,12 @@ function hoverChanged(gd, evt, oldhoverdata) {
}
return false;
}

function spikesChanged(gd, oldspikepoints) {
// don't emit any events if nothing changed

This comment has been minimized.

Copy link
@etpinard

etpinard Jan 16, 2018

Member

Looks like this got copied from function hoverChanged() {}, but spike lines don't emit any events whatsoever. Would you mind 🔪 this line to avoid confusion.

This comment has been minimized.

Copy link
@apalchys

apalchys Jan 17, 2018

Author Contributor

I use it to avoid the redrawing of the plot because of new spikelines if spikelines points didn't change

if(closestVPoints.length) {
var closestVPt = closestVPoints[0];
if(isNumeric(closestVPt.x0) && isNumeric(closestVPt.y0)) {
tmpPoint = clearClosestPoint(closestVPt);

This comment has been minimized.

Copy link
@etpinard

etpinard Jan 16, 2018

Member

This clearClosestPoint method is doing mostly initialisation as opposed to clearing something that exists already.

Would be mind rename it either initClosestPoint or fillClosestPoint? This would make it more aligned with the rest of our codebase.

This comment has been minimized.

Copy link
@apalchys

apalchys Jan 17, 2018

Author Contributor

You are right, I've renamed it to fillClosestPoint.

xpx = xa.c2p(xval),
ypx = ya.c2p(yval),
dxy = function(point) {
var rad = Math.max(3, point.mrc || 0),

This comment has been minimized.

Copy link
@etpinard

etpinard Jan 16, 2018

Member

This Math.max(3, point.mrc || 0) only applies to scatter traces and is a duplicate of this line in scatter/hover.js.

Perhaps we should make the relevant traces/*/hover.js methods (I can think of scatter at the moment, but there might be more) add a .kink field to their output point data to not have to duplicate the somewhat tricky logic here again?

This comment has been minimized.

Copy link
@apalchys

apalchys Jan 17, 2018

Author Contributor

Moved it to the point.kink property of the scatter/hover returned object.

var xa,
ya;

var showY = closestPoints.hLinePoint ? true : false;

This comment has been minimized.

Copy link
@etpinard

etpinard Jan 16, 2018

Member

maybe:

var showY = !!closestPoints.hLinePoint;

// or
var showY = Boolean(closestPoints.hLinePoint);

would suffice?

This comment has been minimized.

Copy link
@apalchys

apalchys Jan 17, 2018

Author Contributor

Thanks, changed it to var showY = !!closestPoints.hLinePoint;

@apalchys

This comment has been minimized.

Copy link
Contributor Author

commented Jan 17, 2018

@etpinard Thank you for the review! I fixed all highlighted issues. Please check.

@apalchys

This comment has been minimized.

Copy link
Contributor Author

commented Jan 17, 2018

hmm.. some test is failing but I can't reproduce it locally. Is it possible to re-run tests without commits?

@alexcjohnson

This comment has been minimized.

Copy link
Contributor

commented Jan 17, 2018

hmm.. some test is failing but I can't reproduce it locally. Is it possible to re-run tests without commits?

Mmm, I think I've seen that one fail sporadically. You can't rerun the test, but we can...

@etpinard

This comment has been minimized.

Copy link
Member

commented Jan 17, 2018

Awesome @apalchys

Once the spike toggling modebar tests are restored and updated (#2247 (comment)), this PR will be good to merge!

@etpinard

This comment has been minimized.

Copy link
Member

commented Jan 17, 2018

Great PR. Thanks very much @apalchys

💃 💃 💃

@etpinard etpinard merged commit e341edd into plotly:master Jan 17, 2018

1 check passed

ci/circleci Your tests passed on CircleCI!
Details

@etpinard etpinard added this to the v1.33.0 milestone Jan 17, 2018

@apalchys

This comment has been minimized.

Copy link
Contributor Author

commented Jan 17, 2018

@etpinard @alexcjohnson Thank you for your help! 👍

@lambone

This comment has been minimized.

Copy link

commented Feb 11, 2018

I found it does not work for scattergl and because the pointData in function hoverPoints lacks of kink attribute.

@alexcjohnson

This comment has been minimized.

Copy link
Contributor

commented Feb 11, 2018

@lambone see #2336 - I will include scattergl in the fix.

@wangyueming

This comment has been minimized.

Copy link

commented Feb 23, 2018

I checked the version 1.34.0, it does not work yet.

I made a simple fix in src/traces/scattergl/index.js.

    var minRad = (trace.mode.indexOf('markers') !== -1) ? 3 : 0.5;
    Lib.extendFlat(pointData, {
        color: getTraceColor(trace, di),

        x0: xc - rad,
        x1: xc + rad,
        xLabelVal: di.x,

        y0: yc - rad,
        y1: yc + rad,
        yLabelVal: di.y,

        // HACK add kink
        kink: Math.max(minRad, di.mrc || 0),
        cd: fakeCd
    });

@alexcjohnson

This comment has been minimized.

Copy link
Contributor

commented Feb 23, 2018

@wangyueming #2379 was only merged 3 days ago. It will be in 1.35, likely next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.