Skip to content

Commit

Permalink
Add support for grid contour annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed May 11, 2021
1 parent 33d5485 commit 3014ad8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion girder/girder_large_image/web_client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"copy-webpack-plugin": "^4.5.2",
"d3": "^3.5.16",
"geojs": "^1.0.0",
"geojs": "^1.0.1",
"hammerjs": "^2.0.8",
"js-yaml": "^3.14.0",
"sinon": "^2.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,52 @@ function convertGridToHeatmap(record, properties, layer) {
return [heatmap];
}

/**
* Convert a griddata heatmap contour to a geojs feature.
*
* @param record: the griddata contour annotation element.
* @param properties: a property map of additional data, such as the original
* annotation id.
* @param layer: the layer where this may be added.
*/
function convertGridToContour(record, properties, layer) {
let min = record.values[0] || 0;
let max = min;
for (let i = 1; i < record.values.length; i += 1) {
if (record.values[i] > max) {
max = record.values[i];
}
if (record.values[i] < max) {
min = record.values[i];
}
}
if (min >= 0) {
min = -1; /* any negative number will do */
}
const contour = layer.createFeature('contour', {
style: {
value: (d) => d || 0
},
contour: {
gridWidth: record.gridWidth,
x0: (record.origin || [])[0] || 0,
y0: (record.origin || [])[1] || 0,
dx: record.dx || 1,
dy: record.dy || 1,
stepped: false,
colorRange: [
record.minColor || {r: 0, g: 0, b: 1, a: 1},
record.zeroColor || {r: 0, g: 0, b: 0, a: 0},
record.maxColor || {r: 1, g: 1, b: 0, a: 1}
],
rangeValues: [min, 0, Math.max(0, max)]
}
}).data(record.values);
return [contour];
}

const converters = {
griddata_contour: convertGridToContour,
griddata_heatmap: convertGridToHeatmap,
heatmap: convertHeatmap
};
Expand Down

0 comments on commit 3014ad8

Please sign in to comment.