(spec)
| 9414 | module.exports = createColormap; |
| 9415 | |
| 9416 | function createColormap (spec) { |
| 9417 | /* |
| 9418 | * Default Options |
| 9419 | */ |
| 9420 | var indicies, fromrgba, torgba, |
| 9421 | nsteps, cmap, colormap, format, |
| 9422 | nshades, colors, alpha, i; |
| 9423 | |
| 9424 | if ( !spec ) spec = {}; |
| 9425 | |
| 9426 | nshades = (spec.nshades || 72) - 1; |
| 9427 | format = spec.format || 'hex'; |
| 9428 | |
| 9429 | colormap = spec.colormap; |
| 9430 | if (!colormap) colormap = 'jet'; |
| 9431 | |
| 9432 | if (typeof colormap === 'string') { |
| 9433 | colormap = colormap.toLowerCase(); |
| 9434 | |
| 9435 | if (!colorScale[colormap]) { |
| 9436 | throw Error(colormap + ' not a supported colorscale'); |
| 9437 | } |
| 9438 | |
| 9439 | cmap = colorScale[colormap]; |
| 9440 | |
| 9441 | } else if (Array.isArray(colormap)) { |
| 9442 | cmap = colormap.slice(); |
| 9443 | |
| 9444 | } else { |
| 9445 | throw Error('unsupported colormap option', colormap); |
| 9446 | } |
| 9447 | |
| 9448 | if (cmap.length > nshades + 1) { |
| 9449 | throw new Error( |
| 9450 | colormap+' map requires nshades to be at least size '+cmap.length |
| 9451 | ); |
| 9452 | } |
| 9453 | |
| 9454 | if (!Array.isArray(spec.alpha)) { |
| 9455 | |
| 9456 | if (typeof spec.alpha === 'number') { |
| 9457 | alpha = [spec.alpha, spec.alpha]; |
| 9458 | |
| 9459 | } else { |
| 9460 | alpha = [1, 1]; |
| 9461 | } |
| 9462 | |
| 9463 | } else if (spec.alpha.length !== 2) { |
| 9464 | alpha = [1, 1]; |
| 9465 | |
| 9466 | } else { |
| 9467 | alpha = spec.alpha.slice(); |
| 9468 | } |
| 9469 | |
| 9470 | // map index points from 0..1 to 0..n-1 |
| 9471 | indicies = cmap.map(function(c) { |
| 9472 | return Math.round(c.index * nshades); |
| 9473 | }); |
nothing calls this directly
no test coverage detected
searching dependent graphs…