Skip to content

Commit fa67db3

Browse files
committed
make colorbar from color axes editable
1 parent b6503ac commit fa67db3

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/components/colorbar/draw.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ function makeColorBarData(gd) {
155155

156156
opts = initOpts(cont.colorbar);
157157
opts._id = 'cb' + k;
158+
opts._propPrefix = k + '.colorbar.';
158159

159160
cbOpt = {min: 'cmin', max: 'cmax'};
160161
calcOpts();
@@ -591,7 +592,11 @@ function makeEditable(g, opts, gd) {
591592
var update = {};
592593
update[opts._propPrefix + 'x'] = xf;
593594
update[opts._propPrefix + 'y'] = yf;
594-
Registry.call('_guiRestyle', gd, update, opts._traceIndex);
595+
if(opts._traceIndex !== undefined) {
596+
Registry.call('_guiRestyle', gd, update, opts._traceIndex);
597+
} else {
598+
Registry.call('_guiRelayout', gd, update);
599+
}
595600
}
596601
}
597602
});

test/jasmine/tests/colorbar_test.js

+22
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,28 @@ describe('Test colorbar:', function() {
436436
.then(done);
437437
});
438438

439+
it('can drag colorbars linked to color axes in editable mode', function(done) {
440+
Plotly.newPlot(gd,
441+
[{z: [[1, 2], [3, 4]], type: 'heatmap', coloraxis: 'coloraxis'}],
442+
{coloraxis: {}, width: 400, height: 400},
443+
{editable: true}
444+
)
445+
.then(function() {
446+
expect(gd.layout.coloraxis.colorbar).toBeUndefined();
447+
expect(gd._fullLayout.coloraxis.colorbar.x).toBe(1.02);
448+
expect(gd._fullLayout.coloraxis.colorbar.y).toBe(0.5);
449+
return drag(getCBNode(), -100, 100);
450+
})
451+
.then(function() {
452+
expect(gd.layout.coloraxis.colorbar.x).toBeWithin(0.591, 0.01);
453+
expect(gd.layout.coloraxis.colorbar.y).toBeWithin(0.045, 0.01);
454+
expect(gd._fullLayout.coloraxis.colorbar.x).toBeWithin(0.591, 0.01);
455+
expect(gd._fullLayout.coloraxis.colorbar.y).toBeWithin(0.045, 0.01);
456+
})
457+
.catch(failTest)
458+
.then(done);
459+
});
460+
439461
it('can edit colorbar visuals in optimized edit pathway', function(done) {
440462
spyOn(subroutines, 'doColorBars').and.callThrough();
441463
spyOn(Plots, 'doCalcdata').and.callThrough();

0 commit comments

Comments
 (0)