|
| 1 | +/** |
| 2 | +* Copyright 2012-2017, Plotly, Inc. |
| 3 | +* All rights reserved. |
| 4 | +* |
| 5 | +* This source code is licensed under the MIT license found in the |
| 6 | +* LICENSE file in the root directory of this source tree. |
| 7 | +*/ |
| 8 | + |
| 9 | + |
| 10 | +'use strict'; |
| 11 | + |
| 12 | +var isNumeric = require('fast-isnumeric'); |
| 13 | + |
| 14 | +var Lib = require('../../lib'); |
| 15 | +var Plots = require('../../plots/plots'); |
| 16 | +var Colorscale = require('../../components/colorscale'); |
| 17 | +var drawColorbar = require('../../components/colorbar/draw'); |
| 18 | + |
| 19 | + |
| 20 | +module.exports = function colorbar(gd, cd) { |
| 21 | + var trace = cd[0].trace, |
| 22 | + line = trace.line, |
| 23 | + cbId = 'cb' + trace.uid; |
| 24 | + |
| 25 | + gd._fullLayout._infolayer.selectAll('.' + cbId).remove(); |
| 26 | + |
| 27 | + if((line === undefined) || !line.showscale) { |
| 28 | + Plots.autoMargin(gd, cbId); |
| 29 | + return; |
| 30 | + } |
| 31 | + |
| 32 | + var vals = line.color, |
| 33 | + cmin = line.cmin, |
| 34 | + cmax = line.cmax; |
| 35 | + |
| 36 | + if(!isNumeric(cmin)) cmin = Lib.aggNums(Math.min, null, vals); |
| 37 | + if(!isNumeric(cmax)) cmax = Lib.aggNums(Math.max, null, vals); |
| 38 | + |
| 39 | + var cb = cd[0].t.cb = drawColorbar(gd, cbId); |
| 40 | + var sclFunc = Colorscale.makeColorScaleFunc( |
| 41 | + Colorscale.extractScale( |
| 42 | + line.colorscale, |
| 43 | + cmin, |
| 44 | + cmax |
| 45 | + ), |
| 46 | + { noNumericCheck: true } |
| 47 | + ); |
| 48 | + |
| 49 | + cb.fillcolor(sclFunc) |
| 50 | + .filllevels({start: cmin, end: cmax, size: (cmax - cmin) / 254}) |
| 51 | + .options(line.colorbar)(); |
| 52 | +}; |
0 commit comments