Skip to content

Commit a83d5af

Browse files
committed
add ticklabelposition option to colorbar
1 parent 60addca commit a83d5af

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/components/colorbar/attributes.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,19 @@ module.exports = overrideAll({
157157
tickvals: axesAttrs.tickvals,
158158
ticktext: axesAttrs.ticktext,
159159
ticks: extendFlat({}, axesAttrs.ticks, {dflt: ''}),
160+
ticklabelposition: {
161+
valType: 'enumerated',
162+
values: [
163+
'outside', 'inside',
164+
'outside top', 'inside top',
165+
'outside bottom', 'inside bottom'
166+
],
167+
dflt: 'outside',
168+
role: 'info',
169+
description: [
170+
'Determines where tick labels are drawn.'
171+
].join(' ')
172+
},
160173
ticklen: axesAttrs.ticklen,
161174
tickwidth: axesAttrs.tickwidth,
162175
tickcolor: axesAttrs.tickcolor,

src/components/colorbar/defaults.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ module.exports = function colorbarDefaults(containerIn, containerOut, layout) {
5151
coerce('bordercolor');
5252
coerce('borderwidth');
5353
coerce('bgcolor');
54+
var ticklabelposition = coerce('ticklabelposition');
5455

5556
handleTickValueDefaults(colorbarIn, colorbarOut, coerce, 'linear');
5657

5758
var opts = {outerTicks: false, font: layout.font};
59+
if(ticklabelposition.indexOf('inside') !== -1) {
60+
opts.bgColor = 'black'; // could we instead use the average of colors in the scale?
61+
}
5862
handleTickLabelDefaults(colorbarIn, colorbarOut, coerce, 'linear', opts);
5963
handleTickMarkDefaults(colorbarIn, colorbarOut, coerce, 'linear', opts);
6064

src/components/colorbar/draw.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,20 +462,19 @@ function drawColorBar(g, opts, gd) {
462462
(opts.outlinewidth || 0) / 2 - (opts.ticks === 'outside' ? 1 : 0);
463463

464464
var vals = Axes.calcTicks(ax);
465-
var transFn = Axes.makeTransTickFn(ax);
466465
var tickSign = Axes.getTickSigns(ax)[2];
467466

468467
Axes.drawTicks(gd, ax, {
469468
vals: ax.ticks === 'inside' ? Axes.clipEnds(ax, vals) : vals,
470469
layer: axLayer,
471470
path: Axes.makeTickPath(ax, shift, tickSign),
472-
transFn: transFn
471+
transFn: Axes.makeTransTickFn(ax)
473472
});
474473

475474
return Axes.drawLabels(gd, ax, {
476475
vals: vals,
477476
layer: axLayer,
478-
transFn: transFn,
477+
transFn: Axes.makeTransTickLabelFn(ax),
479478
labelFns: Axes.makeLabelFns(ax, shift)
480479
});
481480
}
@@ -485,7 +484,11 @@ function drawColorBar(g, opts, gd) {
485484
// TODO: why are we redrawing multiple times now with this?
486485
// I guess autoMargin doesn't like being post-promise?
487486
function positionCB() {
488-
var innerWidth = thickPx + opts.outlinewidth / 2 + Drawing.bBox(axLayer.node()).width;
487+
var innerWidth = thickPx + opts.outlinewidth / 2;
488+
if(ax.ticklabelposition.indexOf('inside') === -1) {
489+
innerWidth += Drawing.bBox(axLayer.node()).width;
490+
}
491+
489492
titleEl = titleCont.select('text');
490493

491494
if(titleEl.node() && !titleEl.classed(cn.jsPlaceholder)) {
@@ -681,6 +684,7 @@ function mockColorBarAxis(gd, opts, zrange) {
681684
tickwidth: opts.tickwidth,
682685
tickcolor: opts.tickcolor,
683686
showticklabels: opts.showticklabels,
687+
ticklabelposition: opts.ticklabelposition,
684688
tickfont: opts.tickfont,
685689
tickangle: opts.tickangle,
686690
tickformat: opts.tickformat,
@@ -710,7 +714,6 @@ function mockColorBarAxis(gd, opts, zrange) {
710714
noHover: true,
711715
noTickson: true,
712716
noTicklabelmode: true,
713-
noTicklabelposition: true,
714717
calendar: fullLayout.calendar // not really necessary (yet?)
715718
};
716719

0 commit comments

Comments
 (0)