Skip to content
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

scale contour intensity to intensityBounds #7

Merged
merged 3 commits into from
Mar 21, 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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ Creates a surface plot object. `params` is an object with any of the following
* `gl` is a WebGL context
* `field` a new 2D field encoded as an ndarray
* `coords` is an array of 3 2D fields, each encoded as ndarrays (for parameteric surfaces)
* `colormap` the name of the new color map for the surface
* `colorBounds` sets the z range for the colormap
* `intensity` a 2D intensity field (defaults to `field` or `coords[2] is not present)
* `colormap` the name of the new color map for the surface (see list of names in `colormap` [docs](https://github.com/bpostlethwaite/colormap))
* `intensityBounds` sets the intensity range for the colormap
* `ticks` is a pair of arrays of ticks representing the spacing of the points for the axes of the surface
* `showSurface` if set, draw the surface
* `showContour` if set, draw contour lines
Expand Down
12 changes: 10 additions & 2 deletions surface.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function SurfacePlot (
this.gl = gl
this.shape = shape
this.bounds = bounds
this.intensityBounds = [];

this._shader = shader
this._pickShader = pickShader
Expand Down Expand Up @@ -750,6 +751,7 @@ proto.update = function (params) {
}

var field = params.field || (params.coords && params.coords[2]) || null
var levelsChanged = false

if (!field) {
if (this._field[2].shape[0] || this._field[2].shape[2]) {
Expand Down Expand Up @@ -968,10 +970,16 @@ proto.update = function (params) {

// Save intensity
this.intensity = params.intensity || this._field[2]

if(this.intensityBounds[0] !== lo_intensity || this.intensityBounds[1] !== hi_intensity) {
levelsChanged = true
}

// Save intensity bound
this.intensityBounds = [lo_intensity, hi_intensity]
}

// Update level crossings
var levelsChanged = false
if ('levels' in params) {
var levels = params.levels
if (!Array.isArray(levels[0])) {
Expand Down Expand Up @@ -1049,7 +1057,7 @@ proto.update = function (params) {
if (dd < 2) {
f = this._field[iu].get(r, c)
} else {
f = this.intensity.get(r, c)
f = (this.intensity.get(r, c) - this.intensityBounds[0]) / (this.intensityBounds[1] - this.intensityBounds[0])
}
if (!isFinite(f) || isNaN(f)) {
hole = true
Expand Down