From 09ab60cc3c22089f966fa4e71dddcc9071dacfe1 Mon Sep 17 00:00:00 2001 From: Robert Monfera Date: Thu, 2 Nov 2017 06:24:22 +0100 Subject: [PATCH 1/2] classing colorbar --- src/components/colorbar/draw.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/colorbar/draw.js b/src/components/colorbar/draw.js index d41334c8d32..e1e792399fd 100644 --- a/src/components/colorbar/draw.js +++ b/src/components/colorbar/draw.js @@ -248,6 +248,7 @@ 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('colorbar', true) .each(function() { var s = d3.select(this); s.append('rect').classed('cbbg', true); From 5d9bc08831005afb78357e84a223e2c8f5ae0505 Mon Sep 17 00:00:00 2001 From: Robert Monfera Date: Thu, 2 Nov 2017 06:30:35 +0100 Subject: [PATCH 2/2] extracting out class names --- src/components/colorbar/constants.js | 26 ++++++++++++++++++++++++++ src/components/colorbar/draw.js | 26 +++++++++++++------------- src/traces/choropleth/attributes.js | 2 +- 3 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 src/components/colorbar/constants.js 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 e1e792399fd..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,16 +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('colorbar', 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) + @@ -316,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) { @@ -349,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) { @@ -390,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) @@ -480,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'},