-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Contour line labels #1815
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 88cc33c
collect contour clipPath in the main <defs>
alexcjohnson ee7a839
more standard format for contour constants
alexcjohnson b56f4ea
move lineIntersect -> Lib.geometry2d
alexcjohnson d534fb2
segmentDistance and tests of geometry2d
alexcjohnson d1e3448
contour line label basic functionality
alexcjohnson b8c75c0
better test of alternate Drawing.font syntax
alexcjohnson 2f3a712
use contour/attributes in contourcarpet/attributes
alexcjohnson 6299303
pull path measurement routines out into Lib
alexcjohnson 99f39f8
allow contour labels even without lines
alexcjohnson d518c83
simple contour label position optimization
alexcjohnson 27f8cfe
use axis formatting for contour labels
alexcjohnson 221b124
include label attrs in contourcarpet to avoid errors but they're noops
alexcjohnson ca1cced
location -> loc (window global potential confusion)
alexcjohnson d52cfba
scale min path length for contour labels to width + height
alexcjohnson 0f37648
:cow2: remove obsolete regexp
alexcjohnson 62156dd
:hocho: long-obsolete cache object
alexcjohnson 539ca22
Drawing.bBox "inTester" mode for quicker testing of dummy elements
alexcjohnson 2116a12
contours.font -> contours.labelfont
alexcjohnson e1880c1
more permissive Drawing.bBox test
alexcjohnson 14c832e
image tests of contour labels
alexcjohnson 1bbdf59
contour line-colored label test
alexcjohnson e5a2f91
use `editTypes` for contour/contourcarpet-specific attributes
alexcjohnson cbdf795
no editType nesting - just docalc on editing full containers
alexcjohnson 4db549c
:hocho: obsolete import
alexcjohnson fb4b690
refactor contour/plot for smaller functions
alexcjohnson b0f9bb2
updated contour_edge_cases baseline
alexcjohnson e1caa9e
unify contour.style and contourcarpet.style
alexcjohnson 0ff2dc4
cover contour edge cases with contourcarpet
alexcjohnson f5873f1
fix contour style when coloring=none
alexcjohnson b5a674f
a little more stuff contourcarpet can inherit from contour
alexcjohnson 1f85a6f
fix carpet plot clip path
alexcjohnson 6c2043e
:hocho: some obsolete code in carpet/plot
alexcjohnson bbb9574
update histogram2dcontour for contour.plot API change
alexcjohnson 9495dee
nest scattercontour lines inside a contourlines group
alexcjohnson 7f086e0
fixup font->labelfont in contourcarpet
alexcjohnson 49b8141
labels on contourcarpet
alexcjohnson 8934038
update comment on contourcarpet label bounds
alexcjohnson dbeecd0
update baselines for findBestTextLocation bugfix
alexcjohnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
pull path measurement routines out into Lib
- Loading branch information
commit 6299303f19d37a0b4ecfbf0cd12f6624163064af
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ function plotOne(gd, plotinfo, cd) { | |
var plotGroup = makeContourGroup(plotinfo, cd, id); | ||
makeBackground(plotGroup, perimeter, contours); | ||
makeFills(plotGroup, pathinfo, perimeter, contours); | ||
makeLines(plotGroup, pathinfo, gd, cd[0], contours, perimeter); | ||
makeLinesAndLabels(plotGroup, pathinfo, gd, cd[0], contours, perimeter); 8000 span> | ||
clipGaps(plotGroup, plotinfo, fullLayout._defs, cd[0], perimeter); | ||
} | ||
|
||
|
@@ -263,7 +263,7 @@ function joinAllPaths(pi, perimeter) { | |
|
||
var TRAILING_ZEROS = /\.?0+$/; | ||
|
||
function makeLines(plotgroup, pathinfo, gd, cd0, contours, perimeter) { | ||
function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Except for the innermost join content, it looks like mostly d3 operations so is probably okay, but this function comes out to 240 lines, which seems a bit on the high side. |
||
var defs = gd._fullLayout._defs; | ||
|
||
var smoothing = pathinfo[0].smoothing; | ||
|
@@ -329,6 +329,9 @@ function makeLines(plotgroup, pathinfo, gd, cd0, contours, perimeter) { | |
|
||
var labelData = []; | ||
|
||
// invalidate the getTextLocation cache in case paths changed | ||
Lib.clearLocationCache(); | ||
|
||
var contourFormat; | ||
if(contours.labelformat) { | ||
contourFormat = d3.format(contours.labelformat); | ||
|
@@ -352,8 +355,21 @@ function makeLines(plotgroup, pathinfo, gd, cd0, contours, perimeter) { | |
.attr('data-notex', 1) | ||
.call(Drawing.font, contours.font); | ||
|
||
var plotDiagonal = Math.sqrt(Math.pow(pathinfo[0].xaxis._length, 2) + | ||
Math.pow(pathinfo[0].yaxis._length, 2)); | ||
var xLen = pathinfo[0].xaxis._length; | ||
var yLen = pathinfo[0].yaxis._length; | ||
|
||
// visible bounds of the contour trace (and the midpoints, to | ||
// help with cost calculations) | ||
var bounds = { | ||
left: Math.max(perimeter[0][0], 0), | ||
right: Math.min(perimeter[2][0], xLen), | ||
top: Math.max(perimeter[0][1], 0), | ||
bottom: Math.min(perimeter[2][1], yLen) | ||
}; | ||
bounds.middle = (bounds.top + bounds.bottom) / 2; | ||
bounds.center = (bounds.left + bounds.right) / 2; | ||
|
||
var plotDiagonal = Math.sqrt(xLen * xLen + yLen * yLen); | ||
|
||
// the path length to use to scale the number of labels to draw: | ||
var normLength = plotDiagonal / | ||
|
@@ -470,24 +486,6 @@ function addLabel(loc, textOpts, labelData) { | |
return straightClosedPath(bBoxPts); | ||
} | ||
|
||
function getLocation(path, pathLen, positionOnPath, textOpts) { | ||
var halfWidth = textOpts.width / 2; | ||
|
||
// for the angle, use points on the path separated by the text width | ||
// even though due to curvature, the text will cover a bit more than that | ||
var p0 = path.getPointAtLength(Lib.mod(positionOnPath - halfWidth, pathLen)); | ||
var p1 = path.getPointAtLength(Lib.mod(positionOnPath + halfWidth, pathLen)); | ||
// note: atan handles 1/0 nicely | ||
var theta = Math.atan((p1.y - p0.y) / (p1.x - p0.x)); | ||
// center the text at 2/3 of the center position plus 1/3 the p0/p1 midpoint | ||
// that's the average position of this segment, assuming it's roughly quadratic | ||
var pCenter = path.getPointAtLength(positionOnPath); | ||
var x = (pCenter.x * 4 + p0.x + p1.x) / 6; | ||
var y = (pCenter.y * 4 + p0.y + p1.y) / 6; | ||
|
||
return {x: x, y: y, theta: theta}; | ||
} | ||
|
||
function clipGaps(plotGroup, plotinfo, defs, cd0, perimeter) { | ||
var clipId = 'clip' + cd0.trace.uid; | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 man, I've implemented something similar to this before. It's such a pain!