Skip to content

Commit f49b18e

Browse files
authored
Merge pull request #2139 from plotly/colorbar-class
Add class to `colorbar`; extract out class names
2 parents 81ddaca + 5d9bc08 commit f49b18e

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

src/components/colorbar/constants.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
'use strict';
10+
11+
module.exports = {
12+
cn: {
13+
colorbar: 'colorbar',
14+
cbbg: 'cbbg',
15+
cbfill: 'cbfill',
16+
cbfills: 'cbfills',
17+
cbline: 'cbline',
18+
cblines: 'cblines',
19+
cbaxis: 'cbaxis',
20+
cbtitleunshift: 'cbtitleunshift',
21+
cbtitle: 'cbtitle',
22+
cboutline: 'cboutline',
23+
crisp: 'crisp',
24+
jsPlaceholder: 'js-placeholder'
25+
}
26+
};

src/components/colorbar/draw.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var handleAxisPositionDefaults = require('../../plots/cartesian/position_default
3131
var axisLayoutAttrs = require('../../plots/cartesian/layout_attributes');
3232

3333
var attributes = require('./attributes');
34-
34+
var cn = require('./constants').cn;
3535

3636
module.exports = function draw(gd, id) {
3737
// opts: options object, containing everything from attributes
@@ -248,15 +248,16 @@ module.exports = function draw(gd, id) {
248248
// now draw the elements
249249
var container = fullLayout._infolayer.selectAll('g.' + id).data([0]);
250250
container.enter().append('g').classed(id, true)
251+
.classed(cn.colorbar, true)
251252
.each(function() {
252253
var s = d3.select(this);
253-
s.append('rect').classed('cbbg', true);
254-
s.append('g').classed('cbfills', true);
255-
s.append('g').classed('cblines', true);
256-
s.append('g').classed('cbaxis', true).classed('crisp', true);
257-
s.append('g').classed('cbtitleunshift', true)
258-
.append('g').classed('cbtitle', true);
259-
s.append('rect').classed('cboutline', true);
254+
s.append('rect').classed(cn.cbbg, true);
255+
s.append('g').classed(cn.cbfills, true);
256+
s.append('g').classed(cn.cblines, true);
257+
s.append('g').classed(cn.cbaxis, true).classed(cn.crisp, true);
258+
s.append('g').classed(cn.cbtitleunshift, true)
259+
.append('g').classed(cn.cbtitle, true);
260+
s.append('rect').classed(cn.cboutline, true);
260261
s.select('.cbtitle').datum(0);
261262
});
262263
container.attr('transform', 'translate(' + Math.round(gs.l) +
@@ -315,7 +316,7 @@ module.exports = function draw(gd, id) {
315316
}
316317
}
317318
else if(titleText.node() &&
318-
!titleText.classed('js-placeholder')) {
319+
!titleText.classed(cn.jsPlaceholder)) {
319320
titleHeight = Drawing.bBox(titleText.node()).height;
320321
}
321322
if(titleHeight) {
@@ -348,7 +349,7 @@ module.exports = function draw(gd, id) {
348349
.selectAll('rect.cbfill')
349350
.data(filllevels);
350351
fills.enter().append('rect')
351-
.classed('cbfill', true)
352+
.classed(cn.cbfill, true)
352353
.style('stroke', 'none');
353354
fills.exit().remove();
354355
fills.each(function(d, i) {
@@ -389,7 +390,7 @@ module.exports = function draw(gd, id) {
389390
.data(opts.line.color && opts.line.width ?
390391
linelevels : []);
391392
lines.enter().append('path')
392-
.classed('cbline', true);
393+
.classed(cn.cbline, true);
393394
lines.exit().remove();
394395
lines.each(function(d) {
395396
d3.select(this)
@@ -479,7 +480,7 @@ module.exports = function draw(gd, id) {
479480
var innerWidth = thickPx + opts.outlinewidth / 2 +
480481
Drawing.bBox(cbAxisOut._axislayer.node()).width;
481482
titleEl = titleCont.select('text');
482-
if(titleEl.node() && !titleEl.classed('js-placeholder')) {
483+
if(titleEl.node() && !titleEl.classed(cn.jsPlaceholder)) {
483484
var mathJaxNode = titleCont
484485
.select('.h' + cbAxisOut._id + 'title-math-group')
485486
.node(),

src/traces/choropleth/attributes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = extendFlat({
4848
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {
4949
editType: 'calc',
5050
flags: ['location', 'z', 'text', 'name']
51-
}),
51+
})
5252
},
5353
extendDeepAll({}, colorscaleAttrs, {
5454
zmax: {editType: 'calc'},

0 commit comments

Comments
 (0)