Skip to content

Commit 10ddbb9

Browse files
committed
fix and 🔒 problem with dragging colorbars in sub-containers
1 parent a11ec44 commit 10ddbb9

File tree

2 files changed

+59
-12
lines changed

2 files changed

+59
-12
lines changed

src/components/colorbar/draw.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -467,15 +467,10 @@ module.exports = function draw(gd, id) {
467467
}
468468

469469
function drawTitle(titleClass, titleOpts) {
470-
var trace = getTrace();
471-
var propName = 'colorbar.title';
472-
var containerName = trace._module.colorbar.container;
473-
if(containerName) propName = containerName + '.' + propName;
474-
475470
var dfltTitleOpts = {
476471
propContainer: cbAxisOut,
477-
propName: propName,
478-
traceIndex: trace.index,
472+
propName: getPropName('title'),
473+
traceIndex: getTrace().index,
479474
placeholder: fullLayout._dfltTitle.colorbar,
480475
containerGroup: container.select('.cbtitle')
481476
};
@@ -627,11 +622,10 @@ module.exports = function draw(gd, id) {
627622
setCursor(container);
628623

629624
if(xf !== undefined && yf !== undefined) {
630-
Registry.call('_guiRestyle',
631-
gd,
632-
{'colorbar.x': xf, 'colorbar.y': yf},
633-
getTrace().index
634-
);
625+
var update = {};
626+
update[getPropName('x')] = xf;
627+
update[getPropName('y')] = yf;
628+
Registry.call('_guiRestyle', gd, update, getTrace().index);
635629
}
636630
}
637631
});
@@ -649,6 +643,14 @@ module.exports = function draw(gd, id) {
649643
}
650644
}
651645

646+
function getPropName(suffix) {
647+
var trace = getTrace();
648+
var propName = 'colorbar.';
649+
var containerName = trace._module.colorbar.container;
650+
if(containerName) propName = containerName + '.' + propName;
651+
return propName + suffix;
652+
}
653+
652654
// setter/getters for every item defined in opts
653655
Object.keys(opts).forEach(function(name) {
654656
component[name] = function(v) {

test/jasmine/tests/colorbar_test.js

+45
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
88
var failTest = require('../assets/fail_test');
99
var supplyAllDefaults = require('../assets/supply_defaults');
1010
var assertPlotSize = require('../assets/custom_assertions').assertPlotSize;
11+
var drag = require('../assets/drag');
1112

1213

1314
describe('Test colorbar:', function() {
@@ -354,5 +355,49 @@ describe('Test colorbar:', function() {
354355
.catch(failTest)
355356
.then(done);
356357
});
358+
359+
function getCBNode() {
360+
return document.querySelector('.colorbar');
361+
}
362+
363+
it('can drag root-level colorbars in editable mode', function(done) {
364+
Plotly.newPlot(gd,
365+
[{z: [[1, 2], [3, 4]], type: 'heatmap'}],
366+
{width: 400, height: 400},
367+
{editable: true}
368+
)
369+
.then(function() {
370+
expect(gd.data[0].colorbar).toBeUndefined();
371+
expect(gd._fullData[0].colorbar.x).toBe(1.02);
372+
expect(gd._fullData[0].colorbar.y).toBe(0.5);
373+
return drag(getCBNode(), -100, 100);
374+
})
375+
.then(function() {
376+
expect(gd.data[0].colorbar.x).toBeWithin(0.591, 0.01);
377+
expect(gd.data[0].colorbar.y).toBeWithin(0.045, 0.01);
378+
})
379+
.catch(failTest)
380+
.then(done);
381+
});
382+
383+
it('can drag marker-level colorbars in editable mode', function(done) {
384+
Plotly.newPlot(gd,
385+
[{y: [1, 2, 1], marker: {color: [0, 1, 2], showscale: true}}],
386+
{width: 400, height: 400},
387+
{editable: true}
388+
)
389+
.then(function() {
390+
expect(gd.data[0].marker.colorbar).toBeUndefined();
391+
expect(gd._fullData[0].marker.colorbar.x).toBe(1.02);
392+
expect(gd._fullData[0].marker.colorbar.y).toBe(0.5);
393+
return drag(getCBNode(), -100, 100);
394+
})
395+
.then(function() {
396+
expect(gd.data[0].marker.colorbar.x).toBeWithin(0.591, 0.01);
397+
expect(gd.data[0].marker.colorbar.y).toBeWithin(0.045, 0.01);
398+
})
399+
.catch(failTest)
400+
.then(done);
401+
});
357402
});
358403
});

0 commit comments

Comments
 (0)