diff --git a/src/components/colorbar/constants.js b/src/components/colorbar/constants.js new file mode 100644 index 00000000000..0fad225f102 --- /dev/null +++ b/src/components/colorbar/constants.js @@ -0,0 +1,26 @@ +/** +* Copyright 2012-2017, Plotly, Inc. +* All rights reserved. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +*/ + +'use strict'; + +module.exports = { + cn: { + colorbar: 'colorbar', + cbbg: 'cbbg', + cbfill: 'cbfill', + cbfills: 'cbfills', + cbline: 'cbline', + cblines: 'cblines', + cbaxis: 'cbaxis', + cbtitleunshift: 'cbtitleunshift', + cbtitle: 'cbtitle', + cboutline: 'cboutline', + crisp: 'crisp', + jsPlaceholder: 'js-placeholder' + } +}; diff --git a/src/components/colorbar/draw.js b/src/components/colorbar/draw.js index d41334c8d32..d584c134fa8 100644 --- a/src/components/colorbar/draw.js +++ b/src/components/colorbar/draw.js @@ -31,7 +31,7 @@ var handleAxisPositionDefaults = require('../../plots/cartesian/position_default var axisLayoutAttrs = require('../../plots/cartesian/layout_attributes'); var attributes = require('./attributes'); - +var cn = require('./constants').cn; module.exports = function draw(gd, id) { // opts: options object, containing everything from attributes @@ -248,15 +248,16 @@ module.exports = function draw(gd, id) { // now draw the elements var container = fullLayout._infolayer.selectAll('g.' + id).data([0]); container.enter().append('g').classed(id, true) + .classed(cn.colorbar, true) .each(function() { var s = d3.select(this); - s.append('rect').classed('cbbg', true); - s.append('g').classed('cbfills', true); - s.append('g').classed('cblines', true); - s.append('g').classed('cbaxis', true).classed('crisp', true); - s.append('g').classed('cbtitleunshift', true) - .append('g').classed('cbtitle', true); - s.append('rect').classed('cboutline', true); + s.append('rect').classed(cn.cbbg, true); + s.append('g').classed(cn.cbfills, true); + s.append('g').classed(cn.cblines, true); + s.append('g').classed(cn.cbaxis, true).classed(cn.crisp, true); + s.append('g').classed(cn.cbtitleunshift, true) + .append('g').classed(cn.cbtitle, true); + s.append('rect').classed(cn.cboutline, true); s.select('.cbtitle').datum(0); }); container.attr('transform', 'translate(' + Math.round(gs.l) + @@ -315,7 +316,7 @@ module.exports = function draw(gd, id) { } } else if(titleText.node() && - !titleText.classed('js-placeholder')) { + !titleText.classed(cn.jsPlaceholder)) { titleHeight = Drawing.bBox(titleText.node()).height; } if(titleHeight) { @@ -348,7 +349,7 @@ module.exports = function draw(gd, id) { .selectAll('rect.cbfill') .data(filllevels); fills.enter().append('rect') - .classed('cbfill', true) + .classed(cn.cbfill, true) .style('stroke', 'none'); fills.exit().remove(); fills.each(function(d, i) { @@ -389,7 +390,7 @@ module.exports = function draw(gd, id) { .data(opts.line.color && opts.line.width ? linelevels : []); lines.enter().append('path') - .classed('cbline', true); + .classed(cn.cbline, true); lines.exit().remove(); lines.each(function(d) { d3.select(this) @@ -479,7 +480,7 @@ module.exports = function draw(gd, id) { var innerWidth = thickPx + opts.outlinewidth / 2 + Drawing.bBox(cbAxisOut._axislayer.node()).width; titleEl = titleCont.select('text'); - if(titleEl.node() && !titleEl.classed('js-placeholder')) { + if(titleEl.node() && !titleEl.classed(cn.jsPlaceholder)) { var mathJaxNode = titleCont .select('.h' + cbAxisOut._id + 'title-math-group') .node(), diff --git a/src/traces/choropleth/attributes.js b/src/traces/choropleth/attributes.js index cab58297206..6c9ffb93cbf 100644 --- a/src/traces/choropleth/attributes.js +++ b/src/traces/choropleth/attributes.js @@ -48,7 +48,7 @@ module.exports = extendFlat({ hoverinfo: extendFlat({}, plotAttrs.hoverinfo, { editType: 'calc', flags: ['location', 'z', 'text', 'name'] - }), + }) }, extendDeepAll({}, colorscaleAttrs, { zmax: {editType: 'calc'},