Skip to content

Histogram events & bin hover label improvements #2113

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

Merged
merged 18 commits into from
Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/traces/histogram/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,19 @@ module.exports = function calc(gd, trace) {
var cdi = {
p: pos[i],
s: size[i],
b: 0,
pts: inputPoints[i]
b: 0
};
if(uniqueValsPerBin) {
cdi.p0 = cdi.p1 = (inputPoints[i].length) ? pos0[inputPoints[i][0]] : pos[i];
}
else {
cdi.p0 = roundFn(binEdges[i]);
cdi.p1 = roundFn(binEdges[i + 1], true);

// pts and p0/p1 don't seem to make much sense for cumulative distributions
if(!cumulativeSpec.enabled) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A questionable decision... this gets at some of the same issues that led to cumulative.currentbin but in principle a CDF shows the sum of all the data prior to a specific point, not the data within that bin. perhaps I should shift p0 and p1 depending on currentbin so that the hover label at least gets the description "all the data prior to X" precisely correct, even though it'll be a different value than the center of the bar...

And then what about pts? You could say it should be included and again should be "all the data prior to X" but then it would be meaningless to select a single bar and not all the bars before it. Alternatively pts could contain "all the data that was added in this bar" which might be more useful in terms of selecting a single bar, but it's not really what that bar means.

Copy link
Contributor

Choose a reason for hiding this comment

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

so that the hover label at least gets the description "all the data prior to X"

Yeah. I think something along those lines would be useful down the road.

You could say it should be included and again should be "all the data prior to X" but then it would be meaningless to select a single bar and not all the bars before it. Alternatively pts could contain "all the data that was added in this bar"

Sounds to me like both all-data-prior-to-X and data-added-in-this-bar point lists could be useful, so we'll might have to emit both in the future. Leaving this discussion for another time is 👌 with me. I doubt that most plotly.js users even know about cumulative histograms.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great, I'll make a new issue to discuss how this should work for CDFs.

cdi.pts = inputPoints[i];
if(uniqueValsPerBin) {
cdi.p0 = cdi.p1 = (inputPoints[i].length) ? pos0[inputPoints[i][0]] : pos[i];
}
else {
cdi.p0 = roundFn(binEdges[i]);
cdi.p1 = roundFn(binEdges[i + 1], true);
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️ ing that you were able to put all thing new rounding logic in calc.

}
}
cd.push(cdi);
}
Expand Down
9 changes: 6 additions & 3 deletions src/traces/histogram/event_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ module.exports = function eventData(out, pt) {
out.yaxis = pt.ya;

// specific to histogram
out.pointNumbers = pt.pts;
out.binNumber = out.pointNumber;
delete out.pointNumber;
// CDFs do not have pts (yet?)
if(pt.pts) {
out.pointNumbers = pt.pts;
out.binNumber = out.pointNumber;
delete out.pointNumber;
}

return out;
};
11 changes: 7 additions & 4 deletions src/traces/histogram/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {

pointData = pts[0];
var di = pointData.cd[pointData.index];
var trace = pointData.cd[0].trace;

var posLetter = pointData.cd[0].trace.orientation === 'h' ? 'y' : 'x';
if(!trace.cumulative.enabled) {
var posLetter = trace.orientation === 'h' ? 'y' : 'x';

pointData[posLetter + 'LabelVal0'] = di.p0;
pointData[posLetter + 'LabelVal1'] = di.p1;
pointData.pts = di.pts;
pointData[posLetter + 'LabelVal0'] = di.p0;
pointData[posLetter + 'LabelVal1'] = di.p1;
pointData.pts = di.pts;
}

return pts;
};