Skip to content

Commit b6503ac

Browse files
committed
add 'colorbars' edit type to layout flags
1 parent 5bb341e commit b6503ac

File tree

4 files changed

+77
-5
lines changed

4 files changed

+77
-5
lines changed

src/plot_api/edit_types.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var layoutOpts = {
3535
extras: ['none'],
3636
flags: [
3737
'calc', 'plot', 'legend', 'ticks', 'axrange',
38-
'layoutstyle', 'modebar', 'camera', 'arraydraw'
38+
'layoutstyle', 'modebar', 'camera', 'arraydraw', 'colorbars'
3939
],
4040
description: [
4141
'layout attributes should include an `editType` string matching this flaglist.',
@@ -49,7 +49,8 @@ var layoutOpts = {
4949
'*modebar* just updates the modebar.',
5050
'*camera* just updates the camera settings for gl3d scenes.',
5151
'*arraydraw* allows component arrays to invoke the redraw routines just for the',
52-
'component(s) that changed.'
52+
'component(s) that changed.',
53+
'*colorbars* only redraws colorbars.'
5354
].join(' ')
5455
};
5556

src/plot_api/plot_api.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,7 @@ function relayout(gd, astr, val) {
18711871
if(flags.ticks) seq.push(subroutines.doTicksRelayout);
18721872
if(flags.modebar) seq.push(subroutines.doModeBar);
18731873
if(flags.camera) seq.push(subroutines.doCamera);
1874+
if(flags.colorbars) seq.push(subroutines.doColorBars);
18741875

18751876
seq.push(emitAfterPlot);
18761877
}
@@ -2382,7 +2383,7 @@ function update(gd, traceUpdate, layoutUpdate, _traces) {
23822383
axRangeSupplyDefaultsByPass(gd, relayoutFlags, relayoutSpecs) || Plots.supplyDefaults(gd);
23832384

23842385
if(restyleFlags.style) seq.push(subroutines.doTraceStyle);
2385-
if(restyleFlags.colorbars) seq.push(subroutines.doColorBars);
2386+
if(restyleFlags.colorbars || relayoutFlags.colorbars) seq.push(subroutines.doColorBars);
23862387
if(relayoutFlags.legend) seq.push(subroutines.doLegend);
23872388
if(relayoutFlags.layoutstyle) seq.push(subroutines.layoutStyles);
23882389
if(relayoutFlags.axrange) addAxRangeSequence(seq, relayoutSpecs.rangesAltered);
@@ -2779,7 +2780,7 @@ exports.react = function(gd, data, layout, config) {
27792780

27802781
seq.push(Plots.previousPromises);
27812782
if(restyleFlags.style) seq.push(subroutines.doTraceStyle);
2782-
if(restyleFlags.colorbars) seq.push(subroutines.doColorBars);
2783+
if(restyleFlags.colorbars || relayoutFlags.colorbars) seq.push(subroutines.doColorBars);
27832784
if(relayoutFlags.legend) seq.push(subroutines.doLegend);
27842785
if(relayoutFlags.layoutstyle) seq.push(subroutines.layoutStyles);
27852786
if(relayoutFlags.axrange) addAxRangeSequence(seq);

src/plot_api/plot_schema.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ function layoutHeadAttr(fullLayout, head) {
373373
*/
374374
for(key in Registry.componentsRegistry) {
375375
_module = Registry.componentsRegistry[key];
376-
if(!_module.schema && (head === _module.name)) {
376+
if(_module.name === 'colorscale' && head.indexOf('coloraxis') === 0) {
377+
return _module.layoutAttributes[head];
378+
} else if(!_module.schema && (head === _module.name)) {
377379
return _module.layoutAttributes;
378380
}
379381
}

test/jasmine/tests/colorbar_test.js

+68
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ var d3 = require('d3');
22

33
var Plotly = require('@lib/index');
44
var Colorbar = require('@src/components/colorbar');
5+
var Plots = require('@src/plots/plots');
6+
var subroutines = require('@src/plot_api/subroutines');
57

68
var createGraphDiv = require('../assets/create_graph_div');
79
var destroyGraphDiv = require('../assets/destroy_graph_div');
@@ -433,5 +435,71 @@ describe('Test colorbar:', function() {
433435
.catch(failTest)
434436
.then(done);
435437
});
438+
439+
it('can edit colorbar visuals in optimized edit pathway', function(done) {
440+
spyOn(subroutines, 'doColorBars').and.callThrough();
441+
spyOn(Plots, 'doCalcdata').and.callThrough();
442+
443+
function getOutline(cb) {
444+
return Number(cb.select('.cboutline').node().style['stroke-width']);
445+
}
446+
447+
function _assert(msg, exp) {
448+
var gd3 = d3.select(gd);
449+
var cb0 = gd3.select('.cbtrace0');
450+
var cb1 = gd3.select('.cbcoloraxis');
451+
452+
if(msg !== 'base') {
453+
expect(subroutines.doColorBars).toHaveBeenCalledTimes(1);
454+
expect(Plots.doCalcdata).toHaveBeenCalledTimes(0);
455+
}
456+
subroutines.doColorBars.calls.reset();
457+
Plots.doCalcdata.calls.reset();
458+
459+
expect(getOutline(cb0)).toBe(exp.outline[0], 'trace0 cb outline');
460+
expect(getOutline(cb1)).toBe(exp.outline[1], 'coloraxis cb outline');
461+
}
462+
463+
Plotly.newPlot(gd, [{
464+
type: 'heatmap',
465+
z: [[1, 2, 3], [2, 1, 2]],
466+
uid: 'trace0'
467+
}, {
468+
y: [1, 2, 3],
469+
marker: {color: [2, 1, 2], coloraxis: 'coloraxis'}
470+
}], {
471+
width: 500,
472+
height: 500
473+
})
474+
.then(function() { _assert('base', {outline: [1, 1]}); })
475+
.then(function() {
476+
return Plotly.restyle(gd, 'colorbar.outlinewidth', 2, [0]);
477+
})
478+
.then(function() { _assert('after restyle', {outline: [2, 1]}); })
479+
.then(function() {
480+
return Plotly.relayout(gd, 'coloraxis.colorbar.outlinewidth', 5);
481+
})
482+
.then(function() { _assert('after relayout', {outline: [2, 5]}); })
483+
.then(function() {
484+
return Plotly.update(gd, {'colorbar.outlinewidth': 1}, {}, [0]);
485+
})
486+
.then(function() { _assert('after trace update', {outline: [1, 5]}); })
487+
.then(function() {
488+
return Plotly.update(gd, {}, {'coloraxis.colorbar.outlinewidth': 1});
489+
})
490+
.then(function() { _assert('after layout update', {outline: [1, 1]}); })
491+
.then(function() {
492+
gd.data[0].colorbar = {outlinewidth: 10};
493+
return Plotly.react(gd, gd.data, gd.layout);
494+
})
495+
.then(function() { _assert('after trace react', {outline: [10, 1]}); })
496+
.then(function() {
497+
gd.layout.coloraxis = {colorbar: {outlinewidth: 10}};
498+
return Plotly.react(gd, gd.data, gd.layout);
499+
})
500+
.then(function() { _assert('after layout trace', {outline: [10, 10]}); })
501+
.catch(failTest)
502+
.then(done);
503+
});
436504
});
437505
});

0 commit comments

Comments
 (0)