Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e1732e

Browse files
committed
require colorbar draw method directly
1 parent accf041 commit 9e1732e

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/traces/contour/colorbar.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ var d3 = require('d3');
1313

1414
var Plotly = require('../../plotly');
1515
var getColorscale = require('../../components/colorscale/get_scale');
16+
var drawColorbar = require('../../components/colorbar/draw');
1617

1718

1819
module.exports = function colorbar(gd, cd) {
1920
var trace = cd[0].trace,
20-
cbId = 'cb'+trace.uid;
21+
cbId = 'cb' + trace.uid;
2122

22-
gd._fullLayout._infolayer.selectAll('.'+cbId).remove();
23+
gd._fullLayout._infolayer.selectAll('.' + cbId).remove();
2324

2425
if(trace.showscale===false){
2526
Plotly.Plots.autoMargin(gd, cbId);
2627
return;
2728
}
2829

29-
// instantiate the colorbar (will be drawn and styled in contour.style)
30-
var cb = Plotly.Colorbar(gd, cbId);
30+
var cb = drawColorbar(gd, cbId);
3131
cd[0].t.cb = cb;
3232

3333
var contours = trace.contours,

src/traces/heatmap/colorbar.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var isNumeric = require('fast-isnumeric');
1515
var Plotly = require('../../plotly');
1616
var Lib = require('../../lib');
1717
var getColorscale = require('../../components/colorscale/get_scale');
18+
var drawColorbar = require('../../components/colorbar/draw');
19+
1820

1921
module.exports = function colorbar(gd, cd) {
2022
var trace = cd[0].trace,
@@ -23,16 +25,17 @@ module.exports = function colorbar(gd, cd) {
2325
zmin = trace.zmin,
2426
zmax = trace.zmax;
2527

26-
if(!isNumeric(zmin)) zmin = Plotly.Lib.aggNums(Math.min, null, trace.z);
27-
if(!isNumeric(zmax)) zmax = Plotly.Lib.aggNums(Math.max, null, trace.z);
28+
if(!isNumeric(zmin)) zmin = Lib.aggNums(Math.min, null, trace.z);
29+
if(!isNumeric(zmax)) zmax = Lib.aggNums(Math.max, null, trace.z);
30+
31+
gd._fullLayout._infolayer.selectAll('.' + cbId).remove();
2832

29-
gd._fullLayout._infolayer.selectAll('.'+cbId).remove();
3033
if(!trace.showscale){
3134
Plotly.Plots.autoMargin(gd, cbId);
3235
return;
3336
}
3437

35-
var cb = cd[0].t.cb = Plotly.Colorbar(gd, cbId);
38+
var cb = cd[0].t.cb = drawColorbar(gd, cbId);
3639
cb.fillcolor(d3.scale.linear()
3740
.domain(scl.map(function(v){ return zmin + v[0]*(zmax-zmin); }))
3841
.range(scl.map(function(v){ return v[1]; })))

src/traces/scatter/colorbar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var isNumeric = require('fast-isnumeric');
1515
var Plotly = require('../../plotly');
1616
var Lib = require('../../lib');
1717
var getColorscale = require('../../components/colorscale/get_scale');
18+
var drawColorbar = require('../../components/colorbar/draw');
1819

1920

2021
module.exports = function colorbar(gd, cd) {
@@ -40,7 +41,7 @@ module.exports = function colorbar(gd, cd) {
4041
if(!isNumeric(cmin)) cmin = Plotly.Lib.aggNums(Math.min, null, vals);
4142
if(!isNumeric(cmax)) cmax = Plotly.Lib.aggNums(Math.max, null, vals);
4243

43-
var cb = cd[0].t.cb = Plotly.Colorbar(gd, cbId);
44+
var cb = cd[0].t.cb = drawColorbar(gd, cbId);
4445

4546
cb.fillcolor(d3.scale.linear()
4647
.domain(scl.map(function(v){ return cmin + v[0] * (cmax - cmin); }))

0 commit comments

Comments
 (0)