Skip to content

Add class to colorbar; extract out class names #2139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/components/colorbar/constants.js
Original file line number Diff line number Diff line change
@@ -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'
}
};
25 changes: 13 additions & 12 deletions src/components/colorbar/draw.js
Original file line number Diff line number Diff line change
@@ -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(),
2 changes: 1 addition & 1 deletion src/traces/choropleth/attributes.js
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ module.exports = extendFlat({
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {
editType: 'calc',
flags: ['location', 'z', 'text', 'name']
}),
})
},
extendDeepAll({}, colorscaleAttrs, {
zmax: {editType: 'calc'},