Skip to content

Commit 52614d1

Browse files
committedJul 4, 2018
fix and 🔒 selections + array textfont.color
1 parent e462eda commit 52614d1

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed
 

‎src/traces/scattergl/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -921,20 +921,24 @@ function styleTextSelection(cd) {
921921
var selOpts = scene.textSelectedOptions[index] || {};
922922
var unselOpts = scene.textUnselectedOptions[index] || {};
923923
var opts = Lib.extendFlat({}, baseOpts);
924-
var i;
924+
var i, j;
925925

926926
if(els && unels) {
927927
var stc = selOpts.color;
928928
var utc = unselOpts.color;
929929
var base = baseOpts.color;
930+
var hasArrayBase = Array.isArray(base);
930931
opts.color = new Array(stash.count);
931932

932933
for(i = 0; i < els.length; i++) {
933-
opts.color[els[i]] = stc || base;
934+
j = els[i];
935+
opts.color[j] = stc || hasArrayBase ? base[j] : base;
934936
}
935937
for(i = 0; i < unels.length; i++) {
936-
opts.color[unels[i]] = utc ? utc :
937-
stc ? base : Color.addOpacity(base, DESELECTDIM);
938+
j = unels[i];
939+
var basej = hasArrayBase ? base[j] : base;
940+
opts.color[j] = utc ? utc :
941+
stc ? basej : Color.addOpacity(basej, DESELECTDIM);
938942
}
939943
}
940944

‎test/jasmine/tests/gl2d_click_test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,4 +795,63 @@ describe('@noCI @gl Test gl2d lasso/select:', function() {
795795
.catch(failTest)
796796
.then(done);
797797
});
798+
799+
it('should work on gl text charts with array textfont.color', function(done) {
800+
var fig = Lib.extendDeep({}, require('@mocks/gl2d_text_chart_arrays.json'));
801+
fig.layout.dragmode = 'select';
802+
fig.layout.margin = {t: 0, b: 0, l: 0, r: 0};
803+
fig.layout.height = 500;
804+
fig.layout.width = 500;
805+
gd = createGraphDiv();
806+
807+
function _assertGlTextOpts(msg, exp) {
808+
var scene = gd.calcdata[0][0].t._scene;
809+
scene.glText.forEach(function(opts, i) {
810+
expect(Array.from(opts.color))
811+
.toBeCloseToArray(exp.rgba[i], 2, 'item ' + i + ' - ' + msg);
812+
});
813+
}
814+
815+
Plotly.plot(gd, fig)
816+
.then(delay(100))
817+
.then(function() {
818+
_assertGlTextOpts('base', {
819+
rgba: [
820+
[
821+
255, 0, 0, 255,
822+
0, 0, 255, 255,
823+
0, 128, 0, 255
824+
],
825+
[
826+
0, 0, 0, 255,
827+
211, 211, 210, 255,
828+
237, 97, 0, 255
829+
]
830+
]
831+
});
832+
})
833+
.then(function() { return select([[100, 10], [250, 100]]); })
834+
.then(function(eventData) {
835+
assertEventData(eventData, {
836+
points: [{x: 1, y: 2}]
837+
});
838+
_assertGlTextOpts('after selection', {
839+
rgba: [
840+
[
841+
255, 0, 0, 51,
842+
0, 0, 255, 51,
843+
0, 128, 0, 51
844+
],
845+
[
846+
0, 0, 0, 51,
847+
// this is the selected pt!
848+
211, 211, 210, 255,
849+
237, 97, 0, 51
850+
]
851+
]
852+
});
853+
})
854+
.catch(failTest)
855+
.then(done);
856+
});
798857
});

0 commit comments

Comments
 (0)
Please sign in to comment.