Skip to content

Commit f415e96

Browse files
committed
first-cut editType:'style' pathway for sploms
- using `_module.editStyle`, and not _module.style which would lead to double drawing from Plots.style. - in brief, for 'style' edits, we: + clear gl canvas + merge new convertMarkerStyle() into matrixOptions + call matrix.update and matrix.draw
1 parent 4792f08 commit f415e96

File tree

4 files changed

+118
-6
lines changed

4 files changed

+118
-6
lines changed

src/plot_api/subroutines.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,34 @@ exports.drawMainTitle = function(gd) {
466466
// supplyDefaults brought in an array that was already
467467
// in gd.data but not in gd._fullData previously
468468
exports.doTraceStyle = function(gd) {
469-
for(var i = 0; i < gd.calcdata.length; i++) {
470-
var cdi = gd.calcdata[i],
471-
_module = ((cdi[0] || {}).trace || {})._module || {},
472-
arraysToCalcdata = _module.arraysToCalcdata;
469+
var fullLayout = gd._fullLayout;
470+
var editStyleCalls = [];
471+
var i;
472+
473+
for(i = 0; i < gd.calcdata.length; i++) {
474+
var cd = gd.calcdata[i];
475+
var cd0 = cd[0] || {};
476+
var trace = cd0.trace || {};
477+
var _module = trace._module || {};
478+
479+
var arraysToCalcdata = _module.arraysToCalcdata;
480+
if(arraysToCalcdata) arraysToCalcdata(cd, trace);
481+
482+
var editStyle = _module.editStyle;
483+
if(editStyle) editStyleCalls.push({fn: editStyle, cd0: cd0});
484+
}
485+
486+
if(editStyleCalls.length) {
487+
clearGlCanvases(gd);
473488

474-
if(arraysToCalcdata) arraysToCalcdata(cdi, cdi[0].trace);
489+
if(fullLayout._hasOnlyLargeSploms) {
490+
fullLayout._splomGrid.draw();
491+
}
492+
493+
for(i = 0; i < editStyleCalls.length; i++) {
494+
var edit = editStyleCalls[i];
495+
edit.fn(gd, edit.cd0);
496+
}
475497
}
476498

477499
Plots.style(gd);

src/traces/splom/attributes.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88

99
'use strict';
1010

11+
var scatterAttrs = require('../scatter/attributes');
12+
var colorAttrs = require('../../components/colorscale/attributes');
1113
var scatterGlAttrs = require('../scattergl/attributes');
1214
var cartesianIdRegex = require('../../plots/cartesian/constants').idRegex;
1315
var templatedArray = require('../../plot_api/plot_template').templatedArray;
1416
var extendFlat = require('../../lib/extend').extendFlat;
1517

18+
var scatterMarkerAttrs = scatterAttrs.marker;
19+
var scatterMarkerLineAttrs = scatterMarkerAttrs.line;
20+
1621
function makeAxesValObject(axLetter) {
1722
return {
1823
valType: 'info_array',
@@ -96,7 +101,21 @@ module.exports = {
96101
'this trace\'s (x,y) coordinates.'
97102
].join(' ')
98103
}),
99-
marker: scatterGlAttrs.marker,
104+
105+
marker: extendFlat({}, colorAttrs('marker'), {
106+
symbol: scatterMarkerAttrs.symbol,
107+
size: scatterMarkerAttrs.size,
108+
sizeref: scatterMarkerAttrs.sizeref,
109+
sizemin: scatterMarkerAttrs.sizemin,
110+
sizemode: scatterMarkerAttrs.sizemode,
111+
opacity: scatterMarkerAttrs.opacity,
112+
colorbar: scatterMarkerAttrs.colorbar,
113+
line: extendFlat({}, colorAttrs('marker.line'), {
114+
width: scatterMarkerLineAttrs.width,
115+
editType: 'calc'
116+
}),
117+
editType: 'calc'
118+
}),
100119

101120
xaxes: makeAxesValObject('x'),
102121
yaxes: makeAxesValObject('y'),

src/traces/splom/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,23 @@ function plotOne(gd, cd0) {
306306
scene.draw();
307307
}
308308

309+
function editStyle(gd, cd0) {
310+
var trace = cd0.trace;
311+
var scene = gd._fullLayout._splomScenes[trace.uid];
312+
313+
calcColorscales(trace);
314+
315+
Lib.extendFlat(scene.matrixOptions, convertMarkerStyle(trace));
316+
// TODO [un]selected styles?
317+
318+
var opts = Lib.extendFlat({}, scene.matrixOptions, scene.viewOpts);
319+
320+
// TODO this is too long for arrayOk attributes!
321+
scene.matrix.update(opts, null);
322+
323+
scene.draw();
324+
}
325+
309326
function hoverPoints(pointData, xval, yval) {
310327
var cd = pointData.cd;
311328
var trace = cd[0].trace;
@@ -476,6 +493,7 @@ module.exports = {
476493
hoverPoints: hoverPoints,
477494
selectPoints: selectPoints,
478495
styleOnSelect: styleOnSelect,
496+
editStyle: editStyle,
479497

480498
meta: {
481499
description: [

test/jasmine/tests/splom_test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,10 @@ describe('Test splom update switchboard:', function() {
808808
});
809809
}
810810

811+
function toPlainArray(typedArray) {
812+
return Array.prototype.slice.call(typedArray);
813+
}
814+
811815
it('@gl should trigger minimal sequence for axis range updates (large splom case)', function(done) {
812816
var fig = Lib.extendDeep({}, require('@mocks/splom_large.json'));
813817
var matrix, regl, splomGrid;
@@ -851,6 +855,55 @@ describe('Test splom update switchboard:', function() {
851855
.catch(failTest)
852856
.then(done);
853857
});
858+
859+
it('@gl should trigger minimal sequence for marker style updates', function(done) {
860+
var fig = Lib.extendDeep({}, require('@mocks/splom_0.json'));
861+
var scene, matrix, regl;
862+
863+
Plotly.plot(gd, fig).then(function() {
864+
var fullLayout = gd._fullLayout;
865+
var trace = gd._fullData[0];
866+
scene = fullLayout._splomScenes[trace.uid];
867+
matrix = scene.matrix;
868+
regl = matrix.regl;
869+
870+
methods = [
871+
[Plots, 'supplyDefaults'],
872+
[Plots, 'doCalcdata'],
873+
[Axes, 'doTicks'],
874+
[regl, 'clear'],
875+
[matrix, 'update'],
876+
[matrix, 'draw']
877+
];
878+
addSpies();
879+
880+
expect(toPlainArray(scene.matrixOptions.color))
881+
.toBeCloseToArray([31, 119, 180, 255], 1, 'base color');
882+
expect(scene.matrixOptions.size).toBe(3, 'base size');
883+
expect(fullLayout.xaxis.range).toBeCloseToArray([0.851, 3.148], 1, 'base xrng');
884+
885+
return Plotly.restyle(gd, 'marker.color', 'black');
886+
})
887+
.then(function() {
888+
var msg = 'after scaler marker.color restyle';
889+
890+
assertSpies(msg, [
891+
['supplyDefaults', 1],
892+
['doCalcdata', 0],
893+
['doTicks', 0],
894+
['regl clear', 1],
895+
['update', 1],
896+
['draw', 1]
897+
]);
898+
899+
expect(toPlainArray(scene.matrixOptions.color))
900+
.toBeCloseToArray([0, 0, 0, 255], 1, msg);
901+
902+
return Plotly.restyle(gd, 'marker.color', [['red', 'green', 'blue']]);
903+
})
904+
.catch(failTest)
905+
.then(done);
906+
});
854907
});
855908

856909
describe('Test splom hover:', function() {

0 commit comments

Comments
 (0)