Skip to content

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 6 commits into from
May 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"delaunay-triangulate": "^1.1.6",
"es6-promise": "^3.0.2",
"fast-isnumeric": "^1.1.1",
"gl-contour2d": "^1.0.1",
"gl-contour2d": "^1.1.2",
"gl-error2d": "^1.0.0",
"gl-error3d": "^1.0.0",
"gl-heatmap2d": "^1.0.2",
Expand Down
28 changes: 21 additions & 7 deletions src/traces/contourgl/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Copy link
Contributor

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, as convertColorscale is only used in this file. But @monfera, I hope you agree that convertColorscale(fullTrace, { fill: true }); would have been cleaner and more robust.

Copy link
Contributor Author

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!

Copy link
Contributor

Choose a reason for hiding this comment

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

No need for now. 👍

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);
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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++) {
Expand Down
Loading