Skip to content

Commit f69f6fc

Browse files
authored
Merge pull request #694 from plotly/fix-colorscale-restyle
Fix heatmap colorscale restyles
2 parents 9dba590 + 77cc5d5 commit f69f6fc

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/traces/heatmap/plot.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,15 @@ function plotOne(gd, plotinfo, cd) {
382382

383383
image3.enter().append('svg:image').attr({
384384
xmlns: xmlnsNamespaces.svg,
385-
'xlink:href': canvas.toDataURL('image/png'),
386385
preserveAspectRatio: 'none'
387386
});
388387

389388
image3.attr({
390389
height: imageHeight,
391390
width: imageWidth,
392391
x: left,
393-
y: top
392+
y: top,
393+
'xlink:href': canvas.toDataURL('image/png')
394394
});
395395

396396
image3.exit().remove();

test/jasmine/tests/heatmap_test.js

+37
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,43 @@ describe('heatmap plot', function() {
334334
done();
335335
});
336336
});
337+
338+
it('should be able to restyle', function(done) {
339+
var mock = require('@mocks/13.json'),
340+
mockCopy = Lib.extendDeep({}, mock),
341+
gd = createGraphDiv();
342+
343+
function getImageURL() {
344+
return d3.select('.hm > image').attr('href');
345+
}
346+
347+
var imageURLs = [];
348+
349+
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() {
350+
imageURLs.push(getImageURL());
351+
352+
return Plotly.restyle(gd, 'colorscale', 'Greens');
353+
}).then(function() {
354+
imageURLs.push(getImageURL());
355+
356+
expect(imageURLs[0]).not.toEqual(imageURLs[1]);
357+
358+
return Plotly.restyle(gd, 'colorscale', 'Reds');
359+
}).then(function() {
360+
imageURLs.push(getImageURL());
361+
362+
expect(imageURLs[1]).not.toEqual(imageURLs[2]);
363+
364+
return Plotly.restyle(gd, 'colorscale', 'Greens');
365+
}).then(function() {
366+
imageURLs.push(getImageURL());
367+
368+
expect(imageURLs[1]).toEqual(imageURLs[3]);
369+
370+
done();
371+
});
372+
373+
});
337374
});
338375

339376
describe('heatmap hover', function() {

0 commit comments

Comments
 (0)