Implement cleaner solution for removing breathe styling from deselected features

This commit is contained in:
Quincy Morgan
2019-12-13 13:16:29 -05:00
parent 61f0a670db
commit 91b6844377
2 changed files with 18 additions and 17 deletions

View File

@@ -117,6 +117,7 @@ export function behaviorBreathe() {
if (_done || currSelected.empty()) {
_selected.call(reset);
_selected = d3_select(null);
return;
}
@@ -139,11 +140,14 @@ export function behaviorBreathe() {
surface.call(run, toFrom);
didCallNextRun = true;
}
// if entity was deselected, remove breathe styling
if (!d3_select(this).classed('selected')) {
reset(d3_select(this));
}
});
}
var _isInstalled = false;
function behavior(surface) {
_done = false;
_timer = d3_timer(function() {
@@ -156,11 +160,15 @@ export function behaviorBreathe() {
_timer.stop();
return true;
}, 20);
_isInstalled = true;
}
behavior.isInstalled = function() {
return _isInstalled;
behavior.restartIfNeeded = function(surface) {
if (_selected.empty()) {
surface.call(run, 'from');
if (_timer) {
_timer.stop();
}
}
};
behavior.off = function() {
@@ -171,7 +179,6 @@ export function behaviorBreathe() {
_selected
.interrupt()
.call(reset);
_isInstalled = false;
};

View File

@@ -321,7 +321,10 @@ export function modeSelect(context, selectedIDs) {
context.map()
.on('move.select', closeMenu)
.on('drawn.select', selectElements)
.on('crossEditableZoom.select', selectElements);
.on('crossEditableZoom.select', function() {
selectElements();
breatheBehavior.restartIfNeeded(context.surface());
});
context.surface()
.on('dblclick.select', dblclick);
@@ -421,7 +424,7 @@ export function modeSelect(context, selectedIDs) {
}
if (context.map().withinEditableZoom()) {
// Only apply selection styling if not in wide selection
// Apply selection styling if not in wide selection
surface
.selectAll(utilDeepMemberSelector(selectedIDs, context.graph()))
@@ -429,15 +432,6 @@ export function modeSelect(context, selectedIDs) {
surface
.selectAll(utilEntityOrDeepMemberSelector(selectedIDs, context.graph()))
.classed('selected', true);
if (!breatheBehavior.isInstalled()) {
context.install(breatheBehavior);
}
} else {
if (breatheBehavior.isInstalled()) {
context.uninstall(breatheBehavior);
}
}
}