@rcsb/rcsb-saguaro
Version:
RCSB 1D Feature Viewer
86 lines (85 loc) • 3.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RcsbD3EventDispatcher = void 0;
const d3_selection_1 = require("d3-selection");
const RcsbD3Constants_1 = require("./RcsbD3Constants");
const rxjs_1 = require("rxjs");
class RcsbD3EventDispatcher {
static elementClick(event, callback, d) {
if (event.shiftKey || event.ctrlKey)
callback(d, 'add', 'select', false);
else
callback(d, 'set', 'select', false);
}
static boardMousedown(event, board) {
const svgNode = board.d3Manager.svgG().node();
if (svgNode != null) {
const x = (0, d3_selection_1.pointer)(event, svgNode)[0];
RcsbD3EventDispatcher.selectionBegin = Math.round(board.xScale().invert(x));
}
RcsbD3EventDispatcher.keepSelectingFlag = true;
RcsbD3EventDispatcher.operation = (event.shiftKey || event.ctrlKey) ? 'add' : 'set';
board.d3Manager.svgG().on(RcsbD3Constants_1.RcsbD3Constants.MOUSE_MOVE, (e) => {
RcsbD3EventDispatcher.boardMousemove(e, board);
});
}
static boardMousemove(event, board) {
const svgNode = board.d3Manager.svgG().node();
if (svgNode != null) {
const x = (0, d3_selection_1.pointer)(event, svgNode)[0];
let _end = Math.round(board.xScale().invert(x));
RcsbD3EventDispatcher.selectionEnd = _end;
let _begin = RcsbD3EventDispatcher.selectionBegin;
if (_begin > _end) {
const aux = _begin;
_begin = _end;
_end = aux;
}
const region = { begin: _begin, end: _end, nonSpecific: true };
board.highlightRegion(region, RcsbD3EventDispatcher.operation, 'select', false);
return region;
}
else {
throw "Board main G element not found";
}
}
static boardMouseup(event, board) {
if (!RcsbD3EventDispatcher.keepSelectingFlag)
return;
board.d3Manager.svgG().on(RcsbD3Constants_1.RcsbD3Constants.MOUSE_MOVE, null);
const region = RcsbD3EventDispatcher.boardMousemove(event, board);
board.elementClickSubject.next({ d: region, e: event });
RcsbD3EventDispatcher.keepSelectingFlag = false;
}
static leavingTrack(event, board) {
RcsbD3EventDispatcher.changeTrackFlag = true;
board.d3Manager.svgG().on(RcsbD3Constants_1.RcsbD3Constants.MOUSE_MOVE, null);
rxjs_1.asyncScheduler.schedule(() => {
if (RcsbD3EventDispatcher.changeTrackFlag) {
RcsbD3EventDispatcher.keepSelectingFlag = false;
RcsbD3EventDispatcher.changeTrackFlag = false;
let _end = RcsbD3EventDispatcher.selectionEnd;
let _begin = RcsbD3EventDispatcher.selectionBegin;
if (_begin > _end) {
const aux = _begin;
_begin = _end;
_end = aux;
}
const region = { begin: _begin, end: _end };
board.elementClickSubject.next({ d: Object.assign(Object.assign({}, region), { nonSpecific: true }), e: event });
}
}, 50);
}
static changeTrack(event, board) {
if (!RcsbD3EventDispatcher.changeTrackFlag)
return;
RcsbD3EventDispatcher.changeTrackFlag = false;
board.d3Manager.svgG().on(RcsbD3Constants_1.RcsbD3Constants.MOUSE_MOVE, (e) => {
RcsbD3EventDispatcher.boardMousemove(e, board);
});
}
}
exports.RcsbD3EventDispatcher = RcsbD3EventDispatcher;
RcsbD3EventDispatcher.keepSelectingFlag = false;
RcsbD3EventDispatcher.changeTrackFlag = true;
RcsbD3EventDispatcher.operation = 'set';