diff --git a/.eslintrc b/.eslintrc index 384ef0783ce..f39c183260f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -35,6 +35,7 @@ "no-multi-spaces": [2], "no-whitespace-before-property": [2], "no-unexpected-multiline": [2], + "no-floating-decimal": [2], "space-infix-ops": [0, {"int32Hint": false}], "quotes": [2, "single"], "dot-notation": [2, {"allowKeywords": false}], diff --git a/src/traces/contour/calc.js b/src/traces/contour/calc.js index a432e17456c..2e41de9251d 100644 --- a/src/traces/contour/calc.js +++ b/src/traces/contour/calc.js @@ -13,21 +13,25 @@ var Axes = require('../../plots/cartesian/axes'); var heatmapCalc = require('../heatmap/calc'); +// most is the same as heatmap calc, then adjust it +// though a few things inside heatmap calc still look for +// contour maps, because the makeBoundArray calls are too entangled module.exports = function calc(gd, trace) { - // most is the same as heatmap calc, then adjust it - // though a few things inside heatmap calc still look for - // contour maps, because the makeBoundArray calls are too entangled var cd = heatmapCalc(gd, trace), contours = trace.contours; // check if we need to auto-choose contour levels - if(trace.autocontour!==false) { + if(trace.autocontour !== false) { var dummyAx = { type: 'linear', range: [trace.zmin, trace.zmax] }; - Axes.autoTicks(dummyAx, - (trace.zmax - trace.zmin) / (trace.ncontours||15)); + + Axes.autoTicks( + dummyAx, + (trace.zmax - trace.zmin) / (trace.ncontours || 15) + ); + contours.start = Axes.tickFirst(dummyAx); contours.size = dummyAx.dtick; dummyAx.range.reverse(); @@ -37,7 +41,7 @@ module.exports = function calc(gd, trace) { if(contours.end === trace.zmax) contours.end -= contours.size; // so rounding errors don't cause us to miss the last contour - contours.end += contours.size/100; + contours.end += contours.size / 100; // copy auto-contour info back to the source data. trace._input.contours = contours; diff --git a/src/traces/contour/colorbar.js b/src/traces/contour/colorbar.js index f11972a2ced..51b9e65fab4 100644 --- a/src/traces/contour/colorbar.js +++ b/src/traces/contour/colorbar.js @@ -9,12 +9,11 @@ 'use strict'; -var d3 = require('d3'); - var Plots = require('../../plots/plots'); -var getColorscale = require('../../components/colorscale/get_scale'); var drawColorbar = require('../../components/colorbar/draw'); +var makeColorMap = require('./make_color_map'); + module.exports = function colorbar(gd, cd) { var trace = cd[0].trace, @@ -32,55 +31,23 @@ module.exports = function colorbar(gd, cd) { var contours = trace.contours, line = trace.line, - cs = contours.size||1, - nc = Math.floor((contours.end + cs/10 - contours.start)/cs)+1, - scl = getColorscale(trace.colorscale), - extraLevel = contours.coloring==='lines' ? 0 : 1, - colormap = d3.scale.linear().interpolate(d3.interpolateRgb), - colorDomain = scl.map(function(si) { - return (si[0]*(nc+extraLevel-1)-(extraLevel/2)) * cs + - contours.start; - }), - colorRange = scl.map(function(si) { return si[1]; }); + cs = contours.size || 1, + coloring = contours.coloring; + + var colorMap = makeColorMap(trace, {isColorbar: true}); - // colorbar fill and lines - if(contours.coloring==='heatmap') { - if(trace.zauto && trace.autocontour===false) { - trace.zmin = contours.start-cs/2; - trace.zmax = trace.zmin+nc*cs; - } + if(coloring === 'heatmap') { cb.filllevels({ start: trace.zmin, end: trace.zmax, - size: (trace.zmax-trace.zmin)/254 + size: (trace.zmax - trace.zmin) / 254 }); - colorDomain = scl.map(function(si) { - return si[0]*(trace.zmax-trace.zmin) + trace.zmin; - }); - - // do the contours extend beyond the colorscale? - // if so, extend the colorscale with constants - var zRange = d3.extent([trace.zmin, trace.zmax, contours.start, - contours.start + cs*(nc-1)]), - zmin = zRange[trace.zmin