Skip to content

Commit 1702b30

Browse files
committed
Make selection work better
1 parent a41ea35 commit 1702b30

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/traces/scattergl/index.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var createLine = require('regl-line2d');
1313
var createError = require('regl-error2d');
1414
var cluster = require('point-cluster');
1515
var arrayRange = require('array-range');
16-
var Text = require('gl-text');
16+
var Text = require('../../../../gl-text/index');
1717

1818
var Registry = require('../../registry');
1919
var Lib = require('../../lib');
@@ -861,17 +861,21 @@ function selectPoints(searchInfo, polygon) {
861861

862862
// update texts selection
863863
if(hasText) {
864-
var textOptions = {};
864+
var textOptions = Lib.extendFlat({}, scene.textOptions[stash.index]);
865865
if(els && unels) {
866866
if(els) {
867867
applyTextoption(textOptions, els, scene.selectedOptions[stash.index]);
868868
}
869869
if(unels) {
870870
applyTextoption(textOptions, unels, scene.unselectedOptions[stash.index]);
871+
if(!scene.unselectedOptions[stash.index].opacity) {
872+
applyTextoption(textOptions, unels, {opacity: 1});
873+
}
871874
}
872875
}
873876
else {
874-
// TODO: reset unselected style properly
877+
applyTextoption(textOptions, unels, { opacity: 1 });
878+
applyTextoption(textOptions, unels, scene.textOptions[stash.index]);
875879
}
876880

877881
scene.glText[stash.index].update(textOptions);
@@ -883,12 +887,11 @@ function selectPoints(searchInfo, polygon) {
883887
var el = els[i];
884888
if(selOptions.textfont) {
885889
if(selOptions.textfont.color) {
886-
if(!textOptions.color) textOptions.color = [];
890+
textOptions.color = toArray(textOptions.color);
887891
textOptions.color[el] = selOptions.textfont.color;
888892
}
889893
if(selOptions.textfont.family || selOptions.textfont.size) {
890-
if(!textOptions.font) textOptions.font = [];
891-
textOptions.font[el] = {};
894+
textOptions.font = toArray(textOptions.font, {});
892895
if(selOptions.textfont.family) {
893896
textOptions.font[el].family = selOptions.textfont.family;
894897
}
@@ -898,12 +901,23 @@ function selectPoints(searchInfo, polygon) {
898901
}
899902
}
900903
if('opacity' in selOptions) {
901-
if(!textOptions.opacity) textOptions.opacity = [];
904+
textOptions.opacity = toArray(textOptions.opacity, 1);
902905
textOptions.opacity[el] = selOptions.opacity;
903906
}
904907
}
905908
}
906909

910+
function toArray(value, dflt) {
911+
if(!Array.isArray(value)) {
912+
var v = value;
913+
value = Array(stash.count);
914+
for(var j = 0; j < stash.count; j++) {
915+
value[j] = v !== null ? v : dflt;
916+
}
917+
}
918+
return value;
919+
}
920+
907921
scene.selectBatch[stash.index] = els;
908922
scene.unselectBatch[stash.index] = unels;
909923

0 commit comments

Comments
 (0)