Skip to content

Commit 503fd93

Browse files
committed
mv traceColorbar from colorbar/ to heatmap/
- similar to scatter colorbar
1 parent c0f85e6 commit 503fd93

File tree

6 files changed

+46
-30
lines changed

6 files changed

+46
-30
lines changed

src/components/colorbar/index.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -575,29 +575,3 @@ colorbar.supplyDefaults = function(containerIn, containerOut, layout) {
575575
Plotly.Lib.coerceFont(coerce, 'titlefont', layout.font);
576576
coerce('titleside');
577577
};
578-
579-
colorbar.traceColorbar = function(gd, cd) {
580-
var trace = cd[0].trace,
581-
cbId = 'cb' + trace.uid,
582-
scl = Plotly.Colorscale.getScale(trace.colorscale),
583-
zmin = trace.zmin,
584-
zmax = trace.zmax;
585-
586-
if(!isNumeric(zmin)) zmin = Plotly.Lib.aggNums(Math.min, null, trace.z);
587-
if(!isNumeric(zmax)) zmax = Plotly.Lib.aggNums(Math.max, null, trace.z);
588-
589-
gd._fullLayout._infolayer.selectAll('.'+cbId).remove();
590-
if(!trace.showscale){
591-
Plotly.Plots.autoMargin(gd, cbId);
592-
return;
593-
}
594-
595-
var cb = cd[0].t.cb = colorbar(gd, cbId);
596-
cb.fillcolor(d3.scale.linear()
597-
.domain(scl.map(function(v){ return zmin + v[0]*(zmax-zmin); }))
598-
.range(scl.map(function(v){ return v[1]; })))
599-
.filllevels({start: zmin, end: zmax, size: (zmax-zmin)/254})
600-
.options(trace.colorbar)();
601-
602-
Plotly.Lib.markTime('done colorbar');
603-
};

src/traces/choropleth/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Choropleth.attributes = require('./attributes');
2626

2727
Choropleth.supplyDefaults = require('./defaults');
2828

29-
Choropleth.colorbar = Plotly.Colorbar.traceColorbar;
29+
Choropleth.colorbar = require('../heatmap/colorbar');
3030

3131
Choropleth.calc = function(gd, trace) {
3232

src/traces/heatmap/colorbar.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright 2012-2015, 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 d3 = require('d3');
13+
var isNumeric = require('fast-isnumeric');
14+
15+
var Plotly = require('../../plotly');
16+
var Lib = require('../../lib');
17+
18+
module.exports = function colorbar(gd, cd) {
19+
var trace = cd[0].trace,
20+
cbId = 'cb' + trace.uid,
21+
scl = Plotly.Colorscale.getScale(trace.colorscale),
22+
zmin = trace.zmin,
23+
zmax = trace.zmax;
24+
25+
if(!isNumeric(zmin)) zmin = Plotly.Lib.aggNums(Math.min, null, trace.z);
26+
if(!isNumeric(zmax)) zmax = Plotly.Lib.aggNums(Math.max, null, trace.z);
27+
28+
gd._fullLayout._infolayer.selectAll('.'+cbId).remove();
29+
if(!trace.showscale){
30+
Plotly.Plots.autoMargin(gd, cbId);
31+
return;
32+
}
33+
34+
var cb = cd[0].t.cb = Plotly.Colorbar(gd, cbId);
35+
cb.fillcolor(d3.scale.linear()
36+
.domain(scl.map(function(v){ return zmin + v[0]*(zmax-zmin); }))
37+
.range(scl.map(function(v){ return v[1]; })))
38+
.filllevels({start: zmin, end: zmax, size: (zmax-zmin)/254})
39+
.options(trace.colorbar)();
40+
41+
Lib.markTime('done colorbar');
42+
};

src/traces/heatmap/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ exports.calc = require('./calc');
4646

4747
exports.plot = require('./plot');
4848

49-
exports.colorbar = Plotly.Colorbar.traceColorbar;
49+
exports.colorbar = require('./colorbar');
5050

5151
exports.style = require('./style');
5252

src/traces/mesh3d/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ Mesh3D.attributes = require('./attributes');
2828

2929
Mesh3D.supplyDefaults = require('./defaults');
3030

31-
Mesh3D.colorbar = Plotly.Colorbar.traceColorbar;
31+
Mesh3D.colorbar = require('../heatmap/colorbar');

src/traces/surface/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Surface.attributes = require('./attributes');
3030

3131
Surface.supplyDefaults = require('./defaults');
3232

33-
Surface.colorbar = Plotly.Colorbar.traceColorbar;
33+
Surface.colorbar = require('../heatmap/colorbar');
3434

3535
Surface.calc = function(gd, trace) {
3636

0 commit comments

Comments
 (0)