-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Contour legend #2891
Contour legend #2891
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR 💪
I misread parts of #2880, where I thought the individual contour levels would optionally get corresponding legend items too. Was this ever discussed?
Thanks for fixing those heatmap/contour ordering bugs that I probably encountered before in #2574, but didn't bother fixing. My bad.
I made a few comments. I found one potential red flag: the additional showlegend: false
in colorscale_opacity,json
and contour_scatter.json
.
var markersOrText = subTypes.hasMarkers(trace) || subTypes.hasText(trace); | ||
var anyFill = showFill || showGradientFill; | ||
var anyLine = showLine || showGradientLine; | ||
var pathStart = (markersOrText || !anyFill) ? 'M5,0' : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice touch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/traces/contour/plot.js
Outdated
@@ -28,32 +27,35 @@ var constants = require('./constants'); | |||
var costConstants = constants.LABELOPTIMIZER; | |||
|
|||
exports.plot = function plot(gd, plotinfo, cdcontours, contourLayer) { | |||
var uidLookup = getUidsFromCalcData(cdcontours); | |||
var contours = contourLayer.selectAll('g.contour') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call -> #2907
test/jasmine/tests/contour_test.js
Outdated
@@ -439,21 +441,21 @@ describe('contour plotting and editing', function() { | |||
.then(function() { | |||
_assert({ | |||
hmIndex: 0, | |||
contoursIndex: 1 | |||
contoursIndex: 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ok, that's tricky. Now that <.hm>
is inside <g.contour>
, this test is a little tricky to interpret.
Maybe we could instead assert:
Array.prototype.slice.call(contourPlot.children).map(n => n.classList[0])
// to check ordering
Array.prototype.slice.call(contourPlot.children).map(n => n.children.length)
// to check the number of children
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is really about layer ordering, which is a consistently testable feature in SVG and likely to be useful elsewhere in our tests, I added a generic custom assertion for this. See what you think e25b9ff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See what you think e25b9ff
💯
test/jasmine/tests/contour_test.js
Outdated
@@ -501,4 +503,34 @@ describe('contour plotting and editing', function() { | |||
.catch(fail) | |||
.then(done); | |||
}); | |||
|
|||
it('keeps the correct ordering after hide and show', function(done) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice test. Thanks!
test/jasmine/tests/contour_test.js
Outdated
expect(getIndices()).toEqual([0, 1]); | ||
}) | ||
.catch(fail) | ||
.then(done); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh would you mind s/fail/failTest
in this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
failTest in contour & carpet -> 7843d83
test/jasmine/tests/carpet_test.js
Outdated
expect(getIndices()).toEqual([1, 2]); | ||
}) | ||
.catch(fail) | ||
.then(done); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one more s/fail/failTest
- we must be getting pretty close 🤞
function lineGradient(s) { | ||
if(s.size()) { | ||
var gradientID = 'legendline-' + trace.uid; | ||
Drawing.lineGroupStyle(s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should double-check that this works ok with line.dash
and other line stylings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, added to a mock in 73f279b
@@ -27,6 +27,10 @@ module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, | |||
} | |||
|
|||
if(coloring !== 'none') { | |||
// plots/plots always coerces showlegend to true, but in this case | |||
// we default to false and (by default) show a colorbar instead | |||
if(traceIn.showlegend !== true) traceOut.showlegend = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,54 @@ | |||
{ | |||
"data":[{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice mock! Could we lock down the contourcarpet
legend behavior in a mock as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and for histogram2dcontour
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, histogram2dcontour
didn't get this functionality before -> added and tested in 73f279b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and contourcarpet colored contours in 74e7f84
and referencing #2642 where work in this PR could somewhat easily be extended to heatmap, histogram2d and surface traces. |
and add assertNodeOrder as a custom assertion
@@ -9,16 +9,6 @@ | |||
|
|||
'use strict'; | |||
|
|||
exports.legendGetsTrace = function legendGetsTrace(trace) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was used in getLegendData
and in legendDefaults
, but even before one of them overrode half the logic, and now that logic has diverged further, so it didn't make sense to pull it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice 🔪 job here
coerce('showlegend'); | ||
coerce('legendgroup'); | ||
} | ||
else { | ||
traceOut._dfltShowLegend = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#749 🙄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the record: I added _dfltShowLegend
because there's otherwise no robust way to tell from just traceIn
and traceOut
what the default is... so there would be some situations where we would NOT show a legend (eg scatter + colored contour) but then setting showlegend: false
explicitly in the trace that already defaults to showlegend: false
would make the legend appear 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that's what I expected. I don't think there's a nicer way to do this than what you coded in this commit 👌
'a) Two or more traces would by default be shown in the legend.', | ||
'b) One pie trace is shown in the legend.', | ||
'c) One trace is explicitly given with `showlegend: true`.' | ||
].join(' ') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for 📚
Thanks for restoring backward-compatibility in 1d05081 All my blocking comments have been addressed, so 💃 We should still open an issue about (potential) heatmap and carpet layer ordering bugs as mentioned in #2891 (comment) |
Addresses most of #2880, all but the question about colorscales avoiding the legend.
contour
(orcontourcarpet
) trace can now appear in the legendDrawing.gradient
is extended to support arbitrary stops, as used by our built-in and custom colorscales. (Side note: we could use this to simplify continuous colorbar drawing, ie instead of making lots of little constant-color rectangles just make one rectangle with the colorscale applied as a gradient. I did not do that in this PR. But doing so would probably make it easier to finally close colorbar draws outside the bounds #970)contour
andcontourcarpet
) by, surprise surprise, moving to more standard d3 enter/exit/each(order) logic.cc @etpinard