Skip to content

Contour line labels #1815

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 39 commits into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
468ef5d
put all contour lines into one group (so we can clip it later)
alexcjohnson Jun 21, 2017
88cc33c
collect contour clipPath in the main <defs>
alexcjohnson Jun 21, 2017
ee7a839
more standard format for contour constants
alexcjohnson Jun 22, 2017
b56f4ea
move lineIntersect -> Lib.geometry2d
alexcjohnson Jun 22, 2017
d534fb2
segmentDistance and tests of geometry2d
alexcjohnson Jun 22, 2017
d1e3448
contour line label basic functionality
alexcjohnson Jun 22, 2017
b8c75c0
better test of alternate Drawing.font syntax
alexcjohnson Jun 23, 2017
2f3a712
use contour/attributes in contourcarpet/attributes
alexcjohnson Jun 23, 2017
6299303
pull path measurement routines out into Lib
alexcjohnson Jun 23, 2017
99f39f8
allow contour labels even without lines
alexcjohnson Jun 23, 2017
d518c83
simple contour label position optimization
alexcjohnson Jun 23, 2017
27f8cfe
use axis formatting for contour labels
alexcjohnson Jun 23, 2017
221b124
include label attrs in contourcarpet to avoid errors but they're noops
alexcjohnson Jun 23, 2017
ca1cced
location -> loc (window global potential confusion)
alexcjohnson Jun 26, 2017
d52cfba
scale min path length for contour labels to width + height
alexcjohnson Jun 26, 2017
0f37648
:cow2: remove obsolete regexp
alexcjohnson Jun 26, 2017
62156dd
:hocho: long-obsolete cache object
alexcjohnson Jun 27, 2017
539ca22
Drawing.bBox "inTester" mode for quicker testing of dummy elements
alexcjohnson Jun 27, 2017
2116a12
contours.font -> contours.labelfont
alexcjohnson Jun 27, 2017
e1880c1
more permissive Drawing.bBox test
alexcjohnson Jun 27, 2017
14c832e
image tests of contour labels
alexcjohnson Jun 27, 2017
1bbdf59
contour line-colored label test
alexcjohnson Jun 27, 2017
e5a2f91
use `editTypes` for contour/contourcarpet-specific attributes
alexcjohnson Jun 27, 2017
cbdf795
no editType nesting - just docalc on editing full containers
alexcjohnson Jun 27, 2017
4db549c
:hocho: obsolete import
alexcjohnson Jun 27, 2017
fb4b690
refactor contour/plot for smaller functions
alexcjohnson Jun 29, 2017
b0f9bb2
updated contour_edge_cases baseline
alexcjohnson Jun 29, 2017
e1caa9e
unify contour.style and contourcarpet.style
alexcjohnson Jun 29, 2017
0ff2dc4
cover contour edge cases with contourcarpet
alexcjohnson Jun 29, 2017
f5873f1
fix contour style when coloring=none
alexcjohnson Jun 29, 2017
b5a674f
a little more stuff contourcarpet can inherit from contour
alexcjohnson Jun 29, 2017
1f85a6f
fix carpet plot clip path
alexcjohnson Jun 30, 2017
6c2043e
:hocho: some obsolete code in carpet/plot
alexcjohnson Jun 30, 2017
bbb9574
update histogram2dcontour for contour.plot API change
alexcjohnson Jun 30, 2017
9495dee
nest scattercontour lines inside a contourlines group
alexcjohnson Jun 30, 2017
7f086e0
fixup font->labelfont in contourcarpet
alexcjohnson Jun 30, 2017
49b8141
labels on contourcarpet
alexcjohnson Jun 30, 2017
8934038
update comment on contourcarpet label bounds
alexcjohnson Jun 30, 2017
dbeecd0
update baselines for findBestTextLocation bugfix
alexcjohnson Jun 30, 2017
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
32 changes: 21 additions & 11 deletions src/traces/contour/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ module.exports = function style(gd) {
var line = trace.line;
var cs = contours.size || 1;
var start = contours.start;
var colorLines = contours.coloring === 'lines';

var colorMap = makeColorMap(trace);
// for contourcarpet only - is this a constraint-type contour trace?
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 bit funny to have contourcarpet only code in contour.style - but perhaps someday we would like to support constraint-type coloring for regular contour plots too?

var isConstraintType = contours.type === 'constraint';
var colorLines = !isConstraintType && contours.coloring === 'lines';
var colorFills = !isConstraintType && contours.coloring === 'fill';

var colorMap = isConstraintType ? null : makeColorMap(trace);

c.selectAll('g.contourlevel').each(function(d) {
d3.select(this).selectAll('path')
Expand All @@ -52,18 +56,24 @@ module.exports = function style(gd) {
});
});

var firstFill;
if(isConstraintType) {
c.selectAll('g.contourfill path')
.style('fill', trace.fillcolor);
}
else if(colorFills) {
var firstFill;

c.selectAll('g.contourfill path')
.style('fill', function(d) {
if(firstFill === undefined) firstFill = d.level;
return colorMap(d.level + 0.5 * cs);
});
c.selectAll('g.contourfill path')
.style('fill', function(d) {
if(firstFill === undefined) firstFill = d.level;
return colorMap(d.level + 0.5 * cs);
});

if(firstFill === undefined) firstFill = start;
if(firstFill === undefined) firstFill = start;

c.selectAll('g.contourbg path')
.style('fill', colorMap(firstFill - 0.5 * cs));
c.selectAll('g.contourbg path')
.style('fill', colorMap(firstFill - 0.5 * cs));
}
});

heatmapStyle(gd);
Expand Down
2 changes: 1 addition & 1 deletion src/traces/contourcarpet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ContourCarpet.supplyDefaults = require('./defaults');
ContourCarpet.colorbar = require('../contour/colorbar');
ContourCarpet.calc = require('./calc');
ContourCarpet.plot = require('./plot');
ContourCarpet.style = require('./style');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

continuing to 🌴 contour/contourcarpet... this also fixes some bugs such as:

  • contourcarpet failed with contours.coloring='lines'
  • if the first contour wasn't shown (if you give an explicit contour start value lower than what the data would be) the colors would have been wrong. For contour this was fixed in Contour bug #1309 (the key is to use d.level rather than i in coloring the contour lines/fills) and tested in contour_edge_cases.

@etpinard do you think it's sufficient to rely on the contour tests for contourcarpet too - since it's using the same code now - or would you like me to add contourcarpet tests of these cases?

Copy link
Contributor

Choose a reason for hiding this comment

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

do you think it's sufficient to rely

We have plenty of carpet mocks, maybe you could update one of them with contours.coloring='lines' ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm, as far as I can tell only cheater_contour is not constraint-type, but perhaps I can extend that one to cover these cases. Sure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

0ff2dc4
This mock on master:
screen shot 2017-06-29 at 6 39 10 pm
and now:
screen shot 2017-06-29 at 6 40 20 pm

Copy link
Contributor

Choose a reason for hiding this comment

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

This is great. I'd have to dig in further to refresh my memory, but I struggled a bit to wrangle the behavior under control for both constraints and contours since it felt like they had slightly different semantics. Like constraints tend to be a single color while contours have multiple colors. But if it passes the existing image tests and fixes other behaviors, then I'm 100% content.

ContourCarpet.style = require('../contour/style');
Copy link
Contributor

Choose a reason for hiding this comment

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

Amazing 🎉


ContourCarpet.moduleType = 'trace';
ContourCarpet.name = 'contourcarpet';
Expand Down
63 changes: 0 additions & 63 deletions src/traces/contourcarpet/style.js

This file was deleted.