Skip to content

Commit 6eac0b3

Browse files
authored
Merge pull request #5217 from anaplian/fix5161-fix-colorbar-react
Fix issue where styles weren't reset when re-using SVGs in colorbar
2 parents 31955e7 + f5ad0cc commit 6eac0b3

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/components/colorbar/draw.js

+1
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ function drawColorBar(g, opts, gd) {
397397

398398
var fills = g.select('.' + cn.cbfills)
399399
.selectAll('rect.' + cn.cbfill)
400+
.attr('style', '')
400401
.data(fillLevels);
401402
fills.enter().append('rect')
402403
.classed(cn.cbfill, true)

test/jasmine/tests/colorbar_test.js

+37
Original file line numberDiff line numberDiff line change
@@ -524,5 +524,42 @@ describe('Test colorbar:', function() {
524524
.catch(failTest)
525525
.then(done);
526526
});
527+
528+
it('creates the same colorbars attributes in newPlot and react', function(done) {
529+
function getCBFillAttributes() {
530+
var attrs = [];
531+
var colorbars = d3.select(gd).selectAll('.colorbar');
532+
colorbars.selectAll('.cbfill').each(function() {
533+
var attrsForElem = {};
534+
for(var i = 0; i < this.attributes.length; i++) {
535+
var attr = this.attributes.item(i);
536+
attrsForElem[attr.name] = attr.value;
537+
}
538+
attrs.push(attrsForElem);
539+
});
540+
return attrs;
541+
}
542+
543+
var z = [[1, 10], [100, 1000]];
544+
545+
var expectedAttrs;
546+
var actualAttrs;
547+
548+
Plotly.newPlot(gd, [{type: 'contour', z: z}])
549+
.then(function() {
550+
expectedAttrs = getCBFillAttributes();
551+
552+
return Plotly.newPlot(gd, [{type: 'heatmap', z: z}])
553+
.then(function() {
554+
return Plotly.react(gd, [{type: 'contour', z: z}]);
555+
});
556+
})
557+
.then(function() {
558+
actualAttrs = getCBFillAttributes();
559+
expect(actualAttrs).toEqual(expectedAttrs);
560+
})
561+
.catch(failTest)
562+
.then(done);
563+
});
527564
});
528565
});

0 commit comments

Comments
 (0)