Skip to content

Commit e54d009

Browse files
authored
Merge pull request #1641 from plotly/fix-scattercarpet
Fix scattercarpet calc
2 parents 2bac6ef + 9985068 commit e54d009

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

src/traces/scattercarpet/calc.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
var isNumeric = require('fast-isnumeric');
1313

1414
var Axes = require('../../plots/cartesian/axes');
15-
var Lib = require('../../lib');
1615

1716
var subTypes = require('../scatter/subtypes');
1817
var calcColorscale = require('../scatter/colorscale_calc');
18+
var arraysToCalcdata = require('../scatter/arrays_to_calcdata');
1919
var lookupCarpet = require('../carpet/lookup_carpetid');
2020

2121
module.exports = function calc(gd, trace) {
@@ -68,8 +68,7 @@ module.exports = function calc(gd, trace) {
6868

6969
calcColorscale(trace);
7070

71-
// this has migrated up from arraysToCalcdata as we have a reference to 's' here
72-
if(typeof s !== 'undefined') Lib.mergeArray(s, cd, 'ms');
71+
arraysToCalcdata(cd, trace);
7372

7473
return cd;
7574
};

test/jasmine/tests/carpet_test.js

+58
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,61 @@ describe('Test carpet interactions:', function() {
512512
.then(done);
513513
});
514514
});
515+
516+
describe('scattercarpet array attributes', function() {
517+
var gd;
518+
519+
beforeEach(function() {
520+
gd = createGraphDiv();
521+
});
522+
523+
afterEach(destroyGraphDiv);
524+
525+
it('works in both initial draws and restyles', function(done) {
526+
var mock = Lib.extendDeep({}, require('@mocks/scattercarpet.json'));
527+
528+
var mc = ['#000', '#00f', '#0ff', '#ff0'];
529+
var ms = [10, 20, 30, 40];
530+
var ms2 = [5, 6, 7, 8];
531+
var mlw = [1, 2, 3, 4];
532+
var mlc = ['#00e', '#0ee', '#ee0', '#eee'];
533+
534+
// add some arrayOk array attributes
535+
mock.data[5].marker = {
536+
color: mc,
537+
size: ms,
538+
line: {
539+
width: mlw,
540+
color: mlc
541+
}
542+
};
543+
544+
Plotly.plot(gd, mock)
545+
.then(function() {
546+
for(var i = 0; i < 4; i++) {
547+
var pt = gd.calcdata[5][i];
548+
expect(pt.mc).toBe(mc[i]);
549+
expect(pt.ms).toBe(ms[i]);
550+
expect(pt.mlw).toBe(mlw[i]);
551+
expect(pt.mlc).toBe(mlc[i]);
552+
}
553+
554+
// turn one array into a constant, another into a new array,
555+
return Plotly.restyle(gd, {'marker.color': '#f00', 'marker.size': [ms2]},
556+
null, [5]);
557+
})
558+
.then(function() {
559+
expect(gd._fullData[5].marker.color).toBe('#f00');
560+
561+
for(var i = 0; i < 4; i++) {
562+
var pt = gd.calcdata[5][i];
563+
expect(pt.mc).toBeUndefined();
564+
expect(pt.ms).toBe(ms2[i]);
565+
expect(pt.mlw).toBe(mlw[i]);
566+
expect(pt.mlc).toBe(mlc[i]);
567+
}
568+
})
569+
.catch(fail)
570+
.then(done);
571+
});
572+
});

0 commit comments

Comments
 (0)