-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
FI-51 contour plot fill #522
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e3a80ce
#fi-51 contour plot fill test case
monfera 6330e62
#fi-51 contour plot fill test case
monfera 13d78bc
#fi-51 contour plot fill test case
monfera a61b249
#fi-51 contour plot fill image based test case
monfera 9d7bbfb
#fi-51 contour plot fill test cases
monfera f421d4e
#fi-51 updating repo in package.js; phasing out withSetupTeardown
monfera 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,8 @@ proto.update = function(fullTrace, calcTrace) { | |
// convert z from 2D -> 1D | ||
var z = calcPt.z, | ||
rowLen = z[0].length, | ||
colLen = z.length; | ||
colLen = z.length, | ||
colorOptions; | ||
|
||
this.contourOptions.z = flattenZ(z, rowLen, colLen); | ||
this.heatmapOptions.z = [].concat.apply([], z); | ||
|
@@ -95,9 +96,22 @@ proto.update = function(fullTrace, calcTrace) { | |
this.contourOptions.x = this.heatmapOptions.x = calcPt.x; | ||
this.contourOptions.y = this.heatmapOptions.y = calcPt.y; | ||
|
||
var colorOptions = convertColorscale(fullTrace); | ||
this.contourOptions.levels = colorOptions.levels; | ||
this.contourOptions.levelColors = colorOptions.levelColors; | ||
|
||
// pass on fill information | ||
if(fullTrace.contours.coloring === 'fill') { | ||
colorOptions = convertColorscale(fullTrace, true); | ||
this.contourOptions.levels = colorOptions.levels.slice(1); | ||
// though gl-contour2d automatically defaults to a transparent layer for the last | ||
// band color, it's set manually here in case the gl-contour2 API changes | ||
this.contourOptions.fillColors = colorOptions.levelColors; | ||
this.contourOptions.levelColors = [].concat.apply([], this.contourOptions.levels.map(function() { | ||
return [0.25, 0.25, 0.25, 1.0]; | ||
})); | ||
} else { | ||
colorOptions = convertColorscale(fullTrace, false); | ||
this.contourOptions.levels = colorOptions.levels; | ||
this.contourOptions.levelColors = colorOptions.levelColors; | ||
} | ||
|
||
// convert text from 2D -> 1D | ||
this.textLabels = [].concat.apply([], fullTrace.text); | ||
|
@@ -124,20 +138,20 @@ function flattenZ(zIn, rowLen, colLen) { | |
return zOut; | ||
} | ||
|
||
function convertColorscale(fullTrace) { | ||
function convertColorscale(fullTrace, fill) { | ||
var contours = fullTrace.contours, | ||
start = contours.start, | ||
end = contours.end, | ||
cs = contours.size || 1; | ||
|
||
var colorMap = makeColorMap(fullTrace); | ||
|
||
var N = Math.floor((end - start) / cs) + 1, | ||
var N = Math.floor((end - start) / cs) + (fill ? 2 : 1), // for K thresholds (contour linees) there are K+1 areas | ||
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. nicely done! |
||
levels = new Array(N), | ||
levelColors = new Array(4 * N); | ||
|
||
for(var i = 0; i < N; i++) { | ||
var level = levels[i] = start + cs * (i); | ||
var level = levels[i] = start + cs * (i) - (fill ? cs / 2 : 0); // in case of fill, use band midpoint | ||
var color = str2RGBArray(colorMap(level)); | ||
|
||
for(var j = 0; j < 4; j++) { | ||
|
Oops, something went wrong.
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.
I'm ok with the boolean
fill
option here, asconvertColorscale
is only used in this file. But @monfera, I hope you agree thatconvertColorscale(fullTrace, { fill: true });
would have been cleaner and more robust.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.
@etpinard Glad to make this small change!
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.
No need for now. 👍